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