1.1 --- a/simplify.py Sun Oct 29 21:22:31 2006 +0100
1.2 +++ b/simplify.py Sun Oct 29 21:23:39 2006 +0100
1.3 @@ -115,7 +115,7 @@
1.4 attribute is set on the Module object using a value other than None.
1.5 """
1.6
1.7 - result = Module(module, 1, name=name)
1.8 + result = self.module = Module(module, 1, name=name)
1.9 module_code = self.dispatch(module.node)
1.10
1.11 # NOTE: Constant initialisation necessary for annotation but perhaps
1.12 @@ -337,12 +337,15 @@
1.13 result.else_ = self.dispatch(tryexcept.else_)
1.14
1.15 results = nodes = []
1.16 + catch_all = 0
1.17 +
1.18 for spec, assign, stmt in tryexcept.handlers:
1.19
1.20 # If no specification exists, produce an unconditional block.
1.21
1.22 if spec is None:
1.23 nodes += self.dispatch(stmt)
1.24 + catch_all = 1
1.25
1.26 # Produce something like...
1.27 # isinstance(<exc>, <spec>)
1.28 @@ -377,10 +380,11 @@
1.29
1.30 # Add a raise operation to deal with unhandled exceptions.
1.31
1.32 - nodes.append(
1.33 - Raise(
1.34 - expr=LoadExc())
1.35 - )
1.36 + if not catch_all:
1.37 + nodes.append(
1.38 + Raise(
1.39 + expr=LoadExc())
1.40 + )
1.41
1.42 result.handler = results
1.43 return result
1.44 @@ -407,7 +411,7 @@
1.45 (else) -> ...
1.46 """
1.47
1.48 - subprogram = Subprogram(name=None, internal=1, returns_value=1, params=[], star=None, dstar=None)
1.49 + subprogram = Subprogram(name=None, module=self.module, internal=1, returns_value=1, params=[], star=None, dstar=None)
1.50 self.current_subprograms.append(subprogram)
1.51
1.52 # In the subprogram, make instructions which invoke a method on the
1.53 @@ -512,7 +516,7 @@
1.54 (else) -> ...
1.55 """
1.56
1.57 - subprogram = Subprogram(name=None, internal=1, returns_value=1, params=[], star=None, dstar=None)
1.58 + subprogram = Subprogram(name=None, module=self.module, internal=1, returns_value=1, params=[], star=None, dstar=None)
1.59 self.current_subprograms.append(subprogram)
1.60
1.61 # In the subprogram, make instructions which store each operand, test
1.62 @@ -572,7 +576,7 @@
1.63 (else) -> ...
1.64 """
1.65
1.66 - subprogram = Subprogram(name=None, internal=1, returns_value=1, params=[], star=None, dstar=None)
1.67 + subprogram = Subprogram(name=None, module=self.module, internal=1, returns_value=1, params=[], star=None, dstar=None)
1.68 self.current_subprograms.append(subprogram)
1.69
1.70 # In the subprogram, make instructions which store each operand, test
1.71 @@ -1015,12 +1019,12 @@
1.72 # Invocation and subprogram transformations.
1.73
1.74 def visitClass(self, class_):
1.75 - structure = Class(name=class_.name, bases=self.dispatches(class_.bases))
1.76 + structure = Class(name=class_.name, module=self.module, bases=self.dispatches(class_.bases))
1.77 self.structures.append(structure)
1.78
1.79 # Make a subprogram which initialises the class structure.
1.80
1.81 - subprogram = Subprogram(name=None, structure=structure, params=[], star=None, dstar=None)
1.82 + subprogram = Subprogram(name=None, module=self.module, structure=structure, params=[], star=None, dstar=None)
1.83 self.current_subprograms.append(subprogram)
1.84
1.85 # The class is initialised using the code found inside.
1.86 @@ -1116,7 +1120,7 @@
1.87 (dstar)
1.88 """
1.89
1.90 - subprogram = Subprogram(name=function.name, internal=0, returns_value=1, star=None, dstar=None)
1.91 + subprogram = Subprogram(name=function.name, module=self.module, internal=0, returns_value=1, star=None, dstar=None)
1.92 self.current_subprograms.append(subprogram)
1.93 subprogram.code = self.dispatch(function.code) + [Return()]
1.94 self.current_subprograms.pop()
1.95 @@ -1132,7 +1136,7 @@
1.96 # Make a subprogram for the function and record it outside the main
1.97 # tree.
1.98
1.99 - subprogram = Subprogram(name=None, internal=0, returns_value=1, star=None, dstar=None)
1.100 + subprogram = Subprogram(name=None, module=self.module, internal=0, returns_value=1, star=None, dstar=None)
1.101 self.current_subprograms.append(subprogram)
1.102 subprogram.code = [Return(expr=self.dispatch(lambda_.code))]
1.103 self.current_subprograms.pop()
1.104 @@ -1167,7 +1171,7 @@
1.105 (else) -> ...
1.106 """
1.107
1.108 - subprogram = Subprogram(name=None, internal=1, returns_value=0, params=[], star=None, dstar=None)
1.109 + subprogram = Subprogram(name=None, module=self.module, internal=1, returns_value=0, params=[], star=None, dstar=None)
1.110 self.current_subprograms.append(subprogram)
1.111
1.112 # Include a conditional statement in the subprogram.
1.113 @@ -1223,7 +1227,7 @@
1.114 (else) -> ...
1.115 """
1.116
1.117 - subprogram = Subprogram(name=None, internal=1, returns_value=0, params=[], star=None, dstar=None)
1.118 + subprogram = Subprogram(name=None, module=self.module, internal=1, returns_value=0, params=[], star=None, dstar=None)
1.119 self.current_subprograms.append(subprogram)
1.120
1.121 # Always return from conditional sections/subprograms.