def bound(a, b): if a is None and b is None: return IntUnbounded() elif a is None: return IntUpperBound(b) elif b is None: return IntLowerBound(a) else: return IntBound(a, b)
def __init__(self, box, level=None, known_class=None, intbound=None): OptValue.__init__(self, box, level, None, None) if isinstance(box, Const): return if intbound: self.intbound = intbound else: if isinstance(box, BoxInt): self.intbound = IntBound(MININT, MAXINT) else: self.intbound = IntUnbounded()
def __init__(self, value, is_opaque=False): self.is_opaque = is_opaque self.known_class = value.get_known_class() self.level = value.getlevel() if value.getintbound() is None: self.intbound = IntUnbounded() else: self.intbound = value.getintbound().clone() if value.is_constant(): self.constbox = value.box else: self.constbox = None self.position_in_notvirtuals = -1 self.lenbound = value.getlenbound()
def getintbound(self, op): assert op.type == 'i' op = get_box_replacement(op) if isinstance(op, ConstInt): return ConstIntBound(op.getint()) fw = op.get_forwarded() if fw is not None: if isinstance(fw, IntBound): return fw # rare case: fw might be a RawBufferPtrInfo return IntUnbounded() assert op.type == 'i' intbound = IntBound(MININT, MAXINT) op.set_forwarded(intbound) return intbound
def getintbound(self): return IntUnbounded()
def test_make(): for _, _, b1 in some_bounds(): for _, _, b2 in some_bounds(): lt = IntUnbounded() lt.make_lt(b1) lt.make_lt(b2) for n in nbr: c = const(n) if b1.known_le(c) or b2.known_le(c): assert lt.known_lt(c) else: assert not lt.known_lt(c) assert not lt.known_gt(c) assert not lt.known_ge(c) gt = IntUnbounded() gt.make_gt(b1) gt.make_gt(b2) for n in nbr: c = const(n) if b1.known_ge(c) or b2.known_ge(c): assert gt.known_gt(c) else: assert not gt.known_gt(c) assert not gt.known_lt(c) assert not gt.known_le(c) le = IntUnbounded() le.make_le(b1) le.make_le(b2) for n in nbr: c = const(n) if b1.known_le(c) or b2.known_le(c): assert le.known_le(c) else: assert not le.known_le(c) assert not le.known_gt(c) assert not le.known_ge(c) ge = IntUnbounded() ge.make_ge(b1) ge.make_ge(b2) for n in nbr: c = const(n) if b1.known_ge(c) or b2.known_ge(c): assert ge.known_ge(c) else: assert not ge.known_ge(c) assert not ge.known_lt(c) assert not ge.known_le(c) gl = IntUnbounded() gl.make_ge(b1) gl.make_le(b2) for n in nbr: c = const(n) if b1.known_ge(c): assert gl.known_ge(c) else: assert not gl.known_ge(c) assert not gl.known_gt(c) if b2.known_le(c): assert gl.known_le(c) else: assert not gl.known_le(c) assert not gl.known_lt(c)