# HG changeset patch # User Paul Boddie # Date 1314740284 -7200 # Node ID e30d36f517ed7fe6129ac516b14b2010afbcf4da # Parent 0c488107ea06f5fae14c7e24a566983b17e9e5e3 Added recording of __bool__ method usage during inspection instead of __bool__ being in the list of names always used in programs. diff -r 0c488107ea06 -r e30d36f517ed micropython/__init__.py --- a/micropython/__init__.py Tue Aug 30 23:36:08 2011 +0200 +++ b/micropython/__init__.py Tue Aug 30 23:38:04 2011 +0200 @@ -349,7 +349,7 @@ } names_always_used = [ - "bool", "__call__", "__bool__" + "bool", "__call__" ] def __init__(self, path=None, verbose=0, optimisations=None): diff -r 0c488107ea06 -r e30d36f517ed micropython/ast.py --- a/micropython/ast.py Tue Aug 30 23:36:08 2011 +0200 +++ b/micropython/ast.py Tue Aug 30 23:38:04 2011 +0200 @@ -790,6 +790,8 @@ self.set_block(exit_block) + def visitIfExp(self, node): raise TranslationNotImplementedError("IfExp") + def visitPass(self, node): pass def visitPrint(self, node): diff -r 0c488107ea06 -r e30d36f517ed micropython/inspect.py --- a/micropython/inspect.py Tue Aug 30 23:36:08 2011 +0200 +++ b/micropython/inspect.py Tue Aug 30 23:38:04 2011 +0200 @@ -424,11 +424,19 @@ self.NOP(node) self.abandon_branch() + def TEST_NOP(self, node): + self.use_name("__bool__", node) + self.NOP(node) + def OP(self, node): for n in node.getChildNodes(): self.dispatch(n) return make_instance() + def TEST_OP(self, node): + self.use_name("__bool__", node) + return self.OP(node) + # Generic support for classes of operations. def _ensureOperators(self): @@ -602,7 +610,7 @@ visitAdd = _visitBinary - visitAnd = OP + visitAnd = TEST_OP visitAssert = NOP @@ -787,6 +795,8 @@ # Accounting. # NOTE: Replicates some code in micropython.ast.visitCompare. + self.use_name("__bool__", node) + this_node = node for op in node.ops: @@ -936,6 +946,7 @@ # The name is recorded in an earlier process. def visitIf(self, node): + self.use_name("__bool__", node) self.new_branchpoint() # Propagate attribute usage to branches. @@ -957,6 +968,7 @@ self.merge_branches() def visitIfExp(self, node): + self.use_name("__bool__", node) self.new_branchpoint() # Propagate attribute usage to branches. @@ -1038,7 +1050,7 @@ self.merge_branches() - visitListCompIf = NOP + visitListCompIf = TEST_NOP visitMod = _visitBinary @@ -1054,9 +1066,9 @@ def visitName(self, node): return self.get_namespace().get_using_node(node.name, node) or make_instance() - visitNot = OP + visitNot = TEST_OP - visitOr = OP + visitOr = TEST_OP visitPass = NOP @@ -1125,6 +1137,7 @@ visitUnarySub = _visitUnary def visitWhile(self, node): + self.use_name("__bool__", node) self.new_branchpoint(node) # Propagate attribute usage to branches.