From 8910d0a13e9f56d2a4f82e80a45a3d808b311bc4 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sun, 21 May 2017 16:22:00 -0700 Subject: [PATCH] Fix warnings (almost all numeric cast-related) --- src/code_completion.cc | 7 ++++--- src/command_line.cc | 24 ++++++++++++------------ src/include_completion.cc | 6 +++--- src/indexer.cc | 7 +++---- src/indexer.h | 2 +- src/language_server_api.cc | 4 ++-- src/libclangmm/Cursor.cc | 2 ++ src/libclangmm/TranslationUnit.cc | 6 +++--- src/platform.cc | 2 +- src/platform_win.cc | 5 ++--- src/position.cc | 14 +++++++------- src/position.h | 2 +- src/project.cc | 4 ++-- src/query.cc | 2 +- src/query.h | 12 ++++++------ src/serializer.cc | 2 +- src/test.cc | 2 +- src/working_files.cc | 2 +- 18 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/code_completion.cc b/src/code_completion.cc index 6637c543..61f9bf98 100644 --- a/src/code_completion.cc +++ b/src/code_completion.cc @@ -294,11 +294,12 @@ void CompletionQueryMain(CompletionManager* completion_manager) { timer.ResetAndPrint("[complete] Fetching unsaved files"); timer.Reset(); + unsigned const kCompleteOptions = CXCodeComplete_IncludeMacros | CXCodeComplete_IncludeBriefComments; CXCodeCompleteResults* cx_results = clang_codeCompleteAt( session->active->cx_tu, session->file.filename.c_str(), line, column, - unsaved.data(), unsaved.size(), - CXCodeComplete_IncludeMacros | CXCodeComplete_IncludeBriefComments); + unsaved.data(), (unsigned)unsaved.size(), + kCompleteOptions); if (!cx_results) { std::cerr << "[complete] Code completion failed" << std::endl; request->on_complete({}, {}); @@ -332,7 +333,7 @@ void CompletionQueryMain(CompletionManager* completion_manager) { ls_completion_item.kind = GetCompletionKind(result.CursorKind); BuildDetailString(result.CompletionString, ls_completion_item.label, ls_completion_item.detail, ls_completion_item.insertText, &ls_completion_item.parameters_); ls_completion_item.documentation = clang::ToString(clang_getCompletionBriefComment(result.CompletionString)); - ls_completion_item.sortText = uint64_t(GetCompletionPriority(result.CompletionString, result.CursorKind, ls_completion_item.label)); + ls_completion_item.sortText = (const char)uint64_t(GetCompletionPriority(result.CompletionString, result.CursorKind, ls_completion_item.label)); // If this function is slow we can skip building insertText at the cost of some code duplication. if (!IsCallKind(result.CursorKind)) diff --git a/src/command_line.cc b/src/command_line.cc index 6d60d7a9..7ab3eea6 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -233,7 +233,7 @@ QueryFile* FindFile(QueryDatabase* db, const std::string& filename, QueryFileId* } std::cerr << "Unable to find file " << filename << std::endl; - *file_id = QueryFileId(-1); + *file_id = QueryFileId((size_t)-1); return nullptr; } @@ -1048,15 +1048,15 @@ bool ImportCachedIndex(Config* config, PerformanceImportFile tu_perf; Timer time; - std::unique_ptr cache = LoadCachedIndex(config, tu_path); + std::unique_ptr tu_cache = LoadCachedIndex(config, tu_path); tu_perf.index_load_cached = time.ElapsedMicrosecondsAndReset(); - if (!cache) + if (!tu_cache) return true; bool needs_reparse = false; // Import all dependencies. - for (auto& dependency_path : cache->dependencies) { + for (auto& dependency_path : tu_cache->dependencies) { //std::cerr << "- Got dependency " << dependency_path << std::endl; PerformanceImportFile perf; time.Reset(); @@ -1071,11 +1071,11 @@ bool ImportCachedIndex(Config* config, } // Import primary file. - if (GetLastModificationTime(tu_path) == cache->last_modification_time) + if (GetLastModificationTime(tu_path) == tu_cache->last_modification_time) file_consumer_shared->Mark(tu_path); else needs_reparse = true; - queue_do_id_map->Enqueue(Index_DoIdMap(std::move(cache), indexed_content, tu_perf, false /*is_interactive*/)); + queue_do_id_map->Enqueue(Index_DoIdMap(std::move(tu_cache), indexed_content, tu_perf, false /*is_interactive*/)); return needs_reparse; } @@ -1180,9 +1180,9 @@ bool ResetStaleFiles(Config* config, FileConsumer::SharedState* file_consumer_shared, const std::string& tu_path) { Timer time; - std::unique_ptr cache = LoadCachedIndex(config, tu_path); + std::unique_ptr tu_cache = LoadCachedIndex(config, tu_path); - if (!cache) { + if (!tu_cache) { std::cerr << "[indexer] Unable to load existing index from file when freshening (dependences will not be freshened)" << std::endl; file_consumer_shared->Mark(tu_path); return true; @@ -1191,7 +1191,7 @@ bool ResetStaleFiles(Config* config, bool needs_reparse = false; // Check dependencies - for (auto& dependency_path : cache->dependencies) { + for (auto& dependency_path : tu_cache->dependencies) { std::unique_ptr cache = LoadCachedIndex(config, dependency_path); if (GetLastModificationTime(cache->path) != cache->last_modification_time) { needs_reparse = true; @@ -1200,7 +1200,7 @@ bool ResetStaleFiles(Config* config, } // Check primary file - if (GetLastModificationTime(tu_path) != cache->last_modification_time) { + if (GetLastModificationTime(tu_path) != tu_cache->last_modification_time) { needs_reparse = true; file_consumer_shared->Mark(tu_path); } @@ -2188,7 +2188,7 @@ bool QueryDbMainLoop( } if (start == buffer_line_content->size()) continue; - int end = buffer_line_content->size(); + int end = (int)buffer_line_content->size(); while (end > 0) { char c = (*buffer_line_content)[end]; if (c == '"' || c == '>') @@ -2297,7 +2297,7 @@ bool QueryDbMainLoop( if (!func) continue; - int offset = 0; + int16_t offset = 0; std::vector base_callers = GetCallersForAllBaseFunctions(db, *func); std::vector derived_callers = GetCallersForAllDerivedFunctions(db, *func); diff --git a/src/include_completion.cc b/src/include_completion.cc index e40d8d6c..183c98d0 100644 --- a/src/include_completion.cc +++ b/src/include_completion.cc @@ -17,7 +17,7 @@ std::string ElideLongPath(Config* config, const std::string& path) { if (path.size() <= config->includeCompletionMaximumPathLength) return path; - int start = path.size() - config->includeCompletionMaximumPathLength; + size_t start = path.size() - config->includeCompletionMaximumPathLength; return ".." + path.substr(start + 2); } @@ -27,8 +27,8 @@ size_t TrimCommonPathPrefix(const std::string& result, const std::string& trimme char a = result[i]; char b = trimmer[i]; #if defined(_WIN32) - a = tolower(a); - b = tolower(b); + a = (char)tolower(a); + b = (char)tolower(b); #endif if (a != b) break; diff --git a/src/indexer.cc b/src/indexer.cc index 26cc366d..29264e39 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -34,8 +34,8 @@ Range Resolve(const CXSourceRange& range, CXFile* cx_file = nullptr) { clang_getSpellingLocation(end, nullptr, &end_line, &end_column, nullptr); return Range( - Position(start_line, start_column) /*start*/, - Position(end_line, end_column) /*end*/); + Position((int16_t)start_line, (int16_t)start_column) /*start*/, + Position((int16_t)end_line, (int16_t)end_column) /*end*/); } Range ResolveSpelling(const CXCursor& cx_cursor, CXFile* cx_file = nullptr) { @@ -685,7 +685,6 @@ clang::VisiterResult AddDeclInitializerUsagesVisitor(clang::Cursor cursor, switch (cursor.get_kind()) { case CXCursor_DeclRefExpr: - CXCursorKind referenced_kind = cursor.get_referenced().get_kind(); if (cursor.get_referenced().get_kind() != CXCursor_VarDecl) break; @@ -1173,7 +1172,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { optional parent_type_id = ResolveToDeclarationType(db, base_class->cursor); // type_def ptr could be invalidated by ResolveToDeclarationType. - IndexType* type_def = db->Resolve(type_id); + type_def = db->Resolve(type_id); if (parent_type_id) { IndexType* parent_type_def = db->Resolve(parent_type_id.value()); diff --git a/src/indexer.h b/src/indexer.h index 25d01c60..c7533935 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -91,7 +91,7 @@ struct Ref { Ref() {} // For serialization. Ref(Id id, Range loc) : id_(id), loc(loc) {} - Ref(Range loc) : id_(Id(-1)), loc(loc) {} + Ref(Range loc) : id_(Id((size_t)-1)), loc(loc) {} bool operator==(const Ref& other) { return id_ == other.id_ && loc == other.loc; diff --git a/src/language_server_api.cc b/src/language_server_api.cc index 0211eb58..25e03dfc 100644 --- a/src/language_server_api.cc +++ b/src/language_server_api.cc @@ -103,10 +103,10 @@ MessageRegistry* MessageRegistry::instance() { void lsResponseError::Write(Writer& visitor) { auto& value = *this; - int code = static_cast(this->code); + int code2 = static_cast(this->code); visitor.StartObject(); - REFLECT_MEMBER2("code", code); + REFLECT_MEMBER2("code", code2); REFLECT_MEMBER(message); if (data) { visitor.Key("data"); diff --git a/src/libclangmm/Cursor.cc b/src/libclangmm/Cursor.cc index 79f2ab99..2690296f 100644 --- a/src/libclangmm/Cursor.cc +++ b/src/libclangmm/Cursor.cc @@ -203,6 +203,7 @@ std::string Cursor::get_type_description() const { auto type = clang_getCursorType(cx_cursor); return clang::ToString(clang_getTypeSpelling(type)); +#if false std::string spelling; auto referenced = clang_getCursorReferenced(cx_cursor); @@ -244,6 +245,7 @@ std::string Cursor::get_type_description() const { return get_spelling(); return spelling; +#endif } #if false diff --git a/src/libclangmm/TranslationUnit.cc b/src/libclangmm/TranslationUnit.cc index a43c3d0f..5d055d8a 100644 --- a/src/libclangmm/TranslationUnit.cc +++ b/src/libclangmm/TranslationUnit.cc @@ -27,8 +27,8 @@ TranslationUnit::TranslationUnit(Index& index, //CXErrorCode error_code = clang_parseTranslationUnit2FullArgv( CXErrorCode error_code = clang_parseTranslationUnit2( - index.cx_index, filepath.c_str(), args.data(), args.size(), - unsaved_files.data(), unsaved_files.size(), flags, &cx_tu); + index.cx_index, filepath.c_str(), args.data(), (int)args.size(), + unsaved_files.data(), (unsigned)unsaved_files.size(), flags, &cx_tu); switch (error_code) { case CXError_Success: @@ -61,7 +61,7 @@ TranslationUnit::~TranslationUnit() { void TranslationUnit::ReparseTranslationUnit( std::vector& unsaved) { int error_code = - clang_reparseTranslationUnit(cx_tu, unsaved.size(), unsaved.data(), + clang_reparseTranslationUnit(cx_tu, (unsigned)unsaved.size(), unsaved.data(), clang_defaultReparseOptions(cx_tu)); switch (error_code) { case CXError_Success: diff --git a/src/platform.cc b/src/platform.cc index e777a8fa..ae7a5f74 100644 --- a/src/platform.cc +++ b/src/platform.cc @@ -62,7 +62,7 @@ void MakeDirectoryRecursive(std::string path) { // Find first parent directory which doesn't exist. int first_success = -1; - for (int i = components.size(); i > 0; --i) { + for (int i = (int)components.size(); i > 0; --i) { if (TryMakeDirectory(prefix + Join(components, '/', i))) { first_success = i; break; diff --git a/src/platform_win.cc b/src/platform_win.cc index ec6d3754..7bd1d429 100644 --- a/src/platform_win.cc +++ b/src/platform_win.cc @@ -81,7 +81,7 @@ struct PlatformSharedMemoryWin : public PlatformSharedMemory { this->name = name; shmem_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, - capacity, name.c_str()); + (DWORD)capacity, name.c_str()); CheckForError({ ERROR_ALREADY_EXISTS } /*allow*/); data = MapViewOfFile(shmem_, FILE_MAP_ALL_ACCESS, 0, 0, capacity); @@ -133,7 +133,6 @@ std::string GetWorkingDirectory() { std::string NormalizePath(const std::string& path) { DWORD retval = 0; - BOOL success = false; TCHAR buffer[MAX_PATH] = TEXT(""); TCHAR buf[MAX_PATH] = TEXT(""); TCHAR** lpp_part = { NULL }; @@ -172,7 +171,7 @@ void SetCurrentThreadName(const std::string& thread_name) { THREADNAME_INFO info; info.dwType = 0x1000; info.szName = thread_name.c_str(); - info.dwThreadID = -1; + info.dwThreadID = (DWORD)-1; info.dwFlags = 0; __try { diff --git a/src/position.cc b/src/position.cc index 568c397b..0cfc191f 100644 --- a/src/position.cc +++ b/src/position.cc @@ -12,16 +12,16 @@ const char* SkipAfter(const char* input, char skip_after) { Position::Position() {} -Position::Position(int32_t line, int32_t column) +Position::Position(int16_t line, int16_t column) : line(line), column(column) {} Position::Position(const char* encoded) { assert(encoded); - line = atoi(encoded); + line = (int16_t)atoi(encoded); encoded = SkipAfter(encoded, ':'); assert(encoded); - column = atoi(encoded); + column = (int16_t)atoi(encoded); } std::string Position::ToString() { @@ -78,19 +78,19 @@ Range::Range(Position start, Position end) : start(start), end(end) {} Range::Range(const char* encoded) { end = start; - start.line = atoi(encoded); + start.line = (int16_t)atoi(encoded); encoded = SkipAfter(encoded, ':'); assert(encoded); - start.column = atoi(encoded); + start.column = (int16_t)atoi(encoded); encoded = SkipAfter(encoded, '-'); assert(encoded); - end.line = atoi(encoded); + end.line = (int16_t)atoi(encoded); encoded = SkipAfter(encoded, ':'); assert(encoded); - end.column = atoi(encoded); + end.column = (int16_t)atoi(encoded); } bool Range::Contains(int line, int column) const { diff --git a/src/position.h b/src/position.h index b1ccc9b2..35e3b91c 100644 --- a/src/position.h +++ b/src/position.h @@ -11,7 +11,7 @@ struct Position { int16_t column = -1; Position(); - Position(int32_t line, int32_t column); + Position(int16_t line, int16_t column); explicit Position(const char* encoded); std::string ToString(); diff --git a/src/project.cc b/src/project.cc index d565eeba..271ea857 100644 --- a/src/project.cc +++ b/src/project.cc @@ -287,8 +287,8 @@ std::vector LoadCompilationEntriesFromDirectory( unsigned num_args = clang_CompileCommand_getNumArgs(cx_command); entry.args.reserve(num_args); - for (unsigned i = 0; i < num_args; ++i) - entry.args.push_back(clang::ToString(clang_CompileCommand_getArg(cx_command, i))); + for (unsigned j = 0; j < num_args; ++j) + entry.args.push_back(clang::ToString(clang_CompileCommand_getArg(cx_command, j))); result.push_back(GetCompilationEntryFromCompileCommandEntry(quote_includes, angle_includes, extra_flags, entry)); } diff --git a/src/query.cc b/src/query.cc index b640342b..6e1d94a0 100644 --- a/src/query.cc +++ b/src/query.cc @@ -315,7 +315,7 @@ QueryTypeId IdMap::ToQuery(IndexTypeId id) const { return QueryTypeId(cached_type_ids_.find(id)->second); } QueryFuncId IdMap::ToQuery(IndexFuncId id) const { - if (id.id == -1) return QueryFuncId(-1); + if (id.id == -1) return QueryFuncId((size_t)-1); assert(cached_func_ids_.find(id) != cached_func_ids_.end()); return QueryFuncId(cached_func_ids_.find(id)->second); } diff --git a/src/query.h b/src/query.h index 7ecdc8ea..69b5314f 100644 --- a/src/query.h +++ b/src/query.h @@ -37,7 +37,7 @@ struct QueryLocation { QueryLocation(QueryFileId path, Range range) : path(path), range(range) {} - QueryLocation OffsetStartColumn(int offset) const { + QueryLocation OffsetStartColumn(int16_t offset) const { QueryLocation result = *this; result.range.start.column += offset; return result; @@ -65,7 +65,7 @@ struct SymbolIdx { SymbolKind kind; size_t idx; - SymbolIdx() : kind(SymbolKind::Invalid), idx(-1) {} // Default ctor needed by stdlib. Do not use. + SymbolIdx() : kind(SymbolKind::Invalid), idx((size_t)-1) {} // Default ctor needed by stdlib. Do not use. SymbolIdx(SymbolKind kind, uint64_t idx) : kind(kind), idx(idx) {} bool operator==(const SymbolIdx& that) const { @@ -172,7 +172,7 @@ struct QueryFile { using DefUpdate = Def; DefUpdate def; - size_t detailed_name_idx = -1; + size_t detailed_name_idx = (size_t)-1; QueryFile(const std::string& path) { def.path = path; } }; @@ -188,7 +188,7 @@ struct QueryType { std::vector derived; std::vector instances; std::vector uses; - size_t detailed_name_idx = -1; + size_t detailed_name_idx = (size_t)-1; QueryType(const Usr& usr) : def(usr) {} }; @@ -203,7 +203,7 @@ struct QueryFunc { std::vector declarations; std::vector derived; std::vector callers; - size_t detailed_name_idx = -1; + size_t detailed_name_idx = (size_t)-1; QueryFunc(const Usr& usr) : def(usr) {} }; @@ -214,7 +214,7 @@ struct QueryVar { DefUpdate def; std::vector uses; - size_t detailed_name_idx = -1; + size_t detailed_name_idx = (size_t)-1; QueryVar(const Usr& usr) : def(usr) {} }; diff --git a/src/serializer.cc b/src/serializer.cc index a13ced61..3fa5e509 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -8,7 +8,7 @@ bool gTestOutputMode = false; // int16_t void Reflect(Reader& visitor, int16_t& value) { - value = visitor.GetInt(); + value = (int16_t)visitor.GetInt(); } void Reflect(Writer& visitor, int16_t& value) { visitor.Int(value); diff --git a/src/test.cc b/src/test.cc index f8a45543..6d051b69 100644 --- a/src/test.cc +++ b/src/test.cc @@ -193,7 +193,7 @@ void RunTests() { std::cout << "[Enter to continue - type u to update test, a to update all]"; char c = 'u'; if (!update_all) { - c = std::cin.get(); + c = (char)std::cin.get(); std::cin.get(); } diff --git a/src/working_files.cc b/src/working_files.cc index 88a4be5c..b8d0a24c 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -10,7 +10,7 @@ namespace { lsPosition GetPositionForOffset(const std::string& content, int offset) { if (offset >= content.size()) - offset = content.size() - 1; + offset = (int)content.size() - 1; lsPosition result; int i = 0;