]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/walk: merge operations
authorcuiweixie <cuiweixie@gmail.com>
Tue, 27 Apr 2021 08:50:06 +0000 (08:50 +0000)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 27 Apr 2021 19:40:24 +0000 (19:40 +0000)
Change-Id: I018872da519dfb4aa6c252ea28fc09289c2d9711
GitHub-Last-Rev: 5969776197003cae317f6b45f88ac4ced10beaf3
GitHub-Pull-Request: golang/go#45795
Reviewed-on: https://go-review.googlesource.com/c/go/+/313550
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Keith Randall <khr@golang.org>

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

index 3384bc826e9c2de01a6e79dfbb11489919741301..0c651c6289e9e59dd7cee81027e16f24dd9b2771 100644 (file)
@@ -118,9 +118,7 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
                        tmp.SetBounded(true)
                        // Use OAS2 to correctly handle assignments
                        // of the form "v1, a[v1] := range".
-                       a := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
-                       a.Lhs = []ir.Node{v1, v2}
-                       a.Rhs = []ir.Node{hv1, tmp}
+                       a := ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{v1, v2}, []ir.Node{hv1, tmp})
                        body = []ir.Node{a}
                        break
                }
@@ -148,9 +146,7 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
 
                // Use OAS2 to correctly handle assignments
                // of the form "v1, a[v1] := range".
-               a := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
-               a.Lhs = []ir.Node{v1, v2}
-               a.Rhs = []ir.Node{hv1, ir.NewStarExpr(base.Pos, hp)}
+               a := ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{v1, v2}, []ir.Node{hv1, ir.NewStarExpr(base.Pos, hp)})
                body = append(body, a)
 
                // Advance pointer as part of the late increment.
@@ -190,9 +186,7 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
                        body = []ir.Node{ir.NewAssignStmt(base.Pos, v1, key)}
                } else {
                        elem := ir.NewStarExpr(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT, hit, elemsym))
-                       a := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
-                       a.Lhs = []ir.Node{v1, v2}
-                       a.Rhs = []ir.Node{key, elem}
+                       a := ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{v1, v2}, []ir.Node{key, elem})
                        body = []ir.Node{a}
                }
 
@@ -208,10 +202,10 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
                hb := typecheck.Temp(types.Types[types.TBOOL])
 
                nfor.Cond = ir.NewBinaryExpr(base.Pos, ir.ONE, hb, ir.NewBool(false))
-               a := ir.NewAssignListStmt(base.Pos, ir.OAS2RECV, nil, nil)
+               lhs := []ir.Node{hv1, hb}
+               rhs := []ir.Node{ir.NewUnaryExpr(base.Pos, ir.ORECV, ha)}
+               a := ir.NewAssignListStmt(base.Pos, ir.OAS2RECV, lhs, rhs)
                a.SetTypecheck(1)
-               a.Lhs = []ir.Node{hv1, hb}
-               a.Rhs = []ir.Node{ir.NewUnaryExpr(base.Pos, ir.ORECV, ha)}
                nfor.Cond = ir.InitExpr([]ir.Node{a}, nfor.Cond)
                if v1 == nil {
                        body = nil
@@ -270,24 +264,18 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
                nif.Body = []ir.Node{ir.NewAssignStmt(base.Pos, hv1, ir.NewBinaryExpr(base.Pos, ir.OADD, hv1, ir.NewInt(1)))}
 
                // } else {
-               eif := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
-
                // hv2, hv1 = decoderune(ha, hv1)
-               eif.Lhs = []ir.Node{hv2, hv1}
                fn := typecheck.LookupRuntime("decoderune")
-               var fnInit ir.Nodes
-               eif.Rhs = []ir.Node{mkcall1(fn, fn.Type().Results(), &fnInit, ha, hv1)}
-               fnInit.Append(eif)
-               nif.Else = fnInit
+               call := mkcall1(fn, fn.Type().Results(), &nif.Else, ha, hv1)
+               a := ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{hv2, hv1}, []ir.Node{call})
+               nif.Else.Append(a)
 
                body = append(body, nif)
 
                if v1 != nil {
                        if v2 != nil {
                                // v1, v2 = hv1t, hv2
-                               a := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
-                               a.Lhs = []ir.Node{v1, v2}
-                               a.Rhs = []ir.Node{hv1t, hv2}
+                               a := ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{v1, v2}, []ir.Node{hv1t, hv2})
                                body = append(body, a)
                        } else {
                                // v1 = hv1t