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

Function pruneOptionalStructFields

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

Source from the content-addressed store, hash-verified

418}
419
420func pruneOptionalStructFields(ctx *OptimizerContext, e ast.Expr) {
421 s := e.AsStruct()
422 fields := s.Fields()
423 updatedFields := []ast.EntryExpr{}
424 modified := false
425 for _, f := range fields {
426 field := f.AsStructField()
427 val := field.Value()
428 if !field.IsOptional() || val.Kind() != ast.LiteralKind {
429 updatedFields = append(updatedFields, f)
430 continue
431 }
432 optElemVal, ok := val.AsLiteral().(*types.Optional)
433 if !ok {
434 updatedFields = append(updatedFields, f)
435 continue
436 }
437 modified = true
438 if !optElemVal.HasValue() {
439 continue
440 }
441 ctx.UpdateExpr(val, ctx.NewLiteral(optElemVal.GetValue()))
442 updatedField := ctx.NewStructField(field.Name(), val, false)
443 updatedFields = append(updatedFields, updatedField)
444 }
445 if modified {
446 ctx.UpdateExpr(e, ctx.NewStruct(s.TypeName(), updatedFields))
447 }
448}
449
450// adaptLiteral converts a runtime CEL value to its equivalent literal expression.
451//

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