1.1 --- a/common.py Thu Sep 08 18:39:38 2016 +0200
1.2 +++ b/common.py Thu Sep 08 21:36:58 2016 +0200
1.3 @@ -472,125 +472,6 @@
1.4 self.next_iterator()
1.5 self.process_structure_node(node)
1.6
1.7 - # Node rewriting, without processing.
1.8 -
1.9 - def convert_ifexp_node(self, n):
1.10 -
1.11 - """
1.12 - Convert the given if expression node 'n'. An if expression is considered
1.13 - as mapping to a function body containing an if statement as follows:
1.14 -
1.15 - <expr> if <test> else <altexpr>
1.16 -
1.17 - lambda <argnames>:
1.18 - if <test>:
1.19 - return <expr>
1.20 - else:
1.21 - return <altexpr>
1.22 -
1.23 - The <argnames> are populated with defaults after the node has been
1.24 - processed.
1.25 - """
1.26 -
1.27 - node = compiler.ast.Lambda(
1.28 - [], [], 0,
1.29 - compiler.ast.If([
1.30 - (n.test, compiler.ast.Return(n.then))
1.31 - ],
1.32 - compiler.ast.Return(n.else_)
1.33 - ))
1.34 -
1.35 - return node
1.36 -
1.37 - def convert_listcomp_node(self, n):
1.38 -
1.39 - """
1.40 - Convert the given list comprehension node 'n'. A list comprehension is
1.41 - considered as mapping to a function body containing a for loop as
1.42 - follows:
1.43 -
1.44 - [<expr> for <varexpr1> in <list1> if <ifexpr1> for <varexpr2> in <list2> if <ifexpr2> if <ifexpr3>]
1.45 -
1.46 - lambda <argnames>:
1.47 - <result> = []
1.48 - for <varexpr1> in <list1>:
1.49 - if <ifexpr1>:
1.50 - for <varexpr2> in <list2>:
1.51 - if <ifexpr2>:
1.52 - if <ifexpr3>:
1.53 - <result>.append(<expr>)
1.54 - return <result>
1.55 -
1.56 - The <argnames> are populated with defaults after the node has been
1.57 - processed.
1.58 - """
1.59 -
1.60 - temp = "$tr"
1.61 -
1.62 - node = compiler.ast.Lambda(
1.63 - [], [], 0,
1.64 - compiler.ast.Stmt([
1.65 -
1.66 - # <result> = []
1.67 -
1.68 - compiler.ast.Assign([compiler.ast.AssName(temp, "OP_ASSIGN")],
1.69 - compiler.ast.List([])
1.70 - ),
1.71 -
1.72 - # for ...
1.73 -
1.74 - self.convert_listcomp_for_node(n.quals[0], n.quals[1:], n.expr, temp),
1.75 -
1.76 - # return <result>
1.77 -
1.78 - compiler.ast.Return(compiler.ast.Name(temp))
1.79 - ]))
1.80 -
1.81 - return node
1.82 -
1.83 - def convert_listcomp_for_node(self, loop, following_loops, expr, temp):
1.84 -
1.85 - """
1.86 - Return a node representing 'loop', encapsulating 'following_loops' and
1.87 - employing 'expr' in the innermost loop body appending to 'temp'.
1.88 - """
1.89 -
1.90 - if loop.ifs:
1.91 - body = self.convert_listcomp_if_node(loop.ifs[0], loop.ifs[1:], following_loops, expr, temp)
1.92 - elif following_loops:
1.93 - body = self.convert_listcomp_for_node(following_loops[0], following_loops[1:], expr, temp)
1.94 - else:
1.95 - body = self.convert_listcomp_body_node(expr, temp)
1.96 -
1.97 - return compiler.ast.For(loop.assign, loop.list, compiler.ast.Stmt([body]), None)
1.98 -
1.99 - def convert_listcomp_if_node(self, if_, following_ifs, following_loops, expr, temp):
1.100 -
1.101 - """
1.102 - Return a node representing 'if_', encapsulating the 'following_ifs' and
1.103 - 'following_loops' and employing 'expr' in the innermost loop body
1.104 - appending to 'temp'.
1.105 - """
1.106 -
1.107 - if following_ifs:
1.108 - body = self.convert_listcomp_if_node(following_ifs[0], following_ifs[1:], following_loops, expr, temp)
1.109 - elif following_loops:
1.110 - body = self.convert_listcomp_for_node(following_loops[0], following_loops[1:], expr, temp)
1.111 - else:
1.112 - body = self.convert_listcomp_body_node(expr, temp)
1.113 -
1.114 - return compiler.ast.If([(if_.test, compiler.ast.Stmt([body]))], None)
1.115 -
1.116 - def convert_listcomp_body_node(self, expr, temp):
1.117 -
1.118 - "Return a node appending 'expr' to 'temp'."
1.119 -
1.120 - return compiler.ast.Discard(
1.121 - compiler.ast.CallFunc(
1.122 - compiler.ast.Getattr(compiler.ast.Name(temp), "append"), [expr]))
1.123 -
1.124 - # More node processing.
1.125 -
1.126 def process_literal_sequence_node(self, n, name, ref, cls):
1.127
1.128 """