mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Prepare array and slice tokens
This commit is contained in:
1 parent
97aab37462
commit
2b91e7861c
12 files changed
+81
-68
No files matched your search
@@ -439,9 +439,10 @@ func (q *checker) bcheckAssignment1(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
||||
case t.KeyPtr:
|
||||
// TODO: handle.
|
||||
return nil
|
||||
case t.KeyOpenBracket:
|
||||
case t.KeyArray:
|
||||
// TODO: handle.
|
||||
return nil
|
||||
// TODO: t.KeySlice?
|
||||
}
|
||||
|
||||
_, _, err := q.bcheckExpr(lhs, 0)
|
||||
@@ -890,7 +891,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
}
|
||||
|
||||
lengthExpr := (*a.Expr)(nil)
|
||||
if lTyp := lhs.MType(); lTyp.Decorator().Key() == t.KeyOpenBracket {
|
||||
if lTyp := lhs.MType(); lTyp.IsArrayType() {
|
||||
lengthExpr = lTyp.ArrayLength()
|
||||
} else {
|
||||
lengthExpr = makeSliceLengthExpr(lhs)
|
||||
@@ -912,7 +913,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
}
|
||||
|
||||
lengthExpr := (*a.Expr)(nil)
|
||||
if lTyp := lhs.MType(); lTyp.Decorator().Key() == t.KeyOpenBracket {
|
||||
if lTyp := lhs.MType(); lTyp.IsArrayType() {
|
||||
lengthExpr = lTyp.ArrayLength()
|
||||
} else {
|
||||
lengthExpr = makeSliceLengthExpr(lhs)
|
||||
@@ -1187,7 +1188,7 @@ func (q *checker) bcheckTypeExpr(typ *a.TypeExpr) (*big.Int, *big.Int, error) {
|
||||
|
||||
switch typ.Decorator().Key() {
|
||||
// TODO: case t.KeyOpenParen.
|
||||
case t.KeyPtr, t.KeyOpenBracket, t.KeyColon:
|
||||
case t.KeyPtr, t.KeyArray, t.KeySlice:
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -332,7 +332,7 @@ func (c *Checker) checkConst(node *a.Node) error {
|
||||
|
||||
nLists := 0
|
||||
typ := n.XType()
|
||||
for typ.Decorator().Key() == t.KeyOpenBracket {
|
||||
for typ.IsArrayType() {
|
||||
if nLists == a.MaxTypeExprDepth {
|
||||
return fmt.Errorf("check: type expression recursion depth too large")
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ var (
|
||||
typeExprIOWriter = a.NewTypeExpr(0, 0, t.IDIOWriter, nil, nil, nil)
|
||||
typeExprImageConfig = a.NewTypeExpr(0, 0, t.IDImageConfig, nil, nil, nil)
|
||||
|
||||
typeExprSliceU8 = a.NewTypeExpr(t.IDColon, 0, 0, nil, nil, typeExprU8)
|
||||
typeExprSliceU8 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, typeExprU8)
|
||||
|
||||
// TODO: delete this.
|
||||
typeExprPlaceholder = a.NewTypeExpr(0, 0, t.IDU8, nil, nil, nil)
|
||||
@@ -139,8 +139,7 @@ func (c *Checker) resolveFunc(typ *a.TypeExpr) (*a.Func, error) {
|
||||
lTyp := typ.Receiver()
|
||||
lQID := lTyp.QID()
|
||||
qqid := t.QQID{lQID[0], lQID[1], typ.FuncName()}
|
||||
if lTyp.Decorator().Key() == t.KeyColon {
|
||||
// lTyp is a slice.
|
||||
if lTyp.IsSliceType() {
|
||||
qqid[0] = 0
|
||||
qqid[1] = t.IDDiamond
|
||||
if f, err := c.builtInSliceFunc(qqid); err != nil {
|
||||
|
||||
+8
-9
@@ -465,7 +465,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
return err
|
||||
}
|
||||
lTyp := lhs.MType()
|
||||
if key := lTyp.Decorator().Key(); key != t.KeyOpenBracket && key != t.KeyColon {
|
||||
if key := lTyp.Decorator().Key(); key != t.KeyArray && key != t.KeySlice {
|
||||
return fmt.Errorf("check: %s is an index expression but %s has type %s, not an array or slice type",
|
||||
n.Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
|
||||
}
|
||||
@@ -510,9 +510,9 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
default:
|
||||
return fmt.Errorf("check: %s is a slice expression but %s has type %s, not an array or slice type",
|
||||
n.Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
|
||||
case t.KeyOpenBracket:
|
||||
n.SetMType(a.NewTypeExpr(t.IDColon, 0, 0, nil, nil, lTyp.Inner()))
|
||||
case t.KeyColon:
|
||||
case t.KeyArray:
|
||||
n.SetMType(a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, lTyp.Inner()))
|
||||
case t.KeySlice:
|
||||
n.SetMType(lTyp)
|
||||
}
|
||||
return nil
|
||||
@@ -689,8 +689,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
lQID := lTyp.QID()
|
||||
qqid := t.QQID{lQID[0], lQID[1], n.Ident()}
|
||||
|
||||
if key := lTyp.Decorator().Key(); key == t.KeyColon {
|
||||
// lTyp is a slice.
|
||||
if lTyp.IsSliceType() {
|
||||
qqid[0] = 0
|
||||
qqid[1] = t.IDDiamond
|
||||
if f, err := q.c.builtInSliceFunc(qqid); err != nil {
|
||||
@@ -700,7 +699,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.Ident(), lTyp.Node(), nil, nil))
|
||||
return nil
|
||||
} else if key != 0 {
|
||||
} else if lTyp.Decorator().Key() != 0 {
|
||||
return fmt.Errorf("check: invalid type %q for dot-expression LHS %q", lTyp.Str(q.tm), lhs.Str(q.tm))
|
||||
}
|
||||
|
||||
@@ -1056,7 +1055,7 @@ swtch:
|
||||
}
|
||||
return fmt.Errorf("check: %q is not a type", typ.Str(q.tm))
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
case t.KeyArray:
|
||||
aLen := typ.ArrayLength()
|
||||
if err := q.tcheckExpr(aLen, 0); err != nil {
|
||||
return err
|
||||
@@ -1067,7 +1066,7 @@ swtch:
|
||||
fallthrough
|
||||
|
||||
// TODO: also check t.KeyNptr? Where else should we look for nptr?
|
||||
case t.KeyPtr, t.KeyColon:
|
||||
case t.KeyPtr, t.KeySlice:
|
||||
if err := q.tcheckTypeExpr(typ.Inner(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user