Index: include/clang/ASTMatchers/ASTMatchFinder.h =================================================================== --- include/clang/ASTMatchers/ASTMatchFinder.h +++ include/clang/ASTMatchers/ASTMatchFinder.h @@ -128,10 +128,17 @@ llvm::StringMap &Records; }; + MatchFinderOptions() + : ShouldVisitImplicitCode(true), + ShouldVisitTemplateInstantiations(true) {} + /// \brief Enables per-check timers. /// /// It prints a report after match. llvm::Optional CheckProfiling; + + bool ShouldVisitImplicitCode; + bool ShouldVisitTemplateInstantiations; }; MatchFinder(MatchFinderOptions Options = MatchFinderOptions()); Index: lib/ASTMatchers/ASTMatchFinder.cpp =================================================================== --- lib/ASTMatchers/ASTMatchFinder.cpp +++ lib/ASTMatchers/ASTMatchFinder.cpp @@ -86,12 +86,14 @@ // matching the descendants. MatchChildASTVisitor(const DynTypedMatcher *Matcher, ASTMatchFinder *Finder, + const MatchFinder::MatchFinderOptions &Options, BoundNodesTreeBuilder *Builder, int MaxDepth, ASTMatchFinder::TraversalKind Traversal, ASTMatchFinder::BindKind Bind) : Matcher(Matcher), Finder(Finder), + Options(Options), Builder(Builder), CurrentDepth(0), MaxDepth(MaxDepth), @@ -195,8 +197,12 @@ return traverse(NNS); } - bool shouldVisitTemplateInstantiations() const { return true; } - bool shouldVisitImplicitCode() const { return true; } + bool shouldVisitTemplateInstantiations() const { + return Options.ShouldVisitTemplateInstantiations; + } + bool shouldVisitImplicitCode() const { + return Options.ShouldVisitImplicitCode; + } // Disables data recursion. We intercept Traverse* methods in the RAV, which // are not triggered during data recursion. bool shouldUseDataRecursionFor(clang::Stmt *S) const { return false; } @@ -282,6 +288,7 @@ const DynTypedMatcher *const Matcher; ASTMatchFinder *const Finder; + const MatchFinder::MatchFinderOptions &Options; BoundNodesTreeBuilder *const Builder; BoundNodesTreeBuilder ResultBindings; int CurrentDepth; @@ -415,7 +422,7 @@ BoundNodesTreeBuilder *Builder, int MaxDepth, TraversalKind Traversal, BindKind Bind) { MatchChildASTVisitor Visitor( - &Matcher, this, Builder, MaxDepth, Traversal, Bind); + &Matcher, this, Options, Builder, MaxDepth, Traversal, Bind); return Visitor.findMatch(Node); } @@ -485,8 +492,12 @@ // Implements ASTMatchFinder::getASTContext. ASTContext &getASTContext() const override { return *ActiveASTContext; } - bool shouldVisitTemplateInstantiations() const { return true; } - bool shouldVisitImplicitCode() const { return true; } + bool shouldVisitTemplateInstantiations() const { + return Options.ShouldVisitTemplateInstantiations; + } + bool shouldVisitImplicitCode() const { + return Options.ShouldVisitImplicitCode; + } // Disables data recursion. We intercept Traverse* methods in the RAV, which // are not triggered during data recursion. bool shouldUseDataRecursionFor(clang::Stmt *S) const { return false; }