[cfe-dev] newbie question on traversing with recursiveASTVisitor

Craig Silverstein csilvers at google.com
Fri Oct 14 15:59:39 PDT 2011


} Now is there a way to come back to the "=" visit once i have visited
} all its children while using recursiveASTvisitor?

Yes: instead of overloading VisitFoo, overload TraverseFoo.  This
means you'll have to manually call the superclass's TraverseFoo, but
can then do whatever logic you want after that.

The code would look something like this:

  bool TraverseCXXConstructorDecl(clang::CXXConstructorDecl* decl) {
    DoStuffThatTakesPlaceBeforeVisitingChildren();
    if (!Base::TraverseCXXConstructorDecl(decl))  return false;
    DoStuffThatTakesPlaceAfterVisitingChildren();
    return true;
  }

craig



More information about the cfe-dev mailing list