Skip to content

Commit

Permalink
[index] Create different USR if a property is a class property.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
akyrtzi committed Jul 15, 2016
1 parent 97fe2e8 commit 51856a5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/clang/Index/USRGeneration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions lib/Index/USRGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ class USRGenerator : public ConstDeclVisitor<USRGenerator> {
}

/// 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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions test/Index/index-decls.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ -(void)setProp:(id)p {
@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
Expand Down Expand Up @@ -82,3 +83,4 @@ -(void)meth;
// 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
2 changes: 1 addition & 1 deletion tools/libclang/CIndexUSRs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 51856a5

Please sign in to comment.