MaskRay created this revision. MaskRay added reviewers: akyrtzi, arphaman. Herald added a subscriber: cfe-commits.
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); } Repository: rC Clang https://reviews.llvm.org/D49002 Files: include/clang/Index/IndexingAction.h lib/Index/IndexDecl.cpp lib/Index/IndexTypeSourceInfo.cpp lib/Index/IndexingContext.cpp lib/Index/IndexingContext.h Index: lib/Index/IndexingContext.h =================================================================== --- lib/Index/IndexingContext.h +++ lib/Index/IndexingContext.h @@ -58,9 +58,7 @@ bool shouldIndexFunctionLocalSymbols() const; - bool shouldIndexImplicitTemplateInsts() const { - return false; - } + bool shouldIndexImplicitInstantiation() const; static bool isTemplateImplicitInstantiation(const Decl *D); Index: lib/Index/IndexingContext.cpp =================================================================== --- lib/Index/IndexingContext.cpp +++ lib/Index/IndexingContext.cpp @@ -36,6 +36,10 @@ return IndexOpts.IndexFunctionLocals; } +bool IndexingContext::shouldIndexImplicitInstantiation() const { + return IndexOpts.IndexImplicitInstantiation; +} + bool IndexingContext::handleDecl(const Decl *D, SymbolRoleSet Roles, ArrayRef<SymbolRelation> Relations) { Index: lib/Index/IndexTypeSourceInfo.cpp =================================================================== --- lib/Index/IndexTypeSourceInfo.cpp +++ lib/Index/IndexTypeSourceInfo.cpp @@ -129,7 +129,7 @@ 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: lib/Index/IndexDecl.cpp =================================================================== --- lib/Index/IndexDecl.cpp +++ lib/Index/IndexDecl.cpp @@ -726,7 +726,7 @@ if (D->isImplicit() && shouldIgnoreIfImplicit(D)) return true; - if (isTemplateImplicitInstantiation(D)) + if (isTemplateImplicitInstantiation(D) && !shouldIndexImplicitInstantiation()) return true; IndexingDeclVisitor Visitor(*this); Index: include/clang/Index/IndexingAction.h =================================================================== --- include/clang/Index/IndexingAction.h +++ include/clang/Index/IndexingAction.h @@ -38,6 +38,7 @@ SystemSymbolFilterKind SystemSymbolFilter = SystemSymbolFilterKind::DeclarationsOnly; bool IndexFunctionLocals = false; + bool IndexImplicitInstantiation = false; }; /// \param WrappedAction another frontend action to wrap over or null.
Index: lib/Index/IndexingContext.h =================================================================== --- lib/Index/IndexingContext.h +++ lib/Index/IndexingContext.h @@ -58,9 +58,7 @@ bool shouldIndexFunctionLocalSymbols() const; - bool shouldIndexImplicitTemplateInsts() const { - return false; - } + bool shouldIndexImplicitInstantiation() const; static bool isTemplateImplicitInstantiation(const Decl *D); Index: lib/Index/IndexingContext.cpp =================================================================== --- lib/Index/IndexingContext.cpp +++ lib/Index/IndexingContext.cpp @@ -36,6 +36,10 @@ return IndexOpts.IndexFunctionLocals; } +bool IndexingContext::shouldIndexImplicitInstantiation() const { + return IndexOpts.IndexImplicitInstantiation; +} + bool IndexingContext::handleDecl(const Decl *D, SymbolRoleSet Roles, ArrayRef<SymbolRelation> Relations) { Index: lib/Index/IndexTypeSourceInfo.cpp =================================================================== --- lib/Index/IndexTypeSourceInfo.cpp +++ lib/Index/IndexTypeSourceInfo.cpp @@ -129,7 +129,7 @@ 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: lib/Index/IndexDecl.cpp =================================================================== --- lib/Index/IndexDecl.cpp +++ lib/Index/IndexDecl.cpp @@ -726,7 +726,7 @@ if (D->isImplicit() && shouldIgnoreIfImplicit(D)) return true; - if (isTemplateImplicitInstantiation(D)) + if (isTemplateImplicitInstantiation(D) && !shouldIndexImplicitInstantiation()) return true; IndexingDeclVisitor Visitor(*this); Index: include/clang/Index/IndexingAction.h =================================================================== --- include/clang/Index/IndexingAction.h +++ include/clang/Index/IndexingAction.h @@ -38,6 +38,7 @@ SystemSymbolFilterKind SystemSymbolFilter = SystemSymbolFilterKind::DeclarationsOnly; bool IndexFunctionLocals = false; + bool IndexImplicitInstantiation = false; }; /// \param WrappedAction another frontend action to wrap over or null.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits