Commit 38abd43b authored by Dave Cheney's avatar Dave Cheney

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 7cbc1058
......@@ -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,11 +1043,10 @@ 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)
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)
......@@ -1059,16 +1056,11 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
init.Append(a)
// add expressions to automatic
structlit(ctxt, 2, n, var_, init)
structlit(0, 2, n, var_, init)
break
}
structlit(ctxt, 1, n, var_, init)
structlit(ctxt, 2, n, var_, init)
break
}
// initialize of not completely specified
if var_.isSimpleName() || n.List.Len() < t.NumFields() {
a := Nod(OAS, var_, nil)
......@@ -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,30 +1081,23 @@ 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)
vstat := staticname(t, 0)
arraylit(1, 1, n, vstat, init)
// copy static to automatic
a := Nod(OAS, var_, vstat)
a = typecheck(a, Etop)
a = walkexpr(a, init)
init.Append(a)
// add expressions to automatic
arraylit(ctxt, 2, n, var_, init)
arraylit(0, 2, n, var_, init)
break
}
arraylit(ctxt, 1, n, var_, init)
arraylit(ctxt, 2, n, var_, init)
break
}
// initialize of not completely specified
if var_.isSimpleName() || int64(n.List.Len()) < t.NumElem() {
a := Nod(OAS, var_, nil)
......@@ -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
......
......@@ -1647,7 +1647,7 @@ opswitch:
break
}
var_ := temp(n.Type)
anylit(0, n, var_, init)
anylit(n, var_, init)
n = var_
case OSEND:
......
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