Commit 2aa2da29 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/compile: convert dcl.go to nodeSeq

Add new functions setNodeSeqNode, appendNodeSeq, appendNodeSeqNode.

Passes toolstash -cmp.

Change-Id: I6c1745b1108dea45a2c0d029b9de1917ae17a962
Reviewed-on: https://go-review.googlesource.com/20196
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 867910ea
...@@ -227,8 +227,8 @@ func variter(vl *NodeList, t *Node, el *NodeList) *NodeList { ...@@ -227,8 +227,8 @@ func variter(vl *NodeList, t *Node, el *NodeList) *NodeList {
if count(el) == 1 && count(vl) > 1 { if count(el) == 1 && count(vl) > 1 {
e := el.N e := el.N
as2 := Nod(OAS2, nil, nil) as2 := Nod(OAS2, nil, nil)
as2.List = vl setNodeSeq(&as2.List, vl)
as2.Rlist = list1(e) setNodeSeqNode(&as2.Rlist, e)
var v *Node var v *Node
for ; vl != nil; vl = vl.Next { for ; vl != nil; vl = vl.Next {
v = vl.N v = vl.N
...@@ -474,7 +474,7 @@ func colasdefn(left *NodeList, defn *Node) { ...@@ -474,7 +474,7 @@ func colasdefn(left *NodeList, defn *Node) {
n = newname(n.Sym) n = newname(n.Sym)
declare(n, dclcontext) declare(n, dclcontext)
n.Name.Defn = defn n.Name.Defn = defn
defn.Ninit = list(defn.Ninit, Nod(ODCL, n, nil)) appendNodeSeqNode(&defn.Ninit, Nod(ODCL, n, nil))
l.N = n l.N = n
} }
...@@ -485,18 +485,18 @@ func colasdefn(left *NodeList, defn *Node) { ...@@ -485,18 +485,18 @@ func colasdefn(left *NodeList, defn *Node) {
func colas(left *NodeList, right *NodeList, lno int32) *Node { func colas(left *NodeList, right *NodeList, lno int32) *Node {
as := Nod(OAS2, nil, nil) as := Nod(OAS2, nil, nil)
as.List = left setNodeSeq(&as.List, left)
as.Rlist = right setNodeSeq(&as.Rlist, right)
as.Colas = true as.Colas = true
as.Lineno = lno as.Lineno = lno
colasdefn(left, as) colasdefn(left, as)
// make the tree prettier; not necessary // make the tree prettier; not necessary
if count(left) == 1 && count(right) == 1 { if count(left) == 1 && count(right) == 1 {
as.Left = as.List.N as.Left = nodeSeqFirst(as.List)
as.Right = as.Rlist.N as.Right = nodeSeqFirst(as.Rlist)
as.List = nil setNodeSeq(&as.List, nil)
as.Rlist = nil setNodeSeq(&as.Rlist, nil)
as.Op = OAS as.Op = OAS
} }
...@@ -570,7 +570,7 @@ func funcargs(nt *Node) { ...@@ -570,7 +570,7 @@ func funcargs(nt *Node) {
// re-start the variable generation number // re-start the variable generation number
// we want to use small numbers for the return variables, // we want to use small numbers for the return variables,
// so let them have the chunk starting at 1. // so let them have the chunk starting at 1.
vargen = count(nt.Rlist) vargen = nodeSeqLen(nt.Rlist)
// declare the receiver and in arguments. // declare the receiver and in arguments.
// no n->defn because type checking of func header // no n->defn because type checking of func header
...@@ -592,8 +592,8 @@ func funcargs(nt *Node) { ...@@ -592,8 +592,8 @@ func funcargs(nt *Node) {
} }
var n *Node var n *Node
for l := nt.List; l != nil; l = l.Next { for it := nodeSeqIterate(nt.List); !it.Done(); it.Next() {
n = l.N n = it.N()
if n.Op != ODCLFIELD { if n.Op != ODCLFIELD {
Fatalf("funcargs in %v", Oconv(int(n.Op), 0)) Fatalf("funcargs in %v", Oconv(int(n.Op), 0))
} }
...@@ -609,11 +609,11 @@ func funcargs(nt *Node) { ...@@ -609,11 +609,11 @@ func funcargs(nt *Node) {
} }
// declare the out arguments. // declare the out arguments.
gen := count(nt.List) gen := nodeSeqLen(nt.List)
var i int = 0 var i int = 0
var nn *Node var nn *Node
for l := nt.Rlist; l != nil; l = l.Next { for it := nodeSeqIterate(nt.Rlist); !it.Done(); it.Next() {
n = l.N n = it.N()
if n.Op != ODCLFIELD { if n.Op != ODCLFIELD {
Fatalf("funcargs out %v", Oconv(int(n.Op), 0)) Fatalf("funcargs out %v", Oconv(int(n.Op), 0))
...@@ -1507,7 +1507,7 @@ func checknowritebarrierrec() { ...@@ -1507,7 +1507,7 @@ func checknowritebarrierrec() {
for _, n := range list { for _, n := range list {
if n.Func.WBLineno == 0 { if n.Func.WBLineno == 0 {
c.curfn = n c.curfn = n
c.visitcodeslice(n.Nbody.Slice()) c.visitcodelist(n.Nbody)
} }
} }
if c.stable { if c.stable {
...@@ -1538,15 +1538,9 @@ func checknowritebarrierrec() { ...@@ -1538,15 +1538,9 @@ func checknowritebarrierrec() {
}) })
} }
func (c *nowritebarrierrecChecker) visitcodelist(l *NodeList) { func (c *nowritebarrierrecChecker) visitcodelist(l nodesOrNodeList) {
for ; l != nil; l = l.Next { for it := nodeSeqIterate(l); !it.Done(); it.Next() {
c.visitcode(l.N) c.visitcode(it.N())
}
}
func (c *nowritebarrierrecChecker) visitcodeslice(l []*Node) {
for _, n := range l {
c.visitcode(n)
} }
} }
...@@ -1563,7 +1557,7 @@ func (c *nowritebarrierrecChecker) visitcode(n *Node) { ...@@ -1563,7 +1557,7 @@ func (c *nowritebarrierrecChecker) visitcode(n *Node) {
c.visitcode(n.Left) c.visitcode(n.Left)
c.visitcode(n.Right) c.visitcode(n.Right)
c.visitcodelist(n.List) c.visitcodelist(n.List)
c.visitcodeslice(n.Nbody.Slice()) c.visitcodelist(n.Nbody)
c.visitcodelist(n.Rlist) c.visitcodelist(n.Rlist)
} }
......
...@@ -657,7 +657,7 @@ func setNodeSeq(a nodesOrNodeListPtr, b nodesOrNodeList) { ...@@ -657,7 +657,7 @@ func setNodeSeq(a nodesOrNodeListPtr, b nodesOrNodeList) {
return return
} }
// Simplify b to either *Nodelist or []*Node. // Simplify b to either *NodeList or []*Node.
if n, ok := b.(Nodes); ok { if n, ok := b.(Nodes); ok {
b = n.Slice() b = n.Slice()
} }
...@@ -698,3 +698,110 @@ func setNodeSeq(a nodesOrNodeListPtr, b nodesOrNodeList) { ...@@ -698,3 +698,110 @@ func setNodeSeq(a nodesOrNodeListPtr, b nodesOrNodeList) {
} }
} }
} }
// setNodeSeqNode sets the node sequence a to the node n.
// a must have type **NodeList, *Nodes, or *[]*Node.
// This is an interim function during the transition from NodeList to Nodes.
// TODO(iant): Remove when transition is complete.
func setNodeSeqNode(a nodesOrNodeListPtr, n *Node) {
// This is what the old list1 function did;
// the rest of the compiler has come to expect it.
if n.Op == OBLOCK && nodeSeqLen(n.Ninit) == 0 {
l := n.List
setNodeSeq(&n.List, nil)
setNodeSeq(a, l)
return
}
switch a := a.(type) {
case **NodeList:
*a = list1(n)
case *Nodes:
a.Set([]*Node{n})
case *[]*Node:
*a = []*Node{n}
default:
panic("can't happen")
}
}
// appendNodeSeq appends the node sequence b to the node sequence a.
// a must have type **NodeList, *Nodes, or *[]*Node.
// b must have type *NodeList, Nodes, or []*Node.
// This is an interim function during the transition from NodeList to Nodes.
// TODO(iant): Remove when transition is complete.
func appendNodeSeq(a nodesOrNodeListPtr, b nodesOrNodeList) {
// Simplify b to either *NodeList or []*Node.
if n, ok := b.(Nodes); ok {
b = n.Slice()
}
if l, ok := a.(**NodeList); ok {
switch b := b.(type) {
case *NodeList:
*l = concat(*l, b)
case []*Node:
for _, n := range b {
*l = list(*l, n)
}
default:
panic("can't happen")
}
} else {
var s []*Node
switch a := a.(type) {
case *Nodes:
s = a.Slice()
case *[]*Node:
s = *a
default:
panic("can't happen")
}
switch b := b.(type) {
case *NodeList:
for l := b; l != nil; l = l.Next {
s = append(s, l.N)
}
case []*Node:
s = append(s, b...)
default:
panic("can't happen")
}
switch a := a.(type) {
case *Nodes:
a.Set(s)
case *[]*Node:
*a = s
default:
panic("can't happen")
}
}
}
// appendNodeSeqNode appends n to the node sequence a.
// a must have type **NodeList, *Nodes, or *[]*Node.
// This is an interim function during the transition from NodeList to Nodes.
// TODO(iant): Remove when transition is complete.
func appendNodeSeqNode(a nodesOrNodeListPtr, n *Node) {
// This is what the old list1 function did;
// the rest of the compiler has come to expect it.
if n.Op == OBLOCK && nodeSeqLen(n.Ninit) == 0 {
l := n.List
setNodeSeq(&n.List, nil)
appendNodeSeq(a, l)
return
}
switch a := a.(type) {
case **NodeList:
*a = list(*a, n)
case *Nodes:
a.Append(n)
case *[]*Node:
*a = append(*a, n)
default:
panic("can't happen")
}
}
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