Exemplo n.º 1
0
def annotationoftype(t, bookkeeper=False):
    from pypy.rpython import extregistry
    """The most precise SomeValue instance that contains all
    objects of type t."""
    assert isinstance(t, (type, types.ClassType))
    if t is bool:
        return SomeBool()
    elif t is int:
        return SomeInteger()
    elif t is float:
        return SomeFloat()
    elif issubclass(t, str):  # py.lib uses annotated str subclasses
        return SomeString()
    elif t is unicode:
        return SomeUnicodeString()
    elif t is list:
        return SomeList(MOST_GENERAL_LISTDEF)
    elif t is dict:
        return SomeDict(MOST_GENERAL_DICTDEF)
    # can't do tuple
    elif t is types.NoneType:
        return s_None
    elif bookkeeper and extregistry.is_registered_type(t, bookkeeper.policy):
        entry = extregistry.lookup_type(t, bookkeeper.policy)
        return entry.compute_annotation_bk(bookkeeper)
    elif bookkeeper and t.__module__ != '__builtin__' and t not in bookkeeper.pbctypes:
        classdef = bookkeeper.getuniqueclassdef(t)
        return SomeInstance(classdef)
    else:
        o = SomeObject()
        if t != object:
            o.knowntype = t
        return o
Exemplo n.º 2
0
def annotationoftype(t, bookkeeper=False):
    from pypy.rpython import extregistry

    """The most precise SomeValue instance that contains all
    objects of type t."""
    assert isinstance(t, (type, types.ClassType))
    if t is bool:
        return SomeBool()
    elif t is int:
        return SomeInteger()
    elif t is float:
        return SomeFloat()
    elif issubclass(t, str): # py.lib uses annotated str subclasses
        return SomeString()
    elif t is unicode:
        return SomeUnicodeString()
    elif t is list:
        return SomeList(MOST_GENERAL_LISTDEF)
    elif t is dict:
        return SomeDict(MOST_GENERAL_DICTDEF)
    # can't do tuple
    elif t is types.NoneType:
        return s_None
    elif bookkeeper and extregistry.is_registered_type(t, bookkeeper.policy):
        entry = extregistry.lookup_type(t, bookkeeper.policy)
        return entry.compute_annotation_bk(bookkeeper)
    elif bookkeeper and t.__module__ != '__builtin__' and t not in bookkeeper.pbctypes:
        classdef = bookkeeper.getuniqueclassdef(t)
        return SomeInstance(classdef)
    else:
        o = SomeObject()
        if t != object:
            o.knowntype = t
        return o
Exemplo n.º 3
0
 def getattr(p, s_attr):
     if s_attr.is_constant() and isinstance(s_attr.const, str):
         attr = s_attr.const
         entry = extregistry.lookup_type(p.knowntype)
         s_value = entry.get_field_annotation(p.knowntype, attr)
         return s_value
     else:
         return SomeObject()
Exemplo n.º 4
0
 def getattr(p, s_attr):
     if s_attr.is_constant() and isinstance(s_attr.const, str):
         attr = s_attr.const
         entry = extregistry.lookup_type(p.knowntype)
         s_value = entry.get_field_annotation(p.knowntype, attr)
         return s_value
     else:
         return SomeObject()
Exemplo n.º 5
0
 def return_annotation(self):
     """Returns either 'self' or the annotation of the unwrapped version
     of this ctype, following the logic used when ctypes operations
     return a value.
     """
     from pypy.rpython import extregistry
     assert extregistry.is_registered_type(self.knowntype)
     entry = extregistry.lookup_type(self.knowntype)
     # special case for returning primitives or c_char_p
     return getattr(entry, 's_return_trick', self)
Exemplo n.º 6
0
 def getattr(p, s_attr):
     if s_attr.is_constant() and isinstance(s_attr.const, str):
         # XXX kill with extfunctable.py
         if p.knowntype in builtin.EXTERNAL_TYPE_ANALYZERS:
             return SomeObject.getattr(p, s_attr)
         
         attr = s_attr.const
         entry = extregistry.lookup_type(p.knowntype)
         s_value = entry.get_field_annotation(p.knowntype, attr)
         return s_value
     else:
         return SomeObject()
Exemplo n.º 7
0
 def rtyper_makerepr(self, rtyper):
     entry = extregistry.lookup_type(self.knowntype)
     return entry.get_repr(rtyper, self)
Exemplo n.º 8
0
 def setattr(p, s_attr, s_value):
     assert s_attr.is_constant()
     attr = s_attr.const
     entry = extregistry.lookup_type(p.knowntype)
     entry.set_field_annotation(p.knowntype, attr, s_value)
Exemplo n.º 9
0
 def setattr(p, s_attr, s_value):
     assert s_attr.is_constant()
     attr = s_attr.const
     entry = extregistry.lookup_type(p.knowntype)
     entry.set_field_annotation(p.knowntype, attr, s_value)
Exemplo n.º 10
0
 def rtyper_makerepr(self, rtyper):
    # delegate to the get_repr() of the extregistrered Entry class
     entry = extregistry.lookup_type(self.knowntype)
     return entry.get_repr(rtyper, self)
Exemplo n.º 11
0
def getcontroller(ctype):
    """Return the CTypeController instance corresponding to the given ctype."""
    entry = extregistry.lookup_type(ctype)
    return entry.getcontroller()
Exemplo n.º 12
0
 def simple_call(cto, *args_s):
     # for variables containing ctypes function pointers
     entry = extregistry.lookup_type(cto.knowntype)
     return entry.compute_result_annotation(*args_s)
Exemplo n.º 13
0
 def compute_annotation(self):
     return lookup_type(W_Object).compute_annotation_bk(self.bookkeeper)