[clang] 2b17438 - [Index/USRGeneration] Make sure that ObjC properties in categories also get namescoped properly for USR generation
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 7 15:07:48 PST 2020
Author: Argyrios Kyrtzidis
Date: 2020-03-07T15:07:37-08:00
New Revision: 2b17438a92ea1ea178d9e14219a8e6ba01d4f04d
URL: https://github.com/llvm/llvm-project/commit/2b17438a92ea1ea178d9e14219a8e6ba01d4f04d
DIFF: https://github.com/llvm/llvm-project/commit/2b17438a92ea1ea178d9e14219a8e6ba01d4f04d.diff
LOG: [Index/USRGeneration] Make sure that ObjC properties in categories also get namescoped properly for USR generation
If the property is in a category that has module names from external_declaration property, make sure they are included in the USR.
rdar://59897320
Added:
Modified:
clang/lib/Index/USRGeneration.cpp
clang/test/Index/Core/external-source-symbol-attr.m
Removed:
################################################################################
diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp
index 394daf94c4b2..f3eb653f10fa 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/lib/Index/USRGeneration.cpp
@@ -382,6 +382,14 @@ void USRGenerator::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Out << "@NA@" << D->getName();
}
+static const ObjCCategoryDecl *getCategoryContext(const NamedDecl *D) {
+ if (auto *CD = dyn_cast<ObjCCategoryDecl>(D->getDeclContext()))
+ return CD;
+ if (auto *ICD = dyn_cast<ObjCCategoryImplDecl>(D->getDeclContext()))
+ return ICD->getCategoryDecl();
+ return nullptr;
+};
+
void USRGenerator::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
const DeclContext *container = D->getDeclContext();
if (const ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) {
@@ -395,14 +403,6 @@ void USRGenerator::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
IgnoreResults = true;
return;
}
- 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);
}
@@ -475,7 +475,7 @@ void USRGenerator::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
// The USR for a property declared in a class extension or category is based
// on the ObjCInterfaceDecl, not the ObjCCategoryDecl.
if (const ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D))
- Visit(ID);
+ VisitObjCContainerDecl(ID, getCategoryContext(D));
else
Visit(cast<Decl>(D->getDeclContext()));
GenObjCProperty(D->getName(), D->isClassProperty());
diff --git a/clang/test/Index/Core/external-source-symbol-attr.m b/clang/test/Index/Core/external-source-symbol-attr.m
index 41bb7a264ab3..d2cef35ffab2 100644
--- a/clang/test/Index/Core/external-source-symbol-attr.m
+++ b/clang/test/Index/Core/external-source-symbol-attr.m
@@ -21,6 +21,10 @@ @interface I2
// CHECK: [[@LINE-1]]:12 | class/Swift | I2 | c:@M at some_module@objc(cs)I2 | {{.*}} | Decl | rel: 0
-(void)method;
// CHECK: [[@LINE-1]]:8 | instance-method/Swift | method | c:@M at some_module@objc(cs)I2(im)method | -[I2 method] | Decl,Dyn,RelChild | rel: 1
+ at property int prop;
+// CHECK: [[@LINE-1]]:15 | instance-method/acc-get/Swift | prop | c:@M at some_module@objc(cs)I2(im)prop |
+// CHECK: [[@LINE-2]]:15 | instance-method/acc-set/Swift | setProp: | c:@M at some_module@objc(cs)I2(im)setProp: |
+// CHECK: [[@LINE-3]]:15 | instance-property/Swift | prop | c:@M at some_module@objc(cs)I2(py)prop |
@end
void test1(I1 *o) {
@@ -45,6 +49,10 @@ @interface I1(cat2)
// CHECK: [[@LINE-1]]:15 | extension/Swift | cat2 | c:@CM at cat_module@some_module at objc(cy)I1 at cat2 |
-(void)cat_method2;
// CHECK: [[@LINE-1]]:8 | instance-method/Swift | cat_method2 | c:@CM at cat_module@some_module at objc(cs)I1(im)cat_method2
+ at property int cat_prop2;
+// CHECK: [[@LINE-1]]:15 | instance-method/acc-get/Swift | cat_prop2 | c:@CM at cat_module@some_module at objc(cs)I1(im)cat_prop2 |
+// CHECK: [[@LINE-2]]:15 | instance-method/acc-set/Swift | setCat_prop2: | c:@CM at cat_module@some_module at objc(cs)I1(im)setCat_prop2: |
+// CHECK: [[@LINE-3]]:15 | instance-property/Swift | cat_prop2 | c:@CM at cat_module@some_module at objc(cs)I1(py)cat_prop2 |
@end
#define NS_ENUM(_name, _type) enum _name:_type _name; enum _name : _type
More information about the cfe-commits
mailing list