diff --git a/src/h1/xsk/decompiler.cpp b/src/h1/xsk/decompiler.cpp index 6aab29a3..456ae268 100644 --- a/src/h1/xsk/decompiler.cpp +++ b/src/h1/xsk/decompiler.cpp @@ -1796,11 +1796,16 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) auto break_loc = last_location_index(stmt, i) ? blocks_.back().loc_end : stmt->list.at(i + 1).loc().label(); auto start = find_location_index(stmt, stmt->list.at(i).as_jump_back->value); - if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) // do-while + if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) { - continue; + if (static_cast(i) < find_location_index(stmt, stmt->list.at(i - 1).as_cond->loc().label())) + { + continue; // do-while + } + // empty if at loop end } - else if (i == static_cast(start)) // empty loop + + if (i == static_cast(start)) // empty loop { decompile_infinite(stmt, start, i); i = static_cast(stmt->list.size()); @@ -1891,7 +1896,15 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j).as_jump->value == entry.as_cond->value) { - decompile_if(stmt, i, j); // if block, have a last empty else inside + if (find_location_reference(stmt, i + 1, j, entry.as_cond->value)) + { + // if block, have a empty else inside at end + decompile_if(stmt, i, j); + } + else + { + decompile_ifelse(stmt, i, j); // if block with empty else + } } else { diff --git a/src/h2/xsk/decompiler.cpp b/src/h2/xsk/decompiler.cpp index f2d69ed9..e7a07083 100644 --- a/src/h2/xsk/decompiler.cpp +++ b/src/h2/xsk/decompiler.cpp @@ -1796,11 +1796,16 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) auto break_loc = last_location_index(stmt, i) ? blocks_.back().loc_end : stmt->list.at(i + 1).loc().label(); auto start = find_location_index(stmt, stmt->list.at(i).as_jump_back->value); - if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) // do-while + if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) { - continue; + if (static_cast(i) < find_location_index(stmt, stmt->list.at(i - 1).as_cond->loc().label())) + { + continue; // do-while + } + // empty if at loop end } - else if (i == static_cast(start)) // empty loop + + if (i == static_cast(start)) // empty loop { decompile_infinite(stmt, start, i); i = static_cast(stmt->list.size()); @@ -1891,7 +1896,15 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j).as_jump->value == entry.as_cond->value) { - decompile_if(stmt, i, j); // if block, have a last empty else inside + if (find_location_reference(stmt, i + 1, j, entry.as_cond->value)) + { + // if block, have a empty else inside at end + decompile_if(stmt, i, j); + } + else + { + decompile_ifelse(stmt, i, j); // if block with empty else + } } else { diff --git a/src/iw5/xsk/decompiler.cpp b/src/iw5/xsk/decompiler.cpp index 9476cd7d..51f48aa2 100644 --- a/src/iw5/xsk/decompiler.cpp +++ b/src/iw5/xsk/decompiler.cpp @@ -1790,11 +1790,16 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) auto break_loc = last_location_index(stmt, i) ? blocks_.back().loc_end : stmt->list.at(i + 1).loc().label(); auto start = find_location_index(stmt, stmt->list.at(i).as_jump_back->value); - if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) // do-while + if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) { - continue; + if (static_cast(i) < find_location_index(stmt, stmt->list.at(i - 1).as_cond->loc().label())) + { + continue; // do-while + } + // empty if at loop end } - else if (i == static_cast(start)) // empty loop + + if (i == static_cast(start)) // empty loop { decompile_infinite(stmt, start, i); i = static_cast(stmt->list.size()); @@ -1885,7 +1890,15 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j).as_jump->value == entry.as_cond->value) { - decompile_if(stmt, i, j); // if block, have a last empty else inside + if (find_location_reference(stmt, i + 1, j, entry.as_cond->value)) + { + // if block, have a empty else inside at end + decompile_if(stmt, i, j); + } + else + { + decompile_ifelse(stmt, i, j); // if block with empty else + } } else { diff --git a/src/iw6/xsk/decompiler.cpp b/src/iw6/xsk/decompiler.cpp index 06850d1d..32a52619 100644 --- a/src/iw6/xsk/decompiler.cpp +++ b/src/iw6/xsk/decompiler.cpp @@ -1790,11 +1790,16 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) auto break_loc = last_location_index(stmt, i) ? blocks_.back().loc_end : stmt->list.at(i + 1).loc().label(); auto start = find_location_index(stmt, stmt->list.at(i).as_jump_back->value); - if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) // do-while + if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) { - continue; + if (static_cast(i) < find_location_index(stmt, stmt->list.at(i - 1).as_cond->loc().label())) + { + continue; // do-while + } + // empty if at loop end } - else if (i == static_cast(start)) // empty loop + + if (i == static_cast(start)) // empty loop { decompile_infinite(stmt, start, i); i = static_cast(stmt->list.size()); @@ -1885,7 +1890,15 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j).as_jump->value == entry.as_cond->value) { - decompile_if(stmt, i, j); // if block, have a last empty else inside + if (find_location_reference(stmt, i + 1, j, entry.as_cond->value)) + { + // if block, have a empty else inside at end + decompile_if(stmt, i, j); + } + else + { + decompile_ifelse(stmt, i, j); // if block with empty else + } } else { diff --git a/src/iw7/xsk/decompiler.cpp b/src/iw7/xsk/decompiler.cpp index 52c62b99..4232735a 100644 --- a/src/iw7/xsk/decompiler.cpp +++ b/src/iw7/xsk/decompiler.cpp @@ -1790,11 +1790,16 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) auto break_loc = last_location_index(stmt, i) ? blocks_.back().loc_end : stmt->list.at(i + 1).loc().label(); auto start = find_location_index(stmt, stmt->list.at(i).as_jump_back->value); - if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) // do-while + if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) { - continue; + if (static_cast(i) < find_location_index(stmt, stmt->list.at(i - 1).as_cond->loc().label())) + { + continue; // do-while + } + // empty if at loop end } - else if (i == static_cast(start)) // empty loop + + if (i == static_cast(start)) // empty loop { decompile_infinite(stmt, start, i); i = static_cast(stmt->list.size()); @@ -1885,7 +1890,15 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j).as_jump->value == entry.as_cond->value) { - decompile_if(stmt, i, j); // if block, have a last empty else inside + if (find_location_reference(stmt, i + 1, j, entry.as_cond->value)) + { + // if block, have a empty else inside at end + decompile_if(stmt, i, j); + } + else + { + decompile_ifelse(stmt, i, j); // if block with empty else + } } else { diff --git a/src/iw8/xsk/decompiler.cpp b/src/iw8/xsk/decompiler.cpp index 9c866755..9c6e098b 100644 --- a/src/iw8/xsk/decompiler.cpp +++ b/src/iw8/xsk/decompiler.cpp @@ -1827,11 +1827,16 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) auto break_loc = last_location_index(stmt, i) ? blocks_.back().loc_end : stmt->list.at(i + 1).loc().label(); auto start = find_location_index(stmt, stmt->list.at(i).as_jump_back->value); - if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) // do-while + if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) { - continue; + if (static_cast(i) < find_location_index(stmt, stmt->list.at(i - 1).as_cond->loc().label())) + { + continue; // do-while + } + // empty if at loop end } - else if (i == static_cast(start)) // empty loop + + if (i == static_cast(start)) // empty loop { decompile_infinite(stmt, start, i); i = static_cast(stmt->list.size()); @@ -1922,7 +1927,15 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j).as_jump->value == entry.as_cond->value) { - decompile_if(stmt, i, j); // if block, have a last empty else inside + if (find_location_reference(stmt, i + 1, j, entry.as_cond->value)) + { + // if block, have a empty else inside at end + decompile_if(stmt, i, j); + } + else + { + decompile_ifelse(stmt, i, j); // if block with empty else + } } else { diff --git a/src/s1/xsk/decompiler.cpp b/src/s1/xsk/decompiler.cpp index 0ff6b56f..4abbeb8a 100644 --- a/src/s1/xsk/decompiler.cpp +++ b/src/s1/xsk/decompiler.cpp @@ -1796,11 +1796,16 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) auto break_loc = last_location_index(stmt, i) ? blocks_.back().loc_end : stmt->list.at(i + 1).loc().label(); auto start = find_location_index(stmt, stmt->list.at(i).as_jump_back->value); - if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) // do-while + if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) { - continue; + if (static_cast(i) < find_location_index(stmt, stmt->list.at(i - 1).as_cond->loc().label())) + { + continue; // do-while + } + // empty if at loop end } - else if (i == static_cast(start)) // empty loop + + if (i == static_cast(start)) // empty loop { decompile_infinite(stmt, start, i); i = static_cast(stmt->list.size()); @@ -1891,7 +1896,15 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j).as_jump->value == entry.as_cond->value) { - decompile_if(stmt, i, j); // if block, have a last empty else inside + if (find_location_reference(stmt, i + 1, j, entry.as_cond->value)) + { + // if block, have a empty else inside at end + decompile_if(stmt, i, j); + } + else + { + decompile_ifelse(stmt, i, j); // if block with empty else + } } else { diff --git a/src/s2/xsk/decompiler.cpp b/src/s2/xsk/decompiler.cpp index 54d39171..d677548d 100644 --- a/src/s2/xsk/decompiler.cpp +++ b/src/s2/xsk/decompiler.cpp @@ -1803,11 +1803,16 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) auto break_loc = last_location_index(stmt, i) ? blocks_.back().loc_end : stmt->list.at(i + 1).loc().label(); auto start = find_location_index(stmt, stmt->list.at(i).as_jump_back->value); - if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) // do-while + if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) { - continue; + if (static_cast(i) < find_location_index(stmt, stmt->list.at(i - 1).as_cond->loc().label())) + { + continue; // do-while + } + // empty if at loop end } - else if (i == static_cast(start)) // empty loop + + if (i == static_cast(start)) // empty loop { decompile_infinite(stmt, start, i); i = static_cast(stmt->list.size()); @@ -1898,7 +1903,15 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j).as_jump->value == entry.as_cond->value) { - decompile_if(stmt, i, j); // if block, have a last empty else inside + if (find_location_reference(stmt, i + 1, j, entry.as_cond->value)) + { + // if block, have a empty else inside at end + decompile_if(stmt, i, j); + } + else + { + decompile_ifelse(stmt, i, j); // if block with empty else + } } else { diff --git a/src/s4/xsk/decompiler.cpp b/src/s4/xsk/decompiler.cpp index 80daac70..20e9adf6 100644 --- a/src/s4/xsk/decompiler.cpp +++ b/src/s4/xsk/decompiler.cpp @@ -1827,11 +1827,16 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) auto break_loc = last_location_index(stmt, i) ? blocks_.back().loc_end : stmt->list.at(i + 1).loc().label(); auto start = find_location_index(stmt, stmt->list.at(i).as_jump_back->value); - if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) // do-while + if (i > 0 && stmt->list.at(i - 1).as_node->kind() == ast::kind::asm_jump_cond) { - continue; + if (static_cast(i) < find_location_index(stmt, stmt->list.at(i - 1).as_cond->loc().label())) + { + continue; // do-while + } + // empty if at loop end } - else if (i == static_cast(start)) // empty loop + + if (i == static_cast(start)) // empty loop { decompile_infinite(stmt, start, i); i = static_cast(stmt->list.size()); @@ -1922,7 +1927,15 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j).as_jump->value == entry.as_cond->value) { - decompile_if(stmt, i, j); // if block, have a last empty else inside + if (find_location_reference(stmt, i + 1, j, entry.as_cond->value)) + { + // if block, have a empty else inside at end + decompile_if(stmt, i, j); + } + else + { + decompile_ifelse(stmt, i, j); // if block with empty else + } } else {