[cfe-dev] RE : AST Transformation

Argyrios Kyrtzidis kyrtzidis at apple.com
Mon Apr 4 09:27:01 PDT 2011


On Apr 4, 2011, at 9:15 AM, David Chisnall wrote:

> On 31 Mar 2011, at 16:35, Nico Weber wrote:
> 
>> The AST is designed to be immutable after construction, so "it's
>> impossible to transform AST".
> 
> Note that this doesn't mean that you can't walk the AST and then construct a new AST that is based on the old one but in some way different.  
> 
> A good project for someone interested in AST transforms would be a subclass of RecursiveASTVisitor that generated a copy of the AST by walking each node in turn and adding an equivalent node to a new AST.  Users could then subclass this and use it to generate a new AST that differed from the original in only the specific ways that they desired.  

I think this is basically the functionality of TreeTransform, any effort should be directed at improving that one IMO.

> 
> This would have the same effect as modifying an AST (albeit with a higher memory overhead), but would not impact any of the AST consumers that expect the AST to be immutable (i.e. all of the ones that currently exist, including CodeGen).
> 
> David
> 
> --
> This email complies with ISO 3103
> _______________________________________________
> 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