diff --git a/src/h1/xsk/decompiler.cpp b/src/h1/xsk/decompiler.cpp index 493a483b..6aab29a3 100644 --- a/src/h1/xsk/decompiler.cpp +++ b/src/h1/xsk/decompiler.cpp @@ -1900,6 +1900,18 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j) == ast::kind::stmt_return && stmt->list.at(j).as_return->expr == ast::kind::null) { + if(entry.as_cond->value != blocks_.back().loc_end) + { + auto ref = stmt->list.at(j + 1).loc().label(); + + if (find_location_reference(stmt, i + 1, j, ref)) + { + // after return is referenced inside the block + decompile_if(stmt, i, j); + continue; + } + } + if (blocks_.back().loc_break != "" || blocks_.back().loc_continue != "") { decompile_if(stmt, i, j); // inside a loop cant be last @@ -2170,7 +2182,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st if (block->list.at(start - index) == ast::kind::stmt_assign) { auto ref = block->list.at(end).loc().label(); - auto ref2 = block->list.at(start).loc().label(); + auto ref2 = block->list.at(start - index + 1).loc().label(); if (find_location_reference(block, start, end, ref)) { @@ -2180,7 +2192,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st } else if (find_location_reference(block, 0, start, ref2)) { - // begin is at condition, not pre-expr + // begin is at condition or localVarCreate, not pre-expr decompile_while(block, start, end); return; } diff --git a/src/h2/xsk/decompiler.cpp b/src/h2/xsk/decompiler.cpp index 661d59c3..f2d69ed9 100644 --- a/src/h2/xsk/decompiler.cpp +++ b/src/h2/xsk/decompiler.cpp @@ -1900,6 +1900,18 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j) == ast::kind::stmt_return && stmt->list.at(j).as_return->expr == ast::kind::null) { + if(entry.as_cond->value != blocks_.back().loc_end) + { + auto ref = stmt->list.at(j + 1).loc().label(); + + if (find_location_reference(stmt, i + 1, j, ref)) + { + // after return is referenced inside the block + decompile_if(stmt, i, j); + continue; + } + } + if (blocks_.back().loc_break != "" || blocks_.back().loc_continue != "") { decompile_if(stmt, i, j); // inside a loop cant be last @@ -2170,7 +2182,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st if (block->list.at(start - index) == ast::kind::stmt_assign) { auto ref = block->list.at(end).loc().label(); - auto ref2 = block->list.at(start).loc().label(); + auto ref2 = block->list.at(start - index + 1).loc().label(); if (find_location_reference(block, start, end, ref)) { @@ -2180,7 +2192,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st } else if (find_location_reference(block, 0, start, ref2)) { - // begin is at condition, not pre-expr + // begin is at condition or localVarCreate, not pre-expr decompile_while(block, start, end); return; } diff --git a/src/iw5/xsk/decompiler.cpp b/src/iw5/xsk/decompiler.cpp index 8148e4b2..9476cd7d 100644 --- a/src/iw5/xsk/decompiler.cpp +++ b/src/iw5/xsk/decompiler.cpp @@ -1894,6 +1894,18 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j) == ast::kind::stmt_return && stmt->list.at(j).as_return->expr == ast::kind::null) { + if(entry.as_cond->value != blocks_.back().loc_end) + { + auto ref = stmt->list.at(j + 1).loc().label(); + + if (find_location_reference(stmt, i + 1, j, ref)) + { + // after return is referenced inside the block + decompile_if(stmt, i, j); + continue; + } + } + if (blocks_.back().loc_break != "" || blocks_.back().loc_continue != "") { decompile_if(stmt, i, j); // inside a loop cant be last @@ -2164,7 +2176,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st if (block->list.at(start - index) == ast::kind::stmt_assign) { auto ref = block->list.at(end).loc().label(); - auto ref2 = block->list.at(start).loc().label(); + auto ref2 = block->list.at(start - index + 1).loc().label(); if (find_location_reference(block, start, end, ref)) { @@ -2174,7 +2186,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st } else if (find_location_reference(block, 0, start, ref2)) { - // begin is at condition, not pre-expr + // begin is at condition or localVarCreate, not pre-expr decompile_while(block, start, end); return; } diff --git a/src/iw6/xsk/decompiler.cpp b/src/iw6/xsk/decompiler.cpp index 91dc0b02..06850d1d 100644 --- a/src/iw6/xsk/decompiler.cpp +++ b/src/iw6/xsk/decompiler.cpp @@ -1894,6 +1894,18 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j) == ast::kind::stmt_return && stmt->list.at(j).as_return->expr == ast::kind::null) { + if(entry.as_cond->value != blocks_.back().loc_end) + { + auto ref = stmt->list.at(j + 1).loc().label(); + + if (find_location_reference(stmt, i + 1, j, ref)) + { + // after return is referenced inside the block + decompile_if(stmt, i, j); + continue; + } + } + if (blocks_.back().loc_break != "" || blocks_.back().loc_continue != "") { decompile_if(stmt, i, j); // inside a loop cant be last @@ -2164,7 +2176,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st if (block->list.at(start - index) == ast::kind::stmt_assign) { auto ref = block->list.at(end).loc().label(); - auto ref2 = block->list.at(start).loc().label(); + auto ref2 = block->list.at(start - index + 1).loc().label(); if (find_location_reference(block, start, end, ref)) { @@ -2174,7 +2186,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st } else if (find_location_reference(block, 0, start, ref2)) { - // begin is at condition, not pre-expr + // begin is at condition or localVarCreate, not pre-expr decompile_while(block, start, end); return; } diff --git a/src/iw7/xsk/decompiler.cpp b/src/iw7/xsk/decompiler.cpp index 02b9fd11..52c62b99 100644 --- a/src/iw7/xsk/decompiler.cpp +++ b/src/iw7/xsk/decompiler.cpp @@ -1894,6 +1894,18 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j) == ast::kind::stmt_return && stmt->list.at(j).as_return->expr == ast::kind::null) { + if(entry.as_cond->value != blocks_.back().loc_end) + { + auto ref = stmt->list.at(j + 1).loc().label(); + + if (find_location_reference(stmt, i + 1, j, ref)) + { + // after return is referenced inside the block + decompile_if(stmt, i, j); + continue; + } + } + if (blocks_.back().loc_break != "" || blocks_.back().loc_continue != "") { decompile_if(stmt, i, j); // inside a loop cant be last @@ -2164,7 +2176,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st if (block->list.at(start - index) == ast::kind::stmt_assign) { auto ref = block->list.at(end).loc().label(); - auto ref2 = block->list.at(start).loc().label(); + auto ref2 = block->list.at(start - index + 1).loc().label(); if (find_location_reference(block, start, end, ref)) { @@ -2174,7 +2186,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st } else if (find_location_reference(block, 0, start, ref2)) { - // begin is at condition, not pre-expr + // begin is at condition or localVarCreate, not pre-expr decompile_while(block, start, end); return; } diff --git a/src/iw8/xsk/decompiler.cpp b/src/iw8/xsk/decompiler.cpp index b9ab5ec0..9c866755 100644 --- a/src/iw8/xsk/decompiler.cpp +++ b/src/iw8/xsk/decompiler.cpp @@ -1931,6 +1931,18 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j) == ast::kind::stmt_return && stmt->list.at(j).as_return->expr == ast::kind::null) { + if(entry.as_cond->value != blocks_.back().loc_end) + { + auto ref = stmt->list.at(j + 1).loc().label(); + + if (find_location_reference(stmt, i + 1, j, ref)) + { + // after return is referenced inside the block + decompile_if(stmt, i, j); + continue; + } + } + if (blocks_.back().loc_break != "" || blocks_.back().loc_continue != "") { decompile_if(stmt, i, j); // inside a loop cant be last @@ -2201,7 +2213,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st if (block->list.at(start - index) == ast::kind::stmt_assign) { auto ref = block->list.at(end).loc().label(); - auto ref2 = block->list.at(start).loc().label(); + auto ref2 = block->list.at(start - index + 1).loc().label(); if (find_location_reference(block, start, end, ref)) { @@ -2211,7 +2223,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st } else if (find_location_reference(block, 0, start, ref2)) { - // begin is at condition, not pre-expr + // begin is at condition or localVarCreate, not pre-expr decompile_while(block, start, end); return; } diff --git a/src/s1/xsk/decompiler.cpp b/src/s1/xsk/decompiler.cpp index 642376ad..0ff6b56f 100644 --- a/src/s1/xsk/decompiler.cpp +++ b/src/s1/xsk/decompiler.cpp @@ -1900,6 +1900,18 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j) == ast::kind::stmt_return && stmt->list.at(j).as_return->expr == ast::kind::null) { + if(entry.as_cond->value != blocks_.back().loc_end) + { + auto ref = stmt->list.at(j + 1).loc().label(); + + if (find_location_reference(stmt, i + 1, j, ref)) + { + // after return is referenced inside the block + decompile_if(stmt, i, j); + continue; + } + } + if (blocks_.back().loc_break != "" || blocks_.back().loc_continue != "") { decompile_if(stmt, i, j); // inside a loop cant be last @@ -2170,7 +2182,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st if (block->list.at(start - index) == ast::kind::stmt_assign) { auto ref = block->list.at(end).loc().label(); - auto ref2 = block->list.at(start).loc().label(); + auto ref2 = block->list.at(start - index + 1).loc().label(); if (find_location_reference(block, start, end, ref)) { @@ -2180,7 +2192,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st } else if (find_location_reference(block, 0, start, ref2)) { - // begin is at condition, not pre-expr + // begin is at condition or localVarCreate, not pre-expr decompile_while(block, start, end); return; } diff --git a/src/s2/xsk/decompiler.cpp b/src/s2/xsk/decompiler.cpp index 8fa8ce26..54d39171 100644 --- a/src/s2/xsk/decompiler.cpp +++ b/src/s2/xsk/decompiler.cpp @@ -1907,6 +1907,18 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j) == ast::kind::stmt_return && stmt->list.at(j).as_return->expr == ast::kind::null) { + if(entry.as_cond->value != blocks_.back().loc_end) + { + auto ref = stmt->list.at(j + 1).loc().label(); + + if (find_location_reference(stmt, i + 1, j, ref)) + { + // after return is referenced inside the block + decompile_if(stmt, i, j); + continue; + } + } + if (blocks_.back().loc_break != "" || blocks_.back().loc_continue != "") { decompile_if(stmt, i, j); // inside a loop cant be last @@ -2177,7 +2189,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st if (block->list.at(start - index) == ast::kind::stmt_assign) { auto ref = block->list.at(end).loc().label(); - auto ref2 = block->list.at(start).loc().label(); + auto ref2 = block->list.at(start - index + 1).loc().label(); if (find_location_reference(block, start, end, ref)) { @@ -2187,7 +2199,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st } else if (find_location_reference(block, 0, start, ref2)) { - // begin is at condition, not pre-expr + // begin is at condition or localVarCreate, not pre-expr decompile_while(block, start, end); return; } diff --git a/src/s4/xsk/decompiler.cpp b/src/s4/xsk/decompiler.cpp index 5f080de0..80daac70 100644 --- a/src/s4/xsk/decompiler.cpp +++ b/src/s4/xsk/decompiler.cpp @@ -1931,6 +1931,18 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) } else if (stmt->list.at(j) == ast::kind::stmt_return && stmt->list.at(j).as_return->expr == ast::kind::null) { + if(entry.as_cond->value != blocks_.back().loc_end) + { + auto ref = stmt->list.at(j + 1).loc().label(); + + if (find_location_reference(stmt, i + 1, j, ref)) + { + // after return is referenced inside the block + decompile_if(stmt, i, j); + continue; + } + } + if (blocks_.back().loc_break != "" || blocks_.back().loc_continue != "") { decompile_if(stmt, i, j); // inside a loop cant be last @@ -2201,7 +2213,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st if (block->list.at(start - index) == ast::kind::stmt_assign) { auto ref = block->list.at(end).loc().label(); - auto ref2 = block->list.at(start).loc().label(); + auto ref2 = block->list.at(start - index + 1).loc().label(); if (find_location_reference(block, start, end, ref)) { @@ -2211,7 +2223,7 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::size_t st } else if (find_location_reference(block, 0, start, ref2)) { - // begin is at condition, not pre-expr + // begin is at condition or localVarCreate, not pre-expr decompile_while(block, start, end); return; } diff --git a/src/tool/xsk/main.cpp b/src/tool/xsk/main.cpp index 883a9916..5e916c6e 100644 --- a/src/tool/xsk/main.cpp +++ b/src/tool/xsk/main.cpp @@ -250,7 +250,7 @@ void disassemble_file(game game, std::string file) } catch (const std::exception& e) { - std::cerr << e.what() << '\n'; + std::cerr << e.what() << " at " << file << '\n'; } } @@ -394,7 +394,7 @@ void decompile_file(game game, std::string file) } catch (const std::exception& e) { - std::cerr << e.what() << '\n'; + std::cerr << e.what() << " at " << file << '\n'; } } @@ -471,7 +471,7 @@ void disassemble_file(game game, const std::filesystem::path& file) } catch (const std::exception& e) { - std::cerr << e.what() << '\n'; + std::cerr << e.what() << " at " << file.string() << '\n'; } } @@ -521,7 +521,7 @@ void decompile_file(game game, const std::filesystem::path& file) } catch (const std::exception& e) { - std::cerr << e.what() << '\n'; + std::cerr << e.what() << " at " << file.string() << '\n'; } }