def _unwarp_if_statement(start, body, end, topmost_end): expression, body, false = _extract_if_expression(start, body, end, topmost_end) node = nodes.If() node.expression = expression # has an else branch if false != end and false != topmost_end: else_start = false else_start_index = body.index(else_start) then_body = body[:else_start_index] then_warp_out = then_body[-1].warp assert _is_jump(then_warp_out) assert then_warp_out.target in (end, topmost_end) else_body = body[else_start_index:] else_warp_out = else_body[-1].warp if isinstance(else_warp_out, nodes.UnconditionalWarp): if else_warp_out.type == nodes.UnconditionalWarp.T_JUMP: assert else_warp_out.target in (end, topmost_end) else: assert else_warp_out.target == end else: # assert isinstance(else_warp_out, nodes.EndWarp) logger.error( "err: unwarper.py assert isinstance(else_warp_out, nodes.EndWarp), Block indices are unreliable while you are mangling them! P.S. Probably they should not be named indices... But they ARE used as indices during other phases. Sometimes." ) _set_end(then_body[-1]) then_blocks = _unwarp_ifs(then_body, then_body[-1], topmost_end) node.then_block.contents = then_blocks _set_end(else_body[-1]) else_blocks = _unwarp_ifs(else_body, else_body[-1], topmost_end) node.else_block.contents = else_blocks else: warp_out = body[-1].warp if not isinstance(warp_out, nodes.EndWarp): assert isinstance(warp_out, nodes.UnconditionalWarp) assert warp_out.target in (end, topmost_end) _set_end(body[-1]) then_blocks = _unwarp_ifs(body, body[-1], topmost_end) node.then_block.contents = then_blocks start.contents.append(node)
def _unwarp_if_statement(start, body, end, topmost_end): expression, body, false = _extract_if_expression(start, body, end, topmost_end) node = nodes.If() node.expression = expression # has an else branch if false != end and false != topmost_end: else_start = false else_start_index = body.index(else_start) then_body = body[:else_start_index] then_warp_out = then_body[-1].warp assert _is_jump(then_warp_out) assert then_warp_out.target in (end, topmost_end) else_body = body[else_start_index:] else_warp_out = else_body[-1].warp if isinstance(else_warp_out, nodes.UnconditionalWarp): if else_warp_out.type == nodes.UnconditionalWarp.T_JUMP: assert else_warp_out.target in (end, topmost_end) else: assert else_warp_out.target == end else: assert isinstance(else_warp_out, nodes.EndWarp) _set_end(then_body[-1]) then_blocks = _unwarp_ifs(then_body, then_body[-1], topmost_end) node.then_block.contents = then_blocks _set_end(else_body[-1]) else_blocks = _unwarp_ifs(else_body, else_body[-1], topmost_end) node.else_block.contents = else_blocks else: warp_out = body[-1].warp if not isinstance(warp_out, nodes.EndWarp): # assert isinstance(warp_out, nodes.UnconditionalWarp) # assert warp_out.target in (end, topmost_end) pass _set_end(body[-1]) then_blocks = _unwarp_ifs(body, body[-1], topmost_end) node.then_block.contents = then_blocks start.contents.append(node)