# HG changeset patch # User Paul Boddie # Date 1265673046 -3600 # Node ID 639aa6eb751c2be172cdf0af5dc13381555813fb # Parent feccb2b0967ea6834fe46d44397dfb282f66a600 Introduced abandoned shelves of attribute usage which are used to provide usage patterns even though they do not contribute to further observations in their own namespaces. This is required because such patterns help discover active functions in a program. diff -r feccb2b0967e -r 639aa6eb751c micropython/data.py --- a/micropython/data.py Mon Feb 08 01:05:23 2010 +0100 +++ b/micropython/data.py Tue Feb 09 00:50:46 2010 +0100 @@ -127,6 +127,7 @@ self.attribute_shelves = [] # stack of unmerged definitions self.attribute_users = [{}] # stack of assignments self.abandon_attributes = 0 # used when a block will never contribute + self.abandoned_shelves = [] self.all_attributes_used = [] # Attribute/name definition and access. @@ -356,6 +357,7 @@ def _new_branchpoint(self): self.attribute_shelves.append([]) + self.abandoned_shelves.append([]) def _new_branch(self): d = {} @@ -369,7 +371,10 @@ def _shelve_branch(self): if not self.abandon_attributes: - self.attribute_shelves[-1].append(self.attributes_used.pop()) + collector = self.attribute_shelves[-1] + else: + collector = self.abandoned_shelves[-1] + collector.append(self.attributes_used.pop()) self.attribute_users.pop() self.abandon_attributes = 0 @@ -380,32 +385,35 @@ # intersection of their contributions for each name. shelved_defs = self.attribute_shelves.pop() + abandoned_defs = self.abandoned_shelves.pop() # Where branches contribute attribute usage observations, process these # as described above. Otherwise, preserve the previous observations. - if not shelved_defs: - return + if shelved_defs: + defs = dict(shelved_defs[0]) - defs = dict(shelved_defs[0]) + for next_defs in shelved_defs[1:]: + for name, attrnames in next_defs.items(): + if defs.has_key(name): + defs[name] = defs[name].intersection(attrnames) - for next_defs in shelved_defs[1:]: - for name, attrnames in next_defs.items(): - if defs.has_key(name): - defs[name] = defs[name].intersection(attrnames) + # Intersect the contributions with the previous state for each name. - # Intersect the contributions with the previous state for each name. - - for name, attrnames in defs.items(): - if active.has_key(name): - active[name].intersection_update(attrnames) - else: - active[name] = attrnames + for name, attrnames in defs.items(): + if active.has_key(name): + active[name].intersection_update(attrnames) + else: + active[name] = attrnames # Where each shelved set of definitions is a superset of the eventual # definitions for a name, record these specialised sets of usage. - for defs in shelved_defs: + # Note that abandoned definitions contribute to sets of usage, since + # although they do not contribute to further usage in a namespace, any + # attribute combinations do indicate function usage. + + for defs in shelved_defs + abandoned_defs: for name, attrnames in defs.items(): # Check for isolated pockets of attribute usage as well as more