r301051 - [index] Take into account the category's external_symbol attr for namespacing its methods
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 21 15:27:06 PDT 2017
Author: akirtzidis
Date: Fri Apr 21 17:27:06 2017
New Revision: 301051
URL: http://llvm.org/viewvc/llvm-project?rev=301051&view=rev
Log:
[index] Take into account the category's external_symbol attr for namespacing its methods
Modified:
cfe/trunk/include/clang/Index/USRGeneration.h
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/test/Index/Core/external-source-symbol-attr.m
Modified: cfe/trunk/include/clang/Index/USRGeneration.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/USRGeneration.h?rev=301051&r1=301050&r2=301051&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/USRGeneration.h (original)
+++ cfe/trunk/include/clang/Index/USRGeneration.h Fri Apr 21 17:27:06 2017
@@ -31,7 +31,8 @@ bool generateUSRForDecl(const Decl *D, S
/// \brief Generate a USR fragment for an Objective-C class.
void generateUSRForObjCClass(StringRef Cls, raw_ostream &OS,
- StringRef ExtSymbolDefinedIn = "");
+ StringRef ExtSymbolDefinedIn = "",
+ StringRef CategoryContextExtSymbolDefinedIn = "");
/// \brief Generate a USR fragment for an Objective-C class category.
void generateUSRForObjCCategory(StringRef Cls, StringRef Cat, raw_ostream &OS,
@@ -58,6 +59,9 @@ void generateUSRForObjCProtocol(StringRe
void generateUSRForGlobalEnum(StringRef EnumName, raw_ostream &OS,
StringRef ExtSymbolDefinedIn = "");
+/// Generate a USR fragment for an enum constant.
+void generateUSRForEnumConstant(StringRef EnumConstantName, raw_ostream &OS);
+
/// \brief Generate a USR for a macro, including the USR prefix.
///
/// \returns true on error, false on success.
Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=301051&r1=301050&r2=301051&view=diff
==============================================================================
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Fri Apr 21 17:27:06 2017
@@ -88,7 +88,8 @@ public:
void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
void VisitClassTemplateDecl(const ClassTemplateDecl *D);
- void VisitObjCContainerDecl(const ObjCContainerDecl *CD);
+ void VisitObjCContainerDecl(const ObjCContainerDecl *CD,
+ const ObjCCategoryDecl *CatD = nullptr);
void VisitObjCMethodDecl(const ObjCMethodDecl *MD);
void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
@@ -138,8 +139,10 @@ public:
/// itself.
/// Generate a USR for an Objective-C class.
- void GenObjCClass(StringRef cls, StringRef ext) {
- generateUSRForObjCClass(cls, Out, ext);
+ void GenObjCClass(StringRef cls, StringRef ExtSymDefinedIn,
+ StringRef CategoryContextExtSymbolDefinedIn) {
+ generateUSRForObjCClass(cls, Out, ExtSymDefinedIn,
+ CategoryContextExtSymbolDefinedIn);
}
/// Generate a USR for an Objective-C class category.
@@ -383,7 +386,16 @@ void USRGenerator::VisitObjCMethodDecl(c
IgnoreResults = true;
return;
}
- Visit(ID);
+ auto getCategoryContext = [](const ObjCMethodDecl *D) ->
+ const ObjCCategoryDecl * {
+ if (auto *CD = dyn_cast<ObjCCategoryDecl>(D->getDeclContext()))
+ return CD;
+ if (auto *ICD = dyn_cast<ObjCCategoryImplDecl>(D->getDeclContext()))
+ return ICD->getCategoryDecl();
+ return nullptr;
+ };
+ auto *CD = getCategoryContext(D);
+ VisitObjCContainerDecl(ID, CD);
}
// Ideally we would use 'GenObjCMethod', but this is such a hot path
// for Objective-C code that we don't want to use
@@ -392,13 +404,15 @@ void USRGenerator::VisitObjCMethodDecl(c
<< DeclarationName(D->getSelector());
}
-void USRGenerator::VisitObjCContainerDecl(const ObjCContainerDecl *D) {
+void USRGenerator::VisitObjCContainerDecl(const ObjCContainerDecl *D,
+ const ObjCCategoryDecl *CatD) {
switch (D->getKind()) {
default:
llvm_unreachable("Invalid ObjC container.");
case Decl::ObjCInterface:
case Decl::ObjCImplementation:
- GenObjCClass(D->getName(), GetExternalSourceContainer(D));
+ GenObjCClass(D->getName(), GetExternalSourceContainer(D),
+ GetExternalSourceContainer(CatD));
break;
case Decl::ObjCCategory: {
const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
@@ -896,10 +910,26 @@ void USRGenerator::VisitTemplateArgument
// USR generation functions.
//===----------------------------------------------------------------------===//
+static void combineClassAndCategoryExtContainers(StringRef ClsSymDefinedIn,
+ StringRef CatSymDefinedIn,
+ raw_ostream &OS) {
+ if (ClsSymDefinedIn.empty() && CatSymDefinedIn.empty())
+ return;
+ if (CatSymDefinedIn.empty()) {
+ OS << "@M@" << ClsSymDefinedIn << '@';
+ return;
+ }
+ OS << "@CM@" << CatSymDefinedIn << '@';
+ if (ClsSymDefinedIn != CatSymDefinedIn) {
+ OS << ClsSymDefinedIn << '@';
+ }
+}
+
void clang::index::generateUSRForObjCClass(StringRef Cls, raw_ostream &OS,
- StringRef ExtSymDefinedIn) {
- if (!ExtSymDefinedIn.empty())
- OS << "@M@" << ExtSymDefinedIn << '@';
+ StringRef ExtSymDefinedIn,
+ StringRef CategoryContextExtSymbolDefinedIn) {
+ combineClassAndCategoryExtContainers(ExtSymDefinedIn,
+ CategoryContextExtSymbolDefinedIn, OS);
OS << "objc(cs)" << Cls;
}
@@ -907,16 +937,7 @@ void clang::index::generateUSRForObjCCat
raw_ostream &OS,
StringRef ClsSymDefinedIn,
StringRef CatSymDefinedIn) {
- if (!CatSymDefinedIn.empty() || !ClsSymDefinedIn.empty()) {
- OS << "@M@";
- if (!CatSymDefinedIn.empty() && !ClsSymDefinedIn.empty())
- OS << CatSymDefinedIn << '-' << ClsSymDefinedIn;
- else if (!CatSymDefinedIn.empty())
- OS << CatSymDefinedIn;
- else
- OS << ClsSymDefinedIn;
- OS << '@';
- }
+ combineClassAndCategoryExtContainers(ClsSymDefinedIn, CatSymDefinedIn, OS);
OS << "objc(cy)" << Cls << '@' << Cat;
}
@@ -949,6 +970,11 @@ void clang::index::generateUSRForGlobalE
OS << "@E@" << EnumName;
}
+void clang::index::generateUSRForEnumConstant(StringRef EnumConstantName,
+ raw_ostream &OS) {
+ OS << '@' << EnumConstantName;
+}
+
bool clang::index::generateUSRForDecl(const Decl *D,
SmallVectorImpl<char> &Buf) {
if (!D)
Modified: cfe/trunk/test/Index/Core/external-source-symbol-attr.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/external-source-symbol-attr.m?rev=301051&r1=301050&r2=301051&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/external-source-symbol-attr.m (original)
+++ cfe/trunk/test/Index/Core/external-source-symbol-attr.m Fri Apr 21 17:27:06 2017
@@ -2,6 +2,7 @@
#define EXT_DECL(mod_name) __attribute__((external_source_symbol(language="Swift", defined_in=mod_name)))
#define GEN_DECL(mod_name) __attribute__((external_source_symbol(language="Swift", defined_in=mod_name, generated_declaration)))
+#define PUSH_GEN_DECL(mod_name) push(GEN_DECL(mod_name), apply_to=any(enum, objc_interface, objc_category, objc_protocol))
// This should not be indexed.
GEN_DECL("some_module")
@@ -37,14 +38,14 @@ EXT_DECL("some_module")
EXT_DECL("cat_module")
@interface I1(cat2)
-// CHECK: [[@LINE-1]]:15 | extension/ObjC | cat2 | c:@M at cat_module-some_module@objc(cy)I1 at cat2 |
+// CHECK: [[@LINE-1]]:15 | extension/ObjC | cat2 | c:@CM at cat_module@some_module at objc(cy)I1 at cat2 |
-(void)cat_method2;
-// CHECK: [[@LINE-1]]:8 | instance-method/ObjC | cat_method2 | c:@M at some_module@objc(cs)I1(im)cat_method2
+// CHECK: [[@LINE-1]]:8 | instance-method/ObjC | cat_method2 | c:@CM at cat_module@some_module at objc(cs)I1(im)cat_method2
@end
#define NS_ENUM(_name, _type) enum _name:_type _name; enum _name : _type
-#pragma clang attribute push(GEN_DECL("modname"), apply_to=any(enum, objc_interface, objc_category, objc_protocol))
+#pragma clang attribute PUSH_GEN_DECL("modname")
@interface I3
// CHECK-NOT: [[@LINE-1]]:12 |
@@ -80,9 +81,20 @@ void test2(I3 *i3, id<ExtProt2> prot2, S
[i3 meth];
// CHECK: [[@LINE-1]]:7 | instance-method/ObjC | meth | c:@M at modname@objc(cs)I3(im)meth |
[i3 meth2];
- // CHECK: [[@LINE-1]]:7 | instance-method/ObjC | meth2 | c:@M at modname@objc(cs)I3(im)meth2 |
+ // CHECK: [[@LINE-1]]:7 | instance-method/ObjC | meth2 | c:@CM at modname@objc(cs)I3(im)meth2 |
[prot2 meth];
// CHECK: [[@LINE-1]]:10 | instance-method/ObjC | meth | c:@M at modname@objc(pl)ExtProt2(im)meth |
some = SomeEnumFirst;
// CHECK: [[@LINE-1]]:10 | enumerator/C | SomeEnumFirst | c:@M at modname@E at SomeEnum@SomeEnumFirst |
}
+
+#pragma clang attribute PUSH_GEN_DECL("other_mod_for_cat")
+ at interface I3(cat_other_mod)
+-(void)meth_other_mod;
+ at end
+#pragma clang attribute pop
+
+void test3(I3 *i3) {
+ [i3 meth_other_mod];
+ // CHECK: [[@LINE-1]]:7 | instance-method/ObjC | meth_other_mod | c:@CM at other_mod_for_cat@modname at objc(cs)I3(im)meth_other_mod |
+}
More information about the cfe-commits
mailing list