Represents a directly evaluated CEL expression. Subexpressions assign to values on the C++ program stack and call their dependencies directly. This reduces the setup overhead for evaluation and minimizes value churn to / from a heap based value stack managed by the CEL runtime, but can't be used for arbitrarily nested expressions.
| 37 | // to / from a heap based value stack managed by the CEL runtime, but can't be |
| 38 | // used for arbitrarily nested expressions. |
| 39 | class DirectExpressionStep { |
| 40 | public: |
| 41 | explicit DirectExpressionStep(int64_t expr_id) : expr_id_(expr_id) {} |
| 42 | DirectExpressionStep() : expr_id_(-1) {} |
| 43 | |
| 44 | virtual ~DirectExpressionStep() = default; |
| 45 | |
| 46 | int64_t expr_id() const { return expr_id_; } |
| 47 | bool comes_from_ast() const { return expr_id_ >= 0; } |
| 48 | |
| 49 | virtual absl::Status Evaluate(ExecutionFrameBase& frame, cel::Value& result, |
| 50 | AttributeTrail& attribute) const = 0; |
| 51 | |
| 52 | // Return a type id for this node. |
| 53 | // |
| 54 | // Users must not make any assumptions about the type if the default value is |
| 55 | // returned. |
| 56 | virtual cel::NativeTypeId GetNativeTypeId() const { |
| 57 | return cel::NativeTypeId(); |
| 58 | } |
| 59 | |
| 60 | // Implementations optionally support inspecting the program tree. |
| 61 | virtual absl::optional<std::vector<const DirectExpressionStep*>> |
| 62 | GetDependencies() const { |
| 63 | return absl::nullopt; |
| 64 | } |
| 65 | |
| 66 | // Implementations optionally support extracting the program tree. |
| 67 | // |
| 68 | // Extract prevents the callee from functioning, and is only intended for use |
| 69 | // when replacing a given expression step. |
| 70 | virtual absl::optional<std::vector<std::unique_ptr<DirectExpressionStep>>> |
| 71 | ExtractDependencies() { |
| 72 | return absl::nullopt; |
| 73 | }; |
| 74 | |
| 75 | protected: |
| 76 | int64_t expr_id_; |
| 77 | }; |
| 78 | |
| 79 | // Wrapper for direct steps to work with the stack machine impl. |
| 80 | class WrappedDirectStep : public ExpressionStep { |