fix decompiler empty switch cases

This commit is contained in:
xensik 2022-07-29 11:43:07 +02:00
parent 3236e6e079
commit ced80282e8
10 changed files with 51 additions and 39 deletions

View File

@ -2504,12 +2504,13 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::size_t s
end = find_location_index(stmt, end_loc); // update end
// fix empty cases at end
if (stmt->list.at(end) == ast::kind::asm_endswitch)
end--;
while (stmt->list.size() > (end + 1) && stmt->list.at(end) != ast::kind::asm_endswitch)
end++;
// TODO: fix more than 1 empty case at end
if (stmt->list.at(end) != ast::kind::asm_endswitch)
decomp_error("bad empty cases in switch block!");
end--;
stmt->list.erase(stmt->list.begin() + start); // remove 'switch'
stmt->list.erase(stmt->list.begin() + end); // remove 'endswitch'

View File

@ -2504,12 +2504,13 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::size_t s
end = find_location_index(stmt, end_loc); // update end
// fix empty cases at end
if (stmt->list.at(end) == ast::kind::asm_endswitch)
end--;
while (stmt->list.size() > (end + 1) && stmt->list.at(end) != ast::kind::asm_endswitch)
end++;
// TODO: fix more than 1 empty case at end
if (stmt->list.at(end) != ast::kind::asm_endswitch)
decomp_error("bad empty cases in switch block!");
end--;
stmt->list.erase(stmt->list.begin() + start); // remove 'switch'
stmt->list.erase(stmt->list.begin() + end); // remove 'endswitch'

View File

@ -2498,12 +2498,13 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::size_t s
end = find_location_index(stmt, end_loc); // update end
// fix empty cases at end
if (stmt->list.at(end) == ast::kind::asm_endswitch)
end--;
while (stmt->list.size() > (end + 1) && stmt->list.at(end) != ast::kind::asm_endswitch)
end++;
// TODO: fix more than 1 empty case at end
if (stmt->list.at(end) != ast::kind::asm_endswitch)
decomp_error("bad empty cases in switch block!");
end--;
stmt->list.erase(stmt->list.begin() + start); // remove 'switch'
stmt->list.erase(stmt->list.begin() + end); // remove 'endswitch'

View File

@ -2498,12 +2498,13 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::size_t s
end = find_location_index(stmt, end_loc); // update end
// fix empty cases at end
if (stmt->list.at(end) == ast::kind::asm_endswitch)
end--;
while (stmt->list.size() > (end + 1) && stmt->list.at(end) != ast::kind::asm_endswitch)
end++;
// TODO: fix more than 1 empty case at end
if (stmt->list.at(end) != ast::kind::asm_endswitch)
decomp_error("bad empty cases in switch block!");
end--;
stmt->list.erase(stmt->list.begin() + start); // remove 'switch'
stmt->list.erase(stmt->list.begin() + end); // remove 'endswitch'

View File

@ -2498,12 +2498,13 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::size_t s
end = find_location_index(stmt, end_loc); // update end
// fix empty cases at end
if (stmt->list.at(end) == ast::kind::asm_endswitch)
end--;
while (stmt->list.size() > (end + 1) && stmt->list.at(end) != ast::kind::asm_endswitch)
end++;
// TODO: fix more than 1 empty case at end
if (stmt->list.at(end) != ast::kind::asm_endswitch)
decomp_error("bad empty cases in switch block!");
end--;
stmt->list.erase(stmt->list.begin() + start); // remove 'switch'
stmt->list.erase(stmt->list.begin() + end); // remove 'endswitch'

View File

@ -2535,12 +2535,13 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::size_t s
end = find_location_index(stmt, end_loc); // update end
// fix empty cases at end
if (stmt->list.at(end) == ast::kind::asm_endswitch)
end--;
while (stmt->list.size() > (end + 1) && stmt->list.at(end) != ast::kind::asm_endswitch)
end++;
// TODO: fix more than 1 empty case at end
if (stmt->list.at(end) != ast::kind::asm_endswitch)
decomp_error("bad empty cases in switch block!");
end--;
stmt->list.erase(stmt->list.begin() + start); // remove 'switch'
stmt->list.erase(stmt->list.begin() + end); // remove 'endswitch'

View File

@ -2504,12 +2504,13 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::size_t s
end = find_location_index(stmt, end_loc); // update end
// fix empty cases at end
if (stmt->list.at(end) == ast::kind::asm_endswitch)
end--;
while (stmt->list.size() > (end + 1) && stmt->list.at(end) != ast::kind::asm_endswitch)
end++;
// TODO: fix more than 1 empty case at end
if (stmt->list.at(end) != ast::kind::asm_endswitch)
decomp_error("bad empty cases in switch block!");
end--;
stmt->list.erase(stmt->list.begin() + start); // remove 'switch'
stmt->list.erase(stmt->list.begin() + end); // remove 'endswitch'

View File

@ -2511,12 +2511,13 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::size_t s
end = find_location_index(stmt, end_loc); // update end
// fix empty cases at end
if (stmt->list.at(end) == ast::kind::asm_endswitch)
end--;
while (stmt->list.size() > (end + 1) && stmt->list.at(end) != ast::kind::asm_endswitch)
end++;
// TODO: fix more than 1 empty case at end
if (stmt->list.at(end) != ast::kind::asm_endswitch)
decomp_error("bad empty cases in switch block!");
end--;
stmt->list.erase(stmt->list.begin() + start); // remove 'switch'
stmt->list.erase(stmt->list.begin() + end); // remove 'endswitch'

View File

@ -2535,12 +2535,13 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::size_t s
end = find_location_index(stmt, end_loc); // update end
// fix empty cases at end
if (stmt->list.at(end) == ast::kind::asm_endswitch)
end--;
while (stmt->list.size() > (end + 1) && stmt->list.at(end) != ast::kind::asm_endswitch)
end++;
// TODO: fix more than 1 empty case at end
if (stmt->list.at(end) != ast::kind::asm_endswitch)
decomp_error("bad empty cases in switch block!");
end--;
stmt->list.erase(stmt->list.begin() + start); // remove 'switch'
stmt->list.erase(stmt->list.begin() + end); // remove 'endswitch'

View File

@ -1915,10 +1915,13 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::size_t s
end = find_location_index(stmt, end_loc); // update end
// fix empty cases at end
if (stmt->list.at(end) == ast::kind::asm_endswitch)
end--;
while (stmt->list.size() > (end + 1) && stmt->list.at(end) != ast::kind::asm_endswitch)
end++;
if (stmt->list.at(end) != ast::kind::asm_endswitch)
decomp_error("bad empty cases in switch block!");
end--;
stmt->list.erase(stmt->list.begin() + start); // remove 'switch'
stmt->list.erase(stmt->list.begin() + end); // remove 'endswitch'