mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Assign values, not just messages, to status codes
This commit is contained in:
1 parent
86010a17e2
commit
634789722d
10 files changed
+103
-59
No files matched your search
+15
-14
@@ -35,20 +35,21 @@ var numTypeBounds = [...][2]*big.Int{
|
||||
}
|
||||
|
||||
var (
|
||||
minusOne = big.NewInt(-1)
|
||||
zero = big.NewInt(+0)
|
||||
one = big.NewInt(+1)
|
||||
two = big.NewInt(+2)
|
||||
three = big.NewInt(+3)
|
||||
four = big.NewInt(+4)
|
||||
five = big.NewInt(+5)
|
||||
six = big.NewInt(+6)
|
||||
seven = big.NewInt(+7)
|
||||
eight = big.NewInt(+8)
|
||||
sixteen = big.NewInt(+16)
|
||||
thirtyTwo = big.NewInt(+32)
|
||||
sixtyFour = big.NewInt(+64)
|
||||
ffff = big.NewInt(0xFFFF)
|
||||
minusOne = big.NewInt(-1)
|
||||
zero = big.NewInt(+0)
|
||||
one = big.NewInt(+1)
|
||||
two = big.NewInt(+2)
|
||||
three = big.NewInt(+3)
|
||||
four = big.NewInt(+4)
|
||||
five = big.NewInt(+5)
|
||||
six = big.NewInt(+6)
|
||||
seven = big.NewInt(+7)
|
||||
eight = big.NewInt(+8)
|
||||
sixteen = big.NewInt(+16)
|
||||
thirtyTwo = big.NewInt(+32)
|
||||
sixtyFour = big.NewInt(+64)
|
||||
oneTwentyEight = big.NewInt(+128)
|
||||
ffff = big.NewInt(0xFFFF)
|
||||
|
||||
maxIntBits = big.NewInt(t.MaxIntBits)
|
||||
|
||||
|
||||
@@ -178,6 +178,8 @@ 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 }
|
||||
@@ -296,6 +298,30 @@ 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 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]
|
||||
}
|
||||
|
||||
n.Node().SetMType(typeExprPlaceholder)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user