1.1 --- a/micropython/__init__.py Sun Nov 22 04:15:05 2009 +0100
1.2 +++ b/micropython/__init__.py Sun Nov 22 18:54:52 2009 +0100
1.3 @@ -369,8 +369,9 @@
1.4
1.5 # Attribute usage.
1.6
1.7 - self.attributes_used = None
1.8 + self.attributes_used = {}
1.9 self.name_references = {}
1.10 + self.specific_name_references = {}
1.11
1.12 # Status information.
1.13
1.14 @@ -446,6 +447,19 @@
1.15 self.name_references[from_name] = set()
1.16 self.name_references[from_name].add(names)
1.17
1.18 + def use_specific_name(self, specific_name, from_name):
1.19 +
1.20 + """
1.21 + Register the given 'specific_name' for an object as being used in the
1.22 + program from within an object with the specified 'from_name'.
1.23 + """
1.24 +
1.25 + if not self.specific_name_references.has_key(from_name):
1.26 + self.specific_name_references[from_name] = set()
1.27 + self.specific_name_references[from_name].add(specific_name)
1.28 +
1.29 + # Name accounting products.
1.30 +
1.31 def uses_attribute(self, obj, name):
1.32
1.33 """
1.34 @@ -470,20 +484,17 @@
1.35
1.36 "Collect attribute references for the entire program."
1.37
1.38 - if self.attributes_used is None:
1.39 -
1.40 - # Include names which may not be explicitly used in programs.
1.41 - # NOTE: Potentially declare these when inspecting.
1.42 + # Include names which may not be explicitly used in programs.
1.43 + # NOTE: Potentially declare these when inspecting.
1.44
1.45 - self.attributes_used = {}
1.46 - for name in self.names_always_used:
1.47 - for objname in objtable.all_possible_objects([name]):
1.48 - self.use_attribute(objname, name)
1.49 + for name in self.names_always_used:
1.50 + for objname in objtable.all_possible_objects([name]):
1.51 + self.use_attribute(objname, name)
1.52
1.53 - # Start with the "root" modules, finding referenced objects.
1.54 + # Start with the "root" modules, finding referenced objects.
1.55
1.56 - self._collect_attributes("__builtins__", objtable)
1.57 - self._collect_attributes("__main__", objtable)
1.58 + self._collect_attributes("__builtins__", objtable)
1.59 + self._collect_attributes("__main__", objtable)
1.60
1.61 def _collect_attributes(self, from_name, objtable):
1.62
1.63 @@ -495,12 +506,21 @@
1.64 if self.attributes_used.has_key(from_name):
1.65 return
1.66
1.67 + # Get name references and find possible objects which support such
1.68 + # combinations of attribute names.
1.69 +
1.70 for names in self.name_references.get(from_name, []):
1.71 for objname in objtable.all_possible_objects(names):
1.72 for name in names:
1.73 self.use_attribute(objname, name)
1.74 self._collect_attributes(objname + "." + name, objtable)
1.75
1.76 + # Get specific name references and visit the referenced objects.
1.77 +
1.78 + for name in self.specific_name_references.get(from_name, []):
1.79 + self.use_attribute(from_name, name)
1.80 + self._collect_attributes(from_name + "." + name, objtable)
1.81 +
1.82 # Constant accounting.
1.83
1.84 def init_predefined_constants(self):
2.1 --- a/micropython/inspect.py Sun Nov 22 04:15:05 2009 +0100
2.2 +++ b/micropython/inspect.py Sun Nov 22 18:54:52 2009 +0100
2.3 @@ -187,7 +187,7 @@
2.4 for names in namespace.get_all_attribute_usage():
2.5 self.importer.use_names(names, namespace.full_name())
2.6 for name in namespace.get_active_attributes():
2.7 - self.importer.use_name(name, namespace.full_name())
2.8 + self.importer.use_specific_name(name, namespace.full_name())
2.9
2.10 def vacuum(self):
2.11
2.12 @@ -215,7 +215,6 @@
2.13 # via names which are never used.
2.14
2.15 if delete_all or not self.importer.uses_attribute(obj, name):
2.16 - print "Deleting", obj.full_name(), name
2.17 del obj[name]
2.18
2.19 # Delete any unambiguous attribute value. Such values can only