def walk_bv_to_bv(self, formula, args, **kwargs): #pylint: disable=unused-argument # We check that all children are BV and the same size target_bv_type = BVType(formula.bv_width()) for a in args: if not a == target_bv_type: return None return target_bv_type
def walk_bv_rotate(self, formula, args, **kwargs): #pylint: disable=unused-argument target_width = formula.bv_width() #if target_width < formula.bv_rotation_step() or target_width < 0: if target_width < 0: return None if target_width != args[0].width: return None return BVType(target_width)
def is_bv_constant(self, value=None, width=None): """Test whether the formula is a BitVector constant. Optionally, check that the constant has the given value. """ if value is None and width is None: return self.node_type() == BV_CONSTANT if width is None: return self.is_constant(value=value) else: return self.is_constant(_type=BVType(width=width), value=value)
def walk_bv_concat(self, formula, args, **kwargs): # Width of BV operators are computed at construction time. # The type-checker only verifies that they are indeed # correct. try: l_width = args[0].width r_width = args[1].width target_width = formula.bv_width() except AttributeError: return None if not l_width + r_width == target_width: return None return BVType(target_width)
def constant_type(self): """Return the type of the Constant.""" if self.node_type() == INT_CONSTANT: return INT elif self.node_type() == REAL_CONSTANT: return REAL elif self.node_type() == BOOL_CONSTANT: return BOOL elif self.node_type() == STR_CONSTANT: return STRING else: assert self.node_type() == BV_CONSTANT,\ "Unsupported method constant_type '%s'" % self return BVType(width=self.bv_width())
def walk_bv_extract(self, formula, args, **kwargs): arg = args[0] if not arg.is_bv_type(): return None base_width = arg.width target_width = formula.bv_width() start = formula.bv_extract_start() end = formula.bv_extract_end() if start >= base_width or end >= base_width: return None if base_width < target_width: return None if target_width != (end - start + 1): return None return BVType(target_width)
def walk_identity_bv(self, formula, args, **kwargs): #pylint: disable=unused-argument assert formula is not None assert len(args) == 0 return BVType(formula.bv_width())
def walk_bv_extend(self, formula, args, **kwargs): #pylint: disable=unused-argument target_width = formula.bv_width() if target_width < args[0].width or target_width < 0: return None return BVType(target_width)
def walk_bv_comp(self, formula, args, **kwargs): # We check that all children are BV and the same size a, b = args if a != b or (not a.is_bv_type()): return None return BVType(1)