mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 00:47:56 +01:00
Remove some hard-coded output in writeExprOther
This commit is contained in:
1 parent
c0c805c36f
commit
1bc174ea77
2 files changed
+47
-54
No files matched your search
@@ -725,7 +725,7 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
|
|||||||
// Base types don't need further initialization.
|
// Base types don't need further initialization.
|
||||||
continue
|
continue
|
||||||
} else if qid[0] != 0 {
|
} else if qid[0] != 0 {
|
||||||
// See gen.writeCTypeName for a related TODO with otherPkg.
|
// See gen.packagePrefix for a related TODO with otherPkg.
|
||||||
otherPkg := g.tm.ByID(qid[0])
|
otherPkg := g.tm.ByID(qid[0])
|
||||||
prefix = "wuffs_" + otherPkg + "__"
|
prefix = "wuffs_" + otherPkg + "__"
|
||||||
} else if g.structMap[qid] == nil {
|
} else if g.structMap[qid] == nil {
|
||||||
|
|||||||
@@ -321,30 +321,6 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth u
|
|||||||
b.printf("((uint64_t)(%s - %s))", p0, p1)
|
b.printf("((uint64_t)(%s - %s))", p0, p1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if isThatMethod(g.tm, n, g.tm.ByName("update"), 1) {
|
|
||||||
// TODO: don't hard-code the class name or this.checksum.
|
|
||||||
class := "wuffs_crc32__ieee_hasher"
|
|
||||||
if g.pkgName == "zlib" {
|
|
||||||
class = "wuffs_adler32__hasher"
|
|
||||||
}
|
|
||||||
b.printf("%s__update(&self->private_impl.f_checksum, ", class)
|
|
||||||
a := n.Args()[0].Arg().Value()
|
|
||||||
if err := g.writeExpr(b, a, rp, depth); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
b.writes(")\n")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if isThatMethod(g.tm, n, g.tm.ByName("set_literal_width"), 1) {
|
|
||||||
// TODO: don't hard-code lzw.
|
|
||||||
b.printf("%slzw_decoder__set_literal_width(&self->private_impl.f_lzw, ", g.pkgPrefix)
|
|
||||||
a := n.Args()[0].Arg().Value()
|
|
||||||
if err := g.writeExpr(b, a, rp, depth); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
b.writes(")\n")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if isThatMethod(g.tm, n, g.tm.ByName("initialize"), 5) {
|
if isThatMethod(g.tm, n, g.tm.ByName("initialize"), 5) {
|
||||||
// TODO: don't hard-code a_dst.
|
// TODO: don't hard-code a_dst.
|
||||||
b.printf("wuffs_base__image_config__initialize(a_dst")
|
b.printf("wuffs_base__image_config__initialize(a_dst")
|
||||||
@@ -357,12 +333,6 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth u
|
|||||||
b.printf(")")
|
b.printf(")")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if isThatMethod(g.tm, n, t.IDReset, 0) {
|
|
||||||
// TODO: don't hard-code f_lzw.
|
|
||||||
b.writes("wuffs_gif__lzw_decoder__initialize(" +
|
|
||||||
"&self->private_impl.f_lzw, WUFFS_VERSION, 0)")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if isThatMethod(g.tm, n, t.IDSet, 1) || isThatMethod(g.tm, n, t.IDSet, 2) {
|
if isThatMethod(g.tm, n, t.IDSet, 1) || isThatMethod(g.tm, n, t.IDSet, 2) {
|
||||||
typ := "reader"
|
typ := "reader"
|
||||||
if len(n.Args()) == 1 {
|
if len(n.Args()) == 1 {
|
||||||
@@ -379,7 +349,27 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth u
|
|||||||
b.writes(")")
|
b.writes(")")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// TODO.
|
if isThatMethod(g.tm, n, t.IDReset, 0) {
|
||||||
|
// TODO: don't hard-code f_lzw.
|
||||||
|
b.writes("wuffs_gif__lzw_decoder__initialize(" +
|
||||||
|
"&self->private_impl.f_lzw, WUFFS_VERSION, 0)")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
method := n.LHS().Expr()
|
||||||
|
receiver := method.LHS().Expr()
|
||||||
|
qid := receiver.MType().QID()
|
||||||
|
b.printf("%s%s__%s(&", g.packagePrefix(qid), qid[1].Str(g.tm), method.Ident().Str(g.tm))
|
||||||
|
if err := g.writeExpr(b, receiver, rp, depth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, o := range n.Args() {
|
||||||
|
b.writeb(',')
|
||||||
|
if err := g.writeExpr(b, o.Arg().Value(), rp, depth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.writeb(')')
|
||||||
|
return nil
|
||||||
|
|
||||||
case t.IDOpenBracket:
|
case t.IDOpenBracket:
|
||||||
// n is an index.
|
// n is an index.
|
||||||
@@ -609,29 +599,8 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fallback {
|
if fallback {
|
||||||
prefix := g.pkgPrefix
|
|
||||||
qid := innermost.QID()
|
qid := innermost.QID()
|
||||||
if qid == (t.QID{t.IDBase, t.IDStatus}) {
|
b.printf("%s%s", g.packagePrefix(qid), qid[1].Str(g.tm))
|
||||||
// No-op: special case "base.status" as being inside this package.
|
|
||||||
//
|
|
||||||
// TODO: change "base.status" in Wuffs code to just "status"? Or
|
|
||||||
// change the C code's "wuffs_foo__status" to "wuffs_base__status"?
|
|
||||||
} else if qid[0] != 0 {
|
|
||||||
otherPkg := g.tm.ByID(qid[0])
|
|
||||||
// TODO: map the "deflate" in "deflate.decoder" to the "deflate" in
|
|
||||||
// `use "std/deflate"`, and use the latter "deflate".
|
|
||||||
//
|
|
||||||
// This is pretty academic at the moment, since they're the same
|
|
||||||
// "deflate", but in the future, we might be able to rename used
|
|
||||||
// packages, e.g. `use "foo/bar" as "baz"`, so "baz.qux" would map
|
|
||||||
// to generating "wuffs_bar__qux".
|
|
||||||
//
|
|
||||||
// TODO: sanitize or validate otherPkg, e.g. that it's ASCII only?
|
|
||||||
//
|
|
||||||
// See gen.writeInitializerImpl for a similar use of otherPkg.
|
|
||||||
prefix = "wuffs_" + otherPkg + "__"
|
|
||||||
}
|
|
||||||
b.printf("%s%s", prefix, qid[1].Str(g.tm))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < numPointers; i++ {
|
for i := 0; i < numPointers; i++ {
|
||||||
@@ -652,6 +621,30 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *gen) packagePrefix(qid t.QID) string {
|
||||||
|
if qid == (t.QID{t.IDBase, t.IDStatus}) {
|
||||||
|
// No-op: special case "base.status" as being inside this package.
|
||||||
|
//
|
||||||
|
// TODO: change "base.status" in Wuffs code to just "status"? Or
|
||||||
|
// change the C code's "wuffs_foo__status" to "wuffs_base__status"?
|
||||||
|
} else if qid[0] != 0 {
|
||||||
|
otherPkg := g.tm.ByID(qid[0])
|
||||||
|
// TODO: map the "deflate" in "deflate.decoder" to the "deflate" in
|
||||||
|
// `use "std/deflate"`, and use the latter "deflate".
|
||||||
|
//
|
||||||
|
// This is pretty academic at the moment, since they're the same
|
||||||
|
// "deflate", but in the future, we might be able to rename used
|
||||||
|
// packages, e.g. `use "foo/bar" as "baz"`, so "baz.qux" would map
|
||||||
|
// to generating "wuffs_bar__qux".
|
||||||
|
//
|
||||||
|
// TODO: sanitize or validate otherPkg, e.g. that it's ASCII only?
|
||||||
|
//
|
||||||
|
// See gen.writeInitializerImpl for a similar use of otherPkg.
|
||||||
|
return "wuffs_" + otherPkg + "__"
|
||||||
|
}
|
||||||
|
return g.pkgPrefix
|
||||||
|
}
|
||||||
|
|
||||||
var cTypeNames = [...]string{
|
var cTypeNames = [...]string{
|
||||||
t.IDI8: "int8_t",
|
t.IDI8: "int8_t",
|
||||||
t.IDI16: "int16_t",
|
t.IDI16: "int16_t",
|
||||||
|
|||||||
Reference in new issue
Block a user