Esempio n. 1
0
def builtin_range(*args):
    s_step = immutablevalue(1)
    if len(args) == 1:
        s_start = immutablevalue(0)
        s_stop = args[0]
    elif len(args) == 2:
        s_start, s_stop = args
    elif len(args) == 3:
        s_start, s_stop = args[:2]
        s_step = args[2]
    else:
        raise AnnotatorError("range() takes 1 to 3 arguments")
    empty = False  # so far
    if not s_step.is_constant():
        step = 0  # this case signals a variable step
    else:
        step = s_step.const
        if step == 0:
            raise AnnotatorError("range() with step zero")
        if s_start.is_constant() and s_stop.is_constant():
            try:
                if len(xrange(s_start.const, s_stop.const, step)) == 0:
                    empty = True
            except TypeError:  # if one of the .const is a Symbolic
                pass
    if empty:
        s_item = s_ImpossibleValue
    else:
        nonneg = False  # so far
        if step > 0 or s_step.nonneg:
            nonneg = s_start.nonneg
        elif step < 0:
            nonneg = s_stop.nonneg or (s_stop.is_constant() and s_stop.const >= -1)
        s_item = SomeInteger(nonneg=nonneg)
    return getbookkeeper().newlist(s_item, range_step=step)
Esempio n. 2
0
 def method_join(self, s_list):
     if s_None.contains(s_list):
         return SomeImpossibleValue()
     s_item = s_list.listdef.read_item()
     if s_None.contains(s_item):
         if isinstance(self, SomeUnicodeString):
             return immutablevalue(u"")
         return immutablevalue("")
     no_nul = self.no_nul and s_item.no_nul
     return self.basestringclass(no_nul=no_nul)
Esempio n. 3
0
 def method_join(self, s_list):
     if s_None.contains(s_list):
         return SomeImpossibleValue()
     s_item = s_list.listdef.read_item()
     if s_None.contains(s_item):
         if isinstance(self, SomeUnicodeString):
             return immutablevalue(u"")
         return immutablevalue("")
     no_nul = self.no_nul and s_item.no_nul
     return self.basestringclass(no_nul=no_nul)
Esempio n. 4
0
 def issubtype(self, s_cls):
     if hasattr(self, 'is_type_of'):
         vars = self.is_type_of
         annotator = getbookkeeper().annotator
         return builtin.builtin_isinstance(annotator.binding(vars[0]),
                                           s_cls, vars)
     if self.is_constant() and s_cls.is_constant():
         return immutablevalue(issubclass(self.const, s_cls.const))
     return s_Bool
Esempio n. 5
0
 def issubtype(self, s_cls):
     if hasattr(self, 'is_type_of'):
         vars = self.is_type_of
         annotator = getbookkeeper().annotator
         return builtin.builtin_isinstance(annotator.binding(vars[0]),
                                           s_cls, vars)
     if self.is_constant() and s_cls.is_constant():
         return immutablevalue(issubclass(self.const, s_cls.const))
     return s_Bool
Esempio n. 6
0
 def getattr(self, s_attr):
     # get a SomeBuiltin if the SomeObject has
     # a corresponding method to handle it
     if not s_attr.is_constant() or not isinstance(s_attr.const, str):
         raise AnnotatorError("getattr(%r, %r) has non-constant argument" %
                              (self, s_attr))
     attr = s_attr.const
     s_method = self.find_method(attr)
     if s_method is not None:
         return s_method
     # if the SomeObject is itself a constant, allow reading its attrs
     if self.is_immutable_constant() and hasattr(self.const, attr):
         return immutablevalue(getattr(self.const, attr))
     raise AnnotatorError("Cannot find attribute %r on %r" % (attr, self))
Esempio n. 7
0
 def getattr(self, s_attr):
     # get a SomeBuiltin if the SomeObject has
     # a corresponding method to handle it
     if not s_attr.is_constant() or not isinstance(s_attr.const, str):
         raise AnnotatorError("getattr(%r, %r) has non-constant argument"
                              % (self, s_attr))
     attr = s_attr.const
     s_method = self.find_method(attr)
     if s_method is not None:
         return s_method
     # if the SomeObject is itself a constant, allow reading its attrs
     if self.is_immutable_constant() and hasattr(self.const, attr):
         return immutablevalue(getattr(self.const, attr))
     raise AnnotatorError("Cannot find attribute %r on %r" % (attr, self))
Esempio n. 8
0
def builtin_range(*args):
    s_step = immutablevalue(1)
    if len(args) == 1:
        s_start = immutablevalue(0)
        s_stop = args[0]
    elif len(args) == 2:
        s_start, s_stop = args
    elif len(args) == 3:
        s_start, s_stop = args[:2]
        s_step = args[2]
    else:
        raise AnnotatorError("range() takes 1 to 3 arguments")
    empty = False  # so far
    if not s_step.is_constant():
        step = 0 # this case signals a variable step
    else:
        step = s_step.const
        if step == 0:
            raise AnnotatorError("range() with step zero")
        if s_start.is_constant() and s_stop.is_constant():
            try:
                if len(xrange(s_start.const, s_stop.const, step)) == 0:
                    empty = True
            except TypeError:   # if one of the .const is a Symbolic
                pass
    if empty:
        s_item = s_ImpossibleValue
    else:
        nonneg = False # so far
        if step > 0 or s_step.nonneg:
            nonneg = s_start.nonneg
        elif step < 0:
            nonneg = s_stop.nonneg or (s_stop.is_constant() and
                                       s_stop.const >= -1)
        s_item = SomeInteger(nonneg=nonneg)
    return getbookkeeper().newlist(s_item, range_step=step)
