1.1 --- a/simplify/fixinstances.py Sat Jun 23 01:54:26 2007 +0200
1.2 +++ b/simplify/fixinstances.py Sat Jun 23 01:57:13 2007 +0200
1.3 @@ -74,15 +74,7 @@
1.4 self.current_subprograms = []
1.5
1.6 self.module = module
1.7 -
1.8 - # Visit structures and instances.
1.9 -
1.10 - for structure in self.module.simplifier.structures:
1.11 - for instance in structure.get_instances():
1.12 - for name, attrs in instance.namespace.items():
1.13 - instance.namespace[name] = self._replace(attrs)
1.14 -
1.15 - self.process_node(self.module)
1.16 + self.process_node(module)
1.17
1.18 # Then, process all functions and methods.
1.19
1.20 @@ -95,6 +87,19 @@
1.21 for specialised in subprogram.active():
1.22 self.subprograms.append(self.process_node(specialised))
1.23
1.24 + def process_structures(self, module):
1.25 +
1.26 + "Process the structures of the given 'module'."
1.27 +
1.28 + self.module = module
1.29 +
1.30 + # Visit structures and instances.
1.31 +
1.32 + for structure in self.module.simplifier.structures:
1.33 + for instance in structure.get_instances():
1.34 + for name, attrs in instance.namespace.items():
1.35 + instance.namespace[name] = self._replace(attrs)
1.36 +
1.37 def process_node(self, node):
1.38
1.39 """
1.40 @@ -139,9 +144,10 @@
1.41 for name in ("accesses", "writes", "paramtypes"):
1.42 if hasattr(node, name):
1.43 d = getattr(node, name)
1.44 + new_d = {}
1.45 for expr, attrs in d.items():
1.46 - del d[expr]
1.47 - d[self._get_replacement(expr)] = self._replace(attrs, name)
1.48 + new_d[self._get_replacement(expr)] = self._replace(attrs, name)
1.49 + setattr(node, name, new_d)
1.50
1.51 # Visit program nodes.
1.52
1.53 @@ -216,9 +222,16 @@
1.54
1.55 # Convenience functions.
1.56
1.57 +def fix_structures(module):
1.58 +
1.59 + "Fix the structures in the given 'module'."
1.60 +
1.61 + fixer = Fixer()
1.62 + fixer.process_structures(module)
1.63 +
1.64 def fix(module):
1.65
1.66 - "Fix the instances in the given 'module'."
1.67 + "Fix the structure references in the given 'module'."
1.68
1.69 fixer = Fixer()
1.70 fixer.process(module)
2.1 --- a/simplify/simplified/data.py Sat Jun 23 01:54:26 2007 +0200
2.2 +++ b/simplify/simplified/data.py Sat Jun 23 01:57:13 2007 +0200
2.3 @@ -24,6 +24,10 @@
2.4 from simplify.simplified.utils import Structure, WithName, name
2.5 from simplify.simplified.program import Subprogram
2.6
2.7 +# Housekeeping.
2.8 +
2.9 +current_structures = set()
2.10 +
2.11 # Special non-program nodes.
2.12
2.13 class _Class(Structure, WithName):
2.14 @@ -37,8 +41,6 @@
2.15 Structure.__init__(self, *args, **kw)
2.16 WithName.__init__(self)
2.17
2.18 - self.cache = None
2.19 -
2.20 def full_name(self):
2.21 return "class %s" % self._full_name
2.22
2.23 @@ -83,8 +85,8 @@
2.24 attribute types are distinct.
2.25 """
2.26
2.27 - if self.cache is not None:
2.28 - return self.cache
2.29 + in_current_structure = (self in current_structures)
2.30 + current_structures.add(self)
2.31
2.32 instances = {}
2.33 names_found = []
2.34 @@ -97,6 +99,11 @@
2.35
2.36 for instance_name in instance_names:
2.37 instance = names_to_instances[instance_name]
2.38 +
2.39 + if in_current_structure:
2.40 + instances[instance] = instance
2.41 + continue
2.42 +
2.43 names = instance.namespace.names
2.44 try:
2.45 i = names_found.index(names)
2.46 @@ -106,7 +113,8 @@
2.47 instances_found.append(instance)
2.48 instances[instance] = instance
2.49
2.50 - self.cache = instances
2.51 + current_structures.remove(self)
2.52 +
2.53 return instances
2.54
2.55 class SingleInstanceClass(_Class):
3.1 --- a/test.py Sat Jun 23 01:54:26 2007 +0200
3.2 +++ b/test.py Sat Jun 23 01:57:13 2007 +0200
3.3 @@ -27,6 +27,8 @@
3.4 raise
3.5 else:
3.6 if "-i" in sys.argv:
3.7 + simplify.fixinstances.fix_structures(module)
3.8 + simplify.fixinstances.fix_structures(builtins)
3.9 simplify.fixinstances.fix(module)
3.10 simplify.fixinstances.fix(builtins)
3.11 if "-d" in sys.argv: