1.1 --- a/micropython/data.py Mon Feb 08 01:05:23 2010 +0100
1.2 +++ b/micropython/data.py Tue Feb 09 00:50:46 2010 +0100
1.3 @@ -127,6 +127,7 @@
1.4 self.attribute_shelves = [] # stack of unmerged definitions
1.5 self.attribute_users = [{}] # stack of assignments
1.6 self.abandon_attributes = 0 # used when a block will never contribute
1.7 + self.abandoned_shelves = []
1.8 self.all_attributes_used = []
1.9
1.10 # Attribute/name definition and access.
1.11 @@ -356,6 +357,7 @@
1.12
1.13 def _new_branchpoint(self):
1.14 self.attribute_shelves.append([])
1.15 + self.abandoned_shelves.append([])
1.16
1.17 def _new_branch(self):
1.18 d = {}
1.19 @@ -369,7 +371,10 @@
1.20
1.21 def _shelve_branch(self):
1.22 if not self.abandon_attributes:
1.23 - self.attribute_shelves[-1].append(self.attributes_used.pop())
1.24 + collector = self.attribute_shelves[-1]
1.25 + else:
1.26 + collector = self.abandoned_shelves[-1]
1.27 + collector.append(self.attributes_used.pop())
1.28 self.attribute_users.pop()
1.29 self.abandon_attributes = 0
1.30
1.31 @@ -380,32 +385,35 @@
1.32 # intersection of their contributions for each name.
1.33
1.34 shelved_defs = self.attribute_shelves.pop()
1.35 + abandoned_defs = self.abandoned_shelves.pop()
1.36
1.37 # Where branches contribute attribute usage observations, process these
1.38 # as described above. Otherwise, preserve the previous observations.
1.39
1.40 - if not shelved_defs:
1.41 - return
1.42 + if shelved_defs:
1.43 + defs = dict(shelved_defs[0])
1.44
1.45 - defs = dict(shelved_defs[0])
1.46 + for next_defs in shelved_defs[1:]:
1.47 + for name, attrnames in next_defs.items():
1.48 + if defs.has_key(name):
1.49 + defs[name] = defs[name].intersection(attrnames)
1.50
1.51 - for next_defs in shelved_defs[1:]:
1.52 - for name, attrnames in next_defs.items():
1.53 - if defs.has_key(name):
1.54 - defs[name] = defs[name].intersection(attrnames)
1.55 + # Intersect the contributions with the previous state for each name.
1.56
1.57 - # Intersect the contributions with the previous state for each name.
1.58 -
1.59 - for name, attrnames in defs.items():
1.60 - if active.has_key(name):
1.61 - active[name].intersection_update(attrnames)
1.62 - else:
1.63 - active[name] = attrnames
1.64 + for name, attrnames in defs.items():
1.65 + if active.has_key(name):
1.66 + active[name].intersection_update(attrnames)
1.67 + else:
1.68 + active[name] = attrnames
1.69
1.70 # Where each shelved set of definitions is a superset of the eventual
1.71 # definitions for a name, record these specialised sets of usage.
1.72
1.73 - for defs in shelved_defs:
1.74 + # Note that abandoned definitions contribute to sets of usage, since
1.75 + # although they do not contribute to further usage in a namespace, any
1.76 + # attribute combinations do indicate function usage.
1.77 +
1.78 + for defs in shelved_defs + abandoned_defs:
1.79 for name, attrnames in defs.items():
1.80
1.81 # Check for isolated pockets of attribute usage as well as more