<s> def flatten ( tup ) : <EOL> elts = [ ] <EOL> for elt in tup : <EOL> if isinstance ( elt , tuple ) : <EOL> elts = elts + flatten ( elt ) <EOL> else : <EOL> elts . append ( elt ) <EOL> return elts <EOL> class Set : <EOL> def __init__ ( self ) : <EOL> self . elts = { } <EOL> def __len__ ( self ) : <EOL> return len ( self . elts ) <EOL> def __contains__ ( self , elt ) : <EOL> return elt in self . elts <EOL> def add ( self , elt ) : <EOL> self . elts [ elt ] = elt <EOL> def elements ( self ) : <EOL> return self . elts . keys ( ) <EOL> def has_elt ( self , elt ) : <EOL> return elt in self . elts <EOL> def remove ( self , elt ) : <EOL> del self . elts [ elt ] <EOL> def copy ( self ) : <EOL> c = Set ( ) <EOL> c . elts . update ( self . elts ) <EOL> return c <EOL> class Stack : <EOL> def __init__ ( self ) : <EOL> self . stack = [ ] <EOL> self . pop = self . stack . pop <EOL> def __len__ ( self ) : <EOL> return len ( self . stack ) <EOL> def push ( self , elt ) : <EOL> self . stack . append ( elt ) <EOL> def top ( self ) : <EOL> return self . stack [ - <NUM_LIT:1> ] <EOL> def __getitem__ ( self , index ) : <EOL> return self . stack [ index ] <EOL> MANGLE_LEN = <NUM_LIT> <EOL> def mangle ( name , klass ) : <EOL> if not name . startswith ( '<STR_LIT>' ) : <EOL> return name <EOL> if len ( name ) + <NUM_LIT:2> >= MANGLE_LEN : <EOL> return name <EOL> if name . endswith ( '<STR_LIT>' ) : <EOL> return name <EOL> try : <EOL> i = <NUM_LIT:0> <EOL> while klass [ i ] == '<STR_LIT:_>' : <EOL> i = i + <NUM_LIT:1> <EOL> except IndexError : <EOL> return name <EOL> klass = klass [ i : ] <EOL> tlen = len ( klass ) + len ( name ) <EOL> if tlen > MANGLE_LEN : <EOL> klass = klass [ : MANGLE_LEN - tlen ] <EOL> return "<STR_LIT>" % ( klass , name ) <EOL> def set_filename ( filename , tree ) : <EOL> """<STR_LIT>""" <EOL> worklist = [ tree ] <EOL> while worklist : <EOL> node = worklist . pop ( <NUM_LIT:0> ) <EOL> node . filename = filename <EOL> worklist . extend ( node . getChildNodes ( ) ) </s>
