[cfe-dev] AST generation API?

John McCall rjmccall at apple.com
Tue Mar 20 15:10:27 PDT 2012


On Mar 20, 2012, at 2:54 PM, Douglas Gregor wrote:
> On Mar 20, 2012, at 11:26 AM, Dave Abrahams wrote:
>> Is there a component/API in Clang, separate from the parser, for
>> generating valid ASTs?
> 
> If you are *extremely* careful, you can create ASTs directly with the AST library, but there isn't much to help you get it right. To actually build semantically valid ASTs (including introducing implicit conversions and such), you would need to call into Sema's entry points yourself.
> 
>> If not, has anyone given thought to what
>> that might look like?
> 
> 
> Not really. One could certainly imagine creating a set of wrapper classes that allow one to form AST nodes using expression syntax, so that you write simple C++ expressions that evaluate into the appropriate Sema calls. I'm sure that people wanting to do AST manipulations would love to have such a library.

One thing that we are definitely interested in having is an AST verifier akin to LLVM's IR verifier:  something which would explicitly check and enforce Clang's AST invariants.  This would make it much easier to do AST manipulations by both (1) documenting the invariants and (2) catching obvious problems where ASTs fail to conform.

John.




More information about the cfe-dev mailing list