40 #ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHFINDER_H 41 #define LLVM_CLANG_ASTMATCHERS_ASTMATCHFINDER_H 44 #include "llvm/ADT/SmallPtrSet.h" 45 #include "llvm/ADT/StringMap.h" 46 #include "llvm/Support/Timer.h" 112 virtual StringRef getID()
const;
119 virtual void run() = 0;
125 : Records(Records) {}
204 std::vector<std::pair<internal::DynTypedMatcher, MatchCallback *>>
206 std::vector<std::pair<TypeMatcher, MatchCallback *>>
Type;
207 std::vector<std::pair<NestedNameSpecifierMatcher, MatchCallback *>>
209 std::vector<std::pair<NestedNameSpecifierLocMatcher, MatchCallback *>>
211 std::vector<std::pair<TypeLocMatcher, MatchCallback *>>
TypeLoc;
212 std::vector<std::pair<CXXCtorInitializerMatcher, MatchCallback *>>
CtorInit;
240 template <
typename MatcherT,
typename NodeT>
244 template <
typename MatcherT>
252 template <
typename MatcherT>
265 template <
typename NodeT>
269 if (
const NodeT *
Node = N.getNodeAs<NodeT>(BoundTo))
285 template <
typename MatcherT>
292 Finder.
match(Node, Context);
293 return std::move(Callback.
Nodes);
296 template <
typename MatcherT,
typename NodeT>
302 template <
typename MatcherT>
309 return std::move(Callback.
Nodes);
318 Finder.
match(Node, Context);
319 return std::move(Callback.
Nodes);
322 template <
typename NodeT>
336 return std::move(Callback.
Nodes);
A class to allow finding matches over the Clang AST.
internal::Matcher< NestedNameSpecifier > NestedNameSpecifierMatcher
const NodeT * selectFirst(StringRef BoundTo, const SmallVectorImpl< BoundNodes > &Results)
Returns the first result of type NodeT bound to BoundTo.
internal::Matcher< Stmt > StatementMatcher
llvm::StringMap< llvm::TimeRecord > & Records
Per bucket timing information.
llvm::SmallPtrSet< MatchCallback *, 16 > AllCallbacks
All the callbacks in one container to simplify iteration.
Called when parsing is finished. Intended for testing only.
MatchFinder(MatchFinderOptions Options=MatchFinderOptions())
internal::Matcher< QualType > TypeMatcher
void match(const T &Node, ASTContext &Context)
Calls the registered callbacks on all matches on the given Node.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void addMatcher(const DeclarationMatcher &NodeMatch, MatchCallback *Action)
Adds a matcher to execute when running over the AST.
std::vector< std::pair< CXXCtorInitializerMatcher, MatchCallback * > > CtorInit
Contains all information for a given match.
void registerTestCallbackAfterParsing(ParsingDoneTestCallback *ParsingDone)
Registers a callback to notify the end of parsing.
SmallVector< BoundNodes, 1 > Nodes
MatchResult(const BoundNodes &Nodes, clang::ASTContext *Context)
Profiling(llvm::StringMap< llvm::TimeRecord > &Records)
std::unique_ptr< clang::ASTConsumer > newASTConsumer()
Creates a clang ASTConsumer that finds all matches.
Maps string IDs to AST nodes matched by parts of a matcher.
clang::ASTContext *const Context
Utilities for interpreting the matched AST structures.
void matchAST(ASTContext &Context)
Finds all matches in the given AST.
std::vector< std::pair< NestedNameSpecifierLocMatcher, MatchCallback * > > NestedNameSpecifierLoc
std::vector< std::pair< internal::DynTypedMatcher, MatchCallback * > > DeclOrStmt
llvm::Optional< Profiling > CheckProfiling
Enables per-check timers.
static DynTypedNode create(const T &Node)
Creates a DynTypedNode from Node.
std::vector< std::pair< NestedNameSpecifierMatcher, MatchCallback * > > NestedNameSpecifier
std::vector< std::pair< TypeMatcher, MatchCallback * > > Type
virtual void onEndOfTranslationUnit()
Called at the end of each translation unit.
const BoundNodes Nodes
Contains the nodes bound on the current match.
ast_type_traits::DynTypedNode Node
For each Matcher<> a MatchCallback that will be called when it matches.
Dataflow Directional Tag Classes.
internal::Matcher< CXXCtorInitializer > CXXCtorInitializerMatcher
A dynamically typed AST node container.
SmallVector< BoundNodes, 1 > matchDynamic(internal::DynTypedMatcher Matcher, const ast_type_traits::DynTypedNode &Node, ASTContext &Context)
std::vector< std::pair< TypeLocMatcher, MatchCallback * > > TypeLoc
internal::Matcher< NestedNameSpecifierLoc > NestedNameSpecifierLocMatcher
internal::Matcher< TypeLoc > TypeLocMatcher
void run(const MatchFinder::MatchResult &Result) override
Called on every match by the MatchFinder.
Called when the Match registered for it was successfully found in the AST.
clang::SourceManager *const SourceManager
virtual void onStartOfTranslationUnit()
Called at the start of each translation unit.
This class handles loading and caching of source files into memory.
internal::Matcher< Decl > DeclarationMatcher
Types of matchers for the top-level classes in the AST class hierarchy.
bool addDynamicMatcher(const internal::DynTypedMatcher &NodeMatch, MatchCallback *Action)
Adds a matcher to execute when running over the AST.