<s> """<STR_LIT>""" <EOL> import sys <EOL> from pypy . annotation . model import SomeInteger , SomeObject , SomeChar , SomeBool <EOL> from pypy . annotation . model import SomeString , SomeTuple , s_Bool , SomeBuiltin <EOL> from pypy . annotation . model import SomeUnicodeCodePoint , SomeAddress <EOL> from pypy . annotation . model import SomeFloat , unionof , SomeUnicodeString <EOL> from pypy . annotation . model import SomePBC , SomeInstance , SomeDict <EOL> from pypy . annotation . model import SomeWeakRef <EOL> from pypy . annotation . model import SomeOOObject <EOL> from pypy . annotation . model import annotation_to_lltype , lltype_to_annotation , ll_to_annotation <EOL> from pypy . annotation . model import add_knowntypedata <EOL> from pypy . annotation . model import s_ImpossibleValue <EOL> from pypy . annotation . bookkeeper import getbookkeeper <EOL> from pypy . annotation import description <EOL> from pypy . objspace . flow . model import Constant <EOL> from pypy . tool . error import AnnotatorError <EOL> import pypy . rlib . rarithmetic <EOL> import pypy . rlib . objectmodel <EOL> def immutablevalue ( x ) : <EOL> return getbookkeeper ( ) . immutablevalue ( x ) <EOL> def constpropagate ( func , args_s , s_result ) : <EOL> """<STR_LIT>""" <EOL> args = [ ] <EOL> for s in args_s : <EOL> if not s . is_immutable_constant ( ) : <EOL> return s_result <EOL> args . append ( s . const ) <EOL> try : <EOL> realresult = func ( * args ) <EOL> except ( ValueError , OverflowError ) : <EOL> return s_ImpossibleValue <EOL> s_realresult = immutablevalue ( realresult ) <EOL> if not s_result . contains ( s_realresult ) : <EOL> raise Exception ( "<STR_LIT>" % ( <EOL> func , args , realresult , s_result ) ) <EOL> return s_realresult <EOL> def builtin_range ( * args ) : <EOL> s_step = immutablevalue ( <NUM_LIT:1> ) <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> s_start = immutablevalue ( <NUM_LIT:0> ) <EOL> s_stop = args [ <NUM_LIT:0> ] <EOL> elif len ( args ) == <NUM_LIT:2> : <EOL> s_start , s_stop = args <EOL> elif len ( args ) == <NUM_LIT:3> : <EOL> s_start , s_stop = args [ : <NUM_LIT:2> ] <EOL> s_step = args [ <NUM_LIT:2> ] <EOL> else : <EOL> raise Exception , "<STR_LIT>" <EOL> empty = False <EOL> if not s_step . is_constant ( ) : <EOL> step = <NUM_LIT:0> <EOL> else : <EOL> step = s_step . const <EOL> if step == <NUM_LIT:0> : <EOL> raise Exception , "<STR_LIT>" <EOL> if s_start . is_constant ( ) and s_stop . is_constant ( ) : <EOL> try : <EOL> if len ( xrange ( s_start . const , s_stop . const , step ) ) == <NUM_LIT:0> : <EOL> empty = True <EOL> except TypeError : <EOL> pass <EOL> if empty : <EOL> s_item = s_ImpossibleValue <EOL> else : <EOL> nonneg = False <EOL> if step > <NUM_LIT:0> : <EOL> nonneg = s_start . nonneg <EOL> elif step < <NUM_LIT:0> : <EOL> nonneg = s_stop . nonneg or ( s_stop . is_constant ( ) and <EOL> s_stop . const >= - <NUM_LIT:1> ) <EOL> s_item = SomeInteger ( nonneg = nonneg ) <EOL> return getbookkeeper ( ) . newlist ( s_item , range_step = step ) <EOL> builtin_xrange = builtin_range <EOL> def builtin_bool ( s_obj ) : <EOL> return s_obj . is_true ( ) <EOL> def builtin_int ( s_obj , s_base = None ) : <EOL> assert ( s_base is None or isinstance ( s_base , SomeInteger ) <EOL> and s_obj . knowntype == str ) , "<STR_LIT>" <EOL> if s_base is not None : <EOL> args_s = [ s_obj , s_base ] <EOL> else : <EOL> args_s = [ s_obj ] <EOL> nonneg = isinstance ( s_obj , SomeInteger ) and s_obj . nonneg <EOL> return constpropagate ( int , args_s , SomeInteger ( nonneg = nonneg ) ) <EOL> def builtin_float ( s_obj ) : <EOL> return constpropagate ( float , [ s_obj ] , SomeFloat ( ) ) <EOL> def builtin_chr ( s_int ) : <EOL> return constpropagate ( chr , [ s_int ] , SomeChar ( ) ) <EOL> def builtin_unichr ( s_int ) : <EOL> return constpropagate ( unichr , [ s_int ] , SomeUnicodeCodePoint ( ) ) <EOL> def builtin_unicode ( s_unicode ) : <EOL> return constpropagate ( unicode , [ s_unicode ] , SomeUnicodeString ( ) ) <EOL> def our_issubclass ( cls1 , cls2 ) : <EOL> """<STR_LIT>""" <EOL> from pypy . annotation . classdef import ClassDef <EOL> if cls2 is object : <EOL> return True <EOL> def classify ( cls ) : <EOL> if isinstance ( cls , ClassDef ) : <EOL> return '<STR_LIT>' <EOL> if cls . __module__ == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> kind1 = classify ( cls1 ) <EOL> kind2 = classify ( cls2 ) <EOL> if kind1 != '<STR_LIT>' and kind2 != '<STR_LIT>' : <EOL> return issubclass ( cls1 , cls2 ) <EOL> if kind1 == '<STR_LIT>' and kind2 == '<STR_LIT>' : <EOL> return False <EOL> elif kind1 == '<STR_LIT>' and kind2 == '<STR_LIT>' : <EOL> return issubclass ( object , cls2 ) <EOL> else : <EOL> bk = getbookkeeper ( ) <EOL> def toclassdef ( kind , cls ) : <EOL> if kind != '<STR_LIT>' : <EOL> return bk . getuniqueclassdef ( cls ) <EOL> else : <EOL> return cls <EOL> return toclassdef ( kind1 , cls1 ) . issubclass ( toclassdef ( kind2 , cls2 ) ) <EOL> def builtin_isinstance ( s_obj , s_type , variables = None ) : <EOL> r = SomeBool ( ) <EOL> if s_type . is_constant ( ) : <EOL> typ = s_type . const <EOL> if issubclass ( typ , pypy . rlib . rarithmetic . base_int ) : <EOL> r . const = issubclass ( s_obj . knowntype , typ ) <EOL> else : <EOL> if typ == long : <EOL> getbookkeeper ( ) . warning ( "<STR_LIT>" ) <EOL> if s_obj . is_constant ( ) : <EOL> r . const = isinstance ( s_obj . const , long ) <EOL> else : <EOL> if type ( s_obj ) is not SomeObject : <EOL> r . const = False <EOL> return r <EOL> assert not issubclass ( typ , ( int , long ) ) or typ in ( bool , int ) , ( <EOL> "<STR_LIT>" ) <EOL> if s_obj . is_constant ( ) : <EOL> r . const = isinstance ( s_obj . const , typ ) <EOL> elif our_issubclass ( s_obj . knowntype , typ ) : <EOL> if not s_obj . can_be_none ( ) : <EOL> r . const = True <EOL> elif not our_issubclass ( typ , s_obj . knowntype ) : <EOL> r . const = False <EOL> elif s_obj . knowntype == int and typ == bool : <EOL> r . const = False <EOL> bk = getbookkeeper ( ) <EOL> if variables is None : <EOL> fn , block , i = bk . position_key <EOL> op = block . operations [ i ] <EOL> assert op . opname == "<STR_LIT>" <EOL> assert len ( op . args ) == <NUM_LIT:3> <EOL> assert op . args [ <NUM_LIT:0> ] == Constant ( isinstance ) <EOL> variables = [ op . args [ <NUM_LIT:1> ] ] <EOL> for variable in variables : <EOL> assert bk . annotator . binding ( variable ) == s_obj <EOL> r . knowntypedata = { } <EOL> if ( not isinstance ( s_type , SomeBuiltin ) <EOL> or typ . __module__ == '<STR_LIT>' ) : <EOL> add_knowntypedata ( r . knowntypedata , True , variables , bk . valueoftype ( typ ) ) <EOL> return r <EOL> def builtin_hasattr ( s_obj , s_attr ) : <EOL> if not s_attr . is_constant ( ) or not isinstance ( s_attr . const , str ) : <EOL> getbookkeeper ( ) . warning ( '<STR_LIT>' % <EOL> ( s_obj , s_attr ) ) <EOL> r = SomeBool ( ) <EOL> if s_obj . is_immutable_constant ( ) : <EOL> r . const = hasattr ( s_obj . const , s_attr . const ) <EOL> elif ( isinstance ( s_obj , SomePBC ) <EOL> and s_obj . getKind ( ) is description . FrozenDesc ) : <EOL> answers = { } <EOL> for d in s_obj . descriptions : <EOL> answer = ( d . s_read_attribute ( s_attr . const ) != s_ImpossibleValue ) <EOL> answers [ answer ] = True <EOL> if len ( answers ) == <NUM_LIT:1> : <EOL> r . const , = answers <EOL> return r <EOL> def builtin_tuple ( s_iterable ) : <EOL> if isinstance ( s_iterable , SomeTuple ) : <EOL> return s_iterable <EOL> return SomeObject ( ) <EOL> def builtin_list ( s_iterable ) : <EOL> s_iter = s_iterable . iter ( ) <EOL> return getbookkeeper ( ) . newlist ( s_iter . next ( ) ) <EOL> def builtin_zip ( s_iterable1 , s_iterable2 ) : <EOL> s_iter1 = s_iterable1 . iter ( ) <EOL> s_iter2 = s_iterable2 . iter ( ) <EOL> s_tup = SomeTuple ( ( s_iter1 . next ( ) , s_iter2 . next ( ) ) ) <EOL> return getbookkeeper ( ) . newlist ( s_tup ) <EOL> def builtin_min ( * s_values ) : <EOL> if len ( s_values ) == <NUM_LIT:1> : <EOL> s_iter = s_values [ <NUM_LIT:0> ] . iter ( ) <EOL> return s_iter . next ( ) <EOL> else : <EOL> return unionof ( * s_values ) <EOL> def builtin_max ( * s_values ) : <EOL> if len ( s_values ) == <NUM_LIT:1> : <EOL> s_iter = s_values [ <NUM_LIT:0> ] . iter ( ) <EOL> return s_iter . next ( ) <EOL> else : <EOL> s = unionof ( * s_values ) <EOL> if type ( s ) is SomeInteger and not s . nonneg : <EOL> nonneg = False <EOL> for s1 in s_values : <EOL> nonneg |= s1 . nonneg <EOL> if nonneg : <EOL> s = SomeInteger ( nonneg = True , knowntype = s . knowntype ) <EOL> return s <EOL> def builtin_apply ( * stuff ) : <EOL> getbookkeeper ( ) . warning ( "<STR_LIT>" % ( stuff , ) ) <EOL> return SomeObject ( ) <EOL> def OSError_init ( s_self , * args ) : <EOL> pass <EOL> def WindowsError_init ( s_self , * args ) : <EOL> pass <EOL> def termios_error_init ( s_self , * args ) : <EOL> pass <EOL> def object_init ( s_self , * args ) : <EOL> pass <EOL> def conf ( ) : <EOL> return SomeString ( ) <EOL> def rarith_intmask ( s_obj ) : <EOL> return SomeInteger ( ) <EOL> def robjmodel_instantiate ( s_clspbc ) : <EOL> assert isinstance ( s_clspbc , SomePBC ) <EOL> clsdef = None <EOL> more_than_one = len ( s_clspbc . descriptions ) <EOL> for desc in s_clspbc . descriptions : <EOL> cdef = desc . getuniqueclassdef ( ) <EOL> if more_than_one : <EOL> getbookkeeper ( ) . needs_generic_instantiate [ cdef ] = True <EOL> if not clsdef : <EOL> clsdef = cdef <EOL> else : <EOL> clsdef = clsdef . commonbase ( cdef ) <EOL> return SomeInstance ( clsdef ) <EOL> def robjmodel_we_are_translated ( ) : <EOL> return immutablevalue ( True ) <EOL> def robjmodel_r_dict ( s_eqfn , s_hashfn ) : <EOL> dictdef = getbookkeeper ( ) . getdictdef ( is_r_dict = True ) <EOL> dictdef . dictkey . update_rdict_annotations ( s_eqfn , s_hashfn ) <EOL> return SomeDict ( dictdef ) <EOL> def robjmodel_hlinvoke ( s_repr , s_llcallable , * args_s ) : <EOL> from pypy . rpython import rmodel <EOL> assert s_repr . is_constant ( ) and isinstance ( s_repr . const , rmodel . Repr ) , "<STR_LIT>" <EOL> r_func , nimplicitarg = s_repr . const . get_r_implfunc ( ) <EOL> nbargs = len ( args_s ) + nimplicitarg <EOL> s_sigs = r_func . get_s_signatures ( ( nbargs , ( ) , False , False ) ) <EOL> if len ( s_sigs ) != <NUM_LIT:1> : <EOL> raise TyperError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( s_repr . const , <EOL> s_sigs ) ) <EOL> _ , s_ret = s_sigs [ <NUM_LIT:0> ] <EOL> rresult = r_func . rtyper . getrepr ( s_ret ) <EOL> return lltype_to_annotation ( rresult . lowleveltype ) <EOL> def robjmodel_keepalive_until_here ( * args_s ) : <EOL> return immutablevalue ( None ) <EOL> def llmemory_cast_ptr_to_adr ( s ) : <EOL> from pypy . annotation . model import SomeInteriorPtr <EOL> assert not isinstance ( s , SomeInteriorPtr ) <EOL> return SomeAddress ( ) <EOL> def llmemory_cast_adr_to_ptr ( s , s_type ) : <EOL> assert s_type . is_constant ( ) <EOL> return SomePtr ( s_type . const ) <EOL> def llmemory_cast_adr_to_int ( s ) : <EOL> return SomeInteger ( ) <EOL> def llmemory_cast_int_to_adr ( s ) : <EOL> return SomeAddress ( ) <EOL> def unicodedata_decimal ( s_uchr ) : <EOL> raise TypeError , "<STR_LIT>" <EOL> def test ( * args ) : <EOL> return s_Bool <EOL> def import_func ( * args ) : <EOL> return SomeObject ( ) <EOL> import __builtin__ <EOL> BUILTIN_ANALYZERS = { } <EOL> for name , value in globals ( ) . items ( ) : <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> original = getattr ( __builtin__ , name [ <NUM_LIT:8> : ] ) <EOL> BUILTIN_ANALYZERS [ original ] = value <EOL> BUILTIN_ANALYZERS [ pypy . rlib . rarithmetic . intmask ] = rarith_intmask <EOL> BUILTIN_ANALYZERS [ pypy . rlib . objectmodel . instantiate ] = robjmodel_instantiate <EOL> BUILTIN_ANALYZERS [ pypy . rlib . objectmodel . we_are_translated ] = ( <EOL> robjmodel_we_are_translated ) <EOL> BUILTIN_ANALYZERS [ pypy . rlib . objectmodel . r_dict ] = robjmodel_r_dict <EOL> BUILTIN_ANALYZERS [ pypy . rlib . objectmodel . hlinvoke ] = robjmodel_hlinvoke <EOL> BUILTIN_ANALYZERS [ pypy . rlib . objectmodel . keepalive_until_here ] = robjmodel_keepalive_until_here <EOL> BUILTIN_ANALYZERS [ pypy . rpython . lltypesystem . llmemory . cast_ptr_to_adr ] = llmemory_cast_ptr_to_adr <EOL> BUILTIN_ANALYZERS [ pypy . rpython . lltypesystem . llmemory . cast_adr_to_ptr ] = llmemory_cast_adr_to_ptr <EOL> BUILTIN_ANALYZERS [ pypy . rpython . lltypesystem . llmemory . cast_adr_to_int ] = llmemory_cast_adr_to_int <EOL> BUILTIN_ANALYZERS [ pypy . rpython . lltypesystem . llmemory . cast_int_to_adr ] = llmemory_cast_int_to_adr <EOL> BUILTIN_ANALYZERS [ getattr ( OSError . __init__ , '<STR_LIT>' , OSError . __init__ ) ] = ( <EOL> OSError_init ) <EOL> try : <EOL> WindowsError <EOL> except NameError : <EOL> pass <EOL> else : <EOL> BUILTIN_ANALYZERS [ getattr ( WindowsError . __init__ , '<STR_LIT>' , <EOL> WindowsError . __init__ ) ] = ( <EOL> WindowsError_init ) <EOL> BUILTIN_ANALYZERS [ sys . getdefaultencoding ] = conf <EOL> try : <EOL> import unicodedata <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> BUILTIN_ANALYZERS [ unicodedata . decimal ] = unicodedata_decimal <EOL> BUILTIN_ANALYZERS [ object . __init__ ] = object_init <EOL> BUILTIN_ANALYZERS [ __import__ ] = import_func <EOL> from pypy . annotation . model import SomePtr <EOL> from pypy . rpython . lltypesystem import lltype <EOL> def malloc ( s_T , s_n = None , s_flavor = None , s_zero = None ) : <EOL> assert ( s_n is None or s_n . knowntype == int <EOL> or issubclass ( s_n . knowntype , pypy . rlib . rarithmetic . base_int ) ) <EOL> assert s_T . is_constant ( ) <EOL> if s_n is not None : <EOL> n = <NUM_LIT:1> <EOL> else : <EOL> n = None <EOL> if s_zero : <EOL> assert s_zero . is_constant ( ) <EOL> if s_flavor is None : <EOL> p = lltype . malloc ( s_T . const , n ) <EOL> r = SomePtr ( lltype . typeOf ( p ) ) <EOL> else : <EOL> assert s_flavor . is_constant ( ) <EOL> r = SomePtr ( lltype . Ptr ( s_T . const ) ) <EOL> return r <EOL> def free ( s_p , s_flavor ) : <EOL> assert s_flavor . is_constant ( ) <EOL> def typeOf ( s_val ) : <EOL> lltype = annotation_to_lltype ( s_val , info = "<STR_LIT>" ) <EOL> return immutablevalue ( lltype ) <EOL> def cast_primitive ( T , s_v ) : <EOL> assert T . is_constant ( ) <EOL> return ll_to_annotation ( lltype . cast_primitive ( T . const , annotation_to_lltype ( s_v ) . _defl ( ) ) ) <EOL> def nullptr ( T ) : <EOL> assert T . is_constant ( ) <EOL> p = lltype . nullptr ( T . const ) <EOL> return immutablevalue ( p ) <EOL> def cast_pointer ( PtrT , s_p ) : <EOL> assert isinstance ( s_p , SomePtr ) , "<STR_LIT>" % s_p <EOL> assert PtrT . is_constant ( ) <EOL> cast_p = lltype . cast_pointer ( PtrT . const , s_p . ll_ptrtype . _defl ( ) ) <EOL> return SomePtr ( ll_ptrtype = lltype . typeOf ( cast_p ) ) <EOL> def cast_opaque_ptr ( PtrT , s_p ) : <EOL> assert isinstance ( s_p , SomePtr ) , "<STR_LIT>" % s_p <EOL> assert PtrT . is_constant ( ) <EOL> cast_p = lltype . cast_opaque_ptr ( PtrT . const , s_p . ll_ptrtype . _defl ( ) ) <EOL> return SomePtr ( ll_ptrtype = lltype . typeOf ( cast_p ) ) <EOL> def direct_fieldptr ( s_p , s_fieldname ) : <EOL> assert isinstance ( s_p , SomePtr ) , "<STR_LIT>" % s_p <EOL> assert s_fieldname . is_constant ( ) <EOL> cast_p = lltype . direct_fieldptr ( s_p . ll_ptrtype . _example ( ) , <EOL> s_fieldname . const ) <EOL> return SomePtr ( ll_ptrtype = lltype . typeOf ( cast_p ) ) <EOL> def direct_arrayitems ( s_p ) : <EOL> assert isinstance ( s_p , SomePtr ) , "<STR_LIT>" % s_p <EOL> cast_p = lltype . direct_arrayitems ( s_p . ll_ptrtype . _example ( ) ) <EOL> return SomePtr ( ll_ptrtype = lltype . typeOf ( cast_p ) ) <EOL> def direct_ptradd ( s_p , s_n ) : <EOL> assert isinstance ( s_p , SomePtr ) , "<STR_LIT>" % s_p <EOL> return s_p <EOL> def cast_ptr_to_int ( s_ptr ) : <EOL> return SomeInteger ( ) <EOL> def cast_int_to_ptr ( PtrT , s_int ) : <EOL> assert PtrT . is_constant ( ) <EOL> return SomePtr ( ll_ptrtype = PtrT . const ) <EOL> def identityhash ( s_obj ) : <EOL> assert isinstance ( s_obj , ( SomePtr , SomeOOObject , SomeOOInstance ) ) <EOL> return SomeInteger ( ) <EOL> def getRuntimeTypeInfo ( T ) : <EOL> assert T . is_constant ( ) <EOL> return immutablevalue ( lltype . getRuntimeTypeInfo ( T . const ) ) <EOL> def runtime_type_info ( s_p ) : <EOL> assert isinstance ( s_p , SomePtr ) , "<STR_LIT>" % s_p <EOL> return SomePtr ( lltype . typeOf ( lltype . runtime_type_info ( s_p . ll_ptrtype . _example ( ) ) ) ) <EOL> def constPtr ( T ) : <EOL> assert T . is_constant ( ) <EOL> return immutablevalue ( lltype . Ptr ( T . const ) ) <EOL> BUILTIN_ANALYZERS [ lltype . malloc ] = malloc <EOL> BUILTIN_ANALYZERS [ lltype . free ] = free <EOL> BUILTIN_ANALYZERS [ lltype . typeOf ] = typeOf <EOL> BUILTIN_ANALYZERS [ lltype . cast_primitive ] = cast_primitive <EOL> BUILTIN_ANALYZERS [ lltype . nullptr ] = nullptr <EOL> BUILTIN_ANALYZERS [ lltype . cast_pointer ] = cast_pointer <EOL> BUILTIN_ANALYZERS [ lltype . cast_opaque_ptr ] = cast_opaque_ptr <EOL> BUILTIN_ANALYZERS [ lltype . direct_fieldptr ] = direct_fieldptr <EOL> BUILTIN_ANALYZERS [ lltype . direct_arrayitems ] = direct_arrayitems <EOL> BUILTIN_ANALYZERS [ lltype . direct_ptradd ] = direct_ptradd <EOL> BUILTIN_ANALYZERS [ lltype . cast_ptr_to_int ] = cast_ptr_to_int <EOL> BUILTIN_ANALYZERS [ lltype . cast_int_to_ptr ] = cast_int_to_ptr <EOL> BUILTIN_ANALYZERS [ lltype . identityhash ] = identityhash <EOL> BUILTIN_ANALYZERS [ lltype . getRuntimeTypeInfo ] = getRuntimeTypeInfo <EOL> BUILTIN_ANALYZERS [ lltype . runtime_type_info ] = runtime_type_info <EOL> BUILTIN_ANALYZERS [ lltype . Ptr ] = constPtr <EOL> from pypy . annotation . model import SomeOOInstance , SomeOOClass , SomeOOStaticMeth <EOL> from pypy . rpython . ootypesystem import ootype <EOL> def new ( I ) : <EOL> assert I . is_constant ( ) <EOL> i = ootype . new ( I . const ) <EOL> r = SomeOOInstance ( ootype . typeOf ( i ) ) <EOL> return r <EOL> def oonewarray ( s_type , length ) : <EOL> assert s_type . is_constant ( ) <EOL> return SomeOOInstance ( s_type . const ) <EOL> def null ( I_OR_SM ) : <EOL> assert I_OR_SM . is_constant ( ) <EOL> null = ootype . null ( I_OR_SM . const ) <EOL> r = lltype_to_annotation ( ootype . typeOf ( null ) ) <EOL> return r <EOL> def instanceof ( i , I ) : <EOL> assert I . is_constant ( ) <EOL> assert isinstance ( I . const , ootype . Instance ) <EOL> return s_Bool <EOL> def classof ( i ) : <EOL> assert isinstance ( i , SomeOOInstance ) <EOL> return SomeOOClass ( i . ootype ) <EOL> def subclassof ( class1 , class2 ) : <EOL> assert isinstance ( class1 , SomeOOClass ) <EOL> assert isinstance ( class2 , SomeOOClass ) <EOL> return s_Bool <EOL> def runtimenew ( c ) : <EOL> assert isinstance ( c , SomeOOClass ) <EOL> if c . ootype is None : <EOL> return s_ImpossibleValue <EOL> else : <EOL> return SomeOOInstance ( c . ootype ) <EOL> def ooupcast ( I , i ) : <EOL> assert isinstance ( I . const , ootype . Instance ) <EOL> if ootype . isSubclass ( i . ootype , I . const ) : <EOL> return SomeOOInstance ( I . const ) <EOL> else : <EOL> raise AnnotatorError , '<STR_LIT>' % ( i . ootype , I . const ) <EOL> def oodowncast ( I , i ) : <EOL> assert isinstance ( I . const , ootype . Instance ) <EOL> if ootype . isSubclass ( I . const , i . ootype ) : <EOL> return SomeOOInstance ( I . const ) <EOL> else : <EOL> raise AnnotatorError , '<STR_LIT>' % ( i . ootype , I . const ) <EOL> def cast_to_object ( obj ) : <EOL> assert isinstance ( obj , SomeOOStaticMeth ) or ( isinstance ( obj , SomeOOClass ) and obj . ootype is None ) or isinstance ( obj . ootype , ootype . OOType ) <EOL> return SomeOOObject ( ) <EOL> def cast_from_object ( T , obj ) : <EOL> TYPE = T . const <EOL> if TYPE is ootype . Object : <EOL> return SomeOOObject ( ) <EOL> elif TYPE is ootype . Class : <EOL> return SomeOOClass ( ootype . ROOT ) <EOL> elif isinstance ( TYPE , ootype . StaticMethod ) : <EOL> return SomeOOStaticMeth ( TYPE ) <EOL> elif isinstance ( TYPE , ootype . OOType ) : <EOL> return SomeOOInstance ( TYPE ) <EOL> else : <EOL> raise AnnotatorError , '<STR_LIT>' % TYPE <EOL> BUILTIN_ANALYZERS [ ootype . instanceof ] = instanceof <EOL> BUILTIN_ANALYZERS [ ootype . new ] = new <EOL> BUILTIN_ANALYZERS [ ootype . oonewarray ] = oonewarray <EOL> BUILTIN_ANALYZERS [ ootype . null ] = null <EOL> BUILTIN_ANALYZERS [ ootype . runtimenew ] = runtimenew <EOL> BUILTIN_ANALYZERS [ ootype . classof ] = classof <EOL> BUILTIN_ANALYZERS [ ootype . subclassof ] = subclassof <EOL> BUILTIN_ANALYZERS [ ootype . ooupcast ] = ooupcast <EOL> BUILTIN_ANALYZERS [ ootype . oodowncast ] = oodowncast <EOL> BUILTIN_ANALYZERS [ ootype . cast_to_object ] = cast_to_object <EOL> BUILTIN_ANALYZERS [ ootype . cast_from_object ] = cast_from_object <EOL> import weakref <EOL> def weakref_ref ( s_obj ) : <EOL> if not isinstance ( s_obj , SomeInstance ) : <EOL> raise Exception ( "<STR_LIT>" % ( s_obj , ) ) <EOL> if s_obj . can_be_None : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return SomeWeakRef ( s_obj . classdef ) <EOL> BUILTIN_ANALYZERS [ weakref . ref ] = weakref_ref <EOL> def llweakref_create ( s_obj ) : <EOL> if ( not isinstance ( s_obj , SomePtr ) or <EOL> s_obj . ll_ptrtype . TO . _gckind != '<STR_LIT>' ) : <EOL> raise Exception ( "<STR_LIT>" % ( <EOL> s_obj , ) ) <EOL> return SomePtr ( llmemory . WeakRefPtr ) <EOL> def llweakref_deref ( s_ptrtype , s_wref ) : <EOL> if not ( s_ptrtype . is_constant ( ) and <EOL> isinstance ( s_ptrtype . const , lltype . Ptr ) and <EOL> s_ptrtype . const . TO . _gckind == '<STR_LIT>' ) : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( s_ptrtype , ) ) <EOL> if not ( isinstance ( s_wref , SomePtr ) and <EOL> s_wref . ll_ptrtype == llmemory . WeakRefPtr ) : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( s_wref , ) ) <EOL> return SomePtr ( s_ptrtype . const ) <EOL> def llcast_ptr_to_weakrefptr ( s_ptr ) : <EOL> assert isinstance ( s_ptr , SomePtr ) <EOL> return SomePtr ( llmemory . WeakRefPtr ) <EOL> def llcast_weakrefptr_to_ptr ( s_ptrtype , s_wref ) : <EOL> if not ( s_ptrtype . is_constant ( ) and <EOL> isinstance ( s_ptrtype . const , lltype . Ptr ) ) : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( s_ptrtype , ) ) <EOL> if not ( isinstance ( s_wref , SomePtr ) and <EOL> s_wref . ll_ptrtype == llmemory . WeakRefPtr ) : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( s_wref , ) ) <EOL> return SomePtr ( s_ptrtype . const ) <EOL> from pypy . rpython . lltypesystem import llmemory <EOL> BUILTIN_ANALYZERS [ llmemory . weakref_create ] = llweakref_create <EOL> BUILTIN_ANALYZERS [ llmemory . weakref_deref ] = llweakref_deref <EOL> BUILTIN_ANALYZERS [ llmemory . cast_ptr_to_weakrefptr ] = llcast_ptr_to_weakrefptr <EOL> BUILTIN_ANALYZERS [ llmemory . cast_weakrefptr_to_ptr ] = llcast_weakrefptr_to_ptr <EOL> def robjmodel_free_non_gc_object ( obj ) : <EOL> pass <EOL> BUILTIN_ANALYZERS [ pypy . rlib . objectmodel . free_non_gc_object ] = ( <EOL> robjmodel_free_non_gc_object ) <EOL> def raw_malloc ( s_size ) : <EOL> assert isinstance ( s_size , SomeInteger ) <EOL> return SomeAddress ( ) <EOL> def raw_malloc_usage ( s_size ) : <EOL> assert isinstance ( s_size , SomeInteger ) <EOL> return SomeInteger ( nonneg = True ) <EOL> def raw_free ( s_addr ) : <EOL> assert isinstance ( s_addr , SomeAddress ) <EOL> assert not s_addr . is_null <EOL> def raw_memclear ( s_addr , s_int ) : <EOL> assert isinstance ( s_addr , SomeAddress ) <EOL> assert not s_addr . is_null <EOL> assert isinstance ( s_int , SomeInteger ) <EOL> def raw_memcopy ( s_addr1 , s_addr2 , s_int ) : <EOL> assert isinstance ( s_addr1 , SomeAddress ) <EOL> assert not s_addr1 . is_null <EOL> assert isinstance ( s_addr2 , SomeAddress ) <EOL> assert not s_addr2 . is_null <EOL> assert isinstance ( s_int , SomeInteger ) <EOL> BUILTIN_ANALYZERS [ llmemory . raw_malloc ] = raw_malloc <EOL> BUILTIN_ANALYZERS [ llmemory . raw_malloc_usage ] = raw_malloc_usage <EOL> BUILTIN_ANALYZERS [ llmemory . raw_free ] = raw_free <EOL> BUILTIN_ANALYZERS [ llmemory . raw_memclear ] = raw_memclear <EOL> BUILTIN_ANALYZERS [ llmemory . raw_memcopy ] = raw_memcopy <EOL> def offsetof ( TYPE , fldname ) : <EOL> return SomeInteger ( ) <EOL> BUILTIN_ANALYZERS [ llmemory . offsetof ] = offsetof </s>
