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

Method Exec

interpreter/interpretable.go:637–675  ·  view source on GitHub ↗

Exec implements the InterpretableV2 interface method.

(frame *ExecutionFrame)

Source from the content-addressed store, hash-verified

635
636// Exec implements the InterpretableV2 interface method.
637func (un *evalUnary) Exec(frame *ExecutionFrame) ref.Val {
638 argVal := un.arg.Exec(frame)
639 // Early return if the argument to the function is error or unknown in strict mode.
640 strict := !un.nonStrict
641 if strict {
642 switch v := argVal.(type) {
643 case *types.Err:
644 // To preserve legacy cost tracking behavior for logical not,
645 // this cost is tracked, but will be removed in the future.
646 if un.function == operators.LogicalNot {
647 if costs := frame.CostTracker(); costs != nil {
648 costs.EvalUnary(frame, un.id, un, argVal, argVal)
649 }
650 }
651 return v
652 case *types.Unknown:
653 if costs := frame.CostTracker(); costs != nil {
654 costs.EvalUnary(frame, un.id, un, argVal, argVal)
655 }
656 return v
657 }
658 }
659 var res ref.Val
660 // If the implementation is bound and the argument value has the right traits required to
661 // invoke it, then call the implementation.
662 if un.impl != nil && (un.trait == 0 || matchOperandTrait(un.trait, strict, argVal)) {
663 res = labelErrNode(un.id, un.impl(argVal))
664 } else if argVal.Type().HasTrait(traits.ReceiverType) {
665 // Otherwise, if the argument is a ReceiverType attempt to invoke the receiver method on the
666 // operand (arg0).
667 res = labelErrNode(un.id, argVal.(traits.Receiver).Receive(un.function, un.overload, []ref.Val{}))
668 } else {
669 res = types.NewErrWithNodeID(un.id, "no such overload: %s", un.function)
670 }
671 if costs := frame.CostTracker(); costs != nil {
672 costs.EvalUnary(frame, un.id, un, argVal, res)
673 }
674 return res
675}
676
677// Eval implements the Interpretable interface method.
678func (un *evalUnary) Eval(ctx Activation) ref.Val {

Callers

nothing calls this directly

Calls 9

NewErrWithNodeIDFunction · 0.92
labelErrNodeFunction · 0.85
CostTrackerMethod · 0.80
EvalUnaryMethod · 0.80
matchOperandTraitFunction · 0.70
ExecMethod · 0.65
HasTraitMethod · 0.65
TypeMethod · 0.65
ReceiveMethod · 0.65

Tested by

no test coverage detected