From: Argyrios Kyrtzidis Date: Wed, 29 Jul 2009 23:40:48 +0000 (+0000) Subject: Find references inside blocks. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad6e5d12d0ec3a49157e7794ddc1baa575ca008b;p=clang Find references inside blocks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77540 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Index/ASTLocation.cpp b/lib/Index/ASTLocation.cpp index d528c5ac5f..f010a2bcc8 100644 --- a/lib/Index/ASTLocation.cpp +++ b/lib/Index/ASTLocation.cpp @@ -103,6 +103,18 @@ Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) { return isContainedInStatement(Node, MD->getBody()) ? D : 0; } + if (BlockDecl *BD = dyn_cast(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; } diff --git a/lib/Index/ASTVisitor.h b/lib/Index/ASTVisitor.h index 330bf016d3..11089f044d 100644 --- a/lib/Index/ASTVisitor.h +++ b/lib/Index/ASTVisitor.h @@ -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) diff --git a/test/Index/find-refs.c b/test/Index/find-refs.c index 741f840d08..8090e67f55 100644 --- a/test/Index/find-refs.c +++ b/test/Index/find-refs.c @@ -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 && diff --git a/test/Index/t1.c b/test/Index/t1.c index 8b57a58b45..45e0488124 100644 --- a/test/Index/t1.c +++ b/test/Index/t1.c @@ -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