]> granicus.if.org Git - clang/commitdiff
[Index] Add index::IndexingOptions::IndexImplicitInstantiation
authorFangrui Song <maskray@google.com>
Mon, 9 Jul 2018 21:49:06 +0000 (21:49 +0000)
committerFangrui Song <maskray@google.com>
Mon, 9 Jul 2018 21:49:06 +0000 (21:49 +0000)
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

include/clang/Index/IndexingAction.h
lib/Index/IndexDecl.cpp
lib/Index/IndexTypeSourceInfo.cpp
lib/Index/IndexingContext.cpp
lib/Index/IndexingContext.h

index 48385b396f74ff29ad34ab0bcc579c8a97081ace..64496a21ec535067c1d0515005a5af4dd34251c5 100644 (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).
index 01608d2b77f5a1461771ce1baf52142accb25c8a..01ad3a2772167ad595c215fb30226120a17d6f85 100644 (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);
index c8ff3d72d4be1362c4a56bb2bc772f923b03f5c6..7a7a156478f88c872dc88499ffa7308d24f94d96 100644 (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);
index 71b92bc6bf20ea2b70d60d8c7822d30442d2198d..6c09ac7c09a7d7508478fabdbb79eab18237f420 100644 (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) {
index f05eaae69651fbba3c14910f9861b5686c561364..04960086d0928f0dbf0ab307923b0c5177d2288e 100644 (file)
@@ -60,9 +60,7 @@ public:
 
   bool shouldIndexFunctionLocalSymbols() const;
 
-  bool shouldIndexImplicitTemplateInsts() const {
-    return false;
-  }
+  bool shouldIndexImplicitInstantiation() const;
 
   static bool isTemplateImplicitInstantiation(const Decl *D);