# HG changeset patch # User Paul Boddie # Date 1258912492 -3600 # Node ID f9896e300492670590e278a24ad9449d23aace25 # Parent 50008931d30405cf731057cd7867e600ec103d0f Introduced specific name usage so that attributes of classes and modules can be registered properly and not omitted. diff -r 50008931d304 -r f9896e300492 micropython/__init__.py --- a/micropython/__init__.py Sun Nov 22 04:15:05 2009 +0100 +++ b/micropython/__init__.py Sun Nov 22 18:54:52 2009 +0100 @@ -369,8 +369,9 @@ # Attribute usage. - self.attributes_used = None + self.attributes_used = {} self.name_references = {} + self.specific_name_references = {} # Status information. @@ -446,6 +447,19 @@ self.name_references[from_name] = set() self.name_references[from_name].add(names) + def use_specific_name(self, specific_name, from_name): + + """ + Register the given 'specific_name' for an object as being used in the + program from within an object with the specified 'from_name'. + """ + + if not self.specific_name_references.has_key(from_name): + self.specific_name_references[from_name] = set() + self.specific_name_references[from_name].add(specific_name) + + # Name accounting products. + def uses_attribute(self, obj, name): """ @@ -470,20 +484,17 @@ "Collect attribute references for the entire program." - if self.attributes_used is None: - - # Include names which may not be explicitly used in programs. - # NOTE: Potentially declare these when inspecting. + # Include names which may not be explicitly used in programs. + # NOTE: Potentially declare these when inspecting. - self.attributes_used = {} - for name in self.names_always_used: - for objname in objtable.all_possible_objects([name]): - self.use_attribute(objname, name) + for name in self.names_always_used: + for objname in objtable.all_possible_objects([name]): + self.use_attribute(objname, name) - # Start with the "root" modules, finding referenced objects. + # Start with the "root" modules, finding referenced objects. - self._collect_attributes("__builtins__", objtable) - self._collect_attributes("__main__", objtable) + self._collect_attributes("__builtins__", objtable) + self._collect_attributes("__main__", objtable) def _collect_attributes(self, from_name, objtable): @@ -495,12 +506,21 @@ if self.attributes_used.has_key(from_name): return + # Get name references and find possible objects which support such + # combinations of attribute names. + for names in self.name_references.get(from_name, []): for objname in objtable.all_possible_objects(names): for name in names: self.use_attribute(objname, name) self._collect_attributes(objname + "." + name, objtable) + # Get specific name references and visit the referenced objects. + + for name in self.specific_name_references.get(from_name, []): + self.use_attribute(from_name, name) + self._collect_attributes(from_name + "." + name, objtable) + # Constant accounting. def init_predefined_constants(self): diff -r 50008931d304 -r f9896e300492 micropython/inspect.py --- a/micropython/inspect.py Sun Nov 22 04:15:05 2009 +0100 +++ b/micropython/inspect.py Sun Nov 22 18:54:52 2009 +0100 @@ -187,7 +187,7 @@ for names in namespace.get_all_attribute_usage(): self.importer.use_names(names, namespace.full_name()) for name in namespace.get_active_attributes(): - self.importer.use_name(name, namespace.full_name()) + self.importer.use_specific_name(name, namespace.full_name()) def vacuum(self): @@ -215,7 +215,6 @@ # via names which are never used. if delete_all or not self.importer.uses_attribute(obj, name): - print "Deleting", obj.full_name(), name del obj[name] # Delete any unambiguous attribute value. Such values can only