MCPcopy Create free account
hub / github.com/cel-expr/cel-go / pruneOptionalElements

Function pruneOptionalElements

cel/folding.go:264–276  ·  view source on GitHub ↗

pruneOptionalElements works from the bottom up to resolve optional elements within aggregate literals. Note, many aggregate literals will be resolved as arguments to functions or select statements, so this method exists to handle the case where the literal could not be fully resolved or exists outs

(ctx *OptimizerContext, root ast.NavigableExpr)

Source from the content-addressed store, hash-verified

262// statements, so this method exists to handle the case where the literal could not be
263// fully resolved or exists outside of a call, select, or comprehension context.
264func pruneOptionalElements(ctx *OptimizerContext, root ast.NavigableExpr) {
265 aggregateLiterals := ast.MatchDescendants(root, aggregateLiteralMatcher)
266 for _, lit := range aggregateLiterals {
267 switch lit.Kind() {
268 case ast.ListKind:
269 pruneOptionalListElements(ctx, lit)
270 case ast.MapKind:
271 pruneOptionalMapEntries(ctx, lit)
272 case ast.StructKind:
273 pruneOptionalStructFields(ctx, lit)
274 }
275 }
276}
277
278func pruneOptionalListElements(ctx *OptimizerContext, e ast.Expr) {
279 l := e.AsList()

Callers 1

OptimizeMethod · 0.85

Calls 5

MatchDescendantsFunction · 0.92
pruneOptionalMapEntriesFunction · 0.85
KindMethod · 0.65

Tested by

no test coverage detected