/proc/self/cwd/common/expr_factory.h
Line | Count | Source |
1 | | // Copyright 2024 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef THIRD_PARTY_CEL_CPP_COMMON_EXPR_FACTORY_H_ |
16 | | #define THIRD_PARTY_CEL_CPP_COMMON_EXPR_FACTORY_H_ |
17 | | |
18 | | #include <cstddef> |
19 | | #include <cstdint> |
20 | | #include <memory> |
21 | | #include <string> |
22 | | #include <type_traits> |
23 | | #include <utility> |
24 | | #include <vector> |
25 | | |
26 | | #include "absl/strings/string_view.h" |
27 | | #include "absl/types/span.h" |
28 | | #include "common/constant.h" |
29 | | #include "common/expr.h" |
30 | | |
31 | | namespace cel { |
32 | | |
33 | | class MacroExprFactory; |
34 | | class ParserMacroExprFactory; |
35 | | class OptimizerExprFactory; |
36 | | |
37 | | namespace tools { |
38 | | class ProtoToPredicateBuilder; |
39 | | } |
40 | | |
41 | | namespace parser_internal { |
42 | | template <typename ExprNode> |
43 | | class AstFactoryInterface; |
44 | | } |
45 | | |
46 | | class ExprFactory { |
47 | | protected: |
48 | | // `IsExprLike` determines whether `T` is some `Expr`. Currently that means |
49 | | // either `Expr` or `std::unique_ptr<Expr>`. This allows us to make the |
50 | | // factory functions generic and avoid redefining them for every argument |
51 | | // combination. |
52 | | template <typename T> |
53 | | struct IsExprLike |
54 | | : std::bool_constant<std::disjunction_v< |
55 | | std::is_same<T, Expr>, std::is_same<T, std::unique_ptr<Expr>>>> {}; |
56 | | |
57 | | // `IsStringLike` determines whether `T` is something that looks like a |
58 | | // string. Currently that means `const char*`, `std::string`, or |
59 | | // `absl::string_view`. This allows us to make the factory functions generic |
60 | | // and avoid redefining them for every argument combination. This is necessary |
61 | | // to avoid copies if possible. |
62 | | template <typename T> |
63 | | struct IsStringLike |
64 | | : std::bool_constant<std::disjunction_v< |
65 | | std::is_same<T, char*>, std::is_same<T, const char*>, |
66 | | std::is_same<T, std::string>, std::is_same<T, absl::string_view>>> { |
67 | | }; |
68 | | |
69 | | template <size_t N> |
70 | | struct IsStringLike<const char[N]> : std::true_type {}; |
71 | | |
72 | | // `IsArrayLike` determines whether `T` is something that looks like an array |
73 | | // or span of some element. |
74 | | template <typename Element, typename Array> |
75 | | struct IsArrayLike : std::false_type {}; |
76 | | |
77 | | template <typename Element> |
78 | | struct IsArrayLike<Element, absl::Span<Element>> : std::true_type {}; |
79 | | |
80 | | template <typename Element> |
81 | | struct IsArrayLike<Element, std::vector<Element>> : std::true_type {}; |
82 | | |
83 | | public: |
84 | | ExprFactory(const ExprFactory&) = delete; |
85 | | ExprFactory(ExprFactory&&) = delete; |
86 | | ExprFactory& operator=(const ExprFactory&) = delete; |
87 | | ExprFactory& operator=(ExprFactory&&) = delete; |
88 | | |
89 | 35.3k | virtual ~ExprFactory() = default; |
90 | | |
91 | 1.81M | Expr NewUnspecified(ExprId id) { |
92 | 1.81M | Expr expr; |
93 | 1.81M | expr.set_id(id); |
94 | 1.81M | return expr; |
95 | 1.81M | } |
96 | | |
97 | 1.34M | Expr NewConst(ExprId id, Constant value) { |
98 | 1.34M | Expr expr; |
99 | 1.34M | expr.set_id(id); |
100 | 1.34M | expr.mutable_const_expr() = std::move(value); |
101 | 1.34M | return expr; |
102 | 1.34M | } |
103 | | |
104 | 2.11k | Expr NewNullConst(ExprId id) { |
105 | 2.11k | Constant constant; |
106 | 2.11k | constant.set_null_value(); |
107 | 2.11k | return NewConst(id, std::move(constant)); |
108 | 2.11k | } |
109 | | |
110 | 66.7k | Expr NewBoolConst(ExprId id, bool value) { |
111 | 66.7k | Constant constant; |
112 | 66.7k | constant.set_bool_value(value); |
113 | 66.7k | return NewConst(id, std::move(constant)); |
114 | 66.7k | } |
115 | | |
116 | 927k | Expr NewIntConst(ExprId id, int64_t value) { |
117 | 927k | Constant constant; |
118 | 927k | constant.set_int_value(value); |
119 | 927k | return NewConst(id, std::move(constant)); |
120 | 927k | } |
121 | | |
122 | 13.3k | Expr NewUintConst(ExprId id, uint64_t value) { |
123 | 13.3k | Constant constant; |
124 | 13.3k | constant.set_uint_value(value); |
125 | 13.3k | return NewConst(id, std::move(constant)); |
126 | 13.3k | } |
127 | | |
128 | 52.9k | Expr NewDoubleConst(ExprId id, double value) { |
129 | 52.9k | Constant constant; |
130 | 52.9k | constant.set_double_value(value); |
131 | 52.9k | return NewConst(id, std::move(constant)); |
132 | 52.9k | } |
133 | | |
134 | 0 | Expr NewBytesConst(ExprId id, BytesConstant value) { |
135 | 0 | Constant constant; |
136 | 0 | constant.set_bytes_value(std::move(value)); |
137 | 0 | return NewConst(id, std::move(constant)); |
138 | 0 | } |
139 | | |
140 | 7.60k | Expr NewBytesConst(ExprId id, std::string value) { |
141 | 7.60k | Constant constant; |
142 | 7.60k | constant.set_bytes_value(std::move(value)); |
143 | 7.60k | return NewConst(id, std::move(constant)); |
144 | 7.60k | } |
145 | | |
146 | 0 | Expr NewBytesConst(ExprId id, absl::string_view value) { |
147 | 0 | Constant constant; |
148 | 0 | constant.set_bytes_value(value); |
149 | 0 | return NewConst(id, std::move(constant)); |
150 | 0 | } |
151 | | |
152 | 0 | Expr NewBytesConst(ExprId id, const char* value) { |
153 | 0 | Constant constant; |
154 | 0 | constant.set_bytes_value(value); |
155 | 0 | return NewConst(id, std::move(constant)); |
156 | 0 | } |
157 | | |
158 | 0 | Expr NewStringConst(ExprId id, StringConstant value) { |
159 | 0 | Constant constant; |
160 | 0 | constant.set_string_value(std::move(value)); |
161 | 0 | return NewConst(id, std::move(constant)); |
162 | 0 | } |
163 | | |
164 | 270k | Expr NewStringConst(ExprId id, std::string value) { |
165 | 270k | Constant constant; |
166 | 270k | constant.set_string_value(std::move(value)); |
167 | 270k | return NewConst(id, std::move(constant)); |
168 | 270k | } |
169 | | |
170 | 0 | Expr NewStringConst(ExprId id, absl::string_view value) { |
171 | 0 | Constant constant; |
172 | 0 | constant.set_string_value(value); |
173 | 0 | return NewConst(id, std::move(constant)); |
174 | 0 | } |
175 | | |
176 | 8.67k | Expr NewStringConst(ExprId id, const char* value) { |
177 | 8.67k | Constant constant; |
178 | 8.67k | constant.set_string_value(value); |
179 | 8.67k | return NewConst(id, std::move(constant)); |
180 | 8.67k | } |
181 | | |
182 | | template <typename Name, |
183 | | typename = std::enable_if_t<IsStringLike<Name>::value>> |
184 | 2.92M | Expr NewIdent(ExprId id, Name name) { |
185 | 2.92M | Expr expr; |
186 | 2.92M | expr.set_id(id); |
187 | 2.92M | auto& ident_expr = expr.mutable_ident_expr(); |
188 | 2.92M | ident_expr.set_name(std::move(name)); |
189 | 2.92M | return expr; |
190 | 2.92M | } cel::Expr cel::ExprFactory::NewIdent<std::__1::basic_string_view<char, std::__1::char_traits<char> >, void>(long, std::__1::basic_string_view<char, std::__1::char_traits<char> >) Line | Count | Source | 184 | 102k | Expr NewIdent(ExprId id, Name name) { | 185 | 102k | Expr expr; | 186 | 102k | expr.set_id(id); | 187 | 102k | auto& ident_expr = expr.mutable_ident_expr(); | 188 | 102k | ident_expr.set_name(std::move(name)); | 189 | 102k | return expr; | 190 | 102k | } |
cel::Expr cel::ExprFactory::NewIdent<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>(long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) Line | Count | Source | 184 | 2.82M | Expr NewIdent(ExprId id, Name name) { | 185 | 2.82M | Expr expr; | 186 | 2.82M | expr.set_id(id); | 187 | 2.82M | auto& ident_expr = expr.mutable_ident_expr(); | 188 | 2.82M | ident_expr.set_name(std::move(name)); | 189 | 2.82M | return expr; | 190 | 2.82M | } |
|
191 | | |
192 | 143k | absl::string_view AccuVarName() { return accu_var_; } |
193 | | |
194 | 102k | Expr NewAccuIdent(ExprId id) { return NewIdent(id, AccuVarName()); } |
195 | | |
196 | | template <typename Operand, typename Field, |
197 | | typename = std::enable_if_t<IsExprLike<Operand>::value>, |
198 | | typename = std::enable_if_t<IsStringLike<Field>::value>> |
199 | 50.9k | Expr NewSelect(ExprId id, Operand operand, Field field) { |
200 | 50.9k | Expr expr; |
201 | 50.9k | expr.set_id(id); |
202 | 50.9k | auto& select_expr = expr.mutable_select_expr(); |
203 | 50.9k | select_expr.set_operand(std::move(operand)); |
204 | 50.9k | select_expr.set_field(std::move(field)); |
205 | 50.9k | select_expr.set_test_only(false); |
206 | 50.9k | return expr; |
207 | 50.9k | } |
208 | | |
209 | | template <typename Operand, typename Field, |
210 | | typename = std::enable_if_t<IsExprLike<Operand>::value>, |
211 | | typename = std::enable_if_t<IsStringLike<Field>::value>> |
212 | 6.61k | Expr NewPresenceTest(ExprId id, Operand operand, Field field) { |
213 | 6.61k | Expr expr; |
214 | 6.61k | expr.set_id(id); |
215 | 6.61k | auto& select_expr = expr.mutable_select_expr(); |
216 | 6.61k | select_expr.set_operand(std::move(operand)); |
217 | 6.61k | select_expr.set_field(std::move(field)); |
218 | 6.61k | select_expr.set_test_only(true); |
219 | 6.61k | return expr; |
220 | 6.61k | } Unexecuted instantiation: cel::Expr cel::ExprFactory::NewPresenceTest<cel::Expr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void, void>(long, cel::Expr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) cel::Expr cel::ExprFactory::NewPresenceTest<std::__1::unique_ptr<cel::Expr, std::__1::default_delete<cel::Expr> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void, void>(long, std::__1::unique_ptr<cel::Expr, std::__1::default_delete<cel::Expr> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) Line | Count | Source | 212 | 6.61k | Expr NewPresenceTest(ExprId id, Operand operand, Field field) { | 213 | 6.61k | Expr expr; | 214 | 6.61k | expr.set_id(id); | 215 | 6.61k | auto& select_expr = expr.mutable_select_expr(); | 216 | 6.61k | select_expr.set_operand(std::move(operand)); | 217 | 6.61k | select_expr.set_field(std::move(field)); | 218 | 6.61k | select_expr.set_test_only(true); | 219 | 6.61k | return expr; | 220 | 6.61k | } |
|
221 | | |
222 | | template <typename Function, typename Args, |
223 | | typename = std::enable_if_t<IsStringLike<Function>::value>, |
224 | | typename = std::enable_if_t<IsArrayLike<Expr, Args>::value>> |
225 | 3.23M | Expr NewCall(ExprId id, Function function, Args args) { |
226 | 3.23M | Expr expr; |
227 | 3.23M | expr.set_id(id); |
228 | 3.23M | auto& call_expr = expr.mutable_call_expr(); |
229 | 3.23M | call_expr.set_function(std::move(function)); |
230 | 3.23M | call_expr.set_args(std::move(args)); |
231 | 3.23M | return expr; |
232 | 3.23M | } cel::Expr cel::ExprFactory::NewCall<char const*, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >, void, void>(long, char const*, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >) Line | Count | Source | 225 | 72.1k | Expr NewCall(ExprId id, Function function, Args args) { | 226 | 72.1k | Expr expr; | 227 | 72.1k | expr.set_id(id); | 228 | 72.1k | auto& call_expr = expr.mutable_call_expr(); | 229 | 72.1k | call_expr.set_function(std::move(function)); | 230 | 72.1k | call_expr.set_args(std::move(args)); | 231 | 72.1k | return expr; | 232 | 72.1k | } |
cel::Expr cel::ExprFactory::NewCall<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >, void, void>(long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >) Line | Count | Source | 225 | 239k | Expr NewCall(ExprId id, Function function, Args args) { | 226 | 239k | Expr expr; | 227 | 239k | expr.set_id(id); | 228 | 239k | auto& call_expr = expr.mutable_call_expr(); | 229 | 239k | call_expr.set_function(std::move(function)); | 230 | 239k | call_expr.set_args(std::move(args)); | 231 | 239k | return expr; | 232 | 239k | } |
cel::Expr cel::ExprFactory::NewCall<std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >, void, void>(long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >) Line | Count | Source | 225 | 2.92M | Expr NewCall(ExprId id, Function function, Args args) { | 226 | 2.92M | Expr expr; | 227 | 2.92M | expr.set_id(id); | 228 | 2.92M | auto& call_expr = expr.mutable_call_expr(); | 229 | 2.92M | call_expr.set_function(std::move(function)); | 230 | 2.92M | call_expr.set_args(std::move(args)); | 231 | 2.92M | return expr; | 232 | 2.92M | } |
|
233 | | |
234 | | template <typename Function, typename Target, typename Args, |
235 | | typename = std::enable_if_t<IsStringLike<Function>::value>, |
236 | | typename = std::enable_if_t<IsExprLike<Target>::value>, |
237 | | typename = std::enable_if_t<IsArrayLike<Expr, Args>::value>> |
238 | 13.0k | Expr NewMemberCall(ExprId id, Function function, Target target, Args args) { |
239 | 13.0k | Expr expr; |
240 | 13.0k | expr.set_id(id); |
241 | 13.0k | auto& call_expr = expr.mutable_call_expr(); |
242 | 13.0k | call_expr.set_function(std::move(function)); |
243 | 13.0k | call_expr.set_target(std::move(target)); |
244 | 13.0k | call_expr.set_args(std::move(args)); |
245 | 13.0k | return expr; |
246 | 13.0k | } Unexecuted instantiation: cel::Expr cel::ExprFactory::NewMemberCall<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >, void, void, void>(long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >) cel::Expr cel::ExprFactory::NewMemberCall<std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Expr, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >, void, void, void>(long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Expr, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >) Line | Count | Source | 238 | 13.0k | Expr NewMemberCall(ExprId id, Function function, Target target, Args args) { | 239 | 13.0k | Expr expr; | 240 | 13.0k | expr.set_id(id); | 241 | 13.0k | auto& call_expr = expr.mutable_call_expr(); | 242 | 13.0k | call_expr.set_function(std::move(function)); | 243 | 13.0k | call_expr.set_target(std::move(target)); | 244 | 13.0k | call_expr.set_args(std::move(args)); | 245 | 13.0k | return expr; | 246 | 13.0k | } |
Unexecuted instantiation: cel::Expr cel::ExprFactory::NewMemberCall<char const*, cel::Expr, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >, void, void, void>(long, char const*, cel::Expr, std::__1::vector<cel::Expr, std::__1::allocator<cel::Expr> >) |
247 | | |
248 | | template <typename Expr, typename = std::enable_if_t<IsExprLike<Expr>::value>> |
249 | 494k | ListExprElement NewListElement(Expr expr, bool optional = false) { |
250 | 494k | ListExprElement element; |
251 | 494k | element.set_expr(std::move(expr)); |
252 | 494k | element.set_optional(optional); |
253 | 494k | return element; |
254 | 494k | } |
255 | | |
256 | | template <typename Elements, |
257 | | typename = |
258 | | std::enable_if_t<IsArrayLike<ListExprElement, Elements>::value>> |
259 | 96.7k | Expr NewList(ExprId id, Elements elements) { |
260 | 96.7k | Expr expr; |
261 | 96.7k | expr.set_id(id); |
262 | 96.7k | auto& list_expr = expr.mutable_list_expr(); |
263 | 96.7k | list_expr.set_elements(std::move(elements)); |
264 | 96.7k | return expr; |
265 | 96.7k | } |
266 | | |
267 | | template <typename Name, typename Value, |
268 | | typename = std::enable_if_t<IsStringLike<Name>::value>, |
269 | | typename = std::enable_if_t<IsExprLike<Value>::value>> |
270 | | StructExprField NewStructField(ExprId id, Name name, Value value, |
271 | 17.1k | bool optional = false) { |
272 | 17.1k | StructExprField field; |
273 | 17.1k | field.set_id(id); |
274 | 17.1k | field.set_name(std::move(name)); |
275 | 17.1k | field.set_value(std::move(value)); |
276 | 17.1k | field.set_optional(optional); |
277 | 17.1k | return field; |
278 | 17.1k | } |
279 | | |
280 | | template < |
281 | | typename Name, typename Fields, |
282 | | typename = std::enable_if_t<IsStringLike<Name>::value>, |
283 | | typename = std::enable_if_t<IsArrayLike<StructExprField, Fields>::value>> |
284 | 12.2k | Expr NewStruct(ExprId id, Name name, Fields fields) { |
285 | 12.2k | Expr expr; |
286 | 12.2k | expr.set_id(id); |
287 | 12.2k | auto& struct_expr = expr.mutable_struct_expr(); |
288 | 12.2k | struct_expr.set_name(std::move(name)); |
289 | 12.2k | struct_expr.set_fields(std::move(fields)); |
290 | 12.2k | return expr; |
291 | 12.2k | } |
292 | | |
293 | | template <typename Key, typename Value, |
294 | | typename = std::enable_if_t<IsExprLike<Key>::value>, |
295 | | typename = std::enable_if_t<IsExprLike<Value>::value>> |
296 | | MapExprEntry NewMapEntry(ExprId id, Key key, Value value, |
297 | 265k | bool optional = false) { |
298 | 265k | MapExprEntry entry; |
299 | 265k | entry.set_id(id); |
300 | 265k | entry.set_key(std::move(key)); |
301 | 265k | entry.set_value(std::move(value)); |
302 | 265k | entry.set_optional(optional); |
303 | 265k | return entry; |
304 | 265k | } |
305 | | |
306 | | template <typename Entries, typename = std::enable_if_t< |
307 | | IsArrayLike<MapExprEntry, Entries>::value>> |
308 | 12.1k | Expr NewMap(ExprId id, Entries entries) { |
309 | 12.1k | Expr expr; |
310 | 12.1k | expr.set_id(id); |
311 | 12.1k | auto& map_expr = expr.mutable_map_expr(); |
312 | 12.1k | map_expr.set_entries(std::move(entries)); |
313 | 12.1k | return expr; |
314 | 12.1k | } |
315 | | |
316 | | template <typename IterVar, typename IterRange, typename AccuVar, |
317 | | typename AccuInit, typename LoopCondition, typename LoopStep, |
318 | | typename Result, |
319 | | typename = std::enable_if_t<IsStringLike<IterVar>::value>, |
320 | | typename = std::enable_if_t<IsExprLike<IterRange>::value>, |
321 | | typename = std::enable_if_t<IsStringLike<AccuVar>::value>, |
322 | | typename = std::enable_if_t<IsExprLike<AccuInit>::value>, |
323 | | typename = std::enable_if_t<IsExprLike<LoopStep>::value>, |
324 | | typename = std::enable_if_t<IsExprLike<LoopCondition>::value>, |
325 | | typename = std::enable_if_t<IsExprLike<Result>::value>> |
326 | | Expr NewComprehension(ExprId id, IterVar iter_var, IterRange iter_range, |
327 | | AccuVar accu_var, AccuInit accu_init, |
328 | | LoopCondition loop_condition, LoopStep loop_step, |
329 | 40.3k | Result result) { |
330 | 40.3k | return NewComprehension(id, std::move(iter_var), "", std::move(iter_range), |
331 | 40.3k | std::move(accu_var), std::move(accu_init), |
332 | 40.3k | std::move(loop_condition), std::move(loop_step), |
333 | 40.3k | std::move(result)); |
334 | 40.3k | } Unexecuted instantiation: cel::Expr cel::ExprFactory::NewComprehension<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr, void, void, void, void, void, void, void>(long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr) cel::Expr cel::ExprFactory::NewComprehension<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr, void, void, void, void, void, void, void>(long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr) Line | Count | Source | 329 | 40.3k | Result result) { | 330 | 40.3k | return NewComprehension(id, std::move(iter_var), "", std::move(iter_range), | 331 | 40.3k | std::move(accu_var), std::move(accu_init), | 332 | 40.3k | std::move(loop_condition), std::move(loop_step), | 333 | 40.3k | std::move(result)); | 334 | 40.3k | } |
Unexecuted instantiation: cel::Expr cel::ExprFactory::NewComprehension<char const*, cel::Expr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr, void, void, void, void, void, void, void>(long, char const*, cel::Expr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr) Unexecuted instantiation: cel::Expr cel::ExprFactory::NewComprehension<char const*, cel::Expr, std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr, void, void, void, void, void, void, void>(long, char const*, cel::Expr, std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr) |
335 | | |
336 | | template <typename IterVar, typename IterVar2, typename IterRange, |
337 | | typename AccuVar, typename AccuInit, typename LoopCondition, |
338 | | typename LoopStep, typename Result, |
339 | | typename = std::enable_if_t<IsStringLike<IterVar>::value>, |
340 | | typename = std::enable_if_t<IsStringLike<IterVar2>::value>, |
341 | | typename = std::enable_if_t<IsExprLike<IterRange>::value>, |
342 | | typename = std::enable_if_t<IsStringLike<AccuVar>::value>, |
343 | | typename = std::enable_if_t<IsExprLike<AccuInit>::value>, |
344 | | typename = std::enable_if_t<IsExprLike<LoopStep>::value>, |
345 | | typename = std::enable_if_t<IsExprLike<LoopCondition>::value>, |
346 | | typename = std::enable_if_t<IsExprLike<Result>::value>> |
347 | | Expr NewComprehension(ExprId id, IterVar iter_var, IterVar2 iter_var2, |
348 | | IterRange iter_range, AccuVar accu_var, |
349 | | AccuInit accu_init, LoopCondition loop_condition, |
350 | 40.3k | LoopStep loop_step, Result result) { |
351 | 40.3k | Expr expr; |
352 | 40.3k | expr.set_id(id); |
353 | 40.3k | auto& comprehension_expr = expr.mutable_comprehension_expr(); |
354 | 40.3k | comprehension_expr.set_iter_var(std::move(iter_var)); |
355 | 40.3k | comprehension_expr.set_iter_var2(std::move(iter_var2)); |
356 | 40.3k | comprehension_expr.set_iter_range(std::move(iter_range)); |
357 | 40.3k | comprehension_expr.set_accu_var(std::move(accu_var)); |
358 | 40.3k | comprehension_expr.set_accu_init(std::move(accu_init)); |
359 | 40.3k | comprehension_expr.set_loop_condition(std::move(loop_condition)); |
360 | 40.3k | comprehension_expr.set_loop_step(std::move(loop_step)); |
361 | 40.3k | comprehension_expr.set_result(std::move(result)); |
362 | 40.3k | return expr; |
363 | 40.3k | } Unexecuted instantiation: cel::Expr cel::ExprFactory::NewComprehension<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, char const*, cel::Expr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr, void, void, void, void, void, void, void, void>(long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, char const*, cel::Expr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr) cel::Expr cel::ExprFactory::NewComprehension<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, char const*, cel::Expr, std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr, void, void, void, void, void, void, void, void>(long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, char const*, cel::Expr, std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr) Line | Count | Source | 350 | 40.3k | LoopStep loop_step, Result result) { | 351 | 40.3k | Expr expr; | 352 | 40.3k | expr.set_id(id); | 353 | 40.3k | auto& comprehension_expr = expr.mutable_comprehension_expr(); | 354 | 40.3k | comprehension_expr.set_iter_var(std::move(iter_var)); | 355 | 40.3k | comprehension_expr.set_iter_var2(std::move(iter_var2)); | 356 | 40.3k | comprehension_expr.set_iter_range(std::move(iter_range)); | 357 | 40.3k | comprehension_expr.set_accu_var(std::move(accu_var)); | 358 | 40.3k | comprehension_expr.set_accu_init(std::move(accu_init)); | 359 | 40.3k | comprehension_expr.set_loop_condition(std::move(loop_condition)); | 360 | 40.3k | comprehension_expr.set_loop_step(std::move(loop_step)); | 361 | 40.3k | comprehension_expr.set_result(std::move(result)); | 362 | 40.3k | return expr; | 363 | 40.3k | } |
Unexecuted instantiation: cel::Expr cel::ExprFactory::NewComprehension<char const*, char const*, cel::Expr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr, void, void, void, void, void, void, void, void>(long, char const*, char const*, cel::Expr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr) Unexecuted instantiation: cel::Expr cel::ExprFactory::NewComprehension<char const*, char const*, cel::Expr, std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr, void, void, void, void, void, void, void, void>(long, char const*, char const*, cel::Expr, std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Expr, cel::Expr, cel::Expr, cel::Expr) |
364 | | |
365 | | template <typename NextIdFunc, typename BindVar, typename BindExpr, |
366 | | typename RestExpr, |
367 | | typename = std::enable_if_t< |
368 | | std::is_invocable_r<ExprId, NextIdFunc>::value>, |
369 | | typename = std::enable_if_t<IsStringLike<BindVar>::value>, |
370 | | typename = std::enable_if_t<IsExprLike<BindExpr>::value>, |
371 | | typename = std::enable_if_t<IsExprLike<RestExpr>::value>> |
372 | | Expr NewBind(NextIdFunc next_id, BindVar bind_var, BindExpr bind_expr, |
373 | | RestExpr rest_expr) { |
374 | | Expr expr; |
375 | | expr.set_id(next_id()); |
376 | | auto& comprehension_expr = expr.mutable_comprehension_expr(); |
377 | | comprehension_expr.set_iter_var("#unused"); |
378 | | comprehension_expr.set_iter_range( |
379 | | NewList(next_id(), std::vector<cel::ListExprElement>{})); |
380 | | comprehension_expr.set_accu_var(bind_var); |
381 | | comprehension_expr.set_accu_init(std::move(bind_expr)); |
382 | | comprehension_expr.set_loop_condition(NewBoolConst(next_id(), false)); |
383 | | comprehension_expr.set_loop_step(NewIdent(next_id(), bind_var)); |
384 | | comprehension_expr.set_result(std::move(rest_expr)); |
385 | | return expr; |
386 | | } |
387 | | |
388 | | private: |
389 | | friend class MacroExprFactory; |
390 | | friend class ParserMacroExprFactory; |
391 | | friend class OptimizerExprFactory; |
392 | | friend class tools::ProtoToPredicateBuilder; |
393 | | friend class parser_internal::AstFactoryInterface<Expr>; |
394 | | |
395 | 35.3k | ExprFactory() : accu_var_(kAccumulatorVariableName) {} |
396 | | |
397 | | std::string accu_var_; |
398 | | }; |
399 | | |
400 | | } // namespace cel |
401 | | |
402 | | #endif // THIRD_PARTY_CEL_CPP_COMMON_EXPR_FACTORY_H_ |