1.1 --- a/simplify/fixinstances.py Sun Oct 14 22:46:10 2007 +0200
1.2 +++ b/simplify/fixinstances.py Sun Oct 14 22:46:36 2007 +0200
1.3 @@ -39,6 +39,29 @@
1.4
1.5 from simplify.simplified import *
1.6
1.7 +class System:
1.8 +
1.9 + """
1.10 + A class maintaining the state of the fixing system like that used by the
1.11 + annotation system. When the system counter can no longer be incremented by
1.12 + any fixing operation, the system may be considered fixed.
1.13 + """
1.14 +
1.15 + def __init__(self):
1.16 + self.count = 0
1.17 +
1.18 + def fix(self, original_value, proposed_value):
1.19 +
1.20 + """
1.21 + Update the counter depending on the 'original_value' and the
1.22 + 'proposed_value' when attempting to fix the instances of a class.
1.23 + """
1.24 +
1.25 + if original_value is not proposed_value:
1.26 + self.count += 1
1.27 +
1.28 +system = System()
1.29 +
1.30 # Fixing of instance information.
1.31
1.32 class Fixer(Visitor):
1.33 @@ -225,7 +248,8 @@
1.34 if name == "accesses":
1.35 attr, accessor = item
1.36 value = attr.type
1.37 - new_items.append((Attribute(self._get_replacement(attr.context), self._get_replacement(value)), self._get_replacement(accessor)))
1.38 + new_items.append((Attribute(self._get_replacement(attr.context), self._get_replacement(value)),
1.39 + self._get_replacement(accessor)))
1.40 elif name == "invocations":
1.41 new_items.add(self._get_replacement(item))
1.42 else:
1.43 @@ -243,6 +267,10 @@
1.44
1.45 if isinstance(value, Instance):
1.46 distinct_instances = value.get_class().get_distinct_instances()
1.47 +
1.48 + # Make the fix by returning the proposed distinct instance.
1.49 +
1.50 + system.fix(value, distinct_instances[value])
1.51 return distinct_instances[value]
1.52
1.53 # For subprograms, find the distinct instance's copy for the owner
1.54 @@ -258,6 +286,10 @@
1.55 if value.copy_of.copies.has_key(instance):
1.56 subprogram = value.copy_of.copies[instance]
1.57 if subprogram.paramtypes == value.paramtypes:
1.58 +
1.59 + # Make the fix by returning the proposed subprogram.
1.60 +
1.61 + system.fix(value, subprogram)
1.62 return subprogram
1.63
1.64 return value