Exemplo n.º 1
0
 def __len__(self, /):  # <slot wrapper '__len__' of 'range' objects>
     """Return len(self)."""
     log.debug("ConRange, __len__ is called")
     value = self.super.__len__()
     expr = ((self.stop - self.start) // self.step) + (
         (self.stop - self.start) % self.step != 0).__int2__()
     return ConcolicObject(value, expr)
Exemplo n.º 2
0
 def index(self, key):  # <method 'index' of 'range' objects>
     """rangeobject.index(value) -> integer -- return index of value.\nRaise ValueError if the value is not present."""
     log.debug(
         "ConRange, index is called"
     )  #; args = [unwrap(arg) for arg in args]; kwargs = {k: unwrap(v) for (k, v) in kwargs.items()}
     value = self.super.index(unwrap(
         key))  # raise Exception when "key" is not in the range object
     if isinstance(key, Concolic) and hasattr(key, '__int2__'):
         key = key.__int2__()
     else:
         try:
             key = int(key)
         except:
             key = 0
         key = ConcolicObject(key)
     return ConcolicObject(value, (key - self.start) // self.step)
Exemplo n.º 3
0
 def __bool__(self, /):  # <slot wrapper '__bool__' of 'int' objects>
     """self != 0"""
     log.debug("ConInt, __bool__ is called")
     value = super().__bool__()
     expr = ["not", ["=", self, "0"]]
     ConcolicObject(value, expr).__bool__()  # insert handmade branch, since
     return value  # "__bool__" can only return primitive objects...
Exemplo n.º 4
0
 def __rpow__(self,
              value,
              mod=None,
              /):  # <slot wrapper '__rpow__' of 'int' objects> TODO
     """Return pow(value, self, mod)."""
     log.debug("ConInt, __rpow__ is called")
     return ConcolicObject(super().__rpow__(unwrap(value), unwrap(mod)))
Exemplo n.º 5
0
 def __reversed__(self, *args,
                  **kwargs):  # <method '__reversed__' of 'range' objects>
     """Return a reverse iterator."""
     log.debug("ConRange, __reversed__ is called")
     args = [unwrap(arg) for arg in args]
     kwargs = {k: unwrap(v)
               for (k, v) in kwargs.items()}
     return ConcolicObject(self.super.__reversed__(*args, **kwargs))
Exemplo n.º 6
0
 def __str2__(self):
     log.debug("ConInt, __str2__ is called")
     value = super().__str__()
     expr = [
         'ite', ['<', self, '0'],
         ['str.++', py2smt('-'), ["int.to.str", ['-', self]]],
         ["int.to.str", self]
     ]
     return ConcolicObject(value, expr)
Exemplo n.º 7
0
 def __floor__(self, *args,
               **kwargs):  # <method '__floor__' of 'int' objects>
     """Flooring an Integral returns itself."""
     log.debug("ConInt, __floor__ is called")
     args = [unwrap(arg) for arg in args]
     kwargs = {k: unwrap(v)
               for (k, v) in kwargs.items()}
     value = super().__floor__(*args, **kwargs)
     return ConcolicObject(value, self)
Exemplo n.º 8
0
 def conjugate(self, *args,
               **kwargs):  # <method 'conjugate' of 'int' objects>
     """Returns self, the complex conjugate of any int."""
     log.debug("ConInt, conjugate is called")
     args = [unwrap(arg) for arg in args]
     kwargs = {k: unwrap(v)
               for (k, v) in kwargs.items()}
     value = super().conjugate(*args, **kwargs)
     return ConcolicObject(value, self)
Exemplo n.º 9
0
 def __round__(self, *args,
               **kwargs):  # <method '__round__' of 'int' objects>
     """Rounding an Integral returns itself.\nRounding with an ndigits argument also returns an integer."""
     log.debug("ConInt, __round__ is called")
     args = [unwrap(arg) for arg in args]
     kwargs = {k: unwrap(v)
               for (k, v) in kwargs.items()}
     value = super().__round__(*args, **kwargs)
     return ConcolicObject(value, self)
Exemplo n.º 10
0
 def __contains__(self, key,
                  /):  # <slot wrapper '__contains__' of 'range' objects>
     """Return key in self."""
     log.debug("ConRange, __contains__ is called")
     value = self.super.__contains__(unwrap(key))
     if isinstance(key, Concolic) and hasattr(key, '__int2__'):
         key = key.__int2__()
     else:
         try:
             key = int(key)
         except:
             key = 0
         key = ConcolicObject(key)
     if self.start < self.stop:
         return ConcolicObject(value, self.start <= key < self.stop and \
                                      (key - self.start) % self.step == 0)
     if self.start > self.stop:
         return ConcolicObject(value, self.start >= key > self.stop and \
                                      (key - self.start) % self.step == 0)
     return ConcolicObject(value)
Exemplo n.º 11
0
 def __ge__(self, other, /):
     try:
         if (value := super().__ge__(unwrap(other))) is NotImplemented:
             raise NotImplementedError
     except:
         value = unwrap(other).__le__(unwrap(self))
     if isinstance(other, Concolic):
         if hasattr(other, 'isBool'): other = other.__float2__()
         assert not (hasattr(other, 'super')
                     and isinstance(other.super, range))
         assert not isinstance(other, str)
         # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = unwrap(other).__ge__(unwrap(self))
     else:
         if type(other) is bool: other = float(other)
         if type(other) is not int and type(other) is not float:
             return ConcolicObject(
                 value
             )  # discard the symbolic expression if it cannot match the concrete value
         other = ConcolicObject(other)
     expr = ['>=', self, other]
     return ConcolicObject(value, expr)
Exemplo n.º 12
0
 def count(self, key):  # <method 'count' of 'range' objects>
     """rangeobject.count(value) -> integer -- return number of occurrences of value"""
     log.debug(
         "ConRange, count is called"
     )  #; args = [unwrap(arg) for arg in args]; kwargs = {k: unwrap(v) for (k, v) in kwargs.items()}
     value = self.super.count(unwrap(key))
     if isinstance(key, Concolic) and hasattr(key, '__int2__'):
         key = key.__int2__()
     else:
         try:
             key = int(key)
         except:
             key = 0
         key = ConcolicObject(key)
     if self.start < self.stop:
         return ConcolicObject(value, (self.start <= key < self.stop and \
                                      (key - self.start) % self.step == 0).__int2__())
     if self.start > self.stop:
         return ConcolicObject(value, (self.start >= key > self.stop and \
                                      (key - self.start) % self.step == 0).__int2__())
     return ConcolicObject(value)
Exemplo n.º 13
0
 def __int2__(self):
     log.debug("ConFloat, __int2__ is called")
     value = super().__int__()
     expr = [
         '+', ['to_int', self],
         [
             'ite', ['and', ['<', self, '0'], ['not', ['is_int', self]]],
             '1', '0'
         ]
     ]
     # Please note that ['to_int', -2.5] evaluates to -3 in smtlib2, but int(-2.5) evaluates to -2 in Python!
     return ConcolicObject(value, expr)
Exemplo n.º 14
0
 def __truediv__(self,
                 other):  # <slot wrapper '__truediv__' of 'float' objects>
     log.debug("ConFloat, __truediv__ is called")
     value = super().__truediv__(unwrap(other))
     if isinstance(other, Concolic):
         if hasattr(other, '__float2__'): other = other.__float2__()
     else:
         try:
             other = float(other)
         except:
             other = 1.0
         other = self.__class__(other)
     expr = ['/', self, other]
     return ConcolicObject(value, expr)
Exemplo n.º 15
0
 def __getitem__(self, key,
                 /):  # <slot wrapper '__getitem__' of 'range' objects>
     value = self.value.__getitem__(unwrap(key))
     if isinstance(
             key, slice
     ) and key.start is None and key.stop is None and key.step == -1:
         if self.step > 0:
             k = (self.stop - self.start) // self.step - int(
                 (self.stop - self.start) % self.step == 0)
             start = self.start + k * self.step
             stop = self.start - self.step
             step = -self.step
             if start == value.start and stop == value.stop and step == value.step:
                 return self.__class__(start, stop, step)
     return ConcolicObject(value)  # TODO
