diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2017-01-11 21:01:07 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2017-01-11 21:01:07 +0000 |
commit | de0f50886f4d122a1142c77fa5f36ad1533c96d7 (patch) | |
tree | f71e2bf9127a04d0d85c1cecf68e9d4e337b49cf /clang/lib | |
parent | 974e4c78999ad00af0505a9bf50b7432b219f717 (diff) | |
download | bcm5719-llvm-de0f50886f4d122a1142c77fa5f36ad1533c96d7.tar.gz bcm5719-llvm-de0f50886f4d122a1142c77fa5f36ad1533c96d7.zip |
[index] Add 'IBTypeOf' relation for ObjC methods marked with IBAction and properties with IBOutletCollection.
llvm-svn: 291703
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Index/IndexDecl.cpp | 17 | ||||
-rw-r--r-- | clang/lib/Index/IndexSymbol.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Index/IndexTypeSourceInfo.cpp | 20 | ||||
-rw-r--r-- | clang/lib/Index/IndexingContext.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Index/IndexingContext.h | 6 |
5 files changed, 40 insertions, 15 deletions
diff --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp index 1225391dc2a..6c5b2e520ef 100644 --- a/clang/lib/Index/IndexDecl.cpp +++ b/clang/lib/Index/IndexDecl.cpp @@ -46,10 +46,13 @@ public: } void handleDeclarator(const DeclaratorDecl *D, - const NamedDecl *Parent = nullptr) { + const NamedDecl *Parent = nullptr, + bool isIBType = false) { if (!Parent) Parent = D; - IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), Parent); + IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), Parent, + Parent->getLexicalDeclContext(), + /*isBase=*/false, isIBType); IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent); if (IndexCtx.shouldIndexFunctionLocalSymbols()) { // Only index parameters in definitions, parameters in declarations are @@ -92,8 +95,11 @@ public: if (!IndexCtx.handleDecl(D, (unsigned)SymbolRole::Dynamic, Relations)) return false; IndexCtx.indexTypeSourceInfo(D->getReturnTypeSourceInfo(), D); - for (const auto *I : D->parameters()) - handleDeclarator(I, D); + bool hasIBActionAndFirst = D->hasAttr<IBActionAttr>(); + for (const auto *I : D->parameters()) { + handleDeclarator(I, D, /*isIBType=*/hasIBActionAndFirst); + hasIBActionAndFirst = false; + } if (D->isThisDeclarationADefinition()) { const Stmt *Body = D->getBody(); @@ -333,6 +339,9 @@ public: handleObjCMethod(MD, D); if (!IndexCtx.handleDecl(D)) return false; + if (IBOutletCollectionAttr *attr = D->getAttr<IBOutletCollectionAttr>()) + IndexCtx.indexTypeSourceInfo(attr->getInterfaceLoc(), D, + D->getLexicalDeclContext(), false, true); IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), D); return true; } diff --git a/clang/lib/Index/IndexSymbol.cpp b/clang/lib/Index/IndexSymbol.cpp index d7df0976b07..5192122ae1e 100644 --- a/clang/lib/Index/IndexSymbol.cpp +++ b/clang/lib/Index/IndexSymbol.cpp @@ -290,6 +290,7 @@ void index::applyForEachSymbolRole(SymbolRoleSet Roles, APPLY_FOR_ROLE(RelationExtendedBy); APPLY_FOR_ROLE(RelationAccessorOf); APPLY_FOR_ROLE(RelationContainedBy); + APPLY_FOR_ROLE(RelationIBTypeOf); #undef APPLY_FOR_ROLE } @@ -319,6 +320,7 @@ void index::printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS) { case SymbolRole::RelationExtendedBy: OS << "RelExt"; break; case SymbolRole::RelationAccessorOf: OS << "RelAcc"; break; case SymbolRole::RelationContainedBy: OS << "RelCont"; break; + case SymbolRole::RelationIBTypeOf: OS << "RelIBType"; break; } }); } diff --git a/clang/lib/Index/IndexTypeSourceInfo.cpp b/clang/lib/Index/IndexTypeSourceInfo.cpp index 619a9a48bef..38bbb30fedf 100644 --- a/clang/lib/Index/IndexTypeSourceInfo.cpp +++ b/clang/lib/Index/IndexTypeSourceInfo.cpp @@ -26,12 +26,16 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> { public: TypeIndexer(IndexingContext &indexCtx, const NamedDecl *parent, - const DeclContext *DC, bool isBase) + const DeclContext *DC, bool isBase, bool isIBType) : IndexCtx(indexCtx), Parent(parent), ParentDC(DC), IsBase(isBase) { if (IsBase) { assert(Parent); Relations.emplace_back((unsigned)SymbolRole::RelationBaseOf, Parent); } + if (isIBType) { + assert(Parent); + Relations.emplace_back((unsigned)SymbolRole::RelationIBTypeOf, Parent); + } } bool shouldWalkTypesOfTypeLocs() const { return false; } @@ -93,13 +97,13 @@ public: bool VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { return IndexCtx.handleReference(TL.getIFaceDecl(), TL.getNameLoc(), - Parent, ParentDC, SymbolRoleSet()); + Parent, ParentDC, SymbolRoleSet(), Relations); } bool VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) { IndexCtx.handleReference(TL.getProtocol(i), TL.getProtocolLoc(i), - Parent, ParentDC, SymbolRoleSet()); + Parent, ParentDC, SymbolRoleSet(), Relations); } return true; } @@ -130,23 +134,25 @@ public: void IndexingContext::indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC, - bool isBase) { + bool isBase, + bool isIBType) { if (!TInfo || TInfo->getTypeLoc().isNull()) return; - indexTypeLoc(TInfo->getTypeLoc(), Parent, DC, isBase); + indexTypeLoc(TInfo->getTypeLoc(), Parent, DC, isBase, isIBType); } void IndexingContext::indexTypeLoc(TypeLoc TL, const NamedDecl *Parent, const DeclContext *DC, - bool isBase) { + bool isBase, + bool isIBType) { if (TL.isNull()) return; if (!DC) DC = Parent->getLexicalDeclContext(); - TypeIndexer(*this, Parent, DC, isBase).TraverseTypeLoc(TL); + TypeIndexer(*this, Parent, DC, isBase, isIBType).TraverseTypeLoc(TL); } void IndexingContext::indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, diff --git a/clang/lib/Index/IndexingContext.cpp b/clang/lib/Index/IndexingContext.cpp index 2d5fc0df3a0..6dd6c0cfb28 100644 --- a/clang/lib/Index/IndexingContext.cpp +++ b/clang/lib/Index/IndexingContext.cpp @@ -314,9 +314,15 @@ bool IndexingContext::handleDeclOccurrence(const Decl *D, SourceLocation Loc, if (Parent) { if (IsRef) { - addRelation(SymbolRelation{(unsigned)SymbolRole::RelationContainedBy, Parent}); + addRelation(SymbolRelation{ + (unsigned)SymbolRole::RelationContainedBy, + Parent + }); } else if (!cast<DeclContext>(Parent)->isFunctionOrMethod()) { - addRelation(SymbolRelation{(unsigned)SymbolRole::RelationChildOf, Parent}); + addRelation(SymbolRelation{ + (unsigned)SymbolRole::RelationChildOf, + Parent + }); } } diff --git a/clang/lib/Index/IndexingContext.h b/clang/lib/Index/IndexingContext.h index 600fc433b58..dd1dd328cd4 100644 --- a/clang/lib/Index/IndexingContext.h +++ b/clang/lib/Index/IndexingContext.h @@ -85,11 +85,13 @@ public: void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC = nullptr, - bool isBase = false); + bool isBase = false, + bool isIBType = false); void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent, const DeclContext *DC = nullptr, - bool isBase = false); + bool isBase = false, + bool isIBType = false); void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const NamedDecl *Parent, |