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

Function ExpandExistsMacro2

extensions/comprehensions_v2_macros.cc:87–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87absl::optional<Expr> ExpandExistsMacro2(MacroExprFactory& factory, Expr& target,
88 absl::Span<Expr> args) {
89 if (args.size() != 3) {
90 return factory.ReportError("exists() requires 3 arguments");
91 }
92 if (!args[0].has_ident_expr() || args[0].ident_expr().name().empty()) {
93 return factory.ReportErrorAt(
94 args[0], "exists() first variable name must be a simple identifier");
95 }
96 if (!args[1].has_ident_expr() || args[1].ident_expr().name().empty()) {
97 return factory.ReportErrorAt(
98 args[1], "exists() second variable name must be a simple identifier");
99 }
100 if (args[0].ident_expr().name() == args[1].ident_expr().name()) {
101 return factory.ReportErrorAt(
102 args[0],
103 "exists() second variable must be different from the first variable");
104 }
105 if (args[0].ident_expr().name() == kAccumulatorVariableName) {
106 return factory.ReportErrorAt(
107 args[0], absl::StrCat("exists() first variable name cannot be ",
108 kAccumulatorVariableName));
109 }
110 if (args[1].ident_expr().name() == kAccumulatorVariableName) {
111 return factory.ReportErrorAt(
112 args[1], absl::StrCat("exists() second variable name cannot be ",
113 kAccumulatorVariableName));
114 }
115 auto init = factory.NewBoolConst(false);
116 auto condition = factory.NewCall(
117 CelOperator::NOT_STRICTLY_FALSE,
118 factory.NewCall(CelOperator::LOGICAL_NOT, factory.NewAccuIdent()));
119 auto step = factory.NewCall(CelOperator::LOGICAL_OR, factory.NewAccuIdent(),
120 std::move(args[2]));
121 auto result = factory.NewAccuIdent();
122 return factory.NewComprehension(
123 args[0].ident_expr().name(), args[1].ident_expr().name(),
124 std::move(target), factory.AccuVarName(), std::move(init),
125 std::move(condition), std::move(step), std::move(result));
126}
127
128Macro MakeExistsMacro2() {
129 auto status_or_macro =

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