Passes toolstash -cmp.
Update #14473.
Change-Id: I0809c6b88643f04c7fc503f866ffe25e69f29910
Reviewed-on: https://go-review.googlesource.com/20260
Reviewed-by: David Crawshaw <crawshaw@golang.org>
if rangeOk && p.got(LRANGE) {
// expr_list '=' LRANGE expr
r := Nod(ORANGE, nil, p.expr())
- r.List = lhs
+ setNodeSeq(&r.List, lhs)
r.Etype = 0 // := flag
return r
}
}
// multiple
stmt := Nod(OAS2, nil, nil)
- stmt.List = lhs
- stmt.Rlist = rhs
+ setNodeSeq(&stmt.List, lhs)
+ setNodeSeq(&stmt.Rlist, rhs)
return stmt
case LCOLAS:
if rangeOk && p.got(LRANGE) {
// expr_list LCOLAS LRANGE expr
r := Nod(ORANGE, nil, p.expr())
- r.List = lhs
+ setNodeSeq(&r.List, lhs)
r.Colas = true
colasdefn(lhs, r)
return r
// done in casebody()
markdcl() // matching popdcl in caseblock
stmt := Nod(OXCASE, nil, nil)
- stmt.List = cases
+ setNodeSeq(&stmt.List, cases)
if tswitch != nil {
if n := tswitch.Left; n != nil {
// type switch - declare variable
nn := newname(n.Sym)
declare(nn, dclcontext)
- stmt.Rlist = list1(nn)
+ setNodeSeq(&stmt.Rlist, []*Node{nn})
// keep track of the instances for reporting unused
nn.Name.Defn = tswitch
n = Nod(OAS, cases.N, rhs)
} else {
n = Nod(OAS2, nil, nil)
- n.List = cases
- n.Rlist = list1(rhs)
+ setNodeSeq(&n.List, cases)
+ setNodeSeq(&n.Rlist, []*Node{rhs})
}
- stmt.List = list1(n)
+ setNodeSeq(&stmt.List, []*Node{n})
p.want(':') // consume ':' after declaring select cases for correct lineno
return stmt
// done in casebody()
markdcl() // matching popdcl in caseblock
stmt := Nod(OXCASE, nil, nil)
- stmt.List = list1(colas(cases, list1(rhs), lno))
+ setNodeSeq(&stmt.List, []*Node{colas(cases, list1(rhs), lno)})
p.want(':') // consume ':' after declaring select cases for correct lineno
return stmt
// type switch - declare variable
nn := newname(n.Sym)
declare(nn, dclcontext)
- stmt.Rlist = list1(nn)
+ setNodeSeq(&stmt.Rlist, []*Node{nn})
// keep track of the instances for reporting unused
nn.Name.Defn = tswitch
}
h := Nod(OFOR, nil, nil)
if init != nil {
- h.Ninit = list1(init)
+ setNodeSeq(&h.Ninit, []*Node{init})
}
h.Left = cond
h.Right = post
init, cond, _ := p.header(false)
h := Nod(OIF, nil, nil)
- h.Ninit = list1(init)
+ setNodeSeq(&h.Ninit, []*Node{init})
h.Left = cond
return h
}
if p.got(LELSE) {
if p.tok == LIF {
- stmt.Rlist = list1(p.if_stmt())
+ setNodeSeq(&stmt.Rlist, []*Node{p.if_stmt()})
} else {
- stmt.Rlist = list1(p.compound_stmt(true))
+ setNodeSeq(&stmt.Rlist, []*Node{p.compound_stmt(true)})
}
}
tswitch = nil
}
- hdr.List = p.caseblock_list(tswitch)
+ setNodeSeq(&hdr.List, p.caseblock_list(tswitch))
popdcl()
return hdr
p.want(LSELECT)
hdr := Nod(OSELECT, nil, nil)
- hdr.List = p.caseblock_list(nil)
+ setNodeSeq(&hdr.List, p.caseblock_list(nil))
return hdr
}
// call or conversion
x = Nod(OCALL, x, nil)
- x.List = args
+ setNodeSeq(&x.List, args)
x.Isddd = ddd
case '{':
p.want('{')
p.xnest++
- var l *NodeList
+ var l []*Node
for p.tok != EOF && p.tok != '}' {
- l = list(l, p.keyval())
+ l = append(l, p.keyval())
if !p.ocomma('}') {
break
}
p.xnest--
p.want('}')
- n.List = l
+ setNodeSeq(&n.List, l)
return n
}
result := p.fnres()
params = checkarglist(params, 1)
t := Nod(OTFUNC, nil, nil)
- t.List = params
- t.Rlist = result
+ setNodeSeq(&t.List, params)
+ setNodeSeq(&t.Rlist, result)
return t
case '[':
p.want('}')
t := Nod(OTSTRUCT, nil, nil)
- t.List = l
+ setNodeSeq(&t.List, l)
return t
}
p.want(LINTERFACE)
p.want('{')
- var l *NodeList
+ var l []*Node
for p.tok != EOF && p.tok != '}' {
- l = list(l, p.interfacedcl())
+ l = append(l, p.interfacedcl())
if !p.osemi('}') {
break
}
p.want('}')
t := Nod(OTINTER, nil, nil)
- t.List = l
+ setNodeSeq(&t.List, l)
return t
}
}
t := Nod(OTFUNC, nil, nil)
- t.List = params
- t.Rlist = result
+ setNodeSeq(&t.List, params)
+ setNodeSeq(&t.Rlist, result)
f := Nod(ODCLFUNC, nil, nil)
f.Func.Nname = newfuncname(name)
}
t := Nod(OTFUNC, rcvr, nil)
- t.List = params
- t.Rlist = result
+ setNodeSeq(&t.List, params)
+ setNodeSeq(&t.Rlist, result)
f := Nod(ODCLFUNC, nil, nil)
f.Func.Shortname = newfuncname(name)
// without func keyword
params = checkarglist(params, 1)
t := Nod(OTFUNC, fakethis(), nil)
- t.List = params
- t.Rlist = result
+ setNodeSeq(&t.List, params)
+ setNodeSeq(&t.Rlist, result)
return t
}
}
stmt := Nod(ORETURN, nil, nil)
- stmt.List = results
- if stmt.List == nil && Curfn != nil {
+ setNodeSeq(&stmt.List, results)
+ if nodeSeqLen(stmt.List) == 0 && Curfn != nil {
for _, ln := range Curfn.Func.Dcl {
if ln.Class == PPARAM {
continue
}
if flag_race == 0 || !ispkgin(norace_inst_pkgs) {
- instrumentslice(fn.Nbody.Slice(), nil)
+ instrumentlist(fn.Nbody.Slice(), nil)
// nothing interesting for race detector in fn->enter
- instrumentslice(fn.Func.Exit.Slice(), nil)
+ instrumentlist(fn.Func.Exit.Slice(), nil)
}
if flag_race != 0 {
}
}
-func instrumentlist(l *NodeList, init **NodeList) {
+func instrumentlist(l nodesOrNodeList, init nodesOrNodeListPtr) {
var instr *NodeList
- for ; l != nil; l = l.Next {
+ for it := nodeSeqIterate(l); !it.Done(); it.Next() {
instr = nil
- instrumentnode(&l.N, &instr, 0, 0)
+ instrumentnode(it.P(), &instr, 0, 0)
if init == nil {
- l.N.Ninit = concat(l.N.Ninit, instr)
+ appendNodeSeq(&it.N().Ninit, instr)
} else {
- *init = concat(*init, instr)
- }
- }
-}
-
-func instrumentslice(l []*Node, init **NodeList) {
- for i := range l {
- var instr *NodeList
- instrumentnode(&l[i], &instr, 0, 0)
- if init == nil {
- l[i].Ninit = concat(l[i].Ninit, instr)
- } else {
- *init = concat(*init, instr)
+ appendNodeSeq(init, instr)
}
}
}
// 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 **NodeList, wr int, skip int) {
+func instrumentnode(np **Node, init nodesOrNodeListPtr, wr int, skip int) {
n := *np
if n == nil {
// nil it out and handle it separately before putting it back.
l := n.Ninit
- n.Ninit = nil
+ setNodeSeq(&n.Ninit, nil)
instrumentlist(l, nil)
instrumentnode(&n, &l, wr, skip) // recurse with nil n->ninit
appendinit(&n, l)
goto ret
case OBLOCK:
- var out *NodeList
- for l := n.List; l != nil; l = l.Next {
- switch l.N.Op {
+ var out []*Node
+ for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
+ switch it.N().Op {
case OCALLFUNC, OCALLMETH, OCALLINTER:
- instrumentnode(&l.N, &l.N.Ninit, 0, 0)
- out = list(out, l.N)
+ instrumentnode(it.P(), &it.N().Ninit, 0, 0)
+ out = append(out, it.N())
// Scan past OAS nodes copying results off stack.
// Those must not be instrumented, because the
// instrumentation calls will smash the results.
// The assignments are to temporaries, so they cannot
// be involved in races and need not be instrumented.
- for l.Next != nil && l.Next.N.Op == OAS && iscallret(l.Next.N.Right) {
- l = l.Next
- out = list(out, l.N)
+ for it.Len() > 1 && nodeSeqSecond(it.Seq()).Op == OAS && iscallret(nodeSeqSecond(it.Seq()).Right) {
+ it.Next()
+ out = append(out, it.N())
}
default:
- instrumentnode(&l.N, &out, 0, 0)
- out = list(out, l.N)
+ instrumentnode(it.P(), &out, 0, 0)
+ out = append(out, it.N())
}
}
- n.List = out
+ setNodeSeq(&n.List, out)
goto ret
case ODEFER:
if n.Op != OBLOCK { // OBLOCK is handled above in a special way.
instrumentlist(n.List, init)
}
- instrumentslice(n.Nbody.Slice(), nil)
+ instrumentlist(n.Nbody.Slice(), nil)
instrumentlist(n.Rlist, nil)
*np = n
}
return false
}
-func callinstr(np **Node, init **NodeList, wr int, skip int) bool {
+func callinstr(np **Node, init nodesOrNodeListPtr, wr int, skip int) bool {
n := *np
//print("callinstr for %+N [ %O ] etype=%E class=%d\n",
f = mkcall(name, nil, init, uintptraddr(n))
}
- *init = list(*init, f)
+ appendNodeSeqNode(init, f)
return true
}
return r
}
-func detachexpr(n *Node, init **NodeList) *Node {
+func detachexpr(n *Node, init nodesOrNodeListPtr) *Node {
addr := Nod(OADDR, n, nil)
l := temp(Ptrto(n.Type))
as := Nod(OAS, l, addr)
typecheck(&as, Etop)
walkexpr(&as, init)
- *init = list(*init, as)
+ appendNodeSeqNode(init, as)
ind := Nod(OIND, l, nil)
typecheck(&ind, Erv)
walkexpr(&ind, init)
}
}
-func foreachlist(l *NodeList, f func(*Node, interface{}), c interface{}) {
- for ; l != nil; l = l.Next {
- foreachnode(l.N, f, c)
- }
-}
-
-func foreachslice(l []*Node, f func(*Node, interface{}), c interface{}) {
- for _, n := range l {
- foreachnode(n, f, c)
+func foreachlist(l nodesOrNodeList, f func(*Node, interface{}), c interface{}) {
+ for it := nodeSeqIterate(l); !it.Done(); it.Next() {
+ foreachnode(it.N(), f, c)
}
}
foreachnode(n.Left, f, c)
foreachnode(n.Right, f, c)
foreachlist(n.List, f, c)
- foreachslice(n.Nbody.Slice(), f, c)
+ foreachlist(n.Nbody, f, c)
foreachlist(n.Rlist, f, c)
}
// appendinit is like addinit in subr.go
// but appends rather than prepends.
-func appendinit(np **Node, init *NodeList) {
- if init == nil {
+func appendinit(np **Node, init nodesOrNodeList) {
+ if nodeSeqLen(init) == 0 {
return
}
*np = n
}
- n.Ninit = concat(n.Ninit, init)
+ appendNodeSeq(&n.Ninit, init)
n.Ullman = UINF
}
}
// delicate little dance. see typecheckas2
- for ll := n.List; ll != nil; ll = ll.Next {
- if ll.N.Name == nil || ll.N.Name.Defn != n {
- typecheck(&ll.N, Erv|Easgn)
+ for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
+ if it.N().Name == nil || it.N().Name.Defn != n {
+ typecheck(it.P(), Erv|Easgn)
}
}
t1 = t.Type
t2 = nil
- if count(n.List) == 2 {
+ if nodeSeqLen(n.List) == 2 {
toomany = 1
}
t2 = runetype
}
- if count(n.List) > 2 || toomany != 0 {
+ if nodeSeqLen(n.List) > 2 || toomany != 0 {
Yyerror("too many variables in range")
}
v1 = nil
- if n.List != nil {
- v1 = n.List.N
+ if nodeSeqLen(n.List) != 0 {
+ v1 = nodeSeqFirst(n.List)
}
v2 = nil
- if n.List != nil && n.List.Next != nil {
- v2 = n.List.Next.N
+ if nodeSeqLen(n.List) > 1 {
+ v2 = nodeSeqSecond(n.List)
}
// this is not only a optimization but also a requirement in the spec.
// present."
if isblank(v2) {
if v1 != nil {
- n.List = list1(v1)
+ setNodeSeq(&n.List, []*Node{v1})
}
v2 = nil
}
out:
n.Typecheck = 1
- for ll := n.List; ll != nil; ll = ll.Next {
- if ll.N.Typecheck == 0 {
- typecheck(&ll.N, Erv|Easgn)
+ for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
+ if it.N().Typecheck == 0 {
+ typecheck(it.P(), Erv|Easgn)
}
}
n.Right = nil
var v1 *Node
- if n.List != nil {
- v1 = n.List.N
+ if nodeSeqLen(n.List) != 0 {
+ v1 = nodeSeqFirst(n.List)
}
var v2 *Node
- if n.List != nil && n.List.Next != nil && !isblank(n.List.Next.N) {
- v2 = n.List.Next.N
+ if nodeSeqLen(n.List) > 1 && !isblank(nodeSeqSecond(n.List)) {
+ v2 = nodeSeqSecond(n.List)
}
// n->list has no meaning anymore, clear it
// to avoid erroneous processing by racewalk.
- n.List = nil
+ setNodeSeq(&n.List, nil)
var body []*Node
var init *NodeList
body = []*Node{Nod(OAS, v1, hv1)}
} else {
a := Nod(OAS2, nil, nil)
- a.List = list(list1(v1), v2)
- a.Rlist = list(list1(hv1), Nod(OIND, hp, nil))
+ setNodeSeq(&a.List, []*Node{v1, v2})
+ setNodeSeq(&a.Rlist, []*Node{hv1, Nod(OIND, hp, nil)})
body = []*Node{a}
// Advance pointer as part of increment.
tmp.Right.Typecheck = 1
a = Nod(OAS, hp, tmp)
typecheck(&a, Etop)
- n.Right.Ninit = list1(a)
+ setNodeSeq(&n.Right.Ninit, []*Node{a})
}
// orderstmt allocated the iterator for us.
val := Nod(ODOT, hit, valname)
val = Nod(OIND, val, nil)
a := Nod(OAS2, nil, nil)
- a.List = list(list1(v1), v2)
- a.Rlist = list(list1(key), val)
+ setNodeSeq(&a.List, []*Node{v1, v2})
+ setNodeSeq(&a.Rlist, []*Node{key, val})
body = []*Node{a}
}
n.Left = Nod(ONE, hb, Nodbool(false))
a := Nod(OAS2RECV, nil, nil)
a.Typecheck = 1
- a.List = list(list1(hv1), hb)
- a.Rlist = list1(Nod(ORECV, ha, nil))
- n.Left.Ninit = list1(a)
+ setNodeSeq(&a.List, []*Node{hv1, hb})
+ setNodeSeq(&a.Rlist, []*Node{Nod(ORECV, ha, nil)})
+ setNodeSeq(&n.Left.Ninit, []*Node{a})
if v1 == nil {
body = nil
} else {
} else {
hv2 = temp(runetype)
a = Nod(OAS2, nil, nil)
- a.List = list(list1(hv1), hv2)
+ setNodeSeq(&a.List, []*Node{hv1, hv2})
fn := syslook("stringiter2")
- a.Rlist = list1(mkcall1(fn, getoutargx(fn.Type), nil, ha, hv1))
+ setNodeSeq(&a.Rlist, []*Node{mkcall1(fn, getoutargx(fn.Type), nil, ha, hv1)})
}
n.Left = Nod(ONE, hv1, Nodintconst(0))
- n.Left.Ninit = list(list1(Nod(OAS, ohv1, hv1)), a)
+ setNodeSeq(&n.Left.Ninit, []*Node{Nod(OAS, ohv1, hv1), a})
body = nil
if v1 != nil {
n.Op = OFOR
typechecklist(init, Etop)
- n.Ninit = concat(n.Ninit, init)
+ appendNodeSeq(&n.Ninit, init)
typechecklist(n.Left.Ninit, Etop)
typecheck(&n.Left, Erv)
typecheck(&n.Right, Etop)