1.1 --- a/micropython/inspect.py Tue Oct 27 00:23:28 2009 +0100
1.2 +++ b/micropython/inspect.py Mon Nov 02 01:06:38 2009 +0100
1.3 @@ -314,8 +314,11 @@
1.4 def reset_attributes(self, name):
1.5 self.get_namespace()._reset_attributes(name)
1.6
1.7 + def reset_all_attributes(self):
1.8 + self.get_namespace()._reset_all_attributes()
1.9 +
1.10 def use_attribute(self, attr, attrname):
1.11 - self.get_namespace()._use_attribute(attr, attrname)
1.12 + return self.get_namespace()._use_attribute(attr, attrname)
1.13
1.14 # Visitor methods.
1.15
1.16 @@ -449,7 +452,7 @@
1.17 # Note usage of the attribute.
1.18
1.19 if expr.parent is self.get_namespace():
1.20 - self.use_attribute(expr, node.attrname)
1.21 + node._attrnames = self.use_attribute(expr, node.attrname)
1.22
1.23 return None
1.24
1.25 @@ -510,7 +513,8 @@
1.26
1.27 visitBitxor = _visitBinary
1.28
1.29 - visitBreak = NOP
1.30 + def visitBreak(self, node):
1.31 + self.reset_all_attributes()
1.32
1.33 visitCallFunc = OP
1.34
1.35 @@ -589,7 +593,8 @@
1.36 self.use_name(self.importer.get_constant_type_name(node.value))
1.37 return self.importer.make_constant(node.value)
1.38
1.39 - visitContinue = NOP
1.40 + def visitContinue(self, node):
1.41 + self.reset_all_attributes()
1.42
1.43 visitDecorators = NOP
1.44
1.45 @@ -619,6 +624,7 @@
1.46 self.dispatch(node.list)
1.47
1.48 # Enter the loop.
1.49 + # Propagate attribute usage to branches.
1.50
1.51 self.in_loop = 1
1.52 self.new_branch()
1.53 @@ -626,10 +632,13 @@
1.54 self.shelve_branch()
1.55 self.in_loop = 0
1.56
1.57 + # Maintain a branch for the else clause or the current retained usage
1.58 + # where execution avoids the conditional clauses.
1.59 +
1.60 + self.new_branch()
1.61 if node.else_ is not None:
1.62 - self.new_branch()
1.63 self.dispatch(node.else_)
1.64 - self.shelve_branch()
1.65 + self.shelve_branch()
1.66
1.67 self.merge_branches()
1.68 return None
1.69 @@ -691,7 +700,7 @@
1.70 # Note usage of the attribute.
1.71
1.72 if expr.parent is self.get_namespace():
1.73 - self.use_attribute(expr, attrname)
1.74 + node._attrnames = self.use_attribute(expr, attrname)
1.75
1.76 elif self.builtins is not None:
1.77 attr = self.builtins.get(attrname)
1.78 @@ -716,6 +725,8 @@
1.79 def visitIf(self, node):
1.80 self.new_branchpoint()
1.81
1.82 + # Propagate attribute usage to branches.
1.83 +
1.84 for test, body in node.tests:
1.85 self.dispatch(test)
1.86
1.87 @@ -723,10 +734,13 @@
1.88 self.dispatch(body)
1.89 self.shelve_branch()
1.90
1.91 + # Maintain a branch for the else clause or the current retained usage
1.92 + # where execution avoids the conditional clauses.
1.93 +
1.94 + self.new_branch()
1.95 if node.else_ is not None:
1.96 - self.new_branch()
1.97 self.dispatch(node.else_)
1.98 - self.shelve_branch()
1.99 + self.shelve_branch()
1.100
1.101 self.merge_branches()
1.102 return None
1.103 @@ -863,6 +877,8 @@
1.104 def visitWhile(self, node):
1.105 self.new_branchpoint()
1.106
1.107 + # Propagate attribute usage to branches.
1.108 +
1.109 self.in_loop = 1
1.110 self.dispatch(node.test)
1.111 self.new_branch()
1.112 @@ -870,10 +886,13 @@
1.113 self.shelve_branch()
1.114 self.in_loop = 0
1.115
1.116 + # Maintain a branch for the else clause or the current retained usage
1.117 + # where execution avoids the conditional clauses.
1.118 +
1.119 + self.new_branch()
1.120 if node.else_ is not None:
1.121 - self.new_branch()
1.122 self.dispatch(node.else_)
1.123 - self.shelve_branch()
1.124 + self.shelve_branch()
1.125
1.126 self.merge_branches()
1.127 return None