From 712a70e658ea7debadcc2c9331f09df009e4cae6 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 17 Aug 2018 23:50:59 +0000 Subject: [PATCH] [index] For an ObjC message call, also record as receivers the protocols if they are present in the ObjC type git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340109 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Index/IndexBody.cpp | 20 ++++++++++++++++++-- test/Index/Core/index-source.m | 22 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/Index/IndexBody.cpp b/lib/Index/IndexBody.cpp index d79f0c3967..dd8a1c7b3f 100644 --- a/lib/Index/IndexBody.cpp +++ b/lib/Index/IndexBody.cpp @@ -259,8 +259,24 @@ public: if (isDynamic(E)) { Roles |= (unsigned)SymbolRole::Dynamic; - if (auto *RecD = E->getReceiverInterface()) - Relations.emplace_back((unsigned)SymbolRole::RelationReceivedBy, RecD); + + auto addReceivers = [&](const ObjCObjectType *Ty) { + if (!Ty) + return; + if (const auto *clsD = Ty->getInterface()) { + Relations.emplace_back((unsigned)SymbolRole::RelationReceivedBy, + clsD); + } + for (const auto *protD : Ty->quals()) { + Relations.emplace_back((unsigned)SymbolRole::RelationReceivedBy, + protD); + } + }; + QualType recT = E->getReceiverType(); + if (const auto *Ptr = recT->getAs()) + addReceivers(Ptr->getObjectType()); + else + addReceivers(recT->getAs()); } return IndexCtx.handleReference(MD, E->getSelectorStartLoc(), diff --git a/test/Index/Core/index-source.m b/test/Index/Core/index-source.m index 2931e664ea..c319be63ab 100644 --- a/test/Index/Core/index-source.m +++ b/test/Index/Core/index-source.m @@ -2,7 +2,7 @@ // RUN: c-index-test core -print-source-symbols -include-locals -- %s -target x86_64-apple-macosx10.7 | FileCheck -check-prefix=LOCAL %s @interface Base -// CHECK: [[@LINE-1]]:12 | class/ObjC | Base | c:objc(cs)Base | _OBJC_CLASS_$_Base | Decl | rel: 0 +// CHECK: [[@LINE-1]]:12 | class/ObjC | Base | [[BASE_USR:.*]] | _OBJC_CLASS_$_Base | Decl | rel: 0 -(void)meth; // CHECK: [[@LINE-1]]:8 | instance-method/ObjC | meth | c:objc(cs)Base(im)meth | -[Base meth] | Decl,Dyn,RelChild | rel: 1 // CHECK-NEXT: RelChild | Base | c:objc(cs)Base @@ -60,7 +60,7 @@ void goo(Base *b) { Base *f = (Base *) 2; } -// CHECK: [[@LINE+1]]:11 | protocol/ObjC | Prot1 | c:objc(pl)Prot1 | | Decl | rel: 0 +// CHECK: [[@LINE+1]]:11 | protocol/ObjC | Prot1 | [[PROT1_USR:.*]] | | Decl | rel: 0 @protocol Prot1 @end @@ -472,3 +472,21 @@ void testImplicitProperties(ImplicitProperties *c) { } @end + +@protocol Prot3 // CHECK: [[@LINE]]:11 | protocol/ObjC | Prot3 | [[PROT3_USR:.*]] | | Decl | +-(void)meth; +@end + +void test_rec1() { + id o1; + [o1 meth]; // CHECK: [[@LINE]]:7 | instance-method/ObjC | meth | {{.*}} | Ref,Call,Dyn,RelRec,RelCall,RelCont | rel: 3 + // CHECK-NEXT: RelCall,RelCont | test_rec1 | + // CHECK-NEXT: RelRec | Prot3 | [[PROT3_USR]] + // CHECK-NEXT: RelRec | Prot1 | [[PROT1_USR]] + Base *o2; + [o2 meth]; // CHECK: [[@LINE]]:7 | instance-method/ObjC | meth | {{.*}} | Ref,Call,Dyn,RelRec,RelCall,RelCont | rel: 4 + // CHECK-NEXT: RelCall,RelCont | test_rec1 | + // CHECK-NEXT: RelRec | Base | [[BASE_USR]] + // CHECK-NEXT: RelRec | Prot3 | [[PROT3_USR]] + // CHECK-NEXT: RelRec | Prot1 | [[PROT1_USR]] +} -- 2.50.1