Пример #1
0
    def test_overloaded_meth_string(self):
        C = Instance("test", ROOT, {}, {
            'foo':
            overload(meth(Meth([Char], Signed)),
                     meth(Meth([String], Float)),
                     resolver=OverloadingResolver),
            'bar':
            overload(meth(Meth([Signed], Char)),
                     meth(Meth([Float], String)),
                     resolver=OverloadingResolver)
        })

        def fn1():
            return new(C).foo('a')

        def fn2():
            return new(C).foo('aa')

        def fn3(x):
            return new(C).bar(x)

        a = RPythonAnnotator()
        assert isinstance(a.build_types(fn1, []), annmodel.SomeInteger)
        assert isinstance(a.build_types(fn2, []), annmodel.SomeFloat)
        assert isinstance(a.build_types(fn3, [int]), annmodel.SomeChar)
        assert isinstance(a.build_types(fn3, [float]), annmodel.SomeString)
Пример #2
0
def test_checkvirtual_simple():
    A = Instance("A", ROOT)
    B = Instance("B", A)

    addMethods(A, {"foo": meth(Meth([], Void)), "bar": meth(Meth([], Void))})

    addMethods(B, {"foo": meth(Meth([], Void))})

    check_virtual_methods()
    assert A._methods["foo"]._virtual == True
    assert A._methods["bar"]._virtual == False
    assert B._methods["foo"]._virtual == False
Пример #3
0
def test_checkvirtual_simple():
    A = Instance("A", ROOT)
    B = Instance("B", A)

    addMethods(A, {"foo": meth(Meth([], Void)),
                   "bar": meth(Meth([], Void))})
    
    addMethods(B, {"foo": meth(Meth([], Void))})

    check_virtual_methods()
    assert A._methods["foo"]._virtual == True
    assert A._methods["bar"]._virtual == False
    assert B._methods["foo"]._virtual == False
Пример #4
0
def test_checkvirtual_brother():
    A = Instance("A", ROOT)
    B1 = Instance("B1", A)
    B2 = Instance("B2", A)

    addMethods(A, {"foo": meth(Meth([], Void)), "bar": meth(Meth([], Void))})

    addMethods(B1, {"foo": meth(Meth([], Void))})

    check_virtual_methods()
    assert A._methods["foo"]._virtual == True
    assert A._methods["bar"]._virtual == False
    assert B1._methods["foo"]._virtual == False
    assert "foo" not in B2._methods
Пример #5
0
 def get_impl(self, name, methdesc, is_finalizer=False):
     impls = {}
     flags = {}
     if is_finalizer:
         flags['finalizer'] = True
     for rowname, (row, M) in self.row_mapping.iteritems():
         if methdesc is None:
             m = ootype.meth(M, _name=name, abstract=True, **flags)
         else:
             impl_graph = row[methdesc.funcdesc].graph
             m = ootype.meth(M, _name=name, graph=impl_graph, **flags)
         derived_name = row_method_name(name, rowname)
         impls[derived_name] = m
     return impls
Пример #6
0
def test_checkvirtual_deep():
    A = Instance("A", ROOT)
    B = Instance("B", A)
    C = Instance("C", B)

    addMethods(A, {"foo": meth(Meth([], Void)), "bar": meth(Meth([], Void))})

    addMethods(C, {"foo": meth(Meth([], Void))})

    check_virtual_methods()
    assert A._methods["foo"]._virtual == True
    assert A._methods["bar"]._virtual == False
    assert "foo" not in B._methods
    assert C._methods["foo"]._virtual == False
Пример #7
0
def test_checkvirtual_brother():
    A = Instance("A", ROOT)
    B1 = Instance("B1", A)
    B2 = Instance("B2", A)

    addMethods(A, {"foo": meth(Meth([], Void)),
                   "bar": meth(Meth([], Void))})
    
    addMethods(B1, {"foo": meth(Meth([], Void))})

    check_virtual_methods()
    assert A._methods["foo"]._virtual == True
    assert A._methods["bar"]._virtual == False
    assert B1._methods["foo"]._virtual == False
    assert "foo" not in B2._methods
Пример #8
0
def test_checkvirtual_deep():
    A = Instance("A", ROOT)
    B = Instance("B", A)
    C = Instance("C", B)

    addMethods(A, {"foo": meth(Meth([], Void)),
                   "bar": meth(Meth([], Void))})
    
    addMethods(C, {"foo": meth(Meth([], Void))})

    check_virtual_methods()
    assert A._methods["foo"]._virtual == True
    assert A._methods["bar"]._virtual == False
    assert "foo" not in B._methods
    assert C._methods["foo"]._virtual == False
