Commit 132ebeac authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/compile: convert walk.go and friends to use nodeSeq

Pases toolstash -cmp.

Update #14473.

Change-Id: I450d9f51fd280da91952008cd917b749d88960a3
Reviewed-on: https://go-review.googlesource.com/20210
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 1765863e
......@@ -404,7 +404,7 @@ func transformclosure(xfunc *Node) {
lineno = lno
}
func walkclosure(func_ *Node, init **NodeList) *Node {
func walkclosure(func_ *Node, init nodesOrNodeListPtr) *Node {
// If no closure vars, don't bother wrapping.
if len(func_.Func.Cvars.Slice()) == 0 {
return func_.Func.Closure.Func.Nname
......@@ -623,7 +623,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
return xfunc
}
func walkpartialcall(n *Node, init **NodeList) *Node {
func walkpartialcall(n *Node, init nodesOrNodeListPtr) *Node {
// Create closure in the form of a composite literal.
// For x.M with receiver (x) type T, the generated code looks like:
//
......
......@@ -321,7 +321,7 @@ func walkselect(sel *Node) {
out:
sel.List = nil
walkstmtslice(sel.Nbody.Slice())
walkstmtlist(sel.Nbody)
lineno = lno
}
......
......@@ -534,11 +534,11 @@ func simplename(n *Node) bool {
return true
}
func litas(l *Node, r *Node, init **NodeList) {
func litas(l *Node, r *Node, init nodesOrNodeListPtr) {
a := Nod(OAS, l, r)
typecheck(&a, Etop)
walkexpr(&a, init)
*init = list(*init, a)
appendNodeSeqNode(init, a)
}
const (
......@@ -576,7 +576,7 @@ func getdyn(n *Node, top int) int {
return mode
}
func structlit(ctxt int, pass int, n *Node, var_ *Node, init **NodeList) {
func structlit(ctxt int, pass int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
for nl := n.List; nl != nil; nl = nl.Next {
r := nl.N
if r.Op != OKEY {
......@@ -637,11 +637,11 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init **NodeList) {
walkstmt(&a)
}
*init = list(*init, a)
appendNodeSeqNode(init, a)
}
}
func arraylit(ctxt int, pass int, n *Node, var_ *Node, init **NodeList) {
func arraylit(ctxt int, pass int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
for l := n.List; l != nil; l = l.Next {
r := l.N
if r.Op != OKEY {
......@@ -702,11 +702,11 @@ func arraylit(ctxt int, pass int, n *Node, var_ *Node, init **NodeList) {
walkstmt(&a)
}
*init = list(*init, a)
appendNodeSeqNode(init, a)
}
}
func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) {
func slicelit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
// make an array type
t := shallow(n.Type)
......@@ -729,7 +729,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) {
a = Nod(OAS, var_, a)
typecheck(&a, Etop)
a.Dodata = 2
*init = list(*init, a)
appendNodeSeqNode(init, a)
return
}
......@@ -774,7 +774,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) {
if vstat == nil {
a = Nod(OAS, x, nil)
typecheck(&a, Etop)
*init = list(*init, a) // zero new temp
appendNodeSeqNode(init, a) // zero new temp
}
a = Nod(OADDR, x, nil)
......@@ -783,7 +783,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) {
if vstat == nil {
a = Nod(OAS, temp(t), nil)
typecheck(&a, Etop)
*init = list(*init, a) // zero new temp
appendNodeSeqNode(init, a) // zero new temp
a = a.Left
}
......@@ -796,7 +796,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) {
a = Nod(OAS, vauto, a)
typecheck(&a, Etop)
walkexpr(&a, init)
*init = list(*init, a)
appendNodeSeqNode(init, a)
if vstat != nil {
// copy static to heap (4)
......@@ -805,7 +805,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) {
a = Nod(OAS, a, vstat)
typecheck(&a, Etop)
walkexpr(&a, init)
*init = list(*init, a)
appendNodeSeqNode(init, a)
}
// make slice out of heap (5)
......@@ -814,7 +814,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) {
typecheck(&a, Etop)
orderstmtinplace(&a)
walkstmt(&a)
*init = list(*init, a)
appendNodeSeqNode(init, a)
// put dynamics into slice (6)
for l := n.List; l != nil; l = l.Next {
......@@ -853,11 +853,11 @@ func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) {
typecheck(&a, Etop)
orderstmtinplace(&a)
walkstmt(&a)
*init = list(*init, a)
appendNodeSeqNode(init, a)
}
}
func maplit(ctxt int, n *Node, var_ *Node, init **NodeList) {
func maplit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
ctxt = 0
// make the map var
......@@ -933,7 +933,7 @@ func maplit(ctxt int, n *Node, var_ *Node, init **NodeList) {
typecheck(&a, Etop)
walkexpr(&a, init)
a.Dodata = 2
*init = list(*init, a)
appendNodeSeqNode(init, a)
// build vstat[b].b = value;
setlineno(value)
......@@ -945,7 +945,7 @@ func maplit(ctxt int, n *Node, var_ *Node, init **NodeList) {
typecheck(&a, Etop)
walkexpr(&a, init)
a.Dodata = 2
*init = list(*init, a)
appendNodeSeqNode(init, a)
b++
}
......@@ -977,7 +977,7 @@ func maplit(ctxt int, n *Node, var_ *Node, init **NodeList) {
typecheck(&a, Etop)
walkstmt(&a)
*init = list(*init, a)
appendNodeSeqNode(init, a)
}
// put in dynamic entries one-at-a-time
......@@ -1006,18 +1006,18 @@ func maplit(ctxt int, n *Node, var_ *Node, init **NodeList) {
a = Nod(OAS, key, r.Left)
typecheck(&a, Etop)
walkstmt(&a)
*init = list(*init, a)
appendNodeSeqNode(init, a)
setlineno(r.Right)
a = Nod(OAS, val, r.Right)
typecheck(&a, Etop)
walkstmt(&a)
*init = list(*init, a)
appendNodeSeqNode(init, a)
setlineno(val)
a = Nod(OAS, Nod(OINDEX, var_, key), val)
typecheck(&a, Etop)
walkstmt(&a)
*init = list(*init, a)
appendNodeSeqNode(init, a)
if nerr != nerrors {
break
......@@ -1027,14 +1027,14 @@ func maplit(ctxt int, n *Node, var_ *Node, init **NodeList) {
if key != nil {
a = Nod(OVARKILL, key, nil)
typecheck(&a, Etop)
*init = list(*init, a)
appendNodeSeqNode(init, a)
a = Nod(OVARKILL, val, nil)
typecheck(&a, Etop)
*init = list(*init, a)
appendNodeSeqNode(init, a)
}
}
func anylit(ctxt int, n *Node, var_ *Node, init **NodeList) {
func anylit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
t := n.Type
switch n.Op {
default:
......@@ -1060,7 +1060,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init **NodeList) {
a := Nod(OAS, var_, r)
typecheck(&a, Etop)
*init = list(*init, a)
appendNodeSeqNode(init, a)
var_ = Nod(OIND, var_, nil)
typecheck(&var_, Erv|Easgn)
......@@ -1083,7 +1083,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init **NodeList) {
typecheck(&a, Etop)
walkexpr(&a, init)
*init = list(*init, a)
appendNodeSeqNode(init, a)
// add expressions to automatic
structlit(ctxt, 2, n, var_, init)
......@@ -1101,7 +1101,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init **NodeList) {
a := Nod(OAS, var_, nil)
typecheck(&a, Etop)
walkexpr(&a, init)
*init = list(*init, a)
appendNodeSeqNode(init, a)
}
structlit(ctxt, 3, n, var_, init)
......@@ -1127,7 +1127,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init **NodeList) {
typecheck(&a, Etop)
walkexpr(&a, init)
*init = list(*init, a)
appendNodeSeqNode(init, a)
// add expressions to automatic
arraylit(ctxt, 2, n, var_, init)
......@@ -1145,7 +1145,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init **NodeList) {
a := Nod(OAS, var_, nil)
typecheck(&a, Etop)
walkexpr(&a, init)
*init = list(*init, a)
appendNodeSeqNode(init, a)
}
arraylit(ctxt, 3, n, var_, init)
......@@ -1158,7 +1158,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init **NodeList) {
}
}
func oaslit(n *Node, init **NodeList) bool {
func oaslit(n *Node, init nodesOrNodeListPtr) bool {
if n.Left == nil || n.Right == nil {
// not a special composit literal assignment
return false
......
......@@ -1651,15 +1651,15 @@ func Brrev(op Op) Op {
// return side effect-free n, appending side effects to init.
// result is assignable if n is.
func safeexpr(n *Node, init **NodeList) *Node {
func safeexpr(n *Node, init nodesOrNodeListPtr) *Node {
if n == nil {
return nil
}
if n.Ninit != nil {
if nodeSeqLen(n.Ninit) != 0 {
walkstmtlist(n.Ninit)
*init = concat(*init, n.Ninit)
n.Ninit = nil
appendNodeSeq(init, n.Ninit)
setNodeSeq(&n.Ninit, nil)
}
switch n.Op {
......@@ -1710,18 +1710,18 @@ func safeexpr(n *Node, init **NodeList) *Node {
return cheapexpr(n, init)
}
func copyexpr(n *Node, t *Type, init **NodeList) *Node {
func copyexpr(n *Node, t *Type, init nodesOrNodeListPtr) *Node {
l := temp(t)
a := Nod(OAS, l, n)
typecheck(&a, Etop)
walkexpr(&a, init)
*init = list(*init, a)
appendNodeSeqNode(init, a)
return l
}
// return side-effect free and cheap n, appending side effects to init.
// result may not be assignable.
func cheapexpr(n *Node, init **NodeList) *Node {
func cheapexpr(n *Node, init nodesOrNodeListPtr) *Node {
switch n.Op {
case ONAME, OLITERAL:
return n
......@@ -2804,7 +2804,7 @@ func isbadimport(path string) bool {
return false
}
func checknil(x *Node, init **NodeList) {
func checknil(x *Node, init nodesOrNodeListPtr) {
if Isinter(x.Type) {
x = Nod(OITAB, x, nil)
typecheck(&x, Erv)
......@@ -2812,7 +2812,7 @@ func checknil(x *Node, init **NodeList) {
n := Nod(OCHECKNIL, x, nil)
n.Typecheck = 1
*init = list(*init, n)
appendNodeSeqNode(init, n)
}
// Can this type be stored directly in an interface word?
......
......@@ -279,7 +279,7 @@ func (s *exprSwitch) walk(sw *Node) {
if nerrors == 0 {
cas = append(cas, def)
sw.Nbody.Set(append(cas, sw.Nbody.Slice()...))
walkstmtslice(sw.Nbody.Slice())
walkstmtlist(sw.Nbody)
}
}
......@@ -670,7 +670,7 @@ func (s *typeSwitch) walk(sw *Node) {
cas = append(cas, def)
sw.Nbody.Set(append(cas, sw.Nbody.Slice()...))
sw.List = nil
walkstmtslice(sw.Nbody.Slice())
walkstmtlist(sw.Nbody)
}
}
......
......@@ -587,13 +587,17 @@ func (ni *nodesIterator) Seq() nodesOrNodeList {
return r
}
// nodeSeqIterate returns an iterator over either a *NodeList or a Nodes.
// nodeSeqIterate returns an iterator over a *NodeList, a Nodes, or a []*Node.
func nodeSeqIterate(ns nodesOrNodeList) nodeSeqIterator {
switch ns := ns.(type) {
case *NodeList:
return &nodeListIterator{ns}
case Nodes:
return &nodesIterator{ns, 0}
case []*Node:
var r Nodes
r.Set(ns)
return &nodesIterator{r, 0}
default:
panic("can't happen")
}
......
This diff is collapsed.
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