]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.unified] cmd/compile/internal/noder: refactor stmtAssign generation
authorMatthew Dempsky <mdempsky@google.com>
Tue, 21 Jun 2022 18:49:27 +0000 (11:49 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 23 Jun 2022 21:55:08 +0000 (21:55 +0000)
Eliminate some code duplication between assignment statements and
variable declarations, so they're easier to extend with implicit
conversions.

Change-Id: I605cf7817e3cb230f2c4612b777d8023c926e8b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/413515
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/noder/writer.go

index 5160cfaac68d5984d9f08052be5e9a9838b94289..942bab4b2bff4253d8935f171c92b5f071eee5b6 100644 (file)
@@ -1087,10 +1087,7 @@ func (w *writer) stmt1(stmt syntax.Stmt) {
                        w.implicitExpr(stmt, typ, stmt.Rhs)
 
                default:
-                       w.Code(stmtAssign)
-                       w.pos(stmt)
-                       w.assignList(stmt.Lhs)
-                       w.exprList(stmt.Rhs) // TODO(mdempsky): Implicit conversions to Lhs types.
+                       w.assignStmt(stmt, stmt.Lhs, stmt.Rhs)
                }
 
        case *syntax.BlockStmt:
@@ -1200,13 +1197,18 @@ func (w *writer) declStmt(decl syntax.Decl) {
        case *syntax.ConstDecl, *syntax.TypeDecl:
 
        case *syntax.VarDecl:
-               w.Code(stmtAssign)
-               w.pos(decl)
-               w.assignList(namesAsExpr(decl.NameList))
-               w.exprList(decl.Values) // TODO(mdempsky): Implicit conversions to Lhs types.
+               w.assignStmt(decl, namesAsExpr(decl.NameList), decl.Values)
        }
 }
 
+// assignStmt writes out an assignment for "lhs = rhs".
+func (w *writer) assignStmt(pos poser, lhs, rhs syntax.Expr) {
+       w.Code(stmtAssign)
+       w.pos(pos)
+       w.assignList(lhs)
+       w.exprList(rhs) // TODO(mdempsky): Implicit conversions to Lhs types.
+}
+
 func (w *writer) blockStmt(stmt *syntax.BlockStmt) {
        w.Sync(pkgbits.SyncBlockStmt)
        w.openScope(stmt.Pos())