[cfe-dev] Back-navigation of the Syntax Tree!

Sebastian Redl sebastian.redl at getdesigned.at
Thu Jan 29 08:10:00 PST 2009


Simone Pellegrini wrote:
> Practically, what I need is the possibility from a statement to access 
> to the PARENT! I know that I can manually save a reference to the parent 
> node before entering into a node and that will solve my problem but it 
> is ugly! :) Is this possible with the current API to access the parent 
> of a node? I searched a lot and there is no way to get this information.
>   
Your search result is correct. AST nodes do not save their parents, so
there is no way of getting the parent of a node save by iterating the
tree and looking.

The reason is that we try to keep the AST nodes as small as possible,
and an additional pointer in every node that is not needed by the most
common use cases (code generation, analysis, and the rewriter - the
users in the Clang repository) makes a very big difference.

Sebastian



More information about the cfe-dev mailing list