mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Generate C code for "a or b or c".
This commit is contained in:
1 parent
540274b57d
commit
ce2720fca1
5 files changed
+65
-3
No files matched your search
@@ -1240,7 +1240,15 @@ func (g *gen) writeExprAs(lhs *a.Expr, rhs *a.TypeExpr, rp replacementPolicy, de
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *gen) writeExprAssociativeOp(n *a.Expr, rp replacementPolicy, depth uint32) error {
|
func (g *gen) writeExprAssociativeOp(n *a.Expr, rp replacementPolicy, depth uint32) error {
|
||||||
// TODO.
|
opName := cOpNames[0xFF&n.ID0().Key()]
|
||||||
|
for i, o := range n.Args() {
|
||||||
|
if i != 0 {
|
||||||
|
g.writes(opName)
|
||||||
|
}
|
||||||
|
if err := g.writeExpr(o.Expr(), rp, parenthesesMandatory, depth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -297,7 +297,19 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
|||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
uint8_t t_1 = a_src->ptr[a_src->ri++];
|
uint8_t t_1 = a_src->ptr[a_src->ri++];
|
||||||
if ((t_0 != 71) || (t_1 != 73)) {
|
if (a_src->ri >= a_src->wi) {
|
||||||
|
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
||||||
|
: puffs_gif_status_short_read;
|
||||||
|
goto cleanup0;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
goto cleanup0;
|
||||||
|
}
|
||||||
|
uint8_t t_3 = a_src->ptr[a_src->ri++];
|
||||||
|
if ((t_0 != 71) || (t_1 != 73) || (t_2 != 70) || (t_3 != 56)) {
|
||||||
status = puffs_gif_error_bad_gif_header;
|
status = puffs_gif_error_bad_gif_header;
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -811,6 +811,24 @@ func (q *checker) bcheckExprBinaryOp(lhs *a.Expr, op t.Key, rhs *a.Expr, depth u
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *checker) bcheckExprAssociativeOp(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) {
|
func (q *checker) bcheckExprAssociativeOp(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) {
|
||||||
|
switch n.ID0().Key() {
|
||||||
|
// TODO.
|
||||||
|
case t.KeyXAssociativePlus:
|
||||||
|
case t.KeyXAssociativeStar:
|
||||||
|
case t.KeyXAssociativeAmp:
|
||||||
|
case t.KeyXAssociativePipe:
|
||||||
|
case t.KeyXAssociativeHat:
|
||||||
|
|
||||||
|
case t.KeyXAssociativeAnd, t.KeyXAssociativeOr:
|
||||||
|
for _, o := range n.Args() {
|
||||||
|
o := o.Expr()
|
||||||
|
if _, _, err := q.bcheckExpr(o, depth); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return zero, one, nil
|
||||||
|
}
|
||||||
|
|
||||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprAssociativeOp", n.ID0().Key())
|
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprAssociativeOp", n.ID0().Key())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -657,7 +657,29 @@ func (q *checker) setConstValueBinaryOp(n *a.Expr, l *big.Int, r *big.Int) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
|
func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
|
||||||
|
switch n.ID0().Key() {
|
||||||
// TODO.
|
// TODO.
|
||||||
|
case t.KeyXAssociativePlus:
|
||||||
|
case t.KeyXAssociativeStar:
|
||||||
|
case t.KeyXAssociativeAmp:
|
||||||
|
case t.KeyXAssociativePipe:
|
||||||
|
case t.KeyXAssociativeHat:
|
||||||
|
|
||||||
|
case t.KeyXAssociativeAnd, t.KeyXAssociativeOr:
|
||||||
|
for _, o := range n.Args() {
|
||||||
|
o := o.Expr()
|
||||||
|
if err := q.tcheckExpr(o, depth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !o.MType().IsBool() {
|
||||||
|
return fmt.Errorf("check: associative %q: %q, of type %q, does not have a boolean type",
|
||||||
|
n.ID0().AmbiguousForm().String(q.tm), o.String(q.tm), o.MType().String(q.tm))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n.SetMType(typeExprBool)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprAssociativeOp", n.ID0().Key())
|
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprAssociativeOp", n.ID0().Key())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ pub struct decoder?(
|
|||||||
)
|
)
|
||||||
|
|
||||||
pub func decoder.decode?(dst ptr buf1, src ptr buf1)() {
|
pub func decoder.decode?(dst ptr buf1, src ptr buf1)() {
|
||||||
if (in.src.read_u8?() != 0x47) or (in.src.read_u8?() != 0x49) {
|
// Read either "GIF87a" or "GIF89a".
|
||||||
|
if (in.src.read_u8?() != 0x47) or (in.src.read_u8?() != 0x49) or
|
||||||
|
(in.src.read_u8?() != 0x46) or (in.src.read_u8?() != 0x38) {
|
||||||
return error "bad GIF header"
|
return error "bad GIF header"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user