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

Function ExpandTransformList3Macro

extensions/comprehensions_v2_macros.cc:187–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187absl::optional<Expr> ExpandTransformList3Macro(MacroExprFactory& factory,
188 Expr& target,
189 absl::Span<Expr> args) {
190 if (args.size() != 3) {
191 return factory.ReportError("transformList() requires 3 arguments");
192 }
193 if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) {
194 return factory.ReportErrorAt(
195 args[0],
196 "transformList() first variable name must be a simple identifier");
197 }
198 if (!args[1].has_ident_expr() || args[1].ident_expr().name().empty()) {
199 return factory.ReportErrorAt(
200 args[1],
201 "transformList() second variable name must be a simple identifier");
202 }
203 if (args[0].ident_expr().name() == args[1].ident_expr().name()) {
204 return factory.ReportErrorAt(args[0],
205 "transformList() second variable must be "
206 "different from the first variable");
207 }
208 if (args[0].ident_expr().name() == kAccumulatorVariableName) {
209 return factory.ReportErrorAt(
210 args[0], absl::StrCat("transformList() first variable name cannot be ",
211 kAccumulatorVariableName));
212 }
213 if (args[1].ident_expr().name() == kAccumulatorVariableName) {
214 return factory.ReportErrorAt(
215 args[1], absl::StrCat("transformList() second variable name cannot be ",
216 kAccumulatorVariableName));
217 }
218 std::string iter_var = args[0].ident_expr().name();
219 std::string iter_var2 = args[1].ident_expr().name();
220 Expr step = factory.NewCall(
221 CelOperator::ADD, factory.NewAccuIdent(),
222 factory.NewList(factory.NewListElement(std::move(args[2]))));
223 return factory.NewComprehension(std::move(iter_var), std::move(iter_var2),
224 std::move(target), factory.AccuVarName(),
225 factory.NewList(), factory.NewBoolConst(true),
226 std::move(step), factory.NewAccuIdent());
227}
228
229Macro MakeTransformList3Macro() {
230 auto status_or_macro =

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
NewCallMethod · 0.45
NewAccuIdentMethod · 0.45
NewListMethod · 0.45
NewComprehensionMethod · 0.45
AccuVarNameMethod · 0.45

Tested by

no test coverage detected