| 197 | class BenchmarkState { |
| 198 | public: |
| 199 | static absl::StatusOr<BenchmarkState> Create(bool optimize) { |
| 200 | CEL_ASSIGN_OR_RETURN( |
| 201 | auto compiler_builder, |
| 202 | cel::NewCompilerBuilder(cel::GetMinimalDescriptorPool())); |
| 203 | CEL_RETURN_IF_ERROR( |
| 204 | compiler_builder->AddLibrary(cel::StandardCompilerLibrary())); |
| 205 | CEL_RETURN_IF_ERROR( |
| 206 | compiler_builder->AddLibrary(NetworkFunctionsCompilerLibrary())); |
| 207 | compiler_builder->GetCheckerBuilder() |
| 208 | .AddVariable(MakeVariableDecl("ip", cel::StringType())) |
| 209 | .IgnoreError(); |
| 210 | |
| 211 | CEL_ASSIGN_OR_RETURN(auto compiler, compiler_builder->Build()); |
| 212 | |
| 213 | RuntimeOptions runtime_options; |
| 214 | CEL_ASSIGN_OR_RETURN(auto runtime_builder, |
| 215 | CreateStandardRuntimeBuilder( |
| 216 | cel::GetMinimalDescriptorPool(), runtime_options)); |
| 217 | CEL_RETURN_IF_ERROR( |
| 218 | RegisterNetworkTypes(runtime_builder.type_registry(), runtime_options)); |
| 219 | CEL_RETURN_IF_ERROR(RegisterNetworkFunctions( |
| 220 | runtime_builder.function_registry(), runtime_options)); |
| 221 | |
| 222 | if (optimize) { |
| 223 | CEL_RETURN_IF_ERROR( |
| 224 | cel::extensions::EnableConstantFolding(runtime_builder)); |
| 225 | } |
| 226 | CEL_ASSIGN_OR_RETURN(auto runtime, std::move(runtime_builder).Build()); |
| 227 | return BenchmarkState(std::move(compiler), std::move(runtime)); |
| 228 | } |
| 229 | |
| 230 | absl::StatusOr<std::unique_ptr<Program>> MakeProgram(absl::string_view expr) { |
| 231 | CEL_ASSIGN_OR_RETURN(auto result, compiler_->Compile(expr)); |
nothing calls this directly
no test coverage detected