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

Function MakeConfiguredCompiler

codelab/exercise4.cc:55–72  ·  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>> MakeConfiguredCompiler() {
56 // Setup for handling for protobuf types.
57 // Using the generated descriptor pool is simpler to configure, but often
58 // adds more types than necessary.
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 CEL_RETURN_IF_ERROR(builder->AddLibrary(cel::StandardCompilerLibrary()));
64 // Adds fields of AttributeContext as variables.
65 CEL_RETURN_IF_ERROR(builder->GetCheckerBuilder().AddContextDeclaration(
66 AttributeContext::descriptor()->full_name()));
67
68 // Codelab part 1:
69 // Add a declaration for the map<string, V>.contains(string, V) function.
70 // Hint: use cel::MakeFunctionDecl and cel::TypeCheckerBuilder::MergeFunction.
71 return builder->Build();
72}
73
74class Evaluator {
75 public:

Callers 1

Calls 6

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

Tested by

no test coverage detected