1.1 --- a/simplify/__init__.py Sun Oct 14 22:46:10 2007 +0200
1.2 +++ b/simplify/__init__.py Sun Oct 14 22:46:36 2007 +0200
1.3 @@ -226,11 +226,27 @@
1.4
1.5 "Fix instances for all modules loaded by this importer."
1.6
1.7 - for module in self.get_modules():
1.8 - simplify.fixinstances.fix_structures(module)
1.9 - for module in self.get_modules():
1.10 - simplify.fixinstances.fix_signatures(module)
1.11 - for module in self.get_modules():
1.12 - simplify.fixinstances.fix(module)
1.13 + count = simplify.fixinstances.system.count
1.14 + while 1:
1.15 + for module in self.get_modules():
1.16 + simplify.fixinstances.fix_structures(module)
1.17 +
1.18 + print simplify.fixinstances.system.count - count, "attributes changed"
1.19 +
1.20 + for module in self.get_modules():
1.21 + simplify.fixinstances.fix_signatures(module)
1.22 +
1.23 + print simplify.fixinstances.system.count - count, "parameters changed"
1.24 +
1.25 + for module in self.get_modules():
1.26 + simplify.fixinstances.fix(module)
1.27 +
1.28 + print simplify.fixinstances.system.count - count, "sites changed"
1.29 +
1.30 + if simplify.fixinstances.system.count == count:
1.31 + break
1.32 + else:
1.33 + print "Processing structures again after", simplify.fixinstances.system.count - count, "changes"
1.34 + count = simplify.fixinstances.system.count
1.35
1.36 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/simplify/fixinstances.py Sun Oct 14 22:46:10 2007 +0200
2.2 +++ b/simplify/fixinstances.py Sun Oct 14 22:46:36 2007 +0200
2.3 @@ -39,6 +39,29 @@
2.4
2.5 from simplify.simplified import *
2.6
2.7 +class System:
2.8 +
2.9 + """
2.10 + A class maintaining the state of the fixing system like that used by the
2.11 + annotation system. When the system counter can no longer be incremented by
2.12 + any fixing operation, the system may be considered fixed.
2.13 + """
2.14 +
2.15 + def __init__(self):
2.16 + self.count = 0
2.17 +
2.18 + def fix(self, original_value, proposed_value):
2.19 +
2.20 + """
2.21 + Update the counter depending on the 'original_value' and the
2.22 + 'proposed_value' when attempting to fix the instances of a class.
2.23 + """
2.24 +
2.25 + if original_value is not proposed_value:
2.26 + self.count += 1
2.27 +
2.28 +system = System()
2.29 +
2.30 # Fixing of instance information.
2.31
2.32 class Fixer(Visitor):
2.33 @@ -225,7 +248,8 @@
2.34 if name == "accesses":
2.35 attr, accessor = item
2.36 value = attr.type
2.37 - new_items.append((Attribute(self._get_replacement(attr.context), self._get_replacement(value)), self._get_replacement(accessor)))
2.38 + new_items.append((Attribute(self._get_replacement(attr.context), self._get_replacement(value)),
2.39 + self._get_replacement(accessor)))
2.40 elif name == "invocations":
2.41 new_items.add(self._get_replacement(item))
2.42 else:
2.43 @@ -243,6 +267,10 @@
2.44
2.45 if isinstance(value, Instance):
2.46 distinct_instances = value.get_class().get_distinct_instances()
2.47 +
2.48 + # Make the fix by returning the proposed distinct instance.
2.49 +
2.50 + system.fix(value, distinct_instances[value])
2.51 return distinct_instances[value]
2.52
2.53 # For subprograms, find the distinct instance's copy for the owner
2.54 @@ -258,6 +286,10 @@
2.55 if value.copy_of.copies.has_key(instance):
2.56 subprogram = value.copy_of.copies[instance]
2.57 if subprogram.paramtypes == value.paramtypes:
2.58 +
2.59 + # Make the fix by returning the proposed subprogram.
2.60 +
2.61 + system.fix(value, subprogram)
2.62 return subprogram
2.63
2.64 return value