mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 08:47:28 +01:00
First cut at a "[] u8" slice type.
This commit is contained in:
1 parent
ceedd8c3b9
commit
519ec373f2
15 files changed
+123
-32
No files matched your search
+5
-3
@@ -456,9 +456,9 @@ func NewJump(keyword t.ID, label t.ID) *Jump {
|
||||
// MaxTypeExprDepth is an advisory limit for a TypeExpr's recursion depth.
|
||||
const MaxTypeExprDepth = 63
|
||||
|
||||
// TypeExpr is a type expression, such as "u32", "u32[..8]", "pkg.foo", "ptr T"
|
||||
// or "[8] T":
|
||||
// - ID0: <0|package name|IDPtr|IDOpenBracket>
|
||||
// TypeExpr is a type expression, such as "u32", "u32[..8]", "pkg.foo", "ptr
|
||||
// T", "[8] T" or "[] T":
|
||||
// - ID0: <0|package name|IDPtr|IDOpenBracket|IDColon>
|
||||
// - ID1: <0|type name>
|
||||
// - LHS: <nil|Expr>
|
||||
// - MHS: <nil|Expr>
|
||||
@@ -468,6 +468,8 @@ const MaxTypeExprDepth = 63
|
||||
//
|
||||
// An IDOpenBracket ID0 means "[LHS] RHS". RHS is the inner type.
|
||||
//
|
||||
// An IDColon ID0 means "[] RHS". RHS is the inner type.
|
||||
//
|
||||
// Other ID0 values mean a (possibly package-qualified) type like "pkg.foo" or
|
||||
// "foo". ID0 is the "pkg" or zero, ID1 is the "foo". Such a type can be
|
||||
// refined as "foo[LHS..MHS]". LHS and MHS are Expr's, possibly nil. For
|
||||
|
||||
@@ -188,6 +188,9 @@ func (n *TypeExpr) appendString(buf []byte, tm *t.Map, depth uint32) []byte {
|
||||
buf = n.ArrayLength().appendString(buf, tm, false, 0)
|
||||
buf = append(buf, "] "...)
|
||||
return n.Inner().appendString(buf, tm, depth)
|
||||
case t.KeyColon:
|
||||
buf = append(buf, "[] "...)
|
||||
return n.Inner().appendString(buf, tm, depth)
|
||||
default:
|
||||
buf = append(buf, tm.ByID(n.Decorator())...)
|
||||
buf = append(buf, '.')
|
||||
|
||||
@@ -353,7 +353,7 @@ func (q *checker) bcheckAssignment1(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
||||
rMin, rMax := (*big.Int)(nil), (*big.Int)(nil)
|
||||
if op == t.IDEq {
|
||||
if cv := rhs.ConstValue(); cv != nil {
|
||||
if cv.Cmp(lMin) < 0 || cv.Cmp(lMax) > 0 {
|
||||
if (lMin != nil && cv.Cmp(lMin) < 0) || (lMax != nil && cv.Cmp(lMax) > 0) {
|
||||
return fmt.Errorf("check: constant %v is not within bounds [%v..%v]", cv, lMin, lMax)
|
||||
}
|
||||
return nil
|
||||
@@ -951,7 +951,7 @@ func (q *checker) bcheckTypeExpr(n *a.TypeExpr) (*big.Int, *big.Int, error) {
|
||||
}
|
||||
|
||||
switch n.Decorator().Key() {
|
||||
case t.KeyPtr, t.KeyOpenBracket:
|
||||
case t.KeyPtr, t.KeyOpenBracket, t.KeyColon:
|
||||
return nil, nil, nil
|
||||
}
|
||||
switch n.Name().Key() {
|
||||
|
||||
+3
-5
@@ -925,11 +925,6 @@ swtch:
|
||||
}
|
||||
return fmt.Errorf("check: %q is not a type", n.Name().String(q.tm))
|
||||
|
||||
case t.KeyPtr:
|
||||
if err := q.tcheckTypeExpr(n.Inner(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
aLen := n.ArrayLength()
|
||||
if err := q.tcheckExpr(aLen, 0); err != nil {
|
||||
@@ -938,6 +933,9 @@ swtch:
|
||||
if aLen.ConstValue() == nil {
|
||||
return fmt.Errorf("check: %q is not constant", aLen.String(q.tm))
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case t.KeyPtr, t.KeyColon:
|
||||
if err := q.tcheckTypeExpr(n.Inner(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+13
-8
@@ -346,20 +346,25 @@ func (p *parser) parseTypeExpr() (*a.TypeExpr, error) {
|
||||
|
||||
if p.peek1().Key() == t.KeyOpenBracket {
|
||||
p.src = p.src[1:]
|
||||
lhs, err := p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if x := p.peek1().Key(); x != t.KeyCloseBracket {
|
||||
got := p.tm.ByKey(x)
|
||||
return nil, fmt.Errorf(`parse: expected "]", got %q at %s:%d`, got, p.filename, p.line())
|
||||
decorator, lhs := t.IDColon, (*a.Expr)(nil)
|
||||
if p.peek1().Key() != t.KeyCloseBracket {
|
||||
decorator = t.IDOpenBracket
|
||||
var err error
|
||||
lhs, err = p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if x := p.peek1().Key(); x != t.KeyCloseBracket {
|
||||
got := p.tm.ByKey(x)
|
||||
return nil, fmt.Errorf(`parse: expected "]", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
rhs, err := p.parseTypeExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.NewTypeExpr(t.IDOpenBracket, 0, lhs, nil, rhs), nil
|
||||
return a.NewTypeExpr(decorator, 0, lhs, nil, rhs), nil
|
||||
}
|
||||
|
||||
pkg, name, err := p.parseQualifiedIdent()
|
||||
|
||||
Reference in new issue
Block a user