diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2016-10-25 21:11:22 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2016-10-25 21:11:22 +0000 |
commit | 806faaf42ba49fffaa9217c368d53bddd7e4fcf1 (patch) | |
tree | ddae84699bde6b4836e831e90e572b9d4aa7d0bc /clang/lib/Index/IndexDecl.cpp | |
parent | 83fb4019f7ebd51cb0ede98e593a4e072bbabd57 (diff) | |
download | bcm5719-llvm-806faaf42ba49fffaa9217c368d53bddd7e4fcf1.tar.gz bcm5719-llvm-806faaf42ba49fffaa9217c368d53bddd7e4fcf1.zip |
[index] Fixes for locations and relations in Objective C categories and getters/setters
- Add entries for protocols on categories
- Add relation between categories and class they extend
- Add relation between getters/setters and their corresponding property
- Use category name location as the location of category decls/defs if it has one
llvm-svn: 285120
Diffstat (limited to 'clang/lib/Index/IndexDecl.cpp')
-rw-r--r-- | clang/lib/Index/IndexDecl.cpp | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp index eb3e1511473..1225391dc2a 100644 --- a/clang/lib/Index/IndexDecl.cpp +++ b/clang/lib/Index/IndexDecl.cpp @@ -75,8 +75,21 @@ public: } } - bool handleObjCMethod(const ObjCMethodDecl *D) { - if (!IndexCtx.handleDecl(D, (unsigned)SymbolRole::Dynamic)) + bool handleObjCMethod(const ObjCMethodDecl *D, + const ObjCPropertyDecl *AssociatedProp = nullptr) { + SmallVector<SymbolRelation, 4> Relations; + SmallVector<const ObjCMethodDecl*, 4> Overriden; + + D->getOverriddenMethods(Overriden); + for(auto overridden: Overriden) { + Relations.emplace_back((unsigned) SymbolRole::RelationOverrideOf, + overridden); + } + if (AssociatedProp) + Relations.emplace_back((unsigned)SymbolRole::RelationAccessorOf, + AssociatedProp); + + if (!IndexCtx.handleDecl(D, (unsigned)SymbolRole::Dynamic, Relations)) return false; IndexCtx.indexTypeSourceInfo(D->getReturnTypeSourceInfo(), D); for (const auto *I : D->parameters()) @@ -269,9 +282,18 @@ public: } bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { - if (!IndexCtx.handleDecl(D)) - return false; - IndexCtx.indexDeclContext(D); + const ObjCInterfaceDecl *C = D->getClassInterface(); + if (C) + TRY_TO(IndexCtx.handleReference(C, D->getLocation(), D, D, + SymbolRoleSet(), SymbolRelation{ + (unsigned)SymbolRole::RelationExtendedBy, D + })); + SourceLocation CategoryLoc = D->getCategoryNameLoc(); + if (!CategoryLoc.isValid()) + CategoryLoc = D->getLocation(); + TRY_TO(IndexCtx.handleDecl(D, CategoryLoc)); + TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D)); + TRY_TO(IndexCtx.indexDeclContext(D)); return true; } @@ -279,8 +301,14 @@ public: const ObjCCategoryDecl *Cat = D->getCategoryDecl(); if (!Cat) return true; - - if (!IndexCtx.handleDecl(D)) + const ObjCInterfaceDecl *C = D->getClassInterface(); + if (C) + TRY_TO(IndexCtx.handleReference(C, D->getLocation(), D, D, + SymbolRoleSet())); + SourceLocation CategoryLoc = D->getCategoryNameLoc(); + if (!CategoryLoc.isValid()) + CategoryLoc = D->getLocation(); + if (!IndexCtx.handleDecl(D, CategoryLoc)) return false; IndexCtx.indexDeclContext(D); return true; @@ -299,10 +327,10 @@ public: bool VisitObjCPropertyDecl(const ObjCPropertyDecl *D) { if (ObjCMethodDecl *MD = D->getGetterMethodDecl()) if (MD->getLexicalDeclContext() == D->getLexicalDeclContext()) - handleObjCMethod(MD); + handleObjCMethod(MD, D); if (ObjCMethodDecl *MD = D->getSetterMethodDecl()) if (MD->getLexicalDeclContext() == D->getLexicalDeclContext()) - handleObjCMethod(MD); + handleObjCMethod(MD, D); if (!IndexCtx.handleDecl(D)) return false; IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), D); |