[cfe-dev] Transforming the AST

Douglas Gregor dgregor at apple.com
Thu Jul 8 08:22:07 PDT 2010

On Jul 8, 2010, at 8:08 AM, Olaf Krzikalla wrote:

> Apparently a lot of people create source-to-source compilers on top of 
> clang.
> John McCall schrieb:
>> If you're interested in producing transformed source code, you should 
>> really
>> use the rewriter (and tell us if that's insufficient for some reason).  
> One thing I've failed to get it right so far is a minimal transparent 
> rewrite:
> Suppose, the AST of a function is given. Then you manipluate that AST 
> (insert, remove, clone statements, all the like).
> After all is done you want to write it back but of course preserve 
> unchanged source code parts.
> While this sounds easy at first (just track the changed parts of the 
> AST) the devil is in the details.

Whenever you manipulate the AST, you could make the same (textual) transformation via the Rewriter. Then the Rewriter becomes responsible for storing all of the changes.

If you find a better solution, we'd love to hear about it!

	- Doug

More information about the cfe-dev mailing list