Source

pypy / pypy / rpython / ootypesystem / exceptiondata.py

Niklaus Haldiman… 5358596 
Niklaus Haldiman… 4e87b94 
Niklaus Haldiman… bba4106 
Niklaus Haldiman… 4e87b94 
Niklaus Haldiman… bba4106 
Niklaus Haldiman… 5358596 



Niklaus Haldiman… dbed09d 











Niklaus Haldiman… 5358596 
Niklaus Haldiman… 4e87b94 
Niklaus Haldiman… bba4106 
Antonio Cuni 5a1153c 
Niklaus Haldiman… 5358596 
Niklaus Haldiman… 4e87b94 
Armin Rigo 830312b 

Samuele Pedroni c1da916 

Antonio Cuni 5a1153c 
Samuele Pedroni c1da916 
Niklaus Haldiman… bba4106 


Samuele Pedroni c1da916 

Niklaus Haldiman… bba4106 
Antonio Cuni cbadfe9 
from pypy.rpython.exceptiondata import AbstractExceptionData
from pypy.rpython.ootypesystem import rclass
from pypy.rpython.ootypesystem import ootype
from pypy.annotation import model as annmodel
from pypy.annotation.classdef import FORCE_ATTRIBUTES_INTO_CLASSES

class ExceptionData(AbstractExceptionData):
    """Public information for the code generators to help with exceptions."""

    def __init__(self, rtyper):
        AbstractExceptionData.__init__(self, rtyper)
        self._compute_exception_instance(rtyper)

    def _compute_exception_instance(self, rtyper):
        excdef = rtyper.annotator.bookkeeper.getuniqueclassdef(Exception)
        excrepr = rclass.getinstancerepr(rtyper, excdef)
        self._EXCEPTION_INST = excrepr.lowleveltype

    def is_exception_instance(self, INSTANCE):
        return ootype.isSubclass(INSTANCE, self._EXCEPTION_INST)

    def make_helpers(self, rtyper):
        self.fn_exception_match = self.make_exception_matcher(rtyper)
        self.fn_type_of_exc_inst = self.make_type_of_exc_inst(rtyper)
        self.fn_raise_OSError    = self.make_raise_OSError(rtyper)        

    def make_exception_matcher(self, rtyper):
        # ll_exception_matcher(real_exception_class, match_exception_class)
        s_classtype = annmodel.SomeOOClass(ootype.ROOT)
        helper_fn = rtyper.annotate_helper_fn(rclass.ll_issubclass, [s_classtype, s_classtype])
        return helper_fn

    
    def make_type_of_exc_inst(self, rtyper):
        # ll_type_of_exc_inst(exception_instance) -> exception_vtable
        s_excinst = annmodel.SomeOOInstance(self.lltype_of_exception_value)
        helper_fn = rtyper.annotate_helper_fn(rclass.ll_inst_type, [s_excinst])
        return helper_fn

    def cast_exception(self, TYPE, value):
        return ootype.ooupcast(TYPE, value)