1.1 --- a/tests/logical_simple.py Tue Feb 28 17:00:26 2017 +0100
1.2 +++ b/tests/logical_simple.py Tue Feb 28 17:18:48 2017 +0100
1.3 @@ -1,3 +1,6 @@
1.4 +def no_temp(a, b):
1.5 + return not (a and b)
1.6 +
1.7 a = 1
1.8 b = 2
1.9 c = a and b
1.10 @@ -11,6 +14,9 @@
1.11
1.12 f = 0
1.13
1.14 +g = no_temp(a, b)
1.15 +print g # False
1.16 +
1.17 if a and b:
1.18 print "a and b" # a and b
1.19 else:
2.1 --- a/translator.py Tue Feb 28 17:00:26 2017 +0100
2.2 +++ b/translator.py Tue Feb 28 17:18:48 2017 +0100
2.3 @@ -1396,7 +1396,7 @@
2.4
2.5 "Process the given operator node 'n'."
2.6
2.7 - return NegationResult(self.process_structure_node(n.expr))
2.8 + return self.make_negation(self.process_structure_node(n.expr))
2.9
2.10 def process_raise_node(self, n):
2.11
2.12 @@ -1610,7 +1610,7 @@
2.13
2.14 # Emit a negated test of the continuation condition.
2.15
2.16 - self.start_if(True, NegationResult(test))
2.17 + self.start_if(True, self.make_negation(test))
2.18 if n.else_:
2.19 self.process_structure_node(n.else_)
2.20 self.writestmt("break;")
2.21 @@ -1676,6 +1676,20 @@
2.22
2.23 return self.temp_usage.has_key(path) and name in self.temp_usage[path]
2.24
2.25 + def make_negation(self, expr):
2.26 +
2.27 + "Return a negated form of 'expr'."
2.28 +
2.29 + result = NegationResult(expr)
2.30 +
2.31 + # Negation discards the temporary results of its operand.
2.32 +
2.33 + temps = expr.discards_temporary()
2.34 + if temps:
2.35 + self.remove_temps(temps)
2.36 +
2.37 + return result
2.38 +
2.39 # Output generation.
2.40
2.41 def start_output(self):
3.1 --- a/transresults.py Tue Feb 28 17:00:26 2017 +0100
3.2 +++ b/transresults.py Tue Feb 28 17:18:48 2017 +0100
3.3 @@ -280,11 +280,11 @@
3.4 def discards_temporary(self, test=True):
3.5
3.6 """
3.7 - Return a list of temporary names that can be discarded if 'test' is
3.8 - specified as a true value (or omitted).
3.9 + Negations should have discarded their operand's temporary names when
3.10 + being instantiated.
3.11 """
3.12
3.13 - return self.expr.discards_temporary(test)
3.14 + return None
3.15
3.16 def __str__(self):
3.17 return "(%s ? %s : %s)" % (