def for_loop(self, loop_block):
iter_block, _, body_else_block = split(loop_block, 'GET_ITER')
# for_iter = body_else_block[0]
for_iter = body_else_block.pop(0)
assert for_iter.opname == 'FOR_ITER'
idx = find_index(body_else_block, lambda instr: instr.opname == 'POP_BLOCK' and for_iter.to == instr.i)
assert idx is not False
body_block = body_else_block[:idx]
else_block = body_else_block[idx + 1:]
jump_abs = body_block.pop()
assert jump_abs.opname == 'JUMP_ABSOLUTE' and jump_abs.to == for_iter.i
iter_stmnt = self.decompile_block(iter_block).stmnt()
assert len(iter_stmnt) == 1
iter_stmnt = iter_stmnt[0]
body_lst = self.decompile_block(body_block[:], stack_items=[None], jump_map={for_iter.i:for_iter.to}).stmnt()
assign_ = body_lst.pop(0)
body = body_lst
if len(else_block) == 0:
else_ = []
else:
else_ = self.decompile_block(else_block[:]).stmnt()
assign = assign_.targets[0]
for_ = _ast.For(target=assign, iter=iter_stmnt, body=body, orelse=else_, lineno=iter_stmnt.lineno, col_offset=0)
self.ast_stack.append(for_)
评论列表
文章目录