| 234 | } |
| 235 | |
| 236 | absl::optional<Expr> ExpandTransformList4Macro(MacroExprFactory& factory, |
| 237 | Expr& target, |
| 238 | absl::Span<Expr> args) { |
| 239 | if (args.size() != 4) { |
| 240 | return factory.ReportError("transformList() requires 4 arguments"); |
| 241 | } |
| 242 | if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) { |
| 243 | return factory.ReportErrorAt( |
| 244 | args[0], |
| 245 | "transformList() first variable name must be a simple identifier"); |
| 246 | } |
| 247 | if (!args[1].has_ident_expr() || args[1].ident_expr().name().empty()) { |
| 248 | return factory.ReportErrorAt( |
| 249 | args[1], |
| 250 | "transformList() second variable name must be a simple identifier"); |
| 251 | } |
| 252 | if (args[0].ident_expr().name() == args[1].ident_expr().name()) { |
| 253 | return factory.ReportErrorAt(args[0], |
| 254 | "transformList() second variable must be " |
| 255 | "different from the first variable"); |
| 256 | } |
| 257 | if (args[0].ident_expr().name() == kAccumulatorVariableName) { |
| 258 | return factory.ReportErrorAt( |
| 259 | args[0], absl::StrCat("transformList() first variable name cannot be ", |
| 260 | kAccumulatorVariableName)); |
| 261 | } |
| 262 | if (args[1].ident_expr().name() == kAccumulatorVariableName) { |
| 263 | return factory.ReportErrorAt( |
| 264 | args[1], absl::StrCat("transformList() second variable name cannot be ", |
| 265 | kAccumulatorVariableName)); |
| 266 | } |
| 267 | std::string iter_var = args[0].ident_expr().name(); |
| 268 | std::string iter_var2 = args[1].ident_expr().name(); |
| 269 | Expr step = factory.NewCall( |
| 270 | CelOperator::ADD, factory.NewAccuIdent(), |
| 271 | factory.NewList(factory.NewListElement(std::move(args[3])))); |
| 272 | step = factory.NewCall(CelOperator::CONDITIONAL, std::move(args[2]), |
| 273 | std::move(step), factory.NewAccuIdent()); |
| 274 | return factory.NewComprehension(std::move(iter_var), std::move(iter_var2), |
| 275 | std::move(target), factory.AccuVarName(), |
| 276 | factory.NewList(), factory.NewBoolConst(true), |
| 277 | std::move(step), factory.NewAccuIdent()); |
| 278 | } |
| 279 | |
| 280 | Macro MakeTransformList4Macro() { |
| 281 | auto status_or_macro = |
nothing calls this directly
no test coverage detected