<s> class MakeProperties ( type ) : <EOL> def __init__ ( cls , name , bases , dct ) : <EOL> def _wrap_set ( names , name ) : <EOL> def fun ( self , value ) : <EOL> for field in names : <EOL> self . __dict__ [ field ] = ( name == field ) and value <EOL> return fun <EOL> def _wrap_get ( name ) : <EOL> def fun ( self ) : <EOL> return self . __dict__ [ name ] <EOL> return fun <EOL> super ( MakeProperties , cls ) . __init__ ( name , bases , dct ) <EOL> attrs = [ ] <EOL> prefixes = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for key in dct . keys ( ) : <EOL> for prefix in prefixes : <EOL> if key . startswith ( prefix ) : <EOL> attrs . append ( key [ <NUM_LIT:4> : ] ) <EOL> delattr ( cls , key ) <EOL> for attr in attrs : <EOL> setattr ( cls , attr [ <NUM_LIT:1> : ] , <EOL> property ( _wrap_get ( attr ) , _wrap_set ( attrs , attr ) ) ) <EOL> cls . _attrs = attrs <EOL> def __call__ ( cls , * args , ** kwds ) : <EOL> obj = super ( MakeProperties , cls ) . __call__ ( * args , ** kwds ) <EOL> for attr in cls . _attrs : <EOL> obj . __dict__ [ attr ] = False <EOL> return obj <EOL> class LoopType ( object ) : <EOL> __metaclass__ = MakeProperties <EOL> _set_is_pretest = _set_is_posttest = _set_is_endless = None <EOL> _get_is_pretest = _get_is_posttest = _get_is_endless = None <EOL> def copy ( self ) : <EOL> res = LoopType ( ) <EOL> for key , value in self . __dict__ . iteritems ( ) : <EOL> setattr ( res , key , value ) <EOL> return res <EOL> class NodeType ( object ) : <EOL> __metaclass__ = MakeProperties <EOL> _set_is_cond = _set_is_switch = _set_is_stmt = None <EOL> _get_is_cond = _get_is_switch = _get_is_stmt = None <EOL> _set_is_return = _set_is_throw = None <EOL> _get_is_return = _get_is_throw = None <EOL> def copy ( self ) : <EOL> res = NodeType ( ) <EOL> for key , value in self . __dict__ . iteritems ( ) : <EOL> setattr ( res , key , value ) <EOL> return res <EOL> class Node ( object ) : <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> self . num = <NUM_LIT:0> <EOL> self . follow = { '<STR_LIT>' : None , '<STR_LIT>' : None , '<STR_LIT>' : None } <EOL> self . looptype = LoopType ( ) <EOL> self . type = NodeType ( ) <EOL> self . in_catch = False <EOL> self . interval = None <EOL> self . startloop = False <EOL> self . latch = None <EOL> self . loop_nodes = [ ] <EOL> def copy_from ( self , node ) : <EOL> self . num = node . num <EOL> self . looptype = node . looptype . copy ( ) <EOL> self . interval = node . interval <EOL> self . startloop = node . startloop <EOL> self . type = node . type . copy ( ) <EOL> self . follow = node . follow . copy ( ) <EOL> self . latch = node . latch <EOL> self . loop_nodes = node . loop_nodes <EOL> self . in_catch = node . in_catch <EOL> def update_attribute_with ( self , n_map ) : <EOL> self . latch = n_map . get ( self . latch , self . latch ) <EOL> for follow_type , value in self . follow . iteritems ( ) : <EOL> self . follow [ follow_type ] = n_map . get ( value , value ) <EOL> self . loop_nodes = list ( set ( n_map . get ( n , n ) for n in self . loop_nodes ) ) <EOL> def get_head ( self ) : <EOL> return self <EOL> def get_end ( self ) : <EOL> return self <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT:%s>' % self <EOL> class Interval ( object ) : <EOL> def __init__ ( self , head ) : <EOL> self . name = '<STR_LIT>' % head . name <EOL> self . content = set ( [ head ] ) <EOL> self . end = None <EOL> self . head = head <EOL> self . in_catch = head . in_catch <EOL> head . interval = self <EOL> def __contains__ ( self , item ) : <EOL> if item in self . content : <EOL> return True <EOL> return any ( item in node for node in self . content <EOL> if isinstance ( node , Interval ) ) <EOL> def add_node ( self , node ) : <EOL> if node in self . content : <EOL> return False <EOL> self . content . add ( node ) <EOL> node . interval = self <EOL> return True <EOL> def compute_end ( self , graph ) : <EOL> for node in self . content : <EOL> for suc in graph . sucs ( node ) : <EOL> if suc not in self . content : <EOL> self . end = node <EOL> def get_end ( self ) : <EOL> return self . end . get_end ( ) <EOL> def get_head ( self ) : <EOL> return self . head . get_head ( ) <EOL> def __len__ ( self ) : <EOL> return len ( self . content ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . name , self . content ) </s>
