cmd/compile: refactor constant node constructors

Passes toolstash-check.

Change-Id: I6a2d46e69d4d3a06858c80c4ea1ad3f5a58f6956
Reviewed-on: https://go-review.googlesource.com/103859
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Matthew Dempsky 2018-03-31 15:53:21 -07:00
parent 917c33fe86
commit fdf33730e1
2 changed files with 9 additions and 20 deletions

View file

@ -1246,6 +1246,7 @@ illegal:
} }
} }
// nodlit returns a new untyped constant with value v.
func nodlit(v Val) *Node { func nodlit(v Val) *Node {
n := nod(OLITERAL, nil, nil) n := nod(OLITERAL, nil, nil)
n.SetVal(v) n.SetVal(v)

View file

@ -413,21 +413,15 @@ func (x methcmp) Less(i, j int) bool {
} }
func nodintconst(v int64) *Node { func nodintconst(v int64) *Node {
c := nod(OLITERAL, nil, nil) u := new(Mpint)
c.SetAddable(true) u.SetInt64(v)
c.SetVal(Val{new(Mpint)}) return nodlit(Val{u})
c.Val().U.(*Mpint).SetInt64(v)
c.Type = types.Types[TIDEAL]
return c
} }
func nodfltconst(v *Mpflt) *Node { func nodfltconst(v *Mpflt) *Node {
c := nod(OLITERAL, nil, nil) u := newMpflt()
c.SetAddable(true) u.Set(v)
c.SetVal(Val{newMpflt()}) return nodlit(Val{u})
c.Val().U.(*Mpflt).Set(v)
c.Type = types.Types[TIDEAL]
return c
} }
func nodconst(n *Node, t *types.Type, v int64) { func nodconst(n *Node, t *types.Type, v int64) {
@ -444,17 +438,11 @@ func nodconst(n *Node, t *types.Type, v int64) {
} }
func nodnil() *Node { func nodnil() *Node {
c := nodintconst(0) return nodlit(Val{new(NilVal)})
c.SetVal(Val{new(NilVal)})
c.Type = types.Types[TNIL]
return c
} }
func nodbool(b bool) *Node { func nodbool(b bool) *Node {
c := nodintconst(0) return nodlit(Val{b})
c.SetVal(Val{b})
c.Type = types.Idealbool
return c
} }
func nodstr(s string) *Node { func nodstr(s string) *Node {