cgen: have writeStatementIOManip use switches

This commit is contained in:
Nigel Tao committed 2024-02-09 15:21:37 +11:00
1 parent be1b1b564c
commit e5dc87e4d3
1 file changed
+8 -10
+8 -10
View File
@@ -313,8 +313,8 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
// instead of block-scoped (smaller scope) if the coro_susp_point
// switch can jump past this initialization??
b.writes("{\n")
{
if keyword := n.Keyword(); keyword == t.IDIOBind {
switch n.Keyword() {
case t.IDIOBind:
b.printf("wuffs_base__io_buffer* %s%d_%s%s = %s%s;\n",
oPrefix, ioBindNum, prefix, name,
prefix, name)
@@ -347,7 +347,7 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
}
b.writes(");\n")
} else if keyword == t.IDIOForgetHistory {
case t.IDIOForgetHistory:
if !isWriter {
return fmt.Errorf("unsupported io_forget_history for an io_reader")
}
@@ -387,7 +387,7 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
}
b.printf("}\n")
} else {
case t.IDIOLimit:
if !isWriter {
b.printf("const bool %s%d_closed_%s%s = %s%s->meta.closed;\n",
oPrefix, ioBindNum, prefix, name, prefix, name)
@@ -413,7 +413,6 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
prefix, name, end)
b.printf("}\n")
}
}
for _, o := range n.Body() {
if err := g.writeStatement(b, o, depth); err != nil {
@@ -421,8 +420,8 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
}
}
{
if keyword := n.Keyword(); keyword == t.IDIOBind {
switch n.Keyword() {
case t.IDIOBind:
b.printf("%s%s = %s%d_%s%s;\n",
prefix, name,
oPrefix, ioBindNum, prefix, name)
@@ -439,7 +438,7 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
io2Prefix, prefix, name,
oPrefix, ioBindNum, io2Prefix, prefix, name)
} else if keyword == t.IDIOForgetHistory {
case t.IDIOForgetHistory:
b.printf("if (%s%s) {\n",
prefix, name)
if isWriter {
@@ -460,7 +459,7 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
}
b.printf("}\n")
} else {
case t.IDIOLimit:
b.printf("%s%s%s = %s%d_%s%s%s;\n",
io2Prefix, prefix, name,
oPrefix, ioBindNum, io2Prefix, prefix, name)
@@ -475,7 +474,6 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
prefix, name)
b.printf("}\n")
}
}
b.writes("}\n")
return nil
}