1.1 --- a/micropython/__init__.py Mon Jun 14 01:46:42 2010 +0200
1.2 +++ b/micropython/__init__.py Tue Jun 15 00:50:51 2010 +0200
1.3 @@ -366,7 +366,7 @@
1.4
1.5 # Attribute usage.
1.6
1.7 - self.attributes_used = {}
1.8 + self.attributes_used = set()
1.9 self.name_references = {}
1.10 self.specific_name_references = {}
1.11 self.attribute_users_visited = set()
1.12 @@ -466,14 +466,14 @@
1.13
1.14 # Name accounting products.
1.15
1.16 - def uses_attribute(self, obj, name):
1.17 + def uses_attribute(self, objname, name):
1.18
1.19 """
1.20 - Return whether the attribute of object 'obj' having the given 'name' is
1.21 - used as an attribute in the program.
1.22 + Return whether the attribute of the object with the given 'objname'
1.23 + having the given 'name' is used as an attribute in the program.
1.24 """
1.25
1.26 - return name in self.attributes_used.get(obj.full_name(), [])
1.27 + return (objname + "." + name) in self.attributes_used
1.28
1.29 def use_attribute(self, objname, name):
1.30
1.31 @@ -482,9 +482,7 @@
1.32 the given 'name' is used.
1.33 """
1.34
1.35 - if not self.attributes_used.has_key(objname):
1.36 - self.attributes_used[objname] = set()
1.37 - self.attributes_used[objname].add(name)
1.38 + self.attributes_used.add(objname + "." + name)
1.39
1.40 def collect_attributes(self, objtable):
1.41
2.1 --- a/micropython/data.py Mon Jun 14 01:46:42 2010 +0200
2.2 +++ b/micropython/data.py Tue Jun 15 00:50:51 2010 +0200
2.3 @@ -160,7 +160,7 @@
2.4
2.5 # Globals.
2.6
2.7 - elif module is not None and module.has_key(name):
2.8 + elif module is not None and module is not self and module.has_key(name):
2.9 return module[name], "global", module.full_name()
2.10
2.11 # Builtins.
2.12 @@ -319,6 +319,17 @@
2.13
2.14 # Attribute usage methods.
2.15
2.16 + def finalise_attribute_usage(self):
2.17 +
2.18 + "Propagate attribute usage for the namespace to the importer."
2.19 +
2.20 + module = self.module
2.21 + importer = module and module.importer
2.22 +
2.23 + if importer is not None:
2.24 + for names in self.get_all_attribute_usage():
2.25 + importer.use_names(names, self.full_name())
2.26 +
2.27 def get_all_attribute_usage(self):
2.28
2.29 """
2.30 @@ -570,7 +581,7 @@
2.31 if not new_scope_usage.has_key(name):
2.32 new_scope_usage[name] = scope
2.33 elif new_scope_usage[name] != scope:
2.34 - raise InspectError("Scope conflict for %r." % name)
2.35 + raise InspectError("Scope conflict for %r: defined as both %s and %s." % (name, new_scope_usage[name], scope))
2.36
2.37 # Scope usage methods.
2.38
3.1 --- a/micropython/inspect.py Mon Jun 14 01:46:42 2010 +0200
3.2 +++ b/micropython/inspect.py Tue Jun 15 00:50:51 2010 +0200
3.3 @@ -146,13 +146,13 @@
3.4 for node, namespaces in self.functions:
3.5 self.process_globals(node)
3.6
3.7 - self.finalise_namespace(self)
3.8 + self.finalise_attribute_usage()
3.9
3.10 # Then, visit each function, recording other names.
3.11
3.12 for node, namespaces in self.functions:
3.13 self._visitFunctionBody(node, namespaces)
3.14 - self.finalise_namespace(namespaces[-1])
3.15 + namespaces[-1].finalise_attribute_usage()
3.16
3.17 # Add references to other modules declared using the __all__ global.
3.18
3.19 @@ -179,13 +179,6 @@
3.20 else:
3.21 self.process_globals(n)
3.22
3.23 - def finalise_namespace(self, namespace):
3.24 -
3.25 - "Finalise the given 'namespace'."
3.26 -
3.27 - for names in namespace.get_all_attribute_usage():
3.28 - self.importer.use_names(names, namespace.full_name())
3.29 -
3.30 def vacuum(self):
3.31
3.32 """
3.33 @@ -211,7 +204,7 @@
3.34 # Only consider deleting entire unused objects or things accessible
3.35 # via names which are never used.
3.36
3.37 - if delete_all or not self.importer.uses_attribute(obj, name):
3.38 + if delete_all or not self.importer.uses_attribute(obj.full_name(), name):
3.39 del obj[name]
3.40
3.41 # Delete any unambiguous attribute value. Such values can only
3.42 @@ -645,7 +638,7 @@
3.43
3.44 self.namespaces.append(cls)
3.45 self.dispatch(node.code)
3.46 - self.finalise_namespace(cls)
3.47 + cls.finalise_attribute_usage()
3.48 self.namespaces.pop()
3.49
3.50 return cls
4.1 --- a/test_all.py Mon Jun 14 01:46:42 2010 +0200
4.2 +++ b/test_all.py Tue Jun 15 00:50:51 2010 +0200
4.3 @@ -39,6 +39,7 @@
4.4 print repr(exc)
4.5 if "-tb" in args:
4.6 raise
4.7 + results.append((filename, 0))
4.8
4.9 else:
4.10 rm = rsvp.machine(p)