From c2233beba431f3ab3f97597ddadee88896ad80f4 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 23 Apr 2013 17:57:17 +0000 Subject: [PATCH] [libclang] Introduce a CXCursor_ObjCSelfExpr cursor, which is the equivalent of CXCursor_CXXThisExpr for C++ code. rdar://13717006 llvm-svn: 180127 --- clang/include/clang-c/Index.h | 8 ++++++-- clang/test/Index/annotate-tokens.m | 10 +++++----- clang/tools/libclang/CIndex.cpp | 2 ++ clang/tools/libclang/CXCursor.cpp | 16 +++++++++++++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 0c9dcbe25dc8..37072a765824 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -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, diff --git a/clang/test/Index/annotate-tokens.m b/clang/test/Index/annotate-tokens.m index 7e888e394cbd..40c66a18b8f0 100644 --- a/clang/test/Index/annotate-tokens.m +++ b/clang/test/Index/annotate-tokens.m @@ -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 diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index d29e3d86087e..0a8a06899833 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -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: diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp index e490b5da3ddd..b5682055b9e3 100644 --- a/clang/tools/libclang/CXCursor.cpp +++ b/clang/tools/libclang/CXCursor.cpp @@ -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(cast(S)->getDecl())) { + if (const ObjCMethodDecl *MD = + dyn_cast(IPD->getDeclContext())) { + if (MD->getSelfDecl() == IPD) { + K = CXCursor_ObjCSelfExpr; + break; + } + } + } + + K = CXCursor_DeclRefExpr; + break; + case Stmt::DependentScopeDeclRefExprClass: case Stmt::SubstNonTypeTemplateParmExprClass: case Stmt::SubstNonTypeTemplateParmPackExprClass: