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

Function pruneOptionalStructFields

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

Source from the content-addressed store, hash-verified

398}
399
400func pruneOptionalStructFields(ctx *OptimizerContext, e ast.Expr) {
401 s := e.AsStruct()
402 fields := s.Fields()
403 updatedFields := []ast.EntryExpr{}
404 modified := false
405 for _, f := range fields {
406 field := f.AsStructField()
407 val := field.Value()
408 if !field.IsOptional() || val.Kind() != ast.LiteralKind {
409 updatedFields = append(updatedFields, f)
410 continue
411 }
412 optElemVal, ok := val.AsLiteral().(*types.Optional)
413 if !ok {
414 updatedFields = append(updatedFields, f)
415 continue
416 }
417 modified = true
418 if !optElemVal.HasValue() {
419 continue
420 }
421 ctx.UpdateExpr(val, ctx.NewLiteral(optElemVal.GetValue()))
422 updatedField := ctx.NewStructField(field.Name(), val, false)
423 updatedFields = append(updatedFields, updatedField)
424 }
425 if modified {
426 ctx.UpdateExpr(e, ctx.NewStruct(s.TypeName(), updatedFields))
427 }
428}
429
430// adaptLiteral converts a runtime CEL value to its equivalent literal expression.
431//

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