[cfe-dev] Detect multiple RecursiveASTVisitor visits

s0rcy siddarth13+clangcfe at gmail.com
Tue Mar 4 08:28:56 PST 2014


I have a RecursiveASTVisitor running over sample code
===
- (int)thisIsACool:(NSString *)str func:(id)wut{
           return 1;
}
===

And a visitor

===
   virtual bool VisitObjCMethodDecl(ObjCMethodDecl *mdecl) {
        if("thisIsACool:func:" == mdecl->getNameAsString())
            rewriteMethod(mdecl);
        return true;
    }
===
    virtual bool HandleTopLevelDecl(DeclGroupRef DG) {
        for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e;
i++) {
            Decl *D = *i;
            visitor->TraverseDecl(D);
        }  
        return true;
    }
===

The same node is encountered twice while walking the tree, and I end up
overwriting the rewritten function.  Why does the node get visited twice? Is
there a way to detect previously visited or rewritten nodes?





--
View this message in context: http://clang-developers.42468.n3.nabble.com/Detect-multiple-RecursiveASTVisitor-visits-tp4038262.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list