]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: simplify a few early var declarations
authorDaniel Martí <mvdan@mvdan.cc>
Mon, 11 Sep 2017 19:23:44 +0000 (21:23 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Mon, 11 Sep 2017 21:16:39 +0000 (21:16 +0000)
These were likely written in C or added by an automated tool. Either
way, they're unnecessary now. Clean up the code.

Change-Id: I56de2c7bb60ebab8c500803a8b6586bdf4bf75c7
Reviewed-on: https://go-review.googlesource.com/62951
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/walk.go

index b23cb56f105fc2bea3132189a5bc1b960b2bd0dd..157693f32109a02aa5b0d02fd4fa758399370ca9 100644 (file)
@@ -113,15 +113,12 @@ func paramoutheap(fn *Node) bool {
 // adds "adjust" to all the argument locations for the call n.
 // n must be a defer or go node that has already been walked.
 func adjustargs(n *Node, adjust int) {
-       var arg *Node
-       var lhs *Node
-
        callfunc := n.Left
-       for _, arg = range callfunc.List.Slice() {
+       for _, arg := range callfunc.List.Slice() {
                if arg.Op != OAS {
                        Fatalf("call arg not assignment")
                }
-               lhs = arg.Left
+               lhs := arg.Left
                if lhs.Op == ONAME {
                        // This is a temporary introduced by reorder1.
                        // The real store to the stack appears later in the arg list.
@@ -303,9 +300,8 @@ func walkstmt(n *Node) *Node {
                        // so that reorder3 can fix up conflicts
                        var rl []*Node
 
-                       var cl Class
                        for _, ln := range Curfn.Func.Dcl {
-                               cl = ln.Class()
+                               cl := ln.Class()
                                if cl == PAUTO || cl == PAUTOHEAP {
                                        break
                                }
@@ -2367,7 +2363,6 @@ func reorder1(all []*Node) []*Node {
        var f *Node   // last fncall assigned to stack
        var r []*Node // non fncalls and tempnames assigned to stack
        d := 0
-       var a *Node
        for _, n := range all {
                if !n.HasCall() {
                        r = append(r, n)
@@ -2381,7 +2376,7 @@ func reorder1(all []*Node) []*Node {
                }
 
                // make assignment of fncall to tempname
-               a = temp(n.Right.Type)
+               a := temp(n.Right.Type)
 
                a = nod(OAS, a, n.Right)
                g = append(g, a)
@@ -2406,8 +2401,6 @@ func reorder1(all []*Node) []*Node {
 //
 // function calls have been removed.
 func reorder3(all []*Node) []*Node {
-       var l *Node
-
        // If a needed expression may be affected by an
        // earlier assignment, make an early copy of that
        // expression and use the copy instead.
@@ -2415,7 +2408,7 @@ func reorder3(all []*Node) []*Node {
 
        var mapinit Nodes
        for i, n := range all {
-               l = n.Left
+               l := n.Left
 
                // Save subexpressions needed on left side.
                // Drill through non-dereferences.
@@ -2522,9 +2515,8 @@ func aliased(n *Node, all []*Node, i int) bool {
        memwrite := 0
 
        varwrite := 0
-       var a *Node
        for _, an := range all[:i] {
-               a = outervalue(an.Left)
+               a := outervalue(an.Left)
 
                for a.Op == ODOT {
                        a = a.Left
@@ -3915,12 +3907,10 @@ func walkprintfunc(n *Node, init *Nodes) *Node {
        t := nod(OTFUNC, nil, nil)
        num := 0
        var printargs []*Node
-       var a *Node
-       var buf string
        for _, n1 := range n.List.Slice() {
-               buf = fmt.Sprintf("a%d", num)
+               buf := fmt.Sprintf("a%d", num)
                num++
-               a = namedfield(buf, n1.Type)
+               a := namedfield(buf, n1.Type)
                t.List.Append(a)
                printargs = append(printargs, a.Left)
        }
@@ -3932,7 +3922,7 @@ func walkprintfunc(n *Node, init *Nodes) *Node {
        sym := lookupN("print·%d", walkprintfunc_prgen)
        fn := dclfunc(sym, t)
 
-       a = nod(n.Op, nil, nil)
+       a := nod(n.Op, nil, nil)
        a.List.Set(printargs)
        a = typecheck(a, Etop)
        a = walkstmt(a)