1.1 --- a/micropython/data.py Mon Nov 16 00:34:47 2009 +0100
1.2 +++ b/micropython/data.py Sun Nov 22 04:15:05 2009 +0100
1.3 @@ -121,10 +121,12 @@
1.4
1.5 # Attributes accessed on objects, potentially narrowing their types.
1.6 # Specific namespaces should define known names during initialisation.
1.7 + # For example, functions can define names belonging to parameters.
1.8
1.9 self.attributes_used = [{}] # stack of usage
1.10 self.attribute_shelves = [] # stack of unmerged definitions
1.11 self.attribute_users = [{}] # stack of assignments
1.12 + self.all_attributes_used = []
1.13
1.14 # Attribute/name definition and access.
1.15
1.16 @@ -278,10 +280,46 @@
1.17
1.18 # Attribute usage methods.
1.19
1.20 - def _use_attribute(self, attr, attrname):
1.21 - name = attr.name
1.22 + def get_active_attributes(self):
1.23 +
1.24 + """
1.25 + Return attributes on this object that are actually used.
1.26 + """
1.27 +
1.28 + return self.attributes_used[-1].get(None, [])
1.29 +
1.30 + def get_all_attribute_usage(self):
1.31 +
1.32 + """
1.33 + Return a set of all usage tuples for attributes used with the different
1.34 + local names.
1.35 + """
1.36 +
1.37 + usage = set()
1.38 + for names in self.all_attributes_used:
1.39 + usage.add(tuple(names))
1.40 + return usage
1.41 +
1.42 + # These shadow various methods in the InspectedModule class, and provide
1.43 + # implementations generally.
1.44 +
1.45 + def _use_attribute(self, name, attrname):
1.46 +
1.47 + """
1.48 + Indicate the use on the given 'name' in this namespace of an attribute
1.49 + with the given 'attrname'.
1.50 + """
1.51 +
1.52 defs = self.attributes_used[-1]
1.53 users = self.attribute_users[-1]
1.54 +
1.55 + # Permit the unforeseen definition of names since some names are likely
1.56 + # to be defined by things (such as class definitions) which will not
1.57 + # require access optimisations, but which still need to be monitored.
1.58 +
1.59 + if not defs.has_key(name):
1.60 + defs[name] = set()
1.61 +
1.62 defs[name].add(attrname)
1.63 return defs[name]
1.64
1.65 @@ -296,14 +334,24 @@
1.66 self._define_attribute_user_for_name(node, name)
1.67
1.68 def _define_attribute_user_for_name(self, node, name):
1.69 +
1.70 + "Define 'node' as the user of attributes for the given 'name'."
1.71 +
1.72 defs = self.attributes_used[-1]
1.73 users = self.attribute_users[-1]
1.74 users[name] = node
1.75 defs[name] = set()
1.76 +
1.77 + # Record the attribute combinations for the name.
1.78 +
1.79 if not hasattr(node, "_attrnames"):
1.80 node._attrnames = {}
1.81 node._attrnames[name] = defs[name]
1.82
1.83 + # Remember all attribute combinations.
1.84 +
1.85 + self.all_attributes_used.append(defs[name])
1.86 +
1.87 def _reset_all_attributes(self):
1.88 self.attributes_used[-1] = {}
1.89 self.attribute_users[-1] = {}