mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: remove all remaining nodeSeq code
Passes toolstash -cmp. Update #14473. Change-Id: I2ac5c595d7af7a8da1a7e3945e6a753299446250 Reviewed-on: https://go-review.googlesource.com/20497 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
53900cea1b
commit
f444b8a80e
16 changed files with 283 additions and 547 deletions
|
|
@ -455,21 +455,6 @@ func (n *Nodes) Second() *Node {
|
|||
return (*n.slice)[1]
|
||||
}
|
||||
|
||||
// NodeList returns the entries in Nodes as a NodeList.
|
||||
// Changes to the NodeList entries (as in l.N = n) will *not* be
|
||||
// reflected in the Nodes.
|
||||
// This wastes memory and should be used as little as possible.
|
||||
func (n *Nodes) NodeList() *NodeList {
|
||||
if n.slice == nil {
|
||||
return nil
|
||||
}
|
||||
var ret *NodeList
|
||||
for _, n := range *n.slice {
|
||||
ret = list(ret, n)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Set sets n to a slice.
|
||||
// This takes ownership of the slice.
|
||||
func (n *Nodes) Set(s []*Node) {
|
||||
|
|
@ -521,253 +506,3 @@ func (n *Nodes) AppendNodes(n2 *Nodes) {
|
|||
}
|
||||
n2.slice = nil
|
||||
}
|
||||
|
||||
// SetToNodeList sets Nodes to the contents of a NodeList.
|
||||
func (n *Nodes) SetToNodeList(l *NodeList) {
|
||||
s := make([]*Node, 0, count(l))
|
||||
for ; l != nil; l = l.Next {
|
||||
s = append(s, l.N)
|
||||
}
|
||||
n.Set(s)
|
||||
}
|
||||
|
||||
// AppendNodeList appends the contents of a NodeList.
|
||||
func (n *Nodes) AppendNodeList(l *NodeList) {
|
||||
if n.slice == nil {
|
||||
n.SetToNodeList(l)
|
||||
} else {
|
||||
for ; l != nil; l = l.Next {
|
||||
*n.slice = append(*n.slice, l.N)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// nodesOrNodeList must be either type Nodes or type *NodeList, or, in
|
||||
// some cases, []*Node. It exists during the transition from NodeList
|
||||
// to Nodes only and then should be deleted. See nodeSeqIterate to
|
||||
// return an iterator from a nodesOrNodeList.
|
||||
type nodesOrNodeList interface{}
|
||||
|
||||
// nodesOrNodeListPtr must be type *Nodes or type **NodeList, or, in
|
||||
// some cases, *[]*Node. It exists during the transition from NodeList
|
||||
// to Nodes only, and then should be deleted. See setNodeSeq to assign
|
||||
// to a generic value.
|
||||
type nodesOrNodeListPtr interface{}
|
||||
|
||||
// nodeSeqLen returns the length of a *NodeList, a Nodes, a []*Node, or nil.
|
||||
func nodeSeqLen(ns nodesOrNodeList) int {
|
||||
switch ns := ns.(type) {
|
||||
case *NodeList:
|
||||
return count(ns)
|
||||
case Nodes:
|
||||
return len(ns.Slice())
|
||||
case []*Node:
|
||||
return len(ns)
|
||||
case nil:
|
||||
return 0
|
||||
default:
|
||||
panic("can't happen")
|
||||
}
|
||||
}
|
||||
|
||||
// nodeSeqFirst returns the first element of a *NodeList, a Nodes,
|
||||
// or a []*Node. It panics if the sequence is empty.
|
||||
func nodeSeqFirst(ns nodesOrNodeList) *Node {
|
||||
switch ns := ns.(type) {
|
||||
case *NodeList:
|
||||
return ns.N
|
||||
case Nodes:
|
||||
return ns.Slice()[0]
|
||||
case []*Node:
|
||||
return ns[0]
|
||||
default:
|
||||
panic("can't happen")
|
||||
}
|
||||
}
|
||||
|
||||
// nodeSeqSecond returns the second element of a *NodeList, a Nodes,
|
||||
// or a []*Node. It panics if the sequence has fewer than two elements.
|
||||
func nodeSeqSecond(ns nodesOrNodeList) *Node {
|
||||
switch ns := ns.(type) {
|
||||
case *NodeList:
|
||||
return ns.Next.N
|
||||
case Nodes:
|
||||
return ns.Slice()[1]
|
||||
case []*Node:
|
||||
return ns[1]
|
||||
default:
|
||||
panic("can't happen")
|
||||
}
|
||||
}
|
||||
|
||||
// nodeSeqSlice returns a []*Node containing the contents of a
|
||||
// *NodeList, a Nodes, or a []*Node.
|
||||
// This is an interim function during the transition from NodeList to Nodes.
|
||||
// TODO(iant): Remove when transition is complete.
|
||||
func nodeSeqSlice(ns nodesOrNodeList) []*Node {
|
||||
switch ns := ns.(type) {
|
||||
case *NodeList:
|
||||
var s []*Node
|
||||
for l := ns; l != nil; l = l.Next {
|
||||
s = append(s, l.N)
|
||||
}
|
||||
return s
|
||||
case Nodes:
|
||||
return ns.Slice()
|
||||
case []*Node:
|
||||
return ns
|
||||
default:
|
||||
panic("can't happen")
|
||||
}
|
||||
}
|
||||
|
||||
// setNodeSeq implements *a = b.
|
||||
// a must have type **NodeList, *Nodes, or *[]*Node.
|
||||
// b must have type *NodeList, Nodes, []*Node, or nil.
|
||||
// This is an interim function during the transition from NodeList to Nodes.
|
||||
// TODO(iant): Remove when transition is complete.
|
||||
func setNodeSeq(a nodesOrNodeListPtr, b nodesOrNodeList) {
|
||||
if b == nil {
|
||||
switch a := a.(type) {
|
||||
case **NodeList:
|
||||
*a = nil
|
||||
case *Nodes:
|
||||
a.Set(nil)
|
||||
case *[]*Node:
|
||||
*a = nil
|
||||
default:
|
||||
panic("can't happen")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 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 = b
|
||||
case []*Node:
|
||||
var ll *NodeList
|
||||
for _, n := range b {
|
||||
ll = list(ll, n)
|
||||
}
|
||||
*l = ll
|
||||
default:
|
||||
panic("can't happen")
|
||||
}
|
||||
} else {
|
||||
var s []*Node
|
||||
switch b := b.(type) {
|
||||
case *NodeList:
|
||||
for l := b; l != nil; l = l.Next {
|
||||
s = append(s, l.N)
|
||||
}
|
||||
case []*Node:
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
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) {
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue