1.1 --- a/micropython/data.py Sat Sep 11 21:45:24 2010 +0200
1.2 +++ b/micropython/data.py Sun Sep 12 01:48:01 2010 +0200
1.3 @@ -364,40 +364,39 @@
1.4 importer = module and module.importer
1.5
1.6 if importer is not None:
1.7 - for names in self.get_all_attribute_usage():
1.8 - importer.use_names(names, self.full_name())
1.9 -
1.10 - def get_all_attribute_usage(self):
1.11 -
1.12 - """
1.13 - Return a set of all usage tuples for attributes used with the different
1.14 - local names.
1.15 - """
1.16 -
1.17 - usage = set()
1.18 - for user in self.all_attribute_users:
1.19 -
1.20 - # First, visit the contributors and combine their usage with the
1.21 - # usage for each user.
1.22 -
1.23 - user._attrcombined = combined_usage = self.get_usage_from_contributors(user)
1.24 -
1.25 - for name, all_usage in combined_usage.items():
1.26 - for attrnames in all_usage:
1.27 - usage.add(tuple(attrnames))
1.28 -
1.29 - return usage
1.30 +
1.31 + # Visit each user and examine the attribute usage for each name.
1.32 +
1.33 + for user in self.all_attribute_users:
1.34 +
1.35 + # First, visit the contributors and combine their attribute
1.36 + # usage with the usage recorded directly on the user.
1.37 +
1.38 + contributors, combined_usage = self.get_usage_from_contributors(user)
1.39 + user._attrcombined = combined_usage
1.40 +
1.41 + # Record the defining user on each contributor.
1.42 +
1.43 + for contributor in contributors:
1.44 + contributor._attrdefs.append(user)
1.45 +
1.46 + # Then, tell the importer about the usage.
1.47 +
1.48 + for name, usage in combined_usage.items():
1.49 + importer.use_names(user, name, usage, self.full_name())
1.50
1.51 def get_usage_from_contributors(self, node):
1.52
1.53 """
1.54 Obtain usage information from the given 'node', combined with usage
1.55 - details from its contributors, returning a dictionary mapping names to
1.56 - lists of usage possibilities.
1.57 + details from its contributors, returning a tuple containing a set of all
1.58 + contributors employed along with a dictionary mapping names to lists of
1.59 + usage possibilities (each a collection of attribute names).
1.60 """
1.61
1.62 usage = {}
1.63 contributor_usage = {}
1.64 + all_contributors = set()
1.65
1.66 # Visit each contributor, gathering usage for each name.
1.67
1.68 @@ -407,11 +406,18 @@
1.69 # This gathers usage for each name such as {(a, b), (c, d)} and
1.70 # {(a, b), (e, f)} into a single set {(a, b), (c, d), (e, f)}.
1.71
1.72 - for name, all_usage in self.get_usage_from_contributors(contributor).items():
1.73 + contributors, contributed_usage = self.get_usage_from_contributors(contributor)
1.74 +
1.75 + for name, all_usage in contributed_usage.items():
1.76 if not contributor_usage.has_key(name):
1.77 contributor_usage[name] = set()
1.78 contributor_usage[name].update(all_usage)
1.79
1.80 + # Record all contributors.
1.81 +
1.82 + all_contributors.add(contributor)
1.83 + all_contributors.update(contributors)
1.84 +
1.85 # Then get the resulting usage.
1.86
1.87 contributed_names = contributor_usage.keys()
1.88 @@ -443,7 +449,7 @@
1.89 if name not in contributed_names:
1.90 usage[name] = set([tuple(current_usage[name])])
1.91
1.92 - return usage
1.93 + return all_contributors, usage
1.94
1.95 def use_attribute(self, name, attrname):
1.96
1.97 @@ -532,12 +538,22 @@
1.98 node._attrnames[name] = set()
1.99
1.100 def _init_attribute_user(self, node):
1.101 +
1.102 + # Attribute usage for names.
1.103 +
1.104 if not hasattr(node, "_attrnames"):
1.105 node._attrnames = {}
1.106
1.107 + # Branches contributing usage to this node.
1.108 +
1.109 if not hasattr(node, "_attrbranches"):
1.110 node._attrbranches = []
1.111
1.112 + # Definitions receiving usage from this node.
1.113 +
1.114 + if not hasattr(node, "_attrdefs"):
1.115 + node._attrdefs = []
1.116 +
1.117 # Branch management methods.
1.118
1.119 def _new_branchpoint(self):