Commit 2fb2ebc3 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: make node.hasVal into two bools

In addition to being more compact,
this makes the code a lot clearer.

Change-Id: Ibcb70526c2e5913dcf34904fda194e3585228c3f
Reviewed-on: https://go-review.googlesource.com/41761
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 7f0757b3
......@@ -62,7 +62,6 @@ type Node struct {
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,
......@@ -93,6 +92,8 @@ const (
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 }
......@@ -113,6 +114,8 @@ func (n *Node) Addable() bool { return n.flags&nodeAddable != 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) }
......@@ -132,10 +135,12 @@ func (n *Node) SetAddable(b bool) { n.flags.set(nodeAddable, 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}
......@@ -143,18 +148,18 @@ func (n *Node) Val() Val {
// 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
......@@ -163,15 +168,15 @@ func (n *Node) Opt() interface{} {
// 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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment