Add a high_bits method.

This commit is contained in:
Nigel Tao committed 2017-07-13 13:23:01 +10:00
1 parent 73a4f2b263
commit 7e9b3aab67
5 files changed
+55 -15

No files matched your search

+3 -3
View File
@@ -638,8 +638,8 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
}
break
}
// TODO: delete this hack that only matches "foo.low_bits(etc)".
if isLowBits(q.tm, n) {
// TODO: delete this hack that only matches "foo.bar_bits(etc)".
if isLowHighBits(q.tm, n, t.KeyLowBits) || isLowHighBits(q.tm, n, t.KeyHighBits) {
a := n.Args()[0].Arg().Value()
aMin, aMax, err := q.bcheckExpr(a, depth)
if err != nil {
@@ -650,7 +650,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
// a.MType() is u32. Checking this properly should fall out
// when a *a.TypeExpr can express function types.
}
// TODO: sixtyFour should actually be sizeof(n.LHS().Expr()).
// TODO: sixtyFour should actually be 8 * sizeof(n.LHS().Expr()).
if aMax.Cmp(sixtyFour) > 0 {
return nil, nil, fmt.Errorf("check: low_bits argument %q is possibly too large", a.String(q.tm))
}
+4 -4
View File
@@ -354,8 +354,8 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
n.SetMType(typeExprPlaceholder) // HACK.
return nil
}
// TODO: delete this hack that only matches "foo.low_bits(etc)".
if isLowBits(q.tm, n) {
// TODO: delete this hack that only matches "foo.bar_bits(etc)".
if isLowHighBits(q.tm, n, t.KeyLowBits) || isLowHighBits(q.tm, n, t.KeyHighBits) {
foo := n.LHS().Expr().LHS().Expr()
if err := q.tcheckExpr(foo, depth); err != nil {
return err
@@ -510,13 +510,13 @@ func isThisMethod(tm *t.Map, n *a.Expr, methodName string, nArgs int) bool {
return n.ID0() == 0 && n.ID1().Key() == t.KeyThis
}
func isLowBits(tm *t.Map, n *a.Expr) bool {
func isLowHighBits(tm *t.Map, n *a.Expr, methodName t.Key) bool {
// TODO: check that n.Args() is "(n:bar)".
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() == t.KeyLowBits
return n.ID0().Key() == t.KeyDot && n.ID1().Key() == methodName
}
func isSetLiteralWidth(tm *t.Map, n *a.Expr) bool {