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

Function ConfigureNetworkFunctions

codelab/network_functions.cc:122–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122absl::Status ConfigureNetworkFunctions(cel::TypeCheckerBuilder& builder) {
123 // Type identifiers
124 CEL_RETURN_IF_ERROR(builder.AddVariable(
125 MakeVariableDecl("net.Address", TypeOfAddressType())));
126 CEL_RETURN_IF_ERROR(builder.AddVariable(
127 MakeVariableDecl("net.AddressMatcher", TypeOfAddressMatcherType())));
128 CEL_RETURN_IF_ERROR(builder.AddVariable(
129 MakeVariableDecl("net.addressZeroValue", AddressType())));
130
131 // net.parseAddress(string) -> net.Address
132 CEL_ASSIGN_OR_RETURN(
133 auto decl,
134 MakeFunctionDecl("net.parseAddress",
135 MakeOverloadDecl("net_parseAddress_string",
136 AddressType(), cel::StringType())));
137
138 CEL_RETURN_IF_ERROR(builder.AddFunction(decl));
139 // net.parseAddressOrZero(string) -> net.Address
140 CEL_ASSIGN_OR_RETURN(
141 decl,
142 MakeFunctionDecl("net.parseAddressOrZero",
143 MakeOverloadDecl("net_parseAddressOrZero_string",
144 AddressType(), cel::StringType())));
145 CEL_RETURN_IF_ERROR(builder.AddFunction(decl));
146
147 // net.parseAddressMatcher(string) -> net.AddressMatcher
148 CEL_ASSIGN_OR_RETURN(
149 decl, MakeFunctionDecl(
150 "net.parseAddressMatcher",
151 MakeOverloadDecl("net_parseAddressMatcher_string",
152 AddressMatcherType(), cel::StringType())));
153 CEL_RETURN_IF_ERROR(builder.AddFunction(decl));
154
155 // (net.AddressMatcher).containsAddress(net.Address) -> bool
156 CEL_ASSIGN_OR_RETURN(
157 decl, MakeFunctionDecl(
158 "containsAddress",
159 MakeMemberOverloadDecl(
160 "net_AddressMatcher_containsAddress_net_Address",
161 cel::BoolType(), AddressMatcherType(), AddressType()),
162 MakeMemberOverloadDecl(
163 "net_AddressMatcher_containsAddress_string",
164 cel::BoolType(), AddressMatcherType(), cel::StringType())));
165 CEL_RETURN_IF_ERROR(builder.AddFunction(decl));
166
167 return absl::OkStatus();
168}
169
170// =============================================================================
171// Opaque Value type implementations for NetworkAddressRep.

Callers

nothing calls this directly

Calls 13

MakeVariableDeclFunction · 0.85
TypeOfAddressTypeFunction · 0.85
TypeOfAddressMatcherTypeFunction · 0.85
AddressTypeFunction · 0.85
MakeOverloadDeclFunction · 0.85
MakeFunctionDeclFunction · 0.85
AddressMatcherTypeFunction · 0.85
MakeMemberOverloadDeclFunction · 0.85
AddVariableMethod · 0.80
StringTypeClass · 0.50
CEL_ASSIGN_OR_RETURNFunction · 0.50
BoolTypeClass · 0.50

Tested by

no test coverage detected