From b1e72a63c203cd48dba8b1a3b3b260dd325a1472 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 9 Jul 2018 21:49:06 +0000 Subject: [PATCH] [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 struct B { void bar() {}}; template struct A { void foo(B *x) { x->bar(); }}; int main() { A a; a.foo(0); } Reviewers: akyrtzi, arphaman, rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49002 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336606 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Index/IndexingAction.h | 1 + lib/Index/IndexDecl.cpp | 2 +- lib/Index/IndexTypeSourceInfo.cpp | 2 +- lib/Index/IndexingContext.cpp | 4 ++++ lib/Index/IndexingContext.h | 4 +--- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/clang/Index/IndexingAction.h b/include/clang/Index/IndexingAction.h index 48385b396f..64496a21ec 100644 --- a/include/clang/Index/IndexingAction.h +++ b/include/clang/Index/IndexingAction.h @@ -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). diff --git a/lib/Index/IndexDecl.cpp b/lib/Index/IndexDecl.cpp index 01608d2b77..01ad3a2772 100644 --- a/lib/Index/IndexDecl.cpp +++ b/lib/Index/IndexDecl.cpp @@ -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); diff --git a/lib/Index/IndexTypeSourceInfo.cpp b/lib/Index/IndexTypeSourceInfo.cpp index c8ff3d72d4..7a7a156478 100644 --- a/lib/Index/IndexTypeSourceInfo.cpp +++ b/lib/Index/IndexTypeSourceInfo.cpp @@ -129,7 +129,7 @@ public: template 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); diff --git a/lib/Index/IndexingContext.cpp b/lib/Index/IndexingContext.cpp index 71b92bc6bf..6c09ac7c09 100644 --- a/lib/Index/IndexingContext.cpp +++ b/lib/Index/IndexingContext.cpp @@ -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 Relations) { diff --git a/lib/Index/IndexingContext.h b/lib/Index/IndexingContext.h index f05eaae696..04960086d0 100644 --- a/lib/Index/IndexingContext.h +++ b/lib/Index/IndexingContext.h @@ -60,9 +60,7 @@ public: bool shouldIndexFunctionLocalSymbols() const; - bool shouldIndexImplicitTemplateInsts() const { - return false; - } + bool shouldIndexImplicitInstantiation() const; static bool isTemplateImplicitInstantiation(const Decl *D); -- 2.40.0