[cfe-dev] Cloning Clang Stmts, declarations and other AST objects

Douglas Gregor dgregor at apple.com
Tue May 12 12:51:47 PDT 2009


On May 12, 2009, at 11:59 AM, moataz ragab wrote:

> Hi Doug,
>
> Thanks. I have another question:
>
> Assuming that somehow I implemented the cloning. What would be the  
> proper way to add new nodes to the AST?
>
> I think there are two ways for adding new nodes to the AST:
>   1.Appending children nodes
>   2.Inserting nodes in arbitrary order not necessary at the end
>
> I took a look at how the parser builds the AST of compound  
> statements specially and it seems that the parser pushes back the  
> statements on a vector. Then it calls the acton method from Sema to  
> create the objects.

Most expressions and statements are either allocated with new  
(ASTContext) or have static Create methods. Expressions and statements  
are generally meant to be immutable once created, so for your  
application you might want to implement some kind of recursive walk  
over the statements that builds the clone with the modifications in- 
place.

   - Doug





More information about the cfe-dev mailing list