Commit e28a890d authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/compile: remove nodesOrNodeListPtr outside of syntax.go

Passes toolstash -cmp.

Update #14473.

Change-Id: I2620374b79c61b1e48467b98afe2d7d3beef878b
Reviewed-on: https://go-review.googlesource.com/20354Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent beabd872
......@@ -395,7 +395,7 @@ func transformclosure(xfunc *Node) {
if len(body) > 0 {
typecheckslice(body, Etop)
walkstmtslice(body)
walkstmtlist(body)
xfunc.Func.Enter.Set(body)
xfunc.Func.Needctxt = true
}
......@@ -404,7 +404,7 @@ func transformclosure(xfunc *Node) {
lineno = lno
}
func walkclosure(func_ *Node, init nodesOrNodeListPtr) *Node {
func walkclosure(func_ *Node, init *Nodes) *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 nodesOrNodeListPtr) *Node {
func walkpartialcall(n *Node, init *Nodes) *Node {
// Create closure in the form of a composite literal.
// For x.M with receiver (x) type T, the generated code looks like:
//
......
......@@ -86,16 +86,14 @@ func instrument(fn *Node) {
}
}
func instrumentlist(l nodesOrNodeList, init nodesOrNodeListPtr) {
var instr *NodeList
func instrumentlist(l nodesOrNodeList, init *Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
instr = nil
var instr Nodes
instrumentnode(it.P(), &instr, 0, 0)
if init == nil {
appendNodeSeq(&it.N().Ninit, instr)
it.N().Ninit.AppendNodes(&instr)
} else {
appendNodeSeq(init, instr)
init.AppendNodes(&instr)
}
}
}
......@@ -103,7 +101,7 @@ func instrumentlist(l nodesOrNodeList, init nodesOrNodeListPtr) {
// walkexpr and walkstmt combined
// walks the tree and adds calls to the
// instrumentation code to top-level (statement) nodes' init
func instrumentnode(np **Node, init nodesOrNodeListPtr, wr int, skip int) {
func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
n := *np
if n == nil {
......@@ -163,8 +161,10 @@ func instrumentnode(np **Node, init nodesOrNodeListPtr, wr int, skip int) {
out = append(out, it.N())
}
default:
instrumentnode(it.P(), &out, 0, 0)
out = append(out, it.N())
var outn Nodes
outn.Set(out)
instrumentnode(it.P(), &outn, 0, 0)
out = append(outn.Slice(), it.N())
}
}
setNodeSeq(&n.List, out)
......@@ -460,7 +460,7 @@ func isartificial(n *Node) bool {
return false
}
func callinstr(np **Node, init nodesOrNodeListPtr, wr int, skip int) bool {
func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
n := *np
//print("callinstr for %+N [ %O ] etype=%E class=%d\n",
......@@ -529,7 +529,7 @@ func callinstr(np **Node, init nodesOrNodeListPtr, wr int, skip int) bool {
f = mkcall(name, nil, init, uintptraddr(n))
}
appendNodeSeqNode(init, f)
init.Append(f)
return true
}
......@@ -575,13 +575,13 @@ func uintptraddr(n *Node) *Node {
return r
}
func detachexpr(n *Node, init nodesOrNodeListPtr) *Node {
func detachexpr(n *Node, init *Nodes) *Node {
addr := Nod(OADDR, n, nil)
l := temp(Ptrto(n.Type))
as := Nod(OAS, l, addr)
typecheck(&as, Etop)
walkexpr(&as, init)
appendNodeSeqNode(init, as)
init.Append(as)
ind := Nod(OIND, l, nil)
typecheck(&ind, Erv)
walkexpr(&ind, init)
......
......@@ -156,7 +156,10 @@ func walkselect(sel *Node) {
a := Nod(OIF, nil, nil)
a.Left = Nod(OEQ, ch, nodnil())
a.Nbody.Set([]*Node{mkcall("block", nil, &l)})
var ln Nodes
ln.Set(l)
a.Nbody.Set([]*Node{mkcall("block", nil, &ln)})
l = ln.Slice()
typecheck(&a, Etop)
l = append(l, a)
l = append(l, n)
......@@ -303,7 +306,7 @@ func walkselect(sel *Node) {
// selv is no longer alive after use.
r.Nbody.Append(Nod(OVARKILL, selv, nil))
r.Nbody.Append(cas.Nbody.Slice()...)
r.Nbody.AppendNodes(&cas.Nbody)
r.Nbody.Append(Nod(OBREAK, nil, nil))
init = append(init, r)
}
......@@ -316,7 +319,7 @@ func walkselect(sel *Node) {
out:
setNodeSeq(&sel.List, nil)
walkstmtlist(sel.Nbody)
walkstmtlist(sel.Nbody.Slice())
lineno = lno
}
......
......@@ -528,11 +528,11 @@ func simplename(n *Node) bool {
return true
}
func litas(l *Node, r *Node, init nodesOrNodeListPtr) {
func litas(l *Node, r *Node, init *Nodes) {
a := Nod(OAS, l, r)
typecheck(&a, Etop)
walkexpr(&a, init)
appendNodeSeqNode(init, a)
init.Append(a)
}
const (
......@@ -570,7 +570,7 @@ func getdyn(n *Node, top int) int {
return mode
}
func structlit(ctxt int, pass int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
func structlit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
r := it.N()
if r.Op != OKEY {
......@@ -631,11 +631,11 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init nodesOrNodeListPtr)
walkstmt(&a)
}
appendNodeSeqNode(init, a)
init.Append(a)
}
}
func arraylit(ctxt int, pass int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
func arraylit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
r := it.N()
if r.Op != OKEY {
......@@ -696,11 +696,11 @@ func arraylit(ctxt int, pass int, n *Node, var_ *Node, init nodesOrNodeListPtr)
walkstmt(&a)
}
appendNodeSeqNode(init, a)
init.Append(a)
}
}
func slicelit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
func slicelit(ctxt int, n *Node, var_ *Node, init *Nodes) {
// make an array type
t := shallow(n.Type)
......@@ -723,7 +723,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
a = Nod(OAS, var_, a)
typecheck(&a, Etop)
a.Dodata = 2
appendNodeSeqNode(init, a)
init.Append(a)
return
}
......@@ -768,7 +768,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
if vstat == nil {
a = Nod(OAS, x, nil)
typecheck(&a, Etop)
appendNodeSeqNode(init, a) // zero new temp
init.Append(a) // zero new temp
}
a = Nod(OADDR, x, nil)
......@@ -777,7 +777,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
if vstat == nil {
a = Nod(OAS, temp(t), nil)
typecheck(&a, Etop)
appendNodeSeqNode(init, a) // zero new temp
init.Append(a) // zero new temp
a = a.Left
}
......@@ -790,7 +790,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
a = Nod(OAS, vauto, a)
typecheck(&a, Etop)
walkexpr(&a, init)
appendNodeSeqNode(init, a)
init.Append(a)
if vstat != nil {
// copy static to heap (4)
......@@ -799,7 +799,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
a = Nod(OAS, a, vstat)
typecheck(&a, Etop)
walkexpr(&a, init)
appendNodeSeqNode(init, a)
init.Append(a)
}
// make slice out of heap (5)
......@@ -808,7 +808,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
typecheck(&a, Etop)
orderstmtinplace(&a)
walkstmt(&a)
appendNodeSeqNode(init, a)
init.Append(a)
// put dynamics into slice (6)
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
......@@ -847,11 +847,11 @@ func slicelit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
typecheck(&a, Etop)
orderstmtinplace(&a)
walkstmt(&a)
appendNodeSeqNode(init, a)
init.Append(a)
}
}
func maplit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
func maplit(ctxt int, n *Node, var_ *Node, init *Nodes) {
ctxt = 0
// make the map var
......@@ -927,7 +927,7 @@ func maplit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
typecheck(&a, Etop)
walkexpr(&a, init)
a.Dodata = 2
appendNodeSeqNode(init, a)
init.Append(a)
// build vstat[b].b = value;
setlineno(value)
......@@ -939,7 +939,7 @@ func maplit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
typecheck(&a, Etop)
walkexpr(&a, init)
a.Dodata = 2
appendNodeSeqNode(init, a)
init.Append(a)
b++
}
......@@ -971,7 +971,7 @@ func maplit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
typecheck(&a, Etop)
walkstmt(&a)
appendNodeSeqNode(init, a)
init.Append(a)
}
// put in dynamic entries one-at-a-time
......@@ -1000,18 +1000,18 @@ func maplit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
a = Nod(OAS, key, r.Left)
typecheck(&a, Etop)
walkstmt(&a)
appendNodeSeqNode(init, a)
init.Append(a)
setlineno(r.Right)
a = Nod(OAS, val, r.Right)
typecheck(&a, Etop)
walkstmt(&a)
appendNodeSeqNode(init, a)
init.Append(a)
setlineno(val)
a = Nod(OAS, Nod(OINDEX, var_, key), val)
typecheck(&a, Etop)
walkstmt(&a)
appendNodeSeqNode(init, a)
init.Append(a)
if nerr != nerrors {
break
......@@ -1021,14 +1021,14 @@ func maplit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
if key != nil {
a = Nod(OVARKILL, key, nil)
typecheck(&a, Etop)
appendNodeSeqNode(init, a)
init.Append(a)
a = Nod(OVARKILL, val, nil)
typecheck(&a, Etop)
appendNodeSeqNode(init, a)
init.Append(a)
}
}
func anylit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
t := n.Type
switch n.Op {
default:
......@@ -1054,7 +1054,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
a := Nod(OAS, var_, r)
typecheck(&a, Etop)
appendNodeSeqNode(init, a)
init.Append(a)
var_ = Nod(OIND, var_, nil)
typecheck(&var_, Erv|Easgn)
......@@ -1077,7 +1077,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
typecheck(&a, Etop)
walkexpr(&a, init)
appendNodeSeqNode(init, a)
init.Append(a)
// add expressions to automatic
structlit(ctxt, 2, n, var_, init)
......@@ -1095,7 +1095,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
a := Nod(OAS, var_, nil)
typecheck(&a, Etop)
walkexpr(&a, init)
appendNodeSeqNode(init, a)
init.Append(a)
}
structlit(ctxt, 3, n, var_, init)
......@@ -1121,7 +1121,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
typecheck(&a, Etop)
walkexpr(&a, init)
appendNodeSeqNode(init, a)
init.Append(a)
// add expressions to automatic
arraylit(ctxt, 2, n, var_, init)
......@@ -1139,7 +1139,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
a := Nod(OAS, var_, nil)
typecheck(&a, Etop)
walkexpr(&a, init)
appendNodeSeqNode(init, a)
init.Append(a)
}
arraylit(ctxt, 3, n, var_, init)
......@@ -1152,7 +1152,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init nodesOrNodeListPtr) {
}
}
func oaslit(n *Node, init nodesOrNodeListPtr) bool {
func oaslit(n *Node, init *Nodes) bool {
if n.Left == nil || n.Right == nil {
// not a special composit literal assignment
return false
......
......@@ -1628,15 +1628,14 @@ 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 nodesOrNodeListPtr) *Node {
func safeexpr(n *Node, init *Nodes) *Node {
if n == nil {
return nil
}
if nodeSeqLen(n.Ninit) != 0 {
walkstmtlist(n.Ninit)
appendNodeSeq(init, n.Ninit)
setNodeSeq(&n.Ninit, nil)
walkstmtlist(n.Ninit.Slice())
init.AppendNodes(&n.Ninit)
}
switch n.Op {
......@@ -1687,18 +1686,18 @@ func safeexpr(n *Node, init nodesOrNodeListPtr) *Node {
return cheapexpr(n, init)
}
func copyexpr(n *Node, t *Type, init nodesOrNodeListPtr) *Node {
func copyexpr(n *Node, t *Type, init *Nodes) *Node {
l := temp(t)
a := Nod(OAS, l, n)
typecheck(&a, Etop)
walkexpr(&a, init)
appendNodeSeqNode(init, a)
init.Append(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 nodesOrNodeListPtr) *Node {
func cheapexpr(n *Node, init *Nodes) *Node {
switch n.Op {
case ONAME, OLITERAL:
return n
......@@ -2765,7 +2764,7 @@ func isbadimport(path string) bool {
return false
}
func checknil(x *Node, init nodesOrNodeListPtr) {
func checknil(x *Node, init *Nodes) {
if Isinter(x.Type) {
x = Nod(OITAB, x, nil)
typecheck(&x, Erv)
......@@ -2773,7 +2772,7 @@ func checknil(x *Node, init nodesOrNodeListPtr) {
n := Nod(OCHECKNIL, x, nil)
n.Typecheck = 1
appendNodeSeqNode(init, n)
init.Append(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()...))
walkstmtlist(sw.Nbody)
walkstmtlist(sw.Nbody.Slice())
}
}
......@@ -670,7 +670,7 @@ func (s *typeSwitch) walk(sw *Node) {
cas = append(cas, def)
sw.Nbody.Set(append(cas, sw.Nbody.Slice()...))
setNodeSeq(&sw.List, nil)
walkstmtlist(sw.Nbody)
walkstmtlist(sw.Nbody.Slice())
}
}
......
......@@ -466,6 +466,18 @@ func (n *Nodes) Append(a ...*Node) {
}
}
// AppendNodes appends the contents of *n2 to n, then clears n2.
func (n *Nodes) AppendNodes(n2 *Nodes) {
switch {
case n2.slice == nil:
case n.slice == nil:
n.slice = n2.slice
default:
*n.slice = append(*n.slice, *n2.slice...)
}
n2.slice = nil
}
// SetToNodeList sets Nodes to the contents of a NodeList.
func (n *Nodes) SetToNodeList(l *NodeList) {
s := make([]*Node, 0, count(l))
......
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