diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2017-02-26 05:37:56 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2017-02-26 05:37:56 +0000 |
commit | 6d1a15b2d402e0d768b285fc9a136ff36be3db1c (patch) | |
tree | f223f8ad0f4edc30b0e38bef5a5dec69990e5aac /clang/lib/Index/IndexSymbol.cpp | |
parent | 42ef2177af937a2eb5a837297373dfa60c700770 (diff) | |
download | bcm5719-llvm-6d1a15b2d402e0d768b285fc9a136ff36be3db1c.tar.gz bcm5719-llvm-6d1a15b2d402e0d768b285fc9a136ff36be3db1c.zip |
[index] Add 'Parameter' symbol kind and 'Local' symbol property to distinguish function-local symbols
Parameters have a 'child' relation to their function/method.
Also add an option '-include-locals' to 'c-index-test core' to enable indexing of function-local symbols.
Original patch from Nathan Hawes with some changes by me.
https://reviews.llvm.org/D30304
llvm-svn: 296282
Diffstat (limited to 'clang/lib/Index/IndexSymbol.cpp')
-rw-r--r-- | clang/lib/Index/IndexSymbol.cpp | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/clang/lib/Index/IndexSymbol.cpp b/clang/lib/Index/IndexSymbol.cpp index 84984fce4dc..ba315696551 100644 --- a/clang/lib/Index/IndexSymbol.cpp +++ b/clang/lib/Index/IndexSymbol.cpp @@ -49,6 +49,37 @@ static void checkForIBOutlets(const Decl *D, SymbolPropertySet &PropSet) { } } +bool index::isFunctionLocalSymbol(const Decl *D) { + assert(D); + + if (isa<ParmVarDecl>(D)) + return true; + + if (isa<TemplateTemplateParmDecl>(D)) + return true; + + if (isa<ObjCTypeParamDecl>(D)) + return true; + + if (!D->getParentFunctionOrMethod()) + return false; + + if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) { + switch (ND->getFormalLinkage()) { + case NoLinkage: + case VisibleNoLinkage: + case InternalLinkage: + return true; + case UniqueExternalLinkage: + llvm_unreachable("Not a sema linkage"); + case ExternalLinkage: + return false; + } + } + + return true; +} + SymbolInfo index::getSymbolInfo(const Decl *D) { assert(D); SymbolInfo Info; @@ -57,6 +88,10 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Properties = SymbolPropertySet(); Info.Lang = SymbolLanguage::C; + if (isFunctionLocalSymbol(D)) { + Info.Properties |= (unsigned)SymbolProperty::Local; + } + if (const TagDecl *TD = dyn_cast<TagDecl>(D)) { switch (TD->getTagKind()) { case TTK_Struct: @@ -94,10 +129,13 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { } else if (auto *VD = dyn_cast<VarDecl>(D)) { Info.Kind = SymbolKind::Variable; - if (isa<CXXRecordDecl>(D->getDeclContext())) { + if (isa<ParmVarDecl>(D)) { + Info.Kind = SymbolKind::Parameter; + } else if (isa<CXXRecordDecl>(D->getDeclContext())) { Info.Kind = SymbolKind::StaticProperty; Info.Lang = SymbolLanguage::CXX; } + if (isa<VarTemplatePartialSpecializationDecl>(D)) { Info.Lang = SymbolLanguage::CXX; Info.Properties |= (unsigned)SymbolProperty::Generic; @@ -378,6 +416,7 @@ StringRef index::getSymbolKindString(SymbolKind K) { case SymbolKind::Constructor: return "constructor"; case SymbolKind::Destructor: return "destructor"; case SymbolKind::ConversionFunction: return "coversion-func"; + case SymbolKind::Parameter: return "param"; } llvm_unreachable("invalid symbol kind"); } @@ -415,6 +454,7 @@ void index::applyForEachSymbolProperty(SymbolPropertySet Props, APPLY_FOR_PROPERTY(IBAnnotated); APPLY_FOR_PROPERTY(IBOutletCollection); APPLY_FOR_PROPERTY(GKInspectable); + APPLY_FOR_PROPERTY(Local); #undef APPLY_FOR_PROPERTY } @@ -434,6 +474,7 @@ void index::printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS) { case SymbolProperty::IBAnnotated: OS << "IB"; break; case SymbolProperty::IBOutletCollection: OS << "IBColl"; break; case SymbolProperty::GKInspectable: OS << "GKI"; break; + case SymbolProperty::Local: OS << "local"; break; } }); } |