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

Function MakeCelCompiler

codelab/exercise2.cc:55–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53using ::google::rpc::context::AttributeContext;
54
55absl::StatusOr<std::unique_ptr<cel::Compiler>> MakeCelCompiler() {
56 // Note: we are using the generated descriptor pool here for simplicity, but
57 // it has the drawback of including all message types that are linked into the
58 // binary instead of just the ones expected for the CEL environment.
59 google::protobuf::LinkMessageReflection<AttributeContext>();
60 CEL_ASSIGN_OR_RETURN(
61 std::unique_ptr<cel::CompilerBuilder> builder,
62 cel::NewCompilerBuilder(google::protobuf::DescriptorPool::generated_pool()));
63
64 CEL_RETURN_IF_ERROR(builder->AddLibrary(cel::StandardCompilerLibrary()));
65 // === Start Codelab ===
66 // Add 'AttributeContext' as a context message to the type checker and a
67 // boolean variable 'bool_var'. Relevant functions are on the
68 // TypeCheckerBuilder class (see CompilerBuilder::GetCheckerBuilder).
69 //
70 // We're reusing the same compiler for both evaluation paths here for brevity,
71 // but it's likely a better fit to configure a separate compiler per use case.
72 // === End Codelab ===
73
74 return builder->Build();
75}
76
77// Parse a cel expression and evaluate it against the given activation and
78// arena.

Callers 2

Calls 5

StandardCompilerLibraryFunction · 0.85
CEL_ASSIGN_OR_RETURNFunction · 0.50
NewCompilerBuilderFunction · 0.50
AddLibraryMethod · 0.45
BuildMethod · 0.45

Tested by

no test coverage detected