[cfe-commits] r115346 - in /cfe/trunk: test/Index/annotate-tokens.m tools/libclang/CIndex.cpp

Douglas Gregor dgregor at apple.com
Fri Oct 1 14:11:22 PDT 2010


Author: dgregor
Date: Fri Oct  1 16:11:22 2010
New Revision: 115346

URL: http://llvm.org/viewvc/llvm-project?rev=115346&view=rev
Log:
Teach clang_getCursorReferenced() about Objective-C property reference
and protocol expressions. Fixes <rdar://problem/7833565>.

Modified:
    cfe/trunk/test/Index/annotate-tokens.m
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/test/Index/annotate-tokens.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens.m?rev=115346&r1=115345&r2=115346&view=diff
==============================================================================
--- cfe/trunk/test/Index/annotate-tokens.m (original)
+++ cfe/trunk/test/Index/annotate-tokens.m Fri Oct  1 16:11:22 2010
@@ -77,9 +77,18 @@
     int second = [self foo:0];
     return local;
 }
+- (int)othermethod:(IBOutletTests *)ibt {
+  return *ibt.aPropOutlet;
+}
 @end
 
-// RUN: c-index-test -test-annotate-tokens=%s:1:1:80:4 %s -DIBOutlet='__attribute__((iboutlet))' -DIBAction='void)__attribute__((ibaction)' | FileCheck %s
+ at protocol Proto @end
+
+void f() {
+  (void)@protocol(Proto);
+}
+
+// RUN: c-index-test -test-annotate-tokens=%s:1:1:89:2 %s -DIBOutlet='__attribute__((iboutlet))' -DIBAction='void)__attribute__((ibaction)' | FileCheck %s
 // CHECK: Punctuation: "@" [1:1 - 1:2] ObjCInterfaceDecl=Foo:1:12
 // CHECK: Keyword: "interface" [1:2 - 1:11] ObjCInterfaceDecl=Foo:1:12
 // CHECK: Identifier: "Foo" [1:12 - 1:15] ObjCInterfaceDecl=Foo:1:12
@@ -347,5 +356,44 @@
 // CHECK: Identifier: "local" [78:12 - 78:17] DeclRefExpr=local:76:9
 // CHECK: Punctuation: ";" [78:17 - 78:18] UnexposedStmt=
 // CHECK: Punctuation: "}" [79:1 - 79:2] UnexposedStmt=
-// CHECK: Punctuation: "@" [80:1 - 80:2] ObjCImplementationDecl=R7974151:70:1 (Definition)
-// CHECK: Keyword: "end" [80:2 - 80:5]
+// CHECK: Punctuation: "-" [80:1 - 80:2] ObjCInstanceMethodDecl=othermethod::80:1 (Definition)
+// CHECK: Punctuation: "(" [80:3 - 80:4] ObjCInstanceMethodDecl=othermethod::80:1 (Definition)
+// CHECK: Keyword: "int" [80:4 - 80:7] ObjCInstanceMethodDecl=othermethod::80:1 (Definition)
+// CHECK: Punctuation: ")" [80:7 - 80:8] ObjCInstanceMethodDecl=othermethod::80:1 (Definition)
+// CHECK: Identifier: "othermethod" [80:8 - 80:19] ObjCInstanceMethodDecl=othermethod::80:1 (Definition)
+// CHECK: Punctuation: ":" [80:19 - 80:20] ObjCInstanceMethodDecl=othermethod::80:1 (Definition)
+// CHECK: Punctuation: "(" [80:20 - 80:21] ObjCInstanceMethodDecl=othermethod::80:1 (Definition)
+// CHECK: Identifier: "IBOutletTests" [80:21 - 80:34] ObjCClassRef=IBOutletTests:51:12
+// CHECK: Punctuation: "*" [80:35 - 80:36] ParmDecl=ibt:80:37 (Definition)
+// CHECK: Punctuation: ")" [80:36 - 80:37] ParmDecl=ibt:80:37 (Definition)
+// CHECK: Identifier: "ibt" [80:37 - 80:40] ParmDecl=ibt:80:37 (Definition)
+// CHECK: Punctuation: "{" [80:41 - 80:42] UnexposedStmt=
+// CHECK: Keyword: "return" [81:3 - 81:9] UnexposedStmt=
+// CHECK: Punctuation: "*" [81:10 - 81:11] UnexposedExpr=
+// CHECK: Identifier: "ibt" [81:11 - 81:14] DeclRefExpr=ibt:80:37
+// CHECK: Punctuation: "." [81:14 - 81:15] MemberRefExpr=aPropOutlet:56:26
+// CHECK: Identifier: "aPropOutlet" [81:15 - 81:26] MemberRefExpr=aPropOutlet:56:26
+// CHECK: Punctuation: ";" [81:26 - 81:27] UnexposedStmt=
+// CHECK: Punctuation: "}" [82:1 - 82:2] UnexposedStmt=
+// CHECK: Punctuation: "@" [83:1 - 83:2] ObjCImplementationDecl=R7974151:70:1 (Definition)
+// CHECK: Keyword: "end" [83:2 - 83:5]
+// CHECK: Punctuation: "@" [85:1 - 85:2] ObjCProtocolDecl=Proto:85:1 (Definition)
+// CHECK: Keyword: "protocol" [85:2 - 85:10] ObjCProtocolDecl=Proto:85:1 (Definition)
+// CHECK: Identifier: "Proto" [85:11 - 85:16] ObjCProtocolDecl=Proto:85:1 (Definition)
+// CHECK: Punctuation: "@" [85:17 - 85:18] ObjCProtocolDecl=Proto:85:1 (Definition)
+// CHECK: Keyword: "end" [85:18 - 85:21] ObjCProtocolDecl=Proto:85:1 (Definition)
+// CHECK: Keyword: "void" [87:1 - 87:5] FunctionDecl=f:87:6 (Definition)
+// CHECK: Identifier: "f" [87:6 - 87:7] FunctionDecl=f:87:6 (Definition)
+// CHECK: Punctuation: "(" [87:7 - 87:8] FunctionDecl=f:87:6 (Definition)
+// CHECK: Punctuation: ")" [87:8 - 87:9] FunctionDecl=f:87:6 (Definition)
+// CHECK: Punctuation: "{" [87:10 - 87:11] UnexposedStmt=
+// CHECK: Punctuation: "(" [88:3 - 88:4] UnexposedExpr=Proto:85:1
+// CHECK: Keyword: "void" [88:4 - 88:8] UnexposedExpr=Proto:85:1
+// CHECK: Punctuation: ")" [88:8 - 88:9] UnexposedExpr=Proto:85:1
+// CHECK: Punctuation: "@" [88:9 - 88:10] UnexposedExpr=Proto:85:1
+// CHECK: Keyword: "protocol" [88:10 - 88:18] UnexposedExpr=Proto:85:1
+// CHECK: Punctuation: "(" [88:18 - 88:19] UnexposedExpr=Proto:85:1
+// CHECK: Identifier: "Proto" [88:19 - 88:24] UnexposedExpr=Proto:85:1
+// CHECK: Punctuation: ")" [88:24 - 88:25] UnexposedExpr=Proto:85:1
+// CHECK: Punctuation: ";" [88:25 - 88:26] UnexposedStmt=
+// CHECK: Punctuation: "}" [89:1 - 89:2] UnexposedStmt=

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=115346&r1=115345&r2=115346&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Fri Oct  1 16:11:22 2010
@@ -2518,20 +2518,26 @@
 //===----------------------------------------------------------------------===//
 
 static Decl *getDeclFromExpr(Stmt *E) {
+  if (CastExpr *CE = dyn_cast<CastExpr>(E))
+    return getDeclFromExpr(CE->getSubExpr());
+
   if (DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(E))
     return RefExpr->getDecl();
   if (MemberExpr *ME = dyn_cast<MemberExpr>(E))
     return ME->getMemberDecl();
   if (ObjCIvarRefExpr *RE = dyn_cast<ObjCIvarRefExpr>(E))
     return RE->getDecl();
-
+  if (ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(E))
+    return PRE->getProperty();
+      
   if (CallExpr *CE = dyn_cast<CallExpr>(E))
     return getDeclFromExpr(CE->getCallee());
-  if (CastExpr *CE = dyn_cast<CastExpr>(E))
-    return getDeclFromExpr(CE->getSubExpr());
   if (ObjCMessageExpr *OME = dyn_cast<ObjCMessageExpr>(E))
     return OME->getMethodDecl();
 
+  if (ObjCProtocolExpr *PE = dyn_cast<ObjCProtocolExpr>(E))
+    return PE->getProtocol();
+  
   return 0;
 }
 





More information about the cfe-commits mailing list