Factor writeStatementAssign into two methods
@@ -99,22 +99,32 @@ func (g *gen) writeStatementAssign(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr,
}
depth++
- wbqcErr := errNoSuchBuiltin
+ if err := g.writeStatementAssign0(b, op, lhs, rhs); err != nil {
+ return err
+ }
+ if lhs != nil {
+ if err := g.writeStatementAssign1(b, op, lhs, rhs); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func (g *gen) writeStatementAssign0(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr) error {
if rhs.Effect().Coroutine() {
if op != t.IDEqQuestion {
if err := g.writeCoroSuspPoint(b, false); err != nil {
return err
}
}
- wbqcErr = g.writeBuiltinQuestionCall(b, rhs, depth)
- if wbqcErr == nil {
- // No-op.
- } else if wbqcErr != errNoSuchBuiltin {
- return wbqcErr
+ if err := g.writeBuiltinQuestionCall(b, rhs, 0); err == nil {
+ return nil
+ } else if err != errNoSuchBuiltin {
+ return err
}
}
- if (wbqcErr != nil) && ((lhs == nil) || (rhs.Effect().Coroutine())) {
+ if (lhs == nil) || rhs.Effect().Coroutine() {
if err := g.writeSaveExprDerivedVars(b, rhs); err != nil {
return err
}
@@ -132,7 +142,7 @@ func (g *gen) writeStatementAssign(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr,
}
// TODO: drop the "Other" in writeExprOther.
- if err := g.writeExprOther(b, rhs, depth); err != nil {
+ if err := g.writeExprOther(b, rhs, 0); err != nil {
return err
}
b.writes(";\n")
@@ -150,9 +160,12 @@ func (g *gen) writeStatementAssign(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr,
}
}
- if lhs != nil {
+ return nil
+}
+
+func (g *gen) writeStatementAssign1(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr) error {
lhsBuf := buffer(nil)
- if err := g.writeExpr(&lhsBuf, lhs, depth); err != nil {
+ if err := g.writeExpr(&lhsBuf, lhs, 0); err != nil {
return err
}
@@ -185,12 +198,11 @@ func (g *gen) writeStatementAssign(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr,
b.writex(lhsBuf)
b.writes(opName)
- if err := g.writeExpr(b, rhs, depth); err != nil {
+ if err := g.writeExpr(b, rhs, 0); err != nil {
return err
}
b.writes(closer)
b.writes(";\n")
- }
return nil
}
