mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 08:47:28 +01:00
Add a slice.suffix method.
This commit is contained in:
1 parent
51f2b183a2
commit
2fb9972bb9
10 files changed
+176
-2
No files matched your search
@@ -689,7 +689,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
return zero, bitMask(int(aMax.Int64())), nil
|
||||
}
|
||||
// TODO: delete this hack that only matches "foo.is_suspension(etc)".
|
||||
if isIsErrorOKSuspension(q.tm, n, t.KeyIsSuspension) {
|
||||
if isIsErrorOKSuspension(q.tm, n, t.KeyIsSuspension) || isIsPrefixSuffix(q.tm, n, t.KeySuffix) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
// TODO: delete this hack that only matches "foo.set_literal_width(etc)".
|
||||
|
||||
@@ -410,6 +410,23 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
n.SetMType(typeExprBool)
|
||||
return nil
|
||||
}
|
||||
// TODO: delete this hack that only matches "foo.suffix(etc)".
|
||||
if isIsPrefixSuffix(q.tm, n, t.KeySuffix) {
|
||||
foo := n.LHS().Expr().LHS().Expr()
|
||||
if err := q.tcheckExpr(foo, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
n.LHS().SetTypeChecked()
|
||||
n.LHS().Expr().SetMType(typeExprPlaceholder) // HACK.
|
||||
for _, o := range n.Args() {
|
||||
if err := q.tcheckArg(o.Arg(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
n.SetMType(typeExprSliceU8)
|
||||
return nil
|
||||
}
|
||||
// TODO: delete this hack that only matches "foo.set_literal_width(etc)".
|
||||
if isSetLiteralWidth(q.tm, n) {
|
||||
foo := n.LHS().Expr().LHS().Expr()
|
||||
@@ -597,6 +614,14 @@ func isIsErrorOKSuspension(tm *t.Map, n *a.Expr, methodName t.Key) bool {
|
||||
return n.ID0().Key() == t.KeyDot && n.ID1().Key() == methodName
|
||||
}
|
||||
|
||||
func isIsPrefixSuffix(tm *t.Map, n *a.Expr, methodName t.Key) bool {
|
||||
if n.ID0().Key() != t.KeyOpenParen || n.CallImpure() || len(n.Args()) != 1 {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.ID0().Key() == t.KeyDot && n.ID1().Key() == methodName
|
||||
}
|
||||
|
||||
func isSetLiteralWidth(tm *t.Map, n *a.Expr) bool {
|
||||
// TODO: check that n.Args() is "(lw:bar)".
|
||||
if n.ID0().Key() != t.KeyOpenParen || n.CallImpure() || len(n.Args()) != 1 {
|
||||
|
||||
Reference in new issue
Block a user