| 89 | } |
| 90 | |
| 91 | absl::StatusOr<bool> Evaluate(const CheckedExpr& expr, |
| 92 | const AttributeContext& context) { |
| 93 | Activation activation; |
| 94 | CEL_RETURN_IF_ERROR(BindProtoToActivation(&context, &arena_, &activation)); |
| 95 | CEL_ASSIGN_OR_RETURN(auto plan, builder_->CreateExpression(&expr)); |
| 96 | CEL_ASSIGN_OR_RETURN(CelValue result, plan->Evaluate(activation, &arena_)); |
| 97 | |
| 98 | if (bool value; result.GetValue(&value)) { |
| 99 | return value; |
| 100 | } else if (const CelError * value; result.GetValue(&value)) { |
| 101 | return *value; |
| 102 | } else { |
| 103 | return absl::InvalidArgumentError( |
| 104 | absl::StrCat("unexpected return type: ", result.DebugString())); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | private: |
| 109 | google::protobuf::Arena arena_; |