AST transformations


for a project of mine I need to do a lot of AST transformations
(inserting new nodes and changing existing ones), thus using the
Rewriter for this task seems not suitable to me because after each
transformation step I would need to rebuild the whole AST.

Transformation of ASTs seems not to be trivial because AST nodes are not
changeable and recreating all nodes from scratch is not practical. I'm
curious why it is not possible to change AST nodes, is there any
specific reason? Or isn't it just done yet because there is no interest
in that right now?

I would also be glad about other suggestions to get my job done.


I'm not sure what you mean here. The ObjC rewriter does certainly replace subexpressions and rebuilds the AST as it goes. For a simple example, see how it handles the @encode (ObjCEncodeExpr) expression. The objc rewriter also correctly handles recursively nested expressions. See test/Rewriter/objc-ivar-receiver-1.m for an example.


Elsa has is commonly used for that task. See

At Mozilla we maintain a fork of elsa with some bugfixes and additional features for coping with newer C++ features.


Stephan Creutz wrote: