| 185 | } |
| 186 | |
| 187 | absl::optional<Expr> ExpandTransformList3Macro(MacroExprFactory& factory, |
| 188 | Expr& target, |
| 189 | absl::Span<Expr> args) { |
| 190 | if (args.size() != 3) { |
| 191 | return factory.ReportError("transformList() requires 3 arguments"); |
| 192 | } |
| 193 | if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) { |
| 194 | return factory.ReportErrorAt( |
| 195 | args[0], |
| 196 | "transformList() first variable name must be a simple identifier"); |
| 197 | } |
| 198 | if (!args[1].has_ident_expr() || args[1].ident_expr().name().empty()) { |
| 199 | return factory.ReportErrorAt( |
| 200 | args[1], |
| 201 | "transformList() second variable name must be a simple identifier"); |
| 202 | } |
| 203 | if (args[0].ident_expr().name() == args[1].ident_expr().name()) { |
| 204 | return factory.ReportErrorAt(args[0], |
| 205 | "transformList() second variable must be " |
| 206 | "different from the first variable"); |
| 207 | } |
| 208 | if (args[0].ident_expr().name() == kAccumulatorVariableName) { |
| 209 | return factory.ReportErrorAt( |
| 210 | args[0], absl::StrCat("transformList() first variable name cannot be ", |
| 211 | kAccumulatorVariableName)); |
| 212 | } |
| 213 | if (args[1].ident_expr().name() == kAccumulatorVariableName) { |
| 214 | return factory.ReportErrorAt( |
| 215 | args[1], absl::StrCat("transformList() second variable name cannot be ", |
| 216 | kAccumulatorVariableName)); |
| 217 | } |
| 218 | std::string iter_var = args[0].ident_expr().name(); |
| 219 | std::string iter_var2 = args[1].ident_expr().name(); |
| 220 | Expr step = factory.NewCall( |
| 221 | CelOperator::ADD, factory.NewAccuIdent(), |
| 222 | factory.NewList(factory.NewListElement(std::move(args[2])))); |
| 223 | return factory.NewComprehension(std::move(iter_var), std::move(iter_var2), |
| 224 | std::move(target), factory.AccuVarName(), |
| 225 | factory.NewList(), factory.NewBoolConst(true), |
| 226 | std::move(step), factory.NewAccuIdent()); |
| 227 | } |
| 228 | |
| 229 | Macro MakeTransformList3Macro() { |
| 230 | auto status_or_macro = |
nothing calls this directly
no test coverage detected