[cfe-dev] Future of AST transformation

Sean Silva silvas at purdue.edu
Fri Jul 20 16:08:50 PDT 2012


> 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.

Check out the block comment right above the class declaration, it
contains a quite thorough discussion. TreeTransform is just a standard
visitor pattern which recursively accumulates the results of
subinvocations. If you're familiar with Pythons `ast.NodeTransformer`,
TreeTransform is basically the same idea.

--Sean Silva

On Fri, Jul 20, 2012 at 2:49 AM, Olaf Krzikalla
<Olaf.Krzikalla at tu-dresden.de> wrote:
> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list