summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2018-07-09 21:49:06 +0000
committerFangrui Song <maskray@google.com>2018-07-09 21:49:06 +0000
commitb1e72a63c203cd48dba8b1a3b3b260dd325a1472 (patch)
tree29b61c237fa4e798b6104f20f06483b22b14e598
parent2a527c0d94c929757ffc59f03009e1b3c67dba25 (diff)
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336606 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Index/IndexingAction.h1
-rw-r--r--lib/Index/IndexDecl.cpp2
-rw-r--r--lib/Index/IndexTypeSourceInfo.cpp2
-rw-r--r--lib/Index/IndexingContext.cpp4
-rw-r--r--lib/Index/IndexingContext.h4
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<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);
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<SymbolRelation> 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);