Пример #9
0
    def attach_class_attr_accessor(self, mangled, value, r_value):
        def ll_getclassattr(self):
            return oovalue

        M = ootype.Meth([], r_value.lowleveltype)
        if value is None:
            m = ootype.meth(M, _name=mangled, abstract=True)
        else:
            oovalue = r_value.convert_desc_or_const(value)
            ll_getclassattr = func_with_new_name(ll_getclassattr,
                                                 'll_get_' + mangled)
            graph = self.rtyper.annotate_helper(ll_getclassattr, [self.lowleveltype])
            m = ootype.meth(M, _name=mangled, _callable=ll_getclassattr,
                            graph=graph)

        ootype.addMethods(self.lowleveltype, {mangled: m})
Пример #10
0
 def get_impl(self, name, methdesc, is_finalizer=False):
     impls = {}
     flags = {}
     if is_finalizer:
         flags['finalizer'] = True
     for rowname, (row, M) in self.row_mapping.iteritems():
         if methdesc is None:
             m = ootype.meth(M, _name=name, abstract=True, **flags)
         else:
             try:
                 impl_graph = row[methdesc.funcdesc].graph
             except KeyError:
                 m = ootype.meth(M, _name=name, abstract=True, **flags) # XXX ???
             else:
                 m = ootype.meth(M, _name=name, graph=impl_graph, **flags)
         derived_name = row_method_name(name, rowname)
         impls[derived_name] = m
     return impls
Пример #11
0
 def test_overloaded_meth_string(self):
     C = Instance("test", ROOT, {},
                  {'foo': overload(meth(Meth([Char], Signed)),
                                   meth(Meth([String], Float)),
                                   resolver=OverloadingResolver),
                   'bar': overload(meth(Meth([Signed], Char)),
                                   meth(Meth([Float], String)),
                                   resolver=OverloadingResolver)})
     def fn1():
         return new(C).foo('a')
     def fn2():
         return new(C).foo('aa')
     def fn3(x):
         return new(C).bar(x)
     a = RPythonAnnotator()
     assert isinstance(a.build_types(fn1, []), annmodel.SomeInteger)
     assert isinstance(a.build_types(fn2, []), annmodel.SomeFloat)
     assert isinstance(a.build_types(fn3, [int]), annmodel.SomeChar)
     assert isinstance(a.build_types(fn3, [float]), annmodel.SomeString)
Пример #12
0
    def attach_class_attr_accessor(self, mangled, value, r_value):
        def ll_getclassattr(self):
            return oovalue

        M = ootype.Meth([], r_value.lowleveltype)
        if value is None:
            m = ootype.meth(M, _name=mangled, abstract=True)
        else:
            oovalue = r_value.convert_desc_or_const(value)
            ll_getclassattr = func_with_new_name(ll_getclassattr,
                                                 'll_get_' + mangled)
            graph = self.rtyper.annotate_helper(ll_getclassattr,
                                                [self.lowleveltype])
            m = ootype.meth(M,
                            _name=mangled,
                            _callable=ll_getclassattr,
                            graph=graph)

        ootype.addMethods(self.lowleveltype, {mangled: m})
Пример #13
0
    def attach_class_attr_accessor(self, mangled, oovalue):
        def ll_getclassattr(self):
            return oovalue

        M = ootype.Meth([], ootype.typeOf(oovalue))
        ll_getclassattr = func_with_new_name(ll_getclassattr,
                                             'll_get_' + mangled)
        graph = self.rtyper.annotate_helper(ll_getclassattr, [self.lowleveltype])
        m = ootype.meth(M, _name=mangled, _callable=ll_getclassattr,
                        graph=graph)
        ootype.addMethods(self.lowleveltype, {mangled: m})
Пример #14
0
    def attach_class_attr_accessor(self, mangled, oovalue):
        def ll_getclassattr(self):
            return oovalue

        M = ootype.Meth([], ootype.typeOf(oovalue))
        ll_getclassattr = func_with_new_name(ll_getclassattr,
                                             'll_get_' + mangled)
        graph = self.rtyper.annotate_helper(ll_getclassattr,
                                            [self.lowleveltype])
        m = ootype.meth(M,
                        _name=mangled,
                        _callable=ll_getclassattr,
                        graph=graph)
        ootype.addMethods(self.lowleveltype, {mangled: m})
Пример #15
0
 def attach_abstract_class_attr_accessor(self, mangled, attrtype):
     M = ootype.Meth([], attrtype)
     m = ootype.meth(M, _name=mangled, abstract=True)
     ootype.addMethods(self.lowleveltype, {mangled: m})
Пример #16
0
 def attach_abstract_class_attr_accessor(self, mangled, attrtype):
     M = ootype.Meth([], attrtype)
     m = ootype.meth(M, _name=mangled, abstract=True)
     ootype.addMethods(self.lowleveltype, {mangled: m})
Пример #17
0
def test_nonvirtual():
    A = Instance("A", ROOT)
    addMethods(A, {"foo": meth(Meth([], Void))})

    check_virtual_methods()
    assert A._methods["foo"]._virtual == False
Пример #18
0
def test_nonvirtual():
    A = Instance("A", ROOT)
    addMethods(A, {"foo": meth(Meth([], Void))})

    check_virtual_methods()
    assert A._methods["foo"]._virtual == False