r262584 - [index] Report references of ObjC super class/protocols in interfaces and protocols.
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 2 21:33:54 PST 2016
Author: akirtzidis
Date: Wed Mar 2 23:33:54 2016
New Revision: 262584
URL: http://llvm.org/viewvc/llvm-project?rev=262584&view=rev
Log:
[index] Report references of ObjC super class/protocols in interfaces and protocols.
Modified:
cfe/trunk/lib/Index/IndexDecl.cpp
cfe/trunk/test/Index/Core/index-source.m
Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=262584&r1=262583&r2=262584&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Wed Mar 2 23:33:54 2016
@@ -14,6 +14,12 @@
using namespace clang;
using namespace index;
+#define TRY_TO(CALL_EXPR) \
+ do { \
+ if (!CALL_EXPR) \
+ return false; \
+ } while (0)
+
namespace {
class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> {
@@ -196,11 +202,30 @@ public:
return true;
}
+ bool handleReferencedProtocols(const ObjCProtocolList &ProtList,
+ const ObjCContainerDecl *ContD) {
+ ObjCInterfaceDecl::protocol_loc_iterator LI = ProtList.loc_begin();
+ for (ObjCInterfaceDecl::protocol_iterator
+ I = ProtList.begin(), E = ProtList.end(); I != E; ++I, ++LI) {
+ SourceLocation Loc = *LI;
+ ObjCProtocolDecl *PD = *I;
+ TRY_TO(IndexCtx.handleReference(PD, Loc, ContD, ContD,
+ SymbolRoleSet(),
+ SymbolRelation{(unsigned)SymbolRole::RelationBaseOf, ContD}));
+ }
+ return true;
+ }
+
bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
if (D->isThisDeclarationADefinition()) {
- if (!IndexCtx.handleDecl(D))
- return false;
- IndexCtx.indexDeclContext(D);
+ TRY_TO(IndexCtx.handleDecl(D));
+ if (auto *SuperD = D->getSuperClass()) {
+ TRY_TO(IndexCtx.handleReference(SuperD, D->getSuperClassLoc(), D, D,
+ SymbolRoleSet(),
+ SymbolRelation{(unsigned)SymbolRole::RelationBaseOf, D}));
+ }
+ TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D));
+ TRY_TO(IndexCtx.indexDeclContext(D));
} else {
return IndexCtx.handleReference(D, D->getLocation(), nullptr, nullptr,
SymbolRoleSet());
@@ -210,9 +235,9 @@ public:
bool VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
if (D->isThisDeclarationADefinition()) {
- if (!IndexCtx.handleDecl(D))
- return false;
- IndexCtx.indexDeclContext(D);
+ TRY_TO(IndexCtx.handleDecl(D));
+ TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D));
+ TRY_TO(IndexCtx.indexDeclContext(D));
} else {
return IndexCtx.handleReference(D, D->getLocation(), nullptr, nullptr,
SymbolRoleSet());
Modified: cfe/trunk/test/Index/Core/index-source.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.m?rev=262584&r1=262583&r2=262584&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/index-source.m (original)
+++ cfe/trunk/test/Index/Core/index-source.m Wed Mar 2 23:33:54 2016
@@ -18,3 +18,23 @@ void goo(Base *b) {
// CHECK-NEXT: RelRec | Base | c:objc(cs)Base
[b meth];
}
+
+// CHECK: [[@LINE+1]]:11 | objc-protocol/ObjC | Prot1 | c:objc(pl)Prot1 | <no-cgname> | Decl | rel: 0
+ at protocol Prot1
+ at end
+
+// CHECK: [[@LINE+3]]:11 | objc-protocol/ObjC | Prot2 | c:objc(pl)Prot2 | <no-cgname> | Decl | rel: 0
+// CHECK: [[@LINE+2]]:17 | objc-protocol/ObjC | Prot1 | c:objc(pl)Prot1 | <no-cgname> | Ref,RelBase | rel: 1
+// CHECK-NEXT: RelBase | Prot2 | c:objc(pl)Prot2
+ at protocol Prot2<Prot1>
+ at end
+
+// CHECK: [[@LINE+7]]:12 | objc-class/ObjC | Sub | c:objc(cs)Sub | _OBJC_CLASS_$_Sub | Decl | rel: 0
+// CHECK: [[@LINE+6]]:18 | objc-class/ObjC | Base | c:objc(cs)Base | _OBJC_CLASS_$_Base | Ref,RelBase | rel: 1
+// CHECK-NEXT: RelBase | Sub | c:objc(cs)Sub
+// CHECK: [[@LINE+4]]:23 | objc-protocol/ObjC | Prot2 | c:objc(pl)Prot2 | <no-cgname> | Ref,RelBase | rel: 1
+// CHECK-NEXT: RelBase | Sub | c:objc(cs)Sub
+// CHECK: [[@LINE+2]]:30 | objc-protocol/ObjC | Prot1 | c:objc(pl)Prot1 | <no-cgname> | Ref,RelBase | rel: 1
+// CHECK-NEXT: RelBase | Sub | c:objc(cs)Sub
+ at interface Sub : Base<Prot2, Prot1>
+ at end
More information about the cfe-commits
mailing list