1.1 --- a/micropython/inspect.py Sun Jun 07 22:55:59 2009 +0200
1.2 +++ b/micropython/inspect.py Mon Jun 08 00:49:37 2009 +0200
1.3 @@ -176,9 +176,11 @@
1.4 names.
1.5 """
1.6
1.7 - for name, value in self.items():
1.8 + # Remove unreferenced objects.
1.9
1.10 - if self.should_optimise_unused_objects():
1.11 + if self.should_optimise_unused_objects():
1.12 +
1.13 + for name, value in self.items():
1.14
1.15 # Remove entries for unreferenced objects.
1.16 # This, due to the nature of the referenced attribute, assumes
1.17 @@ -198,10 +200,6 @@
1.18 else:
1.19 del self[name]
1.20
1.21 - # Remove unreferenced objects.
1.22 -
1.23 - if self.should_optimise_unused_objects():
1.24 -
1.25 all_objects = list(self.all_objects)
1.26
1.27 for obj in all_objects:
1.28 @@ -212,21 +210,33 @@
1.29 isinstance(obj, Class)) and not obj.referenced:
1.30
1.31 self.all_objects.remove(obj)
1.32 + obj_was_removed = 1
1.33 +
1.34 + else:
1.35 + obj_was_removed = 0
1.36
1.37 # Remove unused entries from classes plus associated methods.
1.38
1.39 if isinstance(obj, Class):
1.40 for name, attr in obj.class_attributes().items():
1.41
1.42 - # Methods can only be deleted if they are the only
1.43 - # assigned object to the class and are unreferenced.
1.44 + # In removed classes, all explicitly defined methods can
1.45 + # be removed.
1.46
1.47 - if name not in self.importer.names_used and \
1.48 + # In other classes, methods can only be removed if they
1.49 + # are the only assigned object to the class for a
1.50 + # particular attribute and are unreferenced.
1.51 +
1.52 + if obj_was_removed and isinstance(attr.get_value(), Function) and attr.get_value().is_method() or \
1.53 + name not in self.importer.names_used and \
1.54 attr.assignments == 1 and isinstance(attr.get_value(), Function) and \
1.55 attr.get_value().is_method() and not attr.get_value().referenced:
1.56
1.57 - self.all_objects.remove(attr.get_value())
1.58 - del obj[name]
1.59 + method = attr.get_value()
1.60 +
1.61 + if method in self.all_objects:
1.62 + self.all_objects.remove(method)
1.63 + del obj[name]
1.64
1.65 def finalise(self):
1.66