Exemplo n.º 16
0
 def __init__(self, *args):
     self.super = range(*[unwrap(arg)
                          for arg in args])  # emulate inheritance
     if len(args) < 2:
         self.start = 0
         self.stop = args[0]
     else:
         self.start = args[0]
         self.stop = args[1]
     if len(args) < 3:
         self.step = 1
     else:
         self.step = args[2]
     # We must ensure that all attributes are concolic integers in order to
     # make the overridden __getitem__ and __iter__ work!
     if not (isinstance(self.start, int)
             and isinstance(self.start, Concolic)):  # not ConcolicInt
         if isinstance(self.start, Concolic) and hasattr(
                 self.start, '__int2__'):
             self.start = self.start.__int2__()
             if self.start != self.super.start:
                 self.start = ConcolicObject(
                     self.super.start)  # ConcolicInt
         else:
             self.start = ConcolicObject(self.super.start)  # ConcolicInt
     if not (isinstance(self.stop, int)
             and isinstance(self.stop, Concolic)):  # not ConcolicInt
         if isinstance(self.stop, Concolic) and hasattr(
                 self.stop, '__int2__'):
             self.stop = self.stop.__int2__()
             if self.stop != self.super.stop:
                 self.stop = ConcolicObject(self.super.stop)  # ConcolicInt
         else:
             self.stop = ConcolicObject(self.super.stop)  # ConcolicInt
     if not (isinstance(self.step, int)
             and isinstance(self.step, Concolic)):  # not ConcolicInt
         if isinstance(self.step, Concolic) and hasattr(
                 self.step, '__int2__'):
             self.step = self.step.__int2__()
             if self.step != self.super.step:
                 self.step = ConcolicObject(self.super.step)  # ConcolicInt
         else:
             self.step = ConcolicObject(self.super.step)  # ConcolicInt
Exemplo n.º 17
0
 def bit_length(self, /):  # <method 'bit_length' of 'int' objects> TODO
     """Number of bits necessary to represent self in binary.\n\n>>> bin(37)\n'0b100101'\n>>> (37).bit_length()\n6"""
     log.debug("ConInt, bit_length is called")
     return ConcolicObject(super().bit_length())
Exemplo n.º 18
0
 def __float2__(self, /):  # our version of "def __float__(self, /):"
     log.debug("ConInt, __float2__ is called")
     value = super().__float__()
     expr = ['to_real', self]
     return ConcolicObject(value, expr)
Exemplo n.º 19
0
 def __bool2__(self):
     log.debug("ConInt, __bool2__ is called")
     value = super().__bool__()
     expr = ["not", ["=", self, "0"]]
     return ConcolicObject(value, expr)
Exemplo n.º 20
0
 def real(self):  # <attribute 'real' of 'int' objects>
     """the real part of a complex number"""
     log.debug("ConInt, real is called")
     value = super().real
     return ConcolicObject(value, self)
Exemplo n.º 21
0
 def numerator(self):  # <attribute 'numerator' of 'int' objects>
     """the numerator of a rational number in lowest terms"""
     log.debug("ConInt, numerator is called")
     value = super().numerator
     return ConcolicObject(value, self)
Exemplo n.º 22
0
 def imag(self):  # <attribute 'imag' of 'int' objects>
     """the imaginary part of a complex number"""
     log.debug("ConInt, imag is called")
     return ConcolicObject(super().imag)  # should always return 0
Exemplo n.º 23
0
 def denominator(self):  # <attribute 'denominator' of 'int' objects>
     """the denominator of a rational number in lowest terms"""
     log.debug("ConInt, denominator is called")
     return ConcolicObject(super().denominator)  # should always return 1
Exemplo n.º 24
0
 def __abs__(self, /):  # <slot wrapper '__abs__' of 'int' objects>
     """abs(self)"""
     log.debug("ConInt, __abs__ is called")
     value = super().__abs__()
     expr = ["abs", self]
     return ConcolicObject(value, expr)
Exemplo n.º 25
0
 def _bin_op(self, op, other):
     if op == '__add__':
         try:
             if (value := super().__add__(unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__radd__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that int + float -> float instead of int, so we cannot convert float to int here!
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = unwrap(other).__radd__(unwrap(self))
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['+', self, other]
         return ConcolicObject(value, expr)
     if op == '__eq__':
         try:
             if (value := super().__eq__(unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__eq__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'):
                 other = other.__int2__()
                 # Please note that (int = float) will convert int to float, so we cannot convert float to int here!
             elif (hasattr(other, 'super')
                   and isinstance(other.super, range)) or isinstance(
                       other, str):
                 return ConcolicObject(
                     value
                 )  # smtlib2 cannot compare int with range and str.
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['=', self, other]
         return ConcolicObject(value, expr)
     if op == '__floordiv__':
         # TODO: not sure in the following statement what if "other" does not support the "!=" operator.
         try:
             (other != 0).__bool__(
             )  # insert a handmade branch since a number cannot be divided by zero.
         except:
             pass
         try:
             if (value := super().__floordiv__(
                     unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__rfloordiv__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'):
                 other = other.__int2__()
                 # Please note that int.__floordiv__(float) will be changed to float.__rfloordiv__(int) in Python!
             elif isinstance(other, float):
                 return ConcolicObject(
                     value)  # TODO: smtlib2 cannot perform int // float
             elif isinstance(other, int) and unwrap(other) < 0:
                 return ConcolicObject(
                     value
                 )  # TODO: Currently not support the case when "other" is negative.
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = unwrap(other).__rfloordiv__(unwrap(self))
         else:
             if type(other) is bool: other = int(other)
             if not (type(other) is int and other > 0):
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = self.__class__(other)
         expr = ['div', self, other]
         return ConcolicObject(value, expr)
     if op == '__ge__':
         try:
             if (value := super().__ge__(unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__le__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that (int >= float) will convert int to float, so we cannot convert float to int here!
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = unwrap(other).__le__(unwrap(self))
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['>=', self, other]
         return ConcolicObject(value, expr)
     if op == '__gt__':
         try:
             if (value := super().__gt__(unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__lt__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that (int > float) will convert int to float, so we cannot convert float to int here!
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = unwrap(other).__lt__(unwrap(self))
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['>', self, other]
         return ConcolicObject(value, expr)
     if op == '__le__':
         try:
             if (value := super().__le__(unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__ge__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that (int <= float) will convert int to float, so we cannot convert float to int here!
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = unwrap(other).__ge__(unwrap(self))
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['<=', self, other]
         return ConcolicObject(value, expr)
     if op == '__lt__':
         try:
             if (value := super().__lt__(unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__gt__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that (int < float) will convert int to float, so we cannot convert float to int here!
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = unwrap(other).__gt__(unwrap(self))
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['<', self, other]
         return ConcolicObject(value, expr)
     if op == '__mod__':
         # TODO: not sure in the following statement what if "other" does not support the "!=" operator.
         try:
             (other != 0).__bool__(
             )  # insert a handmade branch since a number cannot be divided by zero.
         except:
             pass
         try:
             if (value := super().__mod__(unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__rmod__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'):
                 other = other.__int2__()
                 # Please note that int.__mod__(float) will be changed to float.__rmod__(int) in Python!
             elif isinstance(other, float):
                 return ConcolicObject(
                     value)  # TODO: smtlib2 cannot perform int // float
             elif isinstance(other, int) and unwrap(other) < 0:
                 return ConcolicObject(
                     value
                 )  # TODO: Currently not support the case when "other" is negative.
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = unwrap(other).__rmod__(unwrap(self))
         else:
             if type(other) is bool: other = int(other)
             if not (type(other) is int and other > 0):
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = self.__class__(other)
         expr = ['mod', self, other]
         return ConcolicObject(value, expr)
     if op == '__mul__':
         try:
             if (value := super().__mul__(unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__rmul__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that int * float -> float instead of int, so we cannot convert float to int here!
             if isinstance(other, str): return other.__mul__(self)
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             # other cannot be of type "range" here, since Exception should be thrown at the statement: value = unwrap(other).__rmul__(unwrap(self))
         else:
             if type(other) is str:
                 return ConcolicObject(other).__mul__(self)
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['*', self, other]
         return ConcolicObject(value, expr)
     if op == '__ne__':
         try:
             if (value := super().__ne__(unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__ne__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'):
                 other = other.__int2__()
                 # Please note that (int != float) will convert int to float, so we cannot convert float to int here!
             elif (hasattr(other, 'super')
                   and isinstance(other.super, range)) or isinstance(
                       other, str):
                 return ConcolicObject(
                     value
                 )  # smtlib2 cannot compare int with range and str.
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['not', ['=', self, other]]
         return ConcolicObject(value, expr)
     if op == '__radd__':
         value = super().__radd__(unwrap(other))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that float + int -> float instead of int, so we cannot convert float to int here!
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = unwrap(other).__radd__(unwrap(self))
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['+', other, self]
         return ConcolicObject(value, expr)
     if op == '__rfloordiv__':
         # TODO: not sure in the following statement what if "other" does not support the "!=" operator.
         try:
             (self != 0).__bool__(
             )  # insert a handmade branch since a number cannot be divided by zero.
         except:
             pass
         value = super().__rfloordiv__(unwrap(other))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             elif isinstance(other, float):
                 return ConcolicObject(
                     value)  # TODO: smtlib2 cannot perform float // int
             elif isinstance(other, int) and unwrap(other) < 0:
                 return ConcolicObject(
                     value
                 )  # TODO: Currently not support the case when "other" is negative.
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = super().__rfloordiv__(unwrap(other))
         else:
             if type(other) is bool: other = int(other)
             if not (type(other) is int and other > 0):
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = self.__class__(other)
         expr = ['div', other, self]
         return ConcolicObject(value, expr)
     if op == '__rmod__':
         # TODO: not sure in the following statement what if "other" does not support the "!=" operator.
         try:
             (self != 0).__bool__(
             )  # insert a handmade branch since a number cannot be divided by zero.
         except:
             pass
         value = super().__rmod__(unwrap(other))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             elif isinstance(other, float):
                 return ConcolicObject(
                     value)  # TODO: smtlib2 cannot perform float // int
             elif isinstance(other, int) and unwrap(other) < 0:
                 return ConcolicObject(
                     value
                 )  # TODO: Currently not support the case when "other" is negative.
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = super().__rmod__(unwrap(other))
         else:
             if type(other) is bool: other = int(other)
             if not (type(other) is int and other > 0):
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = self.__class__(other)
         expr = ['mod', other, self]
         return ConcolicObject(value, expr)
     if op == '__rmul__':
         value = super().__rmul__(unwrap(other))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that float * int -> float instead of int, so we cannot convert float to int here!
             if isinstance(other, str): return other.__mul__(self)
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             # other cannot be of type "range" here, since Exception should be thrown at the statement: value = unwrap(other).__rmul__(unwrap(self))
         else:
             if type(other) is str:
                 return ConcolicObject(other).__mul__(self)
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['*', other, self]
         return ConcolicObject(value, expr)
     if op == '__rsub__':
         value = super().__rsub__(unwrap(other))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that float - int -> float instead of int, so we cannot convert float to int here!
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = super().__rsub__(unwrap(other))
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['-', other, self]
         return ConcolicObject(value, expr)
     if op == '__rtruediv__':
         # TODO: not sure in the following statement what if "other" does not support the "!=" operator.
         try:
             (self != 0).__bool__(
             )  # insert a handmade branch since a number cannot be divided by zero.
         except:
             pass
         value = super().__rtruediv__(unwrap(other))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that int / float -> float instead of int, so we cannot convert float to int here!
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: super().__rtruediv__(unwrap(other))
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['/', other, self]
         return ConcolicObject(value, expr)
     if op == '__sub__':
         try:
             if (value := super().__sub__(unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__rsub__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that int - float -> float instead of int, so we cannot convert float to int here!
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = unwrap(other).__rsub__(unwrap(self))
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['-', self, other]
         return ConcolicObject(value, expr)
     if op == '__truediv__':
         # TODO: not sure in the following statement what if "other" does not support the "!=" operator.
         try:
             (other != 0).__bool__(
             )  # insert a handmade branch since a number cannot be divided by zero.
         except:
             pass
         try:
             if (value := super().__truediv__(
                     unwrap(other))) is NotImplemented:
                 raise NotImplementedError
         except:
             value = unwrap(other).__rtruediv__(unwrap(self))
         if isinstance(other, Concolic):
             if hasattr(other, 'isBool'): other = other.__int2__()
             # Please note that int / float -> float instead of int, so we cannot convert float to int here!
             assert not (hasattr(other, 'super')
                         and isinstance(other.super, range))
             assert not isinstance(other, str)
             # other cannot be of type "range" and "str" here, since Exception should be thrown at the statement: value = unwrap(other).__rtruediv__(unwrap(self))
         else:
             if type(other) is bool: other = int(other)
             if type(other) is not int and type(other) is not float:
                 return ConcolicObject(
                     value
                 )  # discard the symbolic expression if it cannot match the concrete value
             other = ConcolicObject(other)
         expr = ['/', self, other]
         return ConcolicObject(value, expr)
     raise NotImplementedError
Exemplo n.º 26
0
 def __pos__(self, /):  # <slot wrapper '__pos__' of 'int' objects>
     """+self"""
     log.debug("ConInt, __pos__ is called")
     value = super().__pos__()
     return ConcolicObject(value, self)
Exemplo n.º 27
0
 def __divmod__(self, value,
                /):  # <slot wrapper '__divmod__' of 'int' objects> TODO
     """Return divmod(self, value)."""
     log.debug("ConInt, __divmod__ is called")
     return ConcolicObject(super().__divmod__(unwrap(value)))
Exemplo n.º 28
0
 def __rshift__(self, value,
                /):  # <slot wrapper '__rshift__' of 'int' objects>
     """Return self>>value."""
     log.debug("ConInt, __rshift__ is called")
     return ConcolicObject(super().__rshift__(unwrap(value)))
Exemplo n.º 29
0
 def __format__(self, format_spec,
                /):  # <method '__format__' of 'int' objects> TODO
     """Default object formatter."""
     log.debug("ConInt, __format__ is called")
     return ConcolicObject(super().__format__(unwrap(format_spec)))
Exemplo n.º 30
0
 def as_integer_ratio(
         self, /):  # <method 'as_integer_ratio' of 'int' objects> TODO
     """Return integer ratio.\n\nReturn a pair of integers, whose ratio is exactly equal to the original int\nand with a positive denominator.\n\n>>> (10).as_integer_ratio()\n(10, 1)\n>>> (-10).as_integer_ratio()\n(-10, 1)\n>>> (0).as_integer_ratio()\n(0, 1)"""
     log.debug("ConInt, as_integer_ratio is called")
     return ConcolicObject(super().as_integer_ratio())