]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: refactor constant node constructors
authorMatthew Dempsky <mdempsky@google.com>
Sat, 31 Mar 2018 22:53:21 +0000 (15:53 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Sun, 1 Apr 2018 06:55:54 +0000 (06:55 +0000)
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>
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/subr.go

index af840059084dffaf4f75e719e93f65d6030ba017..8422eec17e7405b02a20bf506c9aaefbb26028ea 100644 (file)
@@ -1246,6 +1246,7 @@ illegal:
        }
 }
 
+// nodlit returns a new untyped constant with value v.
 func nodlit(v Val) *Node {
        n := nod(OLITERAL, nil, nil)
        n.SetVal(v)
index 96c1fc1cca0973dfe8e927f33b0857790bd73a2b..7354625de05c8d3f2d6924d41694f63b7049ba01 100644 (file)
@@ -413,21 +413,15 @@ func (x methcmp) Less(i, j int) bool {
 }
 
 func nodintconst(v int64) *Node {
-       c := nod(OLITERAL, nil, nil)
-       c.SetAddable(true)
-       c.SetVal(Val{new(Mpint)})
-       c.Val().U.(*Mpint).SetInt64(v)
-       c.Type = types.Types[TIDEAL]
-       return c
+       u := new(Mpint)
+       u.SetInt64(v)
+       return nodlit(Val{u})
 }
 
 func nodfltconst(v *Mpflt) *Node {
-       c := nod(OLITERAL, nil, nil)
-       c.SetAddable(true)
-       c.SetVal(Val{newMpflt()})
-       c.Val().U.(*Mpflt).Set(v)
-       c.Type = types.Types[TIDEAL]
-       return c
+       u := newMpflt()
+       u.Set(v)
+       return nodlit(Val{u})
 }
 
 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 {
-       c := nodintconst(0)
-       c.SetVal(Val{new(NilVal)})
-       c.Type = types.Types[TNIL]
-       return c
+       return nodlit(Val{new(NilVal)})
 }
 
 func nodbool(b bool) *Node {
-       c := nodintconst(0)
-       c.SetVal(Val{b})
-       c.Type = types.Idealbool
-       return c
+       return nodlit(Val{b})
 }
 
 func nodstr(s string) *Node {