]> granicus.if.org Git - clang/commitdiff
[libclang] Introduce a CXCursor_ObjCSelfExpr cursor, which is the equivalent of CXCur...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 23 Apr 2013 17:57:17 +0000 (17:57 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 23 Apr 2013 17:57:17 +0000 (17:57 +0000)
rdar://13717006

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180127 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
test/Index/annotate-tokens.m
tools/libclang/CIndex.cpp
tools/libclang/CXCursor.cpp

index 0c9dcbe25dc87e5fefe694db4593eb85b1c0bbfe..37072a765824427fc22937aa9aa0d5a7f3757be7 100644 (file)
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 18
+#define CINDEX_VERSION_MINOR 19
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
       ((major) * 10000)                       \
@@ -1903,7 +1903,11 @@ enum CXCursorKind {
    */
   CXCursor_ObjCBoolLiteralExpr           = 145,
 
-  CXCursor_LastExpr                      = CXCursor_ObjCBoolLiteralExpr,
+  /** \brief Represents the "self" expression in a ObjC method.
+   */
+  CXCursor_ObjCSelfExpr                  = 146,
+
+  CXCursor_LastExpr                      = CXCursor_ObjCSelfExpr,
 
   /* Statements */
   CXCursor_FirstStmt                     = 200,
index 7e888e394cbd8c7feb6614f2045d944b928a8f81..40c66a18b8f0231e87e6f667c630f23d548eb294 100644 (file)
@@ -281,7 +281,7 @@ static Rdar8595462_A * Rdar8595462_staticVar;
 // CHECK: Punctuation: ")" [40:19 - 40:20] CallExpr=ibaction_test:36:12
 // CHECK: Punctuation: ";" [40:20 - 40:21] CompoundStmt=
 // CHECK: Punctuation: "[" [41:5 - 41:6] ObjCMessageExpr=foo::34:9
-// CHECK: Identifier: "self" [41:6 - 41:10] DeclRefExpr=self:0:0
+// CHECK: Identifier: "self" [41:6 - 41:10] ObjCSelfExpr=self:0:0
 // CHECK: Identifier: "foo" [41:11 - 41:14] ObjCMessageExpr=foo::34:9
 // CHECK: Punctuation: ":" [41:14 - 41:15] ObjCMessageExpr=foo::34:9
 // CHECK: Literal: "0" [41:15 - 41:16] IntegerLiteral=
@@ -391,7 +391,7 @@ static Rdar8595462_A * Rdar8595462_staticVar;
 // CHECK: Identifier: "local" [76:9 - 76:14] VarDecl=local:76:9 (Definition)
 // CHECK: Punctuation: "=" [76:15 - 76:16] VarDecl=local:76:9 (Definition)
 // CHECK: Punctuation: "[" [76:17 - 76:18] ObjCMessageExpr=foo::66:9
-// CHECK: Identifier: "self" [76:18 - 76:22] DeclRefExpr=self:0:0
+// CHECK: Identifier: "self" [76:18 - 76:22] ObjCSelfExpr=self:0:0
 // CHECK: Identifier: "foo" [76:23 - 76:26] ObjCMessageExpr=foo::66:9
 // CHECK: Punctuation: ":" [76:26 - 76:27] ObjCMessageExpr=foo::66:9
 // CHECK: Identifier: "VAL" [76:27 - 76:30] macro expansion=VAL:63:9
@@ -401,7 +401,7 @@ static Rdar8595462_A * Rdar8595462_staticVar;
 // CHECK: Identifier: "second" [77:9 - 77:15] VarDecl=second:77:9 (Definition)
 // CHECK: Punctuation: "=" [77:16 - 77:17] VarDecl=second:77:9 (Definition)
 // CHECK: Punctuation: "[" [77:18 - 77:19] ObjCMessageExpr=foo::66:9
-// CHECK: Identifier: "self" [77:19 - 77:23] DeclRefExpr=self:0:0
+// CHECK: Identifier: "self" [77:19 - 77:23] ObjCSelfExpr=self:0:0
 // CHECK: Identifier: "foo" [77:24 - 77:27] ObjCMessageExpr=foo::66:9
 // CHECK: Punctuation: ":" [77:27 - 77:28] ObjCMessageExpr=foo::66:9
 // CHECK: Literal: "0" [77:28 - 77:29] IntegerLiteral=
@@ -518,7 +518,7 @@ static Rdar8595462_A * Rdar8595462_staticVar;
 // CHECK-INSIDE_BLOCK: Identifier: "result" [127:9 - 127:15] VarDecl=result:127:9 (Definition)
 // CHECK-INSIDE_BLOCK: Punctuation: "=" [127:16 - 127:17] VarDecl=result:127:9 (Definition)
 // CHECK-INSIDE_BLOCK: Punctuation: "[" [127:18 - 127:19] ObjCMessageExpr=blah::124:8
-// CHECK-INSIDE_BLOCK: Identifier: "self" [127:19 - 127:23] DeclRefExpr=self:0:0
+// CHECK-INSIDE_BLOCK: Identifier: "self" [127:19 - 127:23] ObjCSelfExpr=self:0:0
 // CHECK-INSIDE_BLOCK: Identifier: "blah" [127:24 - 127:28] ObjCMessageExpr=blah::124:8
 // CHECK-INSIDE_BLOCK: Punctuation: ":" [127:28 - 127:29] ObjCMessageExpr=blah::124:8
 // CHECK-INSIDE_BLOCK: Literal: "5" [127:29 - 127:30] IntegerLiteral=
@@ -530,7 +530,7 @@ static Rdar8595462_A * Rdar8595462_staticVar;
 // CHECK-INSIDE_BLOCK: Punctuation: "*" [128:17 - 128:18] VarDecl=a:128:18 (Definition)
 // CHECK-INSIDE_BLOCK: Identifier: "a" [128:18 - 128:19] VarDecl=a:128:18 (Definition)
 // CHECK-INSIDE_BLOCK: Punctuation: "=" [128:20 - 128:21] VarDecl=a:128:18 (Definition)
-// CHECK-INSIDE_BLOCK: Identifier: "self" [128:22 - 128:26] DeclRefExpr=self:0:0
+// CHECK-INSIDE_BLOCK: Identifier: "self" [128:22 - 128:26] ObjCSelfExpr=self:0:0
 
 // RUN: c-index-test -test-annotate-tokens=%s:134:1:138:1 %s -DIBOutlet='__attribute__((iboutlet))' -DIBAction='void)__attribute__((ibaction)' | FileCheck -check-prefix=CHECK-PROP-AFTER-METHOD %s
 // CHECK-PROP-AFTER-METHOD: Punctuation: "@" [134:1 - 134:2] ObjCInterfaceDecl=Rdar8062781:134:12
index d29e3d86087ebb1b05c65c415c6cef43f3bfcccb..0a8a06899833f34cb2acb1e6d5c595d8f0e6524b 100644 (file)
@@ -3588,6 +3588,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
       return cxstring::createRef("ObjCStringLiteral");
   case CXCursor_ObjCBoolLiteralExpr:
       return cxstring::createRef("ObjCBoolLiteralExpr");
+  case CXCursor_ObjCSelfExpr:
+      return cxstring::createRef("ObjCSelfExpr");
   case CXCursor_ObjCEncodeExpr:
       return cxstring::createRef("ObjCEncodeExpr");
   case CXCursor_ObjCSelectorExpr:
index e490b5da3ddda3a0cbaa8e842614fd1223e70491..b5682055b9e3851c7af918e2eae6e62c081575ad 100644 (file)
@@ -435,7 +435,21 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
     K = CXCursor_SizeOfPackExpr;
     break;
 
-  case Stmt::DeclRefExprClass:           
+  case Stmt::DeclRefExprClass:
+    if (const ImplicitParamDecl *IPD =
+         dyn_cast_or_null<ImplicitParamDecl>(cast<DeclRefExpr>(S)->getDecl())) {
+      if (const ObjCMethodDecl *MD =
+            dyn_cast<ObjCMethodDecl>(IPD->getDeclContext())) {
+        if (MD->getSelfDecl() == IPD) {
+          K = CXCursor_ObjCSelfExpr;
+          break;
+        }
+      }
+    }
+
+    K = CXCursor_DeclRefExpr;
+    break;
+
   case Stmt::DependentScopeDeclRefExprClass:
   case Stmt::SubstNonTypeTemplateParmExprClass:
   case Stmt::SubstNonTypeTemplateParmPackExprClass: