[Index] Add index::IndexingOptions::IndexImplicitInstantiation

Summary:
With IndexImplicitInstantiation=true, the following case records an occurrence of B::bar in A::foo, which will benefit cross reference tools.

template <class T> struct B { void bar() {}};
template <class T> struct A { void foo(B<T> *x) { x->bar(); }};
int main() { A<int> a; a.foo(0); }

Reviewers: akyrtzi, arphaman, rsmith

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D49002

llvm-svn: 336606
This commit is contained in:
Fangrui Song 2018-07-09 21:49:06 +00:00
parent 4fee1356ed
commit d50f36ed77
5 changed files with 8 additions and 5 deletions

View File

@ -39,6 +39,7 @@ struct IndexingOptions {
SystemSymbolFilterKind SystemSymbolFilter
= SystemSymbolFilterKind::DeclarationsOnly;
bool IndexFunctionLocals = false;
bool IndexImplicitInstantiation = false;
};
/// Creates a frontend action that indexes all symbols (macros and AST decls).

View File

@ -726,7 +726,7 @@ bool IndexingContext::indexDecl(const Decl *D) {
if (D->isImplicit() && shouldIgnoreIfImplicit(D))
return true;
if (isTemplateImplicitInstantiation(D))
if (isTemplateImplicitInstantiation(D) && !shouldIndexImplicitInstantiation())
return true;
IndexingDeclVisitor Visitor(*this);

View File

@ -129,7 +129,7 @@ public:
template<typename TypeLocType>
bool HandleTemplateSpecializationTypeLoc(TypeLocType TL) {
if (const auto *T = TL.getTypePtr()) {
if (IndexCtx.shouldIndexImplicitTemplateInsts()) {
if (IndexCtx.shouldIndexImplicitInstantiation()) {
if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
IndexCtx.handleReference(RD, TL.getTemplateNameLoc(),
Parent, ParentDC, SymbolRoleSet(), Relations);

View File

@ -37,6 +37,10 @@ bool IndexingContext::shouldIndexFunctionLocalSymbols() const {
return IndexOpts.IndexFunctionLocals;
}
bool IndexingContext::shouldIndexImplicitInstantiation() const {
return IndexOpts.IndexImplicitInstantiation;
}
bool IndexingContext::handleDecl(const Decl *D,
SymbolRoleSet Roles,
ArrayRef<SymbolRelation> Relations) {

View File

@ -60,9 +60,7 @@ public:
bool shouldIndexFunctionLocalSymbols() const;
bool shouldIndexImplicitTemplateInsts() const {
return false;
}
bool shouldIndexImplicitInstantiation() const;
static bool isTemplateImplicitInstantiation(const Decl *D);