[cfe-dev] Transforming the AST
Olaf Krzikalla
Olaf.Krzikalla at tu-dresden.de
Fri Jul 9 06:34:22 PDT 2010
Hi @clang,
Douglas Gregor schrieb:
> 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.
>
This doesnt work if you change a part of an AST that was already changed
before (and thus rewritten) because you have no correct source loc info
anymore. Suppose you inline a function via an AST transformation and
later on perform some loop unrolling on that inlined function
statements. To rewrite that properly you need the source loc infos of
the original AST.
> If you find a better solution, we'd love to hear about it!
>
Well, as I said in my mail before, it's not a solution yet:
Before I start the AST processing I store the tree structure of the
original AST.
Then the first idea was to compare the completely transformed AST with
that stored structure and rewrite the changes on the tree level they
appear (IMHO this is still the correct approach).
But the function dealing with the level comparision grew bigger and
bigger as more special cases popped up and eventually became
unmanageable. Hence I decided to simply propagate changes one level up
to the appropriate parent and thus rewrite the parent statement. However
this means that just one introduced local variable at function scope
leads to a completely rewritten function body. Thus for the moment I've
canceled all efforts in this direction and just rewrite the function
body (I don't even use parent propagation). It works for my puposes but
it is a flawed solution.
Best regards
Olaf Krzikalla
More information about the cfe-dev
mailing list