]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: make setting and accessing of node slice elements more uniform
authorMartin Möhrmann <moehrmann@google.com>
Sun, 19 Feb 2017 14:57:58 +0000 (15:57 +0100)
committerMartin Möhrmann <moehrmann@google.com>
Fri, 24 Feb 2017 21:55:24 +0000 (21:55 +0000)
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>
src/cmd/compile/internal/gc/order.go
src/cmd/compile/internal/gc/range.go
src/cmd/compile/internal/gc/select.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/swt.go
src/cmd/compile/internal/gc/syntax.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go

index 2a707a32accf65bfa3fb7954adaa54768850d214..c3a3be8698a0f93b6ded153b80a279c5f46212e3 100644 (file)
@@ -594,7 +594,7 @@ func orderstmt(n *Node, order *Order) {
                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.
@@ -647,9 +647,9 @@ func orderstmt(n *Node, order *Order) {
 
        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)
 
@@ -1261,12 +1261,12 @@ func orderokas2(n *Node, order *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)
        }
 }
index b59047428f6b893a1a6664c01d63ea23985d2ecf..99ecdd3cc59f1d22ee39e955140fca09f65b8530 100644 (file)
@@ -196,8 +196,8 @@ func walkrange(n *Node) {
                        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.
@@ -251,8 +251,8 @@ func walkrange(n *Node) {
                        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}
                }
 
@@ -272,7 +272,7 @@ func walkrange(n *Node) {
                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 {
index d999190ad1fec39524c2c4a7912fa5067a242924..a59b65c1404d8d9806e40a6a3847de8075be16d8 100644 (file)
@@ -31,8 +31,8 @@ func typecheckselect(sel *Node) {
                } 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)
@@ -187,8 +187,8 @@ func walkselect(sel *Node) {
                                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 {
index 884b87971492d2fda96bb581b7a2ffd1da0c45dd..0f2c00954c976bcd4258e5eb602de7227abbe918 100644 (file)
@@ -1045,7 +1045,7 @@ func (n *Node) SetSliceBounds(low, high, max *Node) {
                        if low == nil && high == nil {
                                return
                        }
-                       n.List.Set([]*Node{low, high})
+                       n.List.Set2(low, high)
                        return
                }
                s[0] = low
@@ -1057,7 +1057,7 @@ func (n *Node) SetSliceBounds(low, high, max *Node) {
                        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
index f48894d77bbc7c5a8a785769830345acbd8220b0..51525788183ac75c4a930db9449b6124abb2cfdc 100644 (file)
@@ -188,7 +188,7 @@ func typecheckswitch(n *Node) {
                                }
 
                                nvar = typecheck(nvar, Erv|Easgn)
-                               ncase.Rlist.SetIndex(0, nvar)
+                               ncase.Rlist.SetFirst(nvar)
                        }
                }
 
@@ -628,8 +628,8 @@ func (s *exprSwitch) checkDupCases(cc []caseClause) {
 
                        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 {
@@ -745,7 +745,7 @@ func (s *typeSwitch) walk(sw *Node) {
                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)
@@ -840,7 +840,7 @@ func (s *typeSwitch) typeone(t *Node) *Node {
        }
 
        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)
index b8aabd7bb4461e60e7df9694fa3450492a544744..36b6af5e1020752c72553aba34e9e86ed5b9aefa 100644 (file)
@@ -556,8 +556,8 @@ func (n *Nodes) Set(s []*Node) {
 }
 
 // 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.
@@ -565,6 +565,11 @@ func (n *Nodes) Set2(n1, n2 *Node) {
        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
@@ -577,6 +582,18 @@ func (n Nodes) SetIndex(i int, node *Node) {
        (*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 {
index 5807f1929e699ac59fdd1063e7c6c0671a6f88d7..ba52b7120044cc13b3ecc41d46cefa2c6b706e63 100644 (file)
@@ -1243,7 +1243,7 @@ OpSwitch:
                }
 
                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)
                }
@@ -1539,7 +1539,7 @@ OpSwitch:
                        return n
                }
 
-               args.SetIndex(1, assignconv(r, l.Type.Key(), "delete"))
+               args.SetSecond(assignconv(r, l.Type.Key(), "delete"))
                break OpSwitch
 
        case OAPPEND:
@@ -1552,7 +1552,7 @@ OpSwitch:
                }
 
                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)
                }
@@ -1597,11 +1597,11 @@ OpSwitch:
                        }
 
                        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
                }
 
@@ -3328,7 +3328,7 @@ func typecheckas2(n *Node) {
        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)
        }
index 066b4ef2f6a5b3995d39eced7e33139e3cd241c5..ce4d62b82c6a1bbece6171e60963eff8fbe592cf 100644 (file)
@@ -818,7 +818,7 @@ opswitch:
                        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))
@@ -2860,8 +2860,8 @@ func appendslice(n *Node, init *Nodes) *Node {
 //   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)