From: Argyrios Kyrtzidis Date: Fri, 15 Jul 2016 22:18:19 +0000 (+0000) Subject: [index] Create different USR if a property is a class property. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=51856a5426575f4c87c5233625cfc8123e4300f3;p=clang [index] Create different USR if a property is a class property. 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 --- diff --git a/include/clang/Index/USRGeneration.h b/include/clang/Index/USRGeneration.h index 55e35cc6d9..be89068469 100644 --- a/include/clang/Index/USRGeneration.h +++ b/include/clang/Index/USRGeneration.h @@ -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); diff --git a/lib/Index/USRGeneration.cpp b/lib/Index/USRGeneration.cpp index 11ee873189..30f1add249 100644 --- a/lib/Index/USRGeneration.cpp +++ b/lib/Index/USRGeneration.cpp @@ -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(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) { diff --git a/test/Index/index-decls.m b/test/Index/index-decls.m index 3564117523..a39d9e3bfa 100644 --- a/test/Index/index-decls.m +++ b/test/Index/index-decls.m @@ -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 diff --git a/tools/libclang/CIndexUSRs.cpp b/tools/libclang/CIndexUSRs.cpp index d7b6585284..69d60c9d44 100644 --- a/tools/libclang/CIndexUSRs.cpp +++ b/tools/libclang/CIndexUSRs.cpp @@ -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()); }