Walkdef uint8 // tracks state during typecheckdef; 2 == loop detected
Typecheck uint8 // tracks state during typechecking; 2 == loop detected
Initorder uint8
- hasVal int8 // +1 for Val, -1 for Opt, 0 for not yet set
}
// IsAutoTmp indicates if n was created by the compiler as a temporary,
nodeUsed // for variable/label declared and not used error
nodeHasCall // expression contains a function call
nodeLikely // if statement condition likely
+ nodeHasVal // node.E contains a Val
+ nodeHasOpt // node.E contains an Opt
)
func (n *Node) HasBreak() bool { return n.flags&nodeHasBreak != 0 }
func (n *Node) Used() bool { return n.flags&nodeUsed != 0 }
func (n *Node) HasCall() bool { return n.flags&nodeHasCall != 0 }
func (n *Node) Likely() bool { return n.flags&nodeLikely != 0 }
+func (n *Node) HasVal() bool { return n.flags&nodeHasVal != 0 }
+func (n *Node) HasOpt() bool { return n.flags&nodeHasOpt != 0 }
func (n *Node) SetHasBreak(b bool) { n.flags.set(nodeHasBreak, b) }
func (n *Node) SetIsClosureVar(b bool) { n.flags.set(nodeIsClosureVar, b) }
func (n *Node) SetUsed(b bool) { n.flags.set(nodeUsed, b) }
func (n *Node) SetHasCall(b bool) { n.flags.set(nodeHasCall, b) }
func (n *Node) SetLikely(b bool) { n.flags.set(nodeLikely, b) }
+func (n *Node) SetHasVal(b bool) { n.flags.set(nodeHasVal, b) }
+func (n *Node) SetHasOpt(b bool) { n.flags.set(nodeHasOpt, b) }
// Val returns the Val for the node.
func (n *Node) Val() Val {
- if n.hasVal != +1 {
+ if !n.HasVal() {
return Val{}
}
return Val{n.E}
// SetVal sets the Val for the node, which must not have been used with SetOpt.
func (n *Node) SetVal(v Val) {
- if n.hasVal == -1 {
+ if n.HasOpt() {
Debug['h'] = 1
Dump("have Opt", n)
Fatalf("have Opt")
}
- n.hasVal = +1
+ n.SetHasVal(true)
n.E = v.U
}
// Opt returns the optimizer data for the node.
func (n *Node) Opt() interface{} {
- if n.hasVal != -1 {
+ if !n.HasOpt() {
return nil
}
return n.E
// SetOpt sets the optimizer data for the node, which must not have been used with SetVal.
// SetOpt(nil) is ignored for Vals to simplify call sites that are clearing Opts.
func (n *Node) SetOpt(x interface{}) {
- if x == nil && n.hasVal >= 0 {
+ if x == nil && n.HasVal() {
return
}
- if n.hasVal == +1 {
+ if n.HasVal() {
Debug['h'] = 1
Dump("have Val", n)
Fatalf("have Val")
}
- n.hasVal = -1
+ n.SetHasOpt(true)
n.E = x
}