On Apr 23, 2013, at 12:03 PM, Jordan Rose <[email protected]> wrote:
> Sorry, why is this right way to implement this? 'self' is very deliberately > not a special kind of expression in Objective-C. Why not expose this on the > associated ParmVarDecl instead? What is the advantage with that approach ? Whether there is a ParmVarDecl or not seems like an implementation detail of the AST. If you are worried that there is one more cursor to consider, I'd argue the same applies for CXCursor_CXXThisExpr. > > Jordan > > > On Apr 23, 2013, at 10:57 , Argyrios Kyrtzidis <[email protected]> wrote: > >> Author: akirtzidis >> Date: Tue Apr 23 12:57:17 2013 >> New Revision: 180127 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=180127&view=rev >> Log: >> [libclang] Introduce a CXCursor_ObjCSelfExpr cursor, which is the equivalent >> of CXCursor_CXXThisExpr for C++ code. >> >> rdar://13717006 >> >> Modified: >> cfe/trunk/include/clang-c/Index.h >> cfe/trunk/test/Index/annotate-tokens.m >> cfe/trunk/tools/libclang/CIndex.cpp >> cfe/trunk/tools/libclang/CXCursor.cpp >> >> Modified: cfe/trunk/include/clang-c/Index.h >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=180127&r1=180126&r2=180127&view=diff >> ============================================================================== >> --- cfe/trunk/include/clang-c/Index.h (original) >> +++ cfe/trunk/include/clang-c/Index.h Tue Apr 23 12:57:17 2013 >> @@ -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, >> >> Modified: cfe/trunk/test/Index/annotate-tokens.m >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens.m?rev=180127&r1=180126&r2=180127&view=diff >> ============================================================================== >> --- cfe/trunk/test/Index/annotate-tokens.m (original) >> +++ cfe/trunk/test/Index/annotate-tokens.m Tue Apr 23 12:57:17 2013 >> @@ -281,7 +281,7 @@ static Rdar8595462_A * Rdar8595462_stati >> // 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_stati >> // 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_stati >> // 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_stati >> // 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_stati >> // 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 >> >> Modified: cfe/trunk/tools/libclang/CIndex.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=180127&r1=180126&r2=180127&view=diff >> ============================================================================== >> --- cfe/trunk/tools/libclang/CIndex.cpp (original) >> +++ cfe/trunk/tools/libclang/CIndex.cpp Tue Apr 23 12:57:17 2013 >> @@ -3588,6 +3588,8 @@ CXString clang_getCursorKindSpelling(enu >> 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: >> >> Modified: cfe/trunk/tools/libclang/CXCursor.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=180127&r1=180126&r2=180127&view=diff >> ============================================================================== >> --- cfe/trunk/tools/libclang/CXCursor.cpp (original) >> +++ cfe/trunk/tools/libclang/CXCursor.cpp Tue Apr 23 12:57:17 2013 >> @@ -435,7 +435,21 @@ CXCursor cxcursor::MakeCXCursor(const St >> 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: >> >> >> _______________________________________________ >> cfe-commits mailing list >> [email protected] >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
