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