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

Function proto_macros

extensions/proto_ext.cc:92–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90} // namespace
91
92std::vector<Macro> proto_macros() {
93 absl::StatusOr<Macro> getExt = Macro::Receiver(
94 kGetExt, 2,
95 [](MacroExprFactory& factory, Expr& target,
96 absl::Span<Expr> arguments) -> absl::optional<Expr> {
97 if (!IsExtensionCall(target)) {
98 return absl::nullopt;
99 }
100 auto extFieldName = GetExtensionFieldName(arguments[1]);
101 if (!extFieldName.has_value()) {
102 return factory.ReportErrorAt(arguments[1], "invalid extension field");
103 }
104 return factory.NewSelect(std::move(arguments[0]),
105 std::move(*extFieldName));
106 });
107 absl::StatusOr<Macro> hasExt = Macro::Receiver(
108 kHasExt, 2,
109 [](MacroExprFactory& factory, Expr& target,
110 absl::Span<Expr> arguments) -> absl::optional<Expr> {
111 if (!IsExtensionCall(target)) {
112 return absl::nullopt;
113 }
114 auto extFieldName = GetExtensionFieldName(arguments[1]);
115 if (!extFieldName.has_value()) {
116 return factory.ReportErrorAt(arguments[1], "invalid extension field");
117 }
118 return factory.NewPresenceTest(std::move(arguments[0]),
119 std::move(*extFieldName));
120 });
121 return {*hasExt, *getExt};
122}
123
124CompilerLibrary ProtoExtCompilerLibrary() {
125 return CompilerLibrary("cel.lib.ext.proto", ConfigureParser);

Callers 2

RegisterProtoMacrosFunction · 0.85
ConfigureParserFunction · 0.85

Calls 6

IsExtensionCallFunction · 0.85
GetExtensionFieldNameFunction · 0.85
has_valueMethod · 0.45
ReportErrorAtMethod · 0.45
NewSelectMethod · 0.45
NewPresenceTestMethod · 0.45

Tested by

no test coverage detected