MCPcopy
hub / github.com/expr-lang/expr / ChainNode

Method ChainNode

compiler/compiler.go:660–680  ·  view source on GitHub ↗
(node *ast.ChainNode)

Source from the content-addressed store, hash-verified

658}
659
660func (c *compiler) ChainNode(node *ast.ChainNode) {
661 c.chains = append(c.chains, []int{})
662 c.compile(node.Node)
663 for _, ph := range c.chains[len(c.chains)-1] {
664 c.patchJump(ph) // If chain activated jump here (got nit somewhere).
665 }
666 parent := c.nodeParent()
667 if binary, ok := parent.(*ast.BinaryNode); ok && binary.Operator == "??" {
668 // If chain is used in nil coalescing operator, we can omit
669 // nil push at the end of the chain. The ?? operator will
670 // handle it.
671 } else {
672 // We need to put the nil on the stack, otherwise "typed"
673 // nil will be used as a result of the chain.
674 j := c.emit(OpJumpIfNotNil, placeholder)
675 c.emit(OpPop)
676 c.emit(OpNil)
677 c.patchJump(j)
678 }
679 c.chains = c.chains[:len(c.chains)-1]
680}
681
682func (c *compiler) MemberNode(node *ast.MemberNode) {
683 var env Nature

Callers 1

compileMethod · 0.95

Calls 4

compileMethod · 0.95
patchJumpMethod · 0.95
nodeParentMethod · 0.95
emitMethod · 0.95

Tested by

no test coverage detected