23#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_MATCHSWITCH_H_
24#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_MATCHSWITCH_H_
31#include "llvm/ADT/StringRef.h"
64template <
typename T,
typename State,
typename Result =
void>
68template <
typename BaseT,
typename State,
typename Result =
void>
74template <
typename State,
typename Result =
void>
97template <
typename BaseT,
typename State,
typename Result =
void>
106 template <
typename NodeT>
109 static_assert(std::is_base_of<BaseT, NodeT>::value,
110 "NodeT must be derived from BaseT.");
111 Matchers.push_back(std::move(M));
113 [A = std::move(A)](
const BaseT *
Node,
115 State &S) {
return A(cast<NodeT>(
Node), R, S); });
116 return std::move(*
this);
120 return [Matcher = BuildMatcher(), Actions = std::move(Actions)](
123 if (Results.empty()) {
128 for (
const auto &Element : Results[0].getMap()) {
129 llvm::StringRef ID(Element.first);
131 if (ID.consume_front(
"Tag") && !ID.getAsInteger(10, Index) &&
132 Index < Actions.size()) {
133 return Actions[Index](
143 ast_matchers::internal::DynTypedMatcher BuildMatcher() {
147 using ast_matchers::internal::DynTypedMatcher;
148 if (Matchers.empty())
150 for (
int I = 0, N = Matchers.size(); I < N; ++I) {
151 std::string Tag = (
"Tag" + llvm::Twine(I)).str();
153 Matchers[I].setAllowBind(
true);
154 auto M = *Matchers[I].tryBind(Tag);
161 !M.getTraversalKind() ? M.withTraversalKind(
TK_AsIs) : std::move(M);
165 return DynTypedMatcher::constructVariadic(
166 DynTypedMatcher::VO_AnyOf, ASTNodeKind::getFromNodeKind<BaseT>(),
167 std::move(Matchers));
170 std::vector<ast_matchers::internal::DynTypedMatcher> Matchers;
171 std::vector<MatchSwitchAction<BaseT, State, Result>> Actions;
176template <
typename State,
typename Result =
void>
Defines the clang::ASTContext interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Collects cases of a "match switch": a collection of matchers paired with callbacks,...
ASTMatchSwitchBuilder && CaseOf(MatchSwitchMatcher< BaseT > M, MatchSwitchAction< NodeT, State, Result > A) &&
Registers an action that will be triggered by the match of a pattern against the input statement.
ASTMatchSwitch< BaseT, State, Result > Build() &&
Holds the state of the program (store and heap) at a given program point.
const internal::VariadicOperatorMatcherFunc< 1, 1 > unless
Matches if the provided matcher does not match.
internal::TrueMatcher anything()
Matches any node.
SmallVector< BoundNodes, 1 > matchDynamic(internal::DynTypedMatcher Matcher, const DynTypedNode &Node, ASTContext &Context)
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
ASTMatchSwitch< Stmt, State, Result > MatchSwitch
std::function< Result(const T *, const ast_matchers::MatchFinder::MatchResult &, State &)> MatchSwitchAction
std::function< Result(const BaseT &, ASTContext &, State &)> ASTMatchSwitch
ast_matchers::internal::Matcher< T > MatchSwitchMatcher
@ TK_AsIs
Will traverse all child nodes.
@ Result
The result type of a method or function.
Contains all information for a given match.
A read-only version of TransferState.
const LatticeT & Lattice
Current lattice element.
TransferStateForDiagnostics(const LatticeT &Lattice, const Environment &Env)
A common form of state shared between the cases of a transfer function.
TransferState(LatticeT &Lattice, Environment &Env)
LatticeT & Lattice
Current lattice element.