mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Remove some hard coded bcheckExprOther checks
This commit is contained in:
1 parent
351fa593c6
commit
8d05db48a4
2 files changed
+1
-77
No files matched your search
+1
-33
@@ -790,33 +790,6 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
||||
if isInSrc(q.tm, n, t.IDReadU8, 0) || isInSrc(q.tm, n, t.IDUnreadU8, 0) ||
|
||||
isInSrc(q.tm, n, t.IDReadU16BE, 0) || isInSrc(q.tm, n, t.IDReadU32BE, 0) ||
|
||||
isInSrc(q.tm, n, t.IDReadU32BE, 0) || isInSrc(q.tm, n, t.IDReadU32LE, 0) ||
|
||||
isInSrc(q.tm, n, t.IDSkip32, 1) || isInSrc(q.tm, n, t.IDSinceMark, 0) ||
|
||||
isInSrc(q.tm, n, t.IDMark, 0) || isInSrc(q.tm, n, t.IDLimit, 1) ||
|
||||
isInDst(q.tm, n, t.IDCopyFromSlice, 1) || isInDst(q.tm, n, t.IDCopyFromSlice32, 2) ||
|
||||
isInDst(q.tm, n, t.IDCopyFromReader32, 2) || isInDst(q.tm, n, t.IDCopyFromHistory32, 2) ||
|
||||
isInDst(q.tm, n, t.IDWriteU8, 1) || isInDst(q.tm, n, t.IDSinceMark, 0) ||
|
||||
isInDst(q.tm, n, t.IDMark, 0) || isInDst(q.tm, n, t.IDIsMarked, 0) ||
|
||||
isThatMethod(q.tm, n, t.IDMark, 0) || isThatMethod(q.tm, n, t.IDLimit, 1) ||
|
||||
isThatMethod(q.tm, n, t.IDSinceMark, 0) {
|
||||
|
||||
for _, o := range n.Args() {
|
||||
a := o.Arg().Value()
|
||||
// TODO: check that the arg range at the caller and the
|
||||
// signature are compatible.
|
||||
aMin, aMax, err := q.bcheckExpr(a, depth)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
// TODO: check that aMin and aMax is within the function's
|
||||
// declared arg bounds.
|
||||
_, _ = aMin, aMax
|
||||
}
|
||||
break
|
||||
}
|
||||
// TODO: delete this hack that only matches "foo.bar_bits(etc)".
|
||||
if isThatMethod(q.tm, n, t.IDLowBits, 1) || isThatMethod(q.tm, n, t.IDHighBits, 1) {
|
||||
a := n.Args()[0].Arg().Value()
|
||||
@@ -835,12 +808,6 @@ 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 isThatMethod(q.tm, n, t.IDIsError, 0) || isThatMethod(q.tm, n, t.IDIsOK, 0) ||
|
||||
isThatMethod(q.tm, n, t.IDIsSuspension, 0) || isThatMethod(q.tm, n, t.IDSuffix, 1) {
|
||||
// TODO: should return be break? Ditto below.
|
||||
return nil, nil, nil
|
||||
}
|
||||
// TODO: delete this hack that only matches "foo.set_literal_width(etc)".
|
||||
if isThatMethod(q.tm, n, q.tm.ByName("set_literal_width"), 1) {
|
||||
a := n.Args()[0].Arg().Value()
|
||||
@@ -851,6 +818,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
if aMin.Cmp(big.NewInt(2)) < 0 || aMax.Cmp(big.NewInt(8)) > 0 {
|
||||
return nil, nil, fmt.Errorf("check: %q not in range [2..8]", a.Str(q.tm))
|
||||
}
|
||||
// TODO: should return be break?
|
||||
return nil, nil, nil
|
||||
}
|
||||
// TODO: delete this hack that only matches "foo.decode(etc)".
|
||||
|
||||
@@ -612,50 +612,6 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func isInSrc(tm *t.Map, n *a.Expr, methodName t.ID, nArgs int) bool {
|
||||
callSuspendible := methodName != t.IDSinceMark &&
|
||||
methodName != t.IDMark &&
|
||||
methodName != t.IDLimit
|
||||
if n.Operator() != t.IDOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.Operator() != t.IDDot || n.Ident() != methodName {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.Operator() != t.IDDot || n.Ident() != tm.ByName("src") {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.Operator() == 0 && n.Ident() == t.IDIn
|
||||
}
|
||||
|
||||
func isInDst(tm *t.Map, n *a.Expr, methodName t.ID, nArgs int) bool {
|
||||
callSuspendible := methodName != t.IDCopyFromReader32 &&
|
||||
methodName != t.IDCopyFromHistory32 &&
|
||||
methodName != t.IDCopyFromSlice32 &&
|
||||
methodName != t.IDCopyFromSlice &&
|
||||
methodName != t.IDSinceMark &&
|
||||
methodName != t.IDIsMarked &&
|
||||
methodName != t.IDMark &&
|
||||
methodName != t.IDLimit
|
||||
// TODO: check that n.Args() is "(x:bar)".
|
||||
if n.Operator() != t.IDOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.Operator() != t.IDDot || n.Ident() != methodName {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.Operator() != t.IDDot || n.Ident() != tm.ByName("dst") {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.Operator() == 0 && n.Ident() == t.IDIn
|
||||
}
|
||||
|
||||
// isThatMethod matches foo.methodName(etc) where etc has nArgs elements.
|
||||
func isThatMethod(tm *t.Map, n *a.Expr, methodName t.ID, nArgs int) bool {
|
||||
if k := n.Operator(); k != t.IDOpenParen && k != t.IDTry {
|
||||
|
||||
Reference in new issue
Block a user