#NEWLINE# def discover_args_and_returns( bytecode , insts , outer_rds , outer_wrs ) : #NEWLINE# #INDENT# '\n    Basic analysis for args and returns\n    This completely ignores the ordering or the read-writes.\n\n    outer_rds and outer_wrs are modified\n\n    Note:\n    An invalid argument and return set will likely to cause a RuntimeWarning\n    in the dataflow analysis due to mismatch in stack offset.\n    ' #NEWLINE# ( rdnames , wrnames ) = find_varnames_uses ( bytecode , insts ) #NEWLINE# remove_from_outer_use ( rdnames , outer_rds ) #NEWLINE# remove_from_outer_use ( wrnames , outer_wrs ) #NEWLINE# rets = set ( ) #NEWLINE# for ( name , uselist ) in wrnames . items ( ) : #NEWLINE# #INDENT# if ( name in outer_rds ) : #NEWLINE# #INDENT# endofloop = insts [ ( - 1 ) ] . offset #NEWLINE# for nextrd in outer_rds [ name ] : #NEWLINE# #INDENT# if ( nextrd > endofloop ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# nextrd = None #NEWLINE# #UNINDENT# for nextwr in outer_wrs [ name ] : #NEWLINE# #INDENT# if ( nextwr > endofloop ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# nextwr = None #NEWLINE# #UNINDENT# if ( ( nextrd is not None ) and ( ( nextwr is None ) or ( nextwr > nextrd ) ) ) : #NEWLINE# #INDENT# rets . add ( name ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# args = set ( ) #NEWLINE# firstline = insts [ 0 ] . offset #NEWLINE# for name in rdnames . keys ( ) : #NEWLINE# #INDENT# outer_write = outer_wrs [ name ] #NEWLINE# if any ( ( ( i < firstline ) for i in outer_write ) ) : #NEWLINE# #INDENT# args . add ( name ) #NEWLINE# #UNINDENT# #UNINDENT# for name in rets : #NEWLINE# #INDENT# if any ( ( ( i < insts [ 0 ] . offset ) for i in outer_wrs [ name ] ) ) : #NEWLINE# #INDENT# args . add ( name ) #NEWLINE# #UNINDENT# #UNINDENT# for name in args : #NEWLINE# #INDENT# outer_rds [ name ] = sorted ( ( set ( outer_rds [ name ] ) | set ( [ firstline ] ) ) ) #NEWLINE# #UNINDENT# for name in rets : #NEWLINE# #INDENT# outer_wrs [ name ] = sorted ( ( set ( outer_wrs [ name ] ) | set ( [ firstline ] ) ) ) #NEWLINE# #UNINDENT# return ( args , rets )