mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55:11 +01:00
Generate C code for "var x[N] T".
This commit is contained in:
1 parent
d24e3ab7a7
commit
380fe3d76f
3 files changed
+39
-57
No files matched your search
+15
-5
@@ -864,13 +864,23 @@ func (g *gen) writeStatement(n *a.Node, depth uint32) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.printf("%s%s = ", vPrefix, n.Name().String(g.tm))
|
if n.XType().Decorator().Key() == t.KeyOpenBracket {
|
||||||
if v := n.Value(); v != nil {
|
if n.Value() != nil {
|
||||||
if err := g.writeExpr(v, replaceCallSuspendibles, parenthesesMandatory, 0); err != nil {
|
return fmt.Errorf("TODO: array initializers for non-zero default values")
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
// TODO: arrays of arrays.
|
||||||
|
cv := n.XType().ArrayLength().ConstValue()
|
||||||
|
// TODO: check that cv is within size_t's range.
|
||||||
|
g.printf("for (size_t i = 0; i < %d; i++) { %s%s[i] = 0; }\n", cv, vPrefix, n.Name().String(g.tm))
|
||||||
} else {
|
} else {
|
||||||
g.writeb('0')
|
g.printf("%s%s = ", vPrefix, n.Name().String(g.tm))
|
||||||
|
if v := n.Value(); v != nil {
|
||||||
|
if err := g.writeExpr(v, replaceCallSuspendibles, parenthesesMandatory, 0); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
g.writeb('0')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
g.writes(";\n")
|
g.writes(";\n")
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+17
-44
@@ -302,52 +302,25 @@ 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 status = self->private_impl.status;
|
puffs_gif_status status = self->private_impl.status;
|
||||||
|
|
||||||
uint8_t v_c;
|
uint8_t v_c[6];
|
||||||
|
uint8_t v_i;
|
||||||
|
|
||||||
if (a_src->ri >= a_src->wi) {
|
for (size_t i = 0; i < 6; i++) {
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
v_c[i] = 0;
|
||||||
: puffs_gif_status_short_read;
|
};
|
||||||
return status;
|
v_i = 0;
|
||||||
|
while (v_i < 6) {
|
||||||
|
if (a_src->ri >= a_src->wi) {
|
||||||
|
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
||||||
|
: puffs_gif_status_short_read;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
uint8_t t_0 = a_src->ptr[a_src->ri++];
|
||||||
|
v_c[v_i] = t_0;
|
||||||
|
v_i += 1;
|
||||||
}
|
}
|
||||||
uint8_t t_0 = a_src->ptr[a_src->ri++];
|
if ((v_c[0] != 71) || (v_c[1] != 73) || (v_c[2] != 70) || (v_c[3] != 56) ||
|
||||||
if (a_src->ri >= a_src->wi) {
|
((v_c[4] != 55) && (v_c[4] != 57)) || (v_c[5] != 97)) {
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
|
||||||
: puffs_gif_status_short_read;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
uint8_t t_1 = a_src->ptr[a_src->ri++];
|
|
||||||
if (a_src->ri >= a_src->wi) {
|
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
|
||||||
: puffs_gif_status_short_read;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
uint8_t t_2 = a_src->ptr[a_src->ri++];
|
|
||||||
if (a_src->ri >= a_src->wi) {
|
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
|
||||||
: puffs_gif_status_short_read;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
uint8_t t_3 = a_src->ptr[a_src->ri++];
|
|
||||||
if ((t_0 != 71) || (t_1 != 73) || (t_2 != 70) || (t_3 != 56)) {
|
|
||||||
return puffs_gif_error_bad_gif_header;
|
|
||||||
}
|
|
||||||
if (a_src->ri >= a_src->wi) {
|
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
|
||||||
: puffs_gif_status_short_read;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
uint8_t t_4 = a_src->ptr[a_src->ri++];
|
|
||||||
v_c = t_4;
|
|
||||||
if ((v_c != 55) && (v_c != 57)) {
|
|
||||||
return puffs_gif_error_bad_gif_header;
|
|
||||||
}
|
|
||||||
if (a_src->ri >= a_src->wi) {
|
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
|
||||||
: puffs_gif_status_short_read;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
uint8_t t_5 = a_src->ptr[a_src->ri++];
|
|
||||||
if (t_5 != 97) {
|
|
||||||
return puffs_gif_error_bad_gif_header;
|
return puffs_gif_error_bad_gif_header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,15 +15,14 @@ pub func decoder.decode?(dst ptr buf1, src ptr buf1)() {
|
|||||||
|
|
||||||
// decode_header reads either "GIF87a" or "GIF89a".
|
// decode_header reads either "GIF87a" or "GIF89a".
|
||||||
pri func decoder.decode_header?(src ptr buf1)() {
|
pri func decoder.decode_header?(src ptr buf1)() {
|
||||||
if (in.src.read_u8?() != 0x47) or (in.src.read_u8?() != 0x49) or
|
var c[6] u8
|
||||||
(in.src.read_u8?() != 0x46) or (in.src.read_u8?() != 0x38) {
|
var i u8
|
||||||
return error "bad GIF header"
|
while i < 6 {
|
||||||
|
c[i] = in.src.read_u8?()
|
||||||
|
i += 1
|
||||||
}
|
}
|
||||||
var c u8 = in.src.read_u8?()
|
if (c[0] != 0x47) or (c[1] != 0x49) or (c[2] != 0x46) or (c[3] != 0x38) or
|
||||||
if (c != 0x37) and (c != 0x39) {
|
((c[4] != 0x37) and (c[4] != 0x39)) or (c[5] != 0x61) {
|
||||||
return error "bad GIF header"
|
|
||||||
}
|
|
||||||
if in.src.read_u8?() != 0x61 {
|
|
||||||
return error "bad GIF header"
|
return error "bad GIF header"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user