| 285 | } |
| 286 | |
| 287 | absl::optional<Expr> ExpandTransformMap3Macro(MacroExprFactory& factory, |
| 288 | Expr& target, |
| 289 | absl::Span<Expr> args) { |
| 290 | if (args.size() != 3) { |
| 291 | return factory.ReportError("transformMap() requires 3 arguments"); |
| 292 | } |
| 293 | if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) { |
| 294 | return factory.ReportErrorAt( |
| 295 | args[0], |
| 296 | "transformMap() first variable name must be a simple identifier"); |
| 297 | } |
| 298 | if (!args[1].has_ident_expr() || args[1].ident_expr().name().empty()) { |
| 299 | return factory.ReportErrorAt( |
| 300 | args[1], |
| 301 | "transformMap() second variable name must be a simple identifier"); |
| 302 | } |
| 303 | if (args[0].ident_expr().name() == args[1].ident_expr().name()) { |
| 304 | return factory.ReportErrorAt(args[0], |
| 305 | "transformMap() second variable must be " |
| 306 | "different from the first variable"); |
| 307 | } |
| 308 | if (args[0].ident_expr().name() == kAccumulatorVariableName) { |
| 309 | return factory.ReportErrorAt( |
| 310 | args[0], absl::StrCat("transformMap() first variable name cannot be ", |
| 311 | kAccumulatorVariableName)); |
| 312 | } |
| 313 | if (args[1].ident_expr().name() == kAccumulatorVariableName) { |
| 314 | return factory.ReportErrorAt( |
| 315 | args[1], absl::StrCat("transformMap() second variable name cannot be ", |
| 316 | kAccumulatorVariableName)); |
| 317 | } |
| 318 | std::string iter_var = args[0].ident_expr().name(); |
| 319 | std::string iter_var2 = args[1].ident_expr().name(); |
| 320 | Expr step = factory.NewCall("cel.@mapInsert", factory.NewAccuIdent(), |
| 321 | std::move(args[0]), std::move(args[2])); |
| 322 | return factory.NewComprehension(std::move(iter_var), std::move(iter_var2), |
| 323 | std::move(target), factory.AccuVarName(), |
| 324 | factory.NewMap(), factory.NewBoolConst(true), |
| 325 | std::move(step), factory.NewAccuIdent()); |
| 326 | } |
| 327 | |
| 328 | Macro MakeTransformMap3Macro() { |
| 329 | auto status_or_macro = |
nothing calls this directly
no test coverage detected