1.1 --- a/micropython/inspect.py Sat Jan 17 22:33:19 2009 +0100
1.2 +++ b/micropython/inspect.py Sat Jan 17 23:25:17 2009 +0100
1.3 @@ -146,17 +146,12 @@
1.4
1.5 if self.should_optimise_unused_objects():
1.6
1.7 - # Remove unused names.
1.8 -
1.9 - if name not in self.importer.names_used:
1.10 - del self[name]
1.11 -
1.12 # Remove entries for unreferenced objects.
1.13 # This, due to the nature of the referenced attribute, assumes
1.14 # that only explicitly mentioned classes and functions are
1.15 # employed in the final program.
1.16
1.17 - elif isinstance(value, Attr):
1.18 + if isinstance(value, Attr):
1.19 attr_value = value.value
1.20
1.21 # Only remove entries for classes and functions, not methods.
1.22 @@ -195,16 +190,15 @@
1.23 if isinstance(obj, Class):
1.24 for name, attr in obj.class_attributes().items():
1.25
1.26 - if name not in self.importer.names_used:
1.27 - del obj[name]
1.28 + # Methods can only be deleted if they are the only
1.29 + # assigned object to the class and are unreferenced.
1.30
1.31 - # Methods can only be deleted if they are the only
1.32 - # assigned object to the class and are unreferenced.
1.33 + if name not in self.importer.names_used and \
1.34 + attr.assignments == 1 and isinstance(attr.value, Function) and \
1.35 + attr.value.is_method() and not attr.value.referenced:
1.36
1.37 - if attr.assignments == 1 and isinstance(attr.value, Function) and \
1.38 - attr.value.is_method() and not attr.value.referenced:
1.39 -
1.40 - self.all_objects.remove(attr.value)
1.41 + self.all_objects.remove(attr.value)
1.42 + del obj[name]
1.43
1.44 def finalise(self):
1.45
1.46 @@ -529,6 +523,16 @@
1.47 return self.OP(node)
1.48
1.49 def visitConst(self, node):
1.50 +
1.51 + # Accounting.
1.52 +
1.53 + name = node.value.__class__.__name__
1.54 + if self.builtins is not None and self.builtins.has_key(name):
1.55 + attr = self.builtins[name]
1.56 + attr.set_referenced()
1.57 +
1.58 + # Register the constant, if necessary, returning the resulting object.
1.59 +
1.60 return self.importer.make_constant(node.value)
1.61
1.62 visitContinue = NOP