[cfe-dev] Parent of an AST node?

Ted Kremenek kremenek at apple.com
Thu Jul 31 16:25:00 PDT 2008


Hi Nico,

Check out the ParentMap class in libAST.  It represents a map from  
Stmt* -> Stmt* (children to parents).  To construct it, you just  
provide the root of the AST:

   ParentMap PM(root);

To query for a parent:

   Stmt* parent = PM.getParent(child);

The parent map will only contain the backmapping from children to  
parents that are descendants of the root AST node that you specified  
when you constructed the parent map.

Ted

On Jul 31, 2008, at 3:44 PM, Nico Weber wrote:

> Hi,
>
> how can I get the parent of an AST node?
>
> I have a DeclRefExpr object and would like the name of the function
> it's contained in. Does clang offer this functionality or do I have to
> keep track of parents myself?
>
> Thanks,
> Nico
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list