<s> """<STR_LIT>""" <EOL> import sys <EOL> from pypy . objspace . flow . model import Block <EOL> from pypy . objspace . flow . model import traverse <EOL> def ordered_blocks ( graph ) : <EOL> allblocks = [ ] <EOL> def visit ( block ) : <EOL> if isinstance ( block , Block ) : <EOL> if block . operations : <EOL> ofs = block . operations [ <NUM_LIT:0> ] . offset <EOL> else : <EOL> ofs = sys . maxint <EOL> if block . inputargs : <EOL> txt = str ( block . inputargs [ <NUM_LIT:0> ] ) <EOL> else : <EOL> txt = "<STR_LIT>" <EOL> allblocks . append ( ( ofs , txt , block ) ) <EOL> traverse ( visit , graph ) <EOL> allblocks . sort ( ) <EOL> return [ block for ofs , txt , block in allblocks ] <EOL> class UniqueList ( list ) : <EOL> def __init__ ( self , * args , ** kwds ) : <EOL> list . __init__ ( self , * args , ** kwds ) <EOL> self . dic = { } <EOL> def append1 ( self , arg ) : <EOL> try : <EOL> self . dic [ arg ] <EOL> except KeyError : <EOL> self . dic [ arg ] = <NUM_LIT:1> <EOL> list . append ( self , arg ) <EOL> except TypeError : <EOL> if arg not in self : <EOL> list . append ( self , arg ) <EOL> def builtin_base ( obj ) : <EOL> typ = type ( obj ) <EOL> return builtin_type_base ( typ ) <EOL> def builtin_type_base ( typ ) : <EOL> from copy_reg import _HEAPTYPE <EOL> while typ . __flags__ & _HEAPTYPE : <EOL> typ = typ . __base__ <EOL> return typ <EOL> def c_string ( s ) : <EOL> return '<STR_LIT>' % ( s . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) , ) <EOL> def uniquemodulename ( name , SEEN = { } ) : <EOL> i = <NUM_LIT:0> <EOL> while True : <EOL> i += <NUM_LIT:1> <EOL> result = '<STR_LIT>' % ( name , i ) <EOL> if result not in SEEN : <EOL> SEEN [ result ] = True <EOL> return result <EOL> C_IDENTIFIER = '<STR_LIT>' . join ( [ ( ( '<STR_LIT:0>' <= chr ( i ) <= '<STR_LIT>' or <EOL> '<STR_LIT:a>' <= chr ( i ) <= '<STR_LIT:z>' or <EOL> '<STR_LIT:A>' <= chr ( i ) <= '<STR_LIT>' ) and chr ( i ) or '<STR_LIT:_>' ) <EOL> for i in range ( <NUM_LIT> ) ] ) <EOL> class NameManager ( object ) : <EOL> def __init__ ( self , global_prefix = '<STR_LIT>' , number_sep = '<STR_LIT:_>' ) : <EOL> self . seennames = { } <EOL> self . scope = <NUM_LIT:0> <EOL> self . scopelist = [ ] <EOL> self . global_prefix = global_prefix <EOL> self . number_sep = number_sep <EOL> def make_reserved_names ( self , txt ) : <EOL> """<STR_LIT>""" <EOL> for name in txt . split ( ) : <EOL> if name in self . seennames : <EOL> raise NameError , "<STR_LIT>" <EOL> self . seennames [ name ] = <NUM_LIT:1> <EOL> def _ensure_unique ( self , basename ) : <EOL> n = self . seennames . get ( basename , <NUM_LIT:0> ) <EOL> self . seennames [ basename ] = n + <NUM_LIT:1> <EOL> if n : <EOL> return self . _ensure_unique ( '<STR_LIT>' % ( basename , n ) ) <EOL> return basename <EOL> def uniquename ( self , basename , with_number = None , bare = False , lenmax = <NUM_LIT:50> ) : <EOL> basename = basename [ : lenmax ] . translate ( C_IDENTIFIER ) <EOL> n = self . seennames . get ( basename , <NUM_LIT:0> ) <EOL> self . seennames [ basename ] = n + <NUM_LIT:1> <EOL> if with_number is None : <EOL> with_number = basename in ( '<STR_LIT:v>' , '<STR_LIT>' ) <EOL> fmt = '<STR_LIT>' % self . number_sep <EOL> if with_number and not basename [ - <NUM_LIT:1> ] . isdigit ( ) : <EOL> fmt = '<STR_LIT>' <EOL> if n != <NUM_LIT:0> or with_number : <EOL> basename = self . _ensure_unique ( fmt % ( basename , n ) ) <EOL> if bare : <EOL> return basename , self . global_prefix + basename <EOL> else : <EOL> return self . global_prefix + basename <EOL> def localScope ( self , parent = None ) : <EOL> ret = _LocalScope ( self , parent ) <EOL> while ret . scope >= len ( self . scopelist ) : <EOL> self . scopelist . append ( { } ) <EOL> return ret <EOL> class _LocalScope ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , glob , parent ) : <EOL> self . glob = glob <EOL> if not parent : <EOL> parent = glob <EOL> self . parent = parent <EOL> self . mapping = { } <EOL> self . usednames = { } <EOL> self . scope = parent . scope + <NUM_LIT:1> <EOL> def uniquename ( self , basename ) : <EOL> basename = basename . translate ( C_IDENTIFIER ) <EOL> glob = self . glob <EOL> p = self . usednames . get ( basename , <NUM_LIT:0> ) <EOL> self . usednames [ basename ] = p + <NUM_LIT:1> <EOL> namesbyscope = glob . scopelist [ self . scope ] <EOL> namelist = namesbyscope . setdefault ( basename , [ ] ) <EOL> if p == len ( namelist ) : <EOL> namelist . append ( glob . uniquename ( basename ) ) <EOL> return namelist [ p ] <EOL> def localname ( self , name , wrapped = False ) : <EOL> """<STR_LIT>""" <EOL> if name in self . mapping : <EOL> return self . mapping [ name ] <EOL> scorepos = name . rfind ( "<STR_LIT:_>" ) <EOL> if name . startswith ( "<STR_LIT:v>" ) and name [ <NUM_LIT:1> : ] . isdigit ( ) : <EOL> basename = ( '<STR_LIT:v>' , '<STR_LIT>' ) [ wrapped ] <EOL> elif scorepos >= <NUM_LIT:0> and name [ scorepos + <NUM_LIT:1> : ] . isdigit ( ) : <EOL> basename = name [ : scorepos ] <EOL> basename = ( "<STR_LIT>" , "<STR_LIT>" ) [ wrapped ] + basename <EOL> else : <EOL> basename = name <EOL> ret = self . uniquename ( basename ) <EOL> self . mapping [ name ] = ret <EOL> return ret </s>
