1
0
mirror of https://github.com/golang/go synced 2024-11-18 03:54:50 -07:00

cmd/compile/internal/gc: clean up sinit.go

The ctxt parameter is always set to 0 on entry into anylit so make this
parameter a literal constant, and where possibly remove ctxt as a parameter
where it is known to be a constant zero.

Change-Id: I3e76e06456d7b1a1ea875ffeb2efefa4a1ff5a7e
Reviewed-on: https://go-review.googlesource.com/28221
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Dave Cheney 2016-08-31 14:39:41 +10:00
parent 7cbc1058ea
commit 38abd43b6a
2 changed files with 31 additions and 54 deletions

View File

@ -860,9 +860,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init *Nodes) {
init.Append(a)
}
func maplit(ctxt int, n *Node, m *Node, init *Nodes) {
ctxt = 0
func maplit(n *Node, m *Node, init *Nodes) {
// make the map var
nerr := nerrors
@ -894,8 +892,8 @@ func maplit(ctxt int, n *Node, m *Node, init *Nodes) {
dowidth(tv)
// make and initialize static arrays
vstatk := staticname(tk, ctxt)
vstatv := staticname(tv, ctxt)
vstatk := staticname(tk, 0)
vstatv := staticname(tv, 0)
b := int64(0)
for _, r := range n.List.Slice() {
@ -1007,7 +1005,7 @@ func maplit(ctxt int, n *Node, m *Node, init *Nodes) {
}
}
func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
func anylit(n *Node, var_ *Node, init *Nodes) {
t := n.Type
switch n.Op {
default:
@ -1037,7 +1035,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
var_ = Nod(OIND, var_, nil)
var_ = typecheck(var_, Erv|Easgn)
anylit(ctxt, n.Left, var_, init)
anylit(n.Left, var_, init)
case OSTRUCTLIT:
if !t.IsStruct() {
@ -1045,27 +1043,21 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
}
if var_.isSimpleName() && n.List.Len() > 4 {
if ctxt == 0 {
// lay out static data
vstat := staticname(t, ctxt)
// lay out static data
vstat := staticname(t, 0)
structlit(ctxt, 1, n, vstat, init)
structlit(0, 1, n, vstat, init)
// copy static to var
a := Nod(OAS, var_, vstat)
// copy static to var
a := Nod(OAS, var_, vstat)
a = typecheck(a, Etop)
a = walkexpr(a, init)
init.Append(a)
a = typecheck(a, Etop)
a = walkexpr(a, init)
init.Append(a)
// add expressions to automatic
structlit(ctxt, 2, n, var_, init)
// add expressions to automatic
structlit(0, 2, n, var_, init)
break
}
structlit(ctxt, 1, n, var_, init)
structlit(ctxt, 2, n, var_, init)
break
}
@ -1077,11 +1069,11 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
init.Append(a)
}
structlit(ctxt, 3, n, var_, init)
structlit(0, 3, n, var_, init)
case OARRAYLIT:
if t.IsSlice() {
slicelit(ctxt, n, var_, init)
slicelit(0, n, var_, init)
break
}
if !t.IsArray() {
@ -1089,27 +1081,20 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
}
if var_.isSimpleName() && n.List.Len() > 4 {
if ctxt == 0 {
// lay out static data
vstat := staticname(t, ctxt)
// lay out static data
vstat := staticname(t, 0)
arraylit(1, 1, n, vstat, init)
arraylit(1, 1, n, vstat, init)
// copy static to automatic
a := Nod(OAS, var_, vstat)
// copy static to automatic
a := Nod(OAS, var_, vstat)
a = typecheck(a, Etop)
a = walkexpr(a, init)
init.Append(a)
a = typecheck(a, Etop)
a = walkexpr(a, init)
init.Append(a)
// add expressions to automatic
arraylit(0, 2, n, var_, init)
// add expressions to automatic
arraylit(ctxt, 2, n, var_, init)
break
}
arraylit(ctxt, 1, n, var_, init)
arraylit(ctxt, 2, n, var_, init)
break
}
@ -1121,13 +1106,13 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
init.Append(a)
}
arraylit(ctxt, 3, n, var_, init)
arraylit(0, 3, n, var_, init)
case OMAPLIT:
if !t.IsMap() {
Fatalf("anylit: not map")
}
maplit(ctxt, n, var_, init)
maplit(n, var_, init)
}
}
@ -1149,14 +1134,6 @@ func oaslit(n *Node, init *Nodes) bool {
return false
}
// context is init() function.
// implies generated data executed
// exactly once and not subject to races.
ctxt := 0
// if(n->dodata == 1)
// ctxt = 1;
switch n.Right.Op {
default:
// not a special composit literal assignment
@ -1167,7 +1144,7 @@ func oaslit(n *Node, init *Nodes) bool {
// not a special composit literal assignment
return false
}
anylit(ctxt, n.Right, n.Left, init)
anylit(n.Right, n.Left, init)
}
n.Op = OEMPTY

View File

@ -1647,7 +1647,7 @@ opswitch:
break
}
var_ := temp(n.Type)
anylit(0, n, var_, init)
anylit(n, var_, init)
n = var_
case OSEND: