if count(el) == 1 && count(vl) > 1 {
e := el.N
as2 := Nod(OAS2, nil, nil)
- as2.List = vl
- as2.Rlist = list1(e)
+ setNodeSeq(&as2.List, vl)
+ setNodeSeqNode(&as2.Rlist, e)
var v *Node
for ; vl != nil; vl = vl.Next {
v = vl.N
n = newname(n.Sym)
declare(n, dclcontext)
n.Name.Defn = defn
- defn.Ninit = list(defn.Ninit, Nod(ODCL, n, nil))
+ appendNodeSeqNode(&defn.Ninit, Nod(ODCL, n, nil))
l.N = n
}
func colas(left *NodeList, right *NodeList, lno int32) *Node {
as := Nod(OAS2, nil, nil)
- as.List = left
- as.Rlist = right
+ setNodeSeq(&as.List, left)
+ setNodeSeq(&as.Rlist, right)
as.Colas = true
as.Lineno = lno
colasdefn(left, as)
// make the tree prettier; not necessary
if count(left) == 1 && count(right) == 1 {
- as.Left = as.List.N
- as.Right = as.Rlist.N
- as.List = nil
- as.Rlist = nil
+ as.Left = nodeSeqFirst(as.List)
+ as.Right = nodeSeqFirst(as.Rlist)
+ setNodeSeq(&as.List, nil)
+ setNodeSeq(&as.Rlist, nil)
as.Op = OAS
}
// 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 = count(nt.Rlist)
+ vargen = nodeSeqLen(nt.Rlist)
// declare the receiver and in arguments.
// no n->defn because type checking of func header
}
var n *Node
- for l := nt.List; l != nil; l = l.Next {
- n = l.N
+ for it := nodeSeqIterate(nt.List); !it.Done(); it.Next() {
+ n = it.N()
if n.Op != ODCLFIELD {
Fatalf("funcargs in %v", Oconv(int(n.Op), 0))
}
}
// declare the out arguments.
- gen := count(nt.List)
+ gen := nodeSeqLen(nt.List)
var i int = 0
var nn *Node
- for l := nt.Rlist; l != nil; l = l.Next {
- n = l.N
+ for it := nodeSeqIterate(nt.Rlist); !it.Done(); it.Next() {
+ n = it.N()
if n.Op != ODCLFIELD {
Fatalf("funcargs out %v", Oconv(int(n.Op), 0))
for _, n := range list {
if n.Func.WBLineno == 0 {
c.curfn = n
- c.visitcodeslice(n.Nbody.Slice())
+ c.visitcodelist(n.Nbody)
}
}
if c.stable {
})
}
-func (c *nowritebarrierrecChecker) visitcodelist(l *NodeList) {
- for ; l != nil; l = l.Next {
- c.visitcode(l.N)
- }
-}
-
-func (c *nowritebarrierrecChecker) visitcodeslice(l []*Node) {
- for _, n := range l {
- c.visitcode(n)
+func (c *nowritebarrierrecChecker) visitcodelist(l nodesOrNodeList) {
+ for it := nodeSeqIterate(l); !it.Done(); it.Next() {
+ c.visitcode(it.N())
}
}
c.visitcode(n.Left)
c.visitcode(n.Right)
c.visitcodelist(n.List)
- c.visitcodeslice(n.Nbody.Slice())
+ c.visitcodelist(n.Nbody)
c.visitcodelist(n.Rlist)
}
return
}
- // Simplify b to either *Nodelist or []*Node.
+ // Simplify b to either *NodeList or []*Node.
if n, ok := b.(Nodes); ok {
b = n.Slice()
}
}
}
}
+
+// 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")
+ }
+}