0

There seems to be no examples online, according to the documentation Path, ParentMap's constructor accepts "Stmt *ASTRoot", which may means that later the ParentMap instance will find parents under the AST subtree under "ASTRoot". But how to get the root node of a translation unit? I tried

virtual bool VisitTranslationUnitDecl(TranslationUnitDecl *decl) {
    //decl->dump();
    Stmt *stmt = decl->getBody();
    mParentMap = new ParentMap(stmt);
    return true;
}

The goal is to create a ParentMap around the root nood then use it in other Visit*** callbacks during the scan process. But decl->getBody() is null. decl->dump() will print everything, and even scan the AST for the second time decl->getBody() is still null.

How to get the root Stmt of an AST? What is the right/better way to use ParentMap?

Kondal
  • 2,870
  • 5
  • 26
  • 40
jw_
  • 1,663
  • 18
  • 32

1 Answers1

1

ParentMap is not really intended to be used on its own. You can use ASTContext::getParents, which constructs and maintains ParentMap.

Valeriy Savchenko
  • 1,524
  • 8
  • 19