Esempio n. 9
0
def constpropagate(func, args_s, s_result):
    """Returns s_result unless all args are constants, in which case the
    func() is called and a constant result is returned (it must be contained
    in s_result).
    """
    args = []
    for s in args_s:
        if not s.is_immutable_constant():
            return s_result
        args.append(s.const)
    try:
        realresult = func(*args)
    except (ValueError, OverflowError):
        # no possible answer for this precise input.  Be conservative
        # and keep the computation non-constant.  Example:
        # unichr(constant-that-doesn't-fit-16-bits) on platforms where
        # the underlying Python has sys.maxunicode == 0xffff.
        return s_result
    s_realresult = immutablevalue(realresult)
    if not s_result.contains(s_realresult):
        raise AnnotatorError("%s%r returned %r, which is not contained in %s" % (func, args, realresult, s_result))
    return s_realresult
Esempio n. 10
0
def constpropagate(func, args_s, s_result):
    """Returns s_result unless all args are constants, in which case the
    func() is called and a constant result is returned (it must be contained
    in s_result).
    """
    args = []
    for s in args_s:
        if not s.is_immutable_constant():
            return s_result
        args.append(s.const)
    try:
        realresult = func(*args)
    except (ValueError, OverflowError):
        # no possible answer for this precise input.  Be conservative
        # and keep the computation non-constant.  Example:
        # unichr(constant-that-doesn't-fit-16-bits) on platforms where
        # the underlying Python has sys.maxunicode == 0xffff.
        return s_result
    s_realresult = immutablevalue(realresult)
    if not s_result.contains(s_realresult):
        raise Exception("%s%r returned %r, which is not contained in %s" %
                        (func, args, realresult, s_result))
    return s_realresult
Esempio n. 11
0
 def len(self):
     position = getbookkeeper().position_key
     if self._is_empty(position):
         return immutablevalue(0)
     return SomeObject.len(self)
Esempio n. 12
0
 def len(self):
     return immutablevalue(1)
Esempio n. 13
0
 def method_endswith(self, frag):
     if self.is_constant() and frag.is_constant():
         return immutablevalue(self.const.endswith(frag.const))
     return s_Bool
Esempio n. 14
0
 def len(self):
     if self._is_empty():
         return immutablevalue(0)
     return SomeObject.len(self)
Esempio n. 15
0
 def default_annotate(annotator, obj1, obj2):
     s_1, s_2 = annotator.annotation(obj1), annotator.annotation(obj2)
     if s_1.is_immutable_constant() and s_2.is_immutable_constant():
         return immutablevalue(cmp_op.pyfunc(s_1.const, s_2.const))
     else:
         return s_Bool
Esempio n. 16
0
 def len(self):
     s_item = self.listdef.read_item()
     if isinstance(s_item, SomeImpossibleValue):
         return immutablevalue(0)
     return SomeObject.len(self)
Esempio n. 17
0
def robjmodel_keepalive_until_here(*args_s):
    return immutablevalue(None)
Esempio n. 18
0
 def len(self):
     if self._is_empty():
         return immutablevalue(0)
     return SomeObject.len(self)
Esempio n. 19
0
def robjmodel_keepalive_until_here(*args_s):
    return immutablevalue(None)
Esempio n. 20
0
 def len(self):
     position = getbookkeeper().position_key
     if self._is_empty(position):
         return immutablevalue(0)
     return SomeObject.len(self)
Esempio n. 21
0
 def len(self):
     position = getbookkeeper().position_key
     s_item = self.listdef.read_item(position)
     if isinstance(s_item, SomeImpossibleValue):
         return immutablevalue(0)
     return SomeObject.len(self)
Esempio n. 22
0
 def len(self):
     return immutablevalue(len(self.items))
Esempio n. 23
0
 def cmp((obj1, obj2)):
     if obj1.is_immutable_constant() and obj2.is_immutable_constant():
         return immutablevalue(cmp(obj1.const, obj2.const))
     else:
         return SomeInteger()
Esempio n. 24
0
 def len(self):
     position = getbookkeeper().position_key
     s_item = self.listdef.read_item(position)
     if isinstance(s_item, SomeImpossibleValue):
         return immutablevalue(0)
     return SomeObject.len(self)
Esempio n. 25
0
 def cmp((obj1, obj2)):
     if obj1.is_immutable_constant() and obj2.is_immutable_constant():
         return immutablevalue(cmp(obj1.const, obj2.const))
     else:
         return SomeInteger()
Esempio n. 26
0
 def method_endswith(self, frag):
     if self.is_constant() and frag.is_constant():
         return immutablevalue(self.const.endswith(frag.const))
     return s_Bool
Esempio n. 27
0
 def len(self):
     return immutablevalue(len(self.items))
Esempio n. 28
0
 def len(self):
     return immutablevalue(1)
Esempio n. 29
0
 def len(self):
     s_item = self.listdef.read_item()
     if isinstance(s_item, SomeImpossibleValue):
         return immutablevalue(0)
     return SomeObject.len(self)
Esempio n. 30
0
 def default_annotate(annotator, obj1, obj2):
     s_1, s_2 = annotator.annotation(obj1), annotator.annotation(obj2)
     if s_1.is_immutable_constant() and s_2.is_immutable_constant():
         return immutablevalue(cmp_op.pyfunc(s_1.const, s_2.const))
     else:
         return s_Bool
Esempio n. 31
0
 def ge((obj1, obj2)):
     if obj1.is_immutable_constant() and obj2.is_immutable_constant():
         return immutablevalue(obj1.const >= obj2.const)
     else:
         return s_Bool