changeset 334:5a7d7698512b

Corrected grouping of ifs
author Sigurd Meldgaard <stm@daimi.au.dk>
date Wed, 07 Jul 2010 11:14:30 +0200
parents b42cc382a1f0
children afabe8ada21f
files pysmcl/range_analysis.py
diffstat 1 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- 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]