MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / Create

Method Create

codelab/network_functions_test.cc:199–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197class 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));

Callers

nothing calls this directly

Calls 10

StandardCompilerLibraryFunction · 0.85
MakeVariableDeclFunction · 0.85
RegisterNetworkTypesFunction · 0.85
RegisterNetworkFunctionsFunction · 0.85
EnableConstantFoldingFunction · 0.85
BenchmarkStateClass · 0.85
AddVariableMethod · 0.80
StringTypeClass · 0.50
AddLibraryMethod · 0.45

Tested by

no test coverage detected