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

Douglas Gregor dgregor at apple.com
Tue Jun 28 14:09:19 PDT 2011


On Jun 27, 2011, at 1:39 PM, Argyrios Kyrtzidis wrote:

> On Jun 27, 2011, at 12:48 PM, Douglas Gregor wrote:
> 
>> 
>> On Jun 27, 2011, at 12:42 PM, Argyrios Kyrtzidis wrote:
>> 
>>> Author: akirtzidis
>>> Date: Mon Jun 27 14:42:20 2011
>>> New Revision: 133929
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=133929&view=rev
>>> Log:
>>> [libclang] Avoid having the cursor of an expression "overwrite" the annotation of the
>>> variable declaration that it belongs to.
>>> 
>>> This can happen for C++ constructor expressions whose range generally
>>> include the variable declaration, e.g.:
>>> 
>>> MyCXXClass foo; // Make sure we don't annotate 'foo' as a CallExpr cursor.
>>> 
>>> rdar://9124499.
>>> 
>>> Modified:
>>>   cfe/trunk/test/Index/annotate-tokens.cpp
>>>   cfe/trunk/tools/libclang/CIndex.cpp
>>> 
>>> Modified: cfe/trunk/test/Index/annotate-tokens.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens.cpp?rev=133929&r1=133928&r2=133929&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/test/Index/annotate-tokens.cpp (original)
>>> +++ cfe/trunk/test/Index/annotate-tokens.cpp Mon Jun 27 14:42:20 2011
>>> @@ -17,9 +17,10 @@
>>> struct S2 { S1 *operator->(); };
>>> void test3(S2 s2) {
>>>  s2->f();
>>> +  X foo;
>>> }
>>> 
>>> -// RUN: c-index-test -test-annotate-tokens=%s:1:1:20:1 %s | FileCheck %s
>>> +// RUN: c-index-test -test-annotate-tokens=%s:1:1:21:1 %s | FileCheck %s
>>> // CHECK: Keyword: "struct" [1:1 - 1:7] StructDecl=bonk:1:8 (Definition)
>>> // CHECK: Identifier: "bonk" [1:8 - 1:12] StructDecl=bonk:1:8 (Definition)
>>> // CHECK: Punctuation: "{" [1:13 - 1:14] StructDecl=bonk:1:8 (Definition)
>>> @@ -115,4 +116,7 @@
>>> // CHECK: Punctuation: "(" [19:8 - 19:9] CallExpr=f:16:18
>>> // CHECK: Punctuation: ")" [19:9 - 19:10] CallExpr=f:16:18
>>> // CHECK: Punctuation: ";" [19:10 - 19:11] UnexposedStmt=
>>> -// CHECK: Punctuation: "}" [20:1 - 20:2] UnexposedStmt=
>>> +// CHECK: Identifier: "X" [20:3 - 20:4] TypeRef=struct X:7:8
>>> +// CHECK: Identifier: "foo" [20:5 - 20:8] VarDecl=foo:20:5 (Definition)
>>> +// CHECK: Punctuation: ";" [20:8 - 20:9] UnexposedStmt=
>>> +// CHECK: Punctuation: "}" [21:1 - 21:2] UnexposedStmt=
>>> 
>>> Modified: cfe/trunk/tools/libclang/CIndex.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=133929&r1=133928&r2=133929&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
>>> +++ cfe/trunk/tools/libclang/CIndex.cpp Mon Jun 27 14:42:20 2011
>>> @@ -4627,6 +4627,24 @@
>>>    break;
>>>  }
>>> 
>>> +  // Avoid having the cursor of an expression "overwrite" the annotation of the
>>> +  // variable declaration that it belongs to.
>>> +  // This can happen for C++ constructor expressions whose range generally
>>> +  // include the variable declaration, e.g.:
>>> +  //  MyCXXClass foo; // Make sure we don't annotate 'foo' as a CallExpr cursor.
>>> +  if (clang_isExpression(cursorK)) {
>>> +    Expr *E = getCursorExpr(cursor);
>>> +    if (Decl *D = getCursorDecl(cursor)) {
>> 
>> I'm confused by this logic, since a cursor can't be both a declaration and an expression. Is the latter supposed to be
> 
> I see 
> 
> CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent,
>                                 CXTranslationUnit TU)
> 
> making statement/expression cursors including the parent Decl. Is this not the case ?


Ah, yes, this will work. We should really have a function that specifically extracts the parent declaration of a statement or expression cursor, but oh well.

	- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110628/f1c6b7fb/attachment.html>


More information about the cfe-commits mailing list