| 85 | } |
| 86 | |
| 87 | absl::optional<Expr> ExpandExistsMacro2(MacroExprFactory& factory, Expr& target, |
| 88 | absl::Span<Expr> args) { |
| 89 | if (args.size() != 3) { |
| 90 | return factory.ReportError("exists() requires 3 arguments"); |
| 91 | } |
| 92 | if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) { |
| 93 | return factory.ReportErrorAt( |
| 94 | args[0], "exists() first variable name must be a simple identifier"); |
| 95 | } |
| 96 | if (!args[1].has_ident_expr() || args[1].ident_expr().name().empty()) { |
| 97 | return factory.ReportErrorAt( |
| 98 | args[1], "exists() second variable name must be a simple identifier"); |
| 99 | } |
| 100 | if (args[0].ident_expr().name() == args[1].ident_expr().name()) { |
| 101 | return factory.ReportErrorAt( |
| 102 | args[0], |
| 103 | "exists() second variable must be different from the first variable"); |
| 104 | } |
| 105 | if (args[0].ident_expr().name() == kAccumulatorVariableName) { |
| 106 | return factory.ReportErrorAt( |
| 107 | args[0], absl::StrCat("exists() first variable name cannot be ", |
| 108 | kAccumulatorVariableName)); |
| 109 | } |
| 110 | if (args[1].ident_expr().name() == kAccumulatorVariableName) { |
| 111 | return factory.ReportErrorAt( |
| 112 | args[1], absl::StrCat("exists() second variable name cannot be ", |
| 113 | kAccumulatorVariableName)); |
| 114 | } |
| 115 | auto init = factory.NewBoolConst(false); |
| 116 | auto condition = factory.NewCall( |
| 117 | CelOperator::NOT_STRICTLY_FALSE, |
| 118 | factory.NewCall(CelOperator::LOGICAL_NOT, factory.NewAccuIdent())); |
| 119 | auto step = factory.NewCall(CelOperator::LOGICAL_OR, factory.NewAccuIdent(), |
| 120 | std::move(args[2])); |
| 121 | auto result = factory.NewAccuIdent(); |
| 122 | return factory.NewComprehension( |
| 123 | args[0].ident_expr().name(), args[1].ident_expr().name(), |
| 124 | std::move(target), factory.AccuVarName(), std::move(init), |
| 125 | std::move(condition), std::move(step), std::move(result)); |
| 126 | } |
| 127 | |
| 128 | Macro MakeExistsMacro2() { |
| 129 | auto status_or_macro = |
nothing calls this directly
no test coverage detected