mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +01:00
Allow explicit returns of built-in status codes.
This commit is contained in:
1 parent
2e883fcc23
commit
010c4db54f
7 files changed
+43
-12
No files matched your search
@@ -97,6 +97,12 @@ var builtInStatuses = [...]string{
|
|||||||
"suspension limited write",
|
"suspension limited write",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var builtInStatusSuffixes = map[string]string{
|
||||||
|
// TODO: fill in the rest of the built in statuses.
|
||||||
|
"short read": "SUSPENSION_SHORT_READ",
|
||||||
|
"short write": "SUSPENSION_SHORT_WRITE",
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// The +1 is for the error bit (the sign bit).
|
// The +1 is for the error bit (the sign bit).
|
||||||
if statusCodeNamespaceShift+base38.MaxBits+1 != 32 {
|
if statusCodeNamespaceShift+base38.MaxBits+1 != 32 {
|
||||||
@@ -107,6 +113,13 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func trimQuotes(s string) string {
|
||||||
|
if len(s) >= 2 && s[0] == '"' && s[len(s)-1] == '"' {
|
||||||
|
return s[1 : len(s)-1]
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
type replacementPolicy bool
|
type replacementPolicy bool
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -122,8 +122,16 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
|||||||
retExpr := (*a.Expr)(nil)
|
retExpr := (*a.Expr)(nil)
|
||||||
if n.Keyword() != 0 {
|
if n.Keyword() != 0 {
|
||||||
ret = g.statusMap[n.Message()]
|
ret = g.statusMap[n.Message()]
|
||||||
|
if ret.name == "" {
|
||||||
|
msg := trimQuotes(n.Message().String(g.tm))
|
||||||
|
suffix := builtInStatusSuffixes[msg]
|
||||||
|
if suffix == "" {
|
||||||
|
return fmt.Errorf("no status code for %q", msg)
|
||||||
|
}
|
||||||
|
ret.name = g.PKGPREFIX + suffix
|
||||||
|
}
|
||||||
} else if retExpr = n.Value(); retExpr == nil {
|
} else if retExpr = n.Value(); retExpr == nil {
|
||||||
ret.name = fmt.Sprintf("%sSTATUS_OK", g.PKGPREFIX)
|
ret.name = g.PKGPREFIX + "STATUS_OK"
|
||||||
}
|
}
|
||||||
if g.currFunk.suspendible {
|
if g.currFunk.suspendible {
|
||||||
b.writes("status = ")
|
b.writes("status = ")
|
||||||
|
|||||||
+2
-2
@@ -1365,8 +1365,8 @@ puffs_flate_status puffs_flate_decoder_decode_huffman(
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
v_length -= v_n;
|
v_length -= v_n;
|
||||||
status = PUFFS_FLATE_ERROR_BAD_HUFFMAN_CODE;
|
status = PUFFS_FLATE_SUSPENSION_SHORT_WRITE;
|
||||||
goto exit;
|
goto suspend;
|
||||||
}
|
}
|
||||||
label_5_break:;
|
label_5_break:;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,6 +95,12 @@ type Struct struct {
|
|||||||
Struct *a.Struct
|
Struct *a.Struct
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var builtInStatuses = map[string]t.ID{
|
||||||
|
// TODO: fill in the rest of the built in statuses.
|
||||||
|
"short read": t.IDSuspension,
|
||||||
|
"short write": t.IDSuspension,
|
||||||
|
}
|
||||||
|
|
||||||
func Check(tm *t.Map, files ...*a.File) (*Checker, error) {
|
func Check(tm *t.Map, files ...*a.File) (*Checker, error) {
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
|
|||||||
+11
-4
@@ -120,10 +120,17 @@ func (q *checker) tcheckStatement(n *a.Node) error {
|
|||||||
case a.KReturn:
|
case a.KReturn:
|
||||||
n := n.Return()
|
n := n.Return()
|
||||||
if nk := n.Keyword(); nk != 0 {
|
if nk := n.Keyword(); nk != 0 {
|
||||||
if s, ok := q.c.statuses[n.Message()]; !ok {
|
sk := t.ID(0)
|
||||||
return fmt.Errorf("check: no error or status with message %q",
|
if s, ok := q.c.statuses[n.Message()]; ok {
|
||||||
trimQuotes(n.Message().String(q.tm)))
|
sk = s.Status.Keyword()
|
||||||
} else if sk := s.Status.Keyword(); nk != sk {
|
} else {
|
||||||
|
msg := trimQuotes(n.Message().String(q.tm))
|
||||||
|
sk, ok = builtInStatuses[msg]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("check: no error or status with message %q", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if nk != sk {
|
||||||
return fmt.Errorf("check: return statement says %q but declaration says %q",
|
return fmt.Errorf("check: return statement says %q but declaration says %q",
|
||||||
nk.String(q.tm), sk.String(q.tm))
|
nk.String(q.tm), sk.String(q.tm))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,10 +351,7 @@ pri func decoder.decode_huffman?(dst writer1, src reader1)() {
|
|||||||
}
|
}
|
||||||
length -= n
|
length -= n
|
||||||
// TODO: distinguish between short and limited writes?
|
// TODO: distinguish between short and limited writes?
|
||||||
//
|
return suspension "short write"
|
||||||
// TODO: return suspension "short write" instead of this bogus
|
|
||||||
// return error "bad Huffman code".
|
|
||||||
return error "bad Huffman code"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -649,7 +649,7 @@ proc tests[] = {
|
|||||||
test_puffs_flate_decode_romeo, //
|
test_puffs_flate_decode_romeo, //
|
||||||
test_puffs_flate_decode_romeo_fixed, //
|
test_puffs_flate_decode_romeo_fixed, //
|
||||||
test_puffs_flate_decode_split_src, //
|
test_puffs_flate_decode_split_src, //
|
||||||
// test_puffs_flate_history_full, //
|
test_puffs_flate_history_full, //
|
||||||
test_puffs_flate_history_partial, //
|
test_puffs_flate_history_partial, //
|
||||||
test_puffs_flate_table_redirect, //
|
test_puffs_flate_table_redirect, //
|
||||||
test_puffs_zlib_decode_midsummer, //
|
test_puffs_zlib_decode_midsummer, //
|
||||||
|
|||||||
Reference in new issue
Block a user