[cfe-dev] AST transformations

Douglas Gregor dgregor at apple.com
Fri Mar 11 08:55:35 PST 2011


On Mar 11, 2011, at 8:47 AM, Olaf Krzikalla wrote:

> Am 11.03.2011 16:00, schrieb Sebastian Redl:
>> Without doubt, AST is a bit of a misnomer for the HLIR component of
>> Clang.
> HLIR? I guess "high level intermediate represantation"? The internet (in 
> terms of google and wikipedia :-) is rather quiet.
> 
>> On the other hand, representing pure syntax leaves so much work
>> to be done, and we would need the annotated tree anyway. At least most
>> of the in-tree components work on the annotated tree and actually
>> require that information.
> I don't argue agains the AST in its current form (beside the naming). 
> And I don't even argue against its immutability, since I fully 
> understand the reasons behind that decision.
> But would a lightweight component (cheap construction from original AST 
> is required) be accepted in the clang universum, which emphasizes on 
> syntax and which e.g. in the rewriter or maybe in the XML printer would 
> replace the AST? It depends on the number of people using clang for 
> source-to-source transformations and similar tasks. Judging from the 
> questions on this list there are a few.

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?

	- Doug



More information about the cfe-dev mailing list