================ @@ -39,6 +39,51 @@ AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) { return FD ? FD->isMain() : false; } +AST_MATCHER(clang::TypeLoc, isWithinImplicitTemplateInstantiation) { + const auto IsImplicitTemplateInstantiation = [](const auto *Node) { + return (Node != nullptr) && + (Node->getTemplateSpecializationKind() == TSK_ImplicitInstantiation); + }; + + DynTypedNodeList ParentNodes = Finder->getASTContext().getParents(Node); + const clang::NamedDecl *ParentDecl = nullptr; + while (!ParentNodes.empty()) { + const DynTypedNode &ParentNode = ParentNodes[0]; + if (IsImplicitTemplateInstantiation( + ParentNode.template get<clang::CXXRecordDecl>()) || + IsImplicitTemplateInstantiation( + ParentNode.template get<clang::FunctionDecl>()) || + IsImplicitTemplateInstantiation( + ParentNode.template get<clang::VarDecl>())) + return true; + + // in case of a `NamedDecl` as parent node, it is more efficient to proceed + // with the upward traversal via DeclContexts (see below) instead of via + // parent nodes + if (ParentDecl = ParentNode.template get<clang::NamedDecl>()) + break; + + ParentNodes = Finder->getASTContext().getParents(ParentNode); + } + + if (ParentDecl != nullptr) { + const clang::DeclContext *DeclContext = ParentDecl->getDeclContext(); + while (DeclContext != nullptr) { + for (const clang::Decl *Decl : DeclContext->decls()) { + if (IsImplicitTemplateInstantiation( + dyn_cast<clang::CXXRecordDecl>(Decl)) || + IsImplicitTemplateInstantiation( + dyn_cast<clang::FunctionDecl>(Decl)) || + IsImplicitTemplateInstantiation(dyn_cast<clang::VarDecl>(Decl))) ---------------- vbvictor wrote:
Could these calls to 3 functions be refactored in a separate function to avoid duplicates with L52-57 https://github.com/llvm/llvm-project/pull/132924 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits