[cfe-dev] Transforming the AST

Olaf Krzikalla Olaf.Krzikalla at tu-dresden.de
Thu Jul 8 08:08:47 PDT 2010


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. Thus currently I rewrite complete 
functions only (and wouldn't promote that incomplete AST processing 
approach here as it is incomplete). IIRC a random access 
RopePieceBTreeIterator could help a lot (and at least a forward random 
access is easy to implement).

Best regards
Olaf Krzikalla





More information about the cfe-dev mailing list