[cfe-commits] r154873 - in /cfe/trunk: test/Index/get-cursor.m tools/libclang/CIndex.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Apr 16 15:42:01 PDT 2012
Author: akirtzidis
Date: Mon Apr 16 17:42:01 2012
New Revision: 154873
URL: http://llvm.org/viewvc/llvm-project?rev=154873&view=rev
Log:
[libclang] Make sure that when we have multiple @class references in the same line,
that later ones do not override the previous ones.
If we have:
@class Foo, Bar;
source ranges for both start at '@', so 'Bar' will end up overriding
'Foo' even though the cursor location was at 'Foo'.
rdar://11257578
Modified:
cfe/trunk/test/Index/get-cursor.m
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/test/Index/get-cursor.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/get-cursor.m?rev=154873&r1=154872&r2=154873&view=diff
==============================================================================
--- cfe/trunk/test/Index/get-cursor.m (original)
+++ cfe/trunk/test/Index/get-cursor.m Mon Apr 16 17:42:01 2012
@@ -67,6 +67,8 @@
@implementation Test4(Dido)
@end
+ at class Forw1, Forw2, Forw3;
+
// RUN: c-index-test -cursor-at=%s:4:28 -cursor-at=%s:5:28 %s | FileCheck -check-prefix=CHECK-PROP %s
// CHECK-PROP: ObjCPropertyDecl=foo1:4:26
// CHECK-PROP: ObjCPropertyDecl=foo2:5:27
@@ -90,8 +92,13 @@
// RUN: c-index-test -cursor-at=%s:56:24 -cursor-at=%s:60:14 \
// RUN: -cursor-at=%s:65:20 -cursor-at=%s:67:25 \
+// RUN: -cursor-at=%s:70:10 -cursor-at=%s:70:16 -cursor-at=%s:70:25 \
// RUN: %s | FileCheck -check-prefix=CHECK-SPELLRANGE %s
// CHECK-SPELLRANGE: 56:8 ObjCInstanceMethodDecl=setFoo:withBar::56:8 Extent=[56:1 - 56:37] Spelling=setFoo:withBar: ([56:8 - 56:14][56:22 - 56:29]) Selector index=1
// CHECK-SPELLRANGE: 60:3 ObjCMessageExpr=setFoo:withBar::56:8 Extent=[60:3 - 60:29] Spelling=setFoo:withBar: ([60:10 - 60:16][60:19 - 60:26]) Selector index=0
// CHECK-SPELLRANGE: 65:12 ObjCCategoryDecl=Dido:65:12 Extent=[65:1 - 66:5] Spelling=Dido ([65:18 - 65:22])
// CHECK-SPELLRANGE: 67:17 ObjCCategoryImplDecl=Dido:67:17 (Definition) Extent=[67:1 - 68:2] Spelling=Dido ([67:23 - 67:27])
+
+// CHECK-SPELLRANGE: 70:8 ObjCClassRef=Forw1:70:8 Extent=[70:8 - 70:13] Spelling=Forw1 ([70:8 - 70:13])
+// CHECK-SPELLRANGE: 70:15 ObjCClassRef=Forw2:70:15 Extent=[70:15 - 70:20] Spelling=Forw2 ([70:15 - 70:20])
+// CHECK-SPELLRANGE: 70:22 ObjCClassRef=Forw3:70:22 Extent=[70:22 - 70:27] Spelling=Forw3 ([70:22 - 70:27])
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=154873&r1=154872&r2=154873&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Mon Apr 16 17:42:01 2012
@@ -3632,9 +3632,29 @@
if (clang_isDeclaration(cursor.kind)) {
// Avoid having the implicit methods override the property decls.
- if (ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(cursor)))
+ if (ObjCMethodDecl *MD
+ = dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(cursor))) {
if (MD->isImplicit())
return CXChildVisit_Break;
+
+ } else if (ObjCInterfaceDecl *ID
+ = dyn_cast_or_null<ObjCInterfaceDecl>(getCursorDecl(cursor))) {
+ // Check that when we have multiple @class references in the same line,
+ // that later ones do not override the previous ones.
+ // If we have:
+ // @class Foo, Bar;
+ // source ranges for both start at '@', so 'Bar' will end up overriding
+ // 'Foo' even though the cursor location was at 'Foo'.
+ if (BestCursor->kind == CXCursor_ObjCInterfaceDecl ||
+ BestCursor->kind == CXCursor_ObjCClassRef)
+ if (ObjCInterfaceDecl *PrevID
+ = dyn_cast_or_null<ObjCInterfaceDecl>(getCursorDecl(*BestCursor))){
+ if (PrevID != ID &&
+ !PrevID->isThisDeclarationADefinition() &&
+ !ID->isThisDeclarationADefinition())
+ return CXChildVisit_Break;
+ }
+ }
}
if (clang_isExpression(cursor.kind) &&
More information about the cfe-commits
mailing list