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

Method Exec

interpreter/interpretable.go:1258–1322  ·  view source on GitHub ↗

Exec implements the InterpretableV2 interface method.

(frame *ExecutionFrame)

Source from the content-addressed store, hash-verified

1256
1257// Exec implements the InterpretableV2 interface method.
1258func (o *evalObj) Exec(frame *ExecutionFrame) ref.Val {
1259 fieldVals := make(map[string]ref.Val, len(o.fields))
1260 var unk *types.Unknown
1261 if !o.hasOptionals {
1262 for i, field := range o.fields {
1263 val := o.vals[i].Exec(frame)
1264 switch v := val.(type) {
1265 case *types.Err:
1266 return v
1267 case *types.Unknown:
1268 if unk == nil {
1269 unk = v
1270 } else {
1271 unk = types.MergeUnknowns(unk, v)
1272 }
1273 }
1274 fieldVals[field] = val
1275 }
1276 if unk != nil {
1277 trackCostCreateStruct(frame, o.id, unk)
1278 return unk
1279 }
1280 res := labelErrNode(o.id, o.provider.NewValue(o.typeName, fieldVals))
1281 trackCostCreateStruct(frame, o.id, res)
1282 return res
1283 }
1284
1285 for i, field := range o.fields {
1286 val := o.vals[i].Exec(frame)
1287 switch v := val.(type) {
1288 case *types.Err:
1289 return v
1290 case *types.Unknown:
1291 if unk == nil {
1292 unk = v
1293 } else {
1294 unk = types.MergeUnknowns(unk, v)
1295 }
1296 case *types.Optional:
1297 if o.optionals[i] {
1298 if !v.HasValue() {
1299 delete(fieldVals, field)
1300 continue
1301 }
1302 val = v.GetValue()
1303 }
1304 default:
1305 if o.optionals[i] {
1306 return types.LabelErrNode(o.id, invalidOptionalEntryInit(field, val))
1307 }
1308 }
1309 fieldVals[field] = val
1310 }
1311 if unk != nil {
1312 if costs := frame.CostTracker(); costs != nil {
1313 costs.CreateStruct(o.id, unk)
1314 }
1315 return unk

Callers

nothing calls this directly

Calls 11

MergeUnknownsFunction · 0.92
LabelErrNodeFunction · 0.92
trackCostCreateStructFunction · 0.85
labelErrNodeFunction · 0.85
invalidOptionalEntryInitFunction · 0.85
HasValueMethod · 0.80
GetValueMethod · 0.80
CostTrackerMethod · 0.80
CreateStructMethod · 0.80
ExecMethod · 0.65
NewValueMethod · 0.65

Tested by

no test coverage detected