]> granicus.if.org Git - clang/commitdiff
USRs for class extensions should "mangle" in the location of the extension. (<rdar...
authorTed Kremenek <kremenek@apple.com>
Tue, 24 Aug 2010 23:13:41 +0000 (23:13 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 24 Aug 2010 23:13:41 +0000 (23:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111991 91177308-0d34-0410-b5e6-96231b3b80d8

test/Index/usrs.m
tools/libclang/CIndexUSRs.cpp

index 143b0673c8912c81255f2cc298a6a701dd572fb2..4b3de5c480ab610a5b604cbbe7d151d26915328c 100644 (file)
@@ -49,12 +49,24 @@ int z;
 static int local_func(int x) { return x; }
 
 @interface CWithExt
+- (id) meth1;
 @end
 @interface CWithExt ()
+- (id) meth2;
 @end
 @interface CWithExt ()
+- (id) meth3;
+@end
+@interface CWithExt (Bar)
+- (id) meth4;
 @end
 @implementation CWithExt
+- (id) meth1 { return 0; }
+- (id) meth2 { return 0; }
+- (id) meth3 { return 0; }
+@end
+@implementation CWithExt (Bar)
+- (id) meth4 { return 0; }
 @end
 
 // CHECK: usrs.m c:usrs.m@85@F@my_helper Extent=[3:19 - 3:60]
@@ -93,10 +105,18 @@ static int local_func(int x) { return x; }
 // CHECK: usrs.m c:@z Extent=[47:1 - 47:6]
 // CHECK: usrs.m c:usrs.m@540@F@local_func Extent=[49:12 - 49:43]
 // CHECK: usrs.m c:usrs.m@551@F@local_func@x Extent=[49:23 - 49:28]
-// CHECK: usrs.m c:objc(cs)CWithExt Extent=[51:1 - 52:5]
-// CHECK: usrs.m c:objc(cy)CWithExt@ Extent=[53:1 - 54:5]
-// CHECK: usrs.m c:objc(cy)CWithExt@ Extent=[55:1 - 56:5]
-// CHECK: usrs.m c:objc(cs)CWithExt Extent=[57:1 - 58:2]
-
-
+// CHECK: usrs.m c:objc(cs)CWithExt Extent=[51:1 - 53:5]
+// CHECK: usrs.m c:objc(cs)CWithExt(im)meth1 Extent=[52:1 - 52:14]
+// CHECK: usrs.m c:objc(ext)CWithExt@usrs.m@612 Extent=[54:1 - 56:5]
+// CHECK: usrs.m c:objc(cs)CWithExt(im)meth2 Extent=[55:1 - 55:14]
+// CHECK: usrs.m c:objc(ext)CWithExt@usrs.m@654 Extent=[57:1 - 59:5]
+// CHECK: usrs.m c:objc(cs)CWithExt(im)meth3 Extent=[58:1 - 58:14]
+// CHECK: usrs.m c:objc(cy)CWithExt@Bar Extent=[60:1 - 62:5]
+// CHECK: usrs.m c:objc(cy)CWithExt@Bar(im)meth4 Extent=[61:1 - 61:14]
+// CHECK: usrs.m c:objc(cs)CWithExt Extent=[63:1 - 67:2]
+// CHECK: usrs.m c:objc(cs)CWithExt(im)meth1 Extent=[64:1 - 64:27]
+// CHECK: usrs.m c:objc(cs)CWithExt(im)meth2 Extent=[65:1 - 65:27]
+// CHECK: usrs.m c:objc(cs)CWithExt(im)meth3 Extent=[66:1 - 66:27]
+// CHECK: usrs.m c:objc(cy)CWithExt@Bar Extent=[68:1 - 70:2]
+// CHECK: usrs.m c:objc(cy)CWithExt@Bar(im)meth4 Extent=[69:1 - 69:27]
 
index 886030fe3800c1f3226680322e4cc5740897564f..0227b2c037e0469b1cb8ffa9c18fc57847c98ce7 100644 (file)
@@ -227,7 +227,20 @@ void USRGenerator::VisitNamespaceDecl(NamespaceDecl *D) {
 }
 
 void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) {
-  Visit(cast<Decl>(D->getDeclContext()));
+  Decl *container = cast<Decl>(D->getDeclContext());
+  
+  // The USR for a method declared in a class extension is based on
+  // the ObjCInterfaceDecl, not the ObjCCategoryDecl.
+  do {
+    if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(container))
+      if (CD->IsClassExtension()) {
+        Visit(CD->getClassInterface());
+        break;
+      }    
+    Visit(cast<Decl>(D->getDeclContext()));
+  }
+  while (false);
+  
   // Ideally we would use 'GenObjCMethod', but this is such a hot path
   // for Objective-C code that we don't want to use
   // DeclarationName::getAsString().
@@ -267,7 +280,15 @@ void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) {
         IgnoreResults = true;
         return;
       }
-      GenObjCCategory(ID->getName(), CD->getName());
+      // Specially handle class extensions, which are anonymous categories.
+      // We want to mangle in the location to uniquely distinguish them.
+      if (CD->IsClassExtension()) {
+        Out << "objc(ext)" << ID->getName() << '@';
+        GenLoc(CD);
+      }
+      else
+        GenObjCCategory(ID->getName(), CD->getName());
+
       break;
     }
     case Decl::ObjCCategoryImpl: {