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

Function pruneOptionalElements

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

341// statements, so this method exists to handle the case where the literal could not be
342// fully resolved or exists outside of a call, select, or comprehension context.
343func pruneOptionalElements(ctx *OptimizerContext, root ast.NavigableExpr) {
344 aggregateLiterals := ast.MatchDescendants(root, aggregateLiteralMatcher)
345 for _, lit := range aggregateLiterals {
346 switch lit.Kind() {
347 case ast.ListKind:
348 pruneOptionalListElements(ctx, lit)
349 case ast.MapKind:
350 pruneOptionalMapEntries(ctx, lit)
351 case ast.StructKind:
352 pruneOptionalStructFields(ctx, lit)
353 }
354 }
355}
356
357func pruneOptionalListElements(ctx *OptimizerContext, e ast.Expr) {
358 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