# HG changeset patch # User Sigurd Meldgaard # Date 1278494070 -7200 # Node ID 5a7d7698512b3d15507d8fdda6c81320ab153388 # Parent b42cc382a1f081c502f31d1f0bc723d6ec813587 Corrected grouping of ifs diff -r b42cc382a1f0 -r 5a7d7698512b pysmcl/range_analysis.py --- a/pysmcl/range_analysis.py Wed Jul 07 11:08:06 2010 +0200 +++ b/pysmcl/range_analysis.py Wed Jul 07 11:14:30 2010 +0200 @@ -181,21 +181,22 @@ isinstance(test.comparators[0], ast.Num)) def distribute(self, x): - if isinstance(x, ast.If): - if self.is_comparison(x.test): - # This works this effect: - # if a <= 3: - # pass # now we know a <= 3 - a = dict(x.out_values[self.key]) - old = a[x.test.left.id] - compared_value = RangeVisitor( - x.out_values[self.key]).visit(x.test.comparators[0]) - a[x.test.left.id] = (min(old[0], compared_value[1]), - min(old[1], compared_value[1])) - print(a, x.test.left.id) - x.body[0].in_values[self.key] = a - if len(x.orelse)>0: - x.orelse[0].in_values[self.key] = x.out_values[self.key] + if(isinstance(x, ast.If) + and self.is_comparison(x.test)): + # This works this effect: + # if a <= 3: + # pass # now we know a <= 3 + # TODO: generalize this + assert(False) + a = dict(x.out_values[self.key]) + old = a[x.test.left.id] + compared_value = RangeVisitor( + x.out_values[self.key]).visit(x.test.comparators[0]) + a[x.test.left.id] = Range(min(old[0], compared_value[1]), + min(old[1], compared_value[1])) + x.body[0].in_values[self.key] = a + if len(x.orelse)>0: + x.orelse[0].in_values[self.key] = x.out_values[self.key] else: for child in x.children: child.in_values[self.key] = x.out_values[self.key]