1.1 --- a/micropython/data.py Sat Jul 14 17:42:42 2012 +0200
1.2 +++ b/micropython/data.py Sat Jul 14 20:38:19 2012 +0200
1.3 @@ -52,6 +52,7 @@
1.4 where each such object is defined.
1.5 """
1.6
1.7 +from compiler.ast import AttributeUser
1.8 from micropython.program import ReplaceableContext, PlaceholderContext
1.9 from micropython.basicdata import *
1.10 from micropython.errors import *
1.11 @@ -424,7 +425,7 @@
1.12 program unit.
1.13 """
1.14
1.15 - if not hasattr(node, "_attrspecifictypes"):
1.16 + if node._attrspecifictypes is None:
1.17 merged = {}
1.18
1.19 # Get the combined usage information from the user definitions.
1.20 @@ -478,9 +479,11 @@
1.21
1.22 unfinished = {}
1.23
1.24 - if not hasattr(node, "_attrcombined"):
1.25 - node._attrcombined = None
1.26 - node._attrcontributors = None
1.27 + # Process any unprocessed contributors, indicating the unfinished state
1.28 + # of the associated data.
1.29 +
1.30 + if node._attrcombined is None:
1.31 + node._attrcombined = Unset
1.32
1.33 for contributor in node._attrbranches:
1.34
1.35 @@ -494,7 +497,7 @@
1.36 # occurred and this node will need to have its usage
1.37 # recalculated later for the unfinished contributor.
1.38
1.39 - if contributor._attrcombined is None:
1.40 + if contributor._attrcombined is Unset:
1.41 if not unfinished.has_key(contributor):
1.42 unfinished[contributor] = []
1.43 unfinished[contributor].append(node)
1.44 @@ -543,7 +546,7 @@
1.45
1.46 for contributor in node._attrbranches:
1.47 usage = contributor._attrcombined
1.48 - if usage is not None:
1.49 + if usage is not Unset:
1.50 all_contributions.append(usage)
1.51
1.52 all_contributors.add(contributor)
1.53 @@ -673,25 +676,25 @@
1.54
1.55 # Attribute usage for names.
1.56
1.57 - if not hasattr(node, "_attrnames"):
1.58 + if node._attrnames is None:
1.59 node._attrnames = {}
1.60 node._attrmerged = {}
1.61
1.62 # Branches contributing usage to this node.
1.63
1.64 - if not hasattr(node, "_attrbranches"):
1.65 + if node._attrbranches is None:
1.66 node._attrbranches = []
1.67
1.68 # Definitions receiving usage from this node.
1.69
1.70 - if not hasattr(node, "_attrdefs"):
1.71 + if node._attrdefs is None:
1.72 node._attrdefs = []
1.73
1.74 def _define_attribute_accessor(self, name, attrname, node, value):
1.75
1.76 # NOTE: Revisiting of nodes may occur for loops.
1.77
1.78 - if not hasattr(node, "_attrusers"):
1.79 + if node._attrusers is None:
1.80 node._attrusers = set()
1.81
1.82 node._attrusers.update(self.use_attribute(name, attrname, value))
1.83 @@ -1021,7 +1024,7 @@
1.84 def __init__(self, scopes):
1.85 self.scopes = scopes
1.86
1.87 -class NullBranch:
1.88 +class NullBranch(AttributeUser):
1.89
1.90 "A class representing an attribute user for a non-existent branch."
1.91
1.92 @@ -2209,4 +2212,13 @@
1.93 def __repr__(self):
1.94 return "AtLeast(%r)" % self.count
1.95
1.96 +class UnsetType:
1.97 +
1.98 + "A None-like value."
1.99 +
1.100 + def __nonzero__(self):
1.101 + return False
1.102 +
1.103 +Unset = UnsetType()
1.104 +
1.105 # vim: tabstop=4 expandtab shiftwidth=4