Add Set3 function to complement existing Set1 and Set2 functions.
Consistently use Set1, Set2 and Set3 for []*Node instead of Set where applicable.
Add SetFirst and SetSecond for setting elements of []*Node to mirror
First and Second for accessing elements in []*Node.
Replace uses of Index by First and Second and
SetIndex with SetFirst and SetSecond where applicable.
Passes toolstash -cmp.
Change-Id: I8255aae768cf245c8f93eec2e9efa05b8112b4e5
Reviewed-on: https://go-review.googlesource.com/37430
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
r = okas(n.List.Second(), tmp2)
r = typecheck(r, Etop)
ordermapassign(r, order)
- n.List.Set([]*Node{tmp1, tmp2})
+ n.List.Set2(tmp1, tmp2)
cleantemp(t, order)
// Special: does not save n onto out.
case ODELETE:
t := marktemp(order)
- n.List.SetIndex(0, orderexpr(n.List.Index(0), order, nil))
- n.List.SetIndex(1, orderexpr(n.List.Index(1), order, nil))
- n.List.SetIndex(1, orderaddrtemp(n.List.Index(1), order)) // map key
+ n.List.SetFirst(orderexpr(n.List.First(), order, nil))
+ n.List.SetSecond(orderexpr(n.List.Second(), order, nil))
+ n.List.SetSecond(orderaddrtemp(n.List.Second(), order)) // map key
order.out = append(order.out, n)
cleantemp(t, order)
r := nod(OAS, n.List.First(), tmp1)
r = typecheck(r, Etop)
ordermapassign(r, order)
- n.List.SetIndex(0, tmp1)
+ n.List.SetFirst(tmp1)
}
if tmp2 != nil {
r := okas(n.List.Second(), tmp2)
r = typecheck(r, Etop)
ordermapassign(r, order)
- n.List.SetIndex(1, tmp2)
+ n.List.SetSecond(tmp2)
}
}
body = []*Node{nod(OAS, v1, hv1)}
} else {
a := nod(OAS2, nil, nil)
- a.List.Set([]*Node{v1, v2})
- a.Rlist.Set([]*Node{hv1, nod(OIND, hp, nil)})
+ a.List.Set2(v1, v2)
+ a.Rlist.Set2(hv1, nod(OIND, hp, nil))
body = []*Node{a}
// Advance pointer as part of increment.
val := nodSym(ODOT, hit, valsym)
val = nod(OIND, val, nil)
a := nod(OAS2, nil, nil)
- a.List.Set([]*Node{v1, v2})
- a.Rlist.Set([]*Node{key, val})
+ a.List.Set2(v1, v2)
+ a.Rlist.Set2(key, val)
body = []*Node{a}
}
n.Left = nod(ONE, hb, nodbool(false))
a := nod(OAS2RECV, nil, nil)
a.Typecheck = 1
- a.List.Set([]*Node{hv1, hb})
+ a.List.Set2(hv1, hb)
a.Rlist.Set1(nod(ORECV, ha, nil))
n.Left.Ninit.Set1(a)
if v1 == nil {
} else if ncase.List.Len() > 1 {
yyerror("select cases cannot be lists")
} else {
- ncase.List.SetIndex(0, typecheck(ncase.List.Index(0), Etop))
- n = ncase.List.Index(0)
+ ncase.List.SetFirst(typecheck(ncase.List.First(), Etop))
+ n = ncase.List.First()
ncase.Left = n
ncase.List.Set(nil)
setlineno(n)
n.Op = OSELRECV
}
if n.Op == OSELRECV2 {
- n.List.SetIndex(0, nod(OADDR, n.List.First(), nil))
- n.List.SetIndex(0, typecheck(n.List.Index(0), Erv))
+ n.List.SetFirst(nod(OADDR, n.List.First(), nil))
+ n.List.SetFirst(typecheck(n.List.First(), Erv))
}
if n.Left == nil {
if low == nil && high == nil {
return
}
- n.List.Set([]*Node{low, high})
+ n.List.Set2(low, high)
return
}
s[0] = low
if low == nil && high == nil && max == nil {
return
}
- n.List.Set([]*Node{low, high, max})
+ n.List.Set3(low, high, max)
return
}
s[0] = low
}
nvar = typecheck(nvar, Erv|Easgn)
- ncase.Rlist.SetIndex(0, nvar)
+ ncase.Rlist.SetFirst(nvar)
}
}
case c.node.List.Len() == 2:
// Range of integers.
- low := c.node.List.Index(0).Int64()
- high := c.node.List.Index(1).Int64()
+ low := c.node.List.First().Int64()
+ high := c.node.List.Second().Int64()
for i := low; i <= high; i++ {
prev, dup := seen[i]
if !dup {
i.Nbody.Set1(nod(OGOTO, lbl, nil))
// Wrap default case with label.
blk := nod(OBLOCK, nil, nil)
- blk.List.Set([]*Node{nod(OLABEL, lbl, nil), def})
+ blk.List.Set2(nod(OLABEL, lbl, nil), def)
def = blk
}
i.Left = typecheck(i.Left, Erv)
}
a := nod(OAS2, nil, nil)
- a.List.Set([]*Node{name, s.okname}) // name, ok =
+ a.List.Set2(name, s.okname) // name, ok =
b := nod(ODOTTYPE, s.facename, nil)
b.Type = t.Left.Type // interface.(type)
a.Rlist.Set1(b)
}
// Set1 sets n to a slice containing a single node.
-func (n *Nodes) Set1(node *Node) {
- n.slice = &[]*Node{node}
+func (n *Nodes) Set1(n1 *Node) {
+ n.slice = &[]*Node{n1}
}
// Set2 sets n to a slice containing two nodes.
n.slice = &[]*Node{n1, n2}
}
+// Set3 sets n to a slice containing three nodes.
+func (n *Nodes) Set3(n1, n2, n3 *Node) {
+ n.slice = &[]*Node{n1, n2, n3}
+}
+
// MoveNodes sets n to the contents of n2, then clears n2.
func (n *Nodes) MoveNodes(n2 *Nodes) {
n.slice = n2.slice
(*n.slice)[i] = node
}
+// SetFirst sets the first element of Nodes to node.
+// It panics if n does not have at least one elements.
+func (n Nodes) SetFirst(node *Node) {
+ (*n.slice)[0] = node
+}
+
+// SetSecond sets the second element of Nodes to node.
+// It panics if n does not have at least two elements.
+func (n Nodes) SetSecond(node *Node) {
+ (*n.slice)[1] = node
+}
+
// Addr returns the address of the i'th element of Nodes.
// It panics if n does not have at least i+1 elements.
func (n Nodes) Addr(i int) **Node {
}
if n.List.Len() == 1 && !n.Isddd {
- n.List.SetIndex(0, typecheck(n.List.Index(0), Erv|Efnstruct))
+ n.List.SetFirst(typecheck(n.List.First(), Erv|Efnstruct))
} else {
typecheckslice(n.List.Slice(), Erv)
}
return n
}
- args.SetIndex(1, assignconv(r, l.Type.Key(), "delete"))
+ args.SetSecond(assignconv(r, l.Type.Key(), "delete"))
break OpSwitch
case OAPPEND:
}
if args.Len() == 1 && !n.Isddd {
- args.SetIndex(0, typecheck(args.Index(0), Erv|Efnstruct))
+ args.SetFirst(typecheck(args.First(), Erv|Efnstruct))
} else {
typecheckslice(args.Slice(), Erv)
}
}
if t.Elem().IsKind(TUINT8) && args.Second().Type.IsString() {
- args.SetIndex(1, defaultlit(args.Index(1), Types[TSTRING]))
+ args.SetSecond(defaultlit(args.Second(), Types[TSTRING]))
break OpSwitch
}
- args.SetIndex(1, assignconv(args.Index(1), t.Orig, "append"))
+ args.SetSecond(assignconv(args.Second(), t.Orig, "append"))
break OpSwitch
}
cl := n.List.Len()
cr := n.Rlist.Len()
if cl > 1 && cr == 1 {
- n.Rlist.SetIndex(0, typecheck(n.Rlist.Index(0), Erv|Efnstruct))
+ n.Rlist.SetFirst(typecheck(n.Rlist.First(), Erv|Efnstruct))
} else {
typecheckslice(n.Rlist.Slice(), Erv)
}
var_ := temp(ptrto(t.Val()))
var_.Typecheck = 1
var_.NonNil = true // mapaccess always returns a non-nil pointer
- n.List.SetIndex(0, var_)
+ n.List.SetFirst(var_)
n = walkexpr(n, init)
init.Append(n)
n = nod(OAS, a, nod(OIND, var_, nil))
// s
func walkappend(n *Node, init *Nodes, dst *Node) *Node {
if !samesafeexpr(dst, n.List.First()) {
- n.List.SetIndex(0, safeexpr(n.List.Index(0), init))
- n.List.SetIndex(0, walkexpr(n.List.Index(0), init))
+ n.List.SetFirst(safeexpr(n.List.First(), init))
+ n.List.SetFirst(walkexpr(n.List.First(), init))
}
walkexprlistsafe(n.List.Slice()[1:], init)