Parse a cel expression and evaluate it against the given activation and arena.
| 77 | // Parse a cel expression and evaluate it against the given activation and |
| 78 | // arena. |
| 79 | absl::StatusOr<bool> EvalCheckedExpr(const CheckedExpr& checked_expr, |
| 80 | const Activation& activation, |
| 81 | google::protobuf::Arena* arena) { |
| 82 | // Setup a default environment for building expressions. |
| 83 | InterpreterOptions options; |
| 84 | std::unique_ptr<CelExpressionBuilder> builder = CreateCelExpressionBuilder( |
| 85 | google::protobuf::DescriptorPool::generated_pool(), |
| 86 | google::protobuf::MessageFactory::generated_factory(), options); |
| 87 | CEL_RETURN_IF_ERROR( |
| 88 | RegisterBuiltinFunctions(builder->GetRegistry(), options)); |
| 89 | |
| 90 | // Note, the expression_plan below is reusable for different inputs, but we |
| 91 | // create one just in time for evaluation here. |
| 92 | CEL_ASSIGN_OR_RETURN(std::unique_ptr<CelExpression> expression_plan, |
| 93 | builder->CreateExpression(&checked_expr)); |
| 94 | |
| 95 | CEL_ASSIGN_OR_RETURN(CelValue result, |
| 96 | expression_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(absl::StrCat( |
| 104 | "expected 'bool' result got '", result.DebugString(), "'")); |
| 105 | } |
| 106 | } |
| 107 | } // namespace |
| 108 | |
| 109 | absl::StatusOr<bool> CompileAndEvaluateWithBoolVar(absl::string_view cel_expr, |
no test coverage detected