mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
Remove status values
This commit is contained in:
1 parent
44e99d79cf
commit
203b45e869
13 files changed
+61
-146
No files matched your search
@@ -181,19 +181,9 @@ const (
|
||||
)
|
||||
|
||||
type status struct {
|
||||
cName string
|
||||
name string
|
||||
value int8
|
||||
msg string
|
||||
keyword t.ID
|
||||
public bool
|
||||
}
|
||||
|
||||
func (z status) cNamePrefix() string {
|
||||
if z.keyword == t.IDSuspension {
|
||||
return "suspension"
|
||||
}
|
||||
return "error"
|
||||
cName string
|
||||
msg string
|
||||
public bool
|
||||
}
|
||||
|
||||
type buffer []byte
|
||||
@@ -361,11 +351,11 @@ func (g *gen) genHeader(b *buffer) error {
|
||||
|
||||
b.writes("// ---------------- Status Codes\n\n")
|
||||
|
||||
for _, s := range g.statusList {
|
||||
if !s.public {
|
||||
for _, z := range g.statusList {
|
||||
if !z.public {
|
||||
continue
|
||||
}
|
||||
b.printf("extern const char* %s%s__%s;\n", g.pkgPrefix, s.cNamePrefix(), s.cName)
|
||||
b.printf("extern const char* %s;\n", z.cName)
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
@@ -418,8 +408,7 @@ func (g *gen) genImpl(b *buffer) error {
|
||||
if z.msg == "" {
|
||||
continue
|
||||
}
|
||||
b.printf("const char* %s%s__%s = \"%s%s: %s\";\n",
|
||||
g.pkgPrefix, z.cNamePrefix(), z.cName, z.msg[:1], g.pkgName, z.msg[1:])
|
||||
b.printf("const char* %s = \"%s%s: %s\";\n", z.cName, z.msg[:1], g.pkgName, z.msg[1:])
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
@@ -573,27 +562,20 @@ func (g *gen) sizeof(typ *a.TypeExpr) (uint32, error) {
|
||||
func (g *gen) gatherStatuses(b *buffer, n *a.Status) error {
|
||||
raw := n.QID()[1].Str(g.tm)
|
||||
msg, ok := t.Unescape(raw)
|
||||
if !ok {
|
||||
if !ok || msg == "" {
|
||||
return fmt.Errorf("bad status message %q", raw)
|
||||
}
|
||||
prefix := "suspension_"
|
||||
if n.Keyword() == t.IDError {
|
||||
prefix = "error_"
|
||||
errSus := "error__"
|
||||
if msg[0] == '$' {
|
||||
errSus = "suspension__"
|
||||
}
|
||||
value := int8(n.Value().ConstValue().Int64())
|
||||
if n.Keyword() == t.IDError {
|
||||
value = -value
|
||||
z := status{
|
||||
cName: g.pkgPrefix + errSus + cName(msg, ""),
|
||||
msg: msg,
|
||||
public: n.Public(),
|
||||
}
|
||||
s := status{
|
||||
cName: cName(msg, ""),
|
||||
name: strings.ToUpper(g.cName(prefix + msg)),
|
||||
value: value,
|
||||
msg: msg,
|
||||
keyword: n.Keyword(),
|
||||
public: n.Public(),
|
||||
}
|
||||
g.statusList = append(g.statusList, s)
|
||||
g.statusMap[n.QID()] = s
|
||||
g.statusList = append(g.statusList, z)
|
||||
g.statusMap[n.QID()] = z
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -210,12 +210,6 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth u
|
||||
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
if z := g.statusMap[n.StatusQID()]; z.cName != "" {
|
||||
b.writes(g.pkgPrefix)
|
||||
if z.keyword == t.IDSuspension {
|
||||
b.writes("suspension__")
|
||||
} else {
|
||||
b.writes("error__")
|
||||
}
|
||||
b.writes(z.cName)
|
||||
} else {
|
||||
msg, _ := t.Unescape(n.Ident().Str(g.tm))
|
||||
|
||||
+1
-2
@@ -310,8 +310,7 @@ func (h *genHelper) genWuffs(dirname string, qualifiedFilenames []string) error
|
||||
if !n.Public() {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(out, "pub %s (%s) %s\n",
|
||||
n.Keyword().Str(&h.tm), n.Value().Str(&h.tm), n.QID().Str(&h.tm))
|
||||
fmt.Fprintf(out, "pub status %s\n", n.QID().Str(&h.tm))
|
||||
|
||||
case a.KStruct:
|
||||
n := n.AsStruct()
|
||||
|
||||
Reference in new issue
Block a user