<s> import types , py <EOL> from pypy . objspace . flow . model import Constant , FunctionGraph <EOL> from pypy . interpreter . pycode import cpython_code_signature <EOL> from pypy . interpreter . argument import rawshape <EOL> from pypy . interpreter . argument import ArgErr <EOL> from pypy . tool . sourcetools import valid_identifier <EOL> from pypy . tool . pairtype import extendabletype <EOL> class CallFamily : <EOL> """<STR_LIT>""" <EOL> overridden = False <EOL> normalized = False <EOL> def __init__ ( self , desc ) : <EOL> self . descs = { desc : True } <EOL> self . calltables = { } <EOL> self . total_calltable_size = <NUM_LIT:0> <EOL> def update ( self , other ) : <EOL> self . normalized = self . normalized or other . normalized <EOL> self . descs . update ( other . descs ) <EOL> for shape , table in other . calltables . items ( ) : <EOL> for row in table : <EOL> self . calltable_add_row ( shape , row ) <EOL> absorb = update <EOL> def calltable_lookup_row ( self , callshape , row ) : <EOL> table = self . calltables . setdefault ( callshape , [ ] ) <EOL> for i , existing_row in enumerate ( table ) : <EOL> if existing_row == row : <EOL> return i <EOL> raise LookupError <EOL> def calltable_add_row ( self , callshape , row ) : <EOL> try : <EOL> self . calltable_lookup_row ( callshape , row ) <EOL> except LookupError : <EOL> table = self . calltables . setdefault ( callshape , [ ] ) <EOL> table . append ( row ) <EOL> self . total_calltable_size += <NUM_LIT:1> <EOL> class FrozenAttrFamily : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , desc ) : <EOL> self . descs = { desc : True } <EOL> self . read_locations = { } <EOL> self . attrs = { } <EOL> def update ( self , other ) : <EOL> self . descs . update ( other . descs ) <EOL> self . read_locations . update ( other . read_locations ) <EOL> self . attrs . update ( other . attrs ) <EOL> absorb = update <EOL> def get_s_value ( self , attrname ) : <EOL> try : <EOL> return self . attrs [ attrname ] <EOL> except KeyError : <EOL> from pypy . annotation . model import s_ImpossibleValue <EOL> return s_ImpossibleValue <EOL> def set_s_value ( self , attrname , s_value ) : <EOL> self . attrs [ attrname ] = s_value <EOL> class ClassAttrFamily : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , desc ) : <EOL> from pypy . annotation . model import s_ImpossibleValue <EOL> self . descs = { desc : True } <EOL> self . read_locations = { } <EOL> self . s_value = s_ImpossibleValue <EOL> def update ( self , other ) : <EOL> from pypy . annotation . model import unionof <EOL> self . descs . update ( other . descs ) <EOL> self . read_locations . update ( other . read_locations ) <EOL> self . s_value = unionof ( self . s_value , other . s_value ) <EOL> absorb = update <EOL> def get_s_value ( self , attrname ) : <EOL> return self . s_value <EOL> def set_s_value ( self , attrname , s_value ) : <EOL> self . s_value = s_value <EOL> class Desc ( object ) : <EOL> __metaclass__ = extendabletype <EOL> def __init__ ( self , bookkeeper , pyobj = None ) : <EOL> self . bookkeeper = bookkeeper <EOL> self . pyobj = pyobj <EOL> def __repr__ ( self ) : <EOL> pyobj = self . pyobj <EOL> if pyobj is None : <EOL> return object . __repr__ ( self ) <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , pyobj ) <EOL> def querycallfamily ( self ) : <EOL> """<STR_LIT>""" <EOL> call_families = self . bookkeeper . pbc_maximal_call_families <EOL> try : <EOL> return call_families [ self ] <EOL> except KeyError : <EOL> return None <EOL> def getcallfamily ( self ) : <EOL> """<STR_LIT>""" <EOL> call_families = self . bookkeeper . pbc_maximal_call_families <EOL> _ , _ , callfamily = call_families . find ( self . rowkey ( ) ) <EOL> return callfamily <EOL> def mergecallfamilies ( self , * others ) : <EOL> """<STR_LIT>""" <EOL> call_families = self . bookkeeper . pbc_maximal_call_families <EOL> changed , rep , callfamily = call_families . find ( self . rowkey ( ) ) <EOL> for desc in others : <EOL> changed1 , rep , callfamily = call_families . union ( rep , desc . rowkey ( ) ) <EOL> changed = changed or changed1 <EOL> return changed <EOL> def queryattrfamily ( self ) : <EOL> return None <EOL> def bind_under ( self , classdef , name ) : <EOL> return self <EOL> def simplify_desc_set ( descs ) : <EOL> pass <EOL> simplify_desc_set = staticmethod ( simplify_desc_set ) <EOL> class NoStandardGraph ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class FunctionDesc ( Desc ) : <EOL> knowntype = types . FunctionType <EOL> overridden = False <EOL> def __init__ ( self , bookkeeper , pyobj = None , <EOL> name = None , signature = None , defaults = None , <EOL> specializer = None ) : <EOL> super ( FunctionDesc , self ) . __init__ ( bookkeeper , pyobj ) <EOL> if name is None : <EOL> name = pyobj . func_name <EOL> if signature is None : <EOL> signature = cpython_code_signature ( pyobj . func_code ) <EOL> if defaults is None : <EOL> defaults = pyobj . func_defaults <EOL> self . name = name <EOL> self . signature = signature <EOL> self . defaults = defaults or ( ) <EOL> self . specializer = specializer <EOL> self . _cache = { } <EOL> def buildgraph ( self , alt_name = None , builder = None ) : <EOL> translator = self . bookkeeper . annotator . translator <EOL> if builder : <EOL> graph = builder ( translator , self . pyobj ) <EOL> else : <EOL> graph = translator . buildflowgraph ( self . pyobj ) <EOL> if alt_name : <EOL> graph . name = alt_name <EOL> return graph <EOL> def getuniquegraph ( self ) : <EOL> if len ( self . _cache ) != <NUM_LIT:1> : <EOL> raise NoStandardGraph ( self ) <EOL> [ graph ] = self . _cache . values ( ) <EOL> if ( graph . signature != self . signature or <EOL> graph . defaults != self . defaults ) : <EOL> raise NoStandardGraph ( self ) <EOL> return graph <EOL> def cachedgraph ( self , key , alt_name = None , builder = None ) : <EOL> try : <EOL> return self . _cache [ key ] <EOL> except KeyError : <EOL> def nameof ( thing ) : <EOL> if isinstance ( thing , str ) : <EOL> return thing <EOL> elif hasattr ( thing , '<STR_LIT>' ) : <EOL> return thing . __name__ <EOL> elif hasattr ( thing , '<STR_LIT:name>' ) : <EOL> return thing . name <EOL> elif isinstance ( thing , tuple ) : <EOL> return '<STR_LIT:_>' . join ( map ( nameof , thing ) ) <EOL> else : <EOL> return str ( thing ) [ : <NUM_LIT:30> ] <EOL> if key is not None and alt_name is None : <EOL> postfix = valid_identifier ( nameof ( key ) ) <EOL> alt_name = "<STR_LIT>" % ( self . name , postfix ) <EOL> graph = self . buildgraph ( alt_name , builder ) <EOL> self . _cache [ key ] = graph <EOL> return graph <EOL> def parse_arguments ( self , args , graph = None ) : <EOL> defs_s = [ ] <EOL> if graph is None : <EOL> signature = self . signature <EOL> defaults = self . defaults <EOL> else : <EOL> signature = graph . signature <EOL> defaults = graph . defaults <EOL> if defaults : <EOL> for x in defaults : <EOL> defs_s . append ( self . bookkeeper . immutablevalue ( x ) ) <EOL> try : <EOL> inputcells = args . match_signature ( signature , defs_s ) <EOL> except ArgErr , e : <EOL> raise TypeError , "<STR_LIT>" % e . getmsg ( self . name ) <EOL> return inputcells <EOL> def specialize ( self , inputcells ) : <EOL> if self . specializer is None : <EOL> tag = getattr ( self . pyobj , '<STR_LIT>' , None ) <EOL> policy = self . bookkeeper . annotator . policy <EOL> self . specializer = policy . get_specializer ( tag ) <EOL> enforceargs = getattr ( self . pyobj , '<STR_LIT>' , None ) <EOL> if enforceargs : <EOL> if not callable ( enforceargs ) : <EOL> from pypy . annotation . policy import Sig <EOL> enforceargs = Sig ( * enforceargs ) <EOL> self . pyobj . _annenforceargs_ = enforceargs <EOL> enforceargs ( self , inputcells ) <EOL> return self . specializer ( self , inputcells ) <EOL> def pycall ( self , schedule , args , s_previous_result ) : <EOL> inputcells = self . parse_arguments ( args ) <EOL> result = self . specialize ( inputcells ) <EOL> if isinstance ( result , FunctionGraph ) : <EOL> graph = result <EOL> new_args = args . unmatch_signature ( self . signature , inputcells ) <EOL> inputcells = self . parse_arguments ( new_args , graph ) <EOL> result = schedule ( graph , inputcells ) <EOL> from pypy . annotation . model import unionof <EOL> result = unionof ( result , s_previous_result ) <EOL> return result <EOL> def bind_under ( self , classdef , name ) : <EOL> return self . bookkeeper . getmethoddesc ( self , <EOL> classdef , <EOL> None , <EOL> name ) <EOL> def consider_call_site ( bookkeeper , family , descs , args , s_result ) : <EOL> shape = rawshape ( args ) <EOL> row = FunctionDesc . row_to_consider ( descs , args ) <EOL> family . calltable_add_row ( shape , row ) <EOL> consider_call_site = staticmethod ( consider_call_site ) <EOL> def variant_for_call_site ( bookkeeper , family , descs , args ) : <EOL> shape = rawshape ( args ) <EOL> bookkeeper . enter ( None ) <EOL> try : <EOL> row = FunctionDesc . row_to_consider ( descs , args ) <EOL> finally : <EOL> bookkeeper . leave ( ) <EOL> index = family . calltable_lookup_row ( shape , row ) <EOL> return shape , index <EOL> variant_for_call_site = staticmethod ( variant_for_call_site ) <EOL> def rowkey ( self ) : <EOL> return self <EOL> def row_to_consider ( descs , args ) : <EOL> from pypy . annotation . model import s_ImpossibleValue <EOL> row = { } <EOL> for desc in descs : <EOL> def enlist ( graph , ignore ) : <EOL> row [ desc . rowkey ( ) ] = graph <EOL> return s_ImpossibleValue <EOL> desc . pycall ( enlist , args , s_ImpossibleValue ) <EOL> return row <EOL> row_to_consider = staticmethod ( row_to_consider ) <EOL> def get_s_signatures ( self , shape ) : <EOL> family = self . getcallfamily ( ) <EOL> table = family . calltables . get ( shape ) <EOL> if table is None : <EOL> return [ ] <EOL> else : <EOL> graph_seen = { } <EOL> s_sigs = [ ] <EOL> binding = self . bookkeeper . annotator . binding <EOL> def enlist ( graph ) : <EOL> if graph in graph_seen : <EOL> return <EOL> graph_seen [ graph ] = True <EOL> s_sig = ( [ binding ( v ) for v in graph . getargs ( ) ] , <EOL> binding ( graph . getreturnvar ( ) ) ) <EOL> if s_sig in s_sigs : <EOL> return <EOL> s_sigs . append ( s_sig ) <EOL> for row in table : <EOL> for graph in row . itervalues ( ) : <EOL> enlist ( graph ) <EOL> return s_sigs <EOL> NODEFAULT = object ( ) <EOL> class ClassDesc ( Desc ) : <EOL> knowntype = type <EOL> instance_level = False <EOL> all_enforced_attrs = None <EOL> settled = False <EOL> def __init__ ( self , bookkeeper , pyobj = None , <EOL> name = None , basedesc = None , classdict = None , <EOL> specialize = None ) : <EOL> super ( ClassDesc , self ) . __init__ ( bookkeeper , pyobj ) <EOL> if name is None : <EOL> name = pyobj . __module__ + '<STR_LIT:.>' + pyobj . __name__ <EOL> self . name = name <EOL> self . basedesc = basedesc <EOL> if classdict is None : <EOL> classdict = { } <EOL> self . classdict = classdict <EOL> if specialize is None : <EOL> specialize = pyobj . __dict__ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . specialize = specialize <EOL> self . _classdefs = { } <EOL> if pyobj is not None : <EOL> assert pyobj . __module__ != '<STR_LIT>' <EOL> cls = pyobj <EOL> base = object <EOL> baselist = list ( cls . __bases__ ) <EOL> baselist . reverse ( ) <EOL> if cls is Exception : <EOL> baselist = [ ] <EOL> elif baselist == [ py . builtin . BaseException ] : <EOL> baselist = [ Exception ] <EOL> for b1 in baselist : <EOL> if b1 is object : <EOL> continue <EOL> if b1 . __dict__ . get ( '<STR_LIT>' , False ) : <EOL> assert b1 . __bases__ == ( ) or b1 . __bases__ == ( object , ) , ( <EOL> "<STR_LIT>" % ( b1 , ) ) <EOL> self . add_sources_for_class ( b1 , mixin = True ) <EOL> else : <EOL> assert base is object , ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( cls , ) ) <EOL> base = b1 <EOL> self . add_sources_for_class ( cls ) <EOL> if base is not object : <EOL> self . basedesc = bookkeeper . getdesc ( base ) <EOL> if '<STR_LIT>' in cls . __dict__ : <EOL> self . settled = bool ( cls . __dict__ [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in cls . __dict__ or '<STR_LIT>' in cls . __dict__ : <EOL> attrs = { } <EOL> for decl in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> decl = cls . __dict__ . get ( decl , [ ] ) <EOL> if isinstance ( decl , str ) : <EOL> decl = ( decl , ) <EOL> decl = dict . fromkeys ( decl ) <EOL> attrs . update ( decl ) <EOL> if self . basedesc is not None : <EOL> if self . basedesc . all_enforced_attrs is None : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( pyobj , ) ) <EOL> attrs . update ( self . basedesc . all_enforced_attrs ) <EOL> self . all_enforced_attrs = attrs <EOL> def add_source_attribute ( self , name , value , mixin = False ) : <EOL> if isinstance ( value , types . FunctionType ) : <EOL> if not hasattr ( value , '<STR_LIT>' ) : <EOL> value . class_ = self . pyobj <EOL> if self . specialize : <EOL> from pypy . annotation . specialize import specialize_argtype <EOL> def argtype0 ( funcdesc , args_s ) : <EOL> return specialize_argtype ( funcdesc , args_s , <NUM_LIT:0> ) <EOL> funcdesc = FunctionDesc ( self . bookkeeper , value , <EOL> specializer = argtype0 ) <EOL> self . classdict [ name ] = funcdesc <EOL> return <EOL> if mixin : <EOL> funcdesc = FunctionDesc ( self . bookkeeper , value ) <EOL> self . classdict [ name ] = funcdesc <EOL> return <EOL> if type ( value ) is MemberDescriptorType : <EOL> return <EOL> if name == '<STR_LIT>' and self . is_builtin_exception_class ( ) : <EOL> from pypy . annotation . builtin import BUILTIN_ANALYZERS <EOL> value = getattr ( value , '<STR_LIT>' , value ) <EOL> if value not in BUILTIN_ANALYZERS : <EOL> return <EOL> self . classdict [ name ] = Constant ( value ) <EOL> def add_sources_for_class ( self , cls , mixin = False ) : <EOL> for name , value in cls . __dict__ . items ( ) : <EOL> self . add_source_attribute ( name , value , mixin ) <EOL> def getallclassdefs ( self ) : <EOL> return self . _classdefs . values ( ) <EOL> def getclassdef ( self , key ) : <EOL> try : <EOL> return self . _classdefs [ key ] <EOL> except KeyError : <EOL> from pypy . annotation . classdef import ClassDef , FORCE_ATTRIBUTES_INTO_CLASSES <EOL> classdef = ClassDef ( self . bookkeeper , self ) <EOL> self . bookkeeper . classdefs . append ( classdef ) <EOL> self . _classdefs [ key ] = classdef <EOL> if self . pyobj is not None : <EOL> cls = self . pyobj <EOL> if cls in FORCE_ATTRIBUTES_INTO_CLASSES : <EOL> for name , s_value in FORCE_ATTRIBUTES_INTO_CLASSES [ cls ] . items ( ) : <EOL> classdef . generalize_attr ( name , s_value ) <EOL> classdef . find_attribute ( name ) . modified ( classdef ) <EOL> classsources = { } <EOL> for attr in self . classdict : <EOL> classsources [ attr ] = self <EOL> classdef . setup ( classsources ) <EOL> if '<STR_LIT>' in self . classdict : <EOL> from pypy . annotation . model import s_None , SomeInstance <EOL> s_func = self . s_read_attribute ( '<STR_LIT>' ) <EOL> args_s = [ SomeInstance ( classdef ) ] <EOL> s = self . bookkeeper . emulate_pbc_call ( classdef , s_func , args_s ) <EOL> assert s_None . contains ( s ) <EOL> return classdef <EOL> def getuniqueclassdef ( self ) : <EOL> if self . specialize : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( self . name , ) ) <EOL> return self . getclassdef ( None ) <EOL> def pycall ( self , schedule , args , s_previous_result ) : <EOL> from pypy . annotation . model import SomeInstance , SomeImpossibleValue <EOL> if self . specialize : <EOL> if self . specialize == '<STR_LIT>' : <EOL> if isinstance ( s_previous_result , SomeInstance ) : <EOL> classdef = s_previous_result . classdef <EOL> else : <EOL> classdef = self . getclassdef ( object ( ) ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" % ( <EOL> self . specialize , ) ) <EOL> else : <EOL> classdef = self . getuniqueclassdef ( ) <EOL> s_instance = SomeInstance ( classdef ) <EOL> s_init = self . s_read_attribute ( '<STR_LIT>' ) <EOL> if isinstance ( s_init , SomeImpossibleValue ) : <EOL> if not self . is_exception_class ( ) : <EOL> try : <EOL> args . fixedunpack ( <NUM_LIT:0> ) <EOL> except ValueError : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( self . name , ) ) <EOL> else : <EOL> args = args . prepend ( s_instance ) <EOL> s_init . call ( args ) <EOL> return s_instance <EOL> def is_exception_class ( self ) : <EOL> return self . pyobj is not None and issubclass ( self . pyobj , <EOL> py . builtin . BaseException ) <EOL> def is_builtin_exception_class ( self ) : <EOL> if self . is_exception_class ( ) : <EOL> if self . pyobj . __module__ == '<STR_LIT>' : <EOL> return True <EOL> if self . pyobj is py . magic . AssertionError : <EOL> return True <EOL> return False <EOL> def lookup ( self , name ) : <EOL> cdesc = self <EOL> while name not in cdesc . classdict : <EOL> cdesc = cdesc . basedesc <EOL> if cdesc is None : <EOL> return None <EOL> else : <EOL> return cdesc <EOL> def read_attribute ( self , name , default = NODEFAULT ) : <EOL> cdesc = self . lookup ( name ) <EOL> if cdesc is None : <EOL> if default is NODEFAULT : <EOL> raise AttributeError <EOL> else : <EOL> return default <EOL> else : <EOL> return cdesc . classdict [ name ] <EOL> def s_read_attribute ( self , name ) : <EOL> cdesc = self . lookup ( name ) <EOL> if cdesc is None : <EOL> from pypy . annotation . model import s_ImpossibleValue <EOL> return s_ImpossibleValue <EOL> else : <EOL> return cdesc . s_get_value ( None , name ) <EOL> def s_get_value ( self , classdef , name ) : <EOL> obj = self . classdict [ name ] <EOL> if isinstance ( obj , Constant ) : <EOL> value = obj . value <EOL> if isinstance ( value , staticmethod ) : <EOL> value = value . __get__ ( <NUM_LIT> ) <EOL> classdef = None <EOL> s_value = self . bookkeeper . immutablevalue ( value ) <EOL> if classdef is not None : <EOL> s_value = s_value . bind_callables_under ( classdef , name ) <EOL> elif isinstance ( obj , Desc ) : <EOL> from pypy . annotation . model import SomePBC <EOL> if classdef is not None : <EOL> obj = obj . bind_under ( classdef , name ) <EOL> s_value = SomePBC ( [ obj ] ) <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" % ( obj , ) ) <EOL> return s_value <EOL> def create_new_attribute ( self , name , value ) : <EOL> assert name not in self . classdict , "<STR_LIT>" % ( name , ) <EOL> self . classdict [ name ] = Constant ( value ) <EOL> def find_source_for ( self , name ) : <EOL> if name in self . classdict : <EOL> return self <EOL> if self . pyobj is not None : <EOL> cls = self . pyobj <EOL> if name in cls . __dict__ : <EOL> self . add_source_attribute ( name , cls . __dict__ [ name ] ) <EOL> if name in self . classdict : <EOL> return self <EOL> return None <EOL> def consider_call_site ( bookkeeper , family , descs , args , s_result ) : <EOL> from pypy . annotation . model import SomeInstance , SomePBC , s_None <EOL> if len ( descs ) == <NUM_LIT:1> : <EOL> if not isinstance ( s_result , SomeInstance ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> classdefs = [ s_result . classdef ] <EOL> else : <EOL> classdefs = [ desc . getuniqueclassdef ( ) for desc in descs ] <EOL> initdescs = [ ] <EOL> for desc , classdef in zip ( descs , classdefs ) : <EOL> s_init = desc . s_read_attribute ( '<STR_LIT>' ) <EOL> if isinstance ( s_init , SomePBC ) : <EOL> assert len ( s_init . descriptions ) == <NUM_LIT:1> , ( <EOL> "<STR_LIT>" ) <EOL> initfuncdesc = s_init . descriptions . keys ( ) [ <NUM_LIT:0> ] <EOL> if isinstance ( initfuncdesc , FunctionDesc ) : <EOL> initmethdesc = bookkeeper . getmethoddesc ( initfuncdesc , <EOL> classdef , <EOL> classdef , <EOL> '<STR_LIT>' ) <EOL> initdescs . append ( initmethdesc ) <EOL> if initdescs : <EOL> initdescs [ <NUM_LIT:0> ] . mergecallfamilies ( * initdescs [ <NUM_LIT:1> : ] ) <EOL> initfamily = initdescs [ <NUM_LIT:0> ] . getcallfamily ( ) <EOL> MethodDesc . consider_call_site ( bookkeeper , initfamily , initdescs , <EOL> args , s_None ) <EOL> consider_call_site = staticmethod ( consider_call_site ) <EOL> def rowkey ( self ) : <EOL> return self <EOL> def getattrfamily ( self , attrname ) : <EOL> "<STR_LIT>" <EOL> access_sets = self . bookkeeper . get_classpbc_attr_families ( attrname ) <EOL> _ , _ , attrfamily = access_sets . find ( self ) <EOL> return attrfamily <EOL> def queryattrfamily ( self , attrname ) : <EOL> """<STR_LIT>""" <EOL> access_sets = self . bookkeeper . get_classpbc_attr_families ( attrname ) <EOL> try : <EOL> return access_sets [ self ] <EOL> except KeyError : <EOL> return None <EOL> def mergeattrfamilies ( self , others , attrname ) : <EOL> """<STR_LIT>""" <EOL> access_sets = self . bookkeeper . get_classpbc_attr_families ( attrname ) <EOL> changed , rep , attrfamily = access_sets . find ( self ) <EOL> for desc in others : <EOL> changed1 , rep , attrfamily = access_sets . union ( rep , desc ) <EOL> changed = changed or changed1 <EOL> return changed <EOL> class MethodDesc ( Desc ) : <EOL> knowntype = types . MethodType <EOL> def __init__ ( self , bookkeeper , funcdesc , originclassdef , <EOL> selfclassdef , name , flags = { } ) : <EOL> super ( MethodDesc , self ) . __init__ ( bookkeeper ) <EOL> self . funcdesc = funcdesc <EOL> self . originclassdef = originclassdef <EOL> self . selfclassdef = selfclassdef <EOL> self . name = name <EOL> self . flags = flags <EOL> def __repr__ ( self ) : <EOL> if self . selfclassdef is None : <EOL> return '<STR_LIT>' % ( self . name , <EOL> self . originclassdef ) <EOL> else : <EOL> return '<STR_LIT>' % ( self . name , <EOL> self . originclassdef , <EOL> self . selfclassdef , <EOL> self . flags ) <EOL> def getuniquegraph ( self ) : <EOL> return self . funcdesc . getuniquegraph ( ) <EOL> def pycall ( self , schedule , args , s_previous_result ) : <EOL> from pypy . annotation . model import SomeInstance <EOL> if self . selfclassdef is None : <EOL> raise Exception ( "<STR_LIT>" % ( self , ) ) <EOL> s_instance = SomeInstance ( self . selfclassdef , flags = self . flags ) <EOL> args = args . prepend ( s_instance ) <EOL> return self . funcdesc . pycall ( schedule , args , s_previous_result ) <EOL> def bind_under ( self , classdef , name ) : <EOL> self . bookkeeper . warning ( "<STR_LIT>" % ( self , ) ) <EOL> return self . funcdesc . bind_under ( classdef , name ) <EOL> def bind_self ( self , newselfclassdef , flags = { } ) : <EOL> return self . bookkeeper . getmethoddesc ( self . funcdesc , <EOL> self . originclassdef , <EOL> newselfclassdef , <EOL> self . name , <EOL> flags ) <EOL> def consider_call_site ( bookkeeper , family , descs , args , s_result ) : <EOL> shape = rawshape ( args , nextra = <NUM_LIT:1> ) <EOL> funcdescs = [ methoddesc . funcdesc for methoddesc in descs ] <EOL> row = FunctionDesc . row_to_consider ( descs , args ) <EOL> family . calltable_add_row ( shape , row ) <EOL> consider_call_site = staticmethod ( consider_call_site ) <EOL> def rowkey ( self ) : <EOL> return self . funcdesc <EOL> def simplify_desc_set ( descs ) : <EOL> lst = list ( descs ) <EOL> commonflags = lst [ <NUM_LIT:0> ] . flags . copy ( ) <EOL> for key , value in commonflags . items ( ) : <EOL> for desc in lst [ <NUM_LIT:1> : ] : <EOL> if key not in desc . flags or desc . flags [ key ] != value : <EOL> del commonflags [ key ] <EOL> break <EOL> for desc in lst : <EOL> if desc . flags != commonflags : <EOL> newdesc = desc . bookkeeper . getmethoddesc ( desc . funcdesc , <EOL> desc . originclassdef , <EOL> desc . selfclassdef , <EOL> desc . name , <EOL> commonflags ) <EOL> del descs [ desc ] <EOL> descs [ newdesc ] = None <EOL> groups = { } <EOL> for desc in descs : <EOL> if desc . selfclassdef is not None : <EOL> key = desc . funcdesc , desc . originclassdef , desc . name <EOL> groups . setdefault ( key , [ ] ) . append ( desc ) <EOL> for group in groups . values ( ) : <EOL> if len ( group ) > <NUM_LIT:1> : <EOL> for desc1 in group : <EOL> cdef1 = desc1 . selfclassdef <EOL> for desc2 in group : <EOL> cdef2 = desc2 . selfclassdef <EOL> if cdef1 is not cdef2 and cdef1 . issubclass ( cdef2 ) : <EOL> del descs [ desc1 ] <EOL> break <EOL> simplify_desc_set = staticmethod ( simplify_desc_set ) <EOL> def new_or_old_class ( c ) : <EOL> if hasattr ( c , '<STR_LIT>' ) : <EOL> return c . __class__ <EOL> else : <EOL> return type ( c ) <EOL> class FrozenDesc ( Desc ) : <EOL> def __init__ ( self , bookkeeper , pyobj , read_attribute = None ) : <EOL> super ( FrozenDesc , self ) . __init__ ( bookkeeper , pyobj ) <EOL> if read_attribute is None : <EOL> read_attribute = lambda attr : getattr ( pyobj , attr ) <EOL> self . _read_attribute = read_attribute <EOL> self . attrcache = { } <EOL> self . knowntype = new_or_old_class ( pyobj ) <EOL> assert bool ( pyobj ) , "<STR_LIT>" % ( pyobj , ) <EOL> def read_attribute ( self , attr ) : <EOL> try : <EOL> return self . attrcache [ attr ] <EOL> except KeyError : <EOL> result = self . attrcache [ attr ] = self . _read_attribute ( attr ) <EOL> return result <EOL> def s_read_attribute ( self , attr ) : <EOL> try : <EOL> value = self . read_attribute ( attr ) <EOL> except AttributeError : <EOL> from pypy . annotation . model import s_ImpossibleValue <EOL> return s_ImpossibleValue <EOL> else : <EOL> return self . bookkeeper . immutablevalue ( value ) <EOL> def create_new_attribute ( self , name , value ) : <EOL> try : <EOL> self . read_attribute ( name ) <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> raise AssertionError ( "<STR_LIT>" % ( name , ) ) <EOL> self . attrcache [ name ] = value <EOL> def getattrfamily ( self , attrname = None ) : <EOL> "<STR_LIT>" <EOL> access_sets = self . bookkeeper . frozenpbc_attr_families <EOL> _ , _ , attrfamily = access_sets . find ( self ) <EOL> return attrfamily <EOL> def queryattrfamily ( self , attrname = None ) : <EOL> """<STR_LIT>""" <EOL> access_sets = self . bookkeeper . frozenpbc_attr_families <EOL> try : <EOL> return access_sets [ self ] <EOL> except KeyError : <EOL> return None <EOL> def mergeattrfamilies ( self , others , attrname = None ) : <EOL> """<STR_LIT>""" <EOL> access_sets = self . bookkeeper . frozenpbc_attr_families <EOL> changed , rep , attrfamily = access_sets . find ( self ) <EOL> for desc in others : <EOL> changed1 , rep , attrfamily = access_sets . union ( rep , desc ) <EOL> changed = changed or changed1 <EOL> return changed <EOL> class MethodOfFrozenDesc ( Desc ) : <EOL> knowntype = types . MethodType <EOL> def __init__ ( self , bookkeeper , funcdesc , frozendesc ) : <EOL> super ( MethodOfFrozenDesc , self ) . __init__ ( bookkeeper ) <EOL> self . funcdesc = funcdesc <EOL> self . frozendesc = frozendesc <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . funcdesc , <EOL> self . frozendesc ) <EOL> def pycall ( self , schedule , args , s_previous_result ) : <EOL> from pypy . annotation . model import SomePBC <EOL> s_self = SomePBC ( [ self . frozendesc ] ) <EOL> args = args . prepend ( s_self ) <EOL> return self . funcdesc . pycall ( schedule , args , s_previous_result ) <EOL> def consider_call_site ( bookkeeper , family , descs , args , s_result ) : <EOL> shape = rawshape ( args , nextra = <NUM_LIT:1> ) <EOL> funcdescs = [ mofdesc . funcdesc for mofdesc in descs ] <EOL> row = FunctionDesc . row_to_consider ( descs , args ) <EOL> family . calltable_add_row ( shape , row ) <EOL> consider_call_site = staticmethod ( consider_call_site ) <EOL> def rowkey ( self ) : <EOL> return self . funcdesc <EOL> class Sample ( object ) : <EOL> __slots__ = '<STR_LIT:x>' <EOL> MemberDescriptorType = type ( Sample . x ) <EOL> del Sample </s>
