1.1 --- a/micropython/data.py Tue Jul 03 23:52:27 2012 +0200
1.2 +++ b/micropython/data.py Wed Jul 04 00:27:29 2012 +0200
1.3 @@ -2015,6 +2015,13 @@
1.4
1.5 self.all_objects = set()
1.6
1.7 + # A dictionary mapping functions to global names that cannot support
1.8 + # combined attribute usage observations because they may be modified in
1.9 + # the given functions during initialisation. Functions could be
1.10 + # eliminated from this dictionary if not thought to be used.
1.11 +
1.12 + self.modified_names = {}
1.13 +
1.14 # Keyword records.
1.15
1.16 self.keyword_names = set()
1.17 @@ -2055,6 +2062,83 @@
1.18
1.19 return dict(self)
1.20
1.21 + # Attribute usage methods that apply to module globals in certain
1.22 + # circumstances.
1.23 +
1.24 + def finalise_users(self, objtable):
1.25 +
1.26 + """
1.27 + Finalise attribute users, first revoking usage for any global names
1.28 + that might be modified during initialisation.
1.29 + """
1.30 +
1.31 + NamespaceDict.finalise_users(self, objtable)
1.32 +
1.33 + # Collect modified names and revoke attribute usage details for those
1.34 + # names.
1.35 +
1.36 + names = set()
1.37 + for function_names in self.modified_names.values():
1.38 + names.update(function_names)
1.39 +
1.40 + self.revoke_attribute_usage(names)
1.41 +
1.42 + def revoke_attribute_usage(self, names):
1.43 +
1.44 + """
1.45 + The definition of attribute users may be overridden or ignored if the
1.46 + module is found to be involved in circular imports where externally
1.47 + initiated modification occurs or if a function in the module may rebind
1.48 + globals, potentially during initialisation.
1.49 + """
1.50 +
1.51 + for user in self.all_attribute_users:
1.52 +
1.53 + # Remove user details for each name.
1.54 +
1.55 + for name in names:
1.56 +
1.57 + # Remove annotations derived from the combined observations.
1.58 +
1.59 + if user._attrtypes.has_key(name):
1.60 + del user._attrtypes[name]
1.61 + if user._attrspecifictypes.has_key(name):
1.62 + del user._attrspecifictypes[name]
1.63 + if user._attrmerged.has_key(name):
1.64 + del user._attrmerged[name]
1.65 +
1.66 + # Usage nodes that can no longer support combined observations
1.67 + # of attribute usage must instead support isolated observations.
1.68 +
1.69 + if not user._attrcombined.has_key(name):
1.70 + continue
1.71 +
1.72 + usage = user._attrcombined[name]
1.73 +
1.74 + # Usage is defined as a collection of attribute name
1.75 + # observations.
1.76 +
1.77 + for attrnames in usage:
1.78 +
1.79 + # Each attribute name may have values associated with it
1.80 + # where such values have been assigned to an attribute of
1.81 + # the given name.
1.82 +
1.83 + for attrname, attrvalues in usage.items():
1.84 + if attrvalues:
1.85 + for value in attrvalues:
1.86 + self.importer.use_name(attrname, self.full_name(), value)
1.87 + else:
1.88 + self.importer.use_name(attrname, self.full_name())
1.89 +
1.90 + del user._attrcombined[name]
1.91 +
1.92 + # Remove annotations on contributors.
1.93 +
1.94 + for contributor in user._attrcontributors:
1.95 + if contributor._attrusers.has_key(name):
1.96 + del contributor._attrusers[name]
1.97 +
1.98 # Pre-made instances.
1.99
1.100 type_class = TypeClass("type") # details to be filled in later