mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 08:47:28 +01:00
Generate C code for "a[i] = x".
This commit is contained in:
1 parent
f5af981f15
commit
587bc2a55d
5 files changed
+69
-7
No files matched your search
+23
-2
@@ -304,6 +304,10 @@ func (q *checker) bcheckAssignment1(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, _, err := q.bcheckExpr(lhs, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lMin, lMax, err := q.bcheckTypeExpr(lhs.MType())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -630,8 +634,25 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprOther", n.ID0().Key())
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
// TODO.
|
||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprOther", n.ID0().Key())
|
||||
lhs := n.LHS().Expr()
|
||||
_, _, err := q.bcheckExpr(lhs, depth)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
rhs := n.RHS().Expr()
|
||||
rMin, rMax, err := q.bcheckExpr(rhs, depth)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
cv := lhs.MType().ArrayLength().ConstValue()
|
||||
if cv == nil {
|
||||
return nil, nil, fmt.Errorf("check: cannot determine constant array length for %q",
|
||||
lhs.MType().String(q.tm))
|
||||
}
|
||||
if rMin.Cmp(zero) < 0 || rMax.Cmp(cv) >= 0 {
|
||||
return nil, nil, fmt.Errorf("check: array index %q (of range %v..%v) out of range",
|
||||
rhs.String(q.tm), rMin, rMax)
|
||||
}
|
||||
|
||||
case t.KeyColon:
|
||||
// TODO.
|
||||
|
||||
+20
-1
@@ -349,7 +349,26 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
// n is an index.
|
||||
// TODO.
|
||||
lhs := n.LHS().Expr()
|
||||
if err := q.tcheckExpr(lhs, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
rhs := n.RHS().Expr()
|
||||
if err := q.tcheckExpr(rhs, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
lTyp := lhs.MType()
|
||||
if lTyp.PackageOrDecorator().Key() != t.KeyOpenBracket {
|
||||
return fmt.Errorf("%s is an array-index expression but %s has type %s, not an array type",
|
||||
n.String(q.tm), lhs.String(q.tm), lTyp.String(q.tm))
|
||||
}
|
||||
rTyp := rhs.MType()
|
||||
if !rTyp.IsNumType() {
|
||||
return fmt.Errorf("%s is an array-index expression but %s has type %s, not a numeric type",
|
||||
n.String(q.tm), rhs.String(q.tm), rTyp.String(q.tm))
|
||||
}
|
||||
n.SetMType(lTyp.Inner())
|
||||
return nil
|
||||
|
||||
case t.KeyColon:
|
||||
// n is a slice.
|
||||
|
||||
Reference in new issue
Block a user