mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +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",
|
||||
}
|
||||
|
||||
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() {
|
||||
// The +1 is for the error bit (the sign bit).
|
||||
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
|
||||
|
||||
const (
|
||||
|
||||
@@ -122,8 +122,16 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
retExpr := (*a.Expr)(nil)
|
||||
if n.Keyword() != 0 {
|
||||
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 {
|
||||
ret.name = fmt.Sprintf("%sSTATUS_OK", g.PKGPREFIX)
|
||||
ret.name = g.PKGPREFIX + "STATUS_OK"
|
||||
}
|
||||
if g.currFunk.suspendible {
|
||||
b.writes("status = ")
|
||||
|
||||
Reference in new issue
Block a user