From 2dcde964e10937d9fee0a8c0ee896a606c90cea7 Mon Sep 17 00:00:00 2001 From: xensik Date: Tue, 16 Nov 2021 16:20:10 +0100 Subject: [PATCH] fix decompiler variable stack --- src/h1/xsk/decompiler.cpp | 41 +++++++++++++++++++++++++++++++++++-- src/h1/xsk/decompiler.hpp | 1 + src/h2/xsk/decompiler.cpp | 41 +++++++++++++++++++++++++++++++++++-- src/h2/xsk/decompiler.hpp | 1 + src/iw5/xsk/decompiler.cpp | 42 ++++++++++++++++++++++++++++++++++++-- src/iw5/xsk/decompiler.hpp | 1 + src/iw6/xsk/decompiler.cpp | 41 +++++++++++++++++++++++++++++++++++-- src/iw6/xsk/decompiler.hpp | 1 + src/iw7/xsk/decompiler.cpp | 41 +++++++++++++++++++++++++++++++++++-- src/iw7/xsk/decompiler.hpp | 1 + src/iw8/xsk/decompiler.cpp | 41 +++++++++++++++++++++++++++++++++++-- src/iw8/xsk/decompiler.hpp | 1 + src/s1/xsk/decompiler.cpp | 41 +++++++++++++++++++++++++++++++++++-- src/s1/xsk/decompiler.hpp | 1 + src/s2/xsk/decompiler.cpp | 41 +++++++++++++++++++++++++++++++++++-- src/s2/xsk/decompiler.hpp | 1 + src/s4/xsk/decompiler.cpp | 41 +++++++++++++++++++++++++++++++++++-- src/s4/xsk/decompiler.hpp | 1 + 18 files changed, 361 insertions(+), 18 deletions(-) diff --git a/src/h1/xsk/decompiler.cpp b/src/h1/xsk/decompiler.cpp index ab0a685e..9b173989 100644 --- a/src/h1/xsk/decompiler.cpp +++ b/src/h1/xsk/decompiler.cpp @@ -2864,6 +2864,9 @@ void decompiler::process_stmt_if(const gsc::context_ptr& ctx, const gsc::stmt_if void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stmt_ifelse_ptr& stmt) { + std::vector childs; + auto abort = gsc::abort_t::abort_return; + process_expr(ctx, stmt->expr); stmt->ctx_if = std::make_unique(); @@ -2871,12 +2874,30 @@ void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stm process_stmt(stmt->ctx_if, stmt->stmt_if); + if(stmt->ctx_if->abort <= gsc::abort_t::abort_return) + { + abort = stmt->ctx_if->abort; + + if(abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_if.get()); + } + stmt->ctx_else = std::make_unique(); ctx->transfer_decompiler(stmt->ctx_else); process_stmt(stmt->ctx_else, stmt->stmt_else); - std::vector childs({stmt->ctx_if.get(), stmt->ctx_else.get()}); + if(stmt->ctx_else->abort <= abort) + { + abort = stmt->ctx_else->abort; + + if (abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_else.get()); + } + + if(ctx->abort == gsc::abort_t::abort_none) + ctx->abort = abort; + ctx->append(childs); if(stmt->stmt_if.as_list->stmts.size() == 1 && !gsc::node::is_special_stmt(stmt->stmt_if.as_list->stmts.at(0))) @@ -3020,11 +3041,27 @@ void decompiler::process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt void decompiler::process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt) { - ctx->abort = gsc::abort_t::abort_break; + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_break; + } +} + +void decompiler::process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt) +{ + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_continue; + } } void decompiler::process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt) { + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_return; + } + if(stmt->expr.as_node->type == gsc::node_t::null) { return; diff --git a/src/h1/xsk/decompiler.hpp b/src/h1/xsk/decompiler.hpp index b1e31310..afe92b6f 100644 --- a/src/h1/xsk/decompiler.hpp +++ b/src/h1/xsk/decompiler.hpp @@ -67,6 +67,7 @@ private: void process_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_switch_ptr& stmt); void process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt_list_ptr& stmt); void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt); + void process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt); void process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt); void process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr); void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); diff --git a/src/h2/xsk/decompiler.cpp b/src/h2/xsk/decompiler.cpp index 8e8325c5..3da9bb72 100644 --- a/src/h2/xsk/decompiler.cpp +++ b/src/h2/xsk/decompiler.cpp @@ -2864,6 +2864,9 @@ void decompiler::process_stmt_if(const gsc::context_ptr& ctx, const gsc::stmt_if void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stmt_ifelse_ptr& stmt) { + std::vector childs; + auto abort = gsc::abort_t::abort_return; + process_expr(ctx, stmt->expr); stmt->ctx_if = std::make_unique(); @@ -2871,12 +2874,30 @@ void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stm process_stmt(stmt->ctx_if, stmt->stmt_if); + if(stmt->ctx_if->abort <= gsc::abort_t::abort_return) + { + abort = stmt->ctx_if->abort; + + if(abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_if.get()); + } + stmt->ctx_else = std::make_unique(); ctx->transfer_decompiler(stmt->ctx_else); process_stmt(stmt->ctx_else, stmt->stmt_else); - std::vector childs({stmt->ctx_if.get(), stmt->ctx_else.get()}); + if(stmt->ctx_else->abort <= abort) + { + abort = stmt->ctx_else->abort; + + if (abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_else.get()); + } + + if(ctx->abort == gsc::abort_t::abort_none) + ctx->abort = abort; + ctx->append(childs); if(stmt->stmt_if.as_list->stmts.size() == 1 && !gsc::node::is_special_stmt(stmt->stmt_if.as_list->stmts.at(0))) @@ -3020,11 +3041,27 @@ void decompiler::process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt void decompiler::process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt) { - ctx->abort = gsc::abort_t::abort_break; + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_break; + } +} + +void decompiler::process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt) +{ + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_continue; + } } void decompiler::process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt) { + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_return; + } + if(stmt->expr.as_node->type == gsc::node_t::null) { return; diff --git a/src/h2/xsk/decompiler.hpp b/src/h2/xsk/decompiler.hpp index dfa59f08..979eb1b9 100644 --- a/src/h2/xsk/decompiler.hpp +++ b/src/h2/xsk/decompiler.hpp @@ -67,6 +67,7 @@ private: void process_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_switch_ptr& stmt); void process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt_list_ptr& stmt); void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt); + void process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt); void process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt); void process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr); void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); diff --git a/src/iw5/xsk/decompiler.cpp b/src/iw5/xsk/decompiler.cpp index bb61f4ed..de786e09 100644 --- a/src/iw5/xsk/decompiler.cpp +++ b/src/iw5/xsk/decompiler.cpp @@ -2877,6 +2877,7 @@ void decompiler::process_stmt(const gsc::context_ptr& ctx, const gsc::stmt_ptr& case gsc::node_t::stmt_foreach: process_stmt_foreach(ctx, stmt.as_foreach); break; case gsc::node_t::stmt_switch: process_stmt_switch(ctx, stmt.as_switch); break; case gsc::node_t::stmt_break: process_stmt_break(ctx, stmt.as_break); break; + case gsc::node_t::stmt_continue: process_stmt_continue(ctx, stmt.as_continue); break; case gsc::node_t::stmt_return: process_stmt_return(ctx, stmt.as_return); break; case gsc::node_t::asm_remove: process_var_remove(ctx, stmt.as_asm_remove); break; case gsc::node_t::asm_create: @@ -2971,6 +2972,9 @@ void decompiler::process_stmt_if(const gsc::context_ptr& ctx, const gsc::stmt_if void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stmt_ifelse_ptr& stmt) { + std::vector childs; + auto abort = gsc::abort_t::abort_return; + process_expr(ctx, stmt->expr); stmt->ctx_if = std::make_unique(); @@ -2978,12 +2982,30 @@ void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stm process_stmt(stmt->ctx_if, stmt->stmt_if); + if(stmt->ctx_if->abort <= gsc::abort_t::abort_return) + { + abort = stmt->ctx_if->abort; + + if(abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_if.get()); + } + stmt->ctx_else = std::make_unique(); ctx->transfer_decompiler(stmt->ctx_else); process_stmt(stmt->ctx_else, stmt->stmt_else); - std::vector childs({stmt->ctx_if.get(), stmt->ctx_else.get()}); + if(stmt->ctx_else->abort <= abort) + { + abort = stmt->ctx_else->abort; + + if (abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_else.get()); + } + + if(ctx->abort == gsc::abort_t::abort_none) + ctx->abort = abort; + ctx->append(childs); if(stmt->stmt_if.as_list->stmts.size() == 1 && !gsc::node::is_special_stmt(stmt->stmt_if.as_list->stmts.at(0))) @@ -3127,11 +3149,27 @@ void decompiler::process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt void decompiler::process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt) { - ctx->abort = gsc::abort_t::abort_break; + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_break; + } +} + +void decompiler::process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt) +{ + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_continue; + } } void decompiler::process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt) { + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_return; + } + if(stmt->expr.as_node->type == gsc::node_t::null) { return; diff --git a/src/iw5/xsk/decompiler.hpp b/src/iw5/xsk/decompiler.hpp index b1986fc5..e8601855 100644 --- a/src/iw5/xsk/decompiler.hpp +++ b/src/iw5/xsk/decompiler.hpp @@ -67,6 +67,7 @@ private: void process_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_switch_ptr& stmt); void process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt_list_ptr& stmt); void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt); + void process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt); void process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt); void process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr); void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); diff --git a/src/iw6/xsk/decompiler.cpp b/src/iw6/xsk/decompiler.cpp index edd081f6..815e1bd2 100644 --- a/src/iw6/xsk/decompiler.cpp +++ b/src/iw6/xsk/decompiler.cpp @@ -2858,6 +2858,9 @@ void decompiler::process_stmt_if(const gsc::context_ptr& ctx, const gsc::stmt_if void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stmt_ifelse_ptr& stmt) { + std::vector childs; + auto abort = gsc::abort_t::abort_return; + process_expr(ctx, stmt->expr); stmt->ctx_if = std::make_unique(); @@ -2865,12 +2868,30 @@ void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stm process_stmt(stmt->ctx_if, stmt->stmt_if); + if(stmt->ctx_if->abort <= gsc::abort_t::abort_return) + { + abort = stmt->ctx_if->abort; + + if(abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_if.get()); + } + stmt->ctx_else = std::make_unique(); ctx->transfer_decompiler(stmt->ctx_else); process_stmt(stmt->ctx_else, stmt->stmt_else); - std::vector childs({stmt->ctx_if.get(), stmt->ctx_else.get()}); + if(stmt->ctx_else->abort <= abort) + { + abort = stmt->ctx_else->abort; + + if (abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_else.get()); + } + + if(ctx->abort == gsc::abort_t::abort_none) + ctx->abort = abort; + ctx->append(childs); if(stmt->stmt_if.as_list->stmts.size() == 1 && !gsc::node::is_special_stmt(stmt->stmt_if.as_list->stmts.at(0))) @@ -3014,11 +3035,27 @@ void decompiler::process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt void decompiler::process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt) { - ctx->abort = gsc::abort_t::abort_break; + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_break; + } +} + +void decompiler::process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt) +{ + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_continue; + } } void decompiler::process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt) { + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_return; + } + if(stmt->expr.as_node->type == gsc::node_t::null) { return; diff --git a/src/iw6/xsk/decompiler.hpp b/src/iw6/xsk/decompiler.hpp index dce3e3c5..f2744082 100644 --- a/src/iw6/xsk/decompiler.hpp +++ b/src/iw6/xsk/decompiler.hpp @@ -67,6 +67,7 @@ private: void process_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_switch_ptr& stmt); void process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt_list_ptr& stmt); void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt); + void process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt); void process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt); void process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr); void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); diff --git a/src/iw7/xsk/decompiler.cpp b/src/iw7/xsk/decompiler.cpp index f1d6d0aa..314ab41a 100644 --- a/src/iw7/xsk/decompiler.cpp +++ b/src/iw7/xsk/decompiler.cpp @@ -2858,6 +2858,9 @@ void decompiler::process_stmt_if(const gsc::context_ptr& ctx, const gsc::stmt_if void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stmt_ifelse_ptr& stmt) { + std::vector childs; + auto abort = gsc::abort_t::abort_return; + process_expr(ctx, stmt->expr); stmt->ctx_if = std::make_unique(); @@ -2865,12 +2868,30 @@ void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stm process_stmt(stmt->ctx_if, stmt->stmt_if); + if(stmt->ctx_if->abort <= gsc::abort_t::abort_return) + { + abort = stmt->ctx_if->abort; + + if(abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_if.get()); + } + stmt->ctx_else = std::make_unique(); ctx->transfer_decompiler(stmt->ctx_else); process_stmt(stmt->ctx_else, stmt->stmt_else); - std::vector childs({stmt->ctx_if.get(), stmt->ctx_else.get()}); + if(stmt->ctx_else->abort <= abort) + { + abort = stmt->ctx_else->abort; + + if (abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_else.get()); + } + + if(ctx->abort == gsc::abort_t::abort_none) + ctx->abort = abort; + ctx->append(childs); if(stmt->stmt_if.as_list->stmts.size() == 1 && !gsc::node::is_special_stmt(stmt->stmt_if.as_list->stmts.at(0))) @@ -3014,11 +3035,27 @@ void decompiler::process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt void decompiler::process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt) { - ctx->abort = gsc::abort_t::abort_break; + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_break; + } +} + +void decompiler::process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt) +{ + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_continue; + } } void decompiler::process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt) { + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_return; + } + if(stmt->expr.as_node->type == gsc::node_t::null) { return; diff --git a/src/iw7/xsk/decompiler.hpp b/src/iw7/xsk/decompiler.hpp index f713b983..76a1a325 100644 --- a/src/iw7/xsk/decompiler.hpp +++ b/src/iw7/xsk/decompiler.hpp @@ -67,6 +67,7 @@ private: void process_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_switch_ptr& stmt); void process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt_list_ptr& stmt); void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt); + void process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt); void process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt); void process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr); void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); diff --git a/src/iw8/xsk/decompiler.cpp b/src/iw8/xsk/decompiler.cpp index 072def4f..68851a87 100644 --- a/src/iw8/xsk/decompiler.cpp +++ b/src/iw8/xsk/decompiler.cpp @@ -2914,6 +2914,9 @@ void decompiler::process_stmt_if(const gsc::context_ptr& ctx, const gsc::stmt_if void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stmt_ifelse_ptr& stmt) { + std::vector childs; + auto abort = gsc::abort_t::abort_return; + process_expr(ctx, stmt->expr); stmt->ctx_if = std::make_unique(); @@ -2921,12 +2924,30 @@ void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stm process_stmt(stmt->ctx_if, stmt->stmt_if); + if(stmt->ctx_if->abort <= gsc::abort_t::abort_return) + { + abort = stmt->ctx_if->abort; + + if(abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_if.get()); + } + stmt->ctx_else = std::make_unique(); ctx->transfer_decompiler(stmt->ctx_else); process_stmt(stmt->ctx_else, stmt->stmt_else); - std::vector childs({stmt->ctx_if.get(), stmt->ctx_else.get()}); + if(stmt->ctx_else->abort <= abort) + { + abort = stmt->ctx_else->abort; + + if (abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_else.get()); + } + + if(ctx->abort == gsc::abort_t::abort_none) + ctx->abort = abort; + ctx->append(childs); if(stmt->stmt_if.as_list->stmts.size() == 1 && !gsc::node::is_special_stmt(stmt->stmt_if.as_list->stmts.at(0))) @@ -3070,11 +3091,27 @@ void decompiler::process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt void decompiler::process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt) { - ctx->abort = gsc::abort_t::abort_break; + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_break; + } +} + +void decompiler::process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt) +{ + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_continue; + } } void decompiler::process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt) { + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_return; + } + if(stmt->expr.as_node->type == gsc::node_t::null) { return; diff --git a/src/iw8/xsk/decompiler.hpp b/src/iw8/xsk/decompiler.hpp index 9294a295..7a5ba0d6 100644 --- a/src/iw8/xsk/decompiler.hpp +++ b/src/iw8/xsk/decompiler.hpp @@ -67,6 +67,7 @@ private: void process_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_switch_ptr& stmt); void process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt_list_ptr& stmt); void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt); + void process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt); void process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt); void process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr); void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); diff --git a/src/s1/xsk/decompiler.cpp b/src/s1/xsk/decompiler.cpp index 5c244cee..97e857b3 100644 --- a/src/s1/xsk/decompiler.cpp +++ b/src/s1/xsk/decompiler.cpp @@ -2864,6 +2864,9 @@ void decompiler::process_stmt_if(const gsc::context_ptr& ctx, const gsc::stmt_if void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stmt_ifelse_ptr& stmt) { + std::vector childs; + auto abort = gsc::abort_t::abort_return; + process_expr(ctx, stmt->expr); stmt->ctx_if = std::make_unique(); @@ -2871,12 +2874,30 @@ void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stm process_stmt(stmt->ctx_if, stmt->stmt_if); + if(stmt->ctx_if->abort <= gsc::abort_t::abort_return) + { + abort = stmt->ctx_if->abort; + + if(abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_if.get()); + } + stmt->ctx_else = std::make_unique(); ctx->transfer_decompiler(stmt->ctx_else); process_stmt(stmt->ctx_else, stmt->stmt_else); - std::vector childs({stmt->ctx_if.get(), stmt->ctx_else.get()}); + if(stmt->ctx_else->abort <= abort) + { + abort = stmt->ctx_else->abort; + + if (abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_else.get()); + } + + if(ctx->abort == gsc::abort_t::abort_none) + ctx->abort = abort; + ctx->append(childs); if(stmt->stmt_if.as_list->stmts.size() == 1 && !gsc::node::is_special_stmt(stmt->stmt_if.as_list->stmts.at(0))) @@ -3020,11 +3041,27 @@ void decompiler::process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt void decompiler::process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt) { - ctx->abort = gsc::abort_t::abort_break; + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_break; + } +} + +void decompiler::process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt) +{ + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_continue; + } } void decompiler::process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt) { + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_return; + } + if(stmt->expr.as_node->type == gsc::node_t::null) { return; diff --git a/src/s1/xsk/decompiler.hpp b/src/s1/xsk/decompiler.hpp index 88f471e9..3ef29dbd 100644 --- a/src/s1/xsk/decompiler.hpp +++ b/src/s1/xsk/decompiler.hpp @@ -67,6 +67,7 @@ private: void process_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_switch_ptr& stmt); void process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt_list_ptr& stmt); void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt); + void process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt); void process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt); void process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr); void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); diff --git a/src/s2/xsk/decompiler.cpp b/src/s2/xsk/decompiler.cpp index aa00af94..43b300a8 100644 --- a/src/s2/xsk/decompiler.cpp +++ b/src/s2/xsk/decompiler.cpp @@ -2873,6 +2873,9 @@ void decompiler::process_stmt_if(const gsc::context_ptr& ctx, const gsc::stmt_if void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stmt_ifelse_ptr& stmt) { + std::vector childs; + auto abort = gsc::abort_t::abort_return; + process_expr(ctx, stmt->expr); stmt->ctx_if = std::make_unique(); @@ -2880,12 +2883,30 @@ void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stm process_stmt(stmt->ctx_if, stmt->stmt_if); + if(stmt->ctx_if->abort <= gsc::abort_t::abort_return) + { + abort = stmt->ctx_if->abort; + + if(abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_if.get()); + } + stmt->ctx_else = std::make_unique(); ctx->transfer_decompiler(stmt->ctx_else); process_stmt(stmt->ctx_else, stmt->stmt_else); - std::vector childs({stmt->ctx_if.get(), stmt->ctx_else.get()}); + if(stmt->ctx_else->abort <= abort) + { + abort = stmt->ctx_else->abort; + + if (abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_else.get()); + } + + if(ctx->abort == gsc::abort_t::abort_none) + ctx->abort = abort; + ctx->append(childs); if(stmt->stmt_if.as_list->stmts.size() == 1 && !gsc::node::is_special_stmt(stmt->stmt_if.as_list->stmts.at(0))) @@ -3029,11 +3050,27 @@ void decompiler::process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt void decompiler::process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt) { - ctx->abort = gsc::abort_t::abort_break; + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_break; + } +} + +void decompiler::process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt) +{ + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_continue; + } } void decompiler::process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt) { + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_return; + } + if(stmt->expr.as_node->type == gsc::node_t::null) { return; diff --git a/src/s2/xsk/decompiler.hpp b/src/s2/xsk/decompiler.hpp index 253fd7f7..3212da3f 100644 --- a/src/s2/xsk/decompiler.hpp +++ b/src/s2/xsk/decompiler.hpp @@ -67,6 +67,7 @@ private: void process_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_switch_ptr& stmt); void process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt_list_ptr& stmt); void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt); + void process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt); void process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt); void process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr); void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); diff --git a/src/s4/xsk/decompiler.cpp b/src/s4/xsk/decompiler.cpp index 8a426f22..8b5c1472 100644 --- a/src/s4/xsk/decompiler.cpp +++ b/src/s4/xsk/decompiler.cpp @@ -2914,6 +2914,9 @@ void decompiler::process_stmt_if(const gsc::context_ptr& ctx, const gsc::stmt_if void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stmt_ifelse_ptr& stmt) { + std::vector childs; + auto abort = gsc::abort_t::abort_return; + process_expr(ctx, stmt->expr); stmt->ctx_if = std::make_unique(); @@ -2921,12 +2924,30 @@ void decompiler::process_stmt_ifelse(const gsc::context_ptr& ctx, const gsc::stm process_stmt(stmt->ctx_if, stmt->stmt_if); + if(stmt->ctx_if->abort <= gsc::abort_t::abort_return) + { + abort = stmt->ctx_if->abort; + + if(abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_if.get()); + } + stmt->ctx_else = std::make_unique(); ctx->transfer_decompiler(stmt->ctx_else); process_stmt(stmt->ctx_else, stmt->stmt_else); - std::vector childs({stmt->ctx_if.get(), stmt->ctx_else.get()}); + if(stmt->ctx_else->abort <= abort) + { + abort = stmt->ctx_else->abort; + + if (abort == gsc::abort_t::abort_none) + childs.push_back(stmt->ctx_else.get()); + } + + if(ctx->abort == gsc::abort_t::abort_none) + ctx->abort = abort; + ctx->append(childs); if(stmt->stmt_if.as_list->stmts.size() == 1 && !gsc::node::is_special_stmt(stmt->stmt_if.as_list->stmts.at(0))) @@ -3070,11 +3091,27 @@ void decompiler::process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt void decompiler::process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt) { - ctx->abort = gsc::abort_t::abort_break; + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_break; + } +} + +void decompiler::process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt) +{ + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_continue; + } } void decompiler::process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt) { + if(ctx->abort == gsc::abort_t::abort_none) + { + ctx->abort = gsc::abort_t::abort_return; + } + if(stmt->expr.as_node->type == gsc::node_t::null) { return; diff --git a/src/s4/xsk/decompiler.hpp b/src/s4/xsk/decompiler.hpp index 5b004723..4f65d873 100644 --- a/src/s4/xsk/decompiler.hpp +++ b/src/s4/xsk/decompiler.hpp @@ -67,6 +67,7 @@ private: void process_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_switch_ptr& stmt); void process_stmt_cases(const gsc::context_ptr& ctx, const gsc::stmt_list_ptr& stmt); void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_ptr& stmt); + void process_stmt_continue(const gsc::context_ptr& ctx, const gsc::stmt_continue_ptr& stmt); void process_stmt_return(const gsc::context_ptr& ctx, const gsc::stmt_return_ptr& stmt); void process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr); void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr);