Visit the condition variables of while and for loops; also, visit the
condition even when we've visited the condition variable, so that
we'll see implicit conversions there.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94423 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index 4436709..c9c6c25 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -292,6 +292,8 @@
// FIXME: LabelStmt label?
bool VisitIfStmt(IfStmt *S);
bool VisitSwitchStmt(SwitchStmt *S);
+ bool VisitWhileStmt(WhileStmt *S);
+ bool VisitForStmt(ForStmt *S);
// Expression visitors
bool VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
@@ -793,7 +795,7 @@
bool CursorVisitor::VisitDeclStmt(DeclStmt *S) {
for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
D != DEnd; ++D) {
- if (Visit(MakeCXCursor(*D, TU)))
+ if (*D && Visit(MakeCXCursor(*D, TU)))
return true;
}
@@ -804,12 +806,12 @@
if (VarDecl *Var = S->getConditionVariable()) {
if (Visit(MakeCXCursor(Var, TU)))
return true;
- } else if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU)))
- return true;
+ }
+ if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU)))
+ return true;
if (S->getThen() && Visit(MakeCXCursor(S->getThen(), StmtParent, TU)))
return true;
-
if (S->getElse() && Visit(MakeCXCursor(S->getElse(), StmtParent, TU)))
return true;
@@ -820,9 +822,42 @@
if (VarDecl *Var = S->getConditionVariable()) {
if (Visit(MakeCXCursor(Var, TU)))
return true;
- } else if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU)))
+ }
+
+ if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU)))
+ return true;
+ if (S->getBody() && Visit(MakeCXCursor(S->getBody(), StmtParent, TU)))
+ return true;
+
+ return false;
+}
+
+bool CursorVisitor::VisitWhileStmt(WhileStmt *S) {
+ if (VarDecl *Var = S->getConditionVariable()) {
+ if (Visit(MakeCXCursor(Var, TU)))
+ return true;
+ }
+
+ if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU)))
+ return true;
+ if (S->getBody() && Visit(MakeCXCursor(S->getBody(), StmtParent, TU)))
return true;
+ return false;
+}
+
+bool CursorVisitor::VisitForStmt(ForStmt *S) {
+ if (S->getInit() && Visit(MakeCXCursor(S->getInit(), StmtParent, TU)))
+ return true;
+ if (VarDecl *Var = S->getConditionVariable()) {
+ if (Visit(MakeCXCursor(Var, TU)))
+ return true;
+ }
+
+ if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU)))
+ return true;
+ if (S->getInc() && Visit(MakeCXCursor(S->getInc(), StmtParent, TU)))
+ return true;
if (S->getBody() && Visit(MakeCXCursor(S->getBody(), StmtParent, TU)))
return true;