1.1 --- a/micropython/__init__.py Sun Sep 12 01:48:01 2010 +0200
1.2 +++ b/micropython/__init__.py Sun Sep 12 21:42:34 2010 +0200
1.3 @@ -450,7 +450,8 @@
1.4 self.name_references[from_name] = set()
1.5
1.6 attrnames = (name,)
1.7 - self.name_references[from_name].add((None, None, attrnames))
1.8 + usage = (attrnames,)
1.9 + self.name_references[from_name].add((None, None, usage))
1.10
1.11 def use_names(self, user, name, usage, from_name):
1.12
1.13 @@ -464,12 +465,7 @@
1.14 if not self.name_references.has_key(from_name):
1.15 self.name_references[from_name] = set()
1.16
1.17 - all_attrnames = set()
1.18 -
1.19 - for attrnames in usage:
1.20 - all_attrnames.update(attrnames)
1.21 -
1.22 - self.name_references[from_name].add((user, name, tuple(all_attrnames)))
1.23 + self.name_references[from_name].add((user, name, usage))
1.24
1.25 def use_specific_name(self, objname, attrname, from_name):
1.26
1.27 @@ -556,17 +552,22 @@
1.28 # Get name references and find possible objects which support such
1.29 # combinations of attribute names.
1.30
1.31 - for user, name, attrnames in self.name_references.get(from_name, []):
1.32 + for user, name, usage in self.name_references.get(from_name, []):
1.33
1.34 # Using all attribute names for a particular name, attempt to get
1.35 # specific object types.
1.36
1.37 - objtypes = objtable.all_possible_objects_plus_status(attrnames)
1.38 - if not objtypes:
1.39 - print "Warning: usage in %r finds no object supporting all attributes %r" % (from_name, attrnames)
1.40 - objtypes = objtable.any_possible_objects_plus_status(attrnames)
1.41 + all_objtypes = set()
1.42 +
1.43 + for attrnames in usage:
1.44 + objtypes = objtable.all_possible_objects_plus_status(attrnames)
1.45 if not objtypes:
1.46 - print "Warning: usage in %r finds no object supporting any attributes %r" % (from_name, attrnames)
1.47 + print "Warning: usage in %r finds no object supporting all attributes %r" % (from_name, attrnames)
1.48 + objtypes = objtable.any_possible_objects_plus_status(attrnames)
1.49 + if not objtypes:
1.50 + print "Warning: usage in %r finds no object supporting any attributes %r" % (from_name, attrnames)
1.51 +
1.52 + all_objtypes.update(objtypes)
1.53
1.54 # Record the object types for generating guards.
1.55
1.56 @@ -574,24 +575,25 @@
1.57 if not hasattr(user, "_attrtypes"):
1.58 user._attrtypes = {}
1.59
1.60 - user._attrtypes[name] = objtypes
1.61 + user._attrtypes[name] = all_objtypes
1.62
1.63 - # For each suggested object, consider each attribute given by the
1.64 - # names.
1.65 + # For each suggested object type, consider each attribute given by
1.66 + # the names.
1.67
1.68 - for objname, is_static in objtypes:
1.69 - for attrname in attrnames:
1.70 + for objname, is_static in all_objtypes:
1.71 + for attrnames in usage:
1.72 + for attrname in attrnames:
1.73
1.74 - # Visit attributes of objects known to be used.
1.75 + # Visit attributes of objects known to be used.
1.76
1.77 - if objname in self.attributes_used:
1.78 - self.use_attribute(objname, attrname)
1.79 - self._collect_attributes(objname + "." + attrname, objtable)
1.80 + if objname in self.attributes_used:
1.81 + self.use_attribute(objname, attrname)
1.82 + self._collect_attributes(objname + "." + attrname, objtable)
1.83
1.84 - # Record attributes of other objects for potential visiting.
1.85 + # Record attributes of other objects for potential visiting.
1.86
1.87 - else:
1.88 - self.add_attribute_to_visit(objname, attrname)
1.89 + else:
1.90 + self.add_attribute_to_visit(objname, attrname)
1.91
1.92 # Get specific name references and visit the referenced objects.
1.93
2.1 --- a/micropython/data.py Sun Sep 12 01:48:01 2010 +0200
2.2 +++ b/micropython/data.py Sun Sep 12 21:42:34 2010 +0200
2.3 @@ -383,7 +383,7 @@
2.4 # Then, tell the importer about the usage.
2.5
2.6 for name, usage in combined_usage.items():
2.7 - importer.use_names(user, name, usage, self.full_name())
2.8 + importer.use_names(user, name, tuple(usage), self.full_name())
2.9
2.10 def get_usage_from_contributors(self, node):
2.11
2.12 @@ -614,6 +614,7 @@
2.13 provided these cannot "escape" from the branch.
2.14 """
2.15
2.16 + self.attribute_users[-1] = {}
2.17 self.scope_usage[-1] = AbandonedBranchScope()
2.18
2.19 def _shelve_branch(self):
2.20 @@ -642,7 +643,6 @@
2.21 # Combine the attribute users. This ensures that a list of users
2.22 # affected by attribute usage is maintained for the current branch.
2.23
2.24 - users = self.attribute_users[-1]
2.25 new_users = {}
2.26
2.27 all_shelved_users = self.attribute_user_shelves.pop()
2.28 @@ -653,18 +653,14 @@
2.29 for shelved_users in all_shelved_users:
2.30 all_user_names.update(shelved_users.keys())
2.31
2.32 - # Copy all definitions from the branches for the names, maintaining
2.33 - # the existing users where a branch does not redefine a name.
2.34 + # Copy all definitions from the branches for the names.
2.35
2.36 for shelved_users in all_shelved_users:
2.37 for name in all_user_names:
2.38
2.39 if shelved_users.has_key(name):
2.40 nodes = shelved_users[name]
2.41 - else:
2.42 - nodes = users.get(name, set())
2.43 -
2.44 - if nodes:
2.45 +
2.46 if not new_users.has_key(name):
2.47 new_users[name] = set(nodes)
2.48 else:
3.1 --- a/micropython/table.py Sun Sep 12 01:48:01 2010 +0200
3.2 +++ b/micropython/table.py Sun Sep 12 21:42:34 2010 +0200
3.3 @@ -370,23 +370,27 @@
3.4
3.5 list_class = ObjectList
3.6
3.7 - def all_possible_objects_plus_status(self, names):
3.8 + def _objects_plus_status(self, names, fn):
3.9
3.10 """
3.11 - Return all objects supporting attributes with the given 'names' plus
3.12 - whether such attributes can be exclusively static or may belong to
3.13 - instances. A list of tuples of the form (object name, is_static) is thus
3.14 - returned.
3.15 + Return objects supporting attributes with the given 'names' plus whether
3.16 + such attributes can be exclusively static or may belong to instances. A
3.17 + list of tuples of the form (object name, is_static) is thus returned.
3.18 +
3.19 + The given 'fn' is employed to retrieve objects having the given 'names'.
3.20 """
3.21
3.22 possible = []
3.23 - for objname in self.all_possible_objects(names):
3.24 + for objname in fn(names):
3.25 attributes = self.table[objname]
3.26
3.27 is_static = 0
3.28 is_instance = 0
3.29
3.30 for name in names:
3.31 + if not attributes.has_key(name):
3.32 + continue
3.33 +
3.34 if attributes[name].is_static_attribute():
3.35 is_static = 1
3.36 else:
3.37 @@ -401,6 +405,28 @@
3.38
3.39 return possible
3.40
3.41 + def all_possible_objects_plus_status(self, names):
3.42 +
3.43 + """
3.44 + Return all objects supporting attributes with the given 'names' plus
3.45 + whether such attributes can be exclusively static or may belong to
3.46 + instances. A list of tuples of the form (object name, is_static) is thus
3.47 + returned.
3.48 + """
3.49 +
3.50 + return self._objects_plus_status(names, self.all_possible_objects)
3.51 +
3.52 + def any_possible_objects_plus_status(self, names):
3.53 +
3.54 + """
3.55 + Return any objects supporting attributes with the given 'names' plus
3.56 + whether such attributes can be exclusively static or may belong to
3.57 + instances. A list of tuples of the form (object name, is_static) is thus
3.58 + returned.
3.59 + """
3.60 +
3.61 + return self._objects_plus_status(names, self.any_possible_objects)
3.62 +
3.63 class ParameterTable(Table):
3.64
3.65 "A parameter table."