def onEnterNode(self, node): assert python_version < 300 if node.isStatementDelVariable(): variable = node.getTargetVariableRef().getVariable() if not variable.isModuleVariable() and \ isSharedLogically(variable): SyntaxErrors.raiseSyntaxError( reason="""\ can not delete variable '%s' referenced in nested scope""" % (variable.getName()), source_ref=(None if isFullCompat() else node.getSourceReference()), display_file=not isFullCompat(), display_line=not isFullCompat())
def onEnterNode(self, node): assert python_version < 300 if node.isStatementDelVariable(): variable = node.getTargetVariableRef().getVariable() if not variable.isModuleVariable() and \ isSharedLogically(variable): SyntaxErrors.raiseSyntaxError( reason = """\ can not delete variable '%s' referenced in nested scope""" % ( variable.getName() ), source_ref = ( None if isFullCompat() else node.getSourceReference() ), display_file = not isFullCompat(), display_line = not isFullCompat() )
def isSharedLogically(self): from nuitka.VariableRegistry import isSharedLogically return isSharedLogically(self)
def __init__(self, parent, function_body): # Too complex stuff here, but could be improved, just not now. # pylint: disable=R0912 assert function_body.isExpressionFunctionBody(), function_body CollectionStartpointMixin.__init__(self) ConstraintCollectionBase.__init__( self, parent = parent ) VariableUsageTrackingMixin.__init__(self) self.function_body = function_body function_body.constraint_collection = self statements_sequence = function_body.getBody() if statements_sequence is not None and \ not statements_sequence.getStatements(): function_body.setStatements(None) statements_sequence = None if statements_sequence is not None: result = statements_sequence.computeStatementsSequence( constraint_collection = self ) if result is not statements_sequence: function_body.setBody(result) self.makeVariableTraceOptimizations(function_body) if not Options.isExperimental() or self.removes_knowledge: return # self.dumpTrace() # Cannot mess with locals yet. if self.unclear_locals: return # TODO: Merge this into makeVariableTraceOptimizations instead, could # check the above for these too. # Trace based optimization goes here: for variable_trace in self.variable_traces.values(): variable = variable_trace.getVariable() # print variable if variable.isLocalVariable() and not isSharedLogically(variable): if variable_trace.isAssignTrace(): assign_node = variable_trace.getAssignNode() if not assign_node.getAssignSource().mayHaveSideEffects(): if not variable_trace.getPotentialUsages() and \ not variable_trace.isEscaped(): assign_node.parent.replaceWith( StatementDelVariable( variable_ref = assign_node, tolerant = True, source_ref = assign_node.getSourceReference() ) ) for release in variable_trace.releases: if release.isStatementDelVariable(): release.replaceWith( None ) self.signalChange( "new_statements", assign_node.parent.getSourceReference(), "Removed assignment without effect." ) elif variable_trace.isMergeTrace(): # print variable_trace if not variable_trace.getDefiniteUsages() and \ not variable_trace.isEscaped() and \ not variable_trace.releases: pass