1.1 --- a/transresults.py Tue Feb 28 00:00:09 2017 +0100
1.2 +++ b/transresults.py Tue Feb 28 17:00:26 2017 +0100
1.3 @@ -37,9 +37,25 @@
1.4 "A general expression."
1.5
1.6 def __init__(self, s):
1.7 - self.s = s
1.8 + if isinstance(s, Result):
1.9 + self.s = str(s)
1.10 + self.expr = s
1.11 + else:
1.12 + self.s = s
1.13 + self.expr = None
1.14 +
1.15 + def discards_temporary(self, test=True):
1.16 +
1.17 + """
1.18 + Return a list of temporary names that can be discarded if 'test' is
1.19 + specified as a true value (or omitted).
1.20 + """
1.21 +
1.22 + return self.expr and self.expr.discards_temporary(False)
1.23 +
1.24 def __str__(self):
1.25 return self.s
1.26 +
1.27 def __repr__(self):
1.28 return "Expression(%r)" % self.s
1.29
1.30 @@ -261,6 +277,15 @@
1.31 expr = self._convert(self.expr)
1.32 return "(!%s)" % expr
1.33
1.34 + def discards_temporary(self, test=True):
1.35 +
1.36 + """
1.37 + Return a list of temporary names that can be discarded if 'test' is
1.38 + specified as a true value (or omitted).
1.39 + """
1.40 +
1.41 + return self.expr.discards_temporary(test)
1.42 +
1.43 def __str__(self):
1.44 return "(%s ? %s : %s)" % (
1.45 self._convert(self.expr),
1.46 @@ -301,6 +326,25 @@
1.47 else:
1.48 return "(%s)" % " || ".join(results)
1.49
1.50 + def discards_temporary(self, test=True):
1.51 +
1.52 + """
1.53 + Return a list of temporary names that can be discarded if 'test' is
1.54 + specified as a true value (or omitted).
1.55 + """
1.56 +
1.57 + if not test:
1.58 + return None
1.59 +
1.60 + temps = ["__tmp_result"]
1.61 +
1.62 + for expr in self.exprs:
1.63 + t = expr.discards_temporary(test)
1.64 + if t:
1.65 + temps += t
1.66 +
1.67 + return temps
1.68 +
1.69 def __str__(self):
1.70
1.71 """