Passes toolstash -cmp.
Update #14473.
Change-Id: I717ebd948dfc8faf8b9ef5aa02c67484af618d18
Reviewed-on: https://go-review.googlesource.com/20359
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Curfn = fn
fn.Func.Dupok = true
typecheck(&fn, Etop)
- typechecklist(fn.Nbody, Etop)
+ typechecklist(fn.Nbody.Slice(), Etop)
Curfn = nil
// Disable safemode while compiling this code: the code we
Curfn = fn
fn.Func.Dupok = true
typecheck(&fn, Etop)
- typechecklist(fn.Nbody, Etop)
+ typechecklist(fn.Nbody.Slice(), Etop)
Curfn = nil
// Disable safemode while compiling this code: the code we
p.int(index)
}
-func (p *exporter) nodeList(list nodesOrNodeList) {
+func (p *exporter) nodeList(list Nodes) {
it := nodeSeqIterate(list)
if p.trace {
p.tracef("[ ")
}
sym := pkg.Lookup(name)
- n := methodname1(newname(sym), recv.N.Right)
- n.Type = functype(recv.N, params, result)
+ n := methodname1(newname(sym), recv[0].Right)
+ n.Type = functype(recv[0], params, result)
checkwidth(n.Type)
// addmethod uses the global variable structpkg to verify consistency
{
}
// go.y:hidden_structdcl_list
-func (p *importer) fieldList() *NodeList {
+func (p *importer) fieldList() []*Node {
i := p.int()
if i == 0 {
return nil
}
- n := list1(p.field())
- for i--; i > 0; i-- {
- n = list(n, p.field())
+ n := make([]*Node, 0, i)
+ for ; i > 0; i-- {
+ n = append(n, p.field())
}
return n
}
}
// go.y:hidden_interfacedcl_list
-func (p *importer) methodList() *NodeList {
+func (p *importer) methodList() []*Node {
i := p.int()
if i == 0 {
return nil
}
- n := list1(p.method())
- for i--; i > 0; i-- {
- n = list(n, p.method())
+ n := make([]*Node, 0, i)
+ for ; i > 0; i-- {
+ n = append(n, p.method())
}
return n
}
}
// go.y:ohidden_funarg_list
-func (p *importer) paramList() *NodeList {
+func (p *importer) paramList() []*Node {
i := p.int()
if i == 0 {
return nil
named = false
}
// i > 0
- n := list1(p.param(named))
- i--
+ n := make([]*Node, 0, i)
for ; i > 0; i-- {
- n = list(n, p.param(named))
+ n = append(n, p.param(named))
}
return n
}
Curfn = func_
olddd := decldepth
decldepth = 1
- typechecklist(func_.Nbody, Etop)
+ typechecklist(func_.Nbody.Slice(), Etop)
decldepth = olddd
Curfn = oldfn
}
lastconst = cl
lasttype = t
}
- clcopy := listtreecopy(cl, lno)
+ clcopy := listtreecopy(nodeSeqSlice(cl), lno)
var v *Node
var c *Node
return false
}
-func colasdefn(left nodesOrNodeList, defn *Node) {
+func colasdefn(left Nodes, defn *Node) {
for it := nodeSeqIterate(left); !it.Done(); it.Next() {
if it.N().Sym != nil {
it.N().Sym.Flags |= SymUniq
// convert a parsed id/type list into
// a type for struct/interface/arglist
-func tostruct(l nodesOrNodeList) *Type {
+func tostruct(l []*Node) *Type {
t := typ(TSTRUCT)
tostruct0(t, l)
return t
}
-func tostruct0(t *Type, l nodesOrNodeList) {
+func tostruct0(t *Type, l []*Node) {
if t == nil || t.Etype != TSTRUCT {
Fatalf("struct expected")
}
}
}
-func tofunargs(l nodesOrNodeList) *Type {
+func tofunargs(l []*Node) *Type {
var f *Type
t := typ(TSTRUCT)
return f
}
-func tointerface(l nodesOrNodeList) *Type {
+func tointerface(l []*Node) *Type {
t := typ(TINTER)
tointerface0(t, l)
return t
}
-func tointerface0(t *Type, l nodesOrNodeList) *Type {
+func tointerface0(t *Type, l []*Node) *Type {
if t == nil || t.Etype != TINTER {
Fatalf("interface expected")
}
}
// turn a parsed function declaration into a type
-func functype(this *Node, in nodesOrNodeList, out nodesOrNodeList) *Type {
+func functype(this *Node, in, out []*Node) *Type {
t := typ(TFUNC)
functype0(t, this, in, out)
return t
}
-func functype0(t *Type, this *Node, in nodesOrNodeList, out nodesOrNodeList) {
+func functype0(t *Type, this *Node, in, out []*Node) {
if t == nil || t.Etype != TFUNC {
Fatalf("function type expected")
}
- var rcvr *NodeList
+ var rcvr []*Node
if this != nil {
- rcvr = list1(this)
+ rcvr = []*Node{this}
}
t.Type = tofunargs(rcvr)
t.Type.Down = tofunargs(out)
})
}
-func (c *nowritebarrierrecChecker) visitcodelist(l nodesOrNodeList) {
+func (c *nowritebarrierrecChecker) visitcodelist(l Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
c.visitcode(it.N())
}
return min
}
-func (v *bottomUpVisitor) visitcodelist(l nodesOrNodeList, min uint32) uint32 {
+func (v *bottomUpVisitor) visitcodelist(l Nodes, min uint32) uint32 {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
min = v.visitcode(it.N(), min)
}
type NodeEscState struct {
Curfn *Node
- Escflowsrc []*Node // flow(this, src)
- Escretval *NodeList // on OCALLxxx, list of dummy return values
- Escloopdepth int32 // -1: global, 0: return variables, 1:function top level, increased inside function for every loop or label to mark scopes
+ Escflowsrc []*Node // flow(this, src)
+ Escretval Nodes // on OCALLxxx, list of dummy return values
+ Escloopdepth int32 // -1: global, 0: return variables, 1:function top level, increased inside function for every loop or label to mark scopes
Esclevel Level
Walkgen uint32
Maxextraloopdepth int32
var nonlooping Label
-func escloopdepthlist(e *EscState, l nodesOrNodeList) {
+func escloopdepthlist(e *EscState, l Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
escloopdepth(e, it.N())
}
escloopdepthlist(e, n.Rlist)
}
-func esclist(e *EscState, l nodesOrNodeList, up *Node) {
+func esclist(e *EscState, l Nodes, up *Node) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
esc(e, it.N(), up)
}
}
case ORETURN:
- ll := nodesOrNodeList(n.List)
+ ll := n.List
if nodeSeqLen(n.List) == 1 && Curfn.Type.Outtuple > 1 {
// OAS2FUNC in disguise
// esccall already done on n->list->n
// escassignfromtag models the input-to-output assignment flow of one of a function
// calls arguments, where the flow is encoded in "note".
-func escassignfromtag(e *EscState, note *string, dsts nodesOrNodeList, src *Node) uint16 {
+func escassignfromtag(e *EscState, note *string, dsts Nodes, src *Node) uint16 {
em := parsetag(note)
if src.Op == OLITERAL {
return em
func initEscretval(e *EscState, n *Node, fntype *Type) {
i := 0
nE := e.nodeEscState(n)
- setNodeSeq(&nE.Escretval, nil) // Suspect this is not nil for indirect calls.
+ nE.Escretval.Set(nil) // Suspect this is not nil for indirect calls.
for t := getoutargx(fntype).Type; t != nil; t = t.Down {
src := Nod(ONAME, nil, nil)
buf := fmt.Sprintf(".out%d", i)
e.nodeEscState(src).Escloopdepth = e.loopdepth
src.Used = true
src.Lineno = n.Lineno
- appendNodeSeqNode(&nE.Escretval, src)
+ nE.Escretval.Append(src)
}
}
indirect = true
}
- ll := nodesOrNodeList(n.List)
+ ll := n.List
if nodeSeqLen(n.List) == 1 {
a := nodeSeqFirst(n.List)
if a.Type.Etype == TSTRUCT && a.Type.Funarg { // f(g()).
}
// Look for anything we need for the inline body
-func reexportdeplist(ll nodesOrNodeList) {
+func reexportdeplist(ll Nodes) {
for it := nodeSeqIterate(ll); !it.Done(); it.Next() {
reexportdep(it.N())
}
}
func (l *NodeList) String() string {
- return Hconv(l, 0)
+ var n Nodes
+ n.Set(nodeSeqSlice(l))
+ return Hconv(n, 0)
}
func (n Nodes) String() string {
// Fmt '%H': NodeList.
// Flags: all those of %N plus ',': separate with comma's instead of semicolons.
-func Hconv(l nodesOrNodeList, flag int) string {
+func Hconv(l Nodes, flag int) string {
if nodeSeqLen(l) == 0 && fmtmode == FDbg {
return "<nil>"
}
return buf.String()
}
-func dumplist(s string, l nodesOrNodeList) {
+func dumplist(s string, l Nodes) {
fmt.Printf("%s%v\n", s, Hconv(l, obj.FmtSign))
}
}
// compile statements
-func Genlist(l nodesOrNodeList) {
+func Genlist(l Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
gen(it.N())
}
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, getinarg(fn.Type), call.List, 0, nil))
+ setNodeSeq(&call.List, ascompatte(OCALLFUNC, call, false, getinarg(fn.Type), call.List.Slice(), 0, nil))
gen(call)
Regfree(&r1)
Regfree(&r2)
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, getinarg(fn.Type), call.List, 0, nil))
+ setNodeSeq(&call.List, ascompatte(OCALLFUNC, call, false, getinarg(fn.Type), call.List.Slice(), 0, nil))
gen(call)
Regfree(&r1)
Regfree(&r2)
return
}
- nf := initfix(n)
+ nf := initfix(nodeSeqSlice(n))
if !anyinit(nf) {
return
}
savefn := Curfn
Curfn = fn
- typechecklist(fn.Func.Inl, Etop)
+ typechecklist(fn.Func.Inl.Slice(), Etop)
Curfn = savefn
safemode = save_safemode
}
// Look for anything we want to punt on.
-func ishairylist(ll nodesOrNodeList, budget *int) bool {
+func ishairylist(ll Nodes, budget *int) bool {
for it := nodeSeqIterate(ll); !it.Done(); it.Next() {
if ishairy(it.N(), budget) {
return true
// Inlcopy and inlcopylist recursively copy the body of a function.
// Any name-like node of non-local class is marked for re-export by adding it to
// the exportlist.
-func inlcopylist(ll nodesOrNodeList) []*Node {
+func inlcopylist(ll []*Node) []*Node {
s := make([]*Node, 0, nodeSeqLen(ll))
for it := nodeSeqIterate(ll); !it.Done(); it.Next() {
s = append(s, inlcopy(it.N()))
}
m.Left = inlcopy(n.Left)
m.Right = inlcopy(n.Right)
- setNodeSeq(&m.List, inlcopylist(n.List))
- setNodeSeq(&m.Rlist, inlcopylist(n.Rlist))
- setNodeSeq(&m.Ninit, inlcopylist(n.Ninit))
+ setNodeSeq(&m.List, inlcopylist(n.List.Slice()))
+ setNodeSeq(&m.Rlist, inlcopylist(n.Rlist.Slice()))
+ setNodeSeq(&m.Ninit, inlcopylist(n.Ninit.Slice()))
m.Nbody.Set(inlcopylist(n.Nbody.Slice()))
return m
return s
}
-func inlnodelist(l nodesOrNodeList) {
+func inlnodelist(l Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
inlnode(it.P())
}
// pristine ->inl body of the function while substituting references
// to input/output parameters with ones to the tmpnames, and
// substituting returns with assignments to the output.
-func inlsubstlist(ll nodesOrNodeList) []*Node {
+func inlsubstlist(ll Nodes) []*Node {
s := make([]*Node, 0, nodeSeqLen(ll))
for it := nodeSeqIterate(ll); !it.Done(); it.Next() {
s = append(s, inlsubst(it.N()))
appendNodeSeqNode(&m.Ninit, as)
}
- typechecklist(m.Ninit, Etop)
+ typechecklist(m.Ninit.Slice(), Etop)
typecheck(&m, Etop)
// dump("Return after substitution", m);
}
// Plaster over linenumbers
-func setlnolist(ll nodesOrNodeList, lno int32) {
+func setlnolist(ll Nodes, lno int32) {
for it := nodeSeqIterate(ll); !it.Done(); it.Next() {
setlno(it.N(), lno)
}
Curfn = l.N
decldepth = 1
saveerrors()
- typechecklist(l.N.Nbody, Etop)
+ typechecklist(l.N.Nbody.Slice(), Etop)
checkreturn(l.N)
if nerrors != 0 {
l.N.Nbody.Set(nil) // type errors; do not compile
}
// Orderstmtlist orders each of the statements in the list.
-func orderstmtlist(l nodesOrNodeList, order *Order) {
+func orderstmtlist(l Nodes, order *Order) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
orderstmt(it.N(), order)
}
// Orderblock orders the block of statements l onto a new list,
// and returns the ordered list.
-func orderblock(l nodesOrNodeList) []*Node {
+func orderblock(l Nodes) []*Node {
var order Order
mark := marktemp(&order)
orderstmtlist(l, &order)
func orderblockNodes(n *Nodes) {
var order Order
mark := marktemp(&order)
- orderstmtlist(n.Slice(), &order)
+ orderstmtlist(*n, &order)
cleantemp(mark, &order)
n.Set(order.out)
}
// Ismulticall reports whether the list l is f() for a multi-value function.
// Such an f() could appear as the lone argument to a multi-arg function.
-func ismulticall(l nodesOrNodeList) bool {
+func ismulticall(l Nodes) bool {
// one arg only
if nodeSeqLen(l) != 1 {
return false
// Copyret emits t1, t2, ... = n, where n is a function call,
// and then returns the list t1, t2, ....
-func copyret(n *Node, order *Order) *NodeList {
+func copyret(n *Node, order *Order) Nodes {
if n.Type.Etype != TSTRUCT || !n.Type.Funarg {
Fatalf("copyret %v %d", n.Type, n.Left.Type.Outtuple)
}
- var l1 *NodeList
- var l2 *NodeList
+ var l1 []*Node
+ var l2 []*Node
var tl Iter
- var tmp *Node
for t := Structfirst(&tl, &n.Type); t != nil; t = structnext(&tl) {
- tmp = temp(t.Type)
- l1 = list(l1, tmp)
- l2 = list(l2, tmp)
+ tmp := temp(t.Type)
+ l1 = append(l1, tmp)
+ l2 = append(l2, tmp)
}
as := Nod(OAS2, nil, nil)
- setNodeSeq(&as.List, l1)
- setNodeSeq(&as.Rlist, list1(n))
+ as.List.Set(l1)
+ as.Rlist.Set([]*Node{n})
typecheck(&as, Etop)
orderstmt(as, order)
- return l2
+ var r Nodes
+ r.Set(l2)
+ return r
}
// Ordercallargs orders the list of call arguments l and returns the
// ordered list.
-func ordercallargs(l nodesOrNodeList, order *Order) nodesOrNodeList {
+func ordercallargs(l Nodes, order *Order) Nodes {
if ismulticall(l) {
// return f() where f() is multiple values.
return copyret(nodeSeqFirst(l), order)
}
// Orderexprlist orders the expression list l into order.
-func orderexprlist(l nodesOrNodeList, order *Order) {
+func orderexprlist(l Nodes, order *Order) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
orderexpr(it.P(), order, nil)
}
// Orderexprlist orders the expression list l but saves
// the side effects on the individual expression ninit lists.
-func orderexprlistinplace(l nodesOrNodeList, order *Order) {
+func orderexprlistinplace(l Nodes, order *Order) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
orderexprinplace(it.P(), order)
}
}
label.Name.Defn = ls
- l := list1(label)
+ l := []*Node{label}
if ls != nil {
if ls.Op == OBLOCK && nodeSeqLen(ls.Ninit) == 0 {
- appendNodeSeq(&l, ls.List)
+ l = append(l, ls.List.Slice()...)
} else {
- appendNodeSeqNode(&l, ls)
+ l = append(l, ls)
}
}
return liststmt(l)
if l == nil {
stmt = Nod(OEMPTY, nil, nil)
} else {
- stmt = liststmt(l)
+ stmt = liststmt(nodeSeqSlice(l))
}
popdcl()
s5 := p.ohidden_funres()
s := s1
- t := functype(nil, s3, s5)
+ t := functype(nil, nodeSeqSlice(s3), nodeSeqSlice(s5))
importsym(s, ONAME)
if s.Def != nil && s.Def.Op == ONAME {
s8 := p.ohidden_funres()
ss := methodname1(newname(s4), s2.N.Right)
- ss.Type = functype(s2.N, s6, s8)
+ ss.Type = functype(s2.N, nodeSeqSlice(s6), nodeSeqSlice(s8))
checkwidth(ss.Type)
addmethod(s4, ss.Type, false, false)
return p.compound_stmt(false)
case LVAR, LCONST, LTYPE:
- return liststmt(p.common_dcl())
+ return liststmt(nodeSeqSlice(p.common_dcl()))
case LNAME, '@', '?', LLITERAL, LFUNC, '(', // operands
'[', LSTRUCT, LMAP, LCHAN, LINTERFACE, // composite types
s3 := p.ohidden_structdcl_list()
p.want('}')
- return tostruct(s3)
+ return tostruct(nodeSeqSlice(s3))
case LINTERFACE:
// LINTERFACE '{' ohidden_interfacedcl_list '}'
s3 := p.ohidden_interfacedcl_list()
p.want('}')
- return tointerface(s3)
+ return tointerface(nodeSeqSlice(s3))
case '*':
// '*' hidden_type
p.want(')')
s5 := p.ohidden_funres()
- return functype(nil, s3, s5)
+ return functype(nil, nodeSeqSlice(s3), nodeSeqSlice(s5))
}
func (p *parser) hidden_funarg() *Node {
p.want(')')
s5 := p.ohidden_funres()
- return Nod(ODCLFIELD, newname(s1), typenod(functype(fakethis(), s3, s5)))
+ return Nod(ODCLFIELD, newname(s1), typenod(functype(fakethis(), nodeSeqSlice(s3), nodeSeqSlice(s5))))
}
func (p *parser) ohidden_funres() *NodeList {
}
if flag_race == 0 || !ispkgin(norace_inst_pkgs) {
- instrumentlist(fn.Nbody.Slice(), nil)
+ instrumentlist(fn.Nbody, nil)
// nothing interesting for race detector in fn->enter
- instrumentlist(fn.Func.Exit.Slice(), nil)
+ instrumentlist(fn.Func.Exit, nil)
}
if flag_race != 0 {
}
}
-func instrumentlist(l nodesOrNodeList, init *Nodes) {
+func instrumentlist(l Nodes, init *Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
var instr Nodes
instrumentnode(it.P(), &instr, 0, 0)
if n.Op != OBLOCK { // OBLOCK is handled above in a special way.
instrumentlist(n.List, init)
}
- instrumentlist(n.Nbody.Slice(), nil)
+ instrumentlist(n.Nbody, nil)
instrumentlist(n.Rlist, nil)
*np = n
}
}
}
-func foreachlist(l nodesOrNodeList, 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)
}
// appendinit is like addinit in subr.go
// but appends rather than prepends.
-func appendinit(np **Node, init nodesOrNodeList) {
+func appendinit(np **Node, init Nodes) {
if nodeSeqLen(init) == 0 {
return
}
}
decldepth++
- typechecklist(n.Nbody, Etop)
+ typechecklist(n.Nbody.Slice(), Etop)
decldepth--
}
setNodeSeq(&n.List, nil)
var body []*Node
- var init *NodeList
+ var init []*Node
switch t.Etype {
default:
Fatalf("walkrange")
hn := temp(Types[TINT])
var hp *Node
- init = list(init, Nod(OAS, hv1, nil))
- init = list(init, Nod(OAS, hn, Nod(OLEN, ha, nil)))
+ init = append(init, Nod(OAS, hv1, nil))
+ init = append(init, Nod(OAS, hn, Nod(OLEN, ha, nil)))
if v2 != nil {
hp = temp(Ptrto(n.Type.Type))
tmp := Nod(OINDEX, ha, Nodintconst(0))
tmp.Bounded = true
- init = list(init, Nod(OAS, hp, Nod(OADDR, tmp, nil)))
+ init = append(init, Nod(OAS, hp, Nod(OADDR, tmp, nil)))
}
n.Left = Nod(OLT, hv1, hn)
fn := syslook("mapiterinit")
substArgTypes(&fn, t.Down, t.Type, th)
- init = list(init, mkcall1(fn, nil, nil, typename(t), ha, Nod(OADDR, hit, nil)))
+ init = append(init, mkcall1(fn, nil, nil, typename(t), ha, Nod(OADDR, hit, nil)))
n.Left = Nod(ONE, Nod(ODOT, hit, keyname), nodnil())
fn = syslook("mapiternext")
hv1 := temp(t.Type)
hv1.Typecheck = 1
if haspointers(t.Type) {
- init = list(init, Nod(OAS, hv1, nil))
+ init = append(init, Nod(OAS, hv1, nil))
}
hb := temp(Types[TBOOL])
ohv1 := temp(Types[TINT])
hv1 := temp(Types[TINT])
- init = list(init, Nod(OAS, hv1, nil))
+ init = append(init, Nod(OAS, hv1, nil))
var a *Node
var hv2 *Node
n.Op = OFOR
typechecklist(init, Etop)
appendNodeSeq(&n.Ninit, init)
- typechecklist(n.Left.Ninit, Etop)
+ typechecklist(n.Left.Ninit.Slice(), Etop)
typecheck(&n.Left, Erv)
typecheck(&n.Right, Etop)
typecheckslice(body, Etop)
n.Nbody.Append(v1)
typecheck(&n.Left, Erv)
- typechecklist(n.Nbody, Etop)
+ typechecklist(n.Nbody.Slice(), Etop)
walkstmt(&n)
return true
}
// f is method type, with receiver.
// return function type, receiver as first argument (or not).
func methodfunc(f *Type, receiver *Type) *Type {
- var in *NodeList
+ var in []*Node
if receiver != nil {
d := Nod(ODCLFIELD, nil, nil)
d.Type = receiver
- in = list(in, d)
+ in = append(in, d)
}
var d *Node
d = Nod(ODCLFIELD, nil, nil)
d.Type = t.Type
d.Isddd = t.Isddd
- in = list(in, d)
+ in = append(in, d)
}
- var out *NodeList
+ var out []*Node
for t := getoutargx(f).Type; t != nil; t = t.Down {
d = Nod(ODCLFIELD, nil, nil)
d.Type = t.Type
- out = list(out, d)
+ out = append(out, d)
}
t := functype(nil, in, out)
// The latter is the type of an auto-generated wrapper.
dtypesym(Ptrto(errortype))
- dtypesym(functype(nil, list1(Nod(ODCLFIELD, nil, typenod(errortype))), list1(Nod(ODCLFIELD, nil, typenod(Types[TSTRING])))))
+ dtypesym(functype(nil, []*Node{Nod(ODCLFIELD, nil, typenod(errortype))}, []*Node{Nod(ODCLFIELD, nil, typenod(Types[TSTRING]))}))
// add paths for runtime and main, which 6l imports implicitly.
dimportpath(Runtimepkg)
var def *Node
lno := setlineno(sel)
count := 0
- typechecklist(sel.Ninit, Etop)
+ typechecklist(sel.Ninit.Slice(), Etop)
for it := nodeSeqIterate(sel.List); !it.Done(); it.Next() {
count++
ncase = it.N()
}
}
- typechecklist(ncase.Nbody, Etop)
+ typechecklist(ncase.Nbody.Slice(), Etop)
}
sel.Xoffset = int64(count)
dflt = nodeSeqFirst(sel.List)
} else {
dflt = nodeSeqSecond(sel.List)
- cas = nodeSeqFirst(sel.List)
+ cas = nodeSeqFirst(sel.List.Slice())
}
n := cas.Left
}
}
-func init2list(l nodesOrNodeList, out *[]*Node) {
+func init2list(l Nodes, out *[]*Node) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
init2(it.N(), out)
}
}
-func initreorder(l nodesOrNodeList, out *[]*Node) {
+func initreorder(l []*Node, out *[]*Node) {
var n *Node
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
continue
}
- initreorder(n.Ninit, out)
+ initreorder(n.Ninit.Slice(), out)
setNodeSeq(&n.Ninit, nil)
init1(n, out)
}
// initfix computes initialization order for a list l of top-level
// declarations and outputs the corresponding list of statements
// to include in the init() function body.
-func initfix(l nodesOrNodeList) []*Node {
+func initfix(l []*Node) []*Node {
var lout []*Node
initplans = make(map[*Node]*InitPlan)
lno := lineno
}
// ssaStmtList converts the statement n to SSA and adds it to s.
-func (s *state) stmtList(l nodesOrNodeList) {
+func (s *state) stmtList(l Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
s.stmt(it.N())
}
m.Orig = m
m.Left = treecopy(n.Left, lineno)
m.Right = treecopy(n.Right, lineno)
- setNodeSeq(&m.List, listtreecopy(n.List, lineno))
+ setNodeSeq(&m.List, listtreecopy(n.List.Slice(), lineno))
if lineno != 0 {
m.Lineno = lineno
}
fn.Func.Dupok = true
}
typecheck(&fn, Etop)
- typechecklist(fn.Nbody, Etop)
+ typechecklist(fn.Nbody.Slice(), Etop)
inlcalls(fn)
escAnalyze([]*Node{fn}, false)
return et
}
-func listtreecopy(l nodesOrNodeList, lineno int32) []*Node {
+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))
return out
}
-func liststmt(l nodesOrNodeList) *Node {
+func liststmt(l []*Node) *Node {
n := Nod(OBLOCK, nil, nil)
setNodeSeq(&n.List, l)
if nodeSeqLen(l) != 0 {
return p
}
-func addinit(np **Node, init nodesOrNodeList) {
+func addinit(np **Node, init []*Node) {
if nodeSeqLen(init) == 0 {
return
}
// typecheckswitch typechecks a switch statement.
func typecheckswitch(n *Node) {
lno := lineno
- typechecklist(n.Ninit, Etop)
+ typechecklist(n.Ninit.Slice(), Etop)
var nilonly string
var top int
}
}
- typechecklist(ncase.Nbody, Etop)
+ typechecklist(ncase.Nbody.Slice(), Etop)
}
lineno = lno
func (s *exprSwitch) walkCases(cc []*caseClause) *Node {
if len(cc) < binarySearchMin {
// linear search
- var cas *NodeList
+ var cas []*Node
for _, c := range cc {
n := c.node
lno := setlineno(n)
}
a.Nbody.Set([]*Node{n.Right}) // goto l
- cas = list(cas, a)
+ cas = append(cas, a)
lineno = lno
}
return liststmt(cas)
ncase := 0
for i := 0; i < run; i++ {
ncase++
- hash := list1(cc[i].node.Right)
+ hash := []*Node{cc[i].node.Right}
for j := i + 1; j < run && cc[i].hash == cc[j].hash; j++ {
- hash = list(hash, cc[j].node.Right)
+ hash = append(hash, cc[j].node.Right)
}
cc[i].node.Right = liststmt(hash)
}
// case body if the variable is of type t.
func (s *typeSwitch) typeone(t *Node) *Node {
var name *Node
- var init *NodeList
+ var init []*Node
if nodeSeqLen(t.Rlist) == 0 {
name = nblank
typecheck(&nblank, Erv|Easgn)
} else {
name = nodeSeqFirst(t.Rlist)
- init = list1(Nod(ODCL, name, nil))
+ init = []*Node{Nod(ODCL, name, nil)}
a := Nod(OAS, name, nil)
typecheck(&a, Etop)
- init = list(init, a)
+ init = append(init, a)
}
a := Nod(OAS2, nil, nil)
b.Type = t.Left.Type // interface.(type)
setNodeSeq(&a.Rlist, []*Node{b})
typecheck(&a, Etop)
- init = list(init, a)
+ init = append(init, a)
c := Nod(OIF, nil, nil)
c.Left = s.okname
c.Nbody.Set([]*Node{t.Right}) // if ok { goto l }
- return liststmt(list(init, c))
+ return liststmt(append(init, c))
}
// walkCases generates an AST implementing the cases in cc.
func (s *typeSwitch) walkCases(cc []*caseClause) *Node {
if len(cc) < binarySearchMin {
- var cas *NodeList
+ var cas []*Node
for _, c := range cc {
n := c.node
if c.typ != caseKindTypeConst {
a.Left = Nod(OEQ, s.hashname, Nodintconst(int64(c.hash)))
typecheck(&a.Left, Erv)
a.Nbody.Set([]*Node{n.Right})
- cas = list(cas, a)
+ cas = append(cas, a)
}
return liststmt(cas)
}
return n
}
-func typechecklist(l nodesOrNodeList, top int) {
+func typechecklist(l []*Node, top int) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
typecheck(it.P(), top)
}
return callrecv(n.Left) || callrecv(n.Right) || callrecvlist(n.Ninit) || callrecvlist(n.Nbody) || callrecvlist(n.List) || callrecvlist(n.Rlist)
}
-func callrecvlist(l nodesOrNodeList) bool {
+func callrecvlist(l Nodes) bool {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
if callrecv(it.N()) {
return true
case OTSTRUCT:
ok |= Etype
n.Op = OTYPE
- n.Type = tostruct(n.List)
+ n.Type = tostruct(n.List.Slice())
if n.Type == nil || n.Type.Broke {
n.Type = nil
return
case OTINTER:
ok |= Etype
n.Op = OTYPE
- n.Type = tointerface(n.List)
+ n.Type = tointerface(n.List.Slice())
if n.Type == nil {
n.Type = nil
return
case OTFUNC:
ok |= Etype
n.Op = OTYPE
- n.Type = functype(n.Left, n.List, n.Rlist)
+ n.Type = functype(n.Left, n.List.Slice(), n.Rlist.Slice())
if n.Type == nil {
n.Type = nil
return
it := nodeSeqIterate(n.List)
typecheck(it.P(), Erv|Efnstruct)
} else {
- typechecklist(n.List, Erv)
+ typechecklist(n.List.Slice(), Erv)
}
t := l.Type
if t == nil {
var r *Node
var l *Node
if nodeSeqLen(n.List) == 1 {
- typechecklist(n.List, Efnstruct)
+ typechecklist(n.List.Slice(), Efnstruct)
if nodeSeqFirst(n.List).Op != OCALLFUNC && nodeSeqFirst(n.List).Op != OCALLMETH {
Yyerror("invalid operation: complex expects two arguments")
n.Type = nil
}
ok |= Etop
- typechecklist(args, Erv)
+ typechecklist(args.Slice(), Erv)
l := nodeSeqFirst(args)
r := nodeSeqSecond(args)
if l.Type != nil && l.Type.Etype != TMAP {
it := nodeSeqIterate(args)
typecheck(it.P(), Erv|Efnstruct)
} else {
- typechecklist(args, Erv)
+ typechecklist(args.Slice(), Erv)
}
t := nodeSeqFirst(args).Type
case OPRINT, OPRINTN:
ok |= Etop
- typechecklist(n.List, Erv|Eindir) // Eindir: address does not escape
+ typechecklist(n.List.Slice(), Erv|Eindir) // Eindir: address does not escape
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
// Special case for print: int constant is int64, not int.
if Isconst(it.N(), CTINT) {
case OFOR:
ok |= Etop
- typechecklist(n.Ninit, Etop)
+ typechecklist(n.Ninit.Slice(), Etop)
decldepth++
typecheck(&n.Left, Erv)
if n.Left != nil {
}
}
typecheck(&n.Right, Etop)
- typechecklist(n.Nbody, Etop)
+ typechecklist(n.Nbody.Slice(), Etop)
decldepth--
break OpSwitch
case OIF:
ok |= Etop
- typechecklist(n.Ninit, Etop)
+ typechecklist(n.Ninit.Slice(), Etop)
typecheck(&n.Left, Erv)
if n.Left != nil {
t := n.Left.Type
Yyerror("non-bool %v used as if condition", Nconv(n.Left, obj.FmtLong))
}
}
- typechecklist(n.Nbody, Etop)
- typechecklist(n.Rlist, Etop)
+ typechecklist(n.Nbody.Slice(), Etop)
+ typechecklist(n.Rlist.Slice(), Etop)
break OpSwitch
case ORETURN:
ok |= Etop
if nodeSeqLen(n.List) == 1 {
- typechecklist(n.List, Erv|Efnstruct)
+ typechecklist(n.List.Slice(), Erv|Efnstruct)
} else {
- typechecklist(n.List, Erv)
+ typechecklist(n.List.Slice(), Erv)
}
if Curfn == nil {
Yyerror("return outside function")
case OXCASE:
ok |= Etop
- typechecklist(n.List, Erv)
- typechecklist(n.Nbody, Etop)
+ typechecklist(n.List.Slice(), Erv)
+ typechecklist(n.Nbody.Slice(), Etop)
break OpSwitch
case ODCLFUNC:
return nil
}
-func nokeys(l nodesOrNodeList) bool {
+func nokeys(l Nodes) bool {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
if it.N().Op == OKEY {
return false
}
// typecheck assignment: type list = expression list
-func typecheckaste(op Op, call *Node, isddd bool, tstruct *Type, nl nodesOrNodeList, desc func() string) {
+func typecheckaste(op Op, call *Node, isddd bool, tstruct *Type, nl Nodes, desc func() string) {
var t *Type
var n *Node
var n1 int
Yyerror("cannot assign to %v", n)
}
-func checkassignlist(stmt *Node, l nodesOrNodeList) {
+func checkassignlist(stmt *Node, l Nodes) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
checkassign(stmt, it.N())
}
it := nodeSeqIterate(n.Rlist)
typecheck(it.P(), Erv|Efnstruct)
} else {
- typechecklist(n.Rlist, Erv)
+ typechecklist(n.Rlist.Slice(), Erv)
}
checkassignlist(n, n.List)
}
}
-func markbreaklist(l nodesOrNodeList, implicit *Node) {
+func markbreaklist(l Nodes, implicit *Node) {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
n := it.N()
if n.Op == OLABEL && it.Len() > 1 && n.Name.Defn == nodeSeqSlice(it.Seq())[1] {
init := n.Ninit
setNodeSeq(&n.Ninit, nil)
walkexpr(&n, &init)
- addinit(&n, init)
+ addinit(&n, init.Slice())
if (*np).Op == OCOPY && n.Op == OCONVNOP {
n.Op = OEMPTY // don't leave plain values as statements.
}
n = mkcall1(chanfn("chanrecv1", 2, n.Left.Type), nil, &init, typename(n.Left.Type), n.Left, nodnil())
walkexpr(&n, &init)
- addinit(&n, init)
+ addinit(&n, init.Slice())
case OBREAK,
ODCL,
init := n.Left.Ninit
setNodeSeq(&n.Left.Ninit, nil)
walkexpr(&n.Left, &init)
- addinit(&n.Left, init)
+ addinit(&n.Left, init.Slice())
}
walkstmt(&n.Right)
// move function calls out, to make reorder3's job easier.
walkexprlistsafe(n.List.Slice(), &n.Ninit)
- ll := ascompatee(n.Op, rl, n.List, &n.Ninit)
+ ll := ascompatee(n.Op, rl, n.List.Slice(), &n.Ninit)
setNodeSeq(&n.List, reorder3(ll))
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
*it.P() = applywritebarrier(it.N())
break
}
- ll := ascompatte(n.Op, nil, false, Getoutarg(Curfn.Type), n.List, 1, &n.Ninit)
+ ll := ascompatte(n.Op, nil, false, Getoutarg(Curfn.Type), n.List.Slice(), 1, &n.Ninit)
setNodeSeq(&n.List, ll)
case ORETJMP:
var ll Nodes
walkexpr(&n.Right, &ll)
- addinit(&n.Right, ll)
+ addinit(&n.Right, ll.Slice())
case OPRINT, OPRINTN:
walkexprlist(n.List.Slice(), init)
}
walkexpr(&n.Left, init)
walkexprlist(n.List.Slice(), init)
- ll := ascompatte(n.Op, n, n.Isddd, getinarg(t), n.List, 0, init)
+ ll := ascompatte(n.Op, n, n.Isddd, getinarg(t), n.List.Slice(), 0, init)
setNodeSeq(&n.List, reorder1(ll))
case OCALLFUNC:
}
}
- ll := ascompatte(n.Op, n, n.Isddd, getinarg(t), n.List, 0, init)
+ ll := ascompatte(n.Op, n, n.Isddd, getinarg(t), n.List.Slice(), 0, init)
setNodeSeq(&n.List, reorder1(ll))
case OCALLMETH:
}
walkexpr(&n.Left, init)
walkexprlist(n.List.Slice(), init)
- ll := ascompatte(n.Op, n, false, getthis(t), list1(n.Left.Left), 0, init)
- lr := ascompatte(n.Op, n, n.Isddd, getinarg(t), n.List, 0, init)
- ll = concat(ll, lr)
+ ll := ascompatte(n.Op, n, false, getthis(t), []*Node{n.Left.Left}, 0, init)
+ lr := ascompatte(n.Op, n, n.Isddd, getinarg(t), n.List.Slice(), 0, init)
+ ll = append(ll, lr...)
n.Left.Left = nil
ullmancalc(n.Left)
setNodeSeq(&n.List, reorder1(ll))
init.AppendNodes(&n.Ninit)
walkexprlistsafe(n.List.Slice(), init)
walkexprlistsafe(n.Rlist.Slice(), init)
- ll := ascompatee(OAS, n.List, n.Rlist, init)
+ ll := ascompatee(OAS, n.List.Slice(), n.Rlist.Slice(), init)
ll = reorder3(ll)
for i, n := range ll {
ll[i] = applywritebarrier(n)
walkexpr(&r, init)
ll := ascompatet(n.Op, n.List, &r.Type, 0, init)
- for lr := ll; lr != nil; lr = lr.Next {
- lr.N = applywritebarrier(lr.N)
+ for i, n := range ll {
+ ll[i] = applywritebarrier(n)
}
- n = liststmt(concat(list1(r), ll))
+ n = liststmt(append([]*Node{r}, ll...))
// x, y = <-c
// orderstmt made sure x is addressable.
return convas(n, init)
}
-func ascompatee(op Op, nl nodesOrNodeList, nr nodesOrNodeList, init *Nodes) []*Node {
+func ascompatee(op Op, nl, nr []*Node, init *Nodes) []*Node {
// check assign expression list to
// a expression list. called in
// expr-list = expr-list
// cannot happen: caller checked that lists had same length
if !nlit.Done() || !nrit.Done() {
- Yyerror("error in shape across %v %v %v / %d %d [%s]", Hconv(nl, obj.FmtSign), Oconv(op, 0), Hconv(nr, obj.FmtSign), nodeSeqLen(nl), nodeSeqLen(nr), Curfn.Func.Nname.Sym.Name)
+ var nln, nrn Nodes
+ nln.Set(nl)
+ nrn.Set(nr)
+ Yyerror("error in shape across %v %v %v / %d %d [%s]", Hconv(nln, obj.FmtSign), Oconv(op, 0), Hconv(nrn, obj.FmtSign), nodeSeqLen(nl), nodeSeqLen(nr), Curfn.Func.Nname.Sym.Name)
}
return nn
}
return true
}
-func ascompatet(op Op, nl nodesOrNodeList, nr **Type, fp int, init *Nodes) *NodeList {
+func ascompatet(op Op, nl Nodes, nr **Type, fp int, init *Nodes) []*Node {
var l *Node
var tmp *Node
var a *Node
// expr-list = func()
r := Structfirst(&saver, nr)
- var nn *NodeList
- var mm *NodeList
+ var nn []*Node
+ var mm []*Node
ucount := 0
it := nodeSeqIterate(nl)
for ; !it.Done(); it.Next() {
typecheck(&tmp, Erv)
a = Nod(OAS, l, tmp)
a = convas(a, init)
- mm = list(mm, a)
+ mm = append(mm, a)
l = tmp
}
ucount++
}
- nn = list(nn, a)
+ nn = append(nn, a)
r = structnext(&saver)
}
if ucount != 0 {
Fatalf("ascompatet: too many function calls evaluating parameters")
}
- return concat(nn, mm)
+ return append(nn, mm...)
}
// package all the arguments that match a ... T parameter into a []T.
-func mkdotargslice(lr0 nodesOrNodeList, nn *NodeList, l *Type, fp int, init *Nodes, ddd *Node) *NodeList {
+func mkdotargslice(lr0, nn []*Node, l *Type, fp int, init *Nodes, ddd *Node) []*Node {
esc := uint16(EscUnknown)
if ddd != nil {
esc = ddd.Esc
}
a := Nod(OAS, nodarg(l, fp), n)
- nn = list(nn, convas(a, init))
+ nn = append(nn, convas(a, init))
return nn
}
return fmt_
}
-func dumpnodetypes(l nodesOrNodeList, what string) string {
+func dumpnodetypes(l []*Node, what string) string {
var r *Node
fmt_ := ""
// a type list. called in
// return expr-list
// func(expr-list)
-func ascompatte(op Op, call *Node, isddd bool, nl **Type, lr nodesOrNodeList, fp int, init *Nodes) *NodeList {
+func ascompatte(op Op, call *Node, isddd bool, nl **Type, lr []*Node, fp int, init *Nodes) []*Node {
var savel Iter
lr0 := lr
if nodeSeqLen(lr) > 0 {
r = nodeSeqFirst(lr)
}
- var nn *NodeList
+ var nn []*Node
// f(g()) where g has multiple return values
var a *Node
var l2 string
var ll *Type
var l1 string
- var lrit nodeSeqIterator
if r != nil && nodeSeqLen(lr) <= 1 && r.Type.Etype == TSTRUCT && r.Type.Funarg {
// optimization - can do block copy
if eqtypenoname(r.Type, *nl) {
a := nodarg(*nl, fp)
r = Nod(OCONVNOP, r, nil)
r.Type = a.Type
- nn = list1(convas(Nod(OAS, a, r), init))
+ nn = []*Node{convas(Nod(OAS, a, r), init)}
goto ret
}
// conversions involved.
// copy into temporaries.
- var alist *NodeList
+ var alist []*Node
for l := Structfirst(&savel, &r.Type); l != nil; l = structnext(&savel) {
a = temp(l.Type)
- alist = list(alist, a)
+ alist = append(alist, a)
}
a = Nod(OAS2, nil, nil)
l = Structfirst(&savel, nl)
}
- lrit = nodeSeqIterate(lr)
loop:
if l != nil && l.Isddd {
// the ddd parameter must be last
// only if we are assigning a single ddd
// argument to a ddd parameter then it is
// passed thru unencapsulated
- if r != nil && lrit.Len() <= 1 && isddd && Eqtype(l.Type, r.Type) {
+ if r != nil && len(lr) <= 1 && isddd && Eqtype(l.Type, r.Type) {
a = Nod(OAS, nodarg(l, fp), r)
a = convas(a, init)
- nn = list(nn, a)
+ nn = append(nn, a)
goto ret
}
// normal case -- make a slice of all
// remaining arguments and pass it to
// the ddd parameter.
- nn = mkdotargslice(lrit.Seq(), nn, l, fp, init, call.Right)
+ nn = mkdotargslice(lr, nn, l, fp, init, call.Right)
goto ret
}
a = Nod(OAS, nodarg(l, fp), r)
a = convas(a, init)
- nn = list(nn, a)
+ nn = append(nn, a)
l = structnext(&savel)
r = nil
- lrit.Next()
- if !lrit.Done() {
- r = lrit.N()
+ lr = lr[1:]
+ if len(lr) > 0 {
+ r = lr[0]
}
goto loop
ret:
- for lrit = nodeSeqIterate(nn); !lrit.Done(); lrit.Next() {
- lrit.N().Typecheck = 1
+ for _, n := range nn {
+ n.Typecheck = 1
}
return nn
}
// if there is exactly one function expr,
// then it is done first. otherwise must
// make temp variables
-func reorder1(all *NodeList) *NodeList {
- var n *Node
-
+func reorder1(all []*Node) []*Node {
c := 0 // function calls
t := 0 // total parameters
- for l := all; l != nil; l = l.Next {
- n = l.N
+ for _, n := range all {
t++
ullmancalc(n)
if n.Ullman >= UINF {
return all
}
- var g *NodeList // fncalls assigned to tempnames
- var f *Node // last fncall assigned to stack
- var r *NodeList // non fncalls and tempnames assigned to stack
+ var g []*Node // fncalls assigned to tempnames
+ var f *Node // last fncall assigned to stack
+ var r []*Node // non fncalls and tempnames assigned to stack
d := 0
var a *Node
- for l := all; l != nil; l = l.Next {
- n = l.N
+ for _, n := range all {
if n.Ullman < UINF {
- r = list(r, n)
+ r = append(r, n)
continue
}
a = temp(n.Right.Type)
a = Nod(OAS, a, n.Right)
- g = list(g, a)
+ g = append(g, a)
// put normal arg assignment on list
// with fncall replaced by tempname
n.Right = a.Left
- r = list(r, n)
+ r = append(r, n)
}
if f != nil {
- g = list(g, f)
+ g = append(g, f)
}
- return concat(g, r)
+ return append(g, r...)
}
// from ascompat[ee]
Curfn.Func.Fieldtrack = append(Curfn.Func.Fieldtrack, field)
}
-func candiscardlist(l nodesOrNodeList) bool {
+func candiscardlist(l Nodes) bool {
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
if !candiscard(it.N()) {
return false
funcbody(fn)
typecheck(&fn, Etop)
- typechecklist(fn.Nbody, Etop)
+ typechecklist(fn.Nbody.Slice(), Etop)
xtop = list(xtop, fn)
Curfn = oldfn