From a7cd82508c943d952f21f3a1b7ccc03fb9010b91 Mon Sep 17 00:00:00 2001 From: xensik Date: Thu, 7 Apr 2022 19:22:10 +0200 Subject: [PATCH] clean warnings --- src/h1/xsk/compiler.cpp | 14 +++++++------- src/h1/xsk/decompiler.cpp | 24 ++++++++++++++---------- src/h1/xsk/lexer.cpp | 20 +++++++++++--------- src/h1/xsk/lexer.hpp | 11 ++++++++--- src/h2/xsk/compiler.cpp | 14 +++++++------- src/h2/xsk/decompiler.cpp | 24 ++++++++++++++---------- src/h2/xsk/lexer.cpp | 20 +++++++++++--------- src/h2/xsk/lexer.hpp | 11 ++++++++--- src/iw5/xsk/compiler.cpp | 14 +++++++------- src/iw5/xsk/decompiler.cpp | 24 ++++++++++++++---------- src/iw5/xsk/lexer.cpp | 20 +++++++++++--------- src/iw5/xsk/lexer.hpp | 11 ++++++++--- src/iw6/xsk/compiler.cpp | 14 +++++++------- src/iw6/xsk/decompiler.cpp | 24 ++++++++++++++---------- src/iw6/xsk/lexer.cpp | 20 +++++++++++--------- src/iw6/xsk/lexer.hpp | 11 ++++++++--- src/iw7/xsk/compiler.cpp | 14 +++++++------- src/iw7/xsk/decompiler.cpp | 24 ++++++++++++++---------- src/iw7/xsk/lexer.cpp | 20 +++++++++++--------- src/iw7/xsk/lexer.hpp | 11 ++++++++--- src/iw8/xsk/compiler.cpp | 14 +++++++------- src/iw8/xsk/decompiler.cpp | 24 ++++++++++++++---------- src/iw8/xsk/lexer.cpp | 22 ++++++++++++---------- src/iw8/xsk/lexer.hpp | 11 ++++++++--- src/s1/xsk/compiler.cpp | 14 +++++++------- src/s1/xsk/decompiler.cpp | 24 ++++++++++++++---------- src/s1/xsk/lexer.cpp | 20 +++++++++++--------- src/s1/xsk/lexer.hpp | 11 ++++++++--- src/s2/xsk/compiler.cpp | 14 +++++++------- src/s2/xsk/decompiler.cpp | 24 ++++++++++++++---------- src/s2/xsk/lexer.cpp | 20 +++++++++++--------- src/s2/xsk/lexer.hpp | 11 ++++++++--- src/s4/xsk/compiler.cpp | 14 +++++++------- src/s4/xsk/decompiler.cpp | 24 ++++++++++++++---------- src/s4/xsk/lexer.cpp | 22 ++++++++++++---------- src/s4/xsk/lexer.hpp | 11 ++++++++--- src/t6/xsk/lexer.hpp | 2 +- src/utils/xsk/arc/nodetree.cpp | 14 +++++++------- src/utils/xsk/arc/nodetree.hpp | 2 +- src/utils/xsk/gsc/block.cpp | 6 +++--- src/utils/xsk/gsc/nodetree.cpp | 14 +++++++------- src/utils/xsk/gsc/nodetree.hpp | 2 +- src/utils/xsk/utils/string.cpp | 6 +++--- 43 files changed, 385 insertions(+), 286 deletions(-) diff --git a/src/h1/xsk/compiler.cpp b/src/h1/xsk/compiler.cpp index a2218635..7f8122d6 100644 --- a/src/h1/xsk/compiler.cpp +++ b/src/h1/xsk/compiler.cpp @@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block:: bool has_default = false; block* default_ctx = nullptr; - for (auto i = 0; i < stmt->stmt->list.size(); i++) + for (auto i = 0u; i < stmt->stmt->list.size(); i++) { auto& entry = stmt->stmt->list[i]; @@ -2296,7 +2296,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block: continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2323,7 +2323,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2355,7 +2355,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_stmt(stmt->iter, stmt->blk_iter); @@ -2405,7 +2405,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl continue_blks_.push_back(stmt->ctx.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_expr(stmt->key_expr, stmt->ctx_post); @@ -2425,7 +2425,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto num = stmt->stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = stmt->stmt->list[0]; @@ -2475,7 +2475,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto old_breaks = break_blks_; break_blks_.clear(); - for (auto i = 0; i < stmt_list->list.size(); i++) + for (auto i = 0u; i < stmt_list->list.size(); i++) { auto& entry = stmt_list->list[i]; diff --git a/src/h1/xsk/decompiler.cpp b/src/h1/xsk/decompiler.cpp index d87b9b04..031e0bab 100644 --- a/src/h1/xsk/decompiler.cpp +++ b/src/h1/xsk/decompiler.cpp @@ -1814,7 +1814,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1841,7 +1841,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { if (stmt->list.at(i) == ast::kind::asm_switch) { @@ -1852,7 +1852,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1927,7 +1927,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) void decompiler::decompile_aborts(const ast::stmt_list::ptr& block) { - for (auto i = 0; i < block->list.size(); i++) + for (auto i = 0u; i < block->list.size(); i++) { if (block->list.at(i) == ast::kind::asm_jump) { @@ -2434,7 +2434,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t auto current_case = ast::stmt(std::make_unique()); auto num = sw_stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = sw_stmt->list[0]; @@ -2623,15 +2623,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block: process_stmt(entry, blk); } - for (auto i = 0; i < stmt->list.size(); i++) + auto i = 0u; + + while (i < stmt->list.size()) { auto type = stmt->list.at(i).kind(); if (type == ast::kind::asm_create || type == ast::kind::asm_remove) { stmt->list.erase(stmt->list.begin() + i); - i--; + continue; } + + i++; } } @@ -3141,7 +3145,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3161,7 +3165,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3317,7 +3321,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk) { - if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index)) + if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index)) { printf("WARNING: bad local var access\n"); } diff --git a/src/h1/xsk/lexer.cpp b/src/h1/xsk/lexer.cpp index 1f3ade72..6702da5c 100644 --- a/src/h1/xsk/lexer.cpp +++ b/src/h1/xsk/lexer.cpp @@ -86,8 +86,10 @@ bool buffer::push(char c) return true; } -reader::reader() : state(reader::end), buffer_pos(0), - bytes_remaining(0), last_byte(0), current_byte(0) {} +reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end) +{ + +} void reader::init(const char* data, size_t size) { @@ -127,8 +129,8 @@ void reader::advance() } } -lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)), - mode_(mode), header_top_(0), locs_(std::stack()), readers_(std::stack()) +lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)), + locs_(std::stack()), readers_(std::stack()), header_top_(0), mode_(mode), indev_(false), clean_(true) { reader_.init(data, size); } @@ -480,7 +482,7 @@ auto lexer::lex() -> parser::symbol_type default: if (last >= '0' && last <= '9') goto lex_number; - else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z') + else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z')) goto lex_name; throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last)); @@ -643,7 +645,7 @@ lex_number: if (last == '\'') throw comp_error(loc_, "invalid number literal"); - if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f') + if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f')) throw comp_error(loc_, "invalid number literal"); if (dot || flt) @@ -660,7 +662,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\'')) throw comp_error(loc_, "invalid octal literal"); if (curr == '\'') @@ -694,7 +696,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\'')) throw comp_error(loc_, "invalid binary literal"); if (curr == '\'') @@ -728,7 +730,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\'')) throw comp_error(loc_, "invalid hexadecimal literal"); if (curr == '\'') diff --git a/src/h1/xsk/lexer.hpp b/src/h1/xsk/lexer.hpp index ae5c13a2..2fc108c8 100644 --- a/src/h1/xsk/lexer.hpp +++ b/src/h1/xsk/lexer.hpp @@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000; struct buffer { char* data; - int length; + size_t length; buffer(); ~buffer(); @@ -32,9 +32,14 @@ struct reader reader(); - reader& operator=(const reader& r) + reader(const reader& obj) { - std::memcpy(this, &r, sizeof(reader)); + std::memcpy(this, &obj, sizeof(reader)); + } + + reader& operator=(const reader& obj) + { + std::memcpy(this, &obj, sizeof(reader)); return *this; } diff --git a/src/h2/xsk/compiler.cpp b/src/h2/xsk/compiler.cpp index 840badf5..8986990c 100644 --- a/src/h2/xsk/compiler.cpp +++ b/src/h2/xsk/compiler.cpp @@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block:: bool has_default = false; block* default_ctx = nullptr; - for (auto i = 0; i < stmt->stmt->list.size(); i++) + for (auto i = 0u; i < stmt->stmt->list.size(); i++) { auto& entry = stmt->stmt->list[i]; @@ -2295,7 +2295,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block: continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2322,7 +2322,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2354,7 +2354,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_stmt(stmt->iter, stmt->blk_iter); @@ -2404,7 +2404,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl continue_blks_.push_back(stmt->ctx.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_expr(stmt->key_expr, stmt->ctx_post); @@ -2424,7 +2424,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto num = stmt->stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = stmt->stmt->list[0]; @@ -2474,7 +2474,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto old_breaks = break_blks_; break_blks_.clear(); - for (auto i = 0; i < stmt_list->list.size(); i++) + for (auto i = 0u; i < stmt_list->list.size(); i++) { auto& entry = stmt_list->list[i]; diff --git a/src/h2/xsk/decompiler.cpp b/src/h2/xsk/decompiler.cpp index d5b663f2..58f50ec7 100644 --- a/src/h2/xsk/decompiler.cpp +++ b/src/h2/xsk/decompiler.cpp @@ -1814,7 +1814,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1841,7 +1841,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { if (stmt->list.at(i) == ast::kind::asm_switch) { @@ -1852,7 +1852,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1927,7 +1927,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) void decompiler::decompile_aborts(const ast::stmt_list::ptr& block) { - for (auto i = 0; i < block->list.size(); i++) + for (auto i = 0u; i < block->list.size(); i++) { if (block->list.at(i) == ast::kind::asm_jump) { @@ -2434,7 +2434,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t auto current_case = ast::stmt(std::make_unique()); auto num = sw_stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = sw_stmt->list[0]; @@ -2623,15 +2623,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block: process_stmt(entry, blk); } - for (auto i = 0; i < stmt->list.size(); i++) + auto i = 0u; + + while (i < stmt->list.size()) { auto type = stmt->list.at(i).kind(); if (type == ast::kind::asm_create || type == ast::kind::asm_remove) { stmt->list.erase(stmt->list.begin() + i); - i--; + continue; } + + i++; } } @@ -3141,7 +3145,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3161,7 +3165,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3317,7 +3321,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk) { - if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index)) + if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index)) { printf("WARNING: bad local var access\n"); } diff --git a/src/h2/xsk/lexer.cpp b/src/h2/xsk/lexer.cpp index 6d1ad388..ba3ebbbd 100644 --- a/src/h2/xsk/lexer.cpp +++ b/src/h2/xsk/lexer.cpp @@ -86,8 +86,10 @@ bool buffer::push(char c) return true; } -reader::reader() : state(reader::end), buffer_pos(0), - bytes_remaining(0), last_byte(0), current_byte(0) {} +reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end) +{ + +} void reader::init(const char* data, size_t size) { @@ -127,8 +129,8 @@ void reader::advance() } } -lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)), - mode_(mode), header_top_(0), locs_(std::stack()), readers_(std::stack()) +lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)), + locs_(std::stack()), readers_(std::stack()), header_top_(0), mode_(mode), indev_(false), clean_(true) { reader_.init(data, size); } @@ -480,7 +482,7 @@ auto lexer::lex() -> parser::symbol_type default: if (last >= '0' && last <= '9') goto lex_number; - else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z') + else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z')) goto lex_name; throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last)); @@ -643,7 +645,7 @@ lex_number: if (last == '\'') throw comp_error(loc_, "invalid number literal"); - if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f') + if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f')) throw comp_error(loc_, "invalid number literal"); if (dot || flt) @@ -660,7 +662,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\'')) throw comp_error(loc_, "invalid octal literal"); if (curr == '\'') @@ -694,7 +696,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\'')) throw comp_error(loc_, "invalid binary literal"); if (curr == '\'') @@ -728,7 +730,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\'')) throw comp_error(loc_, "invalid hexadecimal literal"); if (curr == '\'') diff --git a/src/h2/xsk/lexer.hpp b/src/h2/xsk/lexer.hpp index 81663640..f9efcc7b 100644 --- a/src/h2/xsk/lexer.hpp +++ b/src/h2/xsk/lexer.hpp @@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000; struct buffer { char* data; - int length; + size_t length; buffer(); ~buffer(); @@ -32,9 +32,14 @@ struct reader reader(); - reader& operator=(const reader& r) + reader(const reader& obj) { - std::memcpy(this, &r, sizeof(reader)); + std::memcpy(this, &obj, sizeof(reader)); + } + + reader& operator=(const reader& obj) + { + std::memcpy(this, &obj, sizeof(reader)); return *this; } diff --git a/src/iw5/xsk/compiler.cpp b/src/iw5/xsk/compiler.cpp index 00f6fc41..79e6d408 100644 --- a/src/iw5/xsk/compiler.cpp +++ b/src/iw5/xsk/compiler.cpp @@ -769,7 +769,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block:: bool has_default = false; block* default_ctx = nullptr; - for (auto i = 0; i < stmt->stmt->list.size(); i++) + for (auto i = 0u; i < stmt->stmt->list.size(); i++) { auto& entry = stmt->stmt->list[i]; @@ -2286,7 +2286,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block: continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2313,7 +2313,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2345,7 +2345,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_stmt(stmt->iter, stmt->blk_iter); @@ -2395,7 +2395,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl continue_blks_.push_back(stmt->ctx.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_expr(stmt->key_expr, stmt->ctx_post); @@ -2415,7 +2415,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto num = stmt->stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = stmt->stmt->list[0]; @@ -2465,7 +2465,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto old_breaks = break_blks_; break_blks_.clear(); - for (auto i = 0; i < stmt_list->list.size(); i++) + for (auto i = 0u; i < stmt_list->list.size(); i++) { auto& entry = stmt_list->list[i]; diff --git a/src/iw5/xsk/decompiler.cpp b/src/iw5/xsk/decompiler.cpp index 27a0640b..8f330cab 100644 --- a/src/iw5/xsk/decompiler.cpp +++ b/src/iw5/xsk/decompiler.cpp @@ -1808,7 +1808,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1835,7 +1835,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { if (stmt->list.at(i) == ast::kind::asm_switch) { @@ -1846,7 +1846,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1921,7 +1921,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) void decompiler::decompile_aborts(const ast::stmt_list::ptr& block) { - for (auto i = 0; i < block->list.size(); i++) + for (auto i = 0u; i < block->list.size(); i++) { if (block->list.at(i) == ast::kind::asm_jump) { @@ -2428,7 +2428,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t auto current_case = ast::stmt(std::make_unique()); auto num = sw_stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = sw_stmt->list[0]; @@ -2617,15 +2617,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block: process_stmt(entry, blk); } - for (auto i = 0; i < stmt->list.size(); i++) + auto i = 0u; + + while (i < stmt->list.size()) { auto type = stmt->list.at(i).kind(); if (type == ast::kind::asm_create || type == ast::kind::asm_remove) { stmt->list.erase(stmt->list.begin() + i); - i--; + continue; } + + i++; } } @@ -3135,7 +3139,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3155,7 +3159,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3311,7 +3315,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk) { - if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index)) + if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index)) { printf("WARNING: bad local var access\n"); } diff --git a/src/iw5/xsk/lexer.cpp b/src/iw5/xsk/lexer.cpp index b647f424..88a5f8e6 100644 --- a/src/iw5/xsk/lexer.cpp +++ b/src/iw5/xsk/lexer.cpp @@ -85,8 +85,10 @@ bool buffer::push(char c) return true; } -reader::reader() : state(reader::end), buffer_pos(0), - bytes_remaining(0), last_byte(0), current_byte(0) {} +reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end) +{ + +} void reader::init(const char* data, size_t size) { @@ -126,8 +128,8 @@ void reader::advance() } } -lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)), - mode_(mode), header_top_(0), locs_(std::stack()), readers_(std::stack()) +lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)), + locs_(std::stack()), readers_(std::stack()), header_top_(0), mode_(mode), indev_(false), clean_(true) { reader_.init(data, size); } @@ -479,7 +481,7 @@ auto lexer::lex() -> parser::symbol_type default: if (last >= '0' && last <= '9') goto lex_number; - else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z') + else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z')) goto lex_name; throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last)); @@ -642,7 +644,7 @@ lex_number: if (last == '\'') throw comp_error(loc_, "invalid number literal"); - if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f') + if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f')) throw comp_error(loc_, "invalid number literal"); if (dot || flt) @@ -659,7 +661,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\'')) throw comp_error(loc_, "invalid octal literal"); if (curr == '\'') @@ -693,7 +695,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\'')) throw comp_error(loc_, "invalid binary literal"); if (curr == '\'') @@ -727,7 +729,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\'')) throw comp_error(loc_, "invalid hexadecimal literal"); if (curr == '\'') diff --git a/src/iw5/xsk/lexer.hpp b/src/iw5/xsk/lexer.hpp index 26da6316..259221a8 100644 --- a/src/iw5/xsk/lexer.hpp +++ b/src/iw5/xsk/lexer.hpp @@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000; struct buffer { char* data; - int length; + size_t length; buffer(); ~buffer(); @@ -32,9 +32,14 @@ struct reader reader(); - reader& operator=(const reader& r) + reader(const reader& obj) { - std::memcpy(this, &r, sizeof(reader)); + std::memcpy(this, &obj, sizeof(reader)); + } + + reader& operator=(const reader& obj) + { + std::memcpy(this, &obj, sizeof(reader)); return *this; } diff --git a/src/iw6/xsk/compiler.cpp b/src/iw6/xsk/compiler.cpp index be4d1330..e10db85c 100644 --- a/src/iw6/xsk/compiler.cpp +++ b/src/iw6/xsk/compiler.cpp @@ -769,7 +769,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block:: bool has_default = false; block* default_ctx = nullptr; - for (auto i = 0; i < stmt->stmt->list.size(); i++) + for (auto i = 0u; i < stmt->stmt->list.size(); i++) { auto& entry = stmt->stmt->list[i]; @@ -2286,7 +2286,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block: continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2313,7 +2313,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2345,7 +2345,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_stmt(stmt->iter, stmt->blk_iter); @@ -2395,7 +2395,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl continue_blks_.push_back(stmt->ctx.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_expr(stmt->key_expr, stmt->ctx_post); @@ -2415,7 +2415,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto num = stmt->stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = stmt->stmt->list[0]; @@ -2465,7 +2465,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto old_breaks = break_blks_; break_blks_.clear(); - for (auto i = 0; i < stmt_list->list.size(); i++) + for (auto i = 0u; i < stmt_list->list.size(); i++) { auto& entry = stmt_list->list[i]; diff --git a/src/iw6/xsk/decompiler.cpp b/src/iw6/xsk/decompiler.cpp index e5afecc6..3520149f 100644 --- a/src/iw6/xsk/decompiler.cpp +++ b/src/iw6/xsk/decompiler.cpp @@ -1808,7 +1808,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1835,7 +1835,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { if (stmt->list.at(i) == ast::kind::asm_switch) { @@ -1846,7 +1846,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1921,7 +1921,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) void decompiler::decompile_aborts(const ast::stmt_list::ptr& block) { - for (auto i = 0; i < block->list.size(); i++) + for (auto i = 0u; i < block->list.size(); i++) { if (block->list.at(i) == ast::kind::asm_jump) { @@ -2428,7 +2428,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t auto current_case = ast::stmt(std::make_unique()); auto num = sw_stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = sw_stmt->list[0]; @@ -2617,15 +2617,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block: process_stmt(entry, blk); } - for (auto i = 0; i < stmt->list.size(); i++) + auto i = 0u; + + while (i < stmt->list.size()) { auto type = stmt->list.at(i).kind(); if (type == ast::kind::asm_create || type == ast::kind::asm_remove) { stmt->list.erase(stmt->list.begin() + i); - i--; + continue; } + + i++; } } @@ -3135,7 +3139,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3155,7 +3159,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3311,7 +3315,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk) { - if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index)) + if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index)) { printf("WARNING: bad local var access\n"); } diff --git a/src/iw6/xsk/lexer.cpp b/src/iw6/xsk/lexer.cpp index c831227f..16e37e1a 100644 --- a/src/iw6/xsk/lexer.cpp +++ b/src/iw6/xsk/lexer.cpp @@ -85,8 +85,10 @@ bool buffer::push(char c) return true; } -reader::reader() : state(reader::end), buffer_pos(0), - bytes_remaining(0), last_byte(0), current_byte(0) {} +reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end) +{ + +} void reader::init(const char* data, size_t size) { @@ -126,8 +128,8 @@ void reader::advance() } } -lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)), - mode_(mode), header_top_(0), locs_(std::stack()), readers_(std::stack()) +lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)), + locs_(std::stack()), readers_(std::stack()), header_top_(0), mode_(mode), indev_(false), clean_(true) { reader_.init(data, size); } @@ -479,7 +481,7 @@ auto lexer::lex() -> parser::symbol_type default: if (last >= '0' && last <= '9') goto lex_number; - else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z') + else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z')) goto lex_name; throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last)); @@ -642,7 +644,7 @@ lex_number: if (last == '\'') throw comp_error(loc_, "invalid number literal"); - if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f') + if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f')) throw comp_error(loc_, "invalid number literal"); if (dot || flt) @@ -659,7 +661,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\'')) throw comp_error(loc_, "invalid octal literal"); if (curr == '\'') @@ -693,7 +695,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\'')) throw comp_error(loc_, "invalid binary literal"); if (curr == '\'') @@ -727,7 +729,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\'')) throw comp_error(loc_, "invalid hexadecimal literal"); if (curr == '\'') diff --git a/src/iw6/xsk/lexer.hpp b/src/iw6/xsk/lexer.hpp index 5f15e662..0d8f5fa7 100644 --- a/src/iw6/xsk/lexer.hpp +++ b/src/iw6/xsk/lexer.hpp @@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000; struct buffer { char* data; - int length; + size_t length; buffer(); ~buffer(); @@ -32,9 +32,14 @@ struct reader reader(); - reader& operator=(const reader& r) + reader(const reader& obj) { - std::memcpy(this, &r, sizeof(reader)); + std::memcpy(this, &obj, sizeof(reader)); + } + + reader& operator=(const reader& obj) + { + std::memcpy(this, &obj, sizeof(reader)); return *this; } diff --git a/src/iw7/xsk/compiler.cpp b/src/iw7/xsk/compiler.cpp index 79f54cc0..1e895ef0 100644 --- a/src/iw7/xsk/compiler.cpp +++ b/src/iw7/xsk/compiler.cpp @@ -769,7 +769,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block:: bool has_default = false; block* default_ctx = nullptr; - for (auto i = 0; i < stmt->stmt->list.size(); i++) + for (auto i = 0u; i < stmt->stmt->list.size(); i++) { auto& entry = stmt->stmt->list[i]; @@ -2286,7 +2286,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block: continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2313,7 +2313,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2345,7 +2345,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_stmt(stmt->iter, stmt->blk_iter); @@ -2395,7 +2395,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl continue_blks_.push_back(stmt->ctx.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_expr(stmt->key_expr, stmt->ctx_post); @@ -2415,7 +2415,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto num = stmt->stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = stmt->stmt->list[0]; @@ -2465,7 +2465,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto old_breaks = break_blks_; break_blks_.clear(); - for (auto i = 0; i < stmt_list->list.size(); i++) + for (auto i = 0u; i < stmt_list->list.size(); i++) { auto& entry = stmt_list->list[i]; diff --git a/src/iw7/xsk/decompiler.cpp b/src/iw7/xsk/decompiler.cpp index 751ea2c3..845c855d 100644 --- a/src/iw7/xsk/decompiler.cpp +++ b/src/iw7/xsk/decompiler.cpp @@ -1808,7 +1808,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1835,7 +1835,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { if (stmt->list.at(i) == ast::kind::asm_switch) { @@ -1846,7 +1846,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1921,7 +1921,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) void decompiler::decompile_aborts(const ast::stmt_list::ptr& block) { - for (auto i = 0; i < block->list.size(); i++) + for (auto i = 0u; i < block->list.size(); i++) { if (block->list.at(i) == ast::kind::asm_jump) { @@ -2428,7 +2428,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t auto current_case = ast::stmt(std::make_unique()); auto num = sw_stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = sw_stmt->list[0]; @@ -2617,15 +2617,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block: process_stmt(entry, blk); } - for (auto i = 0; i < stmt->list.size(); i++) + auto i = 0u; + + while (i < stmt->list.size()) { auto type = stmt->list.at(i).kind(); if (type == ast::kind::asm_create || type == ast::kind::asm_remove) { stmt->list.erase(stmt->list.begin() + i); - i--; + continue; } + + i++; } } @@ -3135,7 +3139,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3155,7 +3159,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3311,7 +3315,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk) { - if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index)) + if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index)) { printf("WARNING: bad local var access\n"); } diff --git a/src/iw7/xsk/lexer.cpp b/src/iw7/xsk/lexer.cpp index 71f3517b..90bcf6bb 100644 --- a/src/iw7/xsk/lexer.cpp +++ b/src/iw7/xsk/lexer.cpp @@ -85,8 +85,10 @@ bool buffer::push(char c) return true; } -reader::reader() : state(reader::end), buffer_pos(0), - bytes_remaining(0), last_byte(0), current_byte(0) {} +reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end) +{ + +} void reader::init(const char* data, size_t size) { @@ -126,8 +128,8 @@ void reader::advance() } } -lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)), - mode_(mode), header_top_(0), locs_(std::stack()), readers_(std::stack()) +lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)), + locs_(std::stack()), readers_(std::stack()), header_top_(0), mode_(mode), indev_(false), clean_(true) { reader_.init(data, size); } @@ -479,7 +481,7 @@ auto lexer::lex() -> parser::symbol_type default: if (last >= '0' && last <= '9') goto lex_number; - else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z') + else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z')) goto lex_name; throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last)); @@ -642,7 +644,7 @@ lex_number: if (last == '\'') throw comp_error(loc_, "invalid number literal"); - if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f') + if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f')) throw comp_error(loc_, "invalid number literal"); if (dot || flt) @@ -659,7 +661,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\'')) throw comp_error(loc_, "invalid octal literal"); if (curr == '\'') @@ -693,7 +695,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\'')) throw comp_error(loc_, "invalid binary literal"); if (curr == '\'') @@ -727,7 +729,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\'')) throw comp_error(loc_, "invalid hexadecimal literal"); if (curr == '\'') diff --git a/src/iw7/xsk/lexer.hpp b/src/iw7/xsk/lexer.hpp index 29e4e4cb..c353fcf8 100644 --- a/src/iw7/xsk/lexer.hpp +++ b/src/iw7/xsk/lexer.hpp @@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000; struct buffer { char* data; - int length; + size_t length; buffer(); ~buffer(); @@ -32,9 +32,14 @@ struct reader reader(); - reader& operator=(const reader& r) + reader(const reader& obj) { - std::memcpy(this, &r, sizeof(reader)); + std::memcpy(this, &obj, sizeof(reader)); + } + + reader& operator=(const reader& obj) + { + std::memcpy(this, &obj, sizeof(reader)); return *this; } diff --git a/src/iw8/xsk/compiler.cpp b/src/iw8/xsk/compiler.cpp index 9de2c7f3..4af8e288 100644 --- a/src/iw8/xsk/compiler.cpp +++ b/src/iw8/xsk/compiler.cpp @@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block:: bool has_default = false; block* default_ctx = nullptr; - for (auto i = 0; i < stmt->stmt->list.size(); i++) + for (auto i = 0u; i < stmt->stmt->list.size(); i++) { auto& entry = stmt->stmt->list[i]; @@ -2346,7 +2346,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block: continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2373,7 +2373,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2405,7 +2405,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_stmt(stmt->iter, stmt->blk_iter); @@ -2455,7 +2455,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl continue_blks_.push_back(stmt->ctx.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_expr(stmt->key_expr, stmt->ctx_post); @@ -2475,7 +2475,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto num = stmt->stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = stmt->stmt->list[0]; @@ -2525,7 +2525,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto old_breaks = break_blks_; break_blks_.clear(); - for (auto i = 0; i < stmt_list->list.size(); i++) + for (auto i = 0u; i < stmt_list->list.size(); i++) { auto& entry = stmt_list->list[i]; diff --git a/src/iw8/xsk/decompiler.cpp b/src/iw8/xsk/decompiler.cpp index 8aa2153d..29e3ecca 100644 --- a/src/iw8/xsk/decompiler.cpp +++ b/src/iw8/xsk/decompiler.cpp @@ -1845,7 +1845,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1872,7 +1872,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { if (stmt->list.at(i) == ast::kind::asm_switch) { @@ -1883,7 +1883,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1958,7 +1958,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) void decompiler::decompile_aborts(const ast::stmt_list::ptr& block) { - for (auto i = 0; i < block->list.size(); i++) + for (auto i = 0u; i < block->list.size(); i++) { if (block->list.at(i) == ast::kind::asm_jump) { @@ -2465,7 +2465,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t auto current_case = ast::stmt(std::make_unique()); auto num = sw_stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = sw_stmt->list[0]; @@ -2654,15 +2654,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block: process_stmt(entry, blk); } - for (auto i = 0; i < stmt->list.size(); i++) + auto i = 0u; + + while (i < stmt->list.size()) { auto type = stmt->list.at(i).kind(); if (type == ast::kind::asm_create || type == ast::kind::asm_remove) { stmt->list.erase(stmt->list.begin() + i); - i--; + continue; } + + i++; } } @@ -3178,7 +3182,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3198,7 +3202,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3354,7 +3358,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk) { - if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index)) + if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index)) { printf("WARNING: bad local var access\n"); } diff --git a/src/iw8/xsk/lexer.cpp b/src/iw8/xsk/lexer.cpp index 48a0f081..e2fb0d17 100644 --- a/src/iw8/xsk/lexer.cpp +++ b/src/iw8/xsk/lexer.cpp @@ -88,8 +88,10 @@ bool buffer::push(char c) return true; } -reader::reader() : state(reader::end), buffer_pos(0), - bytes_remaining(0), last_byte(0), current_byte(0) {} +reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end) +{ + +} void reader::init(const char* data, size_t size) { @@ -129,8 +131,8 @@ void reader::advance() } } -lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)), - mode_(mode), header_top_(0), locs_(std::stack()), readers_(std::stack()) +lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)), + locs_(std::stack()), readers_(std::stack()), header_top_(0), mode_(mode), indev_(false), clean_(true) { reader_.init(data, size); } @@ -482,7 +484,7 @@ auto lexer::lex() -> parser::symbol_type default: if (last >= '0' && last <= '9') goto lex_number; - else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z') + else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z')) goto lex_name; throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last)); @@ -587,7 +589,7 @@ lex_name: { if (buffer_.data[0] != '_') { - for (auto i = 0; i < buffer_.length; i++) + for (auto i = 0u; i < buffer_.length; i++) { auto c = buffer_.data[i]; @@ -656,7 +658,7 @@ lex_number: if (last == '\'') throw comp_error(loc_, "invalid number literal"); - if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f') + if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f')) throw comp_error(loc_, "invalid number literal"); if (dot || flt) @@ -673,7 +675,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\'')) throw comp_error(loc_, "invalid octal literal"); if (curr == '\'') @@ -707,7 +709,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\'')) throw comp_error(loc_, "invalid binary literal"); if (curr == '\'') @@ -741,7 +743,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\'')) throw comp_error(loc_, "invalid hexadecimal literal"); if (curr == '\'') diff --git a/src/iw8/xsk/lexer.hpp b/src/iw8/xsk/lexer.hpp index 07c46835..70f110a5 100644 --- a/src/iw8/xsk/lexer.hpp +++ b/src/iw8/xsk/lexer.hpp @@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000; struct buffer { char* data; - int length; + size_t length; buffer(); ~buffer(); @@ -32,9 +32,14 @@ struct reader reader(); - reader& operator=(const reader& r) + reader(const reader& obj) { - std::memcpy(this, &r, sizeof(reader)); + std::memcpy(this, &obj, sizeof(reader)); + } + + reader& operator=(const reader& obj) + { + std::memcpy(this, &obj, sizeof(reader)); return *this; } diff --git a/src/s1/xsk/compiler.cpp b/src/s1/xsk/compiler.cpp index 1f33c588..6e154ebd 100644 --- a/src/s1/xsk/compiler.cpp +++ b/src/s1/xsk/compiler.cpp @@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block:: bool has_default = false; block* default_ctx = nullptr; - for (auto i = 0; i < stmt->stmt->list.size(); i++) + for (auto i = 0u; i < stmt->stmt->list.size(); i++) { auto& entry = stmt->stmt->list[i]; @@ -2295,7 +2295,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block: continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2322,7 +2322,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2354,7 +2354,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_stmt(stmt->iter, stmt->blk_iter); @@ -2404,7 +2404,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl continue_blks_.push_back(stmt->ctx.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_expr(stmt->key_expr, stmt->ctx_post); @@ -2424,7 +2424,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto num = stmt->stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = stmt->stmt->list[0]; @@ -2474,7 +2474,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto old_breaks = break_blks_; break_blks_.clear(); - for (auto i = 0; i < stmt_list->list.size(); i++) + for (auto i = 0u; i < stmt_list->list.size(); i++) { auto& entry = stmt_list->list[i]; diff --git a/src/s1/xsk/decompiler.cpp b/src/s1/xsk/decompiler.cpp index fd1a5aef..07fc90d8 100644 --- a/src/s1/xsk/decompiler.cpp +++ b/src/s1/xsk/decompiler.cpp @@ -1814,7 +1814,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1841,7 +1841,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { if (stmt->list.at(i) == ast::kind::asm_switch) { @@ -1852,7 +1852,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1927,7 +1927,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) void decompiler::decompile_aborts(const ast::stmt_list::ptr& block) { - for (auto i = 0; i < block->list.size(); i++) + for (auto i = 0u; i < block->list.size(); i++) { if (block->list.at(i) == ast::kind::asm_jump) { @@ -2434,7 +2434,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t auto current_case = ast::stmt(std::make_unique()); auto num = sw_stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = sw_stmt->list[0]; @@ -2623,15 +2623,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block: process_stmt(entry, blk); } - for (auto i = 0; i < stmt->list.size(); i++) + auto i = 0u; + + while (i < stmt->list.size()) { auto type = stmt->list.at(i).kind(); if (type == ast::kind::asm_create || type == ast::kind::asm_remove) { stmt->list.erase(stmt->list.begin() + i); - i--; + continue; } + + i++; } } @@ -3141,7 +3145,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3161,7 +3165,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3317,7 +3321,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk) { - if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index)) + if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index)) { printf("WARNING: bad local var access\n"); } diff --git a/src/s1/xsk/lexer.cpp b/src/s1/xsk/lexer.cpp index 8fccc7bc..e179c005 100644 --- a/src/s1/xsk/lexer.cpp +++ b/src/s1/xsk/lexer.cpp @@ -86,8 +86,10 @@ bool buffer::push(char c) return true; } -reader::reader() : state(reader::end), buffer_pos(0), - bytes_remaining(0), last_byte(0), current_byte(0) {} +reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end) +{ + +} void reader::init(const char* data, size_t size) { @@ -127,8 +129,8 @@ void reader::advance() } } -lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)), - mode_(mode), header_top_(0), locs_(std::stack()), readers_(std::stack()) +lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)), + locs_(std::stack()), readers_(std::stack()), header_top_(0), mode_(mode), indev_(false), clean_(true) { reader_.init(data, size); } @@ -480,7 +482,7 @@ auto lexer::lex() -> parser::symbol_type default: if (last >= '0' && last <= '9') goto lex_number; - else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z') + else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z')) goto lex_name; throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last)); @@ -643,7 +645,7 @@ lex_number: if (last == '\'') throw comp_error(loc_, "invalid number literal"); - if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f') + if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f')) throw comp_error(loc_, "invalid number literal"); if (dot || flt) @@ -660,7 +662,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\'')) throw comp_error(loc_, "invalid octal literal"); if (curr == '\'') @@ -694,7 +696,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\'')) throw comp_error(loc_, "invalid binary literal"); if (curr == '\'') @@ -728,7 +730,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\'')) throw comp_error(loc_, "invalid hexadecimal literal"); if (curr == '\'') diff --git a/src/s1/xsk/lexer.hpp b/src/s1/xsk/lexer.hpp index a49e2c8a..89025421 100644 --- a/src/s1/xsk/lexer.hpp +++ b/src/s1/xsk/lexer.hpp @@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000; struct buffer { char* data; - int length; + size_t length; buffer(); ~buffer(); @@ -32,9 +32,14 @@ struct reader reader(); - reader& operator=(const reader& r) + reader(const reader& obj) { - std::memcpy(this, &r, sizeof(reader)); + std::memcpy(this, &obj, sizeof(reader)); + } + + reader& operator=(const reader& obj) + { + std::memcpy(this, &obj, sizeof(reader)); return *this; } diff --git a/src/s2/xsk/compiler.cpp b/src/s2/xsk/compiler.cpp index c9b0dea4..178cb0cc 100644 --- a/src/s2/xsk/compiler.cpp +++ b/src/s2/xsk/compiler.cpp @@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block:: bool has_default = false; block* default_ctx = nullptr; - for (auto i = 0; i < stmt->stmt->list.size(); i++) + for (auto i = 0u; i < stmt->stmt->list.size(); i++) { auto& entry = stmt->stmt->list[i]; @@ -2295,7 +2295,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block: continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2322,7 +2322,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2354,7 +2354,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_stmt(stmt->iter, stmt->blk_iter); @@ -2404,7 +2404,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl continue_blks_.push_back(stmt->ctx.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_expr(stmt->key_expr, stmt->ctx_post); @@ -2424,7 +2424,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto num = stmt->stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = stmt->stmt->list[0]; @@ -2474,7 +2474,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto old_breaks = break_blks_; break_blks_.clear(); - for (auto i = 0; i < stmt_list->list.size(); i++) + for (auto i = 0u; i < stmt_list->list.size(); i++) { auto& entry = stmt_list->list[i]; diff --git a/src/s2/xsk/decompiler.cpp b/src/s2/xsk/decompiler.cpp index 6e20b7ea..d9061ae7 100644 --- a/src/s2/xsk/decompiler.cpp +++ b/src/s2/xsk/decompiler.cpp @@ -1821,7 +1821,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1848,7 +1848,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { if (stmt->list.at(i) == ast::kind::asm_switch) { @@ -1859,7 +1859,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1934,7 +1934,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) void decompiler::decompile_aborts(const ast::stmt_list::ptr& block) { - for (auto i = 0; i < block->list.size(); i++) + for (auto i = 0u; i < block->list.size(); i++) { if (block->list.at(i) == ast::kind::asm_jump) { @@ -2441,7 +2441,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t auto current_case = ast::stmt(std::make_unique()); auto num = sw_stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = sw_stmt->list[0]; @@ -2630,15 +2630,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block: process_stmt(entry, blk); } - for (auto i = 0; i < stmt->list.size(); i++) + auto i = 0u; + + while (i < stmt->list.size()) { auto type = stmt->list.at(i).kind(); if (type == ast::kind::asm_create || type == ast::kind::asm_remove) { stmt->list.erase(stmt->list.begin() + i); - i--; + continue; } + + i++; } } @@ -3148,7 +3152,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3168,7 +3172,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3324,7 +3328,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk) { - if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index)) + if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index)) { printf("WARNING: bad local var access\n"); } diff --git a/src/s2/xsk/lexer.cpp b/src/s2/xsk/lexer.cpp index 92dff738..139fb752 100644 --- a/src/s2/xsk/lexer.cpp +++ b/src/s2/xsk/lexer.cpp @@ -86,8 +86,10 @@ bool buffer::push(char c) return true; } -reader::reader() : state(reader::end), buffer_pos(0), - bytes_remaining(0), last_byte(0), current_byte(0) {} +reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end) +{ + +} void reader::init(const char* data, size_t size) { @@ -127,8 +129,8 @@ void reader::advance() } } -lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)), - mode_(mode), header_top_(0), locs_(std::stack()), readers_(std::stack()) +lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)), + locs_(std::stack()), readers_(std::stack()), header_top_(0), mode_(mode), indev_(false), clean_(true) { reader_.init(data, size); } @@ -480,7 +482,7 @@ auto lexer::lex() -> parser::symbol_type default: if (last >= '0' && last <= '9') goto lex_number; - else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z') + else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z')) goto lex_name; throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last)); @@ -643,7 +645,7 @@ lex_number: if (last == '\'') throw comp_error(loc_, "invalid number literal"); - if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f') + if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f')) throw comp_error(loc_, "invalid number literal"); if (dot || flt) @@ -660,7 +662,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\'')) throw comp_error(loc_, "invalid octal literal"); if (curr == '\'') @@ -694,7 +696,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\'')) throw comp_error(loc_, "invalid binary literal"); if (curr == '\'') @@ -728,7 +730,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\'')) throw comp_error(loc_, "invalid hexadecimal literal"); if (curr == '\'') diff --git a/src/s2/xsk/lexer.hpp b/src/s2/xsk/lexer.hpp index edc8fa98..20bcfcad 100644 --- a/src/s2/xsk/lexer.hpp +++ b/src/s2/xsk/lexer.hpp @@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000; struct buffer { char* data; - int length; + size_t length; buffer(); ~buffer(); @@ -32,9 +32,14 @@ struct reader reader(); - reader& operator=(const reader& r) + reader(const reader& obj) { - std::memcpy(this, &r, sizeof(reader)); + std::memcpy(this, &obj, sizeof(reader)); + } + + reader& operator=(const reader& obj) + { + std::memcpy(this, &obj, sizeof(reader)); return *this; } diff --git a/src/s4/xsk/compiler.cpp b/src/s4/xsk/compiler.cpp index 9e8d89b5..54f78452 100644 --- a/src/s4/xsk/compiler.cpp +++ b/src/s4/xsk/compiler.cpp @@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block:: bool has_default = false; block* default_ctx = nullptr; - for (auto i = 0; i < stmt->stmt->list.size(); i++) + for (auto i = 0u; i < stmt->stmt->list.size(); i++) { auto& entry = stmt->stmt->list[i]; @@ -2346,7 +2346,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block: continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2373,7 +2373,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); if (const_cond) blk->append(break_blks_); @@ -2405,7 +2405,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr continue_blks_.push_back(stmt->blk.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_stmt(stmt->iter, stmt->blk_iter); @@ -2455,7 +2455,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl continue_blks_.push_back(stmt->ctx.get()); - for (auto i = 0; i < continue_blks_.size(); i++) + for (auto i = 0u; i < continue_blks_.size(); i++) blk->append({continue_blks_.at(i)}); process_expr(stmt->key_expr, stmt->ctx_post); @@ -2475,7 +2475,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto num = stmt->stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = stmt->stmt->list[0]; @@ -2525,7 +2525,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc auto old_breaks = break_blks_; break_blks_.clear(); - for (auto i = 0; i < stmt_list->list.size(); i++) + for (auto i = 0u; i < stmt_list->list.size(); i++) { auto& entry = stmt_list->list[i]; diff --git a/src/s4/xsk/decompiler.cpp b/src/s4/xsk/decompiler.cpp index 25fab370..2c7f7868 100644 --- a/src/s4/xsk/decompiler.cpp +++ b/src/s4/xsk/decompiler.cpp @@ -1845,7 +1845,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt) void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1872,7 +1872,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt) void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { if (stmt->list.at(i) == ast::kind::asm_switch) { @@ -1883,7 +1883,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt) void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) { - for (auto i = 0; i < stmt->list.size(); i++) + for (auto i = 0u; i < stmt->list.size(); i++) { auto& entry = stmt->list.at(i); @@ -1958,7 +1958,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt) void decompiler::decompile_aborts(const ast::stmt_list::ptr& block) { - for (auto i = 0; i < block->list.size(); i++) + for (auto i = 0u; i < block->list.size(); i++) { if (block->list.at(i) == ast::kind::asm_jump) { @@ -2465,7 +2465,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t auto current_case = ast::stmt(std::make_unique()); auto num = sw_stmt->list.size(); - for (auto i = 0; i < num; i++) + for (auto i = 0u; i < num; i++) { auto& entry = sw_stmt->list[0]; @@ -2654,15 +2654,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block: process_stmt(entry, blk); } - for (auto i = 0; i < stmt->list.size(); i++) + auto i = 0u; + + while (i < stmt->list.size()) { auto type = stmt->list.at(i).kind(); if (type == ast::kind::asm_create || type == ast::kind::asm_remove) { stmt->list.erase(stmt->list.begin() + i); - i--; + continue; } + + i++; } } @@ -3178,7 +3182,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3198,7 +3202,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p prec = expr->rvalue.as_node->precedence(); - if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) + if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind())) { expr->rvalue = ast::expr(std::make_unique(std::move(expr->rvalue))); } @@ -3354,7 +3358,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk) { - if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index)) + if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index)) { printf("WARNING: bad local var access\n"); } diff --git a/src/s4/xsk/lexer.cpp b/src/s4/xsk/lexer.cpp index fb73c4a2..f5cb17cb 100644 --- a/src/s4/xsk/lexer.cpp +++ b/src/s4/xsk/lexer.cpp @@ -88,8 +88,10 @@ bool buffer::push(char c) return true; } -reader::reader() : state(reader::end), buffer_pos(0), - bytes_remaining(0), last_byte(0), current_byte(0) {} +reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end) +{ + +} void reader::init(const char* data, size_t size) { @@ -129,8 +131,8 @@ void reader::advance() } } -lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)), - mode_(mode), header_top_(0), locs_(std::stack()), readers_(std::stack()) +lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)), + locs_(std::stack()), readers_(std::stack()), header_top_(0), mode_(mode), indev_(false), clean_(true) { reader_.init(data, size); } @@ -482,7 +484,7 @@ auto lexer::lex() -> parser::symbol_type default: if (last >= '0' && last <= '9') goto lex_number; - else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z') + else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z')) goto lex_name; throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last)); @@ -587,7 +589,7 @@ lex_name: { if (buffer_.data[0] != '_') { - for (auto i = 0; i < buffer_.length; i++) + for (auto i = 0u; i < buffer_.length; i++) { auto c = buffer_.data[i]; @@ -656,7 +658,7 @@ lex_number: if (last == '\'') throw comp_error(loc_, "invalid number literal"); - if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f') + if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f')) throw comp_error(loc_, "invalid number literal"); if (dot || flt) @@ -673,7 +675,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\'')) throw comp_error(loc_, "invalid octal literal"); if (curr == '\'') @@ -707,7 +709,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\'')) throw comp_error(loc_, "invalid binary literal"); if (curr == '\'') @@ -741,7 +743,7 @@ lex_number: if (state == reader::end) break; - if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\'')) + if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\'')) throw comp_error(loc_, "invalid hexadecimal literal"); if (curr == '\'') diff --git a/src/s4/xsk/lexer.hpp b/src/s4/xsk/lexer.hpp index 67be8d2c..53d77a07 100644 --- a/src/s4/xsk/lexer.hpp +++ b/src/s4/xsk/lexer.hpp @@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000; struct buffer { char* data; - int length; + size_t length; buffer(); ~buffer(); @@ -32,9 +32,14 @@ struct reader reader(); - reader& operator=(const reader& r) + reader(const reader& obj) { - std::memcpy(this, &r, sizeof(reader)); + std::memcpy(this, &obj, sizeof(reader)); + } + + reader& operator=(const reader& obj) + { + std::memcpy(this, &obj, sizeof(reader)); return *this; } diff --git a/src/t6/xsk/lexer.hpp b/src/t6/xsk/lexer.hpp index 2fa6f797..4bf8a1c1 100644 --- a/src/t6/xsk/lexer.hpp +++ b/src/t6/xsk/lexer.hpp @@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000; struct buffer { char* data; - std::uint32_t length; + size_t length; buffer(); ~buffer(); diff --git a/src/utils/xsk/arc/nodetree.cpp b/src/utils/xsk/arc/nodetree.cpp index 522aa095..5e3f9f04 100644 --- a/src/utils/xsk/arc/nodetree.cpp +++ b/src/utils/xsk/arc/nodetree.cpp @@ -448,11 +448,11 @@ stmt_dowhile::stmt_dowhile(const location& loc, expr test, ast::stmt stmt) : nod stmt_for::stmt_for(ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {} stmt_for::stmt_for(const location& loc, ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for, loc), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {} -stmt_foreach::stmt_foreach(const location& loc, ast::stmt stmt, bool use_key) : node(kind::stmt_foreach, loc), stmt(std::move(stmt)), use_key(use_key), array_expr(nullptr), value_expr(nullptr), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {} -stmt_foreach::stmt_foreach(ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(false), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {} -stmt_foreach::stmt_foreach(ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), key_expr(std::move(key)), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(true), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {} -stmt_foreach::stmt_foreach(const location& loc, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(false), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {} -stmt_foreach::stmt_foreach(const location& loc, ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), key_expr(std::move(key)), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(true), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {} +stmt_foreach::stmt_foreach(const location& loc, ast::stmt stmt, bool use_key) : node(kind::stmt_foreach, loc), array_expr(nullptr), value_expr(nullptr), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(use_key) {} +stmt_foreach::stmt_foreach(ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(false) {} +stmt_foreach::stmt_foreach(ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(std::move(key)), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(true) {} +stmt_foreach::stmt_foreach(const location& loc, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(false) {} +stmt_foreach::stmt_foreach(const location& loc, ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(std::move(key)), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(true) {} stmt_switch::stmt_switch(expr test, stmt_list::ptr stmt) : node(kind::stmt_switch), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {} stmt_switch::stmt_switch(const location& loc, expr test, stmt_list::ptr stmt) : node(kind::stmt_switch, loc), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {} @@ -999,7 +999,7 @@ auto stmt_list::print() const -> std::string for (const auto& stmt : list) { - if ((&stmt != &list.front() && stmt.as_node->is_special_stmt() || last_special) && stmt != kind::stmt_dev && !last_devblock) + if (((&stmt != &list.front() && stmt.as_node->is_special_stmt()) || last_special) && stmt != kind::stmt_dev && !last_devblock) data += "\n"; if (stmt == kind::stmt_dev) @@ -1041,7 +1041,7 @@ auto stmt_dev::print() const -> std::string for (const auto& stmt : list->list) { - if (&stmt != &list->list.front() && stmt.as_node->is_special_stmt() || last_special) + if ((&stmt != &list->list.front() && stmt.as_node->is_special_stmt()) || last_special) data += "\n"; data += stmts_pad + stmt.print(); diff --git a/src/utils/xsk/arc/nodetree.hpp b/src/utils/xsk/arc/nodetree.hpp index f3c7ac1e..0cf35157 100644 --- a/src/utils/xsk/arc/nodetree.hpp +++ b/src/utils/xsk/arc/nodetree.hpp @@ -1836,8 +1836,8 @@ struct asm_jump_cond : public node { using ptr = std::unique_ptr; - std::string value; ast::expr expr; + std::string value; asm_jump_cond(ast::expr expr, const std::string& value); asm_jump_cond(const location& loc, ast::expr expr, const std::string& value); diff --git a/src/utils/xsk/gsc/block.cpp b/src/utils/xsk/gsc/block.cpp index cd0f45d1..2456d622 100644 --- a/src/utils/xsk/gsc/block.cpp +++ b/src/utils/xsk/gsc/block.cpp @@ -8,8 +8,8 @@ namespace xsk::gsc { -block::block() : is_last(false), abort(abort_t::abort_none), - local_vars_create_count(0), local_vars_public_count(0) { } +block::block() : local_vars_create_count(0), local_vars_public_count(0), + abort(abort_t::abort_none), is_last(false) { } void block::transfer(const block::ptr& child) { @@ -98,7 +98,7 @@ void block::merge(const std::vector& childs) { child->local_vars.insert(child->local_vars.begin() + i, this->local_vars.at(i)); } - else if (pos > i) + else if (pos > static_cast(i)) { auto& v = child->local_vars; std::rotate(v.rend() - pos - 1, v.rend() - pos, v.rend() - i); diff --git a/src/utils/xsk/gsc/nodetree.cpp b/src/utils/xsk/gsc/nodetree.cpp index a748bd5c..a38ae8c3 100644 --- a/src/utils/xsk/gsc/nodetree.cpp +++ b/src/utils/xsk/gsc/nodetree.cpp @@ -395,11 +395,11 @@ stmt_dowhile::stmt_dowhile(const location& loc, expr test, ast::stmt stmt) : nod stmt_for::stmt_for(ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {} stmt_for::stmt_for(const location& loc, ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for, loc), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {} -stmt_foreach::stmt_foreach(const location& loc, ast::stmt stmt, bool use_key) : node(kind::stmt_foreach, loc), stmt(std::move(stmt)), use_key(use_key), array_expr(nullptr), value_expr(nullptr), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {} -stmt_foreach::stmt_foreach(ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(false), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {} -stmt_foreach::stmt_foreach(ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), key_expr(std::move(key)), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(true), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {} -stmt_foreach::stmt_foreach(const location& loc, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(false), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {} -stmt_foreach::stmt_foreach(const location& loc, ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), key_expr(std::move(key)), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(true), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {} +stmt_foreach::stmt_foreach(const location& loc, ast::stmt stmt, bool use_key) : node(kind::stmt_foreach, loc), array_expr(nullptr), value_expr(nullptr), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(use_key) {} +stmt_foreach::stmt_foreach(ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(false) {} +stmt_foreach::stmt_foreach(ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(std::move(key)), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(true) {} +stmt_foreach::stmt_foreach(const location& loc, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(false) {} +stmt_foreach::stmt_foreach(const location& loc, ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(std::move(key)), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(true) {} stmt_switch::stmt_switch(expr test, stmt_list::ptr stmt) : node(kind::stmt_switch), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {} stmt_switch::stmt_switch(const location& loc, expr test, stmt_list::ptr stmt) : node(kind::stmt_switch, loc), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {} @@ -885,7 +885,7 @@ auto stmt_list::print() const -> std::string for (const auto& stmt : list) { - if (&stmt != &list.front() && stmt.as_node->is_special_stmt() || last_special) + if ((&stmt != &list.front() && stmt.as_node->is_special_stmt()) || last_special) data += "\n"; if (stmt == kind::stmt_dev) @@ -921,7 +921,7 @@ auto stmt_dev::print() const -> std::string for (const auto& stmt : list->list) { - if (&stmt != &list->list.front() && stmt.as_node->is_special_stmt() || last_special) + if ((&stmt != &list->list.front() && stmt.as_node->is_special_stmt()) || last_special) data += "\n"; if (stmt == kind::stmt_dev) diff --git a/src/utils/xsk/gsc/nodetree.hpp b/src/utils/xsk/gsc/nodetree.hpp index 4e82b8ed..a4e156d3 100644 --- a/src/utils/xsk/gsc/nodetree.hpp +++ b/src/utils/xsk/gsc/nodetree.hpp @@ -1626,8 +1626,8 @@ struct asm_jump_cond : public node { using ptr = std::unique_ptr; - std::string value; ast::expr expr; + std::string value; asm_jump_cond(ast::expr expr, const std::string& value); asm_jump_cond(const location& loc, ast::expr expr, const std::string& value); diff --git a/src/utils/xsk/utils/string.cpp b/src/utils/xsk/utils/string.cpp index 9c13d643..58e148aa 100644 --- a/src/utils/xsk/utils/string.cpp +++ b/src/utils/xsk/utils/string.cpp @@ -245,7 +245,7 @@ auto string::float_string(float value) -> std::string auto flags = integer | (str[0] == '-' ? negative : none); - for (auto i = 1; i < str.size(); i++) + for (auto i = 1u; i < str.size(); i++) { if (str[i] == '-') flags |= exp_neg; else if (str[i] == 'e') flags |= has_exp; @@ -261,7 +261,7 @@ auto string::float_string(float value) -> std::string if (flags & integer) { - auto i = (flags & negative) ? 1 : 0; + auto i = (flags & negative) ? 1u : 0u; while (str[i] != 'e') p_int.push_back(str[i++]); @@ -288,7 +288,7 @@ auto string::float_string(float value) -> std::string } else { - auto i = (flags & negative) ? 1 : 0; + auto i = (flags & negative) ? 1u : 0u; while (str[i] != '.') p_int.push_back(str[i++]);