| 83 | } |
| 84 | |
| 85 | absl::optional<Expr> ExpandAllMacro(MacroExprFactory& factory, Expr& target, |
| 86 | absl::Span<Expr> args) { |
| 87 | if (args.size() != 2) { |
| 88 | return factory.ReportError("all() requires 2 arguments"); |
| 89 | } |
| 90 | if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) { |
| 91 | return factory.ReportErrorAt( |
| 92 | args[0], "all() variable name must be a simple identifier"); |
| 93 | } |
| 94 | if (args[0].ident_expr().name() == kAccumulatorVariableName) { |
| 95 | return factory.ReportErrorAt(args[1], |
| 96 | absl::StrCat("all() variable name cannot be ", |
| 97 | kAccumulatorVariableName)); |
| 98 | } |
| 99 | auto init = factory.NewBoolConst(true); |
| 100 | auto condition = |
| 101 | factory.NewCall(CelOperator::NOT_STRICTLY_FALSE, factory.NewAccuIdent()); |
| 102 | auto step = factory.NewCall(CelOperator::LOGICAL_AND, factory.NewAccuIdent(), |
| 103 | std::move(args[1])); |
| 104 | auto result = factory.NewAccuIdent(); |
| 105 | return factory.NewComprehension(args[0].ident_expr().name(), |
| 106 | std::move(target), factory.AccuVarName(), |
| 107 | std::move(init), std::move(condition), |
| 108 | std::move(step), std::move(result)); |
| 109 | } |
| 110 | |
| 111 | Macro MakeAllMacro() { |
| 112 | auto status_or_macro = Macro::Receiver(CelOperator::ALL, 2, ExpandAllMacro); |
nothing calls this directly
no test coverage detected