From 53336adfa01a795b1a48ef0923560673258c3bcb Mon Sep 17 00:00:00 2001 From: water Date: Sat, 23 Sep 2023 10:22:09 -0400 Subject: [PATCH] cpp warning fixes --- common/formatter/formatter.cpp | 2 +- common/formatter/rules/formatting_rules.cpp | 12 ++++++------ common/log/log.cpp | 2 +- decompiler/IR2/GenericElementMatcher.cpp | 8 ++++---- decompiler/level_extractor/BspHeader.cpp | 4 ++-- game/kernel/jak2/klisten.cpp | 2 +- lsp/handlers/initialize.h | 2 +- lsp/handlers/lsp_router.cpp | 2 +- lsp/handlers/text_document/completion.h | 2 +- lsp/handlers/text_document/document_color.h | 2 +- lsp/handlers/text_document/document_symbol.h | 2 +- lsp/handlers/text_document/formatting.h | 2 +- lsp/handlers/text_document/go_to.h | 2 +- lsp/handlers/text_document/hover.h | 6 +++--- 14 files changed, 25 insertions(+), 25 deletions(-) diff --git a/common/formatter/formatter.cpp b/common/formatter/formatter.cpp index 99b3b7b9d2..5eec750e4c 100644 --- a/common/formatter/formatter.cpp +++ b/common/formatter/formatter.cpp @@ -55,7 +55,7 @@ std::string apply_formatting( } // TODO - might want to make some kind of per-form config struct, simplify the passing around of // info below - for (int i = 0; i < curr_node.refs.size(); i++) { + for (int i = 0; i < (int)curr_node.refs.size(); i++) { const auto& ref = curr_node.refs.at(i); // Figure out if the element should be inlined or not bool inline_element = inline_form; diff --git a/common/formatter/rules/formatting_rules.cpp b/common/formatter/rules/formatting_rules.cpp index 6078b68ddb..bc737f120e 100644 --- a/common/formatter/rules/formatting_rules.cpp +++ b/common/formatter/rules/formatting_rules.cpp @@ -22,7 +22,7 @@ void separate_by_newline(std::string& curr_text, // We only are concerned with top level forms or elements // Skip the last element, no trailing new-lines (let the editors handle this!) // Also peek ahead to see if there was a comment on this line, if so don't separate things! - if (!containing_node.metadata.is_top_level || index >= containing_node.refs.size() - 1 || + if (!containing_node.metadata.is_top_level || index >= (int)containing_node.refs.size() - 1 || (containing_node.refs.at(index + 1).metadata.is_comment && containing_node.refs.at(index + 1).metadata.is_inline)) { return; @@ -100,7 +100,7 @@ bool form_should_be_constant_paired(const FormatterTreeNode& node) { return false; } int num_pairs = 0; - for (int i = 0; i < node.refs.size() - 1; i++) { + for (int i = 0; i < (int)node.refs.size() - 1; i++) { const auto& ref = node.refs.at(i); const auto& next_ref = node.refs.at(i + 1); if (ref.token && next_ref.token) { @@ -147,7 +147,7 @@ int compute_form_width_after_index(const FormatterTreeNode& node, } } int form_width = 0; - for (int i = 0; i < node.refs.size(); i++) { + for (int i = 0; i < (int)node.refs.size(); i++) { const auto& ref = node.refs.at(i); if (depth == 0 && i < index) { continue; @@ -275,7 +275,7 @@ void append_newline(std::string& curr_text, const bool flowing, const bool constant_pair_form, const bool force_newline) { - if (force_newline && index >= 1 || (node.metadata.is_comment && !node.metadata.is_inline)) { + if ((force_newline && index >= 1) || (node.metadata.is_comment && !node.metadata.is_inline)) { curr_text = str_util::rtrim(curr_text) + "\n"; return; } @@ -362,8 +362,8 @@ void align_lines(std::string& text, alignment_width = 1; } std::string aligned_form = ""; - for (int i = 0; i < lines.size(); i++) { - if (i >= start_index) { + for (size_t i = 0; i < lines.size(); i++) { + if ((int)i >= start_index) { aligned_form += str_util::repeat(alignment_width, " "); } aligned_form += lines.at(i); diff --git a/common/log/log.cpp b/common/log/log.cpp index 9b98cda2e5..47423624c7 100644 --- a/common/log/log.cpp +++ b/common/log/log.cpp @@ -147,7 +147,7 @@ void set_file(const std::string& filename, existing_log_files = file_util::sort_filepaths(existing_log_files, true); if (existing_log_files.size() > (LOG_ROTATE_MAX - 1)) { lg::info("removing {} log files", existing_log_files.size() - (LOG_ROTATE_MAX - 1)); - for (int i = 0; i < existing_log_files.size() - (LOG_ROTATE_MAX - 1); i++) { + for (int i = 0; i < (int)existing_log_files.size() - (LOG_ROTATE_MAX - 1); i++) { lg::info("removing {}", existing_log_files.at(i).string()); fs::remove(existing_log_files.at(i)); } diff --git a/decompiler/IR2/GenericElementMatcher.cpp b/decompiler/IR2/GenericElementMatcher.cpp index 53d85bd5d2..d52f018091 100644 --- a/decompiler/IR2/GenericElementMatcher.cpp +++ b/decompiler/IR2/GenericElementMatcher.cpp @@ -276,7 +276,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out, const Env* cons } else if (m_kind == Kind::VAR_NAME) { return env && env->get_variable_name_name_only(result) == m_str; } else if (m_reg_out_id != -1) { - if (m_kind == Kind::SAME_VAR && maps_out->regs.size() > m_reg_out_id && + if (m_kind == Kind::SAME_VAR && (int)maps_out->regs.size() > m_reg_out_id && maps_out->regs.at(m_reg_out_id)) { return env && env->get_variable_name_name_only(result) == env->get_variable_name_name_only(*maps_out->regs.at(m_reg_out_id)); @@ -695,7 +695,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out, const Env* cons if (as_let) { // fail if we have wrong number of entries/body elts or recursive marker if ((m_entry_matchers.size() != as_let->entries().size()) || - (m_sub_matchers.size() != as_let->body()->size()) || + ((int)m_sub_matchers.size() != as_let->body()->size()) || (as_let->is_star() != m_let_is_star)) { return false; } @@ -706,7 +706,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out, const Env* cons } } // now match body - for (int i = 0; i < m_sub_matchers.size(); ++i) { + for (int i = 0; i < (int)m_sub_matchers.size(); ++i) { Form fake; fake.elts().push_back(as_let->body()->elts().at(i)); if (!m_sub_matchers.at(i).do_match(&fake, maps_out, env)) { @@ -908,7 +908,7 @@ bool LetEntryMatcher::do_match(const LetElement::Entry& input, case Kind::ANY: case Kind::NAME: if (m_reg_out_id != -1) { - if (m_kind == Kind::NAME && maps_out->regs.size() > m_reg_out_id && + if (m_kind == Kind::NAME && (int)maps_out->regs.size() > m_reg_out_id && maps_out->regs.at(m_reg_out_id)) { return env && env->get_variable_name_name_only(input.dest) == env->get_variable_name_name_only(*maps_out->regs.at(m_reg_out_id)); diff --git a/decompiler/level_extractor/BspHeader.cpp b/decompiler/level_extractor/BspHeader.cpp index 98f2f4b2e4..5b00795b38 100644 --- a/decompiler/level_extractor/BspHeader.cpp +++ b/decompiler/level_extractor/BspHeader.cpp @@ -2023,8 +2023,8 @@ void DrawableInlineArrayActor::read_from_file(TypedRef ref, void CollideHash::read_from_file(TypedRef ref, const decompiler::DecompilerTypeSystem& dts, - level_tools::DrawStats* stats, - GameVersion version) { + level_tools::DrawStats* /*stats*/, + GameVersion /*version*/) { num_items = read_plain_data_field(ref, "num-items", dts); item_array = deref_label(get_field_ref(ref, "item-array", dts)); } diff --git a/game/kernel/jak2/klisten.cpp b/game/kernel/jak2/klisten.cpp index b3dea6ece6..4bcef8115f 100644 --- a/game/kernel/jak2/klisten.cpp +++ b/game/kernel/jak2/klisten.cpp @@ -178,7 +178,7 @@ int sql_query_sync(Ptr string_in) { auto new_result_ptr = call_method_of_type_arg2(intern_from_c("debug").offset, type, GOAL_NEW_METHOD, type.offset, results.size()); SQLResult* new_result = Ptr(new_result_ptr).c(); - for (int i = 0; i < results.size(); i++) { + for (int i = 0; i < (int)results.size(); i++) { new_result->data[i] = Ptr(make_debug_string_from_c(results.at(i).data())); } new_result->len = results.size(); diff --git a/lsp/handlers/initialize.h b/lsp/handlers/initialize.h index 622f4b4dd3..69ee45537a 100644 --- a/lsp/handlers/initialize.h +++ b/lsp/handlers/initialize.h @@ -8,7 +8,7 @@ using json = nlohmann::json; -std::optional initialize_handler(Workspace& workspace, int id, json params) { +std::optional initialize_handler(Workspace& /*workspace*/, int /*id*/, json /*params*/) { InitializeResult result; return result.to_json(); } diff --git a/lsp/handlers/lsp_router.cpp b/lsp/handlers/lsp_router.cpp index 182f0a0ea7..309cab1499 100644 --- a/lsp/handlers/lsp_router.cpp +++ b/lsp/handlers/lsp_router.cpp @@ -30,7 +30,7 @@ LSPRoute::LSPRoute(std::function(Workspace&, int, json)> req void LSPRouter::init_routes() { m_routes["shutdown"] = - LSPRoute([](Workspace& workspace, int id, nlohmann::json params) -> std::optional { + LSPRoute([](Workspace& /*workspace*/, int /*id*/, nlohmann::json /*params*/) -> std::optional { lg::info("Shutting down LSP due to explicit request"); exit(0); }); diff --git a/lsp/handlers/text_document/completion.h b/lsp/handlers/text_document/completion.h index 70540ec4bd..e75767d166 100644 --- a/lsp/handlers/text_document/completion.h +++ b/lsp/handlers/text_document/completion.h @@ -7,7 +7,7 @@ #include "lsp/state/data/mips_instructions.h" #include "lsp/state/workspace.h" -std::optional get_completions_handler(Workspace& workspace, int id, json params) { +std::optional get_completions_handler(Workspace& /*workspace*/, int /*id*/, json params) { auto converted_params = params.get(); // TODO - these need to be cached, diff --git a/lsp/handlers/text_document/document_color.h b/lsp/handlers/text_document/document_color.h index e88e2f4b3d..df4e5fbcf7 100644 --- a/lsp/handlers/text_document/document_color.h +++ b/lsp/handlers/text_document/document_color.h @@ -29,7 +29,7 @@ std::optional color_hexstring_to_lsp_color(const std::string& co return LSPSpec::Color{red, green, blue, 1.0}; } -std::optional document_color_handler(Workspace& workspace, int id, json raw_params) { +std::optional document_color_handler(Workspace& /*workspace*/, int /*id*/, json raw_params) { auto params = raw_params.get(); json colors = json::array(); diff --git a/lsp/handlers/text_document/document_symbol.h b/lsp/handlers/text_document/document_symbol.h index 01dbe65397..66d8159f07 100644 --- a/lsp/handlers/text_document/document_symbol.h +++ b/lsp/handlers/text_document/document_symbol.h @@ -9,7 +9,7 @@ using json = nlohmann::json; -std::optional document_symbols_handler(Workspace& workspace, int id, json params) { +std::optional document_symbols_handler(Workspace& workspace, int /*id*/, json params) { auto converted_params = params.get(); auto tracked_file = workspace.get_tracked_ir_file(converted_params.m_textDocument.m_uri); diff --git a/lsp/handlers/text_document/formatting.h b/lsp/handlers/text_document/formatting.h index bbad93c0ce..27dc6568e5 100644 --- a/lsp/handlers/text_document/formatting.h +++ b/lsp/handlers/text_document/formatting.h @@ -9,7 +9,7 @@ #include "lsp/state/data/mips_instructions.h" #include "lsp/state/workspace.h" -std::optional formatting_handler(Workspace& workspace, int id, json raw_params) { +std::optional formatting_handler(Workspace& workspace, int /*id*/, json raw_params) { auto params = raw_params.get(); const auto file_type = workspace.determine_filetype_from_uri(params.textDocument.m_uri); diff --git a/lsp/handlers/text_document/go_to.h b/lsp/handlers/text_document/go_to.h index 015cc56cb1..ba78a47314 100644 --- a/lsp/handlers/text_document/go_to.h +++ b/lsp/handlers/text_document/go_to.h @@ -7,7 +7,7 @@ #include "lsp/state/data/mips_instructions.h" #include "lsp/state/workspace.h" -std::optional go_to_definition_handler(Workspace& workspace, int id, json raw_params) { +std::optional go_to_definition_handler(Workspace& workspace, int /*id*/, json raw_params) { auto params = raw_params.get(); const auto file_type = workspace.determine_filetype_from_uri(params.m_textDocument.m_uri); diff --git a/lsp/handlers/text_document/hover.h b/lsp/handlers/text_document/hover.h index 26d854714c..b16b7a3016 100644 --- a/lsp/handlers/text_document/hover.h +++ b/lsp/handlers/text_document/hover.h @@ -173,7 +173,7 @@ std::string truncate_docstring(const std::string& docstring) { return truncated; } -std::optional hover_handler(Workspace& workspace, int id, json raw_params) { +std::optional hover_handler(Workspace& workspace, int /*id*/, json raw_params) { auto params = raw_params.get(); auto file_type = workspace.determine_filetype_from_uri(params.m_textDocument.m_uri); @@ -221,9 +221,9 @@ std::optional hover_handler(Workspace& workspace, int id, json raw_params) signature += symbol.value(); if (takes_args) { signature += "("; - for (int i = 0; i < args.size(); i++) { + for (int i = 0; i < (int)args.size(); i++) { const auto& arg = args.at(i); - if (i == args.size() - 1) { + if (i == (int)args.size() - 1) { signature += fmt::format("{}: {}", arg.name, arg.type); } else { signature += fmt::format("{}: {}, ", arg.name, arg.type);