From 302e8ab0b18faecc34246bbdf3c23e34ad5498a5 Mon Sep 17 00:00:00 2001 From: xensik <8714336+xensik@users.noreply.github.com> Date: Sun, 9 May 2021 16:01:38 +0200 Subject: [PATCH] decompiler assign ops implementation --- src/h1/xsk/decompiler.cpp | 74 ++++++++++++------ src/h1/xsk/decompiler.hpp | 2 +- src/h2/xsk/decompiler.cpp | 74 ++++++++++++------ src/h2/xsk/decompiler.hpp | 2 +- src/iw5/xsk/decompiler.cpp | 74 ++++++++++++------ src/iw5/xsk/decompiler.hpp | 2 +- src/iw6/xsk/decompiler.cpp | 74 ++++++++++++------ src/iw6/xsk/decompiler.hpp | 2 +- src/iw7/xsk/decompiler.cpp | 74 ++++++++++++------ src/iw7/xsk/decompiler.hpp | 2 +- src/s1/xsk/decompiler.cpp | 74 ++++++++++++------ src/s1/xsk/decompiler.hpp | 2 +- src/s2/xsk/decompiler.cpp | 74 ++++++++++++------ src/s2/xsk/decompiler.hpp | 2 +- src/utils/xsk/gsc/nodetree.hpp | 135 ++++++++++++++++++++++++++++++++- src/utils/xsk/utils.cpp | 63 ++++++++++++++- 16 files changed, 553 insertions(+), 177 deletions(-) diff --git a/src/h1/xsk/decompiler.cpp b/src/h1/xsk/decompiler.cpp index 1c5057d3..4ada9f63 100644 --- a/src/h1/xsk/decompiler.cpp +++ b/src/h1/xsk/decompiler.cpp @@ -546,7 +546,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_ScriptLocalMethodChildThreadCall: { - // TODO: child things... auto obj = gsc::expr_ptr(std::move(stack_.top())); stack_.pop(); loc = obj.as_node->loc; @@ -1395,7 +1394,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) stack_.pop(); args->loc = node->loc; args->list.push_back(std::move(node)); - } loc = args->loc; @@ -1425,9 +1423,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) } break; case opcode::OP_checkclearparams: - { - // no needed - } break; case opcode::OP_notify: { @@ -1736,9 +1731,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_CastFieldObject: case opcode::OP_CastBool: - { - //continue; - } break; case opcode::OP_BoolNot: { @@ -1780,7 +1772,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) { auto expr = std::make_unique(loc, inst->data[0]); func_->block->stmts.push_back(gsc::stmt_ptr(std::move(expr))); - } break; case opcode::OP_jumpback: @@ -1871,20 +1862,6 @@ void decompiler::decompile_block(const gsc::stmt_list_ptr& block) this->decompile_search_switch(block); this->decompile_search_ifelse(block); this->decompile_break_continue(block); - this->decompile_nulls(block); -} - -void decompiler::decompile_nulls(const gsc::stmt_list_ptr& block) -{ - auto index = 0; - while(index < block->stmts.size()) - { - if(block->stmts.at(index).as_node->type == gsc::node_t::null) - { - block->stmts.erase(block->stmts.begin() + index); - } - else index++; - } } void decompiler::decompile_search_infinite(const gsc::stmt_list_ptr& block) @@ -2991,7 +2968,7 @@ void decompiler::process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr) } } -void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::expr_assign_ptr& expr) +void decompiler::process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr) { if(expr->type == gsc::node_t::expr_increment) { @@ -3005,6 +2982,55 @@ void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->rvalue); process_expr(ctx, expr->lvalue); + + if(expr->type == gsc::node_t::expr_assign_equal) + { + switch(expr->rvalue.as_node->type) + { + case gsc::node_t::expr_bitwise_or: + if(expr->lvalue == expr->rvalue.as_bitwise_or->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_and: + if(expr->lvalue == expr->rvalue.as_bitwise_and->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_exor: + if(expr->lvalue == expr->rvalue.as_bitwise_exor->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_left: + if(expr->lvalue == expr->rvalue.as_shift_left->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_right: + if(expr->lvalue == expr->rvalue.as_shift_right->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_add: + if(expr->lvalue == expr->rvalue.as_add->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_sub: + if(expr->lvalue == expr->rvalue.as_sub->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mult: + if(expr->lvalue == expr->rvalue.as_mult->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_div: + if(expr->lvalue == expr->rvalue.as_div->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mod: + if(expr->lvalue == expr->rvalue.as_mod->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + default: + break; + } + } } } diff --git a/src/h1/xsk/decompiler.hpp b/src/h1/xsk/decompiler.hpp index f5a8dde1..0b0af2a6 100644 --- a/src/h1/xsk/decompiler.hpp +++ b/src/h1/xsk/decompiler.hpp @@ -68,7 +68,7 @@ private: void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_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, const gsc::expr_assign_ptr& expr); + void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); void process_expr_binary(const gsc::context_ptr& ctx, const gsc::expr_binary_ptr& expr); void process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr); void process_expr_or(const gsc::context_ptr& ctx, const gsc::expr_or_ptr& expr); diff --git a/src/h2/xsk/decompiler.cpp b/src/h2/xsk/decompiler.cpp index f1fe2372..10a2d110 100644 --- a/src/h2/xsk/decompiler.cpp +++ b/src/h2/xsk/decompiler.cpp @@ -546,7 +546,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_ScriptLocalMethodChildThreadCall: { - // TODO: child things... auto obj = gsc::expr_ptr(std::move(stack_.top())); stack_.pop(); loc = obj.as_node->loc; @@ -1395,7 +1394,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) stack_.pop(); args->loc = node->loc; args->list.push_back(std::move(node)); - } loc = args->loc; @@ -1425,9 +1423,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) } break; case opcode::OP_checkclearparams: - { - // no needed - } break; case opcode::OP_notify: { @@ -1736,9 +1731,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_CastFieldObject: case opcode::OP_CastBool: - { - //continue; - } break; case opcode::OP_BoolNot: { @@ -1780,7 +1772,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) { auto expr = std::make_unique(loc, inst->data[0]); func_->block->stmts.push_back(gsc::stmt_ptr(std::move(expr))); - } break; case opcode::OP_jumpback: @@ -1871,20 +1862,6 @@ void decompiler::decompile_block(const gsc::stmt_list_ptr& block) this->decompile_search_switch(block); this->decompile_search_ifelse(block); this->decompile_break_continue(block); - this->decompile_nulls(block); -} - -void decompiler::decompile_nulls(const gsc::stmt_list_ptr& block) -{ - auto index = 0; - while(index < block->stmts.size()) - { - if(block->stmts.at(index).as_node->type == gsc::node_t::null) - { - block->stmts.erase(block->stmts.begin() + index); - } - else index++; - } } void decompiler::decompile_search_infinite(const gsc::stmt_list_ptr& block) @@ -2991,7 +2968,7 @@ void decompiler::process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr) } } -void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::expr_assign_ptr& expr) +void decompiler::process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr) { if(expr->type == gsc::node_t::expr_increment) { @@ -3005,6 +2982,55 @@ void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->rvalue); process_expr(ctx, expr->lvalue); + + if(expr->type == gsc::node_t::expr_assign_equal) + { + switch(expr->rvalue.as_node->type) + { + case gsc::node_t::expr_bitwise_or: + if(expr->lvalue == expr->rvalue.as_bitwise_or->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_and: + if(expr->lvalue == expr->rvalue.as_bitwise_and->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_exor: + if(expr->lvalue == expr->rvalue.as_bitwise_exor->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_left: + if(expr->lvalue == expr->rvalue.as_shift_left->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_right: + if(expr->lvalue == expr->rvalue.as_shift_right->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_add: + if(expr->lvalue == expr->rvalue.as_add->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_sub: + if(expr->lvalue == expr->rvalue.as_sub->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mult: + if(expr->lvalue == expr->rvalue.as_mult->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_div: + if(expr->lvalue == expr->rvalue.as_div->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mod: + if(expr->lvalue == expr->rvalue.as_mod->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + default: + break; + } + } } } diff --git a/src/h2/xsk/decompiler.hpp b/src/h2/xsk/decompiler.hpp index c83e7b5e..2fbdb1af 100644 --- a/src/h2/xsk/decompiler.hpp +++ b/src/h2/xsk/decompiler.hpp @@ -68,7 +68,7 @@ private: void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_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, const gsc::expr_assign_ptr& expr); + void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); void process_expr_binary(const gsc::context_ptr& ctx, const gsc::expr_binary_ptr& expr); void process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr); void process_expr_or(const gsc::context_ptr& ctx, const gsc::expr_or_ptr& expr); diff --git a/src/iw5/xsk/decompiler.cpp b/src/iw5/xsk/decompiler.cpp index 9695e4f0..26baa465 100644 --- a/src/iw5/xsk/decompiler.cpp +++ b/src/iw5/xsk/decompiler.cpp @@ -546,7 +546,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_ScriptLocalMethodChildThreadCall: { - // TODO: child things... auto obj = gsc::expr_ptr(std::move(stack_.top())); stack_.pop(); loc = obj.as_node->loc; @@ -1389,7 +1388,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) stack_.pop(); args->loc = node->loc; args->list.push_back(std::move(node)); - } loc = args->loc; @@ -1419,9 +1417,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) } break; case opcode::OP_checkclearparams: - { - // no needed - } break; case opcode::OP_notify: { @@ -1730,9 +1725,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_CastFieldObject: case opcode::OP_CastBool: - { - //continue; - } break; case opcode::OP_BoolNot: { @@ -1774,7 +1766,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) { auto expr = std::make_unique(loc, inst->data[0]); func_->block->stmts.push_back(gsc::stmt_ptr(std::move(expr))); - } break; case opcode::OP_jumpback: @@ -1865,20 +1856,6 @@ void decompiler::decompile_block(const gsc::stmt_list_ptr& block) this->decompile_search_switch(block); this->decompile_search_ifelse(block); this->decompile_break_continue(block); - this->decompile_nulls(block); -} - -void decompiler::decompile_nulls(const gsc::stmt_list_ptr& block) -{ - auto index = 0; - while(index < block->stmts.size()) - { - if(block->stmts.at(index).as_node->type == gsc::node_t::null) - { - block->stmts.erase(block->stmts.begin() + index); - } - else index++; - } } void decompiler::decompile_search_infinite(const gsc::stmt_list_ptr& block) @@ -2985,7 +2962,7 @@ void decompiler::process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr) } } -void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::expr_assign_ptr& expr) +void decompiler::process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr) { if(expr->type == gsc::node_t::expr_increment) { @@ -2999,6 +2976,55 @@ void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->rvalue); process_expr(ctx, expr->lvalue); + + if(expr->type == gsc::node_t::expr_assign_equal) + { + switch(expr->rvalue.as_node->type) + { + case gsc::node_t::expr_bitwise_or: + if(expr->lvalue == expr->rvalue.as_bitwise_or->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_and: + if(expr->lvalue == expr->rvalue.as_bitwise_and->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_exor: + if(expr->lvalue == expr->rvalue.as_bitwise_exor->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_left: + if(expr->lvalue == expr->rvalue.as_shift_left->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_right: + if(expr->lvalue == expr->rvalue.as_shift_right->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_add: + if(expr->lvalue == expr->rvalue.as_add->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_sub: + if(expr->lvalue == expr->rvalue.as_sub->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mult: + if(expr->lvalue == expr->rvalue.as_mult->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_div: + if(expr->lvalue == expr->rvalue.as_div->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mod: + if(expr->lvalue == expr->rvalue.as_mod->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + default: + break; + } + } } } diff --git a/src/iw5/xsk/decompiler.hpp b/src/iw5/xsk/decompiler.hpp index 14fab3c3..1c3936a1 100644 --- a/src/iw5/xsk/decompiler.hpp +++ b/src/iw5/xsk/decompiler.hpp @@ -68,7 +68,7 @@ private: void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_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, const gsc::expr_assign_ptr& expr); + void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); void process_expr_binary(const gsc::context_ptr& ctx, const gsc::expr_binary_ptr& expr); void process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr); void process_expr_or(const gsc::context_ptr& ctx, const gsc::expr_or_ptr& expr); diff --git a/src/iw6/xsk/decompiler.cpp b/src/iw6/xsk/decompiler.cpp index 18f2e8ed..aadd77cb 100644 --- a/src/iw6/xsk/decompiler.cpp +++ b/src/iw6/xsk/decompiler.cpp @@ -546,7 +546,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_ScriptLocalMethodChildThreadCall: { - // TODO: child things... auto obj = gsc::expr_ptr(std::move(stack_.top())); stack_.pop(); loc = obj.as_node->loc; @@ -1389,7 +1388,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) stack_.pop(); args->loc = node->loc; args->list.push_back(std::move(node)); - } loc = args->loc; @@ -1419,9 +1417,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) } break; case opcode::OP_checkclearparams: - { - // no needed - } break; case opcode::OP_notify: { @@ -1730,9 +1725,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_CastFieldObject: case opcode::OP_CastBool: - { - //continue; - } break; case opcode::OP_BoolNot: { @@ -1774,7 +1766,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) { auto expr = std::make_unique(loc, inst->data[0]); func_->block->stmts.push_back(gsc::stmt_ptr(std::move(expr))); - } break; case opcode::OP_jumpback: @@ -1865,20 +1856,6 @@ void decompiler::decompile_block(const gsc::stmt_list_ptr& block) this->decompile_search_switch(block); this->decompile_search_ifelse(block); this->decompile_break_continue(block); - this->decompile_nulls(block); -} - -void decompiler::decompile_nulls(const gsc::stmt_list_ptr& block) -{ - auto index = 0; - while(index < block->stmts.size()) - { - if(block->stmts.at(index).as_node->type == gsc::node_t::null) - { - block->stmts.erase(block->stmts.begin() + index); - } - else index++; - } } void decompiler::decompile_search_infinite(const gsc::stmt_list_ptr& block) @@ -2985,7 +2962,7 @@ void decompiler::process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr) } } -void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::expr_assign_ptr& expr) +void decompiler::process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr) { if(expr->type == gsc::node_t::expr_increment) { @@ -2999,6 +2976,55 @@ void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->rvalue); process_expr(ctx, expr->lvalue); + + if(expr->type == gsc::node_t::expr_assign_equal) + { + switch(expr->rvalue.as_node->type) + { + case gsc::node_t::expr_bitwise_or: + if(expr->lvalue == expr->rvalue.as_bitwise_or->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_and: + if(expr->lvalue == expr->rvalue.as_bitwise_and->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_exor: + if(expr->lvalue == expr->rvalue.as_bitwise_exor->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_left: + if(expr->lvalue == expr->rvalue.as_shift_left->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_right: + if(expr->lvalue == expr->rvalue.as_shift_right->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_add: + if(expr->lvalue == expr->rvalue.as_add->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_sub: + if(expr->lvalue == expr->rvalue.as_sub->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mult: + if(expr->lvalue == expr->rvalue.as_mult->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_div: + if(expr->lvalue == expr->rvalue.as_div->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mod: + if(expr->lvalue == expr->rvalue.as_mod->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + default: + break; + } + } } } diff --git a/src/iw6/xsk/decompiler.hpp b/src/iw6/xsk/decompiler.hpp index 75e9e628..cae06199 100644 --- a/src/iw6/xsk/decompiler.hpp +++ b/src/iw6/xsk/decompiler.hpp @@ -68,7 +68,7 @@ private: void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_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, const gsc::expr_assign_ptr& expr); + void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); void process_expr_binary(const gsc::context_ptr& ctx, const gsc::expr_binary_ptr& expr); void process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr); void process_expr_or(const gsc::context_ptr& ctx, const gsc::expr_or_ptr& expr); diff --git a/src/iw7/xsk/decompiler.cpp b/src/iw7/xsk/decompiler.cpp index 4ce7afd1..7eb304e4 100644 --- a/src/iw7/xsk/decompiler.cpp +++ b/src/iw7/xsk/decompiler.cpp @@ -546,7 +546,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_ScriptLocalMethodChildThreadCall: { - // TODO: child things... auto obj = gsc::expr_ptr(std::move(stack_.top())); stack_.pop(); loc = obj.as_node->loc; @@ -1389,7 +1388,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) stack_.pop(); args->loc = node->loc; args->list.push_back(std::move(node)); - } loc = args->loc; @@ -1419,9 +1417,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) } break; case opcode::OP_checkclearparams: - { - // no needed - } break; case opcode::OP_notify: { @@ -1730,9 +1725,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_CastFieldObject: case opcode::OP_CastBool: - { - //continue; - } break; case opcode::OP_BoolNot: { @@ -1774,7 +1766,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) { auto expr = std::make_unique(loc, inst->data[0]); func_->block->stmts.push_back(gsc::stmt_ptr(std::move(expr))); - } break; case opcode::OP_jumpback: @@ -1865,20 +1856,6 @@ void decompiler::decompile_block(const gsc::stmt_list_ptr& block) this->decompile_search_switch(block); this->decompile_search_ifelse(block); this->decompile_break_continue(block); - this->decompile_nulls(block); -} - -void decompiler::decompile_nulls(const gsc::stmt_list_ptr& block) -{ - auto index = 0; - while(index < block->stmts.size()) - { - if(block->stmts.at(index).as_node->type == gsc::node_t::null) - { - block->stmts.erase(block->stmts.begin() + index); - } - else index++; - } } void decompiler::decompile_search_infinite(const gsc::stmt_list_ptr& block) @@ -2985,7 +2962,7 @@ void decompiler::process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr) } } -void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::expr_assign_ptr& expr) +void decompiler::process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr) { if(expr->type == gsc::node_t::expr_increment) { @@ -2999,6 +2976,55 @@ void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->rvalue); process_expr(ctx, expr->lvalue); + + if(expr->type == gsc::node_t::expr_assign_equal) + { + switch(expr->rvalue.as_node->type) + { + case gsc::node_t::expr_bitwise_or: + if(expr->lvalue == expr->rvalue.as_bitwise_or->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_and: + if(expr->lvalue == expr->rvalue.as_bitwise_and->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_exor: + if(expr->lvalue == expr->rvalue.as_bitwise_exor->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_left: + if(expr->lvalue == expr->rvalue.as_shift_left->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_right: + if(expr->lvalue == expr->rvalue.as_shift_right->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_add: + if(expr->lvalue == expr->rvalue.as_add->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_sub: + if(expr->lvalue == expr->rvalue.as_sub->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mult: + if(expr->lvalue == expr->rvalue.as_mult->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_div: + if(expr->lvalue == expr->rvalue.as_div->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mod: + if(expr->lvalue == expr->rvalue.as_mod->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + default: + break; + } + } } } diff --git a/src/iw7/xsk/decompiler.hpp b/src/iw7/xsk/decompiler.hpp index 96f56888..63711da5 100644 --- a/src/iw7/xsk/decompiler.hpp +++ b/src/iw7/xsk/decompiler.hpp @@ -68,7 +68,7 @@ private: void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_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, const gsc::expr_assign_ptr& expr); + void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); void process_expr_binary(const gsc::context_ptr& ctx, const gsc::expr_binary_ptr& expr); void process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr); void process_expr_or(const gsc::context_ptr& ctx, const gsc::expr_or_ptr& expr); diff --git a/src/s1/xsk/decompiler.cpp b/src/s1/xsk/decompiler.cpp index 4f6e40df..fe43b069 100644 --- a/src/s1/xsk/decompiler.cpp +++ b/src/s1/xsk/decompiler.cpp @@ -546,7 +546,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_ScriptLocalMethodChildThreadCall: { - // TODO: child things... auto obj = gsc::expr_ptr(std::move(stack_.top())); stack_.pop(); loc = obj.as_node->loc; @@ -1395,7 +1394,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) stack_.pop(); args->loc = node->loc; args->list.push_back(std::move(node)); - } loc = args->loc; @@ -1425,9 +1423,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) } break; case opcode::OP_checkclearparams: - { - // no needed - } break; case opcode::OP_notify: { @@ -1736,9 +1731,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_CastFieldObject: case opcode::OP_CastBool: - { - //continue; - } break; case opcode::OP_BoolNot: { @@ -1780,7 +1772,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) { auto expr = std::make_unique(loc, inst->data[0]); func_->block->stmts.push_back(gsc::stmt_ptr(std::move(expr))); - } break; case opcode::OP_jumpback: @@ -1871,20 +1862,6 @@ void decompiler::decompile_block(const gsc::stmt_list_ptr& block) this->decompile_search_switch(block); this->decompile_search_ifelse(block); this->decompile_break_continue(block); - this->decompile_nulls(block); -} - -void decompiler::decompile_nulls(const gsc::stmt_list_ptr& block) -{ - auto index = 0; - while(index < block->stmts.size()) - { - if(block->stmts.at(index).as_node->type == gsc::node_t::null) - { - block->stmts.erase(block->stmts.begin() + index); - } - else index++; - } } void decompiler::decompile_search_infinite(const gsc::stmt_list_ptr& block) @@ -2991,7 +2968,7 @@ void decompiler::process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr) } } -void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::expr_assign_ptr& expr) +void decompiler::process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr) { if(expr->type == gsc::node_t::expr_increment) { @@ -3005,6 +2982,55 @@ void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->rvalue); process_expr(ctx, expr->lvalue); + + if(expr->type == gsc::node_t::expr_assign_equal) + { + switch(expr->rvalue.as_node->type) + { + case gsc::node_t::expr_bitwise_or: + if(expr->lvalue == expr->rvalue.as_bitwise_or->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_and: + if(expr->lvalue == expr->rvalue.as_bitwise_and->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_exor: + if(expr->lvalue == expr->rvalue.as_bitwise_exor->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_left: + if(expr->lvalue == expr->rvalue.as_shift_left->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_right: + if(expr->lvalue == expr->rvalue.as_shift_right->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_add: + if(expr->lvalue == expr->rvalue.as_add->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_sub: + if(expr->lvalue == expr->rvalue.as_sub->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mult: + if(expr->lvalue == expr->rvalue.as_mult->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_div: + if(expr->lvalue == expr->rvalue.as_div->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mod: + if(expr->lvalue == expr->rvalue.as_mod->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + default: + break; + } + } } } diff --git a/src/s1/xsk/decompiler.hpp b/src/s1/xsk/decompiler.hpp index 7c8992da..c9a46e4e 100644 --- a/src/s1/xsk/decompiler.hpp +++ b/src/s1/xsk/decompiler.hpp @@ -68,7 +68,7 @@ private: void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_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, const gsc::expr_assign_ptr& expr); + void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); void process_expr_binary(const gsc::context_ptr& ctx, const gsc::expr_binary_ptr& expr); void process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr); void process_expr_or(const gsc::context_ptr& ctx, const gsc::expr_or_ptr& expr); diff --git a/src/s2/xsk/decompiler.cpp b/src/s2/xsk/decompiler.cpp index 3944b2c8..3ae492cb 100644 --- a/src/s2/xsk/decompiler.cpp +++ b/src/s2/xsk/decompiler.cpp @@ -546,7 +546,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_ScriptLocalMethodChildThreadCall: { - // TODO: child things... auto obj = gsc::expr_ptr(std::move(stack_.top())); stack_.pop(); loc = obj.as_node->loc; @@ -1395,7 +1394,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) stack_.pop(); args->loc = node->loc; args->list.push_back(std::move(node)); - } loc = args->loc; @@ -1425,9 +1423,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) } break; case opcode::OP_checkclearparams: - { - // no needed - } break; case opcode::OP_notify: { @@ -1736,9 +1731,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) break; case opcode::OP_CastFieldObject: case opcode::OP_CastBool: - { - //continue; - } break; case opcode::OP_BoolNot: { @@ -1780,7 +1772,6 @@ void decompiler::decompile_statements(const gsc::function_ptr& func) { auto expr = std::make_unique(loc, inst->data[0]); func_->block->stmts.push_back(gsc::stmt_ptr(std::move(expr))); - } break; case opcode::OP_jumpback: @@ -1880,20 +1871,6 @@ void decompiler::decompile_block(const gsc::stmt_list_ptr& block) this->decompile_search_switch(block); this->decompile_search_ifelse(block); this->decompile_break_continue(block); - this->decompile_nulls(block); -} - -void decompiler::decompile_nulls(const gsc::stmt_list_ptr& block) -{ - auto index = 0; - while(index < block->stmts.size()) - { - if(block->stmts.at(index).as_node->type == gsc::node_t::null) - { - block->stmts.erase(block->stmts.begin() + index); - } - else index++; - } } void decompiler::decompile_search_infinite(const gsc::stmt_list_ptr& block) @@ -3000,7 +2977,7 @@ void decompiler::process_expr(const gsc::context_ptr& ctx, gsc::expr_ptr& expr) } } -void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::expr_assign_ptr& expr) +void decompiler::process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr) { if(expr->type == gsc::node_t::expr_increment) { @@ -3014,6 +2991,55 @@ void decompiler::process_expr_assign(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->rvalue); process_expr(ctx, expr->lvalue); + + if(expr->type == gsc::node_t::expr_assign_equal) + { + switch(expr->rvalue.as_node->type) + { + case gsc::node_t::expr_bitwise_or: + if(expr->lvalue == expr->rvalue.as_bitwise_or->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_and: + if(expr->lvalue == expr->rvalue.as_bitwise_and->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_bitwise_exor: + if(expr->lvalue == expr->rvalue.as_bitwise_exor->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_left: + if(expr->lvalue == expr->rvalue.as_shift_left->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_shift_right: + if(expr->lvalue == expr->rvalue.as_shift_right->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_add: + if(expr->lvalue == expr->rvalue.as_add->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_sub: + if(expr->lvalue == expr->rvalue.as_sub->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mult: + if(expr->lvalue == expr->rvalue.as_mult->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_div: + if(expr->lvalue == expr->rvalue.as_div->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + case gsc::node_t::expr_mod: + if(expr->lvalue == expr->rvalue.as_mod->lvalue) + expr = std::make_unique(std::move(expr->lvalue), std::move(expr->rvalue.as_mod->rvalue)); + break; + default: + break; + } + } } } diff --git a/src/s2/xsk/decompiler.hpp b/src/s2/xsk/decompiler.hpp index f90bd96f..a02fbde5 100644 --- a/src/s2/xsk/decompiler.hpp +++ b/src/s2/xsk/decompiler.hpp @@ -68,7 +68,7 @@ private: void process_stmt_break(const gsc::context_ptr& ctx, const gsc::stmt_break_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, const gsc::expr_assign_ptr& expr); + void process_expr_assign(const gsc::context_ptr& ctx, gsc::expr_assign_ptr& expr); void process_expr_binary(const gsc::context_ptr& ctx, const gsc::expr_binary_ptr& expr); void process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr); void process_expr_or(const gsc::context_ptr& ctx, const gsc::expr_or_ptr& expr); diff --git a/src/utils/xsk/gsc/nodetree.hpp b/src/utils/xsk/gsc/nodetree.hpp index 7f16abbd..f6011274 100644 --- a/src/utils/xsk/gsc/nodetree.hpp +++ b/src/utils/xsk/gsc/nodetree.hpp @@ -29,6 +29,7 @@ enum class node_t data_undefined, data_empty_array, data_thisthread, + expr_paren, expr_size, expr_field, expr_array, @@ -134,6 +135,7 @@ struct node_game; struct node_undefined; struct node_empty_array; struct node_thisthread; +struct node_expr_paren; struct node_expr_size; struct node_expr_field; struct node_expr_array; @@ -237,6 +239,7 @@ using game_ptr = std::unique_ptr; using undefined_ptr = std::unique_ptr; using empty_array_ptr = std::unique_ptr; using thisthread_ptr = std::unique_ptr; +using expr_paren_ptr = std::unique_ptr; using expr_size_ptr = std::unique_ptr; using expr_field_ptr = std::unique_ptr; using expr_array_ptr = std::unique_ptr; @@ -354,6 +357,7 @@ union expr_ptr undefined_ptr as_undefined; empty_array_ptr as_empty_array; thisthread_ptr as_thisthread; + expr_paren_ptr as_paren; expr_size_ptr as_size; expr_field_ptr as_field; expr_array_ptr as_array; @@ -408,12 +412,15 @@ union expr_ptr new(&as_node) node_ptr(std::move(val.as_node)); } + ~expr_ptr(){} + expr_ptr& operator=(expr_ptr && val) { new(&as_node) node_ptr(std::move(val.as_node)); return *(expr_ptr*)&as_node; } - ~expr_ptr(){} + + bool operator==(const expr_ptr& rhs) const; }; union stmt_ptr @@ -542,6 +549,11 @@ struct node_true : public node { return "true"; } + + friend bool operator==(const node_true& lhs, const node_true& rhs) + { + return true; + } }; struct node_false : public node @@ -553,6 +565,11 @@ struct node_false : public node { return "false"; } + + friend bool operator==(const node_false& lhs, const node_false& rhs) + { + return true; + } }; struct node_integer : public node @@ -569,6 +586,11 @@ struct node_integer : public node { return value; } + + friend bool operator==(const node_integer& lhs, const node_integer& rhs) + { + return lhs.value == rhs.value; + } }; struct node_float : public node @@ -585,6 +607,11 @@ struct node_float : public node { return value; } + + friend bool operator==(const node_float& lhs, const node_float& rhs) + { + return lhs.value == rhs.value; + } }; struct node_vector : public node @@ -603,6 +630,11 @@ struct node_vector : public node { return "( "s + x.as_node->print() + ", " + y.as_node->print() + ", "+ z.as_node->print() + " )"; } + + friend bool operator==(const node_vector& lhs, const node_vector& rhs) + { + return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z; + } }; struct node_string : public node @@ -619,6 +651,11 @@ struct node_string : public node { return value; } + + friend bool operator==(const node_string& lhs, const node_string& rhs) + { + return lhs.value == rhs.value; + } }; struct node_istring : public node @@ -635,6 +672,11 @@ struct node_istring : public node { return "&"s += value; } + + friend bool operator==(const node_istring& lhs, const node_istring& rhs) + { + return lhs.value == rhs.value; + } }; struct node_file : public node @@ -656,6 +698,11 @@ struct node_file : public node { return value; } + + friend bool operator==(const node_file& lhs, const node_file& rhs) + { + return lhs.value == rhs.value; + } }; struct node_name : public node @@ -672,6 +719,11 @@ struct node_name : public node { return value; } + + friend bool operator==(const node_name& lhs, const node_name& rhs) + { + return lhs.value == rhs.value; + } }; struct node_animtree : public node @@ -684,6 +736,11 @@ struct node_animtree : public node { return "#animtree"; } + + friend bool operator==(const node_animtree& lhs, const node_animtree& rhs) + { + return true; + } }; struct node_animation : public node @@ -700,6 +757,11 @@ struct node_animation : public node { return "%"s += value; } + + friend bool operator==(const node_animation& lhs, const node_animation& rhs) + { + return lhs.value == rhs.value; + } }; struct node_level : public node @@ -712,6 +774,11 @@ struct node_level : public node { return "level"; } + + friend bool operator==(const node_level& lhs, const node_level& rhs) + { + return true; + } }; struct node_anim : public node @@ -724,6 +791,11 @@ struct node_anim : public node { return "anim"; } + + friend bool operator==(const node_anim& lhs, const node_anim& rhs) + { + return true; + } }; struct node_self : public node @@ -736,6 +808,11 @@ struct node_self : public node { return "self"; } + + friend bool operator==(const node_self& lhs, const node_self& rhs) + { + return true; + } }; struct node_game : public node @@ -748,6 +825,11 @@ struct node_game : public node { return "game"; } + + friend bool operator==(const node_game& lhs, const node_game& rhs) + { + return true; + } }; struct node_undefined : public node @@ -760,6 +842,11 @@ struct node_undefined : public node { return "undefined"; } + + friend bool operator==(const node_undefined& lhs, const node_undefined& rhs) + { + return true; + } }; struct node_empty_array : public node @@ -772,6 +859,11 @@ struct node_empty_array : public node { return "[]"; } + + friend bool operator==(const node_empty_array& lhs, const node_empty_array& rhs) + { + return true; + } }; struct node_thisthread : public node @@ -784,6 +876,32 @@ struct node_thisthread : public node { return "thisthread"; } + + friend bool operator==(const node_thisthread& lhs, const node_thisthread& rhs) + { + return true; + } +}; + +struct node_expr_paren : public node +{ + expr_ptr expr; + + node_expr_paren(expr_ptr expr) + : node(node_t::expr_paren), expr(std::move(expr)) {} + + node_expr_paren(const location& loc, expr_ptr expr) + : node(node_t::expr_paren, loc), expr(std::move(expr)) {} + + auto print() -> std::string override + { + return "(" + expr.as_node->print() + ")"; + } + + friend bool operator==(const node_expr_paren& lhs, const node_expr_paren& rhs) + { + return lhs.expr == rhs.expr; + } }; struct node_expr_size : public node @@ -800,6 +918,11 @@ struct node_expr_size : public node { return obj.as_node->print() + ".size"; } + + friend bool operator==(const node_expr_size& lhs, const node_expr_size& rhs) + { + return lhs.obj == rhs.obj; + } }; struct node_expr_field : public node @@ -817,6 +940,11 @@ struct node_expr_field : public node { return obj.as_node->print() + "." + field->print(); } + + friend bool operator==(const node_expr_field& lhs, const node_expr_field& rhs) + { + return lhs.obj == rhs.obj && lhs.field == rhs.field; + } }; struct node_expr_array : public node @@ -834,6 +962,11 @@ struct node_expr_array : public node { return obj.as_node->print() + "[" + key.as_node->print() + "]"; } + + friend bool operator==(const node_expr_array& lhs, const node_expr_array& rhs) + { + return lhs.obj == rhs.obj && lhs.key == rhs.key; + } }; struct node_expr_arguments : public node diff --git a/src/utils/xsk/utils.cpp b/src/utils/xsk/utils.cpp index 7fbc37e8..8aa3f618 100644 --- a/src/utils/xsk/utils.cpp +++ b/src/utils/xsk/utils.cpp @@ -5,4 +5,65 @@ #include "stdafx.hpp" -std::uint32_t xsk::gsc::node::indent_; +namespace xsk +{ + +std::uint32_t gsc::node::indent_; + +bool gsc::expr_ptr::operator==(const gsc::expr_ptr& rhs) const +{ + if(as_node->type != rhs.as_node->type) + return false; + + switch(as_node->type) + { + case gsc::node_t::data_true: + return *as_true == *rhs.as_true; + case gsc::node_t::data_false: + return *as_false == *rhs.as_false; + case gsc::node_t::data_integer: + return *as_integer == *rhs.as_integer; + case gsc::node_t::data_float: + return *as_float == *rhs.as_float; + case gsc::node_t::data_vector: + return *as_vector == *rhs.as_vector; + case gsc::node_t::data_string: + return *as_string == *rhs.as_string; + case gsc::node_t::data_istring: + return *as_istring == *rhs.as_istring; + case gsc::node_t::data_file: + return *as_file == *rhs.as_file; + case gsc::node_t::data_name: + return *as_name == *rhs.as_name; + case gsc::node_t::data_animtree: + return *as_animtree == *rhs.as_animtree; + case gsc::node_t::data_animation: + return *as_animation == *rhs.as_animation; + case gsc::node_t::data_level: + return *as_level == *rhs.as_level; + case gsc::node_t::data_anim: + return *as_anim == *rhs.as_anim; + case gsc::node_t::data_self: + return *as_self == *rhs.as_self; + case gsc::node_t::data_game: + return *as_game == *rhs.as_game; + case gsc::node_t::data_undefined: + return *as_undefined == *rhs.as_undefined; + case gsc::node_t::data_empty_array: + return *as_empty_array == *rhs.as_empty_array; + case gsc::node_t::data_thisthread: + return *as_thisthread == *rhs.as_thisthread; + case gsc::node_t::expr_paren: + return *as_paren == *rhs.as_paren; + case gsc::node_t::expr_size: + return *as_size == *rhs.as_size; + case gsc::node_t::expr_field: + return *as_field == *rhs.as_field; + case gsc::node_t::expr_array: + return *as_array == *rhs.as_array; + default: + return false; + } +} + +} // namespace xsk