]> granicus.if.org Git - clang/commitdiff
For index-test, if the ASTLocation points at a CallExpr, get a Decl out of it.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 14 Jul 2009 03:19:30 +0000 (03:19 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 14 Jul 2009 03:19:30 +0000 (03:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75599 91177308-0d34-0410-b5e6-96231b3b80d8

tools/index-test/index-test.cpp

index b7471a1c9d043054fdc0453cb526a23f6a93d5d2..63c86aac464c88c3b0d48e138d80f11e7c91ba24 100644 (file)
@@ -150,18 +150,27 @@ static void ProcessDecl(Decl *D) {
   }
 }
 
+static Decl *getDeclFromExpr(Stmt *E) {
+  if (DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(E))
+    return RefExpr->getDecl();
+  if (MemberExpr *ME = dyn_cast<MemberExpr>(E))
+    return ME->getMemberDecl();
+  if (CallExpr *CE = dyn_cast<CallExpr>(E))
+    return getDeclFromExpr(CE->getCallee());
+  if (CastExpr *CE = dyn_cast<CastExpr>(E))
+    return getDeclFromExpr(CE->getSubExpr());
+  
+  return 0;
+}
+
 static void ProcessASTLocation(ASTLocation ASTLoc, IndexProvider &IdxProvider) {
   assert(ASTLoc.isValid());
 
   Decl *D = 0;
-  if (ASTLoc.isStmt()) {
-    if (DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(ASTLoc.getStmt()))
-      D = RefExpr->getDecl();
-    else if (MemberExpr *ME = dyn_cast<MemberExpr>(ASTLoc.getStmt()))
-      D = ME->getMemberDecl();
-  } else {
+  if (ASTLoc.isStmt())
+    D = getDeclFromExpr(ASTLoc.getStmt());
+  else
     D = ASTLoc.getDecl();
-  }
   
   if (D == 0) {
     llvm::errs() << "Error: Couldn't get a Decl out of the ASTLocation";