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.
| 105 | // select branch. I.e., the list-typed second argument of the cel.@attribute |
| 106 | // call. |
| 107 | Expr 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 |
no test coverage detected