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