From 2fb2ebc32ee37a66e3d6a77ff9450665153a604c Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Tue, 25 Apr 2017 08:51:52 -0700 Subject: [PATCH] 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 Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/syntax.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/cmd/compile/internal/gc/syntax.go b/src/cmd/compile/internal/gc/syntax.go index bcc8df0af69..d59e77c7e94 100644 --- a/src/cmd/compile/internal/gc/syntax.go +++ b/src/cmd/compile/internal/gc/syntax.go @@ -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 }