/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 | | class ExprFactory { |
42 | | protected: |
43 | | // `IsExprLike` determines whether `T` is some `Expr`. Currently that means |
44 | | // either `Expr` or `std::unique_ptr<Expr>`. This allows us to make the |
45 | | // factory functions generic and avoid redefining them for every argument |
46 | | // combination. |
47 | | template <typename T> |
48 | | struct IsExprLike |
49 | | : std::bool_constant<std::disjunction_v< |
50 | | std::is_same<T, Expr>, std::is_same<T, std::unique_ptr<Expr>>>> {}; |
51 | | |
52 | | // `IsStringLike` determines whether `T` is something that looks like a |
53 | | // string. Currently that means `const char*`, `std::string`, or |
54 | | // `absl::string_view`. This allows us to make the factory functions generic |
55 | | // and avoid redefining them for every argument combination. This is necessary |
56 | | // to avoid copies if possible. |
57 | | template <typename T> |
58 | | struct IsStringLike |
59 | | : std::bool_constant<std::disjunction_v< |
60 | | std::is_same<T, char*>, std::is_same<T, const char*>, |
61 | | std::is_same<T, std::string>, std::is_same<T, absl::string_view>>> { |
62 | | }; |
63 | | |
64 | | template <size_t N> |
65 | | struct IsStringLike<const char[N]> : std::true_type {}; |
66 | | |
67 | | // `IsArrayLike` determines whether `T` is something that looks like an array |
68 | | // or span of some element. |
69 | | template <typename Element, typename Array> |
70 | | struct IsArrayLike : std::false_type {}; |
71 | | |
72 | | template <typename Element> |
73 | | struct IsArrayLike<Element, absl::Span<Element>> : std::true_type {}; |
74 | | |
75 | | template <typename Element> |
76 | | struct IsArrayLike<Element, std::vector<Element>> : std::true_type {}; |
77 | | |
78 | | public: |
79 | | ExprFactory(const ExprFactory&) = delete; |
80 | | ExprFactory(ExprFactory&&) = delete; |
81 | | ExprFactory& operator=(const ExprFactory&) = delete; |
82 | | ExprFactory& operator=(ExprFactory&&) = delete; |
83 | | |
84 | 21.6k | virtual ~ExprFactory() = default; |
85 | | |
86 | 8.25M | Expr NewUnspecified(ExprId id) { |
87 | 8.25M | Expr expr; |
88 | 8.25M | expr.set_id(id); |
89 | 8.25M | return expr; |
90 | 8.25M | } |
91 | | |
92 | 1.25M | Expr NewConst(ExprId id, Constant value) { |
93 | 1.25M | Expr expr; |
94 | 1.25M | expr.set_id(id); |
95 | 1.25M | expr.mutable_const_expr() = std::move(value); |
96 | 1.25M | return expr; |
97 | 1.25M | } |
98 | | |
99 | 4.40k | Expr NewNullConst(ExprId id) { |
100 | 4.40k | Constant constant; |
101 | 4.40k | constant.set_null_value(); |
102 | 4.40k | return NewConst(id, std::move(constant)); |
103 | 4.40k | } |
104 | | |
105 | 38.9k | Expr NewBoolConst(ExprId id, bool value) { |
106 | 38.9k | Constant constant; |
107 | 38.9k | constant.set_bool_value(value); |
108 | 38.9k | return NewConst(id, std::move(constant)); |
109 | 38.9k | } |
110 | | |
111 | 768k | Expr NewIntConst(ExprId id, int64_t value) { |
112 | 768k | Constant constant; |
113 | 768k | constant.set_int_value(value); |
114 | 768k | return NewConst(id, std::move(constant)); |
115 | 768k | } |
116 | | |
117 | 16.4k | Expr NewUintConst(ExprId id, uint64_t value) { |
118 | 16.4k | Constant constant; |
119 | 16.4k | constant.set_uint_value(value); |
120 | 16.4k | return NewConst(id, std::move(constant)); |
121 | 16.4k | } |
122 | | |
123 | 91.9k | Expr NewDoubleConst(ExprId id, double value) { |
124 | 91.9k | Constant constant; |
125 | 91.9k | constant.set_double_value(value); |
126 | 91.9k | return NewConst(id, std::move(constant)); |
127 | 91.9k | } |
128 | | |
129 | 0 | Expr NewBytesConst(ExprId id, BytesConstant value) { |
130 | 0 | Constant constant; |
131 | 0 | constant.set_bytes_value(std::move(value)); |
132 | 0 | return NewConst(id, std::move(constant)); |
133 | 0 | } |
134 | | |
135 | 7.00k | Expr NewBytesConst(ExprId id, std::string value) { |
136 | 7.00k | Constant constant; |
137 | 7.00k | constant.set_bytes_value(std::move(value)); |
138 | 7.00k | return NewConst(id, std::move(constant)); |
139 | 7.00k | } |
140 | | |
141 | 0 | Expr NewBytesConst(ExprId id, absl::string_view value) { |
142 | 0 | Constant constant; |
143 | 0 | constant.set_bytes_value(value); |
144 | 0 | return NewConst(id, std::move(constant)); |
145 | 0 | } |
146 | | |
147 | 0 | Expr NewBytesConst(ExprId id, const char* value) { |
148 | 0 | Constant constant; |
149 | 0 | constant.set_bytes_value(value); |
150 | 0 | return NewConst(id, std::move(constant)); |
151 | 0 | } |
152 | | |
153 | 0 | Expr NewStringConst(ExprId id, StringConstant value) { |
154 | 0 | Constant constant; |
155 | 0 | constant.set_string_value(std::move(value)); |
156 | 0 | return NewConst(id, std::move(constant)); |
157 | 0 | } |
158 | | |
159 | 325k | Expr NewStringConst(ExprId id, std::string value) { |
160 | 325k | Constant constant; |
161 | 325k | constant.set_string_value(std::move(value)); |
162 | 325k | return NewConst(id, std::move(constant)); |
163 | 325k | } |
164 | | |
165 | 0 | Expr NewStringConst(ExprId id, absl::string_view value) { |
166 | 0 | Constant constant; |
167 | 0 | constant.set_string_value(value); |
168 | 0 | return NewConst(id, std::move(constant)); |
169 | 0 | } |
170 | | |
171 | 5.15k | Expr NewStringConst(ExprId id, const char* value) { |
172 | 5.15k | Constant constant; |
173 | 5.15k | constant.set_string_value(value); |
174 | 5.15k | return NewConst(id, std::move(constant)); |
175 | 5.15k | } |
176 | | |
177 | | template <typename Name, |
178 | | typename = std::enable_if_t<IsStringLike<Name>::value>> |
179 | 2.85M | Expr NewIdent(ExprId id, Name name) { |
180 | 2.85M | Expr expr; |
181 | 2.85M | expr.set_id(id); |
182 | 2.85M | auto& ident_expr = expr.mutable_ident_expr(); |
183 | 2.85M | ident_expr.set_name(std::move(name)); |
184 | 2.85M | return expr; |
185 | 2.85M | } 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 | 179 | 103k | Expr NewIdent(ExprId id, Name name) { | 180 | 103k | Expr expr; | 181 | 103k | expr.set_id(id); | 182 | 103k | auto& ident_expr = expr.mutable_ident_expr(); | 183 | 103k | ident_expr.set_name(std::move(name)); | 184 | 103k | return expr; | 185 | 103k | } |
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 | 179 | 2.74M | Expr NewIdent(ExprId id, Name name) { | 180 | 2.74M | Expr expr; | 181 | 2.74M | expr.set_id(id); | 182 | 2.74M | auto& ident_expr = expr.mutable_ident_expr(); | 183 | 2.74M | ident_expr.set_name(std::move(name)); | 184 | 2.74M | return expr; | 185 | 2.74M | } |
|
186 | | |
187 | 140k | absl::string_view AccuVarName() { return accu_var_; } |
188 | | |
189 | 103k | Expr NewAccuIdent(ExprId id) { return NewIdent(id, AccuVarName()); } |
190 | | |
191 | | template <typename Operand, typename Field, |
192 | | typename = std::enable_if_t<IsExprLike<Operand>::value>, |
193 | | typename = std::enable_if_t<IsStringLike<Field>::value>> |
194 | 40.5k | Expr NewSelect(ExprId id, Operand operand, Field field) { |
195 | 40.5k | Expr expr; |
196 | 40.5k | expr.set_id(id); |
197 | 40.5k | auto& select_expr = expr.mutable_select_expr(); |
198 | 40.5k | select_expr.set_operand(std::move(operand)); |
199 | 40.5k | select_expr.set_field(std::move(field)); |
200 | 40.5k | select_expr.set_test_only(false); |
201 | 40.5k | return expr; |
202 | 40.5k | } |
203 | | |
204 | | template <typename Operand, typename Field, |
205 | | typename = std::enable_if_t<IsExprLike<Operand>::value>, |
206 | | typename = std::enable_if_t<IsStringLike<Field>::value>> |
207 | 84 | Expr NewPresenceTest(ExprId id, Operand operand, Field field) { |
208 | 84 | Expr expr; |
209 | 84 | expr.set_id(id); |
210 | 84 | auto& select_expr = expr.mutable_select_expr(); |
211 | 84 | select_expr.set_operand(std::move(operand)); |
212 | 84 | select_expr.set_field(std::move(field)); |
213 | 84 | select_expr.set_test_only(true); |
214 | 84 | return expr; |
215 | 84 | } 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 | 207 | 84 | Expr NewPresenceTest(ExprId id, Operand operand, Field field) { | 208 | 84 | Expr expr; | 209 | 84 | expr.set_id(id); | 210 | 84 | auto& select_expr = expr.mutable_select_expr(); | 211 | 84 | select_expr.set_operand(std::move(operand)); | 212 | 84 | select_expr.set_field(std::move(field)); | 213 | 84 | select_expr.set_test_only(true); | 214 | 84 | return expr; | 215 | 84 | } |
|
216 | | |
217 | | template <typename Function, typename Args, |
218 | | typename = std::enable_if_t<IsStringLike<Function>::value>, |
219 | | typename = std::enable_if_t<IsArrayLike<Expr, Args>::value>> |
220 | 3.24M | Expr NewCall(ExprId id, Function function, Args args) { |
221 | 3.24M | Expr expr; |
222 | 3.24M | expr.set_id(id); |
223 | 3.24M | auto& call_expr = expr.mutable_call_expr(); |
224 | 3.24M | call_expr.set_function(std::move(function)); |
225 | 3.24M | call_expr.set_args(std::move(args)); |
226 | 3.24M | return expr; |
227 | 3.24M | } 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 | 220 | 93.6k | Expr NewCall(ExprId id, Function function, Args args) { | 221 | 93.6k | Expr expr; | 222 | 93.6k | expr.set_id(id); | 223 | 93.6k | auto& call_expr = expr.mutable_call_expr(); | 224 | 93.6k | call_expr.set_function(std::move(function)); | 225 | 93.6k | call_expr.set_args(std::move(args)); | 226 | 93.6k | return expr; | 227 | 93.6k | } |
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 | 220 | 416k | Expr NewCall(ExprId id, Function function, Args args) { | 221 | 416k | Expr expr; | 222 | 416k | expr.set_id(id); | 223 | 416k | auto& call_expr = expr.mutable_call_expr(); | 224 | 416k | call_expr.set_function(std::move(function)); | 225 | 416k | call_expr.set_args(std::move(args)); | 226 | 416k | return expr; | 227 | 416k | } |
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 | 220 | 2.73M | Expr NewCall(ExprId id, Function function, Args args) { | 221 | 2.73M | Expr expr; | 222 | 2.73M | expr.set_id(id); | 223 | 2.73M | auto& call_expr = expr.mutable_call_expr(); | 224 | 2.73M | call_expr.set_function(std::move(function)); | 225 | 2.73M | call_expr.set_args(std::move(args)); | 226 | 2.73M | return expr; | 227 | 2.73M | } |
|
228 | | |
229 | | template <typename Function, typename Target, typename Args, |
230 | | typename = std::enable_if_t<IsStringLike<Function>::value>, |
231 | | typename = std::enable_if_t<IsExprLike<Target>::value>, |
232 | | typename = std::enable_if_t<IsArrayLike<Expr, Args>::value>> |
233 | 18.5k | Expr NewMemberCall(ExprId id, Function function, Target target, Args args) { |
234 | 18.5k | Expr expr; |
235 | 18.5k | expr.set_id(id); |
236 | 18.5k | auto& call_expr = expr.mutable_call_expr(); |
237 | 18.5k | call_expr.set_function(std::move(function)); |
238 | 18.5k | call_expr.set_target(std::move(target)); |
239 | 18.5k | call_expr.set_args(std::move(args)); |
240 | 18.5k | return expr; |
241 | 18.5k | } 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 | 233 | 18.5k | Expr NewMemberCall(ExprId id, Function function, Target target, Args args) { | 234 | 18.5k | Expr expr; | 235 | 18.5k | expr.set_id(id); | 236 | 18.5k | auto& call_expr = expr.mutable_call_expr(); | 237 | 18.5k | call_expr.set_function(std::move(function)); | 238 | 18.5k | call_expr.set_target(std::move(target)); | 239 | 18.5k | call_expr.set_args(std::move(args)); | 240 | 18.5k | return expr; | 241 | 18.5k | } |
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> >) |
242 | | |
243 | | template <typename Expr, typename = std::enable_if_t<IsExprLike<Expr>::value>> |
244 | 332k | ListExprElement NewListElement(Expr expr, bool optional = false) { |
245 | 332k | ListExprElement element; |
246 | 332k | element.set_expr(std::move(expr)); |
247 | 332k | element.set_optional(optional); |
248 | 332k | return element; |
249 | 332k | } |
250 | | |
251 | | template <typename Elements, |
252 | | typename = |
253 | | std::enable_if_t<IsArrayLike<ListExprElement, Elements>::value>> |
254 | 51.6k | Expr NewList(ExprId id, Elements elements) { |
255 | 51.6k | Expr expr; |
256 | 51.6k | expr.set_id(id); |
257 | 51.6k | auto& list_expr = expr.mutable_list_expr(); |
258 | 51.6k | list_expr.set_elements(std::move(elements)); |
259 | 51.6k | return expr; |
260 | 51.6k | } |
261 | | |
262 | | template <typename Name, typename Value, |
263 | | typename = std::enable_if_t<IsStringLike<Name>::value>, |
264 | | typename = std::enable_if_t<IsExprLike<Value>::value>> |
265 | | StructExprField NewStructField(ExprId id, Name name, Value value, |
266 | 11.1k | bool optional = false) { |
267 | 11.1k | StructExprField field; |
268 | 11.1k | field.set_id(id); |
269 | 11.1k | field.set_name(std::move(name)); |
270 | 11.1k | field.set_value(std::move(value)); |
271 | 11.1k | field.set_optional(optional); |
272 | 11.1k | return field; |
273 | 11.1k | } |
274 | | |
275 | | template < |
276 | | typename Name, typename Fields, |
277 | | typename = std::enable_if_t<IsStringLike<Name>::value>, |
278 | | typename = std::enable_if_t<IsArrayLike<StructExprField, Fields>::value>> |
279 | 8.31k | Expr NewStruct(ExprId id, Name name, Fields fields) { |
280 | 8.31k | Expr expr; |
281 | 8.31k | expr.set_id(id); |
282 | 8.31k | auto& struct_expr = expr.mutable_struct_expr(); |
283 | 8.31k | struct_expr.set_name(std::move(name)); |
284 | 8.31k | struct_expr.set_fields(std::move(fields)); |
285 | 8.31k | return expr; |
286 | 8.31k | } |
287 | | |
288 | | template <typename Key, typename Value, |
289 | | typename = std::enable_if_t<IsExprLike<Key>::value>, |
290 | | typename = std::enable_if_t<IsExprLike<Value>::value>> |
291 | | MapExprEntry NewMapEntry(ExprId id, Key key, Value value, |
292 | 321k | bool optional = false) { |
293 | 321k | MapExprEntry entry; |
294 | 321k | entry.set_id(id); |
295 | 321k | entry.set_key(std::move(key)); |
296 | 321k | entry.set_value(std::move(value)); |
297 | 321k | entry.set_optional(optional); |
298 | 321k | return entry; |
299 | 321k | } |
300 | | |
301 | | template <typename Entries, typename = std::enable_if_t< |
302 | | IsArrayLike<MapExprEntry, Entries>::value>> |
303 | 13.7k | Expr NewMap(ExprId id, Entries entries) { |
304 | 13.7k | Expr expr; |
305 | 13.7k | expr.set_id(id); |
306 | 13.7k | auto& map_expr = expr.mutable_map_expr(); |
307 | 13.7k | map_expr.set_entries(std::move(entries)); |
308 | 13.7k | return expr; |
309 | 13.7k | } |
310 | | |
311 | | template <typename IterVar, typename IterRange, typename AccuVar, |
312 | | typename AccuInit, typename LoopCondition, typename LoopStep, |
313 | | typename Result, |
314 | | typename = std::enable_if_t<IsStringLike<IterVar>::value>, |
315 | | typename = std::enable_if_t<IsExprLike<IterRange>::value>, |
316 | | typename = std::enable_if_t<IsStringLike<AccuVar>::value>, |
317 | | typename = std::enable_if_t<IsExprLike<AccuInit>::value>, |
318 | | typename = std::enable_if_t<IsExprLike<LoopStep>::value>, |
319 | | typename = std::enable_if_t<IsExprLike<LoopCondition>::value>, |
320 | | typename = std::enable_if_t<IsExprLike<Result>::value>> |
321 | | Expr NewComprehension(ExprId id, IterVar iter_var, IterRange iter_range, |
322 | | AccuVar accu_var, AccuInit accu_init, |
323 | | LoopCondition loop_condition, LoopStep loop_step, |
324 | 36.5k | Result result) { |
325 | 36.5k | return NewComprehension(id, std::move(iter_var), "", std::move(iter_range), |
326 | 36.5k | std::move(accu_var), std::move(accu_init), |
327 | 36.5k | std::move(loop_condition), std::move(loop_step), |
328 | 36.5k | std::move(result)); |
329 | 36.5k | } 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 | 324 | 36.5k | Result result) { | 325 | 36.5k | return NewComprehension(id, std::move(iter_var), "", std::move(iter_range), | 326 | 36.5k | std::move(accu_var), std::move(accu_init), | 327 | 36.5k | std::move(loop_condition), std::move(loop_step), | 328 | 36.5k | std::move(result)); | 329 | 36.5k | } |
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) |
330 | | |
331 | | template <typename IterVar, typename IterVar2, typename IterRange, |
332 | | typename AccuVar, typename AccuInit, typename LoopCondition, |
333 | | typename LoopStep, typename Result, |
334 | | typename = std::enable_if_t<IsStringLike<IterVar>::value>, |
335 | | typename = std::enable_if_t<IsStringLike<IterVar2>::value>, |
336 | | typename = std::enable_if_t<IsExprLike<IterRange>::value>, |
337 | | typename = std::enable_if_t<IsStringLike<AccuVar>::value>, |
338 | | typename = std::enable_if_t<IsExprLike<AccuInit>::value>, |
339 | | typename = std::enable_if_t<IsExprLike<LoopStep>::value>, |
340 | | typename = std::enable_if_t<IsExprLike<LoopCondition>::value>, |
341 | | typename = std::enable_if_t<IsExprLike<Result>::value>> |
342 | | Expr NewComprehension(ExprId id, IterVar iter_var, IterVar2 iter_var2, |
343 | | IterRange iter_range, AccuVar accu_var, |
344 | | AccuInit accu_init, LoopCondition loop_condition, |
345 | 36.5k | LoopStep loop_step, Result result) { |
346 | 36.5k | Expr expr; |
347 | 36.5k | expr.set_id(id); |
348 | 36.5k | auto& comprehension_expr = expr.mutable_comprehension_expr(); |
349 | 36.5k | comprehension_expr.set_iter_var(std::move(iter_var)); |
350 | 36.5k | comprehension_expr.set_iter_var2(std::move(iter_var2)); |
351 | 36.5k | comprehension_expr.set_iter_range(std::move(iter_range)); |
352 | 36.5k | comprehension_expr.set_accu_var(std::move(accu_var)); |
353 | 36.5k | comprehension_expr.set_accu_init(std::move(accu_init)); |
354 | 36.5k | comprehension_expr.set_loop_condition(std::move(loop_condition)); |
355 | 36.5k | comprehension_expr.set_loop_step(std::move(loop_step)); |
356 | 36.5k | comprehension_expr.set_result(std::move(result)); |
357 | 36.5k | return expr; |
358 | 36.5k | } 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 | 345 | 36.5k | LoopStep loop_step, Result result) { | 346 | 36.5k | Expr expr; | 347 | 36.5k | expr.set_id(id); | 348 | 36.5k | auto& comprehension_expr = expr.mutable_comprehension_expr(); | 349 | 36.5k | comprehension_expr.set_iter_var(std::move(iter_var)); | 350 | 36.5k | comprehension_expr.set_iter_var2(std::move(iter_var2)); | 351 | 36.5k | comprehension_expr.set_iter_range(std::move(iter_range)); | 352 | 36.5k | comprehension_expr.set_accu_var(std::move(accu_var)); | 353 | 36.5k | comprehension_expr.set_accu_init(std::move(accu_init)); | 354 | 36.5k | comprehension_expr.set_loop_condition(std::move(loop_condition)); | 355 | 36.5k | comprehension_expr.set_loop_step(std::move(loop_step)); | 356 | 36.5k | comprehension_expr.set_result(std::move(result)); | 357 | 36.5k | return expr; | 358 | 36.5k | } |
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) |
359 | | |
360 | | template <typename NextIdFunc, typename BindVar, typename BindExpr, |
361 | | typename RestExpr, |
362 | | typename = std::enable_if_t< |
363 | | std::is_invocable_r<ExprId, NextIdFunc>::value>, |
364 | | typename = std::enable_if_t<IsStringLike<BindVar>::value>, |
365 | | typename = std::enable_if_t<IsExprLike<BindExpr>::value>, |
366 | | typename = std::enable_if_t<IsExprLike<RestExpr>::value>> |
367 | | Expr NewBind(NextIdFunc next_id, BindVar bind_var, BindExpr bind_expr, |
368 | | RestExpr rest_expr) { |
369 | | Expr expr; |
370 | | expr.set_id(next_id()); |
371 | | auto& comprehension_expr = expr.mutable_comprehension_expr(); |
372 | | comprehension_expr.set_iter_var("#unused"); |
373 | | comprehension_expr.set_iter_range( |
374 | | NewList(next_id(), std::vector<cel::ListExprElement>{})); |
375 | | comprehension_expr.set_accu_var(bind_var); |
376 | | comprehension_expr.set_accu_init(std::move(bind_expr)); |
377 | | comprehension_expr.set_loop_condition(NewBoolConst(next_id(), false)); |
378 | | comprehension_expr.set_loop_step(NewIdent(next_id(), bind_var)); |
379 | | comprehension_expr.set_result(std::move(rest_expr)); |
380 | | return expr; |
381 | | } |
382 | | |
383 | | private: |
384 | | friend class MacroExprFactory; |
385 | | friend class ParserMacroExprFactory; |
386 | | friend class OptimizerExprFactory; |
387 | | friend class tools::ProtoToPredicateBuilder; |
388 | | |
389 | 21.6k | ExprFactory() : accu_var_(kAccumulatorVariableName) {} |
390 | | |
391 | | std::string accu_var_; |
392 | | }; |
393 | | |
394 | | } // namespace cel |
395 | | |
396 | | #endif // THIRD_PARTY_CEL_CPP_COMMON_EXPR_FACTORY_H_ |