r336606 - [Index] Add index::IndexingOptions::IndexImplicitInstantiation

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 9 14:49:06 PDT 2018


Author: maskray
Date: Mon Jul  9 14:49:06 2018
New Revision: 336606

URL: http://llvm.org/viewvc/llvm-project?rev=336606&view=rev
Log:
[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

Modified:
    cfe/trunk/include/clang/Index/IndexingAction.h
    cfe/trunk/lib/Index/IndexDecl.cpp
    cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp
    cfe/trunk/lib/Index/IndexingContext.cpp
    cfe/trunk/lib/Index/IndexingContext.h

Modified: cfe/trunk/include/clang/Index/IndexingAction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexingAction.h?rev=336606&r1=336605&r2=336606&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/IndexingAction.h (original)
+++ cfe/trunk/include/clang/Index/IndexingAction.h Mon Jul  9 14:49:06 2018
@@ -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).

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=336606&r1=336605&r2=336606&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Mon Jul  9 14:49:06 2018
@@ -726,7 +726,7 @@ bool IndexingContext::indexDecl(const De
   if (D->isImplicit() && shouldIgnoreIfImplicit(D))
     return true;
 
-  if (isTemplateImplicitInstantiation(D))
+  if (isTemplateImplicitInstantiation(D) && !shouldIndexImplicitInstantiation())
     return true;
 
   IndexingDeclVisitor Visitor(*this);

Modified: cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp?rev=336606&r1=336605&r2=336606&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp (original)
+++ cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp Mon Jul  9 14:49:06 2018
@@ -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);

Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=336606&r1=336605&r2=336606&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Mon Jul  9 14:49:06 2018
@@ -37,6 +37,10 @@ bool IndexingContext::shouldIndexFunctio
   return IndexOpts.IndexFunctionLocals;
 }
 
+bool IndexingContext::shouldIndexImplicitInstantiation() const {
+  return IndexOpts.IndexImplicitInstantiation;
+}
+
 bool IndexingContext::handleDecl(const Decl *D,
                                  SymbolRoleSet Roles,
                                  ArrayRef<SymbolRelation> Relations) {

Modified: cfe/trunk/lib/Index/IndexingContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.h?rev=336606&r1=336605&r2=336606&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingContext.h (original)
+++ cfe/trunk/lib/Index/IndexingContext.h Mon Jul  9 14:49:06 2018
@@ -60,9 +60,7 @@ public:
 
   bool shouldIndexFunctionLocalSymbols() const;
 
-  bool shouldIndexImplicitTemplateInsts() const {
-    return false;
-  }
+  bool shouldIndexImplicitInstantiation() const;
 
   static bool isTemplateImplicitInstantiation(const Decl *D);
 




More information about the cfe-commits mailing list