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

Function MakeSelectPathExpr

extensions/select_optimization.cc:107–151  ·  view source on GitHub ↗

Generates the AST representation of the qualification path for the optimized select branch. I.e., the list-typed second argument of the cel.@attribute call.

Source from the content-addressed store, hash-verified

105// select branch. I.e., the list-typed second argument of the cel.@attribute
106// call.
107Expr MakeSelectPathExpr(
108 const std::vector<QualifierInstruction>& select_instructions) {
109 Expr result;
110 auto& ast_list = result.mutable_list_expr().mutable_elements();
111 ast_list.reserve(select_instructions.size());
112 auto visitor = absl::Overload(
113 [&](const SelectInstruction& instruction) {
114 Expr ast_instruction;
115 Expr field_number;
116 field_number.mutable_const_expr().set_int64_value(instruction.number);
117 Expr field_name;
118 field_name.mutable_const_expr().set_string_value(instruction.name);
119 auto& field_specifier =
120 ast_instruction.mutable_list_expr().mutable_elements();
121 field_specifier.emplace_back().set_expr(std::move(field_number));
122 field_specifier.emplace_back().set_expr(std::move(field_name));
123
124 ast_list.emplace_back().set_expr(std::move(ast_instruction));
125 },
126 [&](absl::string_view instruction) {
127 Expr const_expr;
128 const_expr.mutable_const_expr().set_string_value(instruction);
129 ast_list.emplace_back().set_expr(std::move(const_expr));
130 },
131 [&](int64_t instruction) {
132 Expr const_expr;
133 const_expr.mutable_const_expr().set_int64_value(instruction);
134 ast_list.emplace_back().set_expr(std::move(const_expr));
135 },
136 [&](uint64_t instruction) {
137 Expr const_expr;
138 const_expr.mutable_const_expr().set_uint64_value(instruction);
139 ast_list.emplace_back().set_expr(std::move(const_expr));
140 },
141 [&](bool instruction) {
142 Expr const_expr;
143 const_expr.mutable_const_expr().set_bool_value(instruction);
144 ast_list.emplace_back().set_expr(std::move(const_expr));
145 });
146
147 for (const auto& instruction : select_instructions) {
148 absl::visit(visitor, instruction);
149 }
150 return result;
151}
152
153// Returns a single select operation based on the inferred type of the operand
154// and the field name. If the operand type doesn't define the field, returns

Callers 1

PostVisitRewriteMethod · 0.85

Calls 2

set_exprMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected