[cfe-dev] Parent of an AST node?
Ted Kremenek
kremenek at apple.com
Sat Aug 2 10:38:14 PDT 2008
On Aug 1, 2008, at 11:43 AM, Nico Weber wrote:
> Hi Ted,
>
> On 01.08.2008, at 01:25, Ted Kremenek wrote:
>
>> 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);
>
> thanks, that class contains nearly exactly the code I wrote myself :-)
>
> Unrelated: Is there "the" root of the AST? As far as I understand,
> there's only a forrest of ASTs, with TranslationUnit storing their
> roots (TranslationUnitDecl has a FIXME that this might change in the
> future).
>
> Nico
Hi Nico,
There is no root statement (Stmt*) since at the top-level there are
only declarations (Decl*). You could consider TranslationUnit to be
the root (which contains references to all the top-level declarations).
Ted
More information about the cfe-dev
mailing list