#NEWLINE# def _split_stages( node , duplicates = None , aliases = None , stages = None , parents = None ) : #NEWLINE# #INDENT# '\n    Split out all reductions and post reduction scalar operations into seperate\n    stacks (stages)\n    This leaves remaining in the tree anything not in these categories.\n    ' #NEWLINE# if ( duplicates is None ) : #NEWLINE# #INDENT# duplicates = dict ( ) #NEWLINE# aliases = set ( ) #NEWLINE# stages = list ( ) #NEWLINE# parents = list ( ) #NEWLINE# #UNINDENT# if ( type ( node ) is list ) : #NEWLINE# #INDENT# if ( node [ 0 ] [ 0 ] != 'assign' ) : #NEWLINE# #INDENT# parents . append ( node ) #NEWLINE# #UNINDENT# if ( len ( node ) > 3 ) : #NEWLINE# #INDENT# _split_stages ( node [ 3 ] , duplicates , aliases , stages , parents ) #NEWLINE# #UNINDENT# if ( len ( node ) > 4 ) : #NEWLINE# #INDENT# _split_stages ( node [ 4 ] , duplicates , aliases , stages , parents ) #NEWLINE# #UNINDENT# if ( len ( parents ) > 0 ) : #NEWLINE# #INDENT# parents . pop ( ) #NEWLINE# #UNINDENT# if ( node [ 0 ] [ 0 ] in _reduction_ops ) : #NEWLINE# #INDENT# red_stack = _process_node ( node , aliases , duplicates ) #NEWLINE# if red_stack : #NEWLINE# #INDENT# stages . append ( ( 'reduction' , red_stack ) ) #NEWLINE# #UNINDENT# for parent in parents : #NEWLINE# #INDENT# parent [ 2 ] -= 1 #NEWLINE# #UNINDENT# scalar_parent = None #NEWLINE# for parent in parents [ : : ( - 1 ) ] : #NEWLINE# #INDENT# if ( parent [ 1 ] and ( parent [ 2 ] == 0 ) ) : #NEWLINE# #INDENT# scalar_parent = parent #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# if ( scalar_parent is not None ) : #NEWLINE# #INDENT# scalar_stack = _process_node ( scalar_parent , aliases , duplicates ) #NEWLINE# if scalar_stack : #NEWLINE# #INDENT# stages . append ( ( 'scalar' , scalar_stack ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return stages