]> granicus.if.org Git - clang/commitdiff
[index] Create different USR if a property is a class property.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 15 Jul 2016 22:18:19 +0000 (22:18 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 15 Jul 2016 22:18:19 +0000 (22:18 +0000)
Avoids USR conflicts between class & instance properties of the same name.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275630 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Index/USRGeneration.h
lib/Index/USRGeneration.cpp
test/Index/index-decls.m
tools/libclang/CIndexUSRs.cpp

index 55e35cc6d9b6ff0da77f9de7ee2464dbdebd4643..be89068469c4d032e010244691d9e5f135fb9cb8 100644 (file)
@@ -44,7 +44,7 @@ void generateUSRForObjCMethod(StringRef Sel, bool IsInstanceMethod,
                               raw_ostream &OS);
 
 /// \brief Generate a USR fragment for an Objective-C property.
-void generateUSRForObjCProperty(StringRef Prop, raw_ostream &OS);
+void generateUSRForObjCProperty(StringRef Prop, bool isClassProp, raw_ostream &OS);
 
 /// \brief Generate a USR fragment for an Objective-C protocol.
 void generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS);
index 11ee873189819e6eef56acf3eddd9cf8167e4ad4..30f1add249b156667cc8d4d6e353626d73ffef05 100644 (file)
@@ -138,8 +138,8 @@ public:
   }
 
   /// Generate a USR fragment for an Objective-C property.
-  void GenObjCProperty(StringRef prop) {
-    generateUSRForObjCProperty(prop, Out);
+  void GenObjCProperty(StringRef prop, bool isClassProp) {
+    generateUSRForObjCProperty(prop, isClassProp, Out);
   }
 
   /// Generate a USR for an Objective-C protocol.
@@ -411,7 +411,7 @@ void USRGenerator::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
     Visit(ID);
   else
     Visit(cast<Decl>(D->getDeclContext()));
-  GenObjCProperty(D->getName());
+  GenObjCProperty(D->getName(), D->isClassProperty());
 }
 
 void USRGenerator::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
@@ -864,8 +864,9 @@ void clang::index::generateUSRForObjCMethod(StringRef Sel,
   OS << (IsInstanceMethod ? "(im)" : "(cm)") << Sel;
 }
 
-void clang::index::generateUSRForObjCProperty(StringRef Prop, raw_ostream &OS) {
-  OS << "(py)" << Prop;
+void clang::index::generateUSRForObjCProperty(StringRef Prop, bool isClassProp,
+                                              raw_ostream &OS) {
+  OS << (isClassProp ? "(cpy)" : "(py)") << Prop;
 }
 
 void clang::index::generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS) {
index 3564117523e594ddf7feaea87533ead1b85f7a25..a39d9e3bfa6b735f65aec324c5379b0a6fbb4bbb 100644 (file)
@@ -52,6 +52,7 @@ int test1() {
 @class I5;
 @interface I5
 -(void)meth;
+@property (class) int c;
 @end
 
 // RUN: c-index-test -index-file %s -target x86_64-apple-macosx10.7 > %t
@@ -82,3 +83,4 @@ int test1() {
 // CHECK-NOT: [indexDeclaration]: kind: objc-instance-method {{.*}} loc: 43:
 
 // CHECK: [indexDeclaration]: kind: objc-instance-method | name: meth | {{.*}} loc: 54:1 | {{.*}} | isRedecl: 0 | isDef: 0 |
+// CHECK: [indexDeclaration]: kind: objc-property | name: c | USR: c:objc(cs)I5(cpy)c | lang: ObjC | cursor: ObjCPropertyDecl=c:55:23 [class,] | loc: 55:23
index d7b65852844eddad5fba76663237e83268fa2582..69d60c9d44f2a45aaf51d1ec341080901066274e 100644 (file)
@@ -137,7 +137,7 @@ CXString clang_constructUSR_ObjCProperty(const char *property,
   SmallString<128> Buf(getUSRSpacePrefix());
   llvm::raw_svector_ostream OS(Buf);
   OS << extractUSRSuffix(clang_getCString(classUSR));
-  generateUSRForObjCProperty(property, OS);
+  generateUSRForObjCProperty(property, /*isClassProp=*/false, OS);
   return cxstring::createDup(OS.str());
 }