| 39 | using ::google::api::expr::common::CelOperator; |
| 40 | |
| 41 | absl::optional<Expr> ExpandAllMacro2(MacroExprFactory& factory, Expr& target, |
| 42 | absl::Span<Expr> args) { |
| 43 | if (args.size() != 3) { |
| 44 | return factory.ReportError("all() requires 3 arguments"); |
| 45 | } |
| 46 | if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) { |
| 47 | return factory.ReportErrorAt( |
| 48 | args[0], "all() first variable name must be a simple identifier"); |
| 49 | } |
| 50 | if (!args[1].has_ident_expr() || args[1].ident_expr().name().empty()) { |
| 51 | return factory.ReportErrorAt( |
| 52 | args[1], "all() second variable name must be a simple identifier"); |
| 53 | } |
| 54 | if (args[0].ident_expr().name() == args[1].ident_expr().name()) { |
| 55 | return factory.ReportErrorAt( |
| 56 | args[0], |
| 57 | "all() second variable must be different from the first variable"); |
| 58 | } |
| 59 | if (args[0].ident_expr().name() == kAccumulatorVariableName) { |
| 60 | return factory.ReportErrorAt( |
| 61 | args[0], absl::StrCat("all() first variable name cannot be ", |
| 62 | kAccumulatorVariableName)); |
| 63 | } |
| 64 | if (args[1].ident_expr().name() == kAccumulatorVariableName) { |
| 65 | return factory.ReportErrorAt( |
| 66 | args[1], absl::StrCat("all() second variable name cannot be ", |
| 67 | kAccumulatorVariableName)); |
| 68 | } |
| 69 | auto init = factory.NewBoolConst(true); |
| 70 | auto condition = |
| 71 | factory.NewCall(CelOperator::NOT_STRICTLY_FALSE, factory.NewAccuIdent()); |
| 72 | auto step = factory.NewCall(CelOperator::LOGICAL_AND, factory.NewAccuIdent(), |
| 73 | std::move(args[2])); |
| 74 | auto result = factory.NewAccuIdent(); |
| 75 | return factory.NewComprehension( |
| 76 | args[0].ident_expr().name(), args[1].ident_expr().name(), |
| 77 | std::move(target), factory.AccuVarName(), std::move(init), |
| 78 | std::move(condition), std::move(step), std::move(result)); |
| 79 | } |
| 80 | |
| 81 | Macro MakeAllMacro2() { |
| 82 | auto status_or_macro = Macro::Receiver(CelOperator::ALL, 3, ExpandAllMacro2); |
nothing calls this directly
no test coverage detected