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

Function pruneOptionalElements

cel/folding.go:305–317  ·  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

303// statements, so this method exists to handle the case where the literal could not be
304// fully resolved or exists outside of a call, select, or comprehension context.
305func pruneOptionalElements(ctx *OptimizerContext, root ast.NavigableExpr) {
306 aggregateLiterals := ast.MatchDescendants(root, aggregateLiteralMatcher)
307 for _, lit := range aggregateLiterals {
308 switch lit.Kind() {
309 case ast.ListKind:
310 pruneOptionalListElements(ctx, lit)
311 case ast.MapKind:
312 pruneOptionalMapEntries(ctx, lit)
313 case ast.StructKind:
314 pruneOptionalStructFields(ctx, lit)
315 }
316 }
317}
318
319func pruneOptionalListElements(ctx *OptimizerContext, e ast.Expr) {
320 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