Find references inside blocks.

llvm-svn: 77540
This commit is contained in:
Argyrios Kyrtzidis 2009-07-29 23:40:48 +00:00
parent c3deb79049
commit 34be01b9f4
4 changed files with 20 additions and 1 deletions

View 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;
}

View 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)

View 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 &&

View 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