[cfe-dev] Future of AST transformation

Olaf Krzikalla Olaf.Krzikalla at tu-dresden.de
Fri Jul 20 02:49:39 PDT 2012


Am 19.07.2012 00:22, schrieb Richard Smith:
> Take a look at lib/Sema/TreeTransform.h. Using that, it is certainly
> possible to perform AST to AST transformations in a way which is
> convenient and maintains the AST invariants.
I'm aware of that means. However I still haven't figuered out how 
TreeTransform can be used for a task like "a+=b" -> "a=a+b". Maybe 
someone has an example. In clang TreeTransform is used for different tasks.

> The usual approach for clang-based source-to-source transformation tools
> is to use the AST to determine what changes should be made, then produce
> a list of modifications to be made to the original source file. See
> clang::Rewriter, clang::tooling::Replacement, and
> clang::tooling::RefactoringTool for some components which make it easier
> to build such tools.
What Ronan said: I use the transformation for SIMD vectorization of 
loops. The resulting code is still readable but not any longer in a way 
suitable for maintenance. Mostly it is sent to a compiler straightforward.

I still think that an universal AST transformation framework would offer 
some great opportunities. I do it for years now and most of the time all 
went OK, esp. on statement level. All the hassle starts on expression 
level (and mostly due to ImplicitCastExpr).


Best regards
Olaf Krzikalla



More information about the cfe-dev mailing list