def _unwarp_expressions_pack(blocks, pack):
    replacements = {}

    for start, end, slot, slot_type in reversed(pack):
        end = replacements.get(end, end)

        start_index = blocks.index(start)
        end_index = blocks.index(end)

        body = blocks[start_index + 1:end_index]

        try:
            _unwarp_logical_expression(start, end, body)
        except (AssertionError, IndexError):
            if walterr_catch_asserts:
                setattr(start, "_walterr_error_here", True)
                print("-- WARNING: Error occurred during decompilation.")
                print("--   Code may be incomplete or incorrect.")
            else:
                raise

        statements = start.contents + end.contents

        if slot_type == nodes.Identifier.T_SLOT:
            min_i = len(start.contents)
            split_i = _split_by_slot_use(statements, min_i, end.warp, slot)
        else:
            split_i = len(start.contents)

        max_i = len(statements)

        if split_i > max_i:
            end.contents = start.contents + end.contents
            start.contents = []

            blocks = blocks[:start_index] + blocks[end_index:]

            _replace_targets(blocks, start, end)

            replacements[start] = end

            slotworks.eliminate_temporary(end)

            _set_flow_to(start, end)
        else:
            blocks = blocks[:start_index + 1] + blocks[end_index:]

            start.contents = statements[:split_i]
            end.contents = statements[split_i:]

            # We need to kill the start's warp before slot
            # elimination or it could result in a cycled AST.
            _set_flow_to(start, end)

            slotworks.eliminate_temporary(start)

    return blocks
Example #2
0
def _unwarp_expressions_pack(blocks, pack):
	replacements = {}

	for start, end, slot, slot_type in reversed(pack):
		end = replacements.get(end, end)

		start_index = blocks.index(start)
		end_index = blocks.index(end)

		body = blocks[start_index + 1:end_index]

		_unwarp_logical_expression(start, end, body)

		statements = start.contents + end.contents

		if slot_type == nodes.Identifier.T_SLOT:
			min_i = len(start.contents)
			split_i = _split_by_slot_use(statements, min_i,
							end.warp, slot)
		else:
			split_i = len(start.contents)

		max_i = len(statements)

		if split_i > max_i:
			end.contents = start.contents + end.contents
			start.contents = []

			blocks = blocks[:start_index] + blocks[end_index:]

			_replace_targets(blocks, start, end)

			replacements[start] = end

			slotworks.eliminate_temporary(end)

			_set_flow_to(start, end)
		else:
			blocks = blocks[:start_index + 1] + blocks[end_index:]

			start.contents = statements[:split_i]
			end.contents = statements[split_i:]

			# We need to kill the start's warp before slot
			# elimination or it could result in a cycled AST.
			_set_flow_to(start, end)

			slotworks.eliminate_temporary(start)

	return blocks