r262206 - [AST/RecursiveASTVisitor] Correction so that dataTraverseStmtPost will get called after the statement has been visited.
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 28 23:55:56 PST 2016
Author: akirtzidis
Date: Mon Feb 29 01:55:55 2016
New Revision: 262206
URL: http://llvm.org/viewvc/llvm-project?rev=262206&view=rev
Log:
[AST/RecursiveASTVisitor] Correction so that dataTraverseStmtPost will get called after the statement has been visited.
Fixes the indexing client of this.
Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/test/Index/Core/index-source.m
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=262206&r1=262205&r2=262206&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon Feb 29 01:55:55 2016
@@ -139,7 +139,9 @@ public:
/// Parameters involving this type are used to implement data
/// recursion over Stmts and Exprs within this class, and should
/// typically not be explicitly specified by derived classes.
- typedef SmallVectorImpl<Stmt *> DataRecursionQueue;
+ /// The bool bit indicates whether the statement has been traversed or not.
+ typedef SmallVectorImpl<llvm::PointerIntPair<Stmt *, 1, bool>>
+ DataRecursionQueue;
/// \brief Return a reference to the derived class.
Derived &getDerived() { return *static_cast<Derived *>(this); }
@@ -561,23 +563,32 @@ bool RecursiveASTVisitor<Derived>::Trave
return true;
if (Queue) {
- Queue->push_back(S);
+ Queue->push_back({S, false});
return true;
}
- SmallVector<Stmt *, 8> LocalQueue;
- LocalQueue.push_back(S);
+ SmallVector<llvm::PointerIntPair<Stmt *, 1, bool>, 8> LocalQueue;
+ LocalQueue.push_back({S, false});
while (!LocalQueue.empty()) {
- Stmt *CurrS = LocalQueue.pop_back_val();
+ auto &CurrSAndVisited = LocalQueue.back();
+ Stmt *CurrS = CurrSAndVisited.getPointer();
+ bool Visited = CurrSAndVisited.getInt();
+ if (Visited) {
+ LocalQueue.pop_back();
+ TRY_TO(dataTraverseStmtPost(CurrS));
+ continue;
+ }
- size_t N = LocalQueue.size();
if (getDerived().dataTraverseStmtPre(CurrS)) {
+ CurrSAndVisited.setInt(true);
+ size_t N = LocalQueue.size();
TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
- TRY_TO(dataTraverseStmtPost(CurrS));
+ // Process new children in the order they were added.
+ std::reverse(LocalQueue.begin() + N, LocalQueue.end());
+ } else {
+ LocalQueue.pop_back();
}
- // Process new children in the order they were added.
- std::reverse(LocalQueue.begin() + N, LocalQueue.end());
}
return true;
Modified: cfe/trunk/test/Index/Core/index-source.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.m?rev=262206&r1=262205&r2=262206&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/index-source.m (original)
+++ cfe/trunk/test/Index/Core/index-source.m Mon Feb 29 01:55:55 2016
@@ -6,3 +6,13 @@
// CHECK: [[@LINE-1]]:1 | objc-instance-method/ObjC | meth | c:objc(cs)Base(im)meth | -[Base meth] | Decl,Dyn,RelChild | rel: 1
// CHECK-NEXT: RelChild | Base | c:objc(cs)Base
@end
+
+void foo();
+// CHECK: [[@LINE+1]]:6 | function/C | goo | c:@F at goo | _goo | Def | rel: 0
+void goo(Base *b) {
+ // CHECK: [[@LINE+1]]:3 | function/C | foo | c:@F at foo | _foo | Ref,Call | rel: 0
+ foo();
+ // CHECK: [[@LINE+2]]:6 | objc-instance-method/ObjC | meth | c:objc(cs)Base(im)meth | -[Base meth] | Ref,Call,Dyn,RelRec | rel: 1
+ // CHECK-NEXT: RelRec | Base | c:objc(cs)Base
+ [b meth];
+}
More information about the cfe-commits
mailing list