| 103 | }; |
| 104 | |
| 105 | absl::StatusOr<cel::Value> CompileAndEvalExpr( |
| 106 | Env& env, absl::string_view expr, |
| 107 | const Activation& activation = Activation()) { |
| 108 | CEL_ASSIGN_OR_RETURN(std::unique_ptr<Compiler> compiler, env.NewCompiler()); |
| 109 | if (compiler == nullptr) { |
| 110 | return absl::InternalError("Failed to create compiler"); |
| 111 | } |
| 112 | CEL_ASSIGN_OR_RETURN(ValidationResult result, compiler->Compile(expr)); |
| 113 | if (!result.GetIssues().empty()) { |
| 114 | return absl::InvalidArgumentError(result.FormatError()); |
| 115 | } |
| 116 | |
| 117 | cel::RuntimeOptions opts; |
| 118 | CEL_ASSIGN_OR_RETURN( |
| 119 | cel::RuntimeBuilder rt_builder, |
| 120 | cel::CreateStandardRuntimeBuilder(env.GetDescriptorPool(), opts)); |
| 121 | CEL_RETURN_IF_ERROR(cel::EnableReferenceResolver( |
| 122 | rt_builder, cel::ReferenceResolverEnabled::kAlways)); |
| 123 | CEL_ASSIGN_OR_RETURN(std::unique_ptr<cel::Runtime> runtime, |
| 124 | std::move(rt_builder).Build()); |
| 125 | if (runtime == nullptr) { |
| 126 | return absl::InternalError("Failed to create runtime"); |
| 127 | } |
| 128 | |
| 129 | CEL_ASSIGN_OR_RETURN(std::unique_ptr<Ast> ast, result.ReleaseAst()); |
| 130 | if (ast == nullptr) { |
| 131 | return absl::InternalError("Failed to create AST"); |
| 132 | } |
| 133 | google::protobuf::Arena arena; |
| 134 | CEL_ASSIGN_OR_RETURN(std::unique_ptr<Program> program, |
| 135 | runtime->CreateProgram(std::move(ast))); |
| 136 | if (program == nullptr) { |
| 137 | return absl::InternalError("Failed to create program"); |
| 138 | } |
| 139 | CEL_ASSIGN_OR_RETURN(Value value, program->Evaluate(&arena, activation)); |
| 140 | return value; |
| 141 | } |
| 142 | |
| 143 | absl::StatusOr<bool> CompileAndEvalBooleanExpr( |
| 144 | Env& env, absl::string_view expr, |
nothing calls this directly
no test coverage detected