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