Skip to content

Commit 466d67a

Browse files
authored
Merge pull request #887 from akyrtzi/usr-generation-objc-prop-external
[Index/USRGeneration] Make sure that ObjC properties in categories also get namescoped properly for USR generation
2 parents e2b6aa3 + a7b7398 commit 466d67a

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

clang/lib/Index/USRGeneration.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ void USRGenerator::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
382382
Out << "@NA@" << D->getName();
383383
}
384384

385+
static const ObjCCategoryDecl *getCategoryContext(const NamedDecl *D) {
386+
if (auto *CD = dyn_cast<ObjCCategoryDecl>(D->getDeclContext()))
387+
return CD;
388+
if (auto *ICD = dyn_cast<ObjCCategoryImplDecl>(D->getDeclContext()))
389+
return ICD->getCategoryDecl();
390+
return nullptr;
391+
};
392+
385393
void USRGenerator::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
386394
const DeclContext *container = D->getDeclContext();
387395
if (const ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) {
@@ -395,14 +403,6 @@ void USRGenerator::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
395403
IgnoreResults = true;
396404
return;
397405
}
398-
auto getCategoryContext = [](const ObjCMethodDecl *D) ->
399-
const ObjCCategoryDecl * {
400-
if (auto *CD = dyn_cast<ObjCCategoryDecl>(D->getDeclContext()))
401-
return CD;
402-
if (auto *ICD = dyn_cast<ObjCCategoryImplDecl>(D->getDeclContext()))
403-
return ICD->getCategoryDecl();
404-
return nullptr;
405-
};
406406
auto *CD = getCategoryContext(D);
407407
VisitObjCContainerDecl(ID, CD);
408408
}
@@ -475,7 +475,7 @@ void USRGenerator::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
475475
// The USR for a property declared in a class extension or category is based
476476
// on the ObjCInterfaceDecl, not the ObjCCategoryDecl.
477477
if (const ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D))
478-
Visit(ID);
478+
VisitObjCContainerDecl(ID, getCategoryContext(D));
479479
else
480480
Visit(cast<Decl>(D->getDeclContext()));
481481
GenObjCProperty(D->getName(), D->isClassProperty());

clang/test/Index/Core/external-source-symbol-attr.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ @interface I2
2121
// CHECK: [[@LINE-1]]:12 | class/Swift | I2 | c:@M@some_module@objc(cs)I2 | {{.*}} | Decl | rel: 0
2222
-(void)method;
2323
// CHECK: [[@LINE-1]]:8 | instance-method/Swift | method | c:@M@some_module@objc(cs)I2(im)method | -[I2 method] | Decl,Dyn,RelChild | rel: 1
24+
@property int prop;
25+
// CHECK: [[@LINE-1]]:15 | instance-method/acc-get/Swift | prop | c:@M@some_module@objc(cs)I2(im)prop |
26+
// CHECK: [[@LINE-2]]:15 | instance-method/acc-set/Swift | setProp: | c:@M@some_module@objc(cs)I2(im)setProp: |
27+
// CHECK: [[@LINE-3]]:15 | instance-property/Swift | prop | c:@M@some_module@objc(cs)I2(py)prop |
2428
@end
2529

2630
void test1(I1 *o) {
@@ -45,6 +49,10 @@ @interface I1(cat2)
4549
// CHECK: [[@LINE-1]]:15 | extension/Swift | cat2 | c:@CM@cat_module@some_module@objc(cy)I1@cat2 |
4650
-(void)cat_method2;
4751
// CHECK: [[@LINE-1]]:8 | instance-method/Swift | cat_method2 | c:@CM@cat_module@some_module@objc(cs)I1(im)cat_method2
52+
@property int cat_prop2;
53+
// CHECK: [[@LINE-1]]:15 | instance-method/acc-get/Swift | cat_prop2 | c:@CM@cat_module@some_module@objc(cs)I1(im)cat_prop2 |
54+
// CHECK: [[@LINE-2]]:15 | instance-method/acc-set/Swift | setCat_prop2: | c:@CM@cat_module@some_module@objc(cs)I1(im)setCat_prop2: |
55+
// CHECK: [[@LINE-3]]:15 | instance-property/Swift | cat_prop2 | c:@CM@cat_module@some_module@objc(cs)I1(py)cat_prop2 |
4856
@end
4957

5058
#define NS_ENUM(_name, _type) enum _name:_type _name; enum _name : _type

0 commit comments

Comments
 (0)