mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 01:01:35 +01:00
cgen: have writeStatementIOManip use switches
This commit is contained in:
1 parent
be1b1b564c
commit
e5dc87e4d3
1 file changed
+8
-10
@@ -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
|
// instead of block-scoped (smaller scope) if the coro_susp_point
|
||||||
// switch can jump past this initialization??
|
// switch can jump past this initialization??
|
||||||
b.writes("{\n")
|
b.writes("{\n")
|
||||||
{
|
switch n.Keyword() {
|
||||||
if keyword := n.Keyword(); keyword == t.IDIOBind {
|
case t.IDIOBind:
|
||||||
b.printf("wuffs_base__io_buffer* %s%d_%s%s = %s%s;\n",
|
b.printf("wuffs_base__io_buffer* %s%d_%s%s = %s%s;\n",
|
||||||
oPrefix, ioBindNum, prefix, name,
|
oPrefix, ioBindNum, prefix, name,
|
||||||
prefix, name)
|
prefix, name)
|
||||||
@@ -347,7 +347,7 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
|
|||||||
}
|
}
|
||||||
b.writes(");\n")
|
b.writes(");\n")
|
||||||
|
|
||||||
} else if keyword == t.IDIOForgetHistory {
|
case t.IDIOForgetHistory:
|
||||||
if !isWriter {
|
if !isWriter {
|
||||||
return fmt.Errorf("unsupported io_forget_history for an io_reader")
|
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")
|
b.printf("}\n")
|
||||||
|
|
||||||
} else {
|
case t.IDIOLimit:
|
||||||
if !isWriter {
|
if !isWriter {
|
||||||
b.printf("const bool %s%d_closed_%s%s = %s%s->meta.closed;\n",
|
b.printf("const bool %s%d_closed_%s%s = %s%s->meta.closed;\n",
|
||||||
oPrefix, ioBindNum, prefix, name, prefix, name)
|
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)
|
prefix, name, end)
|
||||||
b.printf("}\n")
|
b.printf("}\n")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for _, o := range n.Body() {
|
for _, o := range n.Body() {
|
||||||
if err := g.writeStatement(b, o, depth); err != nil {
|
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
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
switch n.Keyword() {
|
||||||
if keyword := n.Keyword(); keyword == t.IDIOBind {
|
case t.IDIOBind:
|
||||||
b.printf("%s%s = %s%d_%s%s;\n",
|
b.printf("%s%s = %s%d_%s%s;\n",
|
||||||
prefix, name,
|
prefix, name,
|
||||||
oPrefix, ioBindNum, 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,
|
io2Prefix, prefix, name,
|
||||||
oPrefix, ioBindNum, io2Prefix, prefix, name)
|
oPrefix, ioBindNum, io2Prefix, prefix, name)
|
||||||
|
|
||||||
} else if keyword == t.IDIOForgetHistory {
|
case t.IDIOForgetHistory:
|
||||||
b.printf("if (%s%s) {\n",
|
b.printf("if (%s%s) {\n",
|
||||||
prefix, name)
|
prefix, name)
|
||||||
if isWriter {
|
if isWriter {
|
||||||
@@ -460,7 +459,7 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
|
|||||||
}
|
}
|
||||||
b.printf("}\n")
|
b.printf("}\n")
|
||||||
|
|
||||||
} else {
|
case t.IDIOLimit:
|
||||||
b.printf("%s%s%s = %s%d_%s%s%s;\n",
|
b.printf("%s%s%s = %s%d_%s%s%s;\n",
|
||||||
io2Prefix, prefix, name,
|
io2Prefix, prefix, name,
|
||||||
oPrefix, ioBindNum, 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)
|
prefix, name)
|
||||||
b.printf("}\n")
|
b.printf("}\n")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
b.writes("}\n")
|
b.writes("}\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user