MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / ExpandMap3Macro

Function ExpandMap3Macro

parser/macro.cc:223–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223absl::optional<Expr> ExpandMap3Macro(MacroExprFactory& factory, Expr& target,
224 absl::Span<Expr> args) {
225 if (args.size() != 3) {
226 return factory.ReportError("map() requires 3 arguments");
227 }
228 if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) {
229 return factory.ReportErrorAt(
230 args[0], "map() variable name must be a simple identifier");
231 }
232 if (args[0].ident_expr().name() == kAccumulatorVariableName) {
233 return factory.ReportErrorAt(args[1],
234 absl::StrCat("map() variable name cannot be ",
235 kAccumulatorVariableName));
236 }
237 auto init = factory.NewList();
238 auto condition = factory.NewBoolConst(true);
239 auto accu_ref = factory.NewAccuIdent();
240 auto accu_update =
241 factory.NewList(factory.NewListElement(std::move(args[2])));
242 auto step = factory.NewCall(CelOperator::ADD, std::move(accu_ref),
243 std::move(accu_update));
244 step = factory.NewCall(CelOperator::CONDITIONAL, std::move(args[1]),
245 std::move(step), factory.NewAccuIdent());
246 return factory.NewComprehension(args[0].ident_expr().name(),
247 std::move(target), factory.AccuVarName(),
248 std::move(init), std::move(condition),
249 std::move(step), factory.NewAccuIdent());
250}
251
252Macro MakeMap3Macro() {
253 auto status_or_macro = Macro::Receiver(CelOperator::MAP, 3, ExpandMap3Macro);

Callers

nothing calls this directly

Calls 13

has_ident_exprMethod · 0.80
NewListElementMethod · 0.80
sizeMethod · 0.45
ReportErrorMethod · 0.45
emptyMethod · 0.45
nameMethod · 0.45
ReportErrorAtMethod · 0.45
NewListMethod · 0.45
NewBoolConstMethod · 0.45
NewAccuIdentMethod · 0.45
NewCallMethod · 0.45
NewComprehensionMethod · 0.45

Tested by

no test coverage detected