1.1 --- a/micropython/inspect.py Thu May 17 23:37:05 2012 +0200
1.2 +++ b/micropython/inspect.py Fri May 18 01:21:20 2012 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Inspect source files, obtaining details of classes and attributes.
1.6
1.7 -Copyright (C) 2007, 2008, 2009, 2010, 2011 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -1063,12 +1063,14 @@
1.13 return self.OP(node)
1.14
1.15 def visitListComp(self, node):
1.16 - for qual in node.quals:
1.17 - self.dispatch(qual)
1.18 - self.dispatch(node.expr)
1.19 +
1.20 + # Note that explicit dispatch is performed.
1.21 +
1.22 + if node.quals:
1.23 + self.visitListCompFor(node.quals[0], node.quals[1:], node.expr)
1.24 return make_instance()
1.25
1.26 - def visitListCompFor(self, node):
1.27 + def visitListCompFor(self, node, following_quals, expr):
1.28 self.new_branchpoint()
1.29
1.30 # Declare names which will be used by generated code.
1.31 @@ -1091,15 +1093,45 @@
1.32
1.33 self.new_branch(node)
1.34
1.35 - for if_ in node.ifs:
1.36 - self.dispatch(if_)
1.37 + # Note that explicit dispatch is performed.
1.38 +
1.39 + if node.ifs:
1.40 + self.visitListCompIf(node.ifs[0], node.ifs[1:], following_quals, expr)
1.41 + elif following_quals:
1.42 + self.visitListCompFor(following_quals[0], following_quals[1:], expr)
1.43 + else:
1.44 + self.dispatch(expr)
1.45
1.46 self.shelve_branch()
1.47 self.in_loop = in_loop
1.48
1.49 self.merge_branches()
1.50
1.51 - visitListCompIf = TEST_NOP
1.52 + def visitListCompIf(self, node, following_ifs, following_quals, expr):
1.53 + self.use_name("__bool__", node)
1.54 + self.new_branchpoint()
1.55 +
1.56 + # Propagate attribute usage to branches.
1.57 +
1.58 + self.dispatch(node.test)
1.59 +
1.60 + # Note that explicit dispatch is performed.
1.61 +
1.62 + if following_ifs:
1.63 + self.visitListCompIf(following_ifs[0], following_ifs[1:], following_quals, expr)
1.64 + elif following_quals:
1.65 + self.visitListCompFor(following_quals[0], following_quals[1:], expr)
1.66 + else:
1.67 + self.new_branch(expr)
1.68 + self.dispatch(expr)
1.69 + self.shelve_branch()
1.70 +
1.71 + # Maintain a branch for the else clause.
1.72 +
1.73 + self.new_branch(NullBranch())
1.74 + self.shelve_branch()
1.75 +
1.76 + self.merge_branches()
1.77
1.78 visitMod = _visitBinary
1.79