[cfe-dev] AST transformations

Olaf Krzikalla Olaf.Krzikalla at tu-dresden.de
Tue Mar 15 05:50:48 PDT 2011


Hi, @clang,

Am 11.03.2011 17:55, schrieb Douglas Gregor:
> I'm fairly surprised that nobody has brought up Sema's TreeTransform, which is a generic transformation on the Clang AST that allows subclasses to decide how to replace certain nodes with other nodes, and then rebuild the tree around that. It is currently used for template instantiation, rebuilding types for out-of-line definitions of class template members once we know what their semantic scope is, and for replacing "auto" with its deduced type.
>
> Has TreeTransform been deemed inadequate for some reason? Or did people just not know about it?
I didn't know about it. But after a quick look into it I don't know 
whether it actually fits for my tasks.
Firstly, I have a lot of independent transformations (applied 
incrementally), including rather tiny ones (e.g. a new condition for a 
ConditionalOperator). It looks as if I have to rebuild the whole AST 
every time.
Secondly, some transformations aren't limited to a particular 
expression. An example would be

if (a && foo())
{
   // ...
}

where the call to foo gets inlined and thus the expression must be 
transformed to a statement. I'm not sure if and how TreeTransform is 
capable of doing that.


Best regards
Olaf Krzikalla



More information about the cfe-dev mailing list