]> granicus.if.org Git - clang/commitdiff
Find references inside blocks.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 29 Jul 2009 23:40:48 +0000 (23:40 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 29 Jul 2009 23:40:48 +0000 (23:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77540 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Index/ASTLocation.cpp
lib/Index/ASTVisitor.h
test/Index/find-refs.c
test/Index/t1.c

index d528c5ac5f9fc2faa5be7e9557e6832462c542e2..f010a2bcc8404f1dc60260066d5a68c1d9bfdbf7 100644 (file)
@@ -103,6 +103,18 @@ Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) {
     return isContainedInStatement(Node, MD->getBody()) ? D : 0;
   }
 
+  if (BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
+    for (DeclContext::decl_iterator
+           I = BD->decls_begin(), E = BD->decls_end(); I != E; ++I) {
+      Decl *Child = FindImmediateParent(*I, Node);
+      if (Child)
+        return Child;
+    }
+
+    assert(BD->getBody() && "BlockDecl without body ?");
+    return isContainedInStatement(Node, BD->getBody()) ? D : 0;
+  }
+
   return 0;
 }
 
index 330bf016d3a468896209c7768ec2a1a143f3bf5e..11089f044dcfe07f671fe03d509214574bf9f830 100644 (file)
@@ -94,6 +94,10 @@ public:
       Visit(*I);
   }
 
+  void VisitBlockExpr(BlockExpr *Node) {
+    Visit(Node->getBlockDecl());
+  }
+
   void VisitStmt(Stmt *Node) {
     for (Stmt::child_iterator
            I = Node->child_begin(), E = Node->child_end(); I != E; ++I)
index 741f840d08172316d3ea7aba0d8ab2e363348b54..8090e67f553554a698515141dd0caf33d488917e 100644 (file)
@@ -2,8 +2,9 @@
 // RUN: clang-cc -emit-pch %S/t2.c -o %t2.ast &&
 
 // RUN: index-test %t1.ast %t2.ast -point-at %S/foo.h:1:14 -print-refs > %t &&
-// RUN: cat %t | count 3 &&
+// RUN: cat %t | count 4 &&
 // RUN: grep 't1.c:4:19,' %t &&
+// RUN: grep 't1.c:28:40,' %t &&
 // RUN: grep 't2.c:6:3,' %t &&
 // RUN: grep 't2.c:7:12,' %t &&
 
index 8b57a58b4522612236fdb471b083c77957a88674..45e04881244dbbfabe80c1618697c3bd6c1d9d5a 100644 (file)
@@ -25,5 +25,7 @@ void field_test(void) {
   ms.field_var = 10;
 }
 
+int (^CP)(int) = ^(int x) { return x * global_var; };
+
 // Suppress 'no run line' failure.
 // RUN: true