| 383 | } |
| 384 | |
| 385 | absl::optional<Expr> ExpandTransformMapEntry3Macro(MacroExprFactory& factory, |
| 386 | Expr& target, |
| 387 | absl::Span<Expr> args) { |
| 388 | if (args.size() != 3) { |
| 389 | return factory.ReportError("transformMapEntry() requires 3 arguments"); |
| 390 | } |
| 391 | if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) { |
| 392 | return factory.ReportErrorAt( |
| 393 | args[0], |
| 394 | "transformMapEntry() first variable name must be a simple identifier"); |
| 395 | } |
| 396 | if (!args[1].has_ident_expr() || args[1].ident_expr().name().empty()) { |
| 397 | return factory.ReportErrorAt( |
| 398 | args[1], |
| 399 | "transformMapEntry() second variable name must be a simple identifier"); |
| 400 | } |
| 401 | if (args[0].ident_expr().name() == args[1].ident_expr().name()) { |
| 402 | return factory.ReportErrorAt(args[0], |
| 403 | "transformMapEntry() second variable must be " |
| 404 | "different from the first variable"); |
| 405 | } |
| 406 | if (args[0].ident_expr().name() == kAccumulatorVariableName) { |
| 407 | return factory.ReportErrorAt( |
| 408 | args[0], |
| 409 | absl::StrCat("transformMapEntry() first variable name cannot be ", |
| 410 | kAccumulatorVariableName)); |
| 411 | } |
| 412 | if (args[1].ident_expr().name() == kAccumulatorVariableName) { |
| 413 | return factory.ReportErrorAt( |
| 414 | args[1], |
| 415 | absl::StrCat("transformMapEntry() second variable name cannot be ", |
| 416 | kAccumulatorVariableName)); |
| 417 | } |
| 418 | std::string iter_var = args[0].ident_expr().name(); |
| 419 | std::string iter_var2 = args[1].ident_expr().name(); |
| 420 | Expr step = factory.NewCall("cel.@mapInsert", factory.NewAccuIdent(), |
| 421 | std::move(args[2])); |
| 422 | return factory.NewComprehension(std::move(iter_var), std::move(iter_var2), |
| 423 | std::move(target), factory.AccuVarName(), |
| 424 | factory.NewMap(), factory.NewBoolConst(true), |
| 425 | std::move(step), factory.NewAccuIdent()); |
| 426 | } |
| 427 | |
| 428 | Macro MakeTransformMap3EntryMacro() { |
| 429 | auto status_or_macro = |
nothing calls this directly
no test coverage detected