mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +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
+1
-6
@@ -846,7 +846,6 @@ func NewFunc(flags Flags, filename string, line uint32, receiverName t.ID, funcN
|
||||
|
||||
// Status is "error (RHS) ID2" or "suspension (RHS) ID2":
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID0: <IDError|IDSuspension>
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: message
|
||||
type Status Node
|
||||
@@ -855,19 +854,15 @@ func (n *Status) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *Status) Public() bool { return n.flags&FlagsPublic != 0 }
|
||||
func (n *Status) Filename() string { return n.filename }
|
||||
func (n *Status) Line() uint32 { return n.line }
|
||||
func (n *Status) Keyword() t.ID { return n.id0 }
|
||||
func (n *Status) QID() t.QID { return t.QID{n.id1, n.id2} }
|
||||
func (n *Status) Value() *Expr { return n.rhs.AsExpr() }
|
||||
|
||||
func NewStatus(flags Flags, filename string, line uint32, keyword t.ID, value *Expr, message t.ID) *Status {
|
||||
func NewStatus(flags Flags, filename string, line uint32, message t.ID) *Status {
|
||||
return &Status{
|
||||
kind: KStatus,
|
||||
flags: flags,
|
||||
filename: filename,
|
||||
line: line,
|
||||
id0: keyword,
|
||||
id2: message,
|
||||
rhs: value.AsNode(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,8 +177,6 @@ type Checker struct {
|
||||
builtInSliceFuncs map[t.QQID]*a.Func
|
||||
builtInTableFuncs map[t.QQID]*a.Func
|
||||
unsortedStructs []*a.Struct
|
||||
|
||||
statusByValue [256]t.ID
|
||||
}
|
||||
|
||||
func (c *Checker) PackageID() uint32 { return c.packageID }
|
||||
@@ -298,33 +296,6 @@ func (c *Checker) checkStatus(node *a.Node) error {
|
||||
}
|
||||
c.statuses[qid] = n
|
||||
|
||||
q := &checker{
|
||||
c: c,
|
||||
tm: c.tm,
|
||||
}
|
||||
if err := q.tcheckExpr(n.Value(), 0); err != nil {
|
||||
return fmt.Errorf("%v in status %s", err, qid.Str(c.tm))
|
||||
}
|
||||
if _, err := q.bcheckExpr(n.Value(), 0); err != nil {
|
||||
return fmt.Errorf("%v in status %s", err, qid.Str(c.tm))
|
||||
}
|
||||
|
||||
if cv := n.Value().ConstValue(); cv == nil {
|
||||
return fmt.Errorf("status %s value is not a constant expression", qid.Str(c.tm))
|
||||
} else if cv.Cmp(zero) <= 0 || oneTwentyEight.Cmp(cv) <= 0 {
|
||||
return fmt.Errorf("status %s value %v is out of range [0x01..0x7F]", qid.Str(c.tm), cv)
|
||||
} else if n.QID()[0] == 0 {
|
||||
x := uint8(cv.Int64())
|
||||
if n.Keyword() == t.IDError {
|
||||
x = -x
|
||||
}
|
||||
if other := c.statusByValue[x]; other != 0 {
|
||||
return fmt.Errorf("duplicate %s value 0x%02X: %s and %s",
|
||||
n.Keyword().Str(c.tm), cv, other.Str(c.tm), n.QID()[1].Str(c.tm))
|
||||
}
|
||||
c.statusByValue[x] = n.QID()[1]
|
||||
}
|
||||
|
||||
setPlaceholderMBoundsMType(n.AsNode())
|
||||
return nil
|
||||
}
|
||||
|
||||
+3
-12
@@ -489,22 +489,13 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
case t.IDDot:
|
||||
return q.tcheckDot(n, depth)
|
||||
|
||||
// TODO: remove all but t.IDStatus.
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
nominalKeyword := n.Operator()
|
||||
declaredKeyword := t.ID(0)
|
||||
if s, ok := q.c.statuses[n.StatusQID()]; ok {
|
||||
declaredKeyword = s.Keyword()
|
||||
} else {
|
||||
if _, ok := q.c.statuses[n.StatusQID()]; !ok {
|
||||
msg, _ := t.Unescape(n.Ident().Str(q.tm))
|
||||
z, ok := builtin.StatusMap[msg]
|
||||
if !ok {
|
||||
if _, ok := builtin.StatusMap[msg]; !ok {
|
||||
return fmt.Errorf("check: no error or status with message %q", msg)
|
||||
}
|
||||
declaredKeyword = z.Keyword
|
||||
}
|
||||
if nominalKeyword != declaredKeyword {
|
||||
return fmt.Errorf("check: status literal says %q but declaration says %q",
|
||||
nominalKeyword.Str(q.tm), declaredKeyword.Str(q.tm))
|
||||
}
|
||||
n.SetMType(typeExprStatus)
|
||||
return nil
|
||||
|
||||
+2
-18
@@ -221,23 +221,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
in := a.NewStruct(0, p.filename, line, t.IDArgs, argFields)
|
||||
return a.NewFunc(flags, p.filename, line, id0, id1, in, out, asserts, body).AsNode(), nil
|
||||
|
||||
case t.IDError, t.IDSuspension:
|
||||
keyword := p.src[0].ID
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDOpenParen {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected "(", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
value, err := p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if x := p.peek1(); x != t.IDCloseParen {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ")", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
case t.IDStatus:
|
||||
p.src = p.src[1:]
|
||||
|
||||
message := p.peek1()
|
||||
@@ -251,7 +235,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
return nil, fmt.Errorf(`parse: expected (implicit) ";", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
return a.NewStatus(flags, p.filename, line, keyword, value, message).AsNode(), nil
|
||||
return a.NewStatus(flags, p.filename, line, message).AsNode(), nil
|
||||
|
||||
case t.IDStruct:
|
||||
p.src = p.src[1:]
|
||||
|
||||
Reference in new issue
Block a user