[cfe-dev] AST transformations

Douglas Gregor dgregor at apple.com
Fri Mar 11 14:28:37 PST 2011


On Mar 11, 2011, at 1:09 PM, Vassil Vassilev wrote:

> On 11.3.2011 г. 18:55, Douglas Gregor wrote:
>> 
>> 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?
>> 
> That is good point! I had have a look 6-7 months ago, but it didn't seem appropriate for my use-case then. Today when I looked at it again, I realized how much it has evolved. I found out that I did a lot of things in the exact same manner as it is done there. Yeah yeah..., I always learn thing in the most difficult way ;) What does "replace certain nodes with other nodes" mean? It is not possible to insert/remove/modify an arbitrary node, is it?

Your subclass could identify the node you want to change, and replace it with a different node. 

> I don't think that TreeTransform.h is public interface. I found it in lib/Sema/

It isn't in the public interface. If it's going to see more general usage, it can be moved into the public interface.

	- Doug



More information about the cfe-dev mailing list