rvalue = str(self[node.rvalue])
if isinstance(node.rvalue, pc_ast.IfExpr):
- # All right, this deserves an explanation.
- # We basically convert T <- C ? A : B into this code:
- #
- # if C then
- # T <- A
- # else
- # T <- B
- #
- # To make things work, we must ensure that objects are unique.
- # Otherwise we'll reuse the bogus code already produced before.
- (body, orelse) = map(lambda node: node.clone(),
- (node.rvalue.body[0], node.rvalue.orelse[0]))
- body = pc_ast.Scope([node.__class__(lvalue=node.lvalue.clone(), rvalue=body)])
- orelse = pc_ast.Scope([node.__class__(lvalue=node.lvalue.clone(), rvalue=orelse)])
- tmpnode = node.rvalue.clone(body=body, orelse=orelse)
- walker = mdis.walker.Walker()
- traverse(root=tmpnode, visitor=self, walker=walker)
- for (level, stmt) in self[tmpnode]:
- self[node].emit(stmt=stmt, level=level)
+ stmt = " ".join([
+ lvalue,
+ mapping[node.__class__],
+ str(self[node.rvalue.test]),
+ "?",
+ str(self[node.rvalue.body[0]]),
+ ":",
+ str(self[node.rvalue.orelse[0]]),
+ ])
else:
stmt = " ".join([
lvalue,
mapping[node.__class__],
rvalue,
])
- self[node].emit(stmt=stmt)
+ self[node].emit(stmt=stmt)
@Hook(pc_ast.BinaryExpr)
def BinaryExpr(self, node):