File indexing completed on 2026-05-10 08:36:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CFGMATCHSWITCH_H_
0020 #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CFGMATCHSWITCH_H_
0021
0022 #include "clang/AST/ASTContext.h"
0023 #include "clang/AST/Stmt.h"
0024 #include "clang/Analysis/CFG.h"
0025 #include "clang/Analysis/FlowSensitive/MatchSwitch.h"
0026 #include <functional>
0027 #include <utility>
0028
0029 namespace clang {
0030 namespace dataflow {
0031
0032 template <typename State, typename Result = void>
0033 using CFGMatchSwitch =
0034 std::function<Result(const CFGElement &, ASTContext &, State &)>;
0035
0036
0037
0038
0039 template <typename State, typename Result = void> class CFGMatchSwitchBuilder {
0040 public:
0041
0042
0043
0044
0045
0046
0047 template <typename NodeT>
0048 CFGMatchSwitchBuilder &&
0049 CaseOfCFGStmt(MatchSwitchMatcher<Stmt> M,
0050 MatchSwitchAction<NodeT, State, Result> A) && {
0051 std::move(StmtBuilder).template CaseOf<NodeT>(M, A);
0052 return std::move(*this);
0053 }
0054
0055
0056
0057
0058
0059
0060
0061
0062 template <typename NodeT>
0063 CFGMatchSwitchBuilder &&
0064 CaseOfCFGInit(MatchSwitchMatcher<CXXCtorInitializer> M,
0065 MatchSwitchAction<NodeT, State, Result> A) && {
0066 std::move(InitBuilder).template CaseOf<NodeT>(M, A);
0067 return std::move(*this);
0068 }
0069
0070 CFGMatchSwitch<State, Result> Build() && {
0071 return [StmtMS = std::move(StmtBuilder).Build(),
0072 InitMS = std::move(InitBuilder).Build()](const CFGElement &Element,
0073 ASTContext &Context,
0074 State &S) -> Result {
0075 switch (Element.getKind()) {
0076 case CFGElement::Initializer:
0077 return InitMS(*Element.castAs<CFGInitializer>().getInitializer(),
0078 Context, S);
0079 case CFGElement::Statement:
0080 case CFGElement::Constructor:
0081 case CFGElement::CXXRecordTypedCall:
0082 return StmtMS(*Element.castAs<CFGStmt>().getStmt(), Context, S);
0083 default:
0084
0085 return Result();
0086 }
0087 };
0088 }
0089
0090 private:
0091 ASTMatchSwitchBuilder<Stmt, State, Result> StmtBuilder;
0092 ASTMatchSwitchBuilder<CXXCtorInitializer, State, Result> InitBuilder;
0093 };
0094
0095 }
0096 }
0097
0098 #endif