<s> from pseudo . middlewares . middleware import Middleware <EOL> class DeclarationMiddleware ( Middleware ) : <EOL> '''<STR_LIT>''' <EOL> @ classmethod <EOL> def process ( cls , tree ) : <EOL> return cls ( tree ) . transform ( tree ) <EOL> def __init__ ( self , tree ) : <EOL> self . envs = [ set ( ) ] <EOL> def transform_module ( self , node , in_block = False , assignment = None ) : <EOL> self . current_function_ = node <EOL> node . local_declarations = [ ] <EOL> node . definitions = self . transform ( node . definitions ) <EOL> node . main = self . transform ( node . main ) <EOL> return node <EOL> def transform_f ( self , node , in_block = False , assignment = None ) : <EOL> self . envs . append ( set ( node . params ) ) <EOL> self . current_function_ , old_function = node , self . current_function_ <EOL> node . local_declarations = [ ] <EOL> node . block = self . transform ( node . block ) <EOL> self . current_function_ = old_function <EOL> self . envs . pop ( ) <EOL> return node <EOL> transform_function = transform_methods = transfrom_anonymous_function = transform_f <EOL> def transform_assignment ( self , node , in_block = False , assignment = None ) : <EOL> if node . target . type == '<STR_LIT>' and node . target . name not in self . envs [ - <NUM_LIT:1> ] : <EOL> node . first_mention = True <EOL> self . current_function_ . local_declarations . append ( node . target . name ) <EOL> else : <EOL> node . first_mention = False <EOL> node . value = self . transform ( node . value ) <EOL> return node <EOL> def transform__go_multi_assignment ( self , node , in_block = False , assignment = False ) : <EOL> node . first_mention = False <EOL> for t in node . targets : <EOL> if t . type == '<STR_LIT>' and t . name not in self . envs [ - <NUM_LIT:1> ] : <EOL> node . first_mention = True <EOL> self . current_function_ . local_declarations . append ( t . name ) <EOL> node . values = self . transform ( node . values ) <EOL> return node </s>
