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

Function MakeCelCompiler

codelab/solutions/exercise2.cc:60–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58using ::google::rpc::context::AttributeContext;
59
60absl::StatusOr<std::unique_ptr<cel::Compiler>> MakeCelCompiler() {
61 // Note: we are using the generated descriptor pool here for simplicity, but
62 // it has the drawback of including all message types that are linked into the
63 // binary instead of just the ones expected for the CEL environment.
64 google::protobuf::LinkMessageReflection<AttributeContext>();
65 CEL_ASSIGN_OR_RETURN(
66 std::unique_ptr<cel::CompilerBuilder> builder,
67 cel::NewCompilerBuilder(google::protobuf::DescriptorPool::generated_pool()));
68
69 CEL_RETURN_IF_ERROR(builder->AddLibrary(cel::StandardCompilerLibrary()));
70 // === Start Codelab ===
71 cel::TypeCheckerBuilder& checker_builder = builder->GetCheckerBuilder();
72 CEL_RETURN_IF_ERROR(checker_builder.AddVariable(
73 cel::MakeVariableDecl("bool_var", cel::BoolType())));
74 CEL_RETURN_IF_ERROR(checker_builder.AddContextDeclaration(
75 AttributeContext::descriptor()->full_name()));
76 // === End Codelab ===
77
78 return builder->Build();
79}
80
81// Parse a cel expression and evaluate it against the given activation and
82// arena.

Callers 2

Calls 9

StandardCompilerLibraryFunction · 0.85
MakeVariableDeclFunction · 0.85
AddVariableMethod · 0.80
AddContextDeclarationMethod · 0.80
CEL_ASSIGN_OR_RETURNFunction · 0.50
NewCompilerBuilderFunction · 0.50
BoolTypeClass · 0.50
AddLibraryMethod · 0.45
BuildMethod · 0.45

Tested by

no test coverage detected