### changeset 343:ebbb77e339f8

flow.py: no longer using distribute, it was a flawed concept
author Sigurd Meldgaard Wed, 07 Jul 2010 16:28:23 +0200 d67f0bb6aeeb 54b28b30f310 pysmcl/flow.py pysmcl/range_analysis.py 2 files changed, 26 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
```--- a/pysmcl/flow.py	Wed Jul 07 16:11:11 2010 +0200
+++ b/pysmcl/flow.py	Wed Jul 07 16:28:23 2010 +0200
@@ -6,7 +6,7 @@
from pysmcl.pretty_print import PrettyPrinter

-def analyze(function, join, combine, key, init, forward=True, distribute=None):
+def analyze(function, join, combine, key, init, forward=True):
"""
Doing a simple intra procedural forward (or backwards) analysis
using the iterative worklist algorithm. Parametrized by the
@@ -30,17 +30,6 @@

"""

-    def default_distribute(x):
-        if forward:
-            for child in x.children:
-                child.in_values[key] = x.out_values[key]
-        else: #Backwards analysis
-            for parent in x.parents:
-                parent.in_values[key] = x.out_values[key]
-
-    if distribute is None:
-        distribute = default_distribute
-
# initialization

Flow().flow(function)
@@ -60,15 +49,15 @@
x = worklist.pop(0)
oldout = x.out_values[key]
if forward:
-            x.out_values[key] = combine(x, join(x.parents))
+            x.in_values[key] = join(x.parents)
+            x.out_values[key] = combine(x, x.in_values[key])
if oldout != x.out_values[key]:
-                distribute(x)
for child in x.children:
worklist.append(child)
else: # Backwards analysis
-            x.out_values[key] = combine(x, join(x.children))
+            x.in_values[key] = join(x.children)
+            x.out_values[key] = combine(x, x.in_values[key])
if oldout != x.out_values[key]:
-                distribute(x)
for parent in x.parents:
worklist.append(parent)
```
```--- a/pysmcl/range_analysis.py	Wed Jul 07 16:11:11 2010 +0200
+++ b/pysmcl/range_analysis.py	Wed Jul 07 16:28:23 2010 +0200
@@ -157,8 +157,7 @@
flow.analyze(function, self.join, self.combine, self.key,
combine_env({'True': Range(1, 1),
'False': Range(0, 0)},
-                                 initial_env),
-                     distribute=self.distribute)
+                                 initial_env))

def join(self, in_nodes):
"""The join function in the monotome framework.
@@ -180,27 +179,26 @@
isinstance(test.left, ast.Name) and
isinstance(test.comparators[0], ast.Num))

-    def distribute(self, x):
-        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]
-
+#    def distribute(self, x):
+#        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]
def combine(self, node, env):
"""The least upper bound of the node and the environment.
```