Commit 4b8a1611 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: add Nodes.Prepend helper method

Prepared with gofmt -r.

Change-Id: Ib9f224cc20353acd9c5850dead1a2d32ca5427d3
Reviewed-on: https://go-review.googlesource.com/29165
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 6f135bfd
......@@ -676,7 +676,7 @@ func orderstmt(n *Node, order *Order) {
n.Left = orderexprinplace(n.Left, order)
var l []*Node
cleantempnopop(t, order, &l)
n.Nbody.Set(append(l, n.Nbody.Slice()...))
n.Nbody.Prepend(l...)
orderblockNodes(&n.Nbody)
n.Right = orderstmtinplace(n.Right)
order.out = append(order.out, n)
......@@ -690,10 +690,10 @@ func orderstmt(n *Node, order *Order) {
n.Left = orderexprinplace(n.Left, order)
var l []*Node
cleantempnopop(t, order, &l)
n.Nbody.Set(append(l, n.Nbody.Slice()...))
n.Nbody.Prepend(l...)
l = nil
cleantempnopop(t, order, &l)
n.Rlist.Set(append(l, n.Rlist.Slice()...))
n.Rlist.Prepend(l...)
poptemp(t, order)
orderblockNodes(&n.Nbody)
n.Rlist.Set(orderblock(n.Rlist))
......@@ -917,7 +917,7 @@ func orderstmt(n *Node, order *Order) {
for _, n3 := range n.List.Slice() {
s := n3.Ninit.Slice()
cleantempnopop(t, order, &s)
n3.Nbody.Set(append(s, n3.Nbody.Slice()...))
n3.Nbody.Prepend(s...)
n3.Ninit.Set(nil)
}
......@@ -1110,7 +1110,7 @@ func orderexpr(n *Node, order *Order, lhs *Node) *Node {
var s []*Node
cleantempnopop(mark, order, &s)
n.Right.Ninit.Set(append(s, n.Right.Ninit.Slice()...))
n.Right.Ninit.Prepend(s...)
n.Right = orderexprinplace(n.Right, order)
case OCALLFUNC,
......
......@@ -376,7 +376,7 @@ func compile(fn *Node) {
if t.Nname != nil {
n := Nod(OAS, t.Nname, nil)
n = typecheck(n, Etop)
Curfn.Nbody.Set(append([]*Node{n}, Curfn.Nbody.Slice()...))
Curfn.Nbody.Prepend(n)
}
}
}
......
......@@ -69,7 +69,7 @@ func instrument(fn *Node) {
nodpc.Type = Types[TUINTPTR]
nodpc.Xoffset = int64(-Widthptr)
nd := mkcall("racefuncenter", nil, nil, &nodpc)
fn.Func.Enter.Set(append([]*Node{nd}, fn.Func.Enter.Slice()...))
fn.Func.Enter.Prepend(nd)
nd = mkcall("racefuncexit", nil, nil)
fn.Func.Exit.Append(nd)
}
......
......@@ -354,7 +354,7 @@ func walkrange(n *Node) {
n.Left = typecheck(n.Left, Erv)
n.Right = typecheck(n.Right, Etop)
typecheckslice(body, Etop)
n.Nbody.Set(append(body, n.Nbody.Slice()...))
n.Nbody.Prepend(body...)
n = walkstmt(n)
lineno = lno
......
......@@ -143,7 +143,7 @@ func walkselect(sel *Node) {
}
n.Op = OAS2
n.List.Set(append([]*Node{n.Left}, n.List.Slice()...))
n.List.Prepend(n.Left)
n.Rlist.Set1(n.Right)
n.Right = nil
n.Left = nil
......
......@@ -2198,7 +2198,7 @@ func addinit(n *Node, init []*Node) *Node {
n.Typecheck = 1
}
n.Ninit.Set(append(init, n.Ninit.Slice()...))
n.Ninit.Prepend(init...)
n.Ullman = UINF
return n
}
......
......@@ -281,7 +281,7 @@ func (s *exprSwitch) walk(sw *Node) {
// handle default case
if nerrors == 0 {
cas = append(cas, clauses.defjmp)
sw.Nbody.Set(append(cas, sw.Nbody.Slice()...))
sw.Nbody.Prepend(cas...)
walkstmtlist(sw.Nbody.Slice())
}
}
......@@ -800,7 +800,7 @@ func (s *typeSwitch) walk(sw *Node) {
// handle default case
if nerrors == 0 {
cas = append(cas, def)
sw.Nbody.Set(append(cas, sw.Nbody.Slice()...))
sw.Nbody.Prepend(cas...)
sw.List.Set(nil)
walkstmtlist(sw.Nbody.Slice())
}
......
......@@ -583,15 +583,29 @@ func (n Nodes) Addr(i int) **Node {
// Append appends entries to Nodes.
// If a slice is passed in, this will take ownership of it.
func (n *Nodes) Append(a ...*Node) {
if len(a) == 0 {
return
}
if n.slice == nil {
if len(a) > 0 {
n.slice = &a
}
n.slice = &a
} else {
*n.slice = append(*n.slice, a...)
}
}
// Prepend prepends entries to Nodes.
// If a slice is passed in, this will take ownership of it.
func (n *Nodes) Prepend(a ...*Node) {
if len(a) == 0 {
return
}
if n.slice == nil {
n.slice = &a
} else {
*n.slice = append(a, *n.slice...)
}
}
// AppendNodes appends the contents of *n2 to n, then clears n2.
func (n *Nodes) AppendNodes(n2 *Nodes) {
switch {
......
......@@ -669,7 +669,7 @@ opswitch:
// transformclosure already did all preparation work.
// Prepend captured variables to argument list.
n.List.Set(append(n.Left.Func.Enter.Slice(), n.List.Slice()...))
n.List.Prepend(n.Left.Func.Enter.Slice()...)
n.Left.Func.Enter.Set(nil)
......
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