# HG changeset patch # User Paul Boddie # Date 1488298728 -3600 # Node ID ba53413ad5de163d7084653a95fd958411844812 # Parent f0fb5ec36d9911ef44a5434876b928c73e4965e7 Remove temporary names used by negation operands. diff -r f0fb5ec36d99 -r ba53413ad5de tests/logical_simple.py --- a/tests/logical_simple.py Tue Feb 28 17:00:26 2017 +0100 +++ b/tests/logical_simple.py Tue Feb 28 17:18:48 2017 +0100 @@ -1,3 +1,6 @@ +def no_temp(a, b): + return not (a and b) + a = 1 b = 2 c = a and b @@ -11,6 +14,9 @@ f = 0 +g = no_temp(a, b) +print g # False + if a and b: print "a and b" # a and b else: diff -r f0fb5ec36d99 -r ba53413ad5de translator.py --- a/translator.py Tue Feb 28 17:00:26 2017 +0100 +++ b/translator.py Tue Feb 28 17:18:48 2017 +0100 @@ -1396,7 +1396,7 @@ "Process the given operator node 'n'." - return NegationResult(self.process_structure_node(n.expr)) + return self.make_negation(self.process_structure_node(n.expr)) def process_raise_node(self, n): @@ -1610,7 +1610,7 @@ # Emit a negated test of the continuation condition. - self.start_if(True, NegationResult(test)) + self.start_if(True, self.make_negation(test)) if n.else_: self.process_structure_node(n.else_) self.writestmt("break;") @@ -1676,6 +1676,20 @@ return self.temp_usage.has_key(path) and name in self.temp_usage[path] + def make_negation(self, expr): + + "Return a negated form of 'expr'." + + result = NegationResult(expr) + + # Negation discards the temporary results of its operand. + + temps = expr.discards_temporary() + if temps: + self.remove_temps(temps) + + return result + # Output generation. def start_output(self): diff -r f0fb5ec36d99 -r ba53413ad5de transresults.py --- a/transresults.py Tue Feb 28 17:00:26 2017 +0100 +++ b/transresults.py Tue Feb 28 17:18:48 2017 +0100 @@ -280,11 +280,11 @@ def discards_temporary(self, test=True): """ - Return a list of temporary names that can be discarded if 'test' is - specified as a true value (or omitted). + Negations should have discarded their operand's temporary names when + being instantiated. """ - return self.expr.discards_temporary(test) + return None def __str__(self): return "(%s ? %s : %s)" % (