diff --git a/src/h1/xsk/compiler.cpp b/src/h1/xsk/compiler.cpp index 72de998d..5ddb2fc2 100644 --- a/src/h1/xsk/compiler.cpp +++ b/src/h1/xsk/compiler.cpp @@ -615,6 +615,11 @@ void compiler::emit_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_swi if(entry.as_node->type == gsc::node_t::stmt_case) { + if(has_default) + { + gsc::comp_error(stmt->loc, "default must be last case"); + } + auto& case_ = entry.as_case; if(case_->value.as_node->type == gsc::node_t::data_integer) { diff --git a/src/h1/xsk/decompiler.cpp b/src/h1/xsk/decompiler.cpp index 0b99b489..617535b2 100644 --- a/src/h1/xsk/decompiler.cpp +++ b/src/h1/xsk/decompiler.cpp @@ -2525,6 +2525,8 @@ void decompiler::decompile_switch(const gsc::stmt_list_ptr& block, std::uint32_t auto list = std::make_unique(loc); list->is_case = true; auto stmt = gsc::stmt_ptr(std::make_unique(loc_pos, std::move(list))); + while(block->stmts.at(loc_idx).as_node->type == gsc::node_t::stmt_case) + loc_idx++; block->stmts.insert(block->stmts.begin() + loc_idx, std::move(stmt)); idx += 2; } diff --git a/src/h2/xsk/compiler.cpp b/src/h2/xsk/compiler.cpp index 4c0b8dde..97c9a613 100644 --- a/src/h2/xsk/compiler.cpp +++ b/src/h2/xsk/compiler.cpp @@ -615,6 +615,11 @@ void compiler::emit_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_swi if(entry.as_node->type == gsc::node_t::stmt_case) { + if(has_default) + { + gsc::comp_error(stmt->loc, "default must be last case"); + } + auto& case_ = entry.as_case; if(case_->value.as_node->type == gsc::node_t::data_integer) { diff --git a/src/h2/xsk/decompiler.cpp b/src/h2/xsk/decompiler.cpp index 8845de32..ee684d05 100644 --- a/src/h2/xsk/decompiler.cpp +++ b/src/h2/xsk/decompiler.cpp @@ -2525,6 +2525,8 @@ void decompiler::decompile_switch(const gsc::stmt_list_ptr& block, std::uint32_t auto list = std::make_unique(loc); list->is_case = true; auto stmt = gsc::stmt_ptr(std::make_unique(loc_pos, std::move(list))); + while(block->stmts.at(loc_idx).as_node->type == gsc::node_t::stmt_case) + loc_idx++; block->stmts.insert(block->stmts.begin() + loc_idx, std::move(stmt)); idx += 2; } diff --git a/src/iw5/xsk/compiler.cpp b/src/iw5/xsk/compiler.cpp index 2032d77b..c6bb21ed 100644 --- a/src/iw5/xsk/compiler.cpp +++ b/src/iw5/xsk/compiler.cpp @@ -609,6 +609,11 @@ void compiler::emit_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_swi if(entry.as_node->type == gsc::node_t::stmt_case) { + if(has_default) + { + gsc::comp_error(stmt->loc, "default must be last case"); + } + auto& case_ = entry.as_case; if(case_->value.as_node->type == gsc::node_t::data_integer) { diff --git a/src/iw5/xsk/decompiler.cpp b/src/iw5/xsk/decompiler.cpp index 345b5796..b2b0ba1b 100644 --- a/src/iw5/xsk/decompiler.cpp +++ b/src/iw5/xsk/decompiler.cpp @@ -2519,6 +2519,8 @@ void decompiler::decompile_switch(const gsc::stmt_list_ptr& block, std::uint32_t auto list = std::make_unique(loc); list->is_case = true; auto stmt = gsc::stmt_ptr(std::make_unique(loc_pos, std::move(list))); + while(block->stmts.at(loc_idx).as_node->type == gsc::node_t::stmt_case) + loc_idx++; block->stmts.insert(block->stmts.begin() + loc_idx, std::move(stmt)); idx += 2; } diff --git a/src/iw6/xsk/compiler.cpp b/src/iw6/xsk/compiler.cpp index 73d38f3e..ba55077b 100644 --- a/src/iw6/xsk/compiler.cpp +++ b/src/iw6/xsk/compiler.cpp @@ -609,6 +609,11 @@ void compiler::emit_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_swi if(entry.as_node->type == gsc::node_t::stmt_case) { + if(has_default) + { + gsc::comp_error(stmt->loc, "default must be last case"); + } + auto& case_ = entry.as_case; if(case_->value.as_node->type == gsc::node_t::data_integer) { diff --git a/src/iw6/xsk/decompiler.cpp b/src/iw6/xsk/decompiler.cpp index fccbd617..a17e2f3a 100644 --- a/src/iw6/xsk/decompiler.cpp +++ b/src/iw6/xsk/decompiler.cpp @@ -2519,6 +2519,8 @@ void decompiler::decompile_switch(const gsc::stmt_list_ptr& block, std::uint32_t auto list = std::make_unique(loc); list->is_case = true; auto stmt = gsc::stmt_ptr(std::make_unique(loc_pos, std::move(list))); + while(block->stmts.at(loc_idx).as_node->type == gsc::node_t::stmt_case) + loc_idx++; block->stmts.insert(block->stmts.begin() + loc_idx, std::move(stmt)); idx += 2; } diff --git a/src/iw7/xsk/compiler.cpp b/src/iw7/xsk/compiler.cpp index 6d0d70dd..4219264e 100644 --- a/src/iw7/xsk/compiler.cpp +++ b/src/iw7/xsk/compiler.cpp @@ -609,6 +609,11 @@ void compiler::emit_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_swi if(entry.as_node->type == gsc::node_t::stmt_case) { + if(has_default) + { + gsc::comp_error(stmt->loc, "default must be last case"); + } + auto& case_ = entry.as_case; if(case_->value.as_node->type == gsc::node_t::data_integer) { diff --git a/src/iw7/xsk/decompiler.cpp b/src/iw7/xsk/decompiler.cpp index 34663f33..3f5f6959 100644 --- a/src/iw7/xsk/decompiler.cpp +++ b/src/iw7/xsk/decompiler.cpp @@ -2519,6 +2519,8 @@ void decompiler::decompile_switch(const gsc::stmt_list_ptr& block, std::uint32_t auto list = std::make_unique(loc); list->is_case = true; auto stmt = gsc::stmt_ptr(std::make_unique(loc_pos, std::move(list))); + while(block->stmts.at(loc_idx).as_node->type == gsc::node_t::stmt_case) + loc_idx++; block->stmts.insert(block->stmts.begin() + loc_idx, std::move(stmt)); idx += 2; } diff --git a/src/s1/xsk/compiler.cpp b/src/s1/xsk/compiler.cpp index 3650fffd..aab9850f 100644 --- a/src/s1/xsk/compiler.cpp +++ b/src/s1/xsk/compiler.cpp @@ -615,6 +615,11 @@ void compiler::emit_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_swi if(entry.as_node->type == gsc::node_t::stmt_case) { + if(has_default) + { + gsc::comp_error(stmt->loc, "default must be last case"); + } + auto& case_ = entry.as_case; if(case_->value.as_node->type == gsc::node_t::data_integer) { diff --git a/src/s1/xsk/decompiler.cpp b/src/s1/xsk/decompiler.cpp index 4d40beb5..eb8eb844 100644 --- a/src/s1/xsk/decompiler.cpp +++ b/src/s1/xsk/decompiler.cpp @@ -2525,6 +2525,8 @@ void decompiler::decompile_switch(const gsc::stmt_list_ptr& block, std::uint32_t auto list = std::make_unique(loc); list->is_case = true; auto stmt = gsc::stmt_ptr(std::make_unique(loc_pos, std::move(list))); + while(block->stmts.at(loc_idx).as_node->type == gsc::node_t::stmt_case) + loc_idx++; block->stmts.insert(block->stmts.begin() + loc_idx, std::move(stmt)); idx += 2; } diff --git a/src/s2/xsk/compiler.cpp b/src/s2/xsk/compiler.cpp index 7e495531..4ee5fc95 100644 --- a/src/s2/xsk/compiler.cpp +++ b/src/s2/xsk/compiler.cpp @@ -615,6 +615,11 @@ void compiler::emit_stmt_switch(const gsc::context_ptr& ctx, const gsc::stmt_swi if(entry.as_node->type == gsc::node_t::stmt_case) { + if(has_default) + { + gsc::comp_error(stmt->loc, "default must be last case"); + } + auto& case_ = entry.as_case; if(case_->value.as_node->type == gsc::node_t::data_integer) { diff --git a/src/s2/xsk/decompiler.cpp b/src/s2/xsk/decompiler.cpp index e9d7776f..89298b73 100644 --- a/src/s2/xsk/decompiler.cpp +++ b/src/s2/xsk/decompiler.cpp @@ -2534,6 +2534,8 @@ void decompiler::decompile_switch(const gsc::stmt_list_ptr& block, std::uint32_t auto list = std::make_unique(loc); list->is_case = true; auto stmt = gsc::stmt_ptr(std::make_unique(loc_pos, std::move(list))); + while(block->stmts.at(loc_idx).as_node->type == gsc::node_t::stmt_case) + loc_idx++; block->stmts.insert(block->stmts.begin() + loc_idx, std::move(stmt)); idx += 2; }