mirror of
https://github.com/golang/go
synced 2024-11-19 13:04:45 -07:00
cmd/compile: change parser, racewalk, range to use nodeSeq
Passes toolstash -cmp. Update #14473. Change-Id: I0809c6b88643f04c7fc503f866ffe25e69f29910 Reviewed-on: https://go-review.googlesource.com/20260 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
65c4b55aba
commit
72d90d8238
@ -606,7 +606,7 @@ func (p *parser) simple_stmt(labelOk, rangeOk bool) *Node {
|
|||||||
if rangeOk && p.got(LRANGE) {
|
if rangeOk && p.got(LRANGE) {
|
||||||
// expr_list '=' LRANGE expr
|
// expr_list '=' LRANGE expr
|
||||||
r := Nod(ORANGE, nil, p.expr())
|
r := Nod(ORANGE, nil, p.expr())
|
||||||
r.List = lhs
|
setNodeSeq(&r.List, lhs)
|
||||||
r.Etype = 0 // := flag
|
r.Etype = 0 // := flag
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@ -620,8 +620,8 @@ func (p *parser) simple_stmt(labelOk, rangeOk bool) *Node {
|
|||||||
}
|
}
|
||||||
// multiple
|
// multiple
|
||||||
stmt := Nod(OAS2, nil, nil)
|
stmt := Nod(OAS2, nil, nil)
|
||||||
stmt.List = lhs
|
setNodeSeq(&stmt.List, lhs)
|
||||||
stmt.Rlist = rhs
|
setNodeSeq(&stmt.Rlist, rhs)
|
||||||
return stmt
|
return stmt
|
||||||
|
|
||||||
case LCOLAS:
|
case LCOLAS:
|
||||||
@ -631,7 +631,7 @@ func (p *parser) simple_stmt(labelOk, rangeOk bool) *Node {
|
|||||||
if rangeOk && p.got(LRANGE) {
|
if rangeOk && p.got(LRANGE) {
|
||||||
// expr_list LCOLAS LRANGE expr
|
// expr_list LCOLAS LRANGE expr
|
||||||
r := Nod(ORANGE, nil, p.expr())
|
r := Nod(ORANGE, nil, p.expr())
|
||||||
r.List = lhs
|
setNodeSeq(&r.List, lhs)
|
||||||
r.Colas = true
|
r.Colas = true
|
||||||
colasdefn(lhs, r)
|
colasdefn(lhs, r)
|
||||||
return r
|
return r
|
||||||
@ -716,13 +716,13 @@ func (p *parser) case_(tswitch *Node) *Node {
|
|||||||
// done in casebody()
|
// done in casebody()
|
||||||
markdcl() // matching popdcl in caseblock
|
markdcl() // matching popdcl in caseblock
|
||||||
stmt := Nod(OXCASE, nil, nil)
|
stmt := Nod(OXCASE, nil, nil)
|
||||||
stmt.List = cases
|
setNodeSeq(&stmt.List, cases)
|
||||||
if tswitch != nil {
|
if tswitch != nil {
|
||||||
if n := tswitch.Left; n != nil {
|
if n := tswitch.Left; n != nil {
|
||||||
// type switch - declare variable
|
// type switch - declare variable
|
||||||
nn := newname(n.Sym)
|
nn := newname(n.Sym)
|
||||||
declare(nn, dclcontext)
|
declare(nn, dclcontext)
|
||||||
stmt.Rlist = list1(nn)
|
setNodeSeq(&stmt.Rlist, []*Node{nn})
|
||||||
|
|
||||||
// keep track of the instances for reporting unused
|
// keep track of the instances for reporting unused
|
||||||
nn.Name.Defn = tswitch
|
nn.Name.Defn = tswitch
|
||||||
@ -747,10 +747,10 @@ func (p *parser) case_(tswitch *Node) *Node {
|
|||||||
n = Nod(OAS, cases.N, rhs)
|
n = Nod(OAS, cases.N, rhs)
|
||||||
} else {
|
} else {
|
||||||
n = Nod(OAS2, nil, nil)
|
n = Nod(OAS2, nil, nil)
|
||||||
n.List = cases
|
setNodeSeq(&n.List, cases)
|
||||||
n.Rlist = list1(rhs)
|
setNodeSeq(&n.Rlist, []*Node{rhs})
|
||||||
}
|
}
|
||||||
stmt.List = list1(n)
|
setNodeSeq(&stmt.List, []*Node{n})
|
||||||
|
|
||||||
p.want(':') // consume ':' after declaring select cases for correct lineno
|
p.want(':') // consume ':' after declaring select cases for correct lineno
|
||||||
return stmt
|
return stmt
|
||||||
@ -766,7 +766,7 @@ func (p *parser) case_(tswitch *Node) *Node {
|
|||||||
// done in casebody()
|
// done in casebody()
|
||||||
markdcl() // matching popdcl in caseblock
|
markdcl() // matching popdcl in caseblock
|
||||||
stmt := Nod(OXCASE, nil, nil)
|
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
|
p.want(':') // consume ':' after declaring select cases for correct lineno
|
||||||
return stmt
|
return stmt
|
||||||
@ -790,7 +790,7 @@ func (p *parser) case_(tswitch *Node) *Node {
|
|||||||
// type switch - declare variable
|
// type switch - declare variable
|
||||||
nn := newname(n.Sym)
|
nn := newname(n.Sym)
|
||||||
declare(nn, dclcontext)
|
declare(nn, dclcontext)
|
||||||
stmt.Rlist = list1(nn)
|
setNodeSeq(&stmt.Rlist, []*Node{nn})
|
||||||
|
|
||||||
// keep track of the instances for reporting unused
|
// keep track of the instances for reporting unused
|
||||||
nn.Name.Defn = tswitch
|
nn.Name.Defn = tswitch
|
||||||
@ -914,7 +914,7 @@ func (p *parser) for_header() *Node {
|
|||||||
}
|
}
|
||||||
h := Nod(OFOR, nil, nil)
|
h := Nod(OFOR, nil, nil)
|
||||||
if init != nil {
|
if init != nil {
|
||||||
h.Ninit = list1(init)
|
setNodeSeq(&h.Ninit, []*Node{init})
|
||||||
}
|
}
|
||||||
h.Left = cond
|
h.Left = cond
|
||||||
h.Right = post
|
h.Right = post
|
||||||
@ -1017,7 +1017,7 @@ func (p *parser) if_header() *Node {
|
|||||||
|
|
||||||
init, cond, _ := p.header(false)
|
init, cond, _ := p.header(false)
|
||||||
h := Nod(OIF, nil, nil)
|
h := Nod(OIF, nil, nil)
|
||||||
h.Ninit = list1(init)
|
setNodeSeq(&h.Ninit, []*Node{init})
|
||||||
h.Left = cond
|
h.Left = cond
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
@ -1041,9 +1041,9 @@ func (p *parser) if_stmt() *Node {
|
|||||||
|
|
||||||
if p.got(LELSE) {
|
if p.got(LELSE) {
|
||||||
if p.tok == LIF {
|
if p.tok == LIF {
|
||||||
stmt.Rlist = list1(p.if_stmt())
|
setNodeSeq(&stmt.Rlist, []*Node{p.if_stmt()})
|
||||||
} else {
|
} else {
|
||||||
stmt.Rlist = list1(p.compound_stmt(true))
|
setNodeSeq(&stmt.Rlist, []*Node{p.compound_stmt(true)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1072,7 +1072,7 @@ func (p *parser) switch_stmt() *Node {
|
|||||||
tswitch = nil
|
tswitch = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
hdr.List = p.caseblock_list(tswitch)
|
setNodeSeq(&hdr.List, p.caseblock_list(tswitch))
|
||||||
popdcl()
|
popdcl()
|
||||||
|
|
||||||
return hdr
|
return hdr
|
||||||
@ -1086,7 +1086,7 @@ func (p *parser) select_stmt() *Node {
|
|||||||
|
|
||||||
p.want(LSELECT)
|
p.want(LSELECT)
|
||||||
hdr := Nod(OSELECT, nil, nil)
|
hdr := Nod(OSELECT, nil, nil)
|
||||||
hdr.List = p.caseblock_list(nil)
|
setNodeSeq(&hdr.List, p.caseblock_list(nil))
|
||||||
return hdr
|
return hdr
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1434,7 +1434,7 @@ loop:
|
|||||||
|
|
||||||
// call or conversion
|
// call or conversion
|
||||||
x = Nod(OCALL, x, nil)
|
x = Nod(OCALL, x, nil)
|
||||||
x.List = args
|
setNodeSeq(&x.List, args)
|
||||||
x.Isddd = ddd
|
x.Isddd = ddd
|
||||||
|
|
||||||
case '{':
|
case '{':
|
||||||
@ -1531,9 +1531,9 @@ func (p *parser) complitexpr() *Node {
|
|||||||
p.want('{')
|
p.want('{')
|
||||||
p.xnest++
|
p.xnest++
|
||||||
|
|
||||||
var l *NodeList
|
var l []*Node
|
||||||
for p.tok != EOF && p.tok != '}' {
|
for p.tok != EOF && p.tok != '}' {
|
||||||
l = list(l, p.keyval())
|
l = append(l, p.keyval())
|
||||||
if !p.ocomma('}') {
|
if !p.ocomma('}') {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -1542,7 +1542,7 @@ func (p *parser) complitexpr() *Node {
|
|||||||
p.xnest--
|
p.xnest--
|
||||||
p.want('}')
|
p.want('}')
|
||||||
|
|
||||||
n.List = l
|
setNodeSeq(&n.List, l)
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1684,8 +1684,8 @@ func (p *parser) try_ntype() *Node {
|
|||||||
result := p.fnres()
|
result := p.fnres()
|
||||||
params = checkarglist(params, 1)
|
params = checkarglist(params, 1)
|
||||||
t := Nod(OTFUNC, nil, nil)
|
t := Nod(OTFUNC, nil, nil)
|
||||||
t.List = params
|
setNodeSeq(&t.List, params)
|
||||||
t.Rlist = result
|
setNodeSeq(&t.Rlist, result)
|
||||||
return t
|
return t
|
||||||
|
|
||||||
case '[':
|
case '[':
|
||||||
@ -1809,7 +1809,7 @@ func (p *parser) structtype() *Node {
|
|||||||
p.want('}')
|
p.want('}')
|
||||||
|
|
||||||
t := Nod(OTSTRUCT, nil, nil)
|
t := Nod(OTSTRUCT, nil, nil)
|
||||||
t.List = l
|
setNodeSeq(&t.List, l)
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1821,9 +1821,9 @@ func (p *parser) interfacetype() *Node {
|
|||||||
|
|
||||||
p.want(LINTERFACE)
|
p.want(LINTERFACE)
|
||||||
p.want('{')
|
p.want('{')
|
||||||
var l *NodeList
|
var l []*Node
|
||||||
for p.tok != EOF && p.tok != '}' {
|
for p.tok != EOF && p.tok != '}' {
|
||||||
l = list(l, p.interfacedcl())
|
l = append(l, p.interfacedcl())
|
||||||
if !p.osemi('}') {
|
if !p.osemi('}') {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -1831,7 +1831,7 @@ func (p *parser) interfacetype() *Node {
|
|||||||
p.want('}')
|
p.want('}')
|
||||||
|
|
||||||
t := Nod(OTINTER, nil, nil)
|
t := Nod(OTINTER, nil, nil)
|
||||||
t.List = l
|
setNodeSeq(&t.List, l)
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1897,8 +1897,8 @@ func (p *parser) fndcl(nointerface bool) *Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := Nod(OTFUNC, nil, nil)
|
t := Nod(OTFUNC, nil, nil)
|
||||||
t.List = params
|
setNodeSeq(&t.List, params)
|
||||||
t.Rlist = result
|
setNodeSeq(&t.Rlist, result)
|
||||||
|
|
||||||
f := Nod(ODCLFUNC, nil, nil)
|
f := Nod(ODCLFUNC, nil, nil)
|
||||||
f.Func.Nname = newfuncname(name)
|
f.Func.Nname = newfuncname(name)
|
||||||
@ -1936,8 +1936,8 @@ func (p *parser) fndcl(nointerface bool) *Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := Nod(OTFUNC, rcvr, nil)
|
t := Nod(OTFUNC, rcvr, nil)
|
||||||
t.List = params
|
setNodeSeq(&t.List, params)
|
||||||
t.Rlist = result
|
setNodeSeq(&t.Rlist, result)
|
||||||
|
|
||||||
f := Nod(ODCLFUNC, nil, nil)
|
f := Nod(ODCLFUNC, nil, nil)
|
||||||
f.Func.Shortname = newfuncname(name)
|
f.Func.Shortname = newfuncname(name)
|
||||||
@ -2352,8 +2352,8 @@ func (p *parser) indcl() *Node {
|
|||||||
// without func keyword
|
// without func keyword
|
||||||
params = checkarglist(params, 1)
|
params = checkarglist(params, 1)
|
||||||
t := Nod(OTFUNC, fakethis(), nil)
|
t := Nod(OTFUNC, fakethis(), nil)
|
||||||
t.List = params
|
setNodeSeq(&t.List, params)
|
||||||
t.Rlist = result
|
setNodeSeq(&t.Rlist, result)
|
||||||
|
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
@ -2502,8 +2502,8 @@ func (p *parser) stmt() *Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stmt := Nod(ORETURN, nil, nil)
|
stmt := Nod(ORETURN, nil, nil)
|
||||||
stmt.List = results
|
setNodeSeq(&stmt.List, results)
|
||||||
if stmt.List == nil && Curfn != nil {
|
if nodeSeqLen(stmt.List) == 0 && Curfn != nil {
|
||||||
for _, ln := range Curfn.Func.Dcl {
|
for _, ln := range Curfn.Func.Dcl {
|
||||||
if ln.Class == PPARAM {
|
if ln.Class == PPARAM {
|
||||||
continue
|
continue
|
||||||
|
@ -55,10 +55,10 @@ func instrument(fn *Node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if flag_race == 0 || !ispkgin(norace_inst_pkgs) {
|
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
|
// nothing interesting for race detector in fn->enter
|
||||||
instrumentslice(fn.Func.Exit.Slice(), nil)
|
instrumentlist(fn.Func.Exit.Slice(), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if flag_race != 0 {
|
if flag_race != 0 {
|
||||||
@ -86,28 +86,16 @@ func instrument(fn *Node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func instrumentlist(l *NodeList, init **NodeList) {
|
func instrumentlist(l nodesOrNodeList, init nodesOrNodeListPtr) {
|
||||||
var instr *NodeList
|
var instr *NodeList
|
||||||
|
|
||||||
for ; l != nil; l = l.Next {
|
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
|
||||||
instr = nil
|
instr = nil
|
||||||
instrumentnode(&l.N, &instr, 0, 0)
|
instrumentnode(it.P(), &instr, 0, 0)
|
||||||
if init == nil {
|
if init == nil {
|
||||||
l.N.Ninit = concat(l.N.Ninit, instr)
|
appendNodeSeq(&it.N().Ninit, instr)
|
||||||
} else {
|
} else {
|
||||||
*init = concat(*init, instr)
|
appendNodeSeq(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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +103,7 @@ func instrumentslice(l []*Node, init **NodeList) {
|
|||||||
// walkexpr and walkstmt combined
|
// walkexpr and walkstmt combined
|
||||||
// walks the tree and adds calls to the
|
// walks the tree and adds calls to the
|
||||||
// instrumentation code to top-level (statement) nodes' init
|
// 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
|
n := *np
|
||||||
|
|
||||||
if n == nil {
|
if n == nil {
|
||||||
@ -135,7 +123,7 @@ func instrumentnode(np **Node, init **NodeList, wr int, skip int) {
|
|||||||
// nil it out and handle it separately before putting it back.
|
// nil it out and handle it separately before putting it back.
|
||||||
l := n.Ninit
|
l := n.Ninit
|
||||||
|
|
||||||
n.Ninit = nil
|
setNodeSeq(&n.Ninit, nil)
|
||||||
instrumentlist(l, nil)
|
instrumentlist(l, nil)
|
||||||
instrumentnode(&n, &l, wr, skip) // recurse with nil n->ninit
|
instrumentnode(&n, &l, wr, skip) // recurse with nil n->ninit
|
||||||
appendinit(&n, l)
|
appendinit(&n, l)
|
||||||
@ -159,27 +147,27 @@ func instrumentnode(np **Node, init **NodeList, wr int, skip int) {
|
|||||||
goto ret
|
goto ret
|
||||||
|
|
||||||
case OBLOCK:
|
case OBLOCK:
|
||||||
var out *NodeList
|
var out []*Node
|
||||||
for l := n.List; l != nil; l = l.Next {
|
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
|
||||||
switch l.N.Op {
|
switch it.N().Op {
|
||||||
case OCALLFUNC, OCALLMETH, OCALLINTER:
|
case OCALLFUNC, OCALLMETH, OCALLINTER:
|
||||||
instrumentnode(&l.N, &l.N.Ninit, 0, 0)
|
instrumentnode(it.P(), &it.N().Ninit, 0, 0)
|
||||||
out = list(out, l.N)
|
out = append(out, it.N())
|
||||||
// Scan past OAS nodes copying results off stack.
|
// Scan past OAS nodes copying results off stack.
|
||||||
// Those must not be instrumented, because the
|
// Those must not be instrumented, because the
|
||||||
// instrumentation calls will smash the results.
|
// instrumentation calls will smash the results.
|
||||||
// The assignments are to temporaries, so they cannot
|
// The assignments are to temporaries, so they cannot
|
||||||
// be involved in races and need not be instrumented.
|
// be involved in races and need not be instrumented.
|
||||||
for l.Next != nil && l.Next.N.Op == OAS && iscallret(l.Next.N.Right) {
|
for it.Len() > 1 && nodeSeqSecond(it.Seq()).Op == OAS && iscallret(nodeSeqSecond(it.Seq()).Right) {
|
||||||
l = l.Next
|
it.Next()
|
||||||
out = list(out, l.N)
|
out = append(out, it.N())
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
instrumentnode(&l.N, &out, 0, 0)
|
instrumentnode(it.P(), &out, 0, 0)
|
||||||
out = list(out, l.N)
|
out = append(out, it.N())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n.List = out
|
setNodeSeq(&n.List, out)
|
||||||
goto ret
|
goto ret
|
||||||
|
|
||||||
case ODEFER:
|
case ODEFER:
|
||||||
@ -439,7 +427,7 @@ ret:
|
|||||||
if n.Op != OBLOCK { // OBLOCK is handled above in a special way.
|
if n.Op != OBLOCK { // OBLOCK is handled above in a special way.
|
||||||
instrumentlist(n.List, init)
|
instrumentlist(n.List, init)
|
||||||
}
|
}
|
||||||
instrumentslice(n.Nbody.Slice(), nil)
|
instrumentlist(n.Nbody.Slice(), nil)
|
||||||
instrumentlist(n.Rlist, nil)
|
instrumentlist(n.Rlist, nil)
|
||||||
*np = n
|
*np = n
|
||||||
}
|
}
|
||||||
@ -472,7 +460,7 @@ func isartificial(n *Node) bool {
|
|||||||
return false
|
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
|
n := *np
|
||||||
|
|
||||||
//print("callinstr for %+N [ %O ] etype=%E class=%d\n",
|
//print("callinstr for %+N [ %O ] etype=%E class=%d\n",
|
||||||
@ -541,7 +529,7 @@ func callinstr(np **Node, init **NodeList, wr int, skip int) bool {
|
|||||||
f = mkcall(name, nil, init, uintptraddr(n))
|
f = mkcall(name, nil, init, uintptraddr(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
*init = list(*init, f)
|
appendNodeSeqNode(init, f)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -587,13 +575,13 @@ func uintptraddr(n *Node) *Node {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func detachexpr(n *Node, init **NodeList) *Node {
|
func detachexpr(n *Node, init nodesOrNodeListPtr) *Node {
|
||||||
addr := Nod(OADDR, n, nil)
|
addr := Nod(OADDR, n, nil)
|
||||||
l := temp(Ptrto(n.Type))
|
l := temp(Ptrto(n.Type))
|
||||||
as := Nod(OAS, l, addr)
|
as := Nod(OAS, l, addr)
|
||||||
typecheck(&as, Etop)
|
typecheck(&as, Etop)
|
||||||
walkexpr(&as, init)
|
walkexpr(&as, init)
|
||||||
*init = list(*init, as)
|
appendNodeSeqNode(init, as)
|
||||||
ind := Nod(OIND, l, nil)
|
ind := Nod(OIND, l, nil)
|
||||||
typecheck(&ind, Erv)
|
typecheck(&ind, Erv)
|
||||||
walkexpr(&ind, init)
|
walkexpr(&ind, init)
|
||||||
@ -606,15 +594,9 @@ func foreachnode(n *Node, f func(*Node, interface{}), c interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func foreachlist(l *NodeList, f func(*Node, interface{}), c interface{}) {
|
func foreachlist(l nodesOrNodeList, f func(*Node, interface{}), c interface{}) {
|
||||||
for ; l != nil; l = l.Next {
|
for it := nodeSeqIterate(l); !it.Done(); it.Next() {
|
||||||
foreachnode(l.N, f, c)
|
foreachnode(it.N(), f, c)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func foreachslice(l []*Node, f func(*Node, interface{}), c interface{}) {
|
|
||||||
for _, n := range l {
|
|
||||||
foreachnode(n, f, c)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -623,7 +605,7 @@ func foreach(n *Node, f func(*Node, interface{}), c interface{}) {
|
|||||||
foreachnode(n.Left, f, c)
|
foreachnode(n.Left, f, c)
|
||||||
foreachnode(n.Right, f, c)
|
foreachnode(n.Right, f, c)
|
||||||
foreachlist(n.List, f, c)
|
foreachlist(n.List, f, c)
|
||||||
foreachslice(n.Nbody.Slice(), f, c)
|
foreachlist(n.Nbody, f, c)
|
||||||
foreachlist(n.Rlist, f, c)
|
foreachlist(n.Rlist, f, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -636,8 +618,8 @@ func hascallspred(n *Node, c interface{}) {
|
|||||||
|
|
||||||
// appendinit is like addinit in subr.go
|
// appendinit is like addinit in subr.go
|
||||||
// but appends rather than prepends.
|
// but appends rather than prepends.
|
||||||
func appendinit(np **Node, init *NodeList) {
|
func appendinit(np **Node, init nodesOrNodeList) {
|
||||||
if init == nil {
|
if nodeSeqLen(init) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -653,6 +635,6 @@ func appendinit(np **Node, init *NodeList) {
|
|||||||
*np = n
|
*np = n
|
||||||
}
|
}
|
||||||
|
|
||||||
n.Ninit = concat(n.Ninit, init)
|
appendNodeSeq(&n.Ninit, init)
|
||||||
n.Ullman = UINF
|
n.Ullman = UINF
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,9 @@ func typecheckrange(n *Node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// delicate little dance. see typecheckas2
|
// delicate little dance. see typecheckas2
|
||||||
for ll := n.List; ll != nil; ll = ll.Next {
|
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
|
||||||
if ll.N.Name == nil || ll.N.Name.Defn != n {
|
if it.N().Name == nil || it.N().Name.Defn != n {
|
||||||
typecheck(&ll.N, Erv|Easgn)
|
typecheck(it.P(), Erv|Easgn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ func typecheckrange(n *Node) {
|
|||||||
|
|
||||||
t1 = t.Type
|
t1 = t.Type
|
||||||
t2 = nil
|
t2 = nil
|
||||||
if count(n.List) == 2 {
|
if nodeSeqLen(n.List) == 2 {
|
||||||
toomany = 1
|
toomany = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,17 +75,17 @@ func typecheckrange(n *Node) {
|
|||||||
t2 = runetype
|
t2 = runetype
|
||||||
}
|
}
|
||||||
|
|
||||||
if count(n.List) > 2 || toomany != 0 {
|
if nodeSeqLen(n.List) > 2 || toomany != 0 {
|
||||||
Yyerror("too many variables in range")
|
Yyerror("too many variables in range")
|
||||||
}
|
}
|
||||||
|
|
||||||
v1 = nil
|
v1 = nil
|
||||||
if n.List != nil {
|
if nodeSeqLen(n.List) != 0 {
|
||||||
v1 = n.List.N
|
v1 = nodeSeqFirst(n.List)
|
||||||
}
|
}
|
||||||
v2 = nil
|
v2 = nil
|
||||||
if n.List != nil && n.List.Next != nil {
|
if nodeSeqLen(n.List) > 1 {
|
||||||
v2 = n.List.Next.N
|
v2 = nodeSeqSecond(n.List)
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is not only a optimization but also a requirement in the spec.
|
// this is not only a optimization but also a requirement in the spec.
|
||||||
@ -94,7 +94,7 @@ func typecheckrange(n *Node) {
|
|||||||
// present."
|
// present."
|
||||||
if isblank(v2) {
|
if isblank(v2) {
|
||||||
if v1 != nil {
|
if v1 != nil {
|
||||||
n.List = list1(v1)
|
setNodeSeq(&n.List, []*Node{v1})
|
||||||
}
|
}
|
||||||
v2 = nil
|
v2 = nil
|
||||||
}
|
}
|
||||||
@ -121,9 +121,9 @@ func typecheckrange(n *Node) {
|
|||||||
out:
|
out:
|
||||||
n.Typecheck = 1
|
n.Typecheck = 1
|
||||||
|
|
||||||
for ll := n.List; ll != nil; ll = ll.Next {
|
for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
|
||||||
if ll.N.Typecheck == 0 {
|
if it.N().Typecheck == 0 {
|
||||||
typecheck(&ll.N, Erv|Easgn)
|
typecheck(it.P(), Erv|Easgn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,17 +147,17 @@ func walkrange(n *Node) {
|
|||||||
n.Right = nil
|
n.Right = nil
|
||||||
|
|
||||||
var v1 *Node
|
var v1 *Node
|
||||||
if n.List != nil {
|
if nodeSeqLen(n.List) != 0 {
|
||||||
v1 = n.List.N
|
v1 = nodeSeqFirst(n.List)
|
||||||
}
|
}
|
||||||
var v2 *Node
|
var v2 *Node
|
||||||
if n.List != nil && n.List.Next != nil && !isblank(n.List.Next.N) {
|
if nodeSeqLen(n.List) > 1 && !isblank(nodeSeqSecond(n.List)) {
|
||||||
v2 = n.List.Next.N
|
v2 = nodeSeqSecond(n.List)
|
||||||
}
|
}
|
||||||
|
|
||||||
// n->list has no meaning anymore, clear it
|
// n->list has no meaning anymore, clear it
|
||||||
// to avoid erroneous processing by racewalk.
|
// to avoid erroneous processing by racewalk.
|
||||||
n.List = nil
|
setNodeSeq(&n.List, nil)
|
||||||
|
|
||||||
var body []*Node
|
var body []*Node
|
||||||
var init *NodeList
|
var init *NodeList
|
||||||
@ -195,8 +195,8 @@ func walkrange(n *Node) {
|
|||||||
body = []*Node{Nod(OAS, v1, hv1)}
|
body = []*Node{Nod(OAS, v1, hv1)}
|
||||||
} else {
|
} else {
|
||||||
a := Nod(OAS2, nil, nil)
|
a := Nod(OAS2, nil, nil)
|
||||||
a.List = list(list1(v1), v2)
|
setNodeSeq(&a.List, []*Node{v1, v2})
|
||||||
a.Rlist = list(list1(hv1), Nod(OIND, hp, nil))
|
setNodeSeq(&a.Rlist, []*Node{hv1, Nod(OIND, hp, nil)})
|
||||||
body = []*Node{a}
|
body = []*Node{a}
|
||||||
|
|
||||||
// Advance pointer as part of increment.
|
// Advance pointer as part of increment.
|
||||||
@ -215,7 +215,7 @@ func walkrange(n *Node) {
|
|||||||
tmp.Right.Typecheck = 1
|
tmp.Right.Typecheck = 1
|
||||||
a = Nod(OAS, hp, tmp)
|
a = Nod(OAS, hp, tmp)
|
||||||
typecheck(&a, Etop)
|
typecheck(&a, Etop)
|
||||||
n.Right.Ninit = list1(a)
|
setNodeSeq(&n.Right.Ninit, []*Node{a})
|
||||||
}
|
}
|
||||||
|
|
||||||
// orderstmt allocated the iterator for us.
|
// orderstmt allocated the iterator for us.
|
||||||
@ -250,8 +250,8 @@ func walkrange(n *Node) {
|
|||||||
val := Nod(ODOT, hit, valname)
|
val := Nod(ODOT, hit, valname)
|
||||||
val = Nod(OIND, val, nil)
|
val = Nod(OIND, val, nil)
|
||||||
a := Nod(OAS2, nil, nil)
|
a := Nod(OAS2, nil, nil)
|
||||||
a.List = list(list1(v1), v2)
|
setNodeSeq(&a.List, []*Node{v1, v2})
|
||||||
a.Rlist = list(list1(key), val)
|
setNodeSeq(&a.Rlist, []*Node{key, val})
|
||||||
body = []*Node{a}
|
body = []*Node{a}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,9 +271,9 @@ func walkrange(n *Node) {
|
|||||||
n.Left = Nod(ONE, hb, Nodbool(false))
|
n.Left = Nod(ONE, hb, Nodbool(false))
|
||||||
a := Nod(OAS2RECV, nil, nil)
|
a := Nod(OAS2RECV, nil, nil)
|
||||||
a.Typecheck = 1
|
a.Typecheck = 1
|
||||||
a.List = list(list1(hv1), hb)
|
setNodeSeq(&a.List, []*Node{hv1, hb})
|
||||||
a.Rlist = list1(Nod(ORECV, ha, nil))
|
setNodeSeq(&a.Rlist, []*Node{Nod(ORECV, ha, nil)})
|
||||||
n.Left.Ninit = list1(a)
|
setNodeSeq(&n.Left.Ninit, []*Node{a})
|
||||||
if v1 == nil {
|
if v1 == nil {
|
||||||
body = nil
|
body = nil
|
||||||
} else {
|
} else {
|
||||||
@ -296,13 +296,13 @@ func walkrange(n *Node) {
|
|||||||
} else {
|
} else {
|
||||||
hv2 = temp(runetype)
|
hv2 = temp(runetype)
|
||||||
a = Nod(OAS2, nil, nil)
|
a = Nod(OAS2, nil, nil)
|
||||||
a.List = list(list1(hv1), hv2)
|
setNodeSeq(&a.List, []*Node{hv1, hv2})
|
||||||
fn := syslook("stringiter2")
|
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 = 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
|
body = nil
|
||||||
if v1 != nil {
|
if v1 != nil {
|
||||||
@ -315,7 +315,7 @@ func walkrange(n *Node) {
|
|||||||
|
|
||||||
n.Op = OFOR
|
n.Op = OFOR
|
||||||
typechecklist(init, Etop)
|
typechecklist(init, Etop)
|
||||||
n.Ninit = concat(n.Ninit, init)
|
appendNodeSeq(&n.Ninit, init)
|
||||||
typechecklist(n.Left.Ninit, Etop)
|
typechecklist(n.Left.Ninit, Etop)
|
||||||
typecheck(&n.Left, Erv)
|
typecheck(&n.Left, Erv)
|
||||||
typecheck(&n.Right, Etop)
|
typecheck(&n.Right, Etop)
|
||||||
|
Loading…
Reference in New Issue
Block a user