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

Function ExpandAllMacro2

extensions/comprehensions_v2_macros.cc:41–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39using ::google::api::expr::common::CelOperator;
40
41absl::optional<Expr> ExpandAllMacro2(MacroExprFactory& factory, Expr& target,
42 absl::Span<Expr> args) {
43 if (args.size() != 3) {
44 return factory.ReportError("all() requires 3 arguments");
45 }
46 if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) {
47 return factory.ReportErrorAt(
48 args[0], "all() first variable name must be a simple identifier");
49 }
50 if (!args[1].has_ident_expr() || args[1].ident_expr().name().empty()) {
51 return factory.ReportErrorAt(
52 args[1], "all() second variable name must be a simple identifier");
53 }
54 if (args[0].ident_expr().name() == args[1].ident_expr().name()) {
55 return factory.ReportErrorAt(
56 args[0],
57 "all() second variable must be different from the first variable");
58 }
59 if (args[0].ident_expr().name() == kAccumulatorVariableName) {
60 return factory.ReportErrorAt(
61 args[0], absl::StrCat("all() first variable name cannot be ",
62 kAccumulatorVariableName));
63 }
64 if (args[1].ident_expr().name() == kAccumulatorVariableName) {
65 return factory.ReportErrorAt(
66 args[1], absl::StrCat("all() second variable name cannot be ",
67 kAccumulatorVariableName));
68 }
69 auto init = factory.NewBoolConst(true);
70 auto condition =
71 factory.NewCall(CelOperator::NOT_STRICTLY_FALSE, factory.NewAccuIdent());
72 auto step = factory.NewCall(CelOperator::LOGICAL_AND, factory.NewAccuIdent(),
73 std::move(args[2]));
74 auto result = factory.NewAccuIdent();
75 return factory.NewComprehension(
76 args[0].ident_expr().name(), args[1].ident_expr().name(),
77 std::move(target), factory.AccuVarName(), std::move(init),
78 std::move(condition), std::move(step), std::move(result));
79}
80
81Macro MakeAllMacro2() {
82 auto status_or_macro = Macro::Receiver(CelOperator::ALL, 3, ExpandAllMacro2);

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected