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