From: Douglas Gregor Date: Fri, 22 Oct 2010 22:24:08 +0000 (+0000) Subject: Teach clang_getCursorReferenced() and friends about BlockDeclRefExprs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38f28c1189142429384996409fffbc57f67b5c60;p=clang Teach clang_getCursorReferenced() and friends about BlockDeclRefExprs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117167 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Index/blocks.c b/test/Index/blocks.c index 08241cbcd1..5a31a21255 100644 --- a/test/Index/blocks.c +++ b/test/Index/blocks.c @@ -5,25 +5,31 @@ struct foo { long x; }; void test() { static struct foo _foo; - ^ int_t(struct foo *foo) { return (int_t) foo->x; }(&_foo); + __block i = 0; + ^ int_t(struct foo *foo) { return (int_t) foo->x + i; }(&_foo); } -// TODO: expose the BlockExpr, CastExpr, and UnaryOperatorExpr here - -// CHECK: blocks.c:3:13: TypedefDecl=int_t:3:13 (Definition) Extent=[3:13 - 3:18] -// CHECK: blocks.c:4:8: StructDecl=foo:4:8 (Definition) Extent=[4:1 - 4:23] -// CHECK: blocks.c:4:19: FieldDecl=x:4:19 (Definition) Extent=[4:19 - 4:20] -// CHECK: blocks.c:6:6: FunctionDecl=test:6:6 (Definition) Extent=[6:6 - 9:2] +// CHECK: blocks.c:6:6: FunctionDecl=test:6:6 (Definition) Extent=[6:6 - 10:2] +// CHECK: blocks.c:6:13: UnexposedStmt= Extent=[6:13 - 10:2] +// CHECK: blocks.c:7:3: UnexposedStmt= Extent=[7:3 - 7:26] // CHECK: blocks.c:7:21: VarDecl=_foo:7:21 (Definition) Extent=[7:17 - 7:25] // CHECK: blocks.c:7:17: TypeRef=struct foo:4:8 Extent=[7:17 - 7:20] -// CHECK: blocks.c:8:3: CallExpr= Extent=[8:3 - 8:61] -// CHECK: blocks.c:8:3: UnexposedExpr= Extent=[8:3 - 8:54] -// CHECK: blocks.c:8:5: TypeRef=int_t:3:13 Extent=[8:5 - 8:10] -// CHECK: blocks.c:8:23: ParmDecl=foo:8:23 (Definition) Extent=[8:18 - 8:26] -// CHECK: blocks.c:8:18: TypeRef=struct foo:4:8 Extent=[8:18 - 8:21] -// CHECK: blocks.c:8:37: UnexposedExpr=x:4:19 Extent=[8:37 - 8:51] -// CHECK: blocks.c:8:38: TypeRef=int_t:3:13 Extent=[8:38 - 8:43] -// CHECK: blocks.c:8:50: MemberRefExpr=x:4:19 Extent=[8:45 - 8:51] -// CHECK: blocks.c:8:45: DeclRefExpr=foo:8:23 Extent=[8:45 - 8:48] -// CHECK: blocks.c:8:55: UnexposedExpr= Extent=[8:55 - 8:60] -// CHECK: blocks.c:8:56: DeclRefExpr=_foo:7:21 Extent=[8:56 - 8:60] +// CHECK: blocks.c:8:3: UnexposedStmt= Extent=[8:3 - 8:17] +// CHECK: blocks.c:8:11: VarDecl=i:8:11 (Definition) Extent=[8:11 - 8:16] +// CHECK: blocks.c:8:15: UnexposedExpr= Extent=[8:15 - 8:16] +// CHECK: blocks.c:9:3: CallExpr= Extent=[9:3 - 9:65] +// CHECK: blocks.c:9:3: UnexposedExpr= Extent=[9:3 - 9:58] +// CHECK: blocks.c:9:5: TypeRef=int_t:3:13 Extent=[9:5 - 9:10] +// CHECK: blocks.c:9:23: ParmDecl=foo:9:23 (Definition) Extent=[9:18 - 9:26] +// CHECK: blocks.c:9:18: TypeRef=struct foo:4:8 Extent=[9:18 - 9:21] +// CHECK: blocks.c:9:28: UnexposedStmt= Extent=[9:28 - 9:58] +// CHECK: blocks.c:9:30: UnexposedStmt= Extent=[9:30 - 9:55] +// CHECK: blocks.c:9:37: UnexposedExpr= Extent=[9:37 - 9:55] +// CHECK: blocks.c:9:37: UnexposedExpr=x:4:19 Extent=[9:37 - 9:51] +// CHECK: blocks.c:9:38: TypeRef=int_t:3:13 Extent=[9:38 - 9:43] +// CHECK: blocks.c:9:50: MemberRefExpr=x:4:19 Extent=[9:45 - 9:51] +// CHECK: blocks.c:9:45: DeclRefExpr=foo:9:23 Extent=[9:45 - 9:48] +// CHECK: blocks.c:9:54: DeclRefExpr=i:8:11 Extent=[9:54 - 9:55] +// CHECK: blocks.c:9:59: UnexposedExpr= Extent=[9:59 - 9:64] +// CHECK: blocks.c:9:60: DeclRefExpr=_foo:7:21 Extent=[9:60 - 9:64] + diff --git a/test/Index/load-exprs.c b/test/Index/load-exprs.c index d0033f88ff..01adf62aff 100644 --- a/test/Index/load-exprs.c +++ b/test/Index/load-exprs.c @@ -56,12 +56,12 @@ void test_members(int aval, int bval) { // CHECK: load-exprs.c:11:19: DeclRefExpr=x:10:21 Extent=[11:19 - 11:20] // CHECK: load-exprs.c:12:3: CallExpr= Extent=[12:3 - 19:7] // CHECK: load-exprs.c:13:17: VarDecl=z:13:17 (Definition) Extent=[13:13 - 13:22] -// CHECK: load-exprs.c:14:6: DeclRefExpr= Extent=[14:6 - 14:7] +// CHECK: load-exprs.c:14:6: DeclRefExpr=y:11:15 Extent=[14:6 - 14:7] // CHECK: load-exprs.c:14:13: DeclRefExpr=z:13:17 Extent=[14:13 - 14:14] -// CHECK: load-exprs.c:14:18: DeclRefExpr= Extent=[14:18 - 14:19] +// CHECK: load-exprs.c:14:18: DeclRefExpr=x:10:21 Extent=[14:18 - 14:19] // CHECK: load-exprs.c:15:6: CallExpr= Extent=[15:6 - 18:9] // CHECK: load-exprs.c:16:10: DeclRefExpr=z:13:17 Extent=[16:10 - 16:11] -// CHECK: load-exprs.c:17:10: DeclRefExpr= Extent=[17:10 - 17:11] +// CHECK: load-exprs.c:17:10: DeclRefExpr=y:11:15 Extent=[17:10 - 17:11] // CHECK: load-exprs.c:20:10: DeclRefExpr=y:11:15 Extent=[20:10 - 20:11] // CHECK: load-exprs.c:29:6: FunctionDecl=test_members:29:6 (Definition) // CHECK: load-exprs.c:30:12: VarDecl=y0:30:12 (Definition) Extent=[30:10 - 30:77] diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index b9147fa1a1..c1e40de714 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -2404,6 +2404,8 @@ static Decl *getDeclFromExpr(Stmt *E) { if (DeclRefExpr *RefExpr = dyn_cast(E)) return RefExpr->getDecl(); + if (BlockDeclRefExpr *RefExpr = dyn_cast(E)) + return RefExpr->getDecl(); if (MemberExpr *ME = dyn_cast(E)) return ME->getMemberDecl(); if (ObjCIvarRefExpr *RE = dyn_cast(E)) @@ -2427,6 +2429,8 @@ static SourceLocation getLocationFromExpr(Expr *E) { return /*FIXME:*/Msg->getLeftLoc(); if (DeclRefExpr *DRE = dyn_cast(E)) return DRE->getLocation(); + if (BlockDeclRefExpr *RefExpr = dyn_cast(E)) + return RefExpr->getLocation(); if (MemberExpr *Member = dyn_cast(E)) return Member->getMemberLoc(); if (ObjCIvarRefExpr *Ivar = dyn_cast(E))