Remove hard-coded cgen of lzw's read_from method

This commit is contained in:
Nigel Tao committed 2018-12-26 11:59:03 +11:00
1 parent ef51d032ba
commit eb108af98a
2 files changed
+9 -29

No files matched your search

+7 -17
View File
@@ -263,11 +263,8 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error {
}
b.writes("\n")
if g.currFunk.astFunc.Effect().Optional() ||
// TODO: delete this lzw.read_from hack.
((g.pkgName == "lzw") && (g.currFunk.astFunc.FuncName().Str(g.tm) == "read_from")) {
g.findDerivedVars()
g.findDerivedVars()
if g.currFunk.derivedVars != nil {
for _, o := range g.currFunk.astFunc.In().Fields() {
o := o.AsField()
if err := g.writeLoadDerivedVar(b, "", aPrefix, o.Name(), o.XType(), true); err != nil {
@@ -334,8 +331,11 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
}
func (g *gen) writeFuncImplEpilogue(b *buffer) error {
// TODO: delete this lzw.read_from hack.
if (g.pkgName == "lzw") && (g.currFunk.astFunc.FuncName().Str(g.tm) == "read_from") {
if g.currFunk.astFunc.Effect().Optional() {
b.writes("goto exit;exit:") // The goto avoids the "unused label" warning.
}
if g.currFunk.derivedVars != nil {
for _, o := range g.currFunk.astFunc.In().Fields() {
o := o.AsField()
if err := g.writeSaveDerivedVar(b, "", aPrefix, o.Name(), o.XType()); err != nil {
@@ -346,16 +346,6 @@ func (g *gen) writeFuncImplEpilogue(b *buffer) error {
}
if g.currFunk.astFunc.Effect().Optional() {
b.writes("goto exit;exit:") // The goto avoids the "unused label" warning.
for _, o := range g.currFunk.astFunc.In().Fields() {
o := o.AsField()
if err := g.writeSaveDerivedVar(b, "", aPrefix, o.Name(), o.XType()); err != nil {
return err
}
}
b.writes("\n")
if g.currFunk.astFunc.Public() {
b.writes("if (wuffs_base__status__is_error(status)) { " +
"self->private_impl.magic = WUFFS_BASE__DISABLED; }\n")
+2 -12
View File
@@ -27,7 +27,7 @@ var errNeedDerivedVar = errors.New("internal: need derived var")
func (g *gen) needDerivedVar(name t.ID) bool {
for _, o := range g.currFunk.astFunc.Body() {
err := o.Walk(func(p *a.Node) error {
// Look for p matching "in.name.etc(etc)".
// Look for p matching "args.name.etc(etc)".
if p.Kind() != a.KExpr {
return nil
}
@@ -59,17 +59,7 @@ func (g *gen) needDerivedVar(name t.ID) bool {
func (g *gen) findDerivedVars() {
for _, o := range g.currFunk.astFunc.In().Fields() {
o := o.AsField()
oTyp := o.XType()
if oTyp.Decorator() != 0 {
continue
}
switch oTyp.QID() {
default:
continue
case t.QID{t.IDBase, t.IDIOReader}, t.QID{t.IDBase, t.IDIOWriter}:
// No-op.
}
if !g.needDerivedVar(o.Name()) {
if !o.XType().IsIOType() || !g.needDerivedVar(o.Name()) {
continue
}
if g.currFunk.derivedVars == nil {