From 87ec9c257c99b4136af6c7f5be5a2d486906ba84 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 1 Nov 2011 17:14:12 +0000 Subject: [libclang] For a class extension, give it a unique USR but for any property or ivar it contains give it a USR based on its semantic context, which is the interface. This follows what we already did for objc methods. rdar://10371669 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143464 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/libclang/CIndexUSRs.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'tools/libclang/CIndexUSRs.cpp') diff --git a/tools/libclang/CIndexUSRs.cpp b/tools/libclang/CIndexUSRs.cpp index 11b124c562..32c4db6abe 100644 --- a/tools/libclang/CIndexUSRs.cpp +++ b/tools/libclang/CIndexUSRs.cpp @@ -169,7 +169,12 @@ void USRGenerator::VisitDeclContext(DeclContext *DC) { } void USRGenerator::VisitFieldDecl(FieldDecl *D) { - VisitDeclContext(D->getDeclContext()); + // The USR for an ivar declared in a class extension is based on the + // ObjCInterfaceDecl, not the ObjCCategoryDecl. + if (ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D)) + Visit(ID); + else + VisitDeclContext(D->getDeclContext()); Out << (isa(D) ? "@" : "@FI@"); if (EmitDeclName(D)) { // Bit fields can be anonymous. @@ -336,9 +341,11 @@ void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) { IgnoreResults = true; return; } + // Specially handle class extensions, which are anonymous categories. + // We want to mangle in the location to uniquely distinguish them. if (CD->IsClassExtension()) { - // An extension semantically continues the interface of the class. - GenObjCClass(ID->getName()); + Out << "objc(ext)" << ID->getName() << '@'; + GenLoc(CD); } else GenObjCCategory(ID->getName(), CD->getName()); @@ -366,7 +373,12 @@ void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) { } void USRGenerator::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { - Visit(cast(D->getDeclContext())); + // The USR for a property declared in a class extension or category is based + // on the ObjCInterfaceDecl, not the ObjCCategoryDecl. + if (ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D)) + Visit(ID); + else + Visit(cast(D->getDeclContext())); GenObjCProperty(D->getName()); } -- cgit v1.2.1