Commit 38921b36 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/compile: rewrite code to omit many nodeSeq calls

This CL was automatically generated using a special-purpose AST
rewriting tool, followed by manual editing to put some comments back in
the right places and fix some bad line breaks.

The result is not perfect but it's a big step toward getting back to
sanity, and because it was automatically generated there is a decent
chance that it is correct.

Passes toolstash -cmp.

Update #14473.

Change-Id: I01c09078a6d78e2b008bc304d744b79469a38d3d
Reviewed-on: https://go-review.googlesource.com/20440Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent db506fe9
......@@ -185,13 +185,13 @@ func genhash(sym *Sym, t *Type) {
fn.Func.Nname.Name.Param.Ntype = tfn
n := Nod(ODCLFIELD, newname(Lookup("p")), typenod(Ptrto(t)))
appendNodeSeqNode(&tfn.List, n)
tfn.List.Append(n)
np := n.Left
n = Nod(ODCLFIELD, newname(Lookup("h")), typenod(Types[TUINTPTR]))
appendNodeSeqNode(&tfn.List, n)
tfn.List.Append(n)
nh := n.Left
n = Nod(ODCLFIELD, nil, typenod(Types[TUINTPTR])) // return value
appendNodeSeqNode(&tfn.Rlist, n)
tfn.Rlist.Append(n)
funchdr(fn)
typecheck(&fn.Func.Nname.Name.Param.Ntype, Etype)
......@@ -216,10 +216,10 @@ func genhash(sym *Sym, t *Type) {
n := Nod(ORANGE, nil, Nod(OIND, np, nil))
ni := newname(Lookup("i"))
ni.Type = Types[TINT]
setNodeSeq(&n.List, []*Node{ni})
n.List.Set([]*Node{ni})
n.Colas = true
colasdefn(n.List, n)
ni = nodeSeqFirst(n.List)
ni = n.List.First()
// h = hashel(&p[i], h)
call := Nod(OCALL, hashel, nil)
......@@ -228,8 +228,8 @@ func genhash(sym *Sym, t *Type) {
nx.Bounded = true
na := Nod(OADDR, nx, nil)
na.Etype = 1 // no escape to heap
appendNodeSeqNode(&call.List, na)
appendNodeSeqNode(&call.List, nh)
call.List.Append(na)
call.List.Append(nh)
n.Nbody.Append(Nod(OAS, nh, call))
fn.Nbody.Append(n)
......@@ -251,8 +251,8 @@ func genhash(sym *Sym, t *Type) {
nx := Nod(OXDOT, np, newname(f.Sym)) // TODO: fields from other packages?
na := Nod(OADDR, nx, nil)
na.Etype = 1 // no escape to heap
appendNodeSeqNode(&call.List, na)
appendNodeSeqNode(&call.List, nh)
call.List.Append(na)
call.List.Append(nh)
fn.Nbody.Append(Nod(OAS, nh, call))
f = f.Down
continue
......@@ -267,9 +267,9 @@ func genhash(sym *Sym, t *Type) {
nx := Nod(OXDOT, np, newname(f.Sym)) // TODO: fields from other packages?
na := Nod(OADDR, nx, nil)
na.Etype = 1 // no escape to heap
appendNodeSeqNode(&call.List, na)
appendNodeSeqNode(&call.List, nh)
appendNodeSeqNode(&call.List, Nodintconst(size))
call.List.Append(na)
call.List.Append(nh)
call.List.Append(Nodintconst(size))
fn.Nbody.Append(Nod(OAS, nh, call))
f = next
......@@ -277,7 +277,7 @@ func genhash(sym *Sym, t *Type) {
}
r := Nod(ORETURN, nil, nil)
appendNodeSeqNode(&r.List, nh)
r.List.Append(nh)
fn.Nbody.Append(r)
if Debug['r'] != 0 {
......@@ -339,9 +339,9 @@ func hashfor(t *Type) *Node {
n := newname(sym)
n.Class = PFUNC
tfn := Nod(OTFUNC, nil, nil)
appendNodeSeqNode(&tfn.List, Nod(ODCLFIELD, nil, typenod(Ptrto(t))))
appendNodeSeqNode(&tfn.List, Nod(ODCLFIELD, nil, typenod(Types[TUINTPTR])))
appendNodeSeqNode(&tfn.Rlist, Nod(ODCLFIELD, nil, typenod(Types[TUINTPTR])))
tfn.List.Append(Nod(ODCLFIELD, nil, typenod(Ptrto(t))))
tfn.List.Append(Nod(ODCLFIELD, nil, typenod(Types[TUINTPTR])))
tfn.Rlist.Append(Nod(ODCLFIELD, nil, typenod(Types[TUINTPTR])))
typecheck(&tfn, Etype)
n.Type = tfn.Type
return n
......@@ -367,13 +367,13 @@ func geneq(sym *Sym, t *Type) {
fn.Func.Nname.Name.Param.Ntype = tfn
n := Nod(ODCLFIELD, newname(Lookup("p")), typenod(Ptrto(t)))
appendNodeSeqNode(&tfn.List, n)
tfn.List.Append(n)
np := n.Left
n = Nod(ODCLFIELD, newname(Lookup("q")), typenod(Ptrto(t)))
appendNodeSeqNode(&tfn.List, n)
tfn.List.Append(n)
nq := n.Left
n = Nod(ODCLFIELD, nil, typenod(Types[TBOOL]))
appendNodeSeqNode(&tfn.Rlist, n)
tfn.Rlist.Append(n)
funchdr(fn)
......@@ -398,10 +398,10 @@ func geneq(sym *Sym, t *Type) {
ni := newname(Lookup("i"))
ni.Type = Types[TINT]
setNodeSeq(&nrange.List, []*Node{ni})
nrange.List.Set([]*Node{ni})
nrange.Colas = true
colasdefn(nrange.List, nrange)
ni = nodeSeqFirst(nrange.List)
ni = nrange.List.First()
// if p[i] != q[i] { return false }
nx := Nod(OINDEX, np, ni)
......@@ -413,14 +413,14 @@ func geneq(sym *Sym, t *Type) {
nif := Nod(OIF, nil, nil)
nif.Left = Nod(ONE, nx, ny)
r := Nod(ORETURN, nil, nil)
appendNodeSeqNode(&r.List, Nodbool(false))
r.List.Append(Nodbool(false))
nif.Nbody.Append(r)
nrange.Nbody.Append(nif)
fn.Nbody.Append(nrange)
// return true
ret := Nod(ORETURN, nil, nil)
appendNodeSeqNode(&ret.List, Nodbool(true))
ret.List.Append(Nodbool(true))
fn.Nbody.Append(ret)
case TSTRUCT:
......@@ -474,7 +474,7 @@ func geneq(sym *Sym, t *Type) {
}
ret := Nod(ORETURN, nil, nil)
appendNodeSeqNode(&ret.List, and)
ret.List.Append(and)
fn.Nbody.Append(ret)
}
......@@ -531,10 +531,10 @@ func eqmem(p *Node, q *Node, field *Node, size int64) *Node {
typecheck(&ny, Erv)
call := Nod(OCALL, eqmemfunc(size, nx.Type.Type, &needsize), nil)
appendNodeSeqNode(&call.List, nx)
appendNodeSeqNode(&call.List, ny)
call.List.Append(nx)
call.List.Append(ny)
if needsize != 0 {
appendNodeSeqNode(&call.List, Nodintconst(size))
call.List.Append(Nodintconst(size))
}
return call
......
......@@ -848,7 +848,7 @@ func (p *exporter) node(n *Node) {
// expressions
case OMAKEMAP, OMAKECHAN, OMAKESLICE:
if p.bool(nodeSeqLen(n.List) != 0) {
if p.bool(n.List.Len() != 0) {
p.nodeList(n.List) // TODO(gri) do we still need to export this?
}
p.nodesOrNil(n.Left, n.Right)
......@@ -970,7 +970,7 @@ func (p *exporter) node(n *Node) {
p.nodeList(n.Nbody)
case ORANGE:
if p.bool(nodeSeqLen(n.List) != 0) {
if p.bool(n.List.Len() != 0) {
p.nodeList(n.List)
}
p.node(n.Right)
......@@ -982,7 +982,7 @@ func (p *exporter) node(n *Node) {
p.nodeList(n.List)
case OCASE, OXCASE:
if p.bool(nodeSeqLen(n.List) != 0) {
if p.bool(n.List.Len() != 0) {
p.nodeList(n.List)
}
p.nodeList(n.Nbody)
......
......@@ -589,7 +589,7 @@ func (p *importer) node() *Node {
// expressions
case OMAKEMAP, OMAKECHAN, OMAKESLICE:
if p.bool() {
setNodeSeq(&n.List, p.nodeList())
n.List.Set(p.nodeList())
}
n.Left, n.Right = p.nodesOrNil()
n.Type = p.typ()
......@@ -604,19 +604,19 @@ func (p *importer) node() *Node {
n.Right = p.node()
case OADDSTR:
setNodeSeq(&n.List, p.nodeList())
n.List.Set(p.nodeList())
case OPTRLIT:
n.Left = p.node()
case OSTRUCTLIT:
n.Type = p.typ()
setNodeSeq(&n.List, p.nodeList())
n.List.Set(p.nodeList())
n.Implicit = p.bool()
case OARRAYLIT, OMAPLIT:
n.Type = p.typ()
setNodeSeq(&n.List, p.nodeList())
n.List.Set(p.nodeList())
n.Implicit = p.bool()
case OKEY:
......@@ -635,9 +635,9 @@ func (p *importer) node() *Node {
// }
x := Nod(OCALL, p.typ().Nod, nil)
if p.bool() {
setNodeSeq(&x.List, []*Node{p.node()})
x.List.Set([]*Node{p.node()})
} else {
setNodeSeq(&x.List, p.nodeList())
x.List.Set(p.nodeList())
}
return x
......@@ -667,12 +667,12 @@ func (p *importer) node() *Node {
case OREAL, OIMAG, OAPPEND, OCAP, OCLOSE, ODELETE, OLEN, OMAKE, ONEW, OPANIC,
ORECOVER, OPRINT, OPRINTN:
n.Left, _ = p.nodesOrNil()
setNodeSeq(&n.List, p.nodeList())
n.List.Set(p.nodeList())
n.Isddd = p.bool()
case OCALL, OCALLFUNC, OCALLMETH, OCALLINTER, OGETG:
n.Left = p.node()
setNodeSeq(&n.List, p.nodeList())
n.List.Set(p.nodeList())
n.Isddd = p.bool()
case OCMPSTR, OCMPIFACE:
......@@ -698,45 +698,45 @@ func (p *importer) node() *Node {
n.Etype = EType(p.int())
case OAS2, OASWB:
setNodeSeq(&n.List, p.nodeList())
setNodeSeq(&n.Rlist, p.nodeList())
n.List.Set(p.nodeList())
n.Rlist.Set(p.nodeList())
case OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
setNodeSeq(&n.List, p.nodeList())
setNodeSeq(&n.Rlist, p.nodeList())
n.List.Set(p.nodeList())
n.Rlist.Set(p.nodeList())
case ORETURN:
setNodeSeq(&n.List, p.nodeList())
n.List.Set(p.nodeList())
case OPROC, ODEFER:
n.Left = p.node()
case OIF:
setNodeSeq(&n.Ninit, p.nodeList())
n.Ninit.Set(p.nodeList())
n.Left = p.node()
n.Nbody.Set(p.nodeList())
setNodeSeq(&n.Rlist, p.nodeList())
n.Rlist.Set(p.nodeList())
case OFOR:
setNodeSeq(&n.Ninit, p.nodeList())
n.Ninit.Set(p.nodeList())
n.Left, n.Right = p.nodesOrNil()
n.Nbody.Set(p.nodeList())
case ORANGE:
if p.bool() {
setNodeSeq(&n.List, p.nodeList())
n.List.Set(p.nodeList())
}
n.Right = p.node()
n.Nbody.Set(p.nodeList())
case OSELECT, OSWITCH:
setNodeSeq(&n.Ninit, p.nodeList())
n.Ninit.Set(p.nodeList())
n.Left, _ = p.nodesOrNil()
setNodeSeq(&n.List, p.nodeList())
n.List.Set(p.nodeList())
case OCASE, OXCASE:
if p.bool() {
setNodeSeq(&n.List, p.nodeList())
n.List.Set(p.nodeList())
}
n.Nbody.Set(p.nodeList())
......
......@@ -1752,7 +1752,7 @@ func Bvgen(n, res *Node, wantTrue bool) {
func bvgenjump(n, res *Node, wantTrue, geninit bool) {
init := n.Ninit
if !geninit {
setNodeSeq(&n.Ninit, nil)
n.Ninit.Set(nil)
}
p1 := Gbranch(obj.AJMP, nil, 0)
p2 := Pc
......@@ -1762,7 +1762,7 @@ func bvgenjump(n, res *Node, wantTrue, geninit bool) {
Bgen(n, wantTrue, 0, p2)
Thearch.Gmove(Nodbool(false), res)
Patch(p3, Pc)
setNodeSeq(&n.Ninit, init)
n.Ninit.Set(init.Slice())
}
// bgenx is the backend for Bgen and Bvgen.
......@@ -1920,11 +1920,11 @@ func bgenx(n, res *Node, wantTrue bool, likely int, to *obj.Prog) {
if Isfloat[nr.Type.Etype] {
// Brcom is not valid on floats when NaN is involved.
ll := n.Ninit // avoid re-genning Ninit
setNodeSeq(&n.Ninit, nil)
n.Ninit.Set(nil)
if genval {
bgenx(n, res, true, likely, to)
Thearch.Gins(Thearch.Optoas(OXOR, Types[TUINT8]), Nodintconst(1), res) // res = !res
setNodeSeq(&n.Ninit, ll)
n.Ninit.Set(ll.Slice())
return
}
p1 := Gbranch(obj.AJMP, nil, 0)
......@@ -1933,7 +1933,7 @@ func bgenx(n, res *Node, wantTrue bool, likely int, to *obj.Prog) {
bgenx(n, res, true, -likely, p2)
Patch(Gbranch(obj.AJMP, nil, 0), to)
Patch(p2, Pc)
setNodeSeq(&n.Ninit, ll)
n.Ninit.Set(ll.Slice())
return
}
......@@ -2799,13 +2799,13 @@ func cgen_append(n, res *Node) {
Dump("cgen_append-n", n)
Dump("cgen_append-res", res)
}
if res.Op != ONAME && !samesafeexpr(res, nodeSeqFirst(n.List)) {
if res.Op != ONAME && !samesafeexpr(res, n.List.First()) {
Dump("cgen_append-n", n)
Dump("cgen_append-res", res)
Fatalf("append not lowered")
}
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
if it.N().Ullman >= UINF {
for _, n1 := range n.List.Slice() {
if n1.Ullman >= UINF {
Fatalf("append with function call arguments")
}
}
......@@ -2814,7 +2814,7 @@ func cgen_append(n, res *Node) {
//
// If res and src are the same, we can avoid writing to base and cap
// unless we grow the underlying array.
needFullUpdate := !samesafeexpr(res, nodeSeqFirst(n.List))
needFullUpdate := !samesafeexpr(res, n.List.First())
// Copy src triple into base, len, cap.
base := temp(Types[Tptr])
......@@ -2822,7 +2822,7 @@ func cgen_append(n, res *Node) {
cap := temp(Types[TUINT])
var src Node
Igen(nodeSeqFirst(n.List), &src, nil)
Igen(n.List.First(), &src, nil)
src.Type = Types[Tptr]
Thearch.Gmove(&src, base)
src.Type = Types[TUINT]
......@@ -2835,7 +2835,7 @@ func cgen_append(n, res *Node) {
var rlen Node
Regalloc(&rlen, Types[TUINT], nil)
Thearch.Gmove(len, &rlen)
Thearch.Ginscon(Thearch.Optoas(OADD, Types[TUINT]), int64(nodeSeqLen(n.List)-1), &rlen)
Thearch.Ginscon(Thearch.Optoas(OADD, Types[TUINT]), int64(n.List.Len()-1), &rlen)
p := Thearch.Ginscmp(OLE, Types[TUINT], &rlen, cap, +1)
// Note: rlen and src are Regrealloc'ed below at the target of the
// branch we just emitted; do not reuse these Go variables for
......@@ -2905,7 +2905,7 @@ func cgen_append(n, res *Node) {
dst.Xoffset += int64(Widthptr)
Regalloc(&r1, Types[TUINT], nil)
Thearch.Gmove(len, &r1)
Thearch.Ginscon(Thearch.Optoas(OADD, Types[TUINT]), int64(nodeSeqLen(n.List)-1), &r1)
Thearch.Ginscon(Thearch.Optoas(OADD, Types[TUINT]), int64(n.List.Len()-1), &r1)
Thearch.Gmove(&r1, &dst)
Regfree(&r1)
dst.Xoffset += int64(Widthptr)
......
......@@ -26,30 +26,29 @@ func closurehdr(ntype *Node) {
// references to these variables need to
// refer to the variables in the external
// function declared below; see walkclosure.
setNodeSeq(&n.List, ntype.List)
n.List.Set(ntype.List.Slice())
setNodeSeq(&n.Rlist, ntype.Rlist)
setNodeSeq(&ntype.List, nil)
setNodeSeq(&ntype.Rlist, nil)
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
name = it.N().Left
n.Rlist.Set(ntype.Rlist.Slice())
ntype.List.Set(nil)
ntype.Rlist.Set(nil)
for _, n1 := range n.List.Slice() {
name = n1.Left
if name != nil {
name = newname(name.Sym)
}
a = Nod(ODCLFIELD, name, it.N().Right)
a.Isddd = it.N().Isddd
a = Nod(ODCLFIELD, name, n1.Right)
a.Isddd = n1.Isddd
if name != nil {
name.Isddd = a.Isddd
}
appendNodeSeqNode(&ntype.List, a)
ntype.List.Append(a)
}
for it := nodeSeqIterate(n.Rlist); !it.Done(); it.Next() {
name = it.N().Left
for _, n2 := range n.Rlist.Slice() {
name = n2.Left
if name != nil {
name = newname(name.Sym)
}
appendNodeSeqNode(&ntype.Rlist, Nod(ODCLFIELD, name, it.N().Right))
ntype.Rlist.Append(Nod(ODCLFIELD, name, n2.Right))
}
}
......@@ -177,8 +176,8 @@ func makeclosure(func_ *Node) *Node {
// that begins by reading closure parameters.
xtype := Nod(OTFUNC, nil, nil)
setNodeSeq(&xtype.List, func_.List)
setNodeSeq(&xtype.Rlist, func_.Rlist)
xtype.List.Set(func_.List.Slice())
xtype.Rlist.Set(func_.Rlist.Slice())
// create the function
xfunc := Nod(ODCLFUNC, nil, nil)
......@@ -205,8 +204,8 @@ func makeclosure(func_ *Node) *Node {
func_.Func.Closure = xfunc
func_.Nbody.Set(nil)
setNodeSeq(&func_.List, nil)
setNodeSeq(&func_.Rlist, nil)
func_.List.Set(nil)
func_.Rlist.Set(nil)
return xfunc
}
......@@ -426,7 +425,7 @@ func walkclosure(func_ *Node, init *Nodes) *Node {
typ := Nod(OTSTRUCT, nil, nil)
setNodeSeq(&typ.List, []*Node{Nod(ODCLFIELD, newname(Lookup(".F")), typenod(Types[TUINTPTR]))})
typ.List.Set([]*Node{Nod(ODCLFIELD, newname(Lookup(".F")), typenod(Types[TUINTPTR]))})
var typ1 *Node
for _, v := range func_.Func.Cvars.Slice() {
if v.Op == OXXX {
......@@ -436,13 +435,13 @@ func walkclosure(func_ *Node, init *Nodes) *Node {
if !v.Name.Byval {
typ1 = Nod(OIND, typ1, nil)
}
appendNodeSeqNode(&typ.List, Nod(ODCLFIELD, newname(v.Sym), typ1))
typ.List.Append(Nod(ODCLFIELD, newname(v.Sym), typ1))
}
clos := Nod(OCOMPLIT, nil, Nod(OIND, typ, nil))
clos.Esc = func_.Esc
clos.Right.Implicit = true
setNodeSeq(&clos.List, append([]*Node{Nod(OCFUNC, func_.Func.Closure.Func.Nname, nil)}, func_.Func.Enter.Slice()...))
clos.List.Set(append([]*Node{Nod(OCFUNC, func_.Func.Closure.Func.Nname, nil)}, func_.Func.Enter.Slice()...))
// Force type conversion from *struct to the func type.
clos = Nod(OCONVNOP, clos, nil)
......@@ -550,7 +549,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
l = append(l, fld)
}
setNodeSeq(&xtype.List, l)
xtype.List.Set(l)
i = 0
l = nil
var retargs []*Node
......@@ -563,7 +562,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
l = append(l, Nod(ODCLFIELD, n, typenod(t.Type)))
}
setNodeSeq(&xtype.Rlist, l)
xtype.Rlist.Set(l)
xfunc.Func.Dupok = true
xfunc.Func.Nname = newfuncname(sym)
......@@ -600,14 +599,14 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
}
call := Nod(OCALL, Nod(OXDOT, ptr, meth), nil)
setNodeSeq(&call.List, callargs)
call.List.Set(callargs)
call.Isddd = ddd
if t0.Outtuple == 0 {
body = append(body, call)
} else {
n := Nod(OAS2, nil, nil)
setNodeSeq(&n.List, retargs)
setNodeSeq(&n.Rlist, []*Node{call})
n.List.Set(retargs)
n.Rlist.Set([]*Node{call})
body = append(body, n)
n = Nod(ORETURN, nil, nil)
body = append(body, n)
......@@ -640,14 +639,14 @@ func walkpartialcall(n *Node, init *Nodes) *Node {
}
typ := Nod(OTSTRUCT, nil, nil)
setNodeSeq(&typ.List, []*Node{Nod(ODCLFIELD, newname(Lookup("F")), typenod(Types[TUINTPTR]))})
appendNodeSeqNode(&typ.List, Nod(ODCLFIELD, newname(Lookup("R")), typenod(n.Left.Type)))
typ.List.Set([]*Node{Nod(ODCLFIELD, newname(Lookup("F")), typenod(Types[TUINTPTR]))})
typ.List.Append(Nod(ODCLFIELD, newname(Lookup("R")), typenod(n.Left.Type)))
clos := Nod(OCOMPLIT, nil, Nod(OIND, typ, nil))
clos.Esc = n.Esc
clos.Right.Implicit = true
setNodeSeq(&clos.List, []*Node{Nod(OCFUNC, n.Func.Nname, nil)})
appendNodeSeqNode(&clos.List, n.Left)
clos.List.Set([]*Node{Nod(OCFUNC, n.Func.Nname, nil)})
clos.List.Append(n.Left)
// Force type conversion from *struct to the func type.
clos = Nod(OCONVNOP, clos, nil)
......
......@@ -543,7 +543,7 @@ func evconst(n *Node) {
// merge adjacent constants in the argument list.
case OADDSTR:
s := nodeSeqSlice(n.List)
s := n.List.Slice()
for i1 := 0; i1 < len(s); i1++ {
if Isconst(s[i1], CTSTR) && i1+1 < len(s) && Isconst(s[i1+1], CTSTR) {
// merge from i1 up to but not including i2
......@@ -567,7 +567,7 @@ func evconst(n *Node) {
n.Op = OLITERAL
n.SetVal(s[0].Val())
} else {
setNodeSeq(&n.List, s)
n.List.Set(s)
}
return
......@@ -1736,14 +1736,13 @@ func hascallchan(n *Node) bool {
if hascallchan(n.Left) || hascallchan(n.Right) {
return true
}
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
if hascallchan(it.N()) {
for _, n1 := range n.List.Slice() {
if hascallchan(n1) {
return true
}
}
for it := nodeSeqIterate(n.Rlist); !it.Done(); it.Next() {
if hascallchan(it.N()) {
for _, n2 := range n.Rlist.Slice() {
if hascallchan(n2) {
return true
}
}
......
......@@ -228,7 +228,7 @@ func variter(vl *NodeList, t *Node, el *NodeList) *NodeList {
e := el.N
as2 := Nod(OAS2, nil, nil)
setNodeSeq(&as2.List, vl)
setNodeSeqNode(&as2.Rlist, e)
as2.Rlist.Set([]*Node{e})
var v *Node
for ; vl != nil; vl = vl.Next {
v = vl.N
......@@ -438,17 +438,17 @@ func colasname(n *Node) bool {
}
func colasdefn(left Nodes, defn *Node) {
for it := nodeSeqIterate(left); !it.Done(); it.Next() {
if it.N().Sym != nil {
it.N().Sym.Flags |= SymUniq
for _, n1 := range left.Slice() {
if n1.Sym != nil {
n1.Sym.Flags |= SymUniq
}
}
nnew := 0
nerr := 0
var n *Node
for it := nodeSeqIterate(left); !it.Done(); it.Next() {
n = it.N()
for i2, n2 := range left.Slice() {
n = n2
if isblank(n) {
continue
}
......@@ -474,8 +474,8 @@ func colasdefn(left Nodes, defn *Node) {
n = newname(n.Sym)
declare(n, dclcontext)
n.Name.Defn = defn
appendNodeSeqNode(&defn.Ninit, Nod(ODCL, n, nil))
*it.P() = n
defn.Ninit.Append(Nod(ODCL, n, nil))
left.Slice()[i2] = n
}
if nnew == 0 && nerr == 0 {
......@@ -492,11 +492,11 @@ func colas(left *NodeList, right *NodeList, lno int32) *Node {
colasdefn(as.List, as)
// make the tree prettier; not necessary
if nodeSeqLen(as.List) == 1 && nodeSeqLen(as.Rlist) == 1 {
as.Left = nodeSeqFirst(as.List)
as.Right = nodeSeqFirst(as.Rlist)
setNodeSeq(&as.List, nil)
setNodeSeq(&as.Rlist, nil)
if as.List.Len() == 1 && as.Rlist.Len() == 1 {
as.Left = as.List.First()
as.Right = as.Rlist.First()
as.List.Set(nil)
as.Rlist.Set(nil)
as.Op = OAS
}
......@@ -570,7 +570,7 @@ func funcargs(nt *Node) {
// re-start the variable generation number
// we want to use small numbers for the return variables,
// so let them have the chunk starting at 1.
vargen = nodeSeqLen(nt.Rlist)
vargen = nt.Rlist.Len()
// declare the receiver and in arguments.
// no n->defn because type checking of func header
......@@ -592,8 +592,7 @@ func funcargs(nt *Node) {
}
var n *Node
for it := nodeSeqIterate(nt.List); !it.Done(); it.Next() {
n = it.N()
for _, n = range nt.List.Slice() {
if n.Op != ODCLFIELD {
Fatalf("funcargs in %v", Oconv(n.Op, 0))
}
......@@ -609,12 +608,10 @@ func funcargs(nt *Node) {
}
// declare the out arguments.
gen := nodeSeqLen(nt.List)
gen := nt.List.Len()
var i int = 0
var nn *Node
for it := nodeSeqIterate(nt.Rlist); !it.Done(); it.Next() {
n = it.N()
for _, n = range nt.Rlist.Slice() {
if n.Op != ODCLFIELD {
Fatalf("funcargs out %v", Oconv(n.Op, 0))
}
......@@ -964,10 +961,10 @@ func tointerface0(t *Type, l []*Node) *Type {
}
tp := &t.Type
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
f := interfacefield(it.N())
for _, n := range l {
f := interfacefield(n)
if it.N().Left == nil && f.Type.Etype == TINTER {
if n.Left == nil && f.Type.Etype == TINTER {
// embedded interface, inline methods
for t1 := f.Type.Type; t1 != nil; t1 = t1.Down {
f = typ(TFIELD)
......@@ -1536,8 +1533,8 @@ func checknowritebarrierrec() {
}
func (c *nowritebarrierrecChecker) visitcodelist(l Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
c.visitcode(it.N())
for _, n := range l.Slice() {
c.visitcode(n)
}
}
......
This diff is collapsed.
......@@ -107,8 +107,8 @@ func dumppkg(p *Pkg) {
// Look for anything we need for the inline body
func reexportdeplist(ll Nodes) {
for it := nodeSeqIterate(ll); !it.Done(); it.Next() {
reexportdep(it.N())
for _, n := range ll.Slice() {
reexportdep(n)
}
}
......
......@@ -800,10 +800,10 @@ func stmtfmt(n *Node) string {
// block starting with the init statements.
// if we can just say "for" n->ninit; ... then do so
simpleinit := nodeSeqLen(n.Ninit) == 1 && nodeSeqLen(nodeSeqFirst(n.Ninit).Ninit) == 0 && stmtwithinit(n.Op)
simpleinit := n.Ninit.Len() == 1 && n.Ninit.First().Ninit.Len() == 0 && stmtwithinit(n.Op)
// otherwise, print the inits as separate statements
complexinit := nodeSeqLen(n.Ninit) != 0 && !simpleinit && (fmtmode != FErr)
complexinit := n.Ninit.Len() != 0 && !simpleinit && (fmtmode != FErr)
// but if it was for if/for/switch, put in an extra surrounding block to limit the scope
extrablock := complexinit && stmtwithinit(n.Op)
......@@ -885,11 +885,11 @@ func stmtfmt(n *Node) string {
case OIF:
if simpleinit {
f += fmt.Sprintf("if %v; %v { %v }", nodeSeqFirst(n.Ninit), n.Left, n.Nbody)
f += fmt.Sprintf("if %v; %v { %v }", n.Ninit.First(), n.Left, n.Nbody)
} else {
f += fmt.Sprintf("if %v { %v }", n.Left, n.Nbody)
}
if nodeSeqLen(n.Rlist) != 0 {
if n.Rlist.Len() != 0 {
f += fmt.Sprintf(" else { %v }", n.Rlist)
}
......@@ -901,7 +901,7 @@ func stmtfmt(n *Node) string {
f += "for"
if simpleinit {
f += fmt.Sprintf(" %v;", nodeSeqFirst(n.Ninit))
f += fmt.Sprintf(" %v;", n.Ninit.First())
} else if n.Right != nil {
f += " ;"
}
......@@ -924,7 +924,7 @@ func stmtfmt(n *Node) string {
break
}
if nodeSeqLen(n.List) == 0 {
if n.List.Len() == 0 {
f += fmt.Sprintf("for range %v { %v }", n.Right, n.Nbody)
break
}
......@@ -939,7 +939,7 @@ func stmtfmt(n *Node) string {
f += Oconv(n.Op, obj.FmtSharp)
if simpleinit {
f += fmt.Sprintf(" %v;", nodeSeqFirst(n.Ninit))
f += fmt.Sprintf(" %v;", n.Ninit.First())
}
if n.Left != nil {
f += Nconv(n.Left, 0)
......@@ -948,7 +948,7 @@ func stmtfmt(n *Node) string {
f += fmt.Sprintf(" { %v }", n.List)
case OCASE, OXCASE:
if nodeSeqLen(n.List) != 0 {
if n.List.Len() != 0 {
f += fmt.Sprintf("case %v: %v", Hconv(n.List, obj.FmtComma), n.Nbody)
} else {
f += fmt.Sprintf("default: %v", n.Nbody)
......@@ -1391,7 +1391,7 @@ func exprfmt(n *Node, prec int) string {
return f
case OMAKEMAP, OMAKECHAN, OMAKESLICE:
if nodeSeqLen(n.List) != 0 { // pre-typecheck
if n.List.Len() != 0 { // pre-typecheck
return fmt.Sprintf("make(%v, %v)", n.Type, Hconv(n.List, obj.FmtComma))
}
if n.Right != nil {
......@@ -1450,11 +1450,11 @@ func exprfmt(n *Node, prec int) string {
case OADDSTR:
var f string
i := 0
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
for _, n1 := range n.List.Slice() {
if i != 0 {
f += " + "
}
f += exprfmt(it.N(), nprec)
f += exprfmt(n1, nprec)
i++
}
......@@ -1523,7 +1523,7 @@ func nodedump(n *Node, flag int) string {
return buf.String()
}
if nodeSeqLen(n.Ninit) != 0 {
if n.Ninit.Len() != 0 {
fmt.Fprintf(&buf, "%v-init%v", Oconv(n.Op, 0), n.Ninit)
indent(&buf)
}
......@@ -1576,12 +1576,12 @@ func nodedump(n *Node, flag int) string {
if n.Right != nil {
buf.WriteString(Nconv(n.Right, 0))
}
if nodeSeqLen(n.List) != 0 {
if n.List.Len() != 0 {
indent(&buf)
fmt.Fprintf(&buf, "%v-list%v", Oconv(n.Op, 0), n.List)
}
if nodeSeqLen(n.Rlist) != 0 {
if n.Rlist.Len() != 0 {
indent(&buf)
fmt.Fprintf(&buf, "%v-rlist%v", Oconv(n.Op, 0), n.Rlist)
}
......@@ -1711,7 +1711,7 @@ func (n Nodes) String() string {
// Fmt '%H': NodeList.
// Flags: all those of %N plus ',': separate with comma's instead of semicolons.
func Hconv(l Nodes, flag int) string {
if nodeSeqLen(l) == 0 && fmtmode == FDbg {
if l.Len() == 0 && fmtmode == FDbg {
return "<nil>"
}
......
......@@ -216,8 +216,8 @@ func stmtlabel(n *Node) *Label {
// compile statements
func Genlist(l Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
gen(it.N())
for _, n := range l.Slice() {
gen(n)
}
}
......@@ -440,7 +440,7 @@ func cgen_dottype(n *Node, res, resok *Node, wb bool) {
r1.Type = byteptr
r2.Type = byteptr
setNodeSeq(&call.List, list(list(list1(&r1), &r2), typename(n.Left.Type)))
setNodeSeq(&call.List, ascompatte(OCALLFUNC, call, false, fn.Type.ParamsP(), call.List.Slice(), 0, nil))
call.List.Set(ascompatte(OCALLFUNC, call, false, fn.Type.ParamsP(), call.List.Slice(), 0, nil))
gen(call)
Regfree(&r1)
Regfree(&r2)
......@@ -526,7 +526,7 @@ func Cgen_As2dottype(n, res, resok *Node) {
dowidth(fn.Type)
call := Nod(OCALLFUNC, fn, nil)
setNodeSeq(&call.List, list(list(list1(&r1), &r2), typename(n.Left.Type)))
setNodeSeq(&call.List, ascompatte(OCALLFUNC, call, false, fn.Type.ParamsP(), call.List.Slice(), 0, nil))
call.List.Set(ascompatte(OCALLFUNC, call, false, fn.Type.ParamsP(), call.List.Slice(), 0, nil))
gen(call)
Regfree(&r1)
Regfree(&r2)
......@@ -638,7 +638,7 @@ func gen(n *Node) {
goto ret
}
if nodeSeqLen(n.Ninit) > 0 {
if n.Ninit.Len() > 0 {
Genlist(n.Ninit)
}
......@@ -845,7 +845,7 @@ func gen(n *Node) {
Cgen_as_wb(n.Left, n.Right, true)
case OAS2DOTTYPE:
cgen_dottype(nodeSeqFirst(n.Rlist), nodeSeqFirst(n.List), nodeSeqSecond(n.List), needwritebarrier(nodeSeqFirst(n.List), nodeSeqFirst(n.Rlist)))
cgen_dottype(n.Rlist.First(), n.List.First(), n.List.Second(), needwritebarrier(n.List.First(), n.Rlist.First()))
case OCALLMETH:
cgen_callmeth(n, 0)
......
This diff is collapsed.
This diff is collapsed.
......@@ -684,7 +684,7 @@ func (p *parser) labeled_stmt(label *Node) *Node {
label.Name.Defn = ls
l := []*Node{label}
if ls != nil {
if ls.Op == OBLOCK && nodeSeqLen(ls.Ninit) == 0 {
if ls.Op == OBLOCK && ls.Ninit.Len() == 0 {
l = append(l, ls.List.Slice()...)
} else {
l = append(l, ls)
......@@ -726,7 +726,7 @@ func (p *parser) case_(tswitch *Node) *Node {
// type switch - declare variable
nn := newname(n.Sym)
declare(nn, dclcontext)
setNodeSeq(&stmt.Rlist, []*Node{nn})
stmt.Rlist.Set([]*Node{nn})
// keep track of the instances for reporting unused
nn.Name.Defn = tswitch
......@@ -752,9 +752,9 @@ func (p *parser) case_(tswitch *Node) *Node {
} else {
n = Nod(OAS2, nil, nil)
setNodeSeq(&n.List, cases)
setNodeSeq(&n.Rlist, []*Node{rhs})
n.Rlist.Set([]*Node{rhs})
}
setNodeSeq(&stmt.List, []*Node{n})
stmt.List.Set([]*Node{n})
p.want(':') // consume ':' after declaring select cases for correct lineno
return stmt
......@@ -770,7 +770,7 @@ func (p *parser) case_(tswitch *Node) *Node {
// done in casebody()
markdcl() // matching popdcl in caseblock
stmt := Nod(OXCASE, nil, nil)
setNodeSeq(&stmt.List, []*Node{colas(cases, list1(rhs), lno)})
stmt.List.Set([]*Node{colas(cases, list1(rhs), lno)})
p.want(':') // consume ':' after declaring select cases for correct lineno
return stmt
......@@ -794,7 +794,7 @@ func (p *parser) case_(tswitch *Node) *Node {
// type switch - declare variable
nn := newname(n.Sym)
declare(nn, dclcontext)
setNodeSeq(&stmt.Rlist, []*Node{nn})
stmt.Rlist.Set([]*Node{nn})
// keep track of the instances for reporting unused
nn.Name.Defn = tswitch
......@@ -918,7 +918,7 @@ func (p *parser) for_header() *Node {
}
h := Nod(OFOR, nil, nil)
if init != nil {
setNodeSeq(&h.Ninit, []*Node{init})
h.Ninit.Set([]*Node{init})
}
h.Left = cond
h.Right = post
......@@ -1022,7 +1022,7 @@ func (p *parser) if_header() *Node {
init, cond, _ := p.header(false)
h := Nod(OIF, nil, nil)
if init != nil {
setNodeSeq(&h.Ninit, []*Node{init})
h.Ninit.Set([]*Node{init})
}
h.Left = cond
return h
......@@ -1047,13 +1047,13 @@ func (p *parser) if_stmt() *Node {
if p.got(LELSE) {
if p.tok == LIF {
setNodeSeq(&stmt.Rlist, []*Node{p.if_stmt()})
stmt.Rlist.Set([]*Node{p.if_stmt()})
} else {
cs := p.compound_stmt(true)
if cs.Op == OBLOCK && nodeSeqLen(cs.Ninit) == 0 {
setNodeSeq(&stmt.Rlist, cs.List)
if cs.Op == OBLOCK && cs.Ninit.Len() == 0 {
stmt.Rlist.Set(cs.List.Slice())
} else {
setNodeSeq(&stmt.Rlist, []*Node{cs})
stmt.Rlist.Set([]*Node{cs})
}
}
}
......@@ -1553,7 +1553,7 @@ func (p *parser) complitexpr() *Node {
p.xnest--
p.want('}')
setNodeSeq(&n.List, l)
n.List.Set(l)
return n
}
......@@ -1842,7 +1842,7 @@ func (p *parser) interfacetype() *Node {
p.want('}')
t := Nod(OTINTER, nil, nil)
setNodeSeq(&t.List, l)
t.List.Set(l)
return t
}
......@@ -2514,7 +2514,7 @@ func (p *parser) stmt() *Node {
stmt := Nod(ORETURN, nil, nil)
setNodeSeq(&stmt.List, results)
if nodeSeqLen(stmt.List) == 0 && Curfn != nil {
if stmt.List.Len() == 0 && Curfn != nil {
for _, ln := range Curfn.Func.Dcl {
if ln.Class == PPARAM {
continue
......@@ -2549,7 +2549,7 @@ func (p *parser) stmt_list() (l *NodeList) {
if s == missing_stmt {
break
}
if s != nil && s.Op == OBLOCK && nodeSeqLen(s.Ninit) == 0 {
if s != nil && s.Op == OBLOCK && s.Ninit.Len() == 0 {
appendNodeSeq(&l, s.List)
} else {
appendNodeSeqNode(&l, s)
......
......@@ -87,11 +87,11 @@ func instrument(fn *Node) {
}
func instrumentlist(l Nodes, init *Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
for i := range l.Slice() {
var instr Nodes
instrumentnode(it.P(), &instr, 0, 0)
instrumentnode(&l.Slice()[i], &instr, 0, 0)
if init == nil {
it.N().Ninit.AppendNodes(&instr)
l.Slice()[i].Ninit.AppendNodes(&instr)
} else {
init.AppendNodes(&instr)
}
......@@ -121,7 +121,7 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
// nil it out and handle it separately before putting it back.
l := n.Ninit
setNodeSeq(&n.Ninit, nil)
n.Ninit.Set(nil)
instrumentlist(l, nil)
instrumentnode(&n, &l, wr, skip) // recurse with nil n->ninit
appendinit(&n, l)
......@@ -167,7 +167,7 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
out = append(outn.Slice(), it.N())
}
}
setNodeSeq(&n.List, out)
n.List.Set(out)
goto ret
case ODEFER:
......@@ -595,8 +595,8 @@ func foreachnode(n *Node, f func(*Node, interface{}), c interface{}) {
}
func foreachlist(l Nodes, f func(*Node, interface{}), c interface{}) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
foreachnode(it.N(), f, c)
for _, n := range l.Slice() {
foreachnode(n, f, c)
}
}
......@@ -619,7 +619,7 @@ func hascallspred(n *Node, c interface{}) {
// appendinit is like addinit in subr.go
// but appends rather than prepends.
func appendinit(np **Node, init Nodes) {
if nodeSeqLen(init) == 0 {
if init.Len() == 0 {
return
}
......@@ -635,6 +635,6 @@ func appendinit(np **Node, init Nodes) {
*np = n
}
appendNodeSeq(&n.Ninit, init)
n.Ninit.AppendNodes(&init)
n.Ullman = UINF
}
......@@ -31,11 +31,10 @@ func typecheckrange(n *Node) {
if t == nil {
goto out
}
// delicate little dance. see typecheckas2
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
if it.N().Name == nil || it.N().Name.Defn != n {
typecheck(it.P(), Erv|Easgn)
for i1, n1 := range n.List.Slice() {
if n1.Name == nil || n1.Name.Defn != n {
typecheck(&n.List.Slice()[i1], Erv|Easgn)
}
}
......@@ -66,7 +65,7 @@ func typecheckrange(n *Node) {
t1 = t.Type
t2 = nil
if nodeSeqLen(n.List) == 2 {
if n.List.Len() == 2 {
toomany = 1
}
......@@ -75,17 +74,17 @@ func typecheckrange(n *Node) {
t2 = runetype
}
if nodeSeqLen(n.List) > 2 || toomany != 0 {
if n.List.Len() > 2 || toomany != 0 {
Yyerror("too many variables in range")
}
v1 = nil
if nodeSeqLen(n.List) != 0 {
v1 = nodeSeqFirst(n.List)
if n.List.Len() != 0 {
v1 = n.List.First()
}
v2 = nil
if nodeSeqLen(n.List) > 1 {
v2 = nodeSeqSecond(n.List)
if n.List.Len() > 1 {
v2 = n.List.Second()
}
// this is not only a optimization but also a requirement in the spec.
......@@ -94,7 +93,7 @@ func typecheckrange(n *Node) {
// present."
if isblank(v2) {
if v1 != nil {
setNodeSeq(&n.List, []*Node{v1})
n.List.Set([]*Node{v1})
}
v2 = nil
}
......@@ -120,10 +119,9 @@ func typecheckrange(n *Node) {
// second half of dance
out:
n.Typecheck = 1
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
if it.N().Typecheck == 0 {
typecheck(it.P(), Erv|Easgn)
for i2, n2 := range n.List.Slice() {
if n2.Typecheck == 0 {
typecheck(&n.List.Slice()[i2], Erv|Easgn)
}
}
......@@ -147,17 +145,17 @@ func walkrange(n *Node) {
n.Right = nil
var v1 *Node
if nodeSeqLen(n.List) != 0 {
v1 = nodeSeqFirst(n.List)
if n.List.Len() != 0 {
v1 = n.List.First()
}
var v2 *Node
if nodeSeqLen(n.List) > 1 && !isblank(nodeSeqSecond(n.List)) {
v2 = nodeSeqSecond(n.List)
if n.List.Len() > 1 && !isblank(n.List.Second()) {
v2 = n.List.Second()
}
// n->list has no meaning anymore, clear it
// to avoid erroneous processing by racewalk.
setNodeSeq(&n.List, nil)
n.List.Set(nil)
var body []*Node
var init []*Node
......@@ -195,8 +193,8 @@ func walkrange(n *Node) {
body = []*Node{Nod(OAS, v1, hv1)}
} else {
a := Nod(OAS2, nil, nil)
setNodeSeq(&a.List, []*Node{v1, v2})
setNodeSeq(&a.Rlist, []*Node{hv1, Nod(OIND, hp, nil)})
a.List.Set([]*Node{v1, v2})
a.Rlist.Set([]*Node{hv1, Nod(OIND, hp, nil)})
body = []*Node{a}
// Advance pointer as part of increment.
......@@ -215,7 +213,7 @@ func walkrange(n *Node) {
tmp.Right.Typecheck = 1
a = Nod(OAS, hp, tmp)
typecheck(&a, Etop)
setNodeSeq(&n.Right.Ninit, []*Node{a})
n.Right.Ninit.Set([]*Node{a})
}
// orderstmt allocated the iterator for us.
......@@ -250,8 +248,8 @@ func walkrange(n *Node) {
val := Nod(ODOT, hit, valname)
val = Nod(OIND, val, nil)
a := Nod(OAS2, nil, nil)
setNodeSeq(&a.List, []*Node{v1, v2})
setNodeSeq(&a.Rlist, []*Node{key, val})
a.List.Set([]*Node{v1, v2})
a.Rlist.Set([]*Node{key, val})
body = []*Node{a}
}
......@@ -271,9 +269,9 @@ func walkrange(n *Node) {
n.Left = Nod(ONE, hb, Nodbool(false))
a := Nod(OAS2RECV, nil, nil)
a.Typecheck = 1
setNodeSeq(&a.List, []*Node{hv1, hb})
setNodeSeq(&a.Rlist, []*Node{Nod(ORECV, ha, nil)})
setNodeSeq(&n.Left.Ninit, []*Node{a})
a.List.Set([]*Node{hv1, hb})
a.Rlist.Set([]*Node{Nod(ORECV, ha, nil)})
n.Left.Ninit.Set([]*Node{a})
if v1 == nil {
body = nil
} else {
......@@ -296,13 +294,13 @@ func walkrange(n *Node) {
} else {
hv2 = temp(runetype)
a = Nod(OAS2, nil, nil)
setNodeSeq(&a.List, []*Node{hv1, hv2})
a.List.Set([]*Node{hv1, hv2})
fn := syslook("stringiter2")
setNodeSeq(&a.Rlist, []*Node{mkcall1(fn, fn.Type.Results(), nil, ha, hv1)})
a.Rlist.Set([]*Node{mkcall1(fn, fn.Type.Results(), nil, ha, hv1)})
}
n.Left = Nod(ONE, hv1, Nodintconst(0))
setNodeSeq(&n.Left.Ninit, []*Node{Nod(OAS, ohv1, hv1), a})
n.Left.Ninit.Set([]*Node{Nod(OAS, ohv1, hv1), a})
body = nil
if v1 != nil {
......@@ -315,7 +313,7 @@ func walkrange(n *Node) {
n.Op = OFOR
typechecklist(init, Etop)
appendNodeSeq(&n.Ninit, init)
n.Ninit.Append(init...)
typechecklist(n.Left.Ninit.Slice(), Etop)
typecheck(&n.Left, Erv)
typecheck(&n.Right, Etop)
......
This diff is collapsed.
......@@ -30,8 +30,8 @@ func init1(n *Node, out *[]*Node) {
}
init1(n.Left, out)
init1(n.Right, out)
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
init1(it.N(), out)
for _, n1 := range n.List.Slice() {
init1(n1, out)
}
if n.Left != nil && n.Type != nil && n.Left.Op == OTYPE && n.Class == PFUNC {
......@@ -128,8 +128,8 @@ func init1(n *Node, out *[]*Node) {
break
}
defn.Initorder = InitPending
for it := nodeSeqIterate(defn.Rlist); !it.Done(); it.Next() {
init1(it.N(), out)
for _, n2 := range defn.Rlist.Slice() {
init1(n2, out)
}
if Debug['%'] != 0 {
Dump("nonstatic", defn)
......@@ -192,7 +192,7 @@ func init2(n *Node, out *[]*Node) {
return
}
if n.Op == ONAME && nodeSeqLen(n.Ninit) != 0 {
if n.Op == ONAME && n.Ninit.Len() != 0 {
Fatalf("name %v with ninit: %v\n", n.Sym, Nconv(n, obj.FmtSign))
}
......@@ -213,23 +213,21 @@ func init2(n *Node, out *[]*Node) {
}
func init2list(l Nodes, out *[]*Node) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
init2(it.N(), out)
for _, n := range l.Slice() {
init2(n, out)
}
}
func initreorder(l []*Node, out *[]*Node) {
var n *Node
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
n = it.N()
for _, n = range l {
switch n.Op {
case ODCLFUNC, ODCLCONST, ODCLTYPE:
continue
}
initreorder(n.Ninit.Slice(), out)
setNodeSeq(&n.Ninit, nil)
n.Ninit.Set(nil)
init1(n, out)
}
}
......@@ -558,9 +556,8 @@ func getdyn(n *Node, top int) int {
case OSTRUCTLIT:
break
}
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
value := it.N().Right
for _, n1 := range n.List.Slice() {
value := n1.Right
mode |= getdyn(value, 0)
if mode == MODEDYNAM|MODECONST {
break
......@@ -571,8 +568,7 @@ func getdyn(n *Node, top int) int {
}
func structlit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
r := it.N()
for _, r := range n.List.Slice() {
if r.Op != OKEY {
Fatalf("structlit: rhs not OKEY: %v", r)
}
......@@ -636,8 +632,7 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
}
func arraylit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
r := it.N()
for _, r := range n.List.Slice() {
if r.Op != OKEY {
Fatalf("arraylit: rhs not OKEY: %v", r)
}
......@@ -784,7 +779,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init *Nodes) {
a = Nod(OADDR, a, nil)
} else {
a = Nod(ONEW, nil, nil)
setNodeSeq(&a.List, []*Node{typenod(t)})
a.List.Set([]*Node{typenod(t)})
}
a = Nod(OAS, vauto, a)
......@@ -809,10 +804,8 @@ func slicelit(ctxt int, n *Node, var_ *Node, init *Nodes) {
orderstmtinplace(&a)
walkstmt(&a)
init.Append(a)
// put dynamics into slice (6)
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
r := it.N()
for _, r := range n.List.Slice() {
if r.Op != OKEY {
Fatalf("slicelit: rhs not OKEY: %v", r)
}
......@@ -858,13 +851,12 @@ func maplit(ctxt int, n *Node, var_ *Node, init *Nodes) {
nerr := nerrors
a := Nod(OMAKE, nil, nil)
setNodeSeq(&a.List, []*Node{typenod(n.Type)})
a.List.Set([]*Node{typenod(n.Type)})
litas(var_, a, init)
// count the initializers
b := 0
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
r := it.N()
for _, r := range n.List.Slice() {
if r.Op != OKEY {
Fatalf("maplit: rhs not OKEY: %v", r)
}
......@@ -907,9 +899,7 @@ func maplit(ctxt int, n *Node, var_ *Node, init *Nodes) {
vstat := staticname(tarr, ctxt)
b := int64(0)
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
r := it.N()
for _, r := range n.List.Slice() {
if r.Op != OKEY {
Fatalf("maplit: rhs not OKEY: %v", r)
}
......@@ -965,7 +955,7 @@ func maplit(ctxt int, n *Node, var_ *Node, init *Nodes) {
a = Nod(OFOR, nil, nil)
a.Nbody.Set([]*Node{r})
setNodeSeq(&a.Ninit, []*Node{Nod(OAS, index, Nodintconst(0))})
a.Ninit.Set([]*Node{Nod(OAS, index, Nodintconst(0))})
a.Left = Nod(OLT, index, Nodintconst(tarr.Bound))
a.Right = Nod(OAS, index, Nod(OADD, index, Nodintconst(1)))
......@@ -976,9 +966,7 @@ func maplit(ctxt int, n *Node, var_ *Node, init *Nodes) {
// put in dynamic entries one-at-a-time
var key, val *Node
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
r := it.N()
for _, r := range n.List.Slice() {
if r.Op != OKEY {
Fatalf("maplit: rhs not OKEY: %v", r)
}
......@@ -1065,7 +1053,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
Fatalf("anylit: not struct")
}
if simplename(var_) && nodeSeqLen(n.List) > 4 {
if simplename(var_) && n.List.Len() > 4 {
if ctxt == 0 {
// lay out static data
vstat := staticname(t, ctxt)
......@@ -1091,7 +1079,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
}
// initialize of not completely specified
if simplename(var_) || nodeSeqLen(n.List) < structcount(t) {
if simplename(var_) || n.List.Len() < structcount(t) {
a := Nod(OAS, var_, nil)
typecheck(&a, Etop)
walkexpr(&a, init)
......@@ -1109,7 +1097,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
break
}
if simplename(var_) && nodeSeqLen(n.List) > 4 {
if simplename(var_) && n.List.Len() > 4 {
if ctxt == 0 {
// lay out static data
vstat := staticname(t, ctxt)
......@@ -1135,7 +1123,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
}
// initialize of not completely specified
if simplename(var_) || int64(nodeSeqLen(n.List)) < t.Bound {
if simplename(var_) || int64(n.List.Len()) < t.Bound {
a := Nod(OAS, var_, nil)
typecheck(&a, Etop)
walkexpr(&a, init)
......@@ -1257,8 +1245,7 @@ func initplan(n *Node) {
Fatalf("initplan")
case OARRAYLIT:
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
a := it.N()
for _, a := range n.List.Slice() {
if a.Op != OKEY || !Smallintconst(a.Left) {
Fatalf("initplan arraylit")
}
......@@ -1266,8 +1253,7 @@ func initplan(n *Node) {
}
case OSTRUCTLIT:
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
a := it.N()
for _, a := range n.List.Slice() {
if a.Op != OKEY || a.Left.Type == nil {
Fatalf("initplan structlit")
}
......@@ -1275,8 +1261,7 @@ func initplan(n *Node) {
}
case OMAPLIT:
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
a := it.N()
for _, a := range n.List.Slice() {
if a.Op != OKEY {
Fatalf("initplan maplit")
}
......@@ -1351,8 +1336,8 @@ func iszero(n *Node) bool {
// fall through
case OSTRUCTLIT:
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
if !iszero(it.N().Right) {
for _, n1 := range n.List.Slice() {
if !iszero(n1.Right) {
return false
}
}
......
......@@ -510,8 +510,8 @@ func (s *state) stmts(a Nodes) {
// ssaStmtList converts the statement n to SSA and adds it to s.
func (s *state) stmtList(l Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
s.stmt(it.N())
for _, n := range l.Slice() {
s.stmt(n)
}
}
......@@ -559,9 +559,9 @@ func (s *state) stmt(n *Node) {
s.call(n.Left, callGo)
case OAS2DOTTYPE:
res, resok := s.dottype(nodeSeqFirst(n.Rlist), true)
s.assign(nodeSeqFirst(n.List), res, needwritebarrier(nodeSeqFirst(n.List), nodeSeqFirst(n.Rlist)), false, n.Lineno)
s.assign(nodeSeqSecond(n.List), resok, false, false, n.Lineno)
res, resok := s.dottype(n.Rlist.First(), true)
s.assign(n.List.First(), res, needwritebarrier(n.List.First(), n.Rlist.First()), false, n.Lineno)
s.assign(n.List.Second(), resok, false, false, n.Lineno)
return
case ODCL:
......@@ -702,7 +702,7 @@ func (s *state) stmt(n *Node) {
bThen := s.f.NewBlock(ssa.BlockPlain)
bEnd := s.f.NewBlock(ssa.BlockPlain)
var bElse *ssa.Block
if nodeSeqLen(n.Rlist) != 0 {
if n.Rlist.Len() != 0 {
bElse = s.f.NewBlock(ssa.BlockPlain)
s.condBranch(n.Left, bThen, bElse, n.Likely)
} else {
......@@ -715,7 +715,7 @@ func (s *state) stmt(n *Node) {
b.AddEdgeTo(bEnd)
}
if nodeSeqLen(n.Rlist) != 0 {
if n.Rlist.Len() != 0 {
s.startBlock(bElse)
s.stmtList(n.Rlist)
if b := s.endBlock(); b != nil {
......@@ -2025,14 +2025,14 @@ func (s *state) expr(n *Node) *ssa.Value {
pt := Ptrto(et)
// Evaluate slice
slice := s.expr(nodeSeqFirst(n.List))
slice := s.expr(n.List.First())
// Allocate new blocks
grow := s.f.NewBlock(ssa.BlockPlain)
assign := s.f.NewBlock(ssa.BlockPlain)
// Decide if we need to grow
nargs := int64(nodeSeqLen(n.List) - 1)
nargs := int64(n.List.Len() - 1)
p := s.newValue1(ssa.OpSlicePtr, pt, slice)
l := s.newValue1(ssa.OpSliceLen, Types[TINT], slice)
c := s.newValue1(ssa.OpSliceCap, Types[TINT], slice)
......
......@@ -536,7 +536,7 @@ func treecopy(n *Node, lineno int32) *Node {
m.Orig = m
m.Left = treecopy(n.Left, lineno)
m.Right = treecopy(n.Right, lineno)
setNodeSeq(&m.List, listtreecopy(n.List.Slice(), lineno))
m.List.Set(listtreecopy(n.List.Slice(), lineno))
if lineno != 0 {
m.Lineno = lineno
}
......@@ -1379,7 +1379,7 @@ func ullmancalc(n *Node) {
var ul int
var ur int
if nodeSeqLen(n.Ninit) != 0 {
if n.Ninit.Len() != 0 {
ul = UINF
goto out
}
......@@ -1497,7 +1497,7 @@ func safeexpr(n *Node, init *Nodes) *Node {
return nil
}
if nodeSeqLen(n.Ninit) != 0 {
if n.Ninit.Len() != 0 {
walkstmtlist(n.Ninit.Slice())
init.AppendNodes(&n.Ninit)
}
......@@ -1968,8 +1968,8 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
l = append(l, pad)
}
setNodeSeq(&t.List, append(l, in...))
setNodeSeq(&t.Rlist, out)
t.List.Set(append(l, in...))
t.Rlist.Set(out)
fn := Nod(ODCLFUNC, nil, nil)
fn.Func.Nname = newname(newnam)
......@@ -2008,7 +2008,7 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
v.U = method.Sym.Name
l = append(l, nodlit(v)) // method name
call := Nod(OCALL, syslook("panicwrap"), nil)
setNodeSeq(&call.List, l)
call.List.Set(l)
n.Nbody.Set([]*Node{call})
fn.Nbody.Append(n)
}
......@@ -2031,11 +2031,11 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
} else {
fn.Func.Wrapper = true // ignore frame for panic+recover matching
call := Nod(OCALL, dot, nil)
setNodeSeq(&call.List, args)
call.List.Set(args)
call.Isddd = isddd
if method.Type.Outtuple > 0 {
n := Nod(ORETURN, nil, nil)
setNodeSeq(&n.List, []*Node{call})
n.List.Set([]*Node{call})
call = n
}
......@@ -2069,10 +2069,10 @@ func hashmem(t *Type) *Node {
n := newname(sym)
n.Class = PFUNC
tfn := Nod(OTFUNC, nil, nil)
appendNodeSeqNode(&tfn.List, Nod(ODCLFIELD, nil, typenod(Ptrto(t))))
appendNodeSeqNode(&tfn.List, Nod(ODCLFIELD, nil, typenod(Types[TUINTPTR])))
appendNodeSeqNode(&tfn.List, Nod(ODCLFIELD, nil, typenod(Types[TUINTPTR])))
appendNodeSeqNode(&tfn.Rlist, Nod(ODCLFIELD, nil, typenod(Types[TUINTPTR])))
tfn.List.Append(Nod(ODCLFIELD, nil, typenod(Ptrto(t))))
tfn.List.Append(Nod(ODCLFIELD, nil, typenod(Types[TUINTPTR])))
tfn.List.Append(Nod(ODCLFIELD, nil, typenod(Types[TUINTPTR])))
tfn.Rlist.Append(Nod(ODCLFIELD, nil, typenod(Types[TUINTPTR])))
typecheck(&tfn, Etype)
n.Type = tfn.Type
return n
......@@ -2218,15 +2218,15 @@ func Simsimtype(t *Type) EType {
func listtreecopy(l []*Node, lineno int32) []*Node {
var out []*Node
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
out = append(out, treecopy(it.N(), lineno))
for _, n := range l {
out = append(out, treecopy(n, lineno))
}
return out
}
func liststmt(l []*Node) *Node {
n := Nod(OBLOCK, nil, nil)
setNodeSeq(&n.List, l)
n.List.Set(l)
if nodeSeqLen(l) != 0 {
n.Lineno = nodeSeqFirst(l).Lineno
}
......@@ -2573,7 +2573,7 @@ func addinit(np **Node, init []*Node) {
*np = n
}
setNodeSeq(&n.Ninit, append(nodeSeqSlice(init), nodeSeqSlice(n.Ninit)...))
n.Ninit.Set(append(nodeSeqSlice(init), n.Ninit.Slice()...))
n.Ullman = UINF
}
......
This diff is collapsed.
......@@ -429,6 +429,26 @@ func (n *Nodes) Slice() []*Node {
return *n.slice
}
// Len returns the number of entries in Nodes.
func (n *Nodes) Len() int {
if n.slice == nil {
return 0
}
return len(*n.slice)
}
// First returns the first element of Nodes.
// It panics if Nodes has no elements.
func (n *Nodes) First() *Node {
return (*n.slice)[0]
}
// Second returns the second element of Nodes.
// It panics if Nodes has fewer than two elements.
func (n *Nodes) Second() *Node {
return (*n.slice)[1]
}
// NodeList returns the entries in Nodes as a NodeList.
// Changes to the NodeList entries (as in l.N = n) will *not* be
// reflected in the Nodes.
......
This diff is collapsed.
......@@ -26,12 +26,12 @@ func unsafenmagic(nn *Node) *Node {
return nil
}
if nodeSeqLen(args) == 0 {
if args.Len() == 0 {
Yyerror("missing argument for %v", s)
return nil
}
r := nodeSeqFirst(args)
r := args.First()
var v int64
if s.Name == "Sizeof" {
......@@ -129,7 +129,7 @@ bad:
goto ret
yes:
if nodeSeqLen(args) > 1 {
if args.Len() > 1 {
Yyerror("extra arguments for %v", s)
}
......
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