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

Function pruneOptionalStructFields

cel/folding.go:438–466  ·  view source on GitHub ↗
(ctx *OptimizerContext, e ast.Expr)

Source from the content-addressed store, hash-verified

436}
437
438func pruneOptionalStructFields(ctx *OptimizerContext, e ast.Expr) {
439 s := e.AsStruct()
440 fields := s.Fields()
441 updatedFields := []ast.EntryExpr{}
442 modified := false
443 for _, f := range fields {
444 field := f.AsStructField()
445 val := field.Value()
446 if !field.IsOptional() || val.Kind() != ast.LiteralKind {
447 updatedFields = append(updatedFields, f)
448 continue
449 }
450 optElemVal, ok := val.AsLiteral().(*types.Optional)
451 if !ok {
452 updatedFields = append(updatedFields, f)
453 continue
454 }
455 modified = true
456 if !optElemVal.HasValue() {
457 continue
458 }
459 ctx.UpdateExpr(val, ctx.NewLiteral(optElemVal.GetValue()))
460 updatedField := ctx.NewStructField(field.Name(), val, false)
461 updatedFields = append(updatedFields, updatedField)
462 }
463 if modified {
464 ctx.UpdateExpr(e, ctx.NewStruct(s.TypeName(), updatedFields))
465 }
466}
467
468// adaptLiteral converts a runtime CEL value to its equivalent literal expression.
469//

Callers 1

pruneOptionalElementsFunction · 0.85

Calls 15

HasValueMethod · 0.80
UpdateExprMethod · 0.80
GetValueMethod · 0.80
AsStructMethod · 0.65
FieldsMethod · 0.65
AsStructFieldMethod · 0.65
ValueMethod · 0.65
IsOptionalMethod · 0.65
KindMethod · 0.65
AsLiteralMethod · 0.65
NewLiteralMethod · 0.65
NewStructFieldMethod · 0.65

Tested by

no test coverage detected