diff --git a/src/h1/xsk/decompiler.cpp b/src/h1/xsk/decompiler.cpp index 4ada9f63..62a230be 100644 --- a/src/h1/xsk/decompiler.cpp +++ b/src/h1/xsk/decompiler.cpp @@ -3038,12 +3038,40 @@ void decompiler::process_expr_binary(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr) { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::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 10a2d110..3714724f 100644 --- a/src/h2/xsk/decompiler.cpp +++ b/src/h2/xsk/decompiler.cpp @@ -3038,12 +3038,40 @@ void decompiler::process_expr_binary(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr) { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::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 26baa465..13ddd182 100644 --- a/src/iw5/xsk/decompiler.cpp +++ b/src/iw5/xsk/decompiler.cpp @@ -3032,12 +3032,40 @@ void decompiler::process_expr_binary(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr) { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::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 aadd77cb..71cb8954 100644 --- a/src/iw6/xsk/decompiler.cpp +++ b/src/iw6/xsk/decompiler.cpp @@ -3032,12 +3032,40 @@ void decompiler::process_expr_binary(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr) { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::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 7eb304e4..f483731b 100644 --- a/src/iw7/xsk/decompiler.cpp +++ b/src/iw7/xsk/decompiler.cpp @@ -3032,12 +3032,40 @@ void decompiler::process_expr_binary(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr) { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::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 fe43b069..013bef67 100644 --- a/src/s1/xsk/decompiler.cpp +++ b/src/s1/xsk/decompiler.cpp @@ -3038,12 +3038,40 @@ void decompiler::process_expr_binary(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr) { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::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 3ae492cb..b112cb35 100644 --- a/src/s2/xsk/decompiler.cpp +++ b/src/s2/xsk/decompiler.cpp @@ -3047,12 +3047,40 @@ void decompiler::process_expr_binary(const gsc::context_ptr& ctx, const gsc::exp { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::process_expr_and(const gsc::context_ptr& ctx, const gsc::expr_and_ptr& expr) { process_expr(ctx, expr->lvalue); process_expr(ctx, expr->rvalue); + + auto prec = expr->lvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->lvalue = expr_ptr(std::make_unique(std::move(expr->lvalue))); + } + + prec = expr->rvalue.as_node->precedence(); + + if(prec && prec < expr->precedence()) + { + expr->rvalue = expr_ptr(std::make_unique(std::move(expr->rvalue))); + } } void decompiler::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 4440f485..9acb15cc 100644 --- a/src/utils/xsk/gsc/nodetree.hpp +++ b/src/utils/xsk/gsc/nodetree.hpp @@ -538,6 +538,32 @@ public: return false; } } + + auto precedence() -> std::uint8_t + { + switch(type) + { + case gsc::node_t::expr_or: return 1; + case gsc::node_t::expr_and: return 2; + case gsc::node_t::expr_bitwise_or: return 3; + case gsc::node_t::expr_bitwise_exor: return 4; + case gsc::node_t::expr_bitwise_and: return 5; + case gsc::node_t::expr_equality: return 6; + case gsc::node_t::expr_inequality: return 6; + case gsc::node_t::expr_less: return 7; + case gsc::node_t::expr_greater: return 7; + case gsc::node_t::expr_less_equal: return 7; + case gsc::node_t::expr_greater_equal:return 7; + case gsc::node_t::expr_shift_left: return 8; + case gsc::node_t::expr_shift_right: return 8; + case gsc::node_t::expr_add: return 9; + case gsc::node_t::expr_sub: return 9; + case gsc::node_t::expr_mult: return 10; + case gsc::node_t::expr_div: return 10; + case gsc::node_t::expr_mod: return 10; + default: return 0; + } + } }; struct node_true : public node