<s> """<STR_LIT>""" <EOL> from nuitka import Options <EOL> from . NodeBases import NodeBase , StatementChildrenHavingBase <EOL> from . NodeMakingHelpers import ( <EOL> makeStatementExpressionOnlyReplacementNode , <EOL> makeStatementsSequenceReplacementNode <EOL> ) <EOL> from . VariableRefNodes import ExpressionTempVariableRef , ExpressionVariableRef <EOL> class StatementAssignmentVariable ( StatementChildrenHavingBase ) : <EOL> """<STR_LIT>""" <EOL> kind = "<STR_LIT>" <EOL> named_children = ( <EOL> "<STR_LIT:source>" , <EOL> "<STR_LIT>" <EOL> ) <EOL> inplace_suspect = None <EOL> def __init__ ( self , variable_ref , source , source_ref ) : <EOL> assert variable_ref is not None , source_ref <EOL> assert source is not None , source_ref <EOL> assert variable_ref . isTargetVariableRef ( ) <EOL> StatementChildrenHavingBase . __init__ ( <EOL> self , <EOL> values = { <EOL> "<STR_LIT:source>" : source , <EOL> "<STR_LIT>" : variable_ref <EOL> } , <EOL> source_ref = source_ref <EOL> ) <EOL> self . variable_trace = None <EOL> def getDetail ( self ) : <EOL> variable_ref = self . getTargetVariableRef ( ) <EOL> variable = variable_ref . getVariable ( ) <EOL> if variable is not None : <EOL> return "<STR_LIT>" % variable <EOL> else : <EOL> return "<STR_LIT>" % self . getTargetVariableRef ( ) <EOL> getTargetVariableRef = StatementChildrenHavingBase . childGetter ( <EOL> "<STR_LIT>" <EOL> ) <EOL> getAssignSource = StatementChildrenHavingBase . childGetter ( <EOL> "<STR_LIT:source>" <EOL> ) <EOL> setAssignSource = StatementChildrenHavingBase . childSetter ( <EOL> "<STR_LIT:source>" <EOL> ) <EOL> def markAsInplaceSuspect ( self ) : <EOL> self . inplace_suspect = True <EOL> def isInplaceSuspect ( self ) : <EOL> return self . inplace_suspect <EOL> def mayRaiseException ( self , exception_type ) : <EOL> return self . getAssignSource ( ) . mayRaiseException ( exception_type ) <EOL> def computeStatement ( self , constraint_collection ) : <EOL> constraint_collection . onExpression ( self . getAssignSource ( ) ) <EOL> source = self . getAssignSource ( ) <EOL> if source . willRaiseException ( BaseException ) : <EOL> result = makeStatementExpressionOnlyReplacementNode ( <EOL> expression = source , <EOL> node = self <EOL> ) <EOL> return result , "<STR_LIT>" , """<STR_LIT>""" <EOL> variable_ref = self . getTargetVariableRef ( ) <EOL> variable = variable_ref . getVariable ( ) <EOL> assert variable is not None <EOL> if not variable . isModuleVariable ( ) and source . isExpressionVariableRef ( ) and source . getVariable ( ) == variable : <EOL> if source . mayHaveSideEffects ( ) : <EOL> result = makeStatementExpressionOnlyReplacementNode ( <EOL> expression = source , <EOL> node = self <EOL> ) <EOL> return result , "<STR_LIT>" , """<STR_LIT>""" % variable . getName ( ) <EOL> else : <EOL> return None , "<STR_LIT>" , """<STR_LIT>""" % variable . getName ( ) <EOL> if source . isExpressionSideEffects ( ) : <EOL> statements = [ <EOL> makeStatementExpressionOnlyReplacementNode ( <EOL> side_effect , <EOL> self <EOL> ) <EOL> for side_effect in <EOL> source . getSideEffects ( ) <EOL> ] <EOL> statements . append ( self ) <EOL> parent = self . parent <EOL> result = makeStatementsSequenceReplacementNode ( <EOL> statements = statements , <EOL> node = self , <EOL> ) <EOL> result . parent = parent <EOL> self . setAssignSource ( source . getExpression ( ) ) <EOL> source = self . getAssignSource ( ) <EOL> constraint_collection . signalChange ( <EOL> tags = "<STR_LIT>" , <EOL> message = """<STR_LIT>""" , <EOL> source_ref = self . getSourceReference ( ) <EOL> ) <EOL> self . variable_trace = constraint_collection . onVariableSet ( <EOL> assign_node = self <EOL> ) <EOL> global_trace = variable . getGlobalVariableTrace ( ) <EOL> if global_trace is not None : <EOL> provider = self . getParentVariableProvider ( ) <EOL> if not global_trace . hasAccessesOutsideOf ( provider ) : <EOL> last_trace = global_trace . getMatchingAssignTrace ( self ) <EOL> if last_trace is not None : <EOL> if variable . isLocalVariable ( ) or variable . isTempVariable ( ) : <EOL> if source . isCompileTimeConstant ( ) : <EOL> if not source . isMutable ( ) : <EOL> provider = self . getParentVariableProvider ( ) <EOL> if variable . isTempVariable ( ) or ( not provider . isExpressionClassBody ( ) and not provider . isUnoptimized ( ) <EOL> ) : <EOL> if last_trace . hasDefiniteUsages ( ) : <EOL> self . variable_trace . setReplacementNode ( <EOL> lambda usage : source . makeClone ( ) <EOL> ) <EOL> propagated = True <EOL> else : <EOL> propagated = False <EOL> if not last_trace . hasPotentialUsages ( ) and not last_trace . hasNameUsages ( ) : <EOL> if not last_trace . getPrevious ( ) . isUninitTrace ( ) : <EOL> result = StatementDelVariable ( <EOL> variable_ref = self . getTargetVariableRef ( ) , <EOL> tolerant = True , <EOL> source_ref = self . getSourceReference ( ) <EOL> ) <EOL> else : <EOL> result = None <EOL> return ( <EOL> result , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" % ( <EOL> "<STR_LIT>" if propagated else "<STR_LIT>" , <EOL> self . getTargetVariableRef ( ) . getVariableName ( ) <EOL> ) <EOL> ) <EOL> else : <EOL> pass <EOL> elif Options . isExperimental ( ) and source . isExpressionFunctionCreation ( ) and source . getFunctionRef ( ) . getFunctionBody ( ) . isExpressionFunctionBody ( ) and not source . getDefaults ( ) and not source . getKwDefaults ( ) and not source . getAnnotations ( ) : <EOL> provider = self . getParentVariableProvider ( ) <EOL> if variable . isTempVariable ( ) or ( not provider . isUnoptimized ( ) and not provider . isExpressionClassBody ( ) ) : <EOL> if last_trace . getDefiniteUsages ( ) <= <NUM_LIT:1> and not last_trace . hasPotentialUsages ( ) and not last_trace . hasNameUsages ( ) : <EOL> if last_trace . getDefiniteUsages ( ) == <NUM_LIT:1> : <EOL> self . variable_trace . setReplacementNode ( <EOL> lambda usage : source . makeClone ( ) <EOL> ) <EOL> propagated = True <EOL> else : <EOL> propagated = False <EOL> if not last_trace . getPrevious ( ) . isUninitTrace ( ) : <EOL> result = StatementDelVariable ( <EOL> variable_ref = self . getTargetVariableRef ( ) , <EOL> tolerant = True , <EOL> source_ref = self . getSourceReference ( ) <EOL> ) <EOL> else : <EOL> result = None <EOL> return ( <EOL> result , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" % ( <EOL> "<STR_LIT>" if propagated else "<STR_LIT>" , <EOL> self . getTargetVariableRef ( ) . getVariableName ( ) <EOL> ) <EOL> ) <EOL> else : <EOL> pass <EOL> return self , None , None <EOL> def needsReleasePreviousValue ( self ) : <EOL> previous = self . variable_trace . getPrevious ( ) <EOL> if previous . mustNotHaveValue ( ) : <EOL> return False <EOL> elif previous . mustHaveValue ( ) : <EOL> return True <EOL> else : <EOL> return None <EOL> class StatementDelVariable ( StatementChildrenHavingBase ) : <EOL> """<STR_LIT>""" <EOL> kind = "<STR_LIT>" <EOL> named_children = ( <EOL> "<STR_LIT>" , <EOL> ) <EOL> def __init__ ( self , variable_ref , tolerant , source_ref ) : <EOL> assert variable_ref is not None <EOL> assert variable_ref . isTargetVariableRef ( ) <EOL> assert tolerant is True or tolerant is False <EOL> StatementChildrenHavingBase . __init__ ( <EOL> self , <EOL> values = { <EOL> "<STR_LIT>" : variable_ref <EOL> } , <EOL> source_ref = source_ref <EOL> ) <EOL> self . variable_trace = None <EOL> self . previous_trace = None <EOL> self . tolerant = tolerant <EOL> def getDetail ( self ) : <EOL> variable_ref = self . getTargetVariableRef ( ) <EOL> variable = variable_ref . getVariable ( ) <EOL> if variable is not None : <EOL> return "<STR_LIT>" % variable <EOL> else : <EOL> return "<STR_LIT>" % self . getTargetVariableRef ( ) <EOL> def getDetails ( self ) : <EOL> return { <EOL> "<STR_LIT>" : self . tolerant <EOL> } <EOL> def isTolerant ( self ) : <EOL> return self . tolerant <EOL> getTargetVariableRef = StatementChildrenHavingBase . childGetter ( <EOL> "<STR_LIT>" <EOL> ) <EOL> def computeStatement ( self , constraint_collection ) : <EOL> variable_ref = self . getTargetVariableRef ( ) <EOL> variable = variable_ref . getVariable ( ) <EOL> self . previous_trace = constraint_collection . getVariableCurrentTrace ( variable ) <EOL> if self . tolerant and self . previous_trace . isUninitTrace ( ) : <EOL> return ( <EOL> None , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" % ( <EOL> variable . getName ( ) , <EOL> ) <EOL> ) <EOL> self . previous_trace . addPotentialUsage ( ) <EOL> if not self . tolerant and not self . previous_trace . mustHaveValue ( ) : <EOL> constraint_collection . onExceptionRaiseExit ( BaseException ) <EOL> constraint_collection . onVariableDel ( <EOL> variable_ref = variable_ref <EOL> ) <EOL> constraint_collection . onVariableContentEscapes ( variable ) <EOL> constraint_collection . onControlFlowEscape ( self ) <EOL> self . variable_trace = constraint_collection . getVariableCurrentTrace ( variable ) <EOL> return self , None , None <EOL> def mayHaveSideEffects ( self ) : <EOL> return True <EOL> def mayRaiseException ( self , exception_type ) : <EOL> if self . tolerant : <EOL> return False <EOL> else : <EOL> if self . variable_trace is not None : <EOL> variable = self . getTargetVariableRef ( ) . getVariable ( ) <EOL> if variable . isTempVariable ( ) : <EOL> return False <EOL> if self . previous_trace is not None and self . previous_trace . mustHaveValue ( ) : <EOL> return False <EOL> return True <EOL> class StatementReleaseVariable ( NodeBase ) : <EOL> """<STR_LIT>""" <EOL> kind = "<STR_LIT>" <EOL> def __init__ ( self , variable , source_ref ) : <EOL> assert variable is not None , source_ref <EOL> NodeBase . __init__ ( <EOL> self , <EOL> source_ref = source_ref <EOL> ) <EOL> self . variable = variable <EOL> self . variable_trace = None <EOL> def getDetail ( self ) : <EOL> return "<STR_LIT>" % self . variable <EOL> def getDetails ( self ) : <EOL> return { <EOL> "<STR_LIT>" : self . variable <EOL> } <EOL> def getDetailsForDisplay ( self ) : <EOL> if self . variable . getOwner ( ) is not self . getParentVariableProvider ( ) : <EOL> return { <EOL> "<STR_LIT>" : self . variable . getName ( ) , <EOL> "<STR_LIT>" : self . variable . getOwner ( ) . getCodeName ( ) <EOL> } <EOL> else : <EOL> return { <EOL> "<STR_LIT>" : self . variable . getName ( ) , <EOL> } <EOL> def getVariable ( self ) : <EOL> return self . variable <EOL> def setVariable ( self , variable ) : <EOL> self . variable = variable <EOL> def computeStatement ( self , constraint_collection ) : <EOL> self . variable_trace = constraint_collection . onVariableRelease ( <EOL> variable = self . variable <EOL> ) <EOL> if self . variable_trace . isUninitTrace ( ) : <EOL> return ( <EOL> None , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" % ( <EOL> self . variable . getName ( ) <EOL> ) <EOL> ) <EOL> constraint_collection . onVariableContentEscapes ( self . variable ) <EOL> constraint_collection . onControlFlowEscape ( self ) <EOL> return self , None , None <EOL> def mayHaveSideEffects ( self ) : <EOL> return True <EOL> def mayRaiseException ( self , exception_type ) : <EOL> return False <EOL> class ExpressionTargetVariableRef ( ExpressionVariableRef ) : <EOL> kind = "<STR_LIT>" <EOL> def __init__ ( self , variable_name , source_ref , variable = None ) : <EOL> ExpressionVariableRef . __init__ ( self , variable_name , source_ref ) <EOL> self . variable_version = None <EOL> if variable is not None : <EOL> self . setVariable ( variable ) <EOL> assert variable . getName ( ) == variable_name <EOL> def getDetailsForDisplay ( self ) : <EOL> if self . variable is None : <EOL> return { <EOL> "<STR_LIT:name>" : self . variable_name <EOL> } <EOL> else : <EOL> return { <EOL> "<STR_LIT:name>" : self . variable_name , <EOL> "<STR_LIT>" : self . variable , <EOL> "<STR_LIT:version>" : self . variable_version <EOL> } <EOL> def computeExpression ( self , constraint_collection ) : <EOL> assert False , self . parent <EOL> @ staticmethod <EOL> def isTargetVariableRef ( ) : <EOL> return True <EOL> def getVariableVersion ( self ) : <EOL> assert self . variable_version is not None , self <EOL> return self . variable_version <EOL> def setVariable ( self , variable ) : <EOL> ExpressionVariableRef . setVariable ( self , variable ) <EOL> self . variable_version = variable . allocateTargetNumber ( ) <EOL> assert self . variable_version is not None <EOL> class ExpressionTargetTempVariableRef ( ExpressionTempVariableRef ) : <EOL> kind = "<STR_LIT>" <EOL> def __init__ ( self , variable , source_ref ) : <EOL> ExpressionTempVariableRef . __init__ ( self , variable , source_ref ) <EOL> self . variable_version = variable . allocateTargetNumber ( ) <EOL> def computeExpression ( self , constraint_collection ) : <EOL> assert False , self . parent <EOL> @ staticmethod <EOL> def isTargetVariableRef ( ) : <EOL> return True <EOL> def getVariableVersion ( self ) : <EOL> return self . variable_version <EOL> def setVariable ( self , variable ) : <EOL> ExpressionTempVariableRef . setVariable ( self , variable ) <EOL> self . variable_version = self . variable . allocateTargetNumber ( ) </s>
