1.1 --- a/simplify/__init__.py Tue Jul 31 01:05:24 2007 +0200
1.2 +++ b/simplify/__init__.py Sun Aug 05 21:38:40 2007 +0200
1.3 @@ -229,6 +229,8 @@
1.4 for module in self.get_modules():
1.5 simplify.fixinstances.fix_structures(module)
1.6 for module in self.get_modules():
1.7 + simplify.fixinstances.fix_signatures(module)
1.8 + for module in self.get_modules():
1.9 simplify.fixinstances.fix(module)
1.10
1.11 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/simplify/ast.py Tue Jul 31 01:05:24 2007 +0200
2.2 +++ b/simplify/ast.py Sun Aug 05 21:38:40 2007 +0200
2.3 @@ -73,8 +73,8 @@
2.4 """
2.5
2.6 Visitor.__init__(self)
2.7 - self.subprograms = [] # Subprograms outside the tree.
2.8 - self.structures = [] # Structures/classes.
2.9 + self.subprograms = set() # Subprograms outside the tree.
2.10 + self.structures = set() # Structures/classes.
2.11 self.constants = {} # Constants.
2.12 self.current_subprograms = [] # Current subprograms being processed.
2.13 self.current_structures = [] # Current structures being processed.
2.14 @@ -208,7 +208,8 @@
2.15 subprogram.code = results
2.16
2.17 self.current_subprograms.pop()
2.18 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.19 + self.subprograms.add(subprogram)
2.20 + self.subnames[subprogram.full_name()] = subprogram
2.21
2.22 # Make an invocation of the subprogram.
2.23
2.24 @@ -556,7 +557,8 @@
2.25 subprogram.code = results
2.26
2.27 self.current_subprograms.pop()
2.28 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.29 + self.subprograms.add(subprogram)
2.30 + self.subnames[subprogram.full_name()] = subprogram
2.31
2.32 # Make an invocation of the subprogram.
2.33
2.34 @@ -586,7 +588,7 @@
2.35 bases = class_.bases
2.36
2.37 structure = get_class()(name=class_.name, module=self.module, bases=self.dispatches(bases))
2.38 - self.structures.append(structure)
2.39 + self.structures.add(structure)
2.40 within_class = self.within_class
2.41 self.within_class = 1
2.42
2.43 @@ -603,7 +605,8 @@
2.44 self.within_class = within_class
2.45 self.current_structures.pop()
2.46 self.current_subprograms.pop()
2.47 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.48 + self.subprograms.add(subprogram)
2.49 + self.subnames[subprogram.full_name()] = subprogram
2.50
2.51 # Make a definition of the class associating it with a name.
2.52
2.53 @@ -759,7 +762,8 @@
2.54 subprogram.code = results
2.55
2.56 self.current_subprograms.pop()
2.57 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.58 + self.subprograms.add(subprogram)
2.59 + self.subnames[subprogram.full_name()] = subprogram
2.60
2.61 # Make an invocation of the subprogram.
2.62
2.63 @@ -885,7 +889,8 @@
2.64 # Finish the subprogram definition.
2.65
2.66 self.current_subprograms.pop()
2.67 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.68 + self.subprograms.add(subprogram)
2.69 + self.subnames[subprogram.full_name()] = subprogram
2.70
2.71 # Obtain an iterator for the sequence involved.
2.72 # Then, make an invocation of the subprogram.
2.73 @@ -994,7 +999,8 @@
2.74 subprogram.params = params
2.75 subprogram.star = star
2.76 subprogram.dstar = dstar
2.77 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.78 + self.subprograms.add(subprogram)
2.79 + self.subnames[subprogram.full_name()] = subprogram
2.80
2.81 def visitFunction(self, function):
2.82
2.83 @@ -1185,7 +1191,8 @@
2.84 )
2.85
2.86 self.current_subprograms.pop()
2.87 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.88 + self.subprograms.add(subprogram)
2.89 + self.subnames[subprogram.full_name()] = subprogram
2.90
2.91 # Make an invocation of the subprogram.
2.92
2.93 @@ -1229,7 +1236,8 @@
2.94 ]
2.95
2.96 self.current_subprograms.pop()
2.97 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.98 + self.subprograms.add(subprogram)
2.99 + self.subnames[subprogram.full_name()] = subprogram
2.100
2.101 # Make an invocation of the subprogram.
2.102
2.103 @@ -1365,7 +1373,8 @@
2.104 subprogram.code = results
2.105
2.106 self.current_subprograms.pop()
2.107 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.108 + self.subprograms.add(subprogram)
2.109 + self.subnames[subprogram.full_name()] = subprogram
2.110
2.111 # Make an invocation of the subprogram.
2.112
2.113 @@ -1722,7 +1731,8 @@
2.114 subprogram.code = [test]
2.115
2.116 self.current_subprograms.pop()
2.117 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.118 + self.subprograms.add(subprogram)
2.119 + self.subnames[subprogram.full_name()] = subprogram
2.120
2.121 # Make an invocation of the subprogram.
2.122
2.123 @@ -1836,7 +1846,8 @@
2.124 ]
2.125
2.126 self.current_subprograms.pop()
2.127 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.128 + self.subprograms.add(subprogram)
2.129 + self.subnames[subprogram.full_name()] = subprogram
2.130
2.131 result = InvokeRef(
2.132 binary,
2.133 @@ -1907,7 +1918,8 @@
2.134 ]
2.135
2.136 self.current_subprograms.pop()
2.137 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.138 + self.subprograms.add(subprogram)
2.139 + self.subnames[subprogram.full_name()] = subprogram
2.140
2.141 result = InvokeRef(
2.142 binary,
3.1 --- a/simplify/fixinstances.py Tue Jul 31 01:05:24 2007 +0200
3.2 +++ b/simplify/fixinstances.py Sun Aug 05 21:38:40 2007 +0200
3.3 @@ -109,6 +109,18 @@
3.4 for name, attrs in instance.namespace.items():
3.5 instance.namespace[name] = self._replace(attrs)
3.6
3.7 + def process_signatures(self, module):
3.8 +
3.9 + "Process the signatures of subprograms in this 'module'."
3.10 +
3.11 + self.module = module
3.12 +
3.13 + # Visit each subprogram, updating the signatures.
3.14 +
3.15 + for subprogram in self.module.simplifier.subprograms:
3.16 + for specialisation in subprogram.active():
3.17 + self._replace_dict(specialisation, "paramtypes")
3.18 +
3.19 def process_node(self, node):
3.20
3.21 """
3.22 @@ -148,15 +160,10 @@
3.23
3.24 for name in ("non_accesses", "non_writes", "raises", "returns", "types", "invocations"):
3.25 if hasattr(node, name):
3.26 - attrs = getattr(node, name)
3.27 - setattr(node, name, self._replace(attrs, name))
3.28 + self._replace_list(node, name)
3.29 for name in ("accesses", "writes", "paramtypes"):
3.30 if hasattr(node, name):
3.31 - d = getattr(node, name)
3.32 - new_d = {}
3.33 - for expr, attrs in d.items():
3.34 - new_d[self._get_replacement(expr)] = self._replace(attrs, name)
3.35 - setattr(node, name, new_d)
3.36 + self._replace_dict(node, name)
3.37
3.38 # Visit program nodes.
3.39
3.40 @@ -182,6 +189,17 @@
3.41
3.42 return node
3.43
3.44 + def _replace_list(self, node, name):
3.45 + attrs = getattr(node, name)
3.46 + setattr(node, name, self._replace(attrs, name))
3.47 +
3.48 + def _replace_dict(self, node, name):
3.49 + d = getattr(node, name)
3.50 + new_d = {}
3.51 + for expr, attrs in d.items():
3.52 + new_d[self._get_replacement(expr)] = self._replace(attrs, name)
3.53 + setattr(node, name, new_d)
3.54 +
3.55 def _replace(self, items, name=None):
3.56
3.57 """
3.58 @@ -265,6 +283,13 @@
3.59 fixer = Fixer()
3.60 fixer.process_structures(module)
3.61
3.62 +def fix_signatures(module):
3.63 +
3.64 + "Fix the signatures in the given 'module'."
3.65 +
3.66 + fixer = Fixer()
3.67 + fixer.process_signatures(module)
3.68 +
3.69 def fix(module):
3.70
3.71 "Fix the structure references in the given 'module'."