/proc/self/cwd/common/expr.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_H_ |
16 | | #define THIRD_PARTY_CEL_CPP_COMMON_EXPR_H_ |
17 | | |
18 | | #include <cstdint> |
19 | | #include <memory> |
20 | | #include <string> |
21 | | #include <utility> |
22 | | #include <vector> |
23 | | |
24 | | #include "absl/algorithm/container.h" |
25 | | #include "absl/base/attributes.h" |
26 | | #include "absl/strings/string_view.h" |
27 | | #include "absl/types/span.h" |
28 | | #include "absl/types/variant.h" |
29 | | #include "common/constant.h" |
30 | | |
31 | | namespace cel { |
32 | | |
33 | | using ExprId = int64_t; |
34 | | |
35 | | class Expr; |
36 | | class UnspecifiedExpr; |
37 | | class IdentExpr; |
38 | | class SelectExpr; |
39 | | class CallExpr; |
40 | | class ListExprElement; |
41 | | class ListExpr; |
42 | | class StructExprField; |
43 | | class StructExpr; |
44 | | class MapExprEntry; |
45 | | class MapExpr; |
46 | | class ComprehensionExpr; |
47 | | |
48 | | inline constexpr absl::string_view kAccumulatorVariableName = "@result"; |
49 | | inline constexpr absl::string_view kDeprecatedAccumulatorVariableName = |
50 | | "__result__"; |
51 | | |
52 | | bool operator==(const Expr& lhs, const Expr& rhs); |
53 | | |
54 | 0 | inline bool operator!=(const Expr& lhs, const Expr& rhs) { |
55 | 0 | return !operator==(lhs, rhs); |
56 | 0 | } |
57 | | |
58 | | bool operator==(const ListExprElement& lhs, const ListExprElement& rhs); |
59 | | |
60 | 0 | inline bool operator!=(const ListExprElement& lhs, const ListExprElement& rhs) { |
61 | 0 | return !operator==(lhs, rhs); |
62 | 0 | } |
63 | | |
64 | | bool operator==(const StructExprField& lhs, const StructExprField& rhs); |
65 | | |
66 | 0 | inline bool operator!=(const StructExprField& lhs, const StructExprField& rhs) { |
67 | 0 | return !operator==(lhs, rhs); |
68 | 0 | } |
69 | | |
70 | | bool operator==(const MapExprEntry& lhs, const MapExprEntry& rhs); |
71 | | |
72 | 0 | inline bool operator!=(const MapExprEntry& lhs, const MapExprEntry& rhs) { |
73 | 0 | return !operator==(lhs, rhs); |
74 | 0 | } |
75 | | |
76 | | // `UnspecifiedExpr` is the default alternative of `Expr`. It is used for |
77 | | // default construction of `Expr` or as a placeholder for when errors occur. |
78 | | class UnspecifiedExpr final { |
79 | | public: |
80 | | UnspecifiedExpr() = default; |
81 | | UnspecifiedExpr(UnspecifiedExpr&&) = default; |
82 | | UnspecifiedExpr& operator=(UnspecifiedExpr&&) = default; |
83 | | |
84 | | UnspecifiedExpr(const UnspecifiedExpr&) = delete; |
85 | | UnspecifiedExpr& operator=(const UnspecifiedExpr&) = delete; |
86 | | |
87 | 0 | void Clear() {} |
88 | | |
89 | 0 | friend void swap(UnspecifiedExpr&, UnspecifiedExpr&) noexcept {} |
90 | | |
91 | | private: |
92 | | friend class Expr; |
93 | | |
94 | | static const UnspecifiedExpr& default_instance(); |
95 | | }; |
96 | | |
97 | 0 | inline bool operator==(const UnspecifiedExpr&, const UnspecifiedExpr&) { |
98 | 0 | return true; |
99 | 0 | } |
100 | | |
101 | 0 | inline bool operator!=(const UnspecifiedExpr& lhs, const UnspecifiedExpr& rhs) { |
102 | 0 | return !operator==(lhs, rhs); |
103 | 0 | } |
104 | | |
105 | | // `IdentExpr` is an alternative of `Expr`, representing an identifier. |
106 | | class IdentExpr final { |
107 | | public: |
108 | 2.23M | IdentExpr() = default; |
109 | 7.38M | IdentExpr(IdentExpr&&) = default; |
110 | 17.8k | IdentExpr& operator=(IdentExpr&&) = default; |
111 | | |
112 | 0 | explicit IdentExpr(std::string name) { set_name(std::move(name)); } |
113 | | |
114 | 0 | explicit IdentExpr(absl::string_view name) { set_name(name); } |
115 | | |
116 | 0 | explicit IdentExpr(const char* name) { set_name(name); } |
117 | | |
118 | | IdentExpr(const IdentExpr&) = delete; |
119 | | IdentExpr& operator=(const IdentExpr&) = delete; |
120 | | |
121 | 0 | void Clear() { name_.clear(); } |
122 | | |
123 | | // Holds a single, unqualified identifier, possibly preceded by a '.'. |
124 | | // |
125 | | // Qualified names are represented by the [Expr.Select][] expression. |
126 | | ABSL_MUST_USE_RESULT const std::string& name() const |
127 | 1.12M | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
128 | 1.12M | return name_; |
129 | 1.12M | } |
130 | | |
131 | 2.15M | void set_name(std::string name) { name_ = std::move(name); } |
132 | | |
133 | 79.0k | void set_name(absl::string_view name) { |
134 | 79.0k | name_.assign(name.data(), name.size()); |
135 | 79.0k | } |
136 | | |
137 | 0 | void set_name(const char* name) { set_name(absl::NullSafeStringView(name)); } |
138 | | |
139 | 0 | ABSL_MUST_USE_RESULT std::string release_name() { return release(name_); } |
140 | | |
141 | 0 | friend void swap(IdentExpr& lhs, IdentExpr& rhs) noexcept { |
142 | 0 | using std::swap; |
143 | 0 | swap(lhs.name_, rhs.name_); |
144 | 0 | } |
145 | | |
146 | | private: |
147 | | friend class Expr; |
148 | | |
149 | | static const IdentExpr& default_instance(); |
150 | | |
151 | 0 | static std::string release(std::string& property) { |
152 | 0 | std::string result; |
153 | 0 | result.swap(property); |
154 | 0 | return result; |
155 | 0 | } |
156 | | |
157 | | std::string name_; |
158 | | }; |
159 | | |
160 | 0 | inline bool operator==(const IdentExpr& lhs, const IdentExpr& rhs) { |
161 | 0 | return lhs.name() == rhs.name(); |
162 | 0 | } |
163 | | |
164 | 0 | inline bool operator!=(const IdentExpr& lhs, const IdentExpr& rhs) { |
165 | 0 | return !operator==(lhs, rhs); |
166 | 0 | } |
167 | | |
168 | | // `SelectExpr` is an alternative of `Expr`, representing field access. |
169 | | class SelectExpr final { |
170 | | public: |
171 | 58.1k | SelectExpr() = default; |
172 | 168k | SelectExpr(SelectExpr&&) = default; |
173 | 0 | SelectExpr& operator=(SelectExpr&&) = default; |
174 | | |
175 | | SelectExpr(const SelectExpr&) = delete; |
176 | | SelectExpr& operator=(const SelectExpr&) = delete; |
177 | | |
178 | | void Clear(); |
179 | | |
180 | 199k | ABSL_MUST_USE_RESULT bool has_operand() const { return operand_ != nullptr; } |
181 | | |
182 | | // The target of the selection expression. |
183 | | // |
184 | | // For example, in the select expression `request.auth`, the `request` |
185 | | // portion of the expression is the `operand`. |
186 | | ABSL_MUST_USE_RESULT const Expr& operand() const |
187 | | ABSL_ATTRIBUTE_LIFETIME_BOUND; |
188 | | |
189 | | Expr& mutable_operand() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
190 | | |
191 | | void set_operand(Expr operand); |
192 | | |
193 | | void set_operand(std::unique_ptr<Expr> operand); |
194 | | |
195 | | ABSL_MUST_USE_RESULT std::unique_ptr<Expr> release_operand(); |
196 | | |
197 | | // The name of the field to select. |
198 | | // |
199 | | // For example, in the select expression `request.auth`, the `auth` portion |
200 | | // of the expression would be the `field`. |
201 | | ABSL_MUST_USE_RESULT const std::string& field() const |
202 | 262k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
203 | 262k | return field_; |
204 | 262k | } |
205 | | |
206 | 58.1k | void set_field(std::string field) { field_ = std::move(field); } |
207 | | |
208 | 0 | void set_field(absl::string_view field) { |
209 | 0 | field_.assign(field.data(), field.size()); |
210 | 0 | } |
211 | | |
212 | 0 | void set_field(const char* field) { |
213 | 0 | set_field(absl::NullSafeStringView(field)); |
214 | 0 | } |
215 | | |
216 | 48 | ABSL_MUST_USE_RESULT std::string release_field() { return release(field_); } |
217 | | |
218 | | // Whether the select is to be interpreted as a field presence test. |
219 | | // |
220 | | // This results from the macro `has(request.auth)`. |
221 | 53.7k | ABSL_MUST_USE_RESULT bool test_only() const { return test_only_; } |
222 | | |
223 | 58.1k | void set_test_only(bool test_only) { test_only_ = test_only; } |
224 | | |
225 | 0 | friend void swap(SelectExpr& lhs, SelectExpr& rhs) noexcept { |
226 | 0 | using std::swap; |
227 | 0 | swap(lhs.operand_, rhs.operand_); |
228 | 0 | swap(lhs.field_, rhs.field_); |
229 | 0 | swap(lhs.test_only_, rhs.test_only_); |
230 | 0 | } |
231 | | |
232 | | private: |
233 | | friend class Expr; |
234 | | |
235 | | static const SelectExpr& default_instance(); |
236 | | |
237 | 48 | static std::string release(std::string& property) { |
238 | 48 | std::string result; |
239 | 48 | result.swap(property); |
240 | 48 | return result; |
241 | 48 | } |
242 | | |
243 | | static std::unique_ptr<Expr> release(std::unique_ptr<Expr>& property); |
244 | | |
245 | | std::unique_ptr<Expr> operand_; |
246 | | std::string field_; |
247 | | bool test_only_ = false; |
248 | | }; |
249 | | |
250 | 0 | inline bool operator==(const SelectExpr& lhs, const SelectExpr& rhs) { |
251 | 0 | return lhs.operand() == rhs.operand() && lhs.field() == rhs.field() && |
252 | 0 | lhs.test_only() == rhs.test_only(); |
253 | 0 | } |
254 | | |
255 | 0 | inline bool operator!=(const SelectExpr& lhs, const SelectExpr& rhs) { |
256 | 0 | return !operator==(lhs, rhs); |
257 | 0 | } |
258 | | |
259 | | // `CallExpr` is an alternative of `Expr`, representing a function call. |
260 | | class CallExpr final { |
261 | | public: |
262 | 2.76M | CallExpr() = default; |
263 | 7.75M | CallExpr(CallExpr&&) = default; |
264 | 6.49k | CallExpr& operator=(CallExpr&&) = default; |
265 | | |
266 | | CallExpr(const CallExpr&) = delete; |
267 | | CallExpr& operator=(const CallExpr&) = delete; |
268 | | |
269 | | void Clear(); |
270 | | |
271 | | // The name of the function or method being called. |
272 | | ABSL_MUST_USE_RESULT const std::string& function() const |
273 | 2.18M | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
274 | 2.18M | return function_; |
275 | 2.18M | } |
276 | | |
277 | 402k | void set_function(std::string function) { function_ = std::move(function); } |
278 | | |
279 | 2.36M | void set_function(absl::string_view function) { |
280 | 2.36M | function_.assign(function.data(), function.size()); |
281 | 2.36M | } |
282 | | |
283 | 73.5k | void set_function(const char* function) { |
284 | 73.5k | set_function(absl::NullSafeStringView(function)); |
285 | 73.5k | } |
286 | | |
287 | 0 | ABSL_MUST_USE_RESULT std::string release_function() { |
288 | 0 | return release(function_); |
289 | 0 | } |
290 | | |
291 | 1.92M | ABSL_MUST_USE_RESULT bool has_target() const { return target_ != nullptr; } |
292 | | |
293 | | // The target of an method call-style expression. For example, `x` in `x.f()`. |
294 | | ABSL_MUST_USE_RESULT const Expr& target() const ABSL_ATTRIBUTE_LIFETIME_BOUND; |
295 | | |
296 | | Expr& mutable_target() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
297 | | |
298 | | void set_target(Expr target); |
299 | | |
300 | | void set_target(std::unique_ptr<Expr> target); |
301 | | |
302 | | ABSL_MUST_USE_RESULT std::unique_ptr<Expr> release_target(); |
303 | | |
304 | | // The arguments. |
305 | | ABSL_MUST_USE_RESULT const std::vector<Expr>& args() const |
306 | 4.30M | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
307 | 4.30M | return args_; |
308 | 4.30M | } |
309 | | |
310 | | ABSL_MUST_USE_RESULT std::vector<Expr>& mutable_args() |
311 | 485k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
312 | 485k | return args_; |
313 | 485k | } |
314 | | |
315 | | void set_args(std::vector<Expr> args); |
316 | | |
317 | | void set_args(absl::Span<Expr> args); |
318 | | |
319 | | Expr& add_args() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
320 | | |
321 | | ABSL_MUST_USE_RESULT std::vector<Expr> release_args(); |
322 | | |
323 | 0 | friend void swap(CallExpr& lhs, CallExpr& rhs) noexcept { |
324 | 0 | using std::swap; |
325 | 0 | swap(lhs.function_, rhs.function_); |
326 | 0 | swap(lhs.target_, rhs.target_); |
327 | 0 | swap(lhs.args_, rhs.args_); |
328 | 0 | } |
329 | | |
330 | | private: |
331 | | friend class Expr; |
332 | | |
333 | | static const CallExpr& default_instance(); |
334 | | |
335 | 0 | static std::string release(std::string& property) { |
336 | 0 | std::string result; |
337 | 0 | result.swap(property); |
338 | 0 | return result; |
339 | 0 | } |
340 | | |
341 | | static std::unique_ptr<Expr> release(std::unique_ptr<Expr>& property); |
342 | | |
343 | | std::string function_; |
344 | | std::unique_ptr<Expr> target_; |
345 | | std::vector<Expr> args_; |
346 | | }; |
347 | | |
348 | | bool operator==(const CallExpr& lhs, const CallExpr& rhs); |
349 | | |
350 | 0 | inline bool operator!=(const CallExpr& lhs, const CallExpr& rhs) { |
351 | 0 | return !operator==(lhs, rhs); |
352 | 0 | } |
353 | | |
354 | | // `ListExprElement` represents an element in `ListExpr`. |
355 | | class ListExprElement final { |
356 | | public: |
357 | 411k | ListExprElement() = default; |
358 | 380k | ListExprElement(ListExprElement&&) = default; |
359 | | ListExprElement& operator=(ListExprElement&&) = default; |
360 | | |
361 | | ListExprElement(const ListExprElement&) = delete; |
362 | | ListExprElement& operator=(const ListExprElement&) = delete; |
363 | | |
364 | | void Clear(); |
365 | | |
366 | 525k | ABSL_MUST_USE_RESULT bool has_expr() const { return expr_ != nullptr; } |
367 | | |
368 | | ABSL_MUST_USE_RESULT const Expr& expr() const ABSL_ATTRIBUTE_LIFETIME_BOUND; |
369 | | |
370 | | ABSL_MUST_USE_RESULT Expr& mutable_expr() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
371 | | |
372 | | void set_expr(Expr expr); |
373 | | |
374 | | void set_expr(std::unique_ptr<Expr> expr); |
375 | | |
376 | | ABSL_MUST_USE_RESULT Expr release_expr(); |
377 | | |
378 | 72.1k | ABSL_MUST_USE_RESULT bool optional() const { return optional_; } |
379 | | |
380 | 411k | void set_optional(bool optional) { optional_ = optional; } |
381 | | |
382 | | friend void swap(ListExprElement& lhs, ListExprElement& rhs) noexcept; |
383 | | |
384 | | private: |
385 | | static Expr release(std::unique_ptr<Expr>& property); |
386 | | |
387 | | std::unique_ptr<Expr> expr_; |
388 | | bool optional_ = false; |
389 | | }; |
390 | | |
391 | | // `ListExpr` is an alternative of `Expr`, representing a list. |
392 | | class ListExpr final { |
393 | | public: |
394 | 46.7k | ListExpr() = default; |
395 | 131k | ListExpr(ListExpr&&) = default; |
396 | 0 | ListExpr& operator=(ListExpr&&) = default; |
397 | | |
398 | | ListExpr(const ListExpr&) = delete; |
399 | | ListExpr& operator=(const ListExpr&) = delete; |
400 | | |
401 | | void Clear(); |
402 | | |
403 | | // The elements of the list. |
404 | | ABSL_MUST_USE_RESULT const std::vector<ListExprElement>& elements() const |
405 | 216k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
406 | 216k | return elements_; |
407 | 216k | } |
408 | | |
409 | | ABSL_MUST_USE_RESULT std::vector<ListExprElement>& mutable_elements() |
410 | 40.2k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
411 | 40.2k | return elements_; |
412 | 40.2k | } |
413 | | |
414 | | void set_elements(std::vector<ListExprElement> elements); |
415 | | |
416 | | void set_elements(absl::Span<ListExprElement> elements); |
417 | | |
418 | | ListExprElement& add_elements() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
419 | | |
420 | | ABSL_MUST_USE_RESULT std::vector<ListExprElement> release_elements(); |
421 | | |
422 | 0 | friend void swap(ListExpr& lhs, ListExpr& rhs) noexcept { |
423 | 0 | using std::swap; |
424 | 0 | swap(lhs.elements_, rhs.elements_); |
425 | 0 | } |
426 | | |
427 | | private: |
428 | | friend class Expr; |
429 | | |
430 | | static const ListExpr& default_instance(); |
431 | | |
432 | | std::vector<ListExprElement> elements_; |
433 | | }; |
434 | | |
435 | | bool operator==(const ListExpr& lhs, const ListExpr& rhs); |
436 | | |
437 | 0 | inline bool operator!=(const ListExpr& lhs, const ListExpr& rhs) { |
438 | 0 | return !operator==(lhs, rhs); |
439 | 0 | } |
440 | | |
441 | | // `StructExprField` represents a field in `StructExpr`. |
442 | | class StructExprField final { |
443 | | public: |
444 | 8.41k | StructExprField() = default; |
445 | 7.56k | StructExprField(StructExprField&&) = default; |
446 | | StructExprField& operator=(StructExprField&&) = default; |
447 | | |
448 | | StructExprField(const StructExprField&) = delete; |
449 | | StructExprField& operator=(const StructExprField&) = delete; |
450 | | |
451 | | void Clear(); |
452 | | |
453 | 2.64k | ABSL_MUST_USE_RESULT ExprId id() const { return id_; } |
454 | | |
455 | 8.41k | void set_id(ExprId id) { id_ = id; } |
456 | | |
457 | | ABSL_MUST_USE_RESULT const std::string& name() const |
458 | 2.76k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
459 | 2.76k | return name_; |
460 | 2.76k | } |
461 | | |
462 | 8.41k | void set_name(std::string name) { name_ = std::move(name); } |
463 | | |
464 | 0 | void set_name(absl::string_view name) { |
465 | 0 | name_.assign(name.data(), name.size()); |
466 | 0 | } |
467 | | |
468 | 0 | void set_name(const char* name) { set_name(absl::NullSafeStringView(name)); } |
469 | | |
470 | 0 | ABSL_MUST_USE_RESULT std::string release_name() { return std::move(name_); } |
471 | | |
472 | 15.4k | ABSL_MUST_USE_RESULT bool has_value() const { return value_ != nullptr; } |
473 | | |
474 | | ABSL_MUST_USE_RESULT const Expr& value() const ABSL_ATTRIBUTE_LIFETIME_BOUND; |
475 | | |
476 | | ABSL_MUST_USE_RESULT Expr& mutable_value() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
477 | | |
478 | | void set_value(Expr value); |
479 | | |
480 | | void set_value(std::unique_ptr<Expr> value); |
481 | | |
482 | | ABSL_MUST_USE_RESULT Expr release_value(); |
483 | | |
484 | 2.64k | ABSL_MUST_USE_RESULT bool optional() const { return optional_; } |
485 | | |
486 | 8.41k | void set_optional(bool optional) { optional_ = optional; } |
487 | | |
488 | | friend void swap(StructExprField& lhs, StructExprField& rhs) noexcept; |
489 | | |
490 | | private: |
491 | | static Expr release(std::unique_ptr<Expr>& property); |
492 | | |
493 | | ExprId id_ = 0; |
494 | | std::string name_; |
495 | | std::unique_ptr<Expr> value_; |
496 | | bool optional_ = false; |
497 | | }; |
498 | | |
499 | | // `StructExpr` is an alternative of `Expr`, representing a struct. |
500 | | class StructExpr final { |
501 | | public: |
502 | 10.0k | StructExpr() = default; |
503 | 28.3k | StructExpr(StructExpr&&) = default; |
504 | 0 | StructExpr& operator=(StructExpr&&) = default; |
505 | | |
506 | | StructExpr(const StructExpr&) = delete; |
507 | | StructExpr& operator=(const StructExpr&) = delete; |
508 | | |
509 | | void Clear(); |
510 | | |
511 | | // The type name of the struct to be created. |
512 | | ABSL_MUST_USE_RESULT const std::string& name() const |
513 | 5.28k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
514 | 5.28k | return name_; |
515 | 5.28k | } |
516 | | |
517 | 10.0k | void set_name(std::string name) { name_ = std::move(name); } |
518 | | |
519 | 0 | void set_name(absl::string_view name) { |
520 | 0 | name_.assign(name.data(), name.size()); |
521 | 0 | } |
522 | | |
523 | 0 | void set_name(const char* name) { set_name(absl::NullSafeStringView(name)); } |
524 | | |
525 | 0 | ABSL_MUST_USE_RESULT std::string release_name() { return release(name_); } |
526 | | |
527 | | // The fields of the struct. |
528 | | ABSL_MUST_USE_RESULT const std::vector<StructExprField>& fields() const |
529 | 22.6k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
530 | 22.6k | return fields_; |
531 | 22.6k | } |
532 | | |
533 | | ABSL_MUST_USE_RESULT std::vector<StructExprField>& mutable_fields() |
534 | 3.31k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
535 | 3.31k | return fields_; |
536 | 3.31k | } |
537 | | |
538 | | void set_fields(std::vector<StructExprField> fields); |
539 | | |
540 | | void set_fields(absl::Span<StructExprField> fields); |
541 | | |
542 | | StructExprField& add_fields() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
543 | | |
544 | | ABSL_MUST_USE_RESULT std::vector<StructExprField> release_fields(); |
545 | | |
546 | 0 | friend void swap(StructExpr& lhs, StructExpr& rhs) noexcept { |
547 | 0 | using std::swap; |
548 | 0 | swap(lhs.name_, rhs.name_); |
549 | 0 | swap(lhs.fields_, rhs.fields_); |
550 | 0 | } |
551 | | |
552 | | private: |
553 | | friend class Expr; |
554 | | |
555 | | static const StructExpr& default_instance(); |
556 | | |
557 | 0 | static std::string release(std::string& property) { |
558 | 0 | std::string result; |
559 | 0 | result.swap(property); |
560 | 0 | return result; |
561 | 0 | } |
562 | | |
563 | | std::string name_; |
564 | | std::vector<StructExprField> fields_; |
565 | | }; |
566 | | |
567 | | bool operator==(const StructExpr& lhs, const StructExpr& rhs); |
568 | | |
569 | 0 | inline bool operator!=(const StructExpr& lhs, const StructExpr& rhs) { |
570 | 0 | return !operator==(lhs, rhs); |
571 | 0 | } |
572 | | |
573 | | // `MapExprEntry` represents an entry in `MapExpr`. |
574 | | class MapExprEntry final { |
575 | | public: |
576 | 286k | MapExprEntry() = default; |
577 | 282k | MapExprEntry(MapExprEntry&&) = default; |
578 | | MapExprEntry& operator=(MapExprEntry&&) = default; |
579 | | |
580 | | MapExprEntry(const MapExprEntry&) = delete; |
581 | | MapExprEntry& operator=(const MapExprEntry&) = delete; |
582 | | |
583 | | void Clear(); |
584 | | |
585 | 182k | ABSL_MUST_USE_RESULT ExprId id() const { return id_; } |
586 | | |
587 | 286k | void set_id(ExprId id) { id_ = id; } |
588 | | |
589 | 663k | ABSL_MUST_USE_RESULT bool has_key() const { return key_ != nullptr; } |
590 | | |
591 | | ABSL_MUST_USE_RESULT const Expr& key() const ABSL_ATTRIBUTE_LIFETIME_BOUND; |
592 | | |
593 | | ABSL_MUST_USE_RESULT Expr& mutable_key() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
594 | | |
595 | | void set_key(Expr key); |
596 | | |
597 | | void set_key(std::unique_ptr<Expr> key); |
598 | | |
599 | | ABSL_MUST_USE_RESULT Expr release_key(); |
600 | | |
601 | 663k | ABSL_MUST_USE_RESULT bool has_value() const { return value_ != nullptr; } |
602 | | |
603 | | ABSL_MUST_USE_RESULT const Expr& value() const ABSL_ATTRIBUTE_LIFETIME_BOUND; |
604 | | |
605 | | ABSL_MUST_USE_RESULT Expr& mutable_value() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
606 | | |
607 | | void set_value(Expr value); |
608 | | |
609 | | void set_value(std::unique_ptr<Expr> value); |
610 | | |
611 | | ABSL_MUST_USE_RESULT Expr release_value(); |
612 | | |
613 | 186k | ABSL_MUST_USE_RESULT bool optional() const { return optional_; } |
614 | | |
615 | 286k | void set_optional(bool optional) { optional_ = optional; } |
616 | | |
617 | | friend void swap(MapExprEntry& lhs, MapExprEntry& rhs) noexcept; |
618 | | |
619 | | private: |
620 | | static Expr release(std::unique_ptr<Expr>& property); |
621 | | |
622 | | ExprId id_ = 0; |
623 | | std::unique_ptr<Expr> key_; |
624 | | std::unique_ptr<Expr> value_; |
625 | | bool optional_ = false; |
626 | | }; |
627 | | |
628 | | // `MapExpr` is an alternative of `Expr`, representing a map. |
629 | | class MapExpr final { |
630 | | public: |
631 | 23.9k | MapExpr() = default; |
632 | 59.9k | MapExpr(MapExpr&&) = default; |
633 | 0 | MapExpr& operator=(MapExpr&&) = default; |
634 | | |
635 | | MapExpr(const MapExpr&) = delete; |
636 | | MapExpr& operator=(const MapExpr&) = delete; |
637 | | |
638 | | void Clear(); |
639 | | |
640 | | // The entries of the map. |
641 | | ABSL_MUST_USE_RESULT const std::vector<MapExprEntry>& entries() const |
642 | 62.1k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
643 | 62.1k | return entries_; |
644 | 62.1k | } |
645 | | |
646 | | ABSL_MUST_USE_RESULT std::vector<MapExprEntry>& mutable_entries() |
647 | 12.5k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
648 | 12.5k | return entries_; |
649 | 12.5k | } |
650 | | |
651 | | void set_entries(std::vector<MapExprEntry> entries); |
652 | | |
653 | | void set_entries(absl::Span<MapExprEntry> entries); |
654 | | |
655 | | MapExprEntry& add_entries() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
656 | | |
657 | | ABSL_MUST_USE_RESULT std::vector<MapExprEntry> release_entries(); |
658 | | |
659 | 0 | friend void swap(MapExpr& lhs, MapExpr& rhs) noexcept { |
660 | 0 | using std::swap; |
661 | 0 | swap(lhs.entries_, rhs.entries_); |
662 | 0 | } |
663 | | |
664 | | private: |
665 | | friend class Expr; |
666 | | |
667 | | static const MapExpr& default_instance(); |
668 | | |
669 | | std::vector<MapExprEntry> entries_; |
670 | | }; |
671 | | |
672 | | bool operator==(const MapExpr& lhs, const MapExpr& rhs); |
673 | | |
674 | 0 | inline bool operator!=(const MapExpr& lhs, const MapExpr& rhs) { |
675 | 0 | return !operator==(lhs, rhs); |
676 | 0 | } |
677 | | |
678 | | // `ComprehensionExpr` is an alternative of `Expr`, representing a |
679 | | // comprehension. These are always synthetic as there is no way to express them |
680 | | // directly in the Common Expression Language, and are created by macros. |
681 | | class ComprehensionExpr final { |
682 | | public: |
683 | 26.8k | ComprehensionExpr() = default; |
684 | 169k | ComprehensionExpr(ComprehensionExpr&&) = default; |
685 | 0 | ComprehensionExpr& operator=(ComprehensionExpr&&) = default; |
686 | | |
687 | | ComprehensionExpr(const ComprehensionExpr&) = delete; |
688 | | ComprehensionExpr& operator=(const ComprehensionExpr&) = delete; |
689 | | |
690 | | void Clear(); |
691 | | |
692 | | ABSL_MUST_USE_RESULT const std::string& iter_var() const |
693 | 1.73k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
694 | 1.73k | return iter_var_; |
695 | 1.73k | } |
696 | | |
697 | 26.8k | void set_iter_var(std::string iter_var) { iter_var_ = std::move(iter_var); } |
698 | | |
699 | 0 | void set_iter_var(absl::string_view iter_var) { |
700 | 0 | iter_var_.assign(iter_var.data(), iter_var.size()); |
701 | 0 | } |
702 | | |
703 | 0 | void set_iter_var(const char* iter_var) { |
704 | 0 | set_iter_var(absl::NullSafeStringView(iter_var)); |
705 | 0 | } |
706 | | |
707 | 0 | ABSL_MUST_USE_RESULT std::string release_iter_var() { |
708 | 0 | return release(iter_var_); |
709 | 0 | } |
710 | | |
711 | | ABSL_MUST_USE_RESULT const std::string& iter_var2() const |
712 | 1.73k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
713 | 1.73k | return iter_var2_; |
714 | 1.73k | } |
715 | | |
716 | 0 | void set_iter_var2(std::string iter_var2) { |
717 | 0 | iter_var2_ = std::move(iter_var2); |
718 | 0 | } |
719 | | |
720 | 26.8k | void set_iter_var2(absl::string_view iter_var2) { |
721 | 26.8k | iter_var2_.assign(iter_var2.data(), iter_var2.size()); |
722 | 26.8k | } |
723 | | |
724 | 26.8k | void set_iter_var2(const char* iter_var2) { |
725 | 26.8k | set_iter_var2(absl::NullSafeStringView(iter_var2)); |
726 | 26.8k | } |
727 | | |
728 | 0 | ABSL_MUST_USE_RESULT std::string release_iter_var2() { |
729 | 0 | return release(iter_var2_); |
730 | 0 | } |
731 | | |
732 | 30.3k | ABSL_MUST_USE_RESULT bool has_iter_range() const { |
733 | 30.3k | return iter_range_ != nullptr; |
734 | 30.3k | } |
735 | | |
736 | | ABSL_MUST_USE_RESULT const Expr& iter_range() const |
737 | | ABSL_ATTRIBUTE_LIFETIME_BOUND; |
738 | | |
739 | | Expr& mutable_iter_range() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
740 | | |
741 | | void set_iter_range(Expr iter_range); |
742 | | |
743 | | void set_iter_range(std::unique_ptr<Expr> iter_range); |
744 | | |
745 | | ABSL_MUST_USE_RESULT std::unique_ptr<Expr> release_iter_range(); |
746 | | |
747 | | ABSL_MUST_USE_RESULT const std::string& accu_var() const |
748 | 1.73k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
749 | 1.73k | return accu_var_; |
750 | 1.73k | } |
751 | | |
752 | 0 | void set_accu_var(std::string accu_var) { accu_var_ = std::move(accu_var); } |
753 | | |
754 | 26.8k | void set_accu_var(absl::string_view accu_var) { |
755 | 26.8k | accu_var_.assign(accu_var.data(), accu_var.size()); |
756 | 26.8k | } |
757 | | |
758 | 0 | void set_accu_var(const char* accu_var) { |
759 | 0 | set_accu_var(absl::NullSafeStringView(accu_var)); |
760 | 0 | } |
761 | | |
762 | 0 | ABSL_MUST_USE_RESULT std::string release_accu_var() { |
763 | 0 | return release(accu_var_); |
764 | 0 | } |
765 | | |
766 | 30.3k | ABSL_MUST_USE_RESULT bool has_accu_init() const { |
767 | 30.3k | return accu_init_ != nullptr; |
768 | 30.3k | } |
769 | | |
770 | | ABSL_MUST_USE_RESULT const Expr& accu_init() const |
771 | | ABSL_ATTRIBUTE_LIFETIME_BOUND; |
772 | | |
773 | | Expr& mutable_accu_init() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
774 | | |
775 | | void set_accu_init(Expr accu_init); |
776 | | |
777 | | void set_accu_init(std::unique_ptr<Expr> accu_init); |
778 | | |
779 | | ABSL_MUST_USE_RESULT std::unique_ptr<Expr> release_accu_init(); |
780 | | |
781 | 30.3k | ABSL_MUST_USE_RESULT bool has_loop_condition() const { |
782 | 30.3k | return loop_condition_ != nullptr; |
783 | 30.3k | } |
784 | | |
785 | | ABSL_MUST_USE_RESULT const Expr& loop_condition() const |
786 | | ABSL_ATTRIBUTE_LIFETIME_BOUND; |
787 | | |
788 | | Expr& mutable_loop_condition() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
789 | | |
790 | | void set_loop_condition(Expr loop_condition); |
791 | | |
792 | | void set_loop_condition(std::unique_ptr<Expr> loop_condition); |
793 | | |
794 | | ABSL_MUST_USE_RESULT std::unique_ptr<Expr> release_loop_condition(); |
795 | | |
796 | 30.3k | ABSL_MUST_USE_RESULT bool has_loop_step() const { |
797 | 30.3k | return loop_step_ != nullptr; |
798 | 30.3k | } |
799 | | |
800 | | ABSL_MUST_USE_RESULT const Expr& loop_step() const |
801 | | ABSL_ATTRIBUTE_LIFETIME_BOUND; |
802 | | |
803 | | Expr& mutable_loop_step() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
804 | | |
805 | | void set_loop_step(Expr loop_step); |
806 | | |
807 | | void set_loop_step(std::unique_ptr<Expr> loop_step); |
808 | | |
809 | | ABSL_MUST_USE_RESULT std::unique_ptr<Expr> release_loop_step(); |
810 | | |
811 | 30.3k | ABSL_MUST_USE_RESULT bool has_result() const { return result_ != nullptr; } |
812 | | |
813 | | ABSL_MUST_USE_RESULT const Expr& result() const ABSL_ATTRIBUTE_LIFETIME_BOUND; |
814 | | |
815 | | Expr& mutable_result() ABSL_ATTRIBUTE_LIFETIME_BOUND; |
816 | | |
817 | | void set_result(Expr result); |
818 | | |
819 | | void set_result(std::unique_ptr<Expr> result); |
820 | | |
821 | | ABSL_MUST_USE_RESULT std::unique_ptr<Expr> release_result(); |
822 | | |
823 | 0 | friend void swap(ComprehensionExpr& lhs, ComprehensionExpr& rhs) noexcept { |
824 | 0 | using std::swap; |
825 | 0 | swap(lhs.iter_var_, rhs.iter_var_); |
826 | 0 | swap(lhs.iter_var2_, rhs.iter_var2_); |
827 | 0 | swap(lhs.iter_range_, rhs.iter_range_); |
828 | 0 | swap(lhs.accu_var_, rhs.accu_var_); |
829 | 0 | swap(lhs.accu_init_, rhs.accu_init_); |
830 | 0 | swap(lhs.loop_condition_, rhs.loop_condition_); |
831 | 0 | swap(lhs.loop_step_, rhs.loop_step_); |
832 | 0 | swap(lhs.result_, rhs.result_); |
833 | 0 | } |
834 | | |
835 | | private: |
836 | | friend class Expr; |
837 | | |
838 | | static const ComprehensionExpr& default_instance(); |
839 | | |
840 | 0 | static std::string release(std::string& property) { |
841 | 0 | std::string result; |
842 | 0 | result.swap(property); |
843 | 0 | return result; |
844 | 0 | } |
845 | | |
846 | | static std::unique_ptr<Expr> release(std::unique_ptr<Expr>& property); |
847 | | |
848 | | std::string iter_var_; |
849 | | std::string iter_var2_; |
850 | | std::unique_ptr<Expr> iter_range_; |
851 | | std::string accu_var_; |
852 | | std::unique_ptr<Expr> accu_init_; |
853 | | std::unique_ptr<Expr> loop_condition_; |
854 | | std::unique_ptr<Expr> loop_step_; |
855 | | std::unique_ptr<Expr> result_; |
856 | | }; |
857 | | |
858 | | inline bool operator==(const ComprehensionExpr& lhs, |
859 | 0 | const ComprehensionExpr& rhs) { |
860 | 0 | return lhs.iter_var() == rhs.iter_var() && |
861 | 0 | lhs.iter_range() == rhs.iter_range() && |
862 | 0 | lhs.accu_var() == rhs.accu_var() && |
863 | 0 | lhs.accu_init() == rhs.accu_init() && |
864 | 0 | lhs.loop_condition() == rhs.loop_condition() && |
865 | 0 | lhs.loop_step() == rhs.loop_step() && lhs.result() == rhs.result(); |
866 | 0 | } |
867 | | |
868 | | inline bool operator!=(const ComprehensionExpr& lhs, |
869 | 0 | const ComprehensionExpr& rhs) { |
870 | 0 | return !operator==(lhs, rhs); |
871 | 0 | } |
872 | | |
873 | | using ExprKind = |
874 | | absl::variant<UnspecifiedExpr, Constant, IdentExpr, SelectExpr, CallExpr, |
875 | | ListExpr, StructExpr, MapExpr, ComprehensionExpr>; |
876 | | |
877 | | enum class ExprKindCase { |
878 | | kUnspecifiedExpr, |
879 | | kConstant, |
880 | | kIdentExpr, |
881 | | kSelectExpr, |
882 | | kCallExpr, |
883 | | kListExpr, |
884 | | kStructExpr, |
885 | | kMapExpr, |
886 | | kComprehensionExpr, |
887 | | }; |
888 | | |
889 | | namespace common_internal { |
890 | | struct ExprEraseTag; |
891 | | } // namespace common_internal |
892 | | |
893 | | // `Expr` is a node in the Common Expression Language's abstract syntax tree. It |
894 | | // is composed of a numeric ID and a kind variant. |
895 | | class Expr final { |
896 | | public: |
897 | 16.1M | Expr() = default; |
898 | 20.7M | Expr(Expr&&) = default; |
899 | | Expr& operator=(Expr&&); |
900 | | |
901 | | Expr(const Expr&); |
902 | | Expr& operator=(const Expr&); |
903 | | |
904 | | void Clear(); |
905 | | |
906 | 3.40M | ABSL_MUST_USE_RESULT ExprId id() const { return u_.id; } |
907 | | |
908 | 14.9M | void set_id(ExprId id) { u_.id = id; } |
909 | | |
910 | | ABSL_MUST_USE_RESULT const ExprKind& kind() const |
911 | 6.00M | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
912 | 6.00M | return kind_; |
913 | 6.00M | } |
914 | | |
915 | 6.89M | ABSL_MUST_USE_RESULT ExprKind& mutable_kind() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
916 | 6.89M | return kind_; |
917 | 6.89M | } |
918 | | |
919 | | void set_kind(ExprKind kind); |
920 | | |
921 | | ABSL_MUST_USE_RESULT ExprKind release_kind(); |
922 | | |
923 | 0 | ABSL_MUST_USE_RESULT bool has_const_expr() const { |
924 | 0 | return absl::holds_alternative<Constant>(kind()); |
925 | 0 | } |
926 | | |
927 | | ABSL_MUST_USE_RESULT const Constant& const_expr() const |
928 | 118k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
929 | 118k | return get_kind<Constant>(); |
930 | 118k | } |
931 | | |
932 | 1.34M | Constant& mutable_const_expr() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
933 | 1.34M | return try_emplace_kind<Constant>(); |
934 | 1.34M | } |
935 | | |
936 | 0 | void set_const_expr(Constant const_expr) { |
937 | 0 | try_emplace_kind<Constant>() = std::move(const_expr); |
938 | 0 | } |
939 | | |
940 | 0 | ABSL_MUST_USE_RESULT Constant release_const_expr() { |
941 | 0 | return release_kind<Constant>(); |
942 | 0 | } |
943 | | |
944 | 44.7k | ABSL_MUST_USE_RESULT bool has_ident_expr() const { |
945 | 44.7k | return absl::holds_alternative<IdentExpr>(kind()); |
946 | 44.7k | } |
947 | | |
948 | | ABSL_MUST_USE_RESULT const IdentExpr& ident_expr() const |
949 | 142k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
950 | 142k | return get_kind<IdentExpr>(); |
951 | 142k | } |
952 | | |
953 | 2.23M | IdentExpr& mutable_ident_expr() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
954 | 2.23M | return try_emplace_kind<IdentExpr>(); |
955 | 2.23M | } |
956 | | |
957 | 0 | void set_ident_expr(IdentExpr ident_expr) { |
958 | 0 | try_emplace_kind<IdentExpr>() = std::move(ident_expr); |
959 | 0 | } |
960 | | |
961 | 0 | ABSL_MUST_USE_RESULT IdentExpr release_ident_expr() { |
962 | 0 | return release_kind<IdentExpr>(); |
963 | 0 | } |
964 | | |
965 | 414k | ABSL_MUST_USE_RESULT bool has_select_expr() const { |
966 | 414k | return absl::holds_alternative<SelectExpr>(kind()); |
967 | 414k | } |
968 | | |
969 | | ABSL_MUST_USE_RESULT const SelectExpr& select_expr() const |
970 | 51.9k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
971 | 51.9k | return get_kind<SelectExpr>(); |
972 | 51.9k | } |
973 | | |
974 | 58.2k | SelectExpr& mutable_select_expr() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
975 | 58.2k | return try_emplace_kind<SelectExpr>(); |
976 | 58.2k | } |
977 | | |
978 | 0 | void set_select_expr(SelectExpr select_expr) { |
979 | 0 | try_emplace_kind<SelectExpr>() = std::move(select_expr); |
980 | 0 | } |
981 | | |
982 | 0 | ABSL_MUST_USE_RESULT SelectExpr release_select_expr() { |
983 | 0 | return release_kind<SelectExpr>(); |
984 | 0 | } |
985 | | |
986 | 368k | ABSL_MUST_USE_RESULT bool has_call_expr() const { |
987 | 368k | return absl::holds_alternative<CallExpr>(kind()); |
988 | 368k | } |
989 | | |
990 | | ABSL_MUST_USE_RESULT const CallExpr& call_expr() const |
991 | 858k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
992 | 858k | return get_kind<CallExpr>(); |
993 | 858k | } |
994 | | |
995 | 2.76M | CallExpr& mutable_call_expr() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
996 | 2.76M | return try_emplace_kind<CallExpr>(); |
997 | 2.76M | } |
998 | | |
999 | | void set_call_expr(CallExpr call_expr); |
1000 | | |
1001 | | ABSL_MUST_USE_RESULT CallExpr release_call_expr(); |
1002 | | |
1003 | 0 | ABSL_MUST_USE_RESULT bool has_list_expr() const { |
1004 | 0 | return absl::holds_alternative<ListExpr>(kind()); |
1005 | 0 | } |
1006 | | |
1007 | | ABSL_MUST_USE_RESULT const ListExpr& list_expr() const |
1008 | 27.3k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1009 | 27.3k | return get_kind<ListExpr>(); |
1010 | 27.3k | } |
1011 | | |
1012 | 46.7k | ListExpr& mutable_list_expr() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1013 | 46.7k | return try_emplace_kind<ListExpr>(); |
1014 | 46.7k | } |
1015 | | |
1016 | | void set_list_expr(ListExpr list_expr); |
1017 | | |
1018 | | ABSL_MUST_USE_RESULT ListExpr release_list_expr(); |
1019 | | |
1020 | 0 | ABSL_MUST_USE_RESULT bool has_struct_expr() const { |
1021 | 0 | return absl::holds_alternative<StructExpr>(kind()); |
1022 | 0 | } |
1023 | | |
1024 | | ABSL_MUST_USE_RESULT const StructExpr& struct_expr() const |
1025 | 15.6k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1026 | 15.6k | return get_kind<StructExpr>(); |
1027 | 15.6k | } |
1028 | | |
1029 | 10.0k | StructExpr& mutable_struct_expr() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1030 | 10.0k | return try_emplace_kind<StructExpr>(); |
1031 | 10.0k | } |
1032 | | |
1033 | | void set_struct_expr(StructExpr struct_expr); |
1034 | | |
1035 | | ABSL_MUST_USE_RESULT StructExpr release_struct_expr(); |
1036 | | |
1037 | 0 | ABSL_MUST_USE_RESULT bool has_map_expr() const { |
1038 | 0 | return absl::holds_alternative<MapExpr>(kind()); |
1039 | 0 | } |
1040 | | |
1041 | | ABSL_MUST_USE_RESULT const MapExpr& map_expr() const |
1042 | 17.4k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1043 | 17.4k | return get_kind<MapExpr>(); |
1044 | 17.4k | } |
1045 | | |
1046 | 23.9k | MapExpr& mutable_map_expr() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1047 | 23.9k | return try_emplace_kind<MapExpr>(); |
1048 | 23.9k | } |
1049 | | |
1050 | | void set_map_expr(MapExpr map_expr); |
1051 | | |
1052 | | ABSL_MUST_USE_RESULT MapExpr release_map_expr(); |
1053 | | |
1054 | 200k | ABSL_MUST_USE_RESULT bool has_comprehension_expr() const { |
1055 | 200k | return absl::holds_alternative<ComprehensionExpr>(kind()); |
1056 | 200k | } |
1057 | | |
1058 | | ABSL_MUST_USE_RESULT const ComprehensionExpr& comprehension_expr() const |
1059 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1060 | 0 | return get_kind<ComprehensionExpr>(); |
1061 | 0 | } |
1062 | | |
1063 | | ComprehensionExpr& mutable_comprehension_expr() |
1064 | 26.8k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1065 | 26.8k | return try_emplace_kind<ComprehensionExpr>(); |
1066 | 26.8k | } |
1067 | | |
1068 | 0 | void set_comprehension_expr(ComprehensionExpr comprehension_expr) { |
1069 | 0 | try_emplace_kind<ComprehensionExpr>() = std::move(comprehension_expr); |
1070 | 0 | } |
1071 | | |
1072 | 0 | ABSL_MUST_USE_RESULT ComprehensionExpr release_comprehension_expr() { |
1073 | 0 | return release_kind<ComprehensionExpr>(); |
1074 | 0 | } |
1075 | | |
1076 | | ExprKindCase kind_case() const; |
1077 | | |
1078 | | friend void swap(Expr& lhs, Expr& rhs) noexcept; |
1079 | | |
1080 | | // Erases the expr in place without recursion. |
1081 | | void FlattenedErase(); |
1082 | | |
1083 | | inline void SetNext(common_internal::ExprEraseTag&, Expr* next); |
1084 | | |
1085 | | private: |
1086 | | friend class IdentExpr; |
1087 | | friend class SelectExpr; |
1088 | | friend class CallExpr; |
1089 | | friend class ListExpr; |
1090 | | friend class StructExpr; |
1091 | | friend class MapExpr; |
1092 | | friend class ComprehensionExpr; |
1093 | | friend class ListExprElement; |
1094 | | friend class StructExprField; |
1095 | | friend class MapExprEntry; |
1096 | | |
1097 | | static const Expr& default_instance(); |
1098 | | |
1099 | | template <typename T, typename... Args> |
1100 | | ABSL_MUST_USE_RESULT T& try_emplace_kind(Args&&... args) |
1101 | 6.50M | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1102 | 6.50M | if (auto* alt = absl::get_if<T>(&mutable_kind()); alt) { |
1103 | 96 | return *alt; |
1104 | 96 | } |
1105 | 6.50M | return kind_.emplace<T>(std::forward<Args>(args)...); |
1106 | 6.50M | } cel::Constant& cel::Expr::try_emplace_kind<cel::Constant>() Line | Count | Source | 1101 | 1.34M | ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1102 | 1.34M | if (auto* alt = absl::get_if<T>(&mutable_kind()); alt) { | 1103 | 0 | return *alt; | 1104 | 0 | } | 1105 | 1.34M | return kind_.emplace<T>(std::forward<Args>(args)...); | 1106 | 1.34M | } |
cel::IdentExpr& cel::Expr::try_emplace_kind<cel::IdentExpr>() Line | Count | Source | 1101 | 2.23M | ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1102 | 2.23M | if (auto* alt = absl::get_if<T>(&mutable_kind()); alt) { | 1103 | 0 | return *alt; | 1104 | 0 | } | 1105 | 2.23M | return kind_.emplace<T>(std::forward<Args>(args)...); | 1106 | 2.23M | } |
cel::SelectExpr& cel::Expr::try_emplace_kind<cel::SelectExpr>() Line | Count | Source | 1101 | 58.2k | ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1102 | 58.2k | if (auto* alt = absl::get_if<T>(&mutable_kind()); alt) { | 1103 | 96 | return *alt; | 1104 | 96 | } | 1105 | 58.1k | return kind_.emplace<T>(std::forward<Args>(args)...); | 1106 | 58.2k | } |
cel::CallExpr& cel::Expr::try_emplace_kind<cel::CallExpr>() Line | Count | Source | 1101 | 2.76M | ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1102 | 2.76M | if (auto* alt = absl::get_if<T>(&mutable_kind()); alt) { | 1103 | 0 | return *alt; | 1104 | 0 | } | 1105 | 2.76M | return kind_.emplace<T>(std::forward<Args>(args)...); | 1106 | 2.76M | } |
cel::ListExpr& cel::Expr::try_emplace_kind<cel::ListExpr>() Line | Count | Source | 1101 | 46.7k | ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1102 | 46.7k | if (auto* alt = absl::get_if<T>(&mutable_kind()); alt) { | 1103 | 0 | return *alt; | 1104 | 0 | } | 1105 | 46.7k | return kind_.emplace<T>(std::forward<Args>(args)...); | 1106 | 46.7k | } |
cel::StructExpr& cel::Expr::try_emplace_kind<cel::StructExpr>() Line | Count | Source | 1101 | 10.0k | ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1102 | 10.0k | if (auto* alt = absl::get_if<T>(&mutable_kind()); alt) { | 1103 | 0 | return *alt; | 1104 | 0 | } | 1105 | 10.0k | return kind_.emplace<T>(std::forward<Args>(args)...); | 1106 | 10.0k | } |
cel::MapExpr& cel::Expr::try_emplace_kind<cel::MapExpr>() Line | Count | Source | 1101 | 23.9k | ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1102 | 23.9k | if (auto* alt = absl::get_if<T>(&mutable_kind()); alt) { | 1103 | 0 | return *alt; | 1104 | 0 | } | 1105 | 23.9k | return kind_.emplace<T>(std::forward<Args>(args)...); | 1106 | 23.9k | } |
cel::ComprehensionExpr& cel::Expr::try_emplace_kind<cel::ComprehensionExpr>() Line | Count | Source | 1101 | 26.8k | ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1102 | 26.8k | if (auto* alt = absl::get_if<T>(&mutable_kind()); alt) { | 1103 | 0 | return *alt; | 1104 | 0 | } | 1105 | 26.8k | return kind_.emplace<T>(std::forward<Args>(args)...); | 1106 | 26.8k | } |
|
1107 | | |
1108 | | template <typename T> |
1109 | 1.23M | ABSL_MUST_USE_RESULT const T& get_kind() const ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1110 | 1.23M | if (const auto* alt = absl::get_if<T>(&kind()); alt) { |
1111 | 1.22M | return *alt; |
1112 | 1.22M | } |
1113 | 8.59k | return T::default_instance(); |
1114 | 1.23M | } cel::IdentExpr const& cel::Expr::get_kind<cel::IdentExpr>() const Line | Count | Source | 1109 | 142k | ABSL_MUST_USE_RESULT const T& get_kind() const ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1110 | 142k | if (const auto* alt = absl::get_if<T>(&kind()); alt) { | 1111 | 142k | return *alt; | 1112 | 142k | } | 1113 | 0 | return T::default_instance(); | 1114 | 142k | } |
cel::SelectExpr const& cel::Expr::get_kind<cel::SelectExpr>() const Line | Count | Source | 1109 | 51.9k | ABSL_MUST_USE_RESULT const T& get_kind() const ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1110 | 51.9k | if (const auto* alt = absl::get_if<T>(&kind()); alt) { | 1111 | 51.9k | return *alt; | 1112 | 51.9k | } | 1113 | 0 | return T::default_instance(); | 1114 | 51.9k | } |
cel::ListExpr const& cel::Expr::get_kind<cel::ListExpr>() const Line | Count | Source | 1109 | 27.3k | ABSL_MUST_USE_RESULT const T& get_kind() const ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1110 | 27.3k | if (const auto* alt = absl::get_if<T>(&kind()); alt) { | 1111 | 27.3k | return *alt; | 1112 | 27.3k | } | 1113 | 0 | return T::default_instance(); | 1114 | 27.3k | } |
Unexecuted instantiation: cel::ComprehensionExpr const& cel::Expr::get_kind<cel::ComprehensionExpr>() const cel::Constant const& cel::Expr::get_kind<cel::Constant>() const Line | Count | Source | 1109 | 118k | ABSL_MUST_USE_RESULT const T& get_kind() const ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1110 | 118k | if (const auto* alt = absl::get_if<T>(&kind()); alt) { | 1111 | 118k | return *alt; | 1112 | 118k | } | 1113 | 0 | return T::default_instance(); | 1114 | 118k | } |
cel::CallExpr const& cel::Expr::get_kind<cel::CallExpr>() const Line | Count | Source | 1109 | 858k | ABSL_MUST_USE_RESULT const T& get_kind() const ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1110 | 858k | if (const auto* alt = absl::get_if<T>(&kind()); alt) { | 1111 | 858k | return *alt; | 1112 | 858k | } | 1113 | 0 | return T::default_instance(); | 1114 | 858k | } |
cel::StructExpr const& cel::Expr::get_kind<cel::StructExpr>() const Line | Count | Source | 1109 | 15.6k | ABSL_MUST_USE_RESULT const T& get_kind() const ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1110 | 15.6k | if (const auto* alt = absl::get_if<T>(&kind()); alt) { | 1111 | 7.08k | return *alt; | 1112 | 7.08k | } | 1113 | 8.59k | return T::default_instance(); | 1114 | 15.6k | } |
cel::MapExpr const& cel::Expr::get_kind<cel::MapExpr>() const Line | Count | Source | 1109 | 17.4k | ABSL_MUST_USE_RESULT const T& get_kind() const ABSL_ATTRIBUTE_LIFETIME_BOUND { | 1110 | 17.4k | if (const auto* alt = absl::get_if<T>(&kind()); alt) { | 1111 | 17.4k | return *alt; | 1112 | 17.4k | } | 1113 | 0 | return T::default_instance(); | 1114 | 17.4k | } |
|
1115 | | |
1116 | | template <typename T> |
1117 | | ABSL_MUST_USE_RESULT T release_kind(); |
1118 | | |
1119 | | union { |
1120 | | ExprId id = 0; |
1121 | | // Intrusive pointer to the next element in the destructor chain. |
1122 | | // Only set from FlattenedErase. |
1123 | | Expr* next; |
1124 | | } u_; |
1125 | | ExprKind kind_; |
1126 | | }; |
1127 | | |
1128 | 0 | inline bool operator==(const Expr& lhs, const Expr& rhs) { |
1129 | 0 | return lhs.id() == rhs.id() && lhs.kind() == rhs.kind(); |
1130 | 0 | } |
1131 | | |
1132 | 0 | inline bool operator==(const CallExpr& lhs, const CallExpr& rhs) { |
1133 | 0 | return lhs.function() == rhs.function() && lhs.target() == rhs.target() && |
1134 | 0 | absl::c_equal(lhs.args(), rhs.args()); |
1135 | 0 | } |
1136 | | |
1137 | 0 | inline void SelectExpr::Clear() { |
1138 | 0 | operand_.reset(); |
1139 | 0 | field_.clear(); |
1140 | 0 | test_only_ = false; |
1141 | 0 | } |
1142 | | |
1143 | | ABSL_MUST_USE_RESULT inline std::unique_ptr<Expr> |
1144 | 48 | SelectExpr::release_operand() { |
1145 | 48 | return release(operand_); |
1146 | 48 | } |
1147 | | |
1148 | 86.4k | inline const Expr& SelectExpr::operand() const ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1149 | 86.4k | return has_operand() ? *operand_ : Expr::default_instance(); |
1150 | 86.4k | } |
1151 | | |
1152 | 58.1k | inline Expr& SelectExpr::mutable_operand() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1153 | 58.1k | if (!has_operand()) { |
1154 | 58.1k | operand_ = std::make_unique<Expr>(); |
1155 | 58.1k | } |
1156 | 58.1k | return *operand_; |
1157 | 58.1k | } |
1158 | | |
1159 | 40.8k | inline void SelectExpr::set_operand(Expr operand) { |
1160 | 40.8k | mutable_operand() = std::move(operand); |
1161 | 40.8k | } |
1162 | | |
1163 | 48 | inline void SelectExpr::set_operand(std::unique_ptr<Expr> operand) { |
1164 | 48 | operand_ = std::move(operand); |
1165 | 48 | } |
1166 | | |
1167 | | inline std::unique_ptr<Expr> SelectExpr::release( |
1168 | 48 | std::unique_ptr<Expr>& property) { |
1169 | 48 | std::unique_ptr<Expr> result; |
1170 | 48 | result.swap(property); |
1171 | 48 | return result; |
1172 | 48 | } |
1173 | | |
1174 | 0 | inline void ComprehensionExpr::Clear() { |
1175 | 0 | iter_var_.clear(); |
1176 | 0 | iter_range_.reset(); |
1177 | 0 | accu_var_.clear(); |
1178 | 0 | accu_init_.reset(); |
1179 | 0 | loop_condition_.reset(); |
1180 | 0 | loop_step_.reset(); |
1181 | 0 | result_.reset(); |
1182 | 0 | } |
1183 | | |
1184 | | inline const Expr& ComprehensionExpr::iter_range() const |
1185 | 1.73k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1186 | 1.73k | return has_iter_range() ? *iter_range_ : Expr::default_instance(); |
1187 | 1.73k | } |
1188 | | |
1189 | | inline Expr& ComprehensionExpr::mutable_iter_range() |
1190 | 26.8k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1191 | 26.8k | if (!has_iter_range()) { |
1192 | 26.8k | iter_range_ = std::make_unique<Expr>(); |
1193 | 26.8k | } |
1194 | 26.8k | return *iter_range_; |
1195 | 26.8k | } |
1196 | | |
1197 | 26.8k | inline void ComprehensionExpr::set_iter_range(Expr iter_range) { |
1198 | 26.8k | mutable_iter_range() = std::move(iter_range); |
1199 | 26.8k | } |
1200 | | |
1201 | | inline void ComprehensionExpr::set_iter_range( |
1202 | 0 | std::unique_ptr<Expr> iter_range) { |
1203 | 0 | iter_range_ = std::move(iter_range); |
1204 | 0 | } |
1205 | | |
1206 | | ABSL_MUST_USE_RESULT inline std::unique_ptr<Expr> |
1207 | 0 | ComprehensionExpr::release_iter_range() { |
1208 | 0 | return release(iter_range_); |
1209 | 0 | } |
1210 | | |
1211 | | inline const Expr& ComprehensionExpr::accu_init() const |
1212 | 1.73k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1213 | 1.73k | return has_accu_init() ? *accu_init_ : Expr::default_instance(); |
1214 | 1.73k | } |
1215 | | |
1216 | | ABSL_MUST_USE_RESULT inline std::unique_ptr<Expr> |
1217 | 0 | ComprehensionExpr::release_accu_init() { |
1218 | 0 | return release(accu_init_); |
1219 | 0 | } |
1220 | | |
1221 | | inline Expr& ComprehensionExpr::mutable_accu_init() |
1222 | 26.8k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1223 | 26.8k | if (!has_accu_init()) { |
1224 | 26.8k | accu_init_ = std::make_unique<Expr>(); |
1225 | 26.8k | } |
1226 | 26.8k | return *accu_init_; |
1227 | 26.8k | } |
1228 | | |
1229 | 26.8k | inline void ComprehensionExpr::set_accu_init(Expr accu_init) { |
1230 | 26.8k | mutable_accu_init() = std::move(accu_init); |
1231 | 26.8k | } |
1232 | | |
1233 | 0 | inline void ComprehensionExpr::set_accu_init(std::unique_ptr<Expr> accu_init) { |
1234 | 0 | accu_init_ = std::move(accu_init); |
1235 | 0 | } |
1236 | | |
1237 | | inline const Expr& ComprehensionExpr::loop_step() const |
1238 | 1.73k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1239 | 1.73k | return has_loop_step() ? *loop_step_ : Expr::default_instance(); |
1240 | 1.73k | } |
1241 | | |
1242 | | inline Expr& ComprehensionExpr::mutable_loop_step() |
1243 | 26.8k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1244 | 26.8k | if (!has_loop_step()) { |
1245 | 26.8k | loop_step_ = std::make_unique<Expr>(); |
1246 | 26.8k | } |
1247 | 26.8k | return *loop_step_; |
1248 | 26.8k | } |
1249 | | |
1250 | 26.8k | inline void ComprehensionExpr::set_loop_step(Expr loop_step) { |
1251 | 26.8k | mutable_loop_step() = std::move(loop_step); |
1252 | 26.8k | } |
1253 | | |
1254 | 0 | inline void ComprehensionExpr::set_loop_step(std::unique_ptr<Expr> loop_step) { |
1255 | 0 | loop_step_ = std::move(loop_step); |
1256 | 0 | } |
1257 | | |
1258 | | ABSL_MUST_USE_RESULT inline std::unique_ptr<Expr> |
1259 | 0 | ComprehensionExpr::release_loop_step() { |
1260 | 0 | return release(loop_step_); |
1261 | 0 | } |
1262 | | |
1263 | | inline const Expr& ComprehensionExpr::loop_condition() const |
1264 | 1.73k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1265 | 1.73k | return has_loop_condition() ? *loop_condition_ : Expr::default_instance(); |
1266 | 1.73k | } |
1267 | | |
1268 | | ABSL_MUST_USE_RESULT inline std::unique_ptr<Expr> |
1269 | 0 | ComprehensionExpr::release_loop_condition() { |
1270 | 0 | return release(loop_condition_); |
1271 | 0 | } |
1272 | | |
1273 | | inline Expr& ComprehensionExpr::mutable_loop_condition() |
1274 | 26.8k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1275 | 26.8k | if (!has_loop_condition()) { |
1276 | 26.8k | loop_condition_ = std::make_unique<Expr>(); |
1277 | 26.8k | } |
1278 | 26.8k | return *loop_condition_; |
1279 | 26.8k | } |
1280 | | |
1281 | 26.8k | inline void ComprehensionExpr::set_loop_condition(Expr loop_condition) { |
1282 | 26.8k | mutable_loop_condition() = std::move(loop_condition); |
1283 | 26.8k | } |
1284 | | |
1285 | | inline void ComprehensionExpr::set_loop_condition( |
1286 | 0 | std::unique_ptr<Expr> loop_condition) { |
1287 | 0 | loop_condition_ = std::move(loop_condition); |
1288 | 0 | } |
1289 | | |
1290 | | inline const Expr& ComprehensionExpr::result() const |
1291 | 1.73k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1292 | 1.73k | return has_result() ? *result_ : Expr::default_instance(); |
1293 | 1.73k | } |
1294 | | |
1295 | 26.8k | inline Expr& ComprehensionExpr::mutable_result() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1296 | 26.8k | if (!has_result()) { |
1297 | 26.8k | result_ = std::make_unique<Expr>(); |
1298 | 26.8k | } |
1299 | 26.8k | return *result_; |
1300 | 26.8k | } |
1301 | | |
1302 | 26.8k | inline void ComprehensionExpr::set_result(Expr result) { |
1303 | 26.8k | mutable_result() = std::move(result); |
1304 | 26.8k | } |
1305 | | |
1306 | 0 | inline void ComprehensionExpr::set_result(std::unique_ptr<Expr> result) { |
1307 | 0 | result_ = std::move(result); |
1308 | 0 | } |
1309 | | |
1310 | | ABSL_MUST_USE_RESULT inline std::unique_ptr<Expr> |
1311 | 0 | ComprehensionExpr::release_result() { |
1312 | 0 | return release(result_); |
1313 | 0 | } |
1314 | | |
1315 | | inline std::unique_ptr<Expr> ComprehensionExpr::release( |
1316 | 0 | std::unique_ptr<Expr>& property) { |
1317 | 0 | std::unique_ptr<Expr> result; |
1318 | 0 | result.swap(property); |
1319 | 0 | return result; |
1320 | 0 | } |
1321 | | |
1322 | 0 | inline bool operator==(const ListExprElement& lhs, const ListExprElement& rhs) { |
1323 | 0 | return lhs.expr() == rhs.expr() && lhs.optional() == rhs.optional(); |
1324 | 0 | } |
1325 | | |
1326 | 0 | inline bool operator==(const ListExpr& lhs, const ListExpr& rhs) { |
1327 | 0 | return absl::c_equal(lhs.elements(), rhs.elements()); |
1328 | 0 | } |
1329 | | |
1330 | 0 | inline bool operator==(const StructExprField& lhs, const StructExprField& rhs) { |
1331 | 0 | return lhs.id() == rhs.id() && lhs.name() == rhs.name() && |
1332 | 0 | lhs.value() == rhs.value() && lhs.optional() == rhs.optional(); |
1333 | 0 | } |
1334 | | |
1335 | 0 | inline bool operator==(const StructExpr& lhs, const StructExpr& rhs) { |
1336 | 0 | return lhs.name() == rhs.name() && absl::c_equal(lhs.fields(), rhs.fields()); |
1337 | 0 | } |
1338 | | |
1339 | 0 | inline bool operator==(const MapExprEntry& lhs, const MapExprEntry& rhs) { |
1340 | 0 | return lhs.id() == rhs.id() && lhs.key() == rhs.key() && |
1341 | 0 | lhs.value() == rhs.value() && lhs.optional() == rhs.optional(); |
1342 | 0 | } |
1343 | | |
1344 | 0 | inline bool operator==(const MapExpr& lhs, const MapExpr& rhs) { |
1345 | 0 | return absl::c_equal(lhs.entries(), rhs.entries()); |
1346 | 0 | } |
1347 | | |
1348 | 0 | inline void MapExpr::Clear() { entries_.clear(); } |
1349 | | |
1350 | 15.1k | inline void MapExpr::set_entries(std::vector<MapExprEntry> entries) { |
1351 | 15.1k | entries_ = std::move(entries); |
1352 | 15.1k | } |
1353 | | |
1354 | 0 | inline void MapExpr::set_entries(absl::Span<MapExprEntry> entries) { |
1355 | 0 | entries_.clear(); |
1356 | 0 | entries_.reserve(entries.size()); |
1357 | 0 | for (auto& entry : entries) { |
1358 | 0 | entries_.push_back(std::move(entry)); |
1359 | 0 | } |
1360 | 0 | } |
1361 | | |
1362 | 3.86k | inline MapExprEntry& MapExpr::add_entries() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1363 | 3.86k | return mutable_entries().emplace_back(); |
1364 | 3.86k | } |
1365 | | |
1366 | 0 | inline std::vector<MapExprEntry> MapExpr::release_entries() { |
1367 | 0 | std::vector<MapExprEntry> entries; |
1368 | 0 | entries.swap(entries_); |
1369 | 0 | return entries; |
1370 | 0 | } |
1371 | | |
1372 | 385k | inline void Expr::Clear() { |
1373 | 385k | u_.id = 0; |
1374 | 385k | mutable_kind().emplace<UnspecifiedExpr>(); |
1375 | 385k | } |
1376 | | |
1377 | 1.19M | inline Expr& Expr::operator=(Expr&&) = default; |
1378 | | |
1379 | 0 | inline void Expr::set_kind(ExprKind kind) { kind_ = std::move(kind); } |
1380 | | |
1381 | 0 | inline ABSL_MUST_USE_RESULT ExprKind Expr::release_kind() { |
1382 | 0 | ExprKind kind = std::move(kind_); |
1383 | 0 | kind_.emplace<UnspecifiedExpr>(); |
1384 | 0 | return kind; |
1385 | 0 | } |
1386 | | |
1387 | 0 | inline void Expr::set_call_expr(CallExpr call_expr) { |
1388 | 0 | try_emplace_kind<CallExpr>() = std::move(call_expr); |
1389 | 0 | } |
1390 | | |
1391 | 0 | inline ABSL_MUST_USE_RESULT CallExpr Expr::release_call_expr() { |
1392 | 0 | return release_kind<CallExpr>(); |
1393 | 0 | } |
1394 | | |
1395 | 0 | inline void Expr::set_list_expr(ListExpr list_expr) { |
1396 | 0 | try_emplace_kind<ListExpr>() = std::move(list_expr); |
1397 | 0 | } |
1398 | | |
1399 | 0 | inline ListExpr Expr::release_list_expr() { return release_kind<ListExpr>(); } |
1400 | | |
1401 | 0 | inline void Expr::set_struct_expr(StructExpr struct_expr) { |
1402 | 0 | try_emplace_kind<StructExpr>() = std::move(struct_expr); |
1403 | 0 | } |
1404 | | |
1405 | 0 | inline StructExpr Expr::release_struct_expr() { |
1406 | 0 | return release_kind<StructExpr>(); |
1407 | 0 | } |
1408 | | |
1409 | 0 | inline void Expr::set_map_expr(MapExpr map_expr) { |
1410 | 0 | try_emplace_kind<MapExpr>() = std::move(map_expr); |
1411 | 0 | } |
1412 | | |
1413 | 0 | inline MapExpr Expr::release_map_expr() { return release_kind<MapExpr>(); } |
1414 | | |
1415 | | template <typename T> |
1416 | 0 | ABSL_MUST_USE_RESULT T Expr::release_kind() { |
1417 | 0 | T result; |
1418 | 0 | if (auto* alt = absl::get_if<T>(&mutable_kind()); alt) { |
1419 | 0 | result = std::move(*alt); |
1420 | 0 | } |
1421 | 0 | kind_.emplace<UnspecifiedExpr>(); |
1422 | 0 | return result; |
1423 | 0 | } Unexecuted instantiation: cel::Constant cel::Expr::release_kind<cel::Constant>() Unexecuted instantiation: cel::IdentExpr cel::Expr::release_kind<cel::IdentExpr>() Unexecuted instantiation: cel::SelectExpr cel::Expr::release_kind<cel::SelectExpr>() Unexecuted instantiation: cel::ComprehensionExpr cel::Expr::release_kind<cel::ComprehensionExpr>() Unexecuted instantiation: cel::CallExpr cel::Expr::release_kind<cel::CallExpr>() Unexecuted instantiation: cel::ListExpr cel::Expr::release_kind<cel::ListExpr>() Unexecuted instantiation: cel::StructExpr cel::Expr::release_kind<cel::StructExpr>() Unexecuted instantiation: cel::MapExpr cel::Expr::release_kind<cel::MapExpr>() |
1424 | | |
1425 | 396k | inline ExprKindCase Expr::kind_case() const { |
1426 | 396k | static_assert(absl::variant_size_v<ExprKind> == 9); |
1427 | 396k | if (kind_.index() <= 9) { |
1428 | 396k | return static_cast<ExprKindCase>(kind_.index()); |
1429 | 396k | } |
1430 | 0 | return ExprKindCase::kUnspecifiedExpr; |
1431 | 396k | } |
1432 | | |
1433 | 0 | inline void swap(Expr& lhs, Expr& rhs) noexcept { |
1434 | 0 | using std::swap; |
1435 | 0 | swap(lhs.u_, rhs.u_); |
1436 | 0 | swap(lhs.kind_, rhs.kind_); |
1437 | 0 | } |
1438 | | |
1439 | 0 | inline void CallExpr::Clear() { |
1440 | 0 | function_.clear(); |
1441 | 0 | target_.reset(); |
1442 | 0 | args_.clear(); |
1443 | 0 | } |
1444 | | |
1445 | 3.93k | inline const Expr& CallExpr::target() const ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1446 | 3.93k | return has_target() ? *target_ : Expr::default_instance(); |
1447 | 3.93k | } |
1448 | | |
1449 | 25.2k | inline Expr& CallExpr::mutable_target() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1450 | 25.2k | if (!has_target()) { |
1451 | 25.2k | target_ = std::make_unique<Expr>(); |
1452 | 25.2k | } |
1453 | 25.2k | return *target_; |
1454 | 25.2k | } |
1455 | | |
1456 | 24.4k | inline void CallExpr::set_target(Expr target) { |
1457 | 24.4k | mutable_target() = std::move(target); |
1458 | 24.4k | } |
1459 | | |
1460 | 0 | inline void CallExpr::set_target(std::unique_ptr<Expr> target) { |
1461 | 0 | target_ = std::move(target); |
1462 | 0 | } |
1463 | | |
1464 | 0 | ABSL_MUST_USE_RESULT inline std::unique_ptr<Expr> CallExpr::release_target() { |
1465 | 0 | return release(target_); |
1466 | 0 | } |
1467 | | |
1468 | 2.59M | inline void CallExpr::set_args(std::vector<Expr> args) { |
1469 | 2.59M | args_ = std::move(args); |
1470 | 2.59M | } |
1471 | | |
1472 | 0 | inline void CallExpr::set_args(absl::Span<Expr> args) { |
1473 | 0 | args_.clear(); |
1474 | 0 | args_.reserve(args.size()); |
1475 | 0 | for (auto& arg : args) { |
1476 | 0 | args_.push_back(std::move(arg)); |
1477 | 0 | } |
1478 | 0 | } |
1479 | | |
1480 | 317k | inline Expr& CallExpr::add_args() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1481 | 317k | return mutable_args().emplace_back(); |
1482 | 317k | } |
1483 | | |
1484 | 0 | inline std::vector<Expr> CallExpr::release_args() { |
1485 | 0 | std::vector<Expr> args; |
1486 | 0 | args.swap(args_); |
1487 | 0 | return args; |
1488 | 0 | } |
1489 | | |
1490 | | inline std::unique_ptr<Expr> CallExpr::release( |
1491 | 0 | std::unique_ptr<Expr>& property) { |
1492 | 0 | std::unique_ptr<Expr> result; |
1493 | 0 | result.swap(property); |
1494 | 0 | return result; |
1495 | 0 | } |
1496 | | |
1497 | 0 | inline void ListExprElement::Clear() { |
1498 | 0 | expr_.reset(); |
1499 | 0 | optional_ = false; |
1500 | 0 | } |
1501 | | |
1502 | | inline ABSL_MUST_USE_RESULT const Expr& ListExprElement::expr() const |
1503 | 72.4k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1504 | 72.4k | return has_expr() ? *expr_ : Expr::default_instance(); |
1505 | 72.4k | } |
1506 | | |
1507 | | inline ABSL_MUST_USE_RESULT Expr& ListExprElement::mutable_expr() |
1508 | 411k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1509 | 411k | if (!has_expr()) { |
1510 | 411k | expr_ = std::make_unique<Expr>(); |
1511 | 411k | } |
1512 | 411k | return *expr_; |
1513 | 411k | } |
1514 | | |
1515 | 380k | inline void ListExprElement::set_expr(Expr expr) { |
1516 | 380k | mutable_expr() = std::move(expr); |
1517 | 380k | } |
1518 | | |
1519 | 0 | inline void ListExprElement::set_expr(std::unique_ptr<Expr> expr) { |
1520 | 0 | expr_ = std::move(expr); |
1521 | 0 | } |
1522 | | |
1523 | 0 | inline ABSL_MUST_USE_RESULT Expr ListExprElement::release_expr() { |
1524 | 0 | return release(expr_); |
1525 | 0 | } |
1526 | | |
1527 | 0 | inline void swap(ListExprElement& lhs, ListExprElement& rhs) noexcept { |
1528 | 0 | using std::swap; |
1529 | 0 | swap(lhs.expr_, rhs.expr_); |
1530 | 0 | swap(lhs.optional_, rhs.optional_); |
1531 | 0 | } |
1532 | | |
1533 | 0 | inline Expr ListExprElement::release(std::unique_ptr<Expr>& property) { |
1534 | 0 | std::unique_ptr<Expr> result; |
1535 | 0 | result.swap(property); |
1536 | 0 | if (result != nullptr) { |
1537 | 0 | return std::move(*result); |
1538 | 0 | } |
1539 | 0 | return Expr{}; |
1540 | 0 | } |
1541 | | |
1542 | 0 | inline void ListExpr::Clear() { elements_.clear(); } |
1543 | | |
1544 | 37.5k | inline void ListExpr::set_elements(std::vector<ListExprElement> elements) { |
1545 | 37.5k | elements_ = std::move(elements); |
1546 | 37.5k | } |
1547 | | |
1548 | 0 | inline void ListExpr::set_elements(absl::Span<ListExprElement> elements) { |
1549 | 0 | elements_.clear(); |
1550 | 0 | elements_.reserve(elements.size()); |
1551 | 0 | for (auto& element : elements) { |
1552 | 0 | elements_.push_back(std::move(element)); |
1553 | 0 | } |
1554 | 0 | } |
1555 | | |
1556 | 31.0k | inline ListExprElement& ListExpr::add_elements() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1557 | 31.0k | return mutable_elements().emplace_back(); |
1558 | 31.0k | } |
1559 | | |
1560 | 0 | inline std::vector<ListExprElement> ListExpr::release_elements() { |
1561 | 0 | std::vector<ListExprElement> elements; |
1562 | 0 | elements.swap(elements_); |
1563 | 0 | return elements; |
1564 | 0 | } |
1565 | | |
1566 | 0 | inline void StructExprField::Clear() { |
1567 | 0 | id_ = 0; |
1568 | 0 | name_.clear(); |
1569 | 0 | value_.reset(); |
1570 | 0 | optional_ = false; |
1571 | 0 | } |
1572 | | |
1573 | | inline ABSL_MUST_USE_RESULT const Expr& StructExprField::value() const |
1574 | 3.50k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1575 | 3.50k | return has_value() ? *value_ : Expr::default_instance(); |
1576 | 3.50k | } |
1577 | | |
1578 | | inline ABSL_MUST_USE_RESULT Expr& StructExprField::mutable_value() |
1579 | 8.41k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1580 | 8.41k | if (!has_value()) { |
1581 | 8.41k | value_ = std::make_unique<Expr>(); |
1582 | 8.41k | } |
1583 | 8.41k | return *value_; |
1584 | 8.41k | } |
1585 | | |
1586 | 7.56k | inline void StructExprField::set_value(Expr value) { |
1587 | 7.56k | mutable_value() = std::move(value); |
1588 | 7.56k | } |
1589 | | |
1590 | 0 | inline void StructExprField::set_value(std::unique_ptr<Expr> value) { |
1591 | 0 | value_ = std::move(value); |
1592 | 0 | } |
1593 | | |
1594 | 0 | inline ABSL_MUST_USE_RESULT Expr StructExprField::release_value() { |
1595 | 0 | return release(value_); |
1596 | 0 | } |
1597 | | |
1598 | 0 | inline void swap(StructExprField& lhs, StructExprField& rhs) noexcept { |
1599 | 0 | using std::swap; |
1600 | 0 | swap(lhs.id_, rhs.id_); |
1601 | 0 | swap(lhs.name_, rhs.name_); |
1602 | 0 | swap(lhs.value_, rhs.value_); |
1603 | 0 | swap(lhs.optional_, rhs.optional_); |
1604 | 0 | } |
1605 | | |
1606 | 0 | inline Expr StructExprField::release(std::unique_ptr<Expr>& property) { |
1607 | 0 | std::unique_ptr<Expr> result; |
1608 | 0 | result.swap(property); |
1609 | 0 | if (result != nullptr) { |
1610 | 0 | return std::move(*result); |
1611 | 0 | } |
1612 | 0 | return Expr{}; |
1613 | 0 | } |
1614 | | |
1615 | 0 | inline void StructExpr::Clear() { |
1616 | 0 | name_.clear(); |
1617 | 0 | fields_.clear(); |
1618 | 0 | } |
1619 | | |
1620 | 7.64k | inline void StructExpr::set_fields(std::vector<StructExprField> fields) { |
1621 | 7.64k | fields_ = std::move(fields); |
1622 | 7.64k | } |
1623 | | |
1624 | 0 | inline void StructExpr::set_fields(absl::Span<StructExprField> fields) { |
1625 | 0 | fields_.clear(); |
1626 | 0 | fields_.reserve(fields.size()); |
1627 | 0 | for (auto& field : fields) { |
1628 | 0 | fields_.push_back(std::move(field)); |
1629 | 0 | } |
1630 | 0 | } |
1631 | | |
1632 | 858 | inline StructExprField& StructExpr::add_fields() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1633 | 858 | return mutable_fields().emplace_back(); |
1634 | 858 | } |
1635 | | |
1636 | 0 | inline std::vector<StructExprField> StructExpr::release_fields() { |
1637 | 0 | std::vector<StructExprField> fields; |
1638 | 0 | fields.swap(fields_); |
1639 | 0 | return fields; |
1640 | 0 | } |
1641 | | |
1642 | 0 | inline void MapExprEntry::Clear() { |
1643 | 0 | id_ = 0; |
1644 | 0 | key_.reset(); |
1645 | 0 | value_.reset(); |
1646 | 0 | optional_ = false; |
1647 | 0 | } |
1648 | | |
1649 | | inline ABSL_MUST_USE_RESULT const Expr& MapExprEntry::key() const |
1650 | 186k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1651 | 186k | return has_key() ? *key_ : Expr::default_instance(); |
1652 | 186k | } |
1653 | | |
1654 | | inline ABSL_MUST_USE_RESULT Expr& MapExprEntry::mutable_key() |
1655 | 286k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1656 | 286k | if (!has_key()) { |
1657 | 286k | key_ = std::make_unique<Expr>(); |
1658 | 286k | } |
1659 | 286k | return *key_; |
1660 | 286k | } |
1661 | | |
1662 | 282k | inline void MapExprEntry::set_key(Expr key) { mutable_key() = std::move(key); } |
1663 | | |
1664 | 0 | inline void MapExprEntry::set_key(std::unique_ptr<Expr> key) { |
1665 | 0 | key_ = std::move(key); |
1666 | 0 | } |
1667 | | |
1668 | 0 | inline ABSL_MUST_USE_RESULT Expr MapExprEntry::release_key() { |
1669 | 0 | return release(key_); |
1670 | 0 | } |
1671 | | |
1672 | | inline ABSL_MUST_USE_RESULT const Expr& MapExprEntry::value() const |
1673 | 186k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1674 | 186k | return has_value() ? *value_ : Expr::default_instance(); |
1675 | 186k | } |
1676 | | |
1677 | | inline ABSL_MUST_USE_RESULT Expr& MapExprEntry::mutable_value() |
1678 | 286k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1679 | 286k | if (!has_value()) { |
1680 | 286k | value_ = std::make_unique<Expr>(); |
1681 | 286k | } |
1682 | 286k | return *value_; |
1683 | 286k | } |
1684 | | |
1685 | 282k | inline void MapExprEntry::set_value(Expr value) { |
1686 | 282k | mutable_value() = std::move(value); |
1687 | 282k | } |
1688 | | |
1689 | 0 | inline void MapExprEntry::set_value(std::unique_ptr<Expr> value) { |
1690 | 0 | value_ = std::move(value); |
1691 | 0 | } |
1692 | | |
1693 | 0 | inline ABSL_MUST_USE_RESULT Expr MapExprEntry::release_value() { |
1694 | 0 | return release(value_); |
1695 | 0 | } |
1696 | | |
1697 | 0 | inline void swap(MapExprEntry& lhs, MapExprEntry& rhs) noexcept { |
1698 | 0 | using std::swap; |
1699 | 0 | swap(lhs.id_, rhs.id_); |
1700 | 0 | swap(lhs.key_, rhs.key_); |
1701 | 0 | swap(lhs.value_, rhs.value_); |
1702 | 0 | swap(lhs.optional_, rhs.optional_); |
1703 | 0 | } |
1704 | | |
1705 | 0 | inline Expr MapExprEntry::release(std::unique_ptr<Expr>& property) { |
1706 | 0 | std::unique_ptr<Expr> result; |
1707 | 0 | result.swap(property); |
1708 | 0 | if (result != nullptr) { |
1709 | 0 | return std::move(*result); |
1710 | 0 | } |
1711 | 0 | return Expr{}; |
1712 | 0 | } |
1713 | | |
1714 | 0 | inline void Expr::SetNext(common_internal::ExprEraseTag&, Expr* next) { |
1715 | 0 | u_.next = next; |
1716 | 0 | } |
1717 | | |
1718 | | } // namespace cel |
1719 | | |
1720 | | #endif // THIRD_PARTY_CEL_CPP_COMMON_EXPR_H_ |