| 333 | } |
| 334 | |
| 335 | absl::optional<Expr> ExpandTransformMap4Macro(MacroExprFactory& factory, |
| 336 | Expr& target, |
| 337 | absl::Span<Expr> args) { |
| 338 | if (args.size() != 4) { |
| 339 | return factory.ReportError("transformMap() requires 4 arguments"); |
| 340 | } |
| 341 | if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) { |
| 342 | return factory.ReportErrorAt( |
| 343 | args[0], |
| 344 | "transformMap() first variable name must be a simple identifier"); |
| 345 | } |
| 346 | if (!args[1].has_ident_expr() || args[1].ident_expr().name().empty()) { |
| 347 | return factory.ReportErrorAt( |
| 348 | args[1], |
| 349 | "transformMap() second variable name must be a simple identifier"); |
| 350 | } |
| 351 | if (args[0].ident_expr().name() == args[1].ident_expr().name()) { |
| 352 | return factory.ReportErrorAt(args[0], |
| 353 | "transformMap() second variable must be " |
| 354 | "different from the first variable"); |
| 355 | } |
| 356 | if (args[0].ident_expr().name() == kAccumulatorVariableName) { |
| 357 | return factory.ReportErrorAt( |
| 358 | args[0], absl::StrCat("transformMap() first variable name cannot be ", |
| 359 | kAccumulatorVariableName)); |
| 360 | } |
| 361 | if (args[1].ident_expr().name() == kAccumulatorVariableName) { |
| 362 | return factory.ReportErrorAt( |
| 363 | args[1], absl::StrCat("transformMap() second variable name cannot be ", |
| 364 | kAccumulatorVariableName)); |
| 365 | } |
| 366 | std::string iter_var = args[0].ident_expr().name(); |
| 367 | std::string iter_var2 = args[1].ident_expr().name(); |
| 368 | Expr step = factory.NewCall("cel.@mapInsert", factory.NewAccuIdent(), |
| 369 | std::move(args[0]), std::move(args[3])); |
| 370 | step = factory.NewCall(CelOperator::CONDITIONAL, std::move(args[2]), |
| 371 | std::move(step), factory.NewAccuIdent()); |
| 372 | return factory.NewComprehension(std::move(iter_var), std::move(iter_var2), |
| 373 | std::move(target), factory.AccuVarName(), |
| 374 | factory.NewMap(), factory.NewBoolConst(true), |
| 375 | std::move(step), factory.NewAccuIdent()); |
| 376 | } |
| 377 | |
| 378 | Macro MakeTransformMap4Macro() { |
| 379 | auto status_or_macro = |
nothing calls this directly
no test coverage detected