mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55:11 +01:00
Add a decoder.decode_lsd skeleton.
This commit is contained in:
1 parent
2543999c61
commit
8d1bf15d70
5 files changed
+35
-7
No files matched your search
@@ -1020,11 +1020,16 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
|||||||
}
|
}
|
||||||
g.writes(";\n")
|
g.writes(";\n")
|
||||||
|
|
||||||
} else if isThisDecodeHeader(g.tm, n) {
|
} else if isThisMethod(g.tm, n, "decode_header") {
|
||||||
g.printf("status = puffs_%s_%s_decode_header(self, %ssrc);\n",
|
g.printf("status = puffs_%s_%s_decode_header(self, %ssrc);\n",
|
||||||
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix)
|
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix)
|
||||||
g.writes("if (status) { goto cleanup0; }\n")
|
g.writes("if (status) { goto cleanup0; }\n")
|
||||||
|
|
||||||
|
} else if isThisMethod(g.tm, n, "decode_lsd") {
|
||||||
|
g.printf("status = puffs_%s_%s_decode_lsd(self, %ssrc);\n",
|
||||||
|
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix)
|
||||||
|
g.writes("if (status) { goto cleanup0; }\n")
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// TODO: fix this.
|
// TODO: fix this.
|
||||||
//
|
//
|
||||||
@@ -1190,13 +1195,13 @@ func isInDst(tm *t.Map, n *a.Expr, methodName t.Key) bool {
|
|||||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||||
}
|
}
|
||||||
|
|
||||||
func isThisDecodeHeader(tm *t.Map, n *a.Expr) bool {
|
func isThisMethod(tm *t.Map, n *a.Expr, methodName string) bool {
|
||||||
// TODO: check that n.Args() is "(src:in.src)".
|
// TODO: check that n.Args() is "(src:in.src)".
|
||||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 {
|
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
if n.ID0().Key() != t.KeyDot || n.ID1() != tm.ByName("decode_header") {
|
if n.ID0().Key() != t.KeyDot || n.ID1() != tm.ByName(methodName) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
|
|||||||
@@ -208,6 +208,9 @@ const char* puffs_gif_status_string(puffs_gif_status s) {
|
|||||||
puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
|
puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
|
||||||
puffs_base_buf1* a_src);
|
puffs_base_buf1* a_src);
|
||||||
|
|
||||||
|
puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
|
||||||
|
puffs_base_buf1* a_src);
|
||||||
|
|
||||||
// ---------------- Constructor and Destructor Implementations
|
// ---------------- Constructor and Destructor Implementations
|
||||||
|
|
||||||
// PUFFS_MAGIC is a magic number to check that constructors are called. It's
|
// PUFFS_MAGIC is a magic number to check that constructors are called. It's
|
||||||
@@ -297,6 +300,10 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
|||||||
if (status) {
|
if (status) {
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
|
status = puffs_gif_decoder_decode_lsd(self, a_src);
|
||||||
|
if (status) {
|
||||||
|
goto cleanup0;
|
||||||
|
}
|
||||||
|
|
||||||
cleanup0:
|
cleanup0:
|
||||||
self->private_impl.status = status;
|
self->private_impl.status = status;
|
||||||
@@ -332,6 +339,13 @@ puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
|
||||||
|
puffs_base_buf1* a_src) {
|
||||||
|
puffs_gif_status status = self->private_impl.status;
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self,
|
void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self,
|
||||||
uint32_t a_lw) {
|
uint32_t a_lw) {
|
||||||
if (!self) {
|
if (!self) {
|
||||||
|
|||||||
@@ -600,7 +600,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
|||||||
case t.KeyOpenParen:
|
case t.KeyOpenParen:
|
||||||
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
||||||
if isInSrcReadU8(q.tm, n) || isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) ||
|
if isInSrcReadU8(q.tm, n) || isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) ||
|
||||||
isThisDecodeHeader(q.tm, n) {
|
isThisMethod(q.tm, n, "decode_header") || isThisMethod(q.tm, n, "decode_lsd") {
|
||||||
|
|
||||||
for _, o := range n.Args() {
|
for _, o := range n.Args() {
|
||||||
// TODO: check that the arg range at the caller and the
|
// TODO: check that the arg range at the caller and the
|
||||||
|
|||||||
+3
-3
@@ -328,7 +328,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
// n is a function call.
|
// n is a function call.
|
||||||
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
||||||
if isInSrcReadU8(q.tm, n) || isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) ||
|
if isInSrcReadU8(q.tm, n) || isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) ||
|
||||||
isThisDecodeHeader(q.tm, n) {
|
isThisMethod(q.tm, n, "decode_header") || isThisMethod(q.tm, n, "decode_lsd") {
|
||||||
|
|
||||||
if err := q.tcheckExpr(n.LHS().Expr(), depth); err != nil {
|
if err := q.tcheckExpr(n.LHS().Expr(), depth); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -424,13 +424,13 @@ func isInDst(tm *t.Map, n *a.Expr, methodName t.Key) bool {
|
|||||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||||
}
|
}
|
||||||
|
|
||||||
func isThisDecodeHeader(tm *t.Map, n *a.Expr) bool {
|
func isThisMethod(tm *t.Map, n *a.Expr, methodName string) bool {
|
||||||
// TODO: check that n.Args() is "(src:in.src)".
|
// TODO: check that n.Args() is "(src:in.src)".
|
||||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 {
|
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
if n.ID0().Key() != t.KeyDot || n.ID1() != tm.ByName("decode_header") {
|
if n.ID0().Key() != t.KeyDot || n.ID1() != tm.ByName(methodName) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
|
|||||||
@@ -11,9 +11,12 @@ pub struct decoder?(
|
|||||||
|
|
||||||
pub func decoder.decode?(dst ptr buf1, src ptr buf1)() {
|
pub func decoder.decode?(dst ptr buf1, src ptr buf1)() {
|
||||||
this.decode_header?(src:in.src)
|
this.decode_header?(src:in.src)
|
||||||
|
this.decode_lsd?(src:in.src)
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode_header reads either "GIF87a" or "GIF89a".
|
// decode_header reads either "GIF87a" or "GIF89a".
|
||||||
|
//
|
||||||
|
// See the spec section 17 "Header" on page 7.
|
||||||
pri func decoder.decode_header?(src ptr buf1)() {
|
pri func decoder.decode_header?(src ptr buf1)() {
|
||||||
var c[6] u8
|
var c[6] u8
|
||||||
var i u8
|
var i u8
|
||||||
@@ -26,3 +29,9 @@ pri func decoder.decode_header?(src ptr buf1)() {
|
|||||||
return error "bad GIF header"
|
return error "bad GIF header"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decode_lsd reads the Logical Screen Descriptor.
|
||||||
|
//
|
||||||
|
// See the spec section 18 "Logical Screen Descriptor" on page 8.
|
||||||
|
pri func decoder.decode_lsd?(src ptr buf1)() {
|
||||||
|
}
|
||||||
Reference in new issue
Block a user