[cfe-dev] Transforming the AST

Douglas Gregor dgregor at apple.com
Tue Jul 6 10:10:23 PDT 2010

On Jul 6, 2010, at 8:34 AM, Zakkak Foivos wrote:

> Hello list,
> i need some help with AST transformations. I searched through the api
> but didn't find anything straight forward except some build*type functions.
> How can i create a new stmt and insert it in the tree? I don't want to
> use the Rewriter for the transformations.

If the statements you are building are relatively simple, you can just create the Stmt/Expr nodes and hook them into the AST. However, you need to build semantically well-formed statements (including all necessary implicit conversions) if you're going to do it this way, and that isn't trivial.

The other way to approach this problem is to use the ActOn* methods of Sema, so that Sema will check the semantics of the statements you create, and then hook the resulting statements/expressions into the AST.

	- Doug

More information about the cfe-dev mailing list