Fix warnings (almost all numeric cast-related)

This commit is contained in:
Jacob Dufault 2017-05-21 16:22:00 -07:00
parent e182ac12ae
commit 8910d0a13e
18 changed files with 53 additions and 52 deletions

View File

@ -294,11 +294,12 @@ void CompletionQueryMain(CompletionManager* completion_manager) {
timer.ResetAndPrint("[complete] Fetching unsaved files"); timer.ResetAndPrint("[complete] Fetching unsaved files");
timer.Reset(); timer.Reset();
unsigned const kCompleteOptions = CXCodeComplete_IncludeMacros | CXCodeComplete_IncludeBriefComments;
CXCodeCompleteResults* cx_results = clang_codeCompleteAt( CXCodeCompleteResults* cx_results = clang_codeCompleteAt(
session->active->cx_tu, session->active->cx_tu,
session->file.filename.c_str(), line, column, session->file.filename.c_str(), line, column,
unsaved.data(), unsaved.size(), unsaved.data(), (unsigned)unsaved.size(),
CXCodeComplete_IncludeMacros | CXCodeComplete_IncludeBriefComments); kCompleteOptions);
if (!cx_results) { if (!cx_results) {
std::cerr << "[complete] Code completion failed" << std::endl; std::cerr << "[complete] Code completion failed" << std::endl;
request->on_complete({}, {}); request->on_complete({}, {});
@ -332,7 +333,7 @@ void CompletionQueryMain(CompletionManager* completion_manager) {
ls_completion_item.kind = GetCompletionKind(result.CursorKind); 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_); 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.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 this function is slow we can skip building insertText at the cost of some code duplication.
if (!IsCallKind(result.CursorKind)) if (!IsCallKind(result.CursorKind))

View File

@ -233,7 +233,7 @@ QueryFile* FindFile(QueryDatabase* db, const std::string& filename, QueryFileId*
} }
std::cerr << "Unable to find file " << filename << std::endl; std::cerr << "Unable to find file " << filename << std::endl;
*file_id = QueryFileId(-1); *file_id = QueryFileId((size_t)-1);
return nullptr; return nullptr;
} }
@ -1048,15 +1048,15 @@ bool ImportCachedIndex(Config* config,
PerformanceImportFile tu_perf; PerformanceImportFile tu_perf;
Timer time; Timer time;
std::unique_ptr<IndexFile> cache = LoadCachedIndex(config, tu_path); std::unique_ptr<IndexFile> tu_cache = LoadCachedIndex(config, tu_path);
tu_perf.index_load_cached = time.ElapsedMicrosecondsAndReset(); tu_perf.index_load_cached = time.ElapsedMicrosecondsAndReset();
if (!cache) if (!tu_cache)
return true; return true;
bool needs_reparse = false; bool needs_reparse = false;
// Import all dependencies. // Import all dependencies.
for (auto& dependency_path : cache->dependencies) { for (auto& dependency_path : tu_cache->dependencies) {
//std::cerr << "- Got dependency " << dependency_path << std::endl; //std::cerr << "- Got dependency " << dependency_path << std::endl;
PerformanceImportFile perf; PerformanceImportFile perf;
time.Reset(); time.Reset();
@ -1071,11 +1071,11 @@ bool ImportCachedIndex(Config* config,
} }
// Import primary file. // 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); file_consumer_shared->Mark(tu_path);
else else
needs_reparse = true; 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; return needs_reparse;
} }
@ -1180,9 +1180,9 @@ bool ResetStaleFiles(Config* config,
FileConsumer::SharedState* file_consumer_shared, FileConsumer::SharedState* file_consumer_shared,
const std::string& tu_path) { const std::string& tu_path) {
Timer time; Timer time;
std::unique_ptr<IndexFile> cache = LoadCachedIndex(config, tu_path); std::unique_ptr<IndexFile> 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; 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); file_consumer_shared->Mark(tu_path);
return true; return true;
@ -1191,7 +1191,7 @@ bool ResetStaleFiles(Config* config,
bool needs_reparse = false; bool needs_reparse = false;
// Check dependencies // Check dependencies
for (auto& dependency_path : cache->dependencies) { for (auto& dependency_path : tu_cache->dependencies) {
std::unique_ptr<IndexFile> cache = LoadCachedIndex(config, dependency_path); std::unique_ptr<IndexFile> cache = LoadCachedIndex(config, dependency_path);
if (GetLastModificationTime(cache->path) != cache->last_modification_time) { if (GetLastModificationTime(cache->path) != cache->last_modification_time) {
needs_reparse = true; needs_reparse = true;
@ -1200,7 +1200,7 @@ bool ResetStaleFiles(Config* config,
} }
// Check primary file // Check primary file
if (GetLastModificationTime(tu_path) != cache->last_modification_time) { if (GetLastModificationTime(tu_path) != tu_cache->last_modification_time) {
needs_reparse = true; needs_reparse = true;
file_consumer_shared->Mark(tu_path); file_consumer_shared->Mark(tu_path);
} }
@ -2188,7 +2188,7 @@ bool QueryDbMainLoop(
} }
if (start == buffer_line_content->size()) if (start == buffer_line_content->size())
continue; continue;
int end = buffer_line_content->size(); int end = (int)buffer_line_content->size();
while (end > 0) { while (end > 0) {
char c = (*buffer_line_content)[end]; char c = (*buffer_line_content)[end];
if (c == '"' || c == '>') if (c == '"' || c == '>')
@ -2297,7 +2297,7 @@ bool QueryDbMainLoop(
if (!func) if (!func)
continue; continue;
int offset = 0; int16_t offset = 0;
std::vector<QueryFuncRef> base_callers = GetCallersForAllBaseFunctions(db, *func); std::vector<QueryFuncRef> base_callers = GetCallersForAllBaseFunctions(db, *func);
std::vector<QueryFuncRef> derived_callers = GetCallersForAllDerivedFunctions(db, *func); std::vector<QueryFuncRef> derived_callers = GetCallersForAllDerivedFunctions(db, *func);

View File

@ -17,7 +17,7 @@ std::string ElideLongPath(Config* config, const std::string& path) {
if (path.size() <= config->includeCompletionMaximumPathLength) if (path.size() <= config->includeCompletionMaximumPathLength)
return path; return path;
int start = path.size() - config->includeCompletionMaximumPathLength; size_t start = path.size() - config->includeCompletionMaximumPathLength;
return ".." + path.substr(start + 2); 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 a = result[i];
char b = trimmer[i]; char b = trimmer[i];
#if defined(_WIN32) #if defined(_WIN32)
a = tolower(a); a = (char)tolower(a);
b = tolower(b); b = (char)tolower(b);
#endif #endif
if (a != b) if (a != b)
break; break;

View File

@ -34,8 +34,8 @@ Range Resolve(const CXSourceRange& range, CXFile* cx_file = nullptr) {
clang_getSpellingLocation(end, nullptr, &end_line, &end_column, nullptr); clang_getSpellingLocation(end, nullptr, &end_line, &end_column, nullptr);
return Range( return Range(
Position(start_line, start_column) /*start*/, Position((int16_t)start_line, (int16_t)start_column) /*start*/,
Position(end_line, end_column) /*end*/); Position((int16_t)end_line, (int16_t)end_column) /*end*/);
} }
Range ResolveSpelling(const CXCursor& cx_cursor, CXFile* cx_file = nullptr) { Range ResolveSpelling(const CXCursor& cx_cursor, CXFile* cx_file = nullptr) {
@ -685,7 +685,6 @@ clang::VisiterResult AddDeclInitializerUsagesVisitor(clang::Cursor cursor,
switch (cursor.get_kind()) { switch (cursor.get_kind()) {
case CXCursor_DeclRefExpr: case CXCursor_DeclRefExpr:
CXCursorKind referenced_kind = cursor.get_referenced().get_kind();
if (cursor.get_referenced().get_kind() != CXCursor_VarDecl) if (cursor.get_referenced().get_kind() != CXCursor_VarDecl)
break; break;
@ -1173,7 +1172,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
optional<IndexTypeId> parent_type_id = optional<IndexTypeId> parent_type_id =
ResolveToDeclarationType(db, base_class->cursor); ResolveToDeclarationType(db, base_class->cursor);
// type_def ptr could be invalidated by ResolveToDeclarationType. // 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) { if (parent_type_id) {
IndexType* parent_type_def = IndexType* parent_type_def =
db->Resolve(parent_type_id.value()); db->Resolve(parent_type_id.value());

View File

@ -91,7 +91,7 @@ struct Ref {
Ref() {} // For serialization. Ref() {} // For serialization.
Ref(Id<T> id, Range loc) : id_(id), loc(loc) {} Ref(Id<T> id, Range loc) : id_(id), loc(loc) {}
Ref(Range loc) : id_(Id<T>(-1)), loc(loc) {} Ref(Range loc) : id_(Id<T>((size_t)-1)), loc(loc) {}
bool operator==(const Ref<T>& other) { bool operator==(const Ref<T>& other) {
return id_ == other.id_ && loc == other.loc; return id_ == other.id_ && loc == other.loc;

View File

@ -103,10 +103,10 @@ MessageRegistry* MessageRegistry::instance() {
void lsResponseError::Write(Writer& visitor) { void lsResponseError::Write(Writer& visitor) {
auto& value = *this; auto& value = *this;
int code = static_cast<int>(this->code); int code2 = static_cast<int>(this->code);
visitor.StartObject(); visitor.StartObject();
REFLECT_MEMBER2("code", code); REFLECT_MEMBER2("code", code2);
REFLECT_MEMBER(message); REFLECT_MEMBER(message);
if (data) { if (data) {
visitor.Key("data"); visitor.Key("data");

View File

@ -203,6 +203,7 @@ std::string Cursor::get_type_description() const {
auto type = clang_getCursorType(cx_cursor); auto type = clang_getCursorType(cx_cursor);
return clang::ToString(clang_getTypeSpelling(type)); return clang::ToString(clang_getTypeSpelling(type));
#if false
std::string spelling; std::string spelling;
auto referenced = clang_getCursorReferenced(cx_cursor); auto referenced = clang_getCursorReferenced(cx_cursor);
@ -244,6 +245,7 @@ std::string Cursor::get_type_description() const {
return get_spelling(); return get_spelling();
return spelling; return spelling;
#endif
} }
#if false #if false

View File

@ -27,8 +27,8 @@ TranslationUnit::TranslationUnit(Index& index,
//CXErrorCode error_code = clang_parseTranslationUnit2FullArgv( //CXErrorCode error_code = clang_parseTranslationUnit2FullArgv(
CXErrorCode error_code = clang_parseTranslationUnit2( CXErrorCode error_code = clang_parseTranslationUnit2(
index.cx_index, filepath.c_str(), args.data(), args.size(), index.cx_index, filepath.c_str(), args.data(), (int)args.size(),
unsaved_files.data(), unsaved_files.size(), flags, &cx_tu); unsaved_files.data(), (unsigned)unsaved_files.size(), flags, &cx_tu);
switch (error_code) { switch (error_code) {
case CXError_Success: case CXError_Success:
@ -61,7 +61,7 @@ TranslationUnit::~TranslationUnit() {
void TranslationUnit::ReparseTranslationUnit( void TranslationUnit::ReparseTranslationUnit(
std::vector<CXUnsavedFile>& unsaved) { std::vector<CXUnsavedFile>& unsaved) {
int error_code = int error_code =
clang_reparseTranslationUnit(cx_tu, unsaved.size(), unsaved.data(), clang_reparseTranslationUnit(cx_tu, (unsigned)unsaved.size(), unsaved.data(),
clang_defaultReparseOptions(cx_tu)); clang_defaultReparseOptions(cx_tu));
switch (error_code) { switch (error_code) {
case CXError_Success: case CXError_Success:

View File

@ -62,7 +62,7 @@ void MakeDirectoryRecursive(std::string path) {
// Find first parent directory which doesn't exist. // Find first parent directory which doesn't exist.
int first_success = -1; 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))) { if (TryMakeDirectory(prefix + Join(components, '/', i))) {
first_success = i; first_success = i;
break; break;

View File

@ -81,7 +81,7 @@ struct PlatformSharedMemoryWin : public PlatformSharedMemory {
this->name = name; this->name = name;
shmem_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, shmem_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
capacity, name.c_str()); (DWORD)capacity, name.c_str());
CheckForError({ ERROR_ALREADY_EXISTS } /*allow*/); CheckForError({ ERROR_ALREADY_EXISTS } /*allow*/);
data = MapViewOfFile(shmem_, FILE_MAP_ALL_ACCESS, 0, 0, capacity); data = MapViewOfFile(shmem_, FILE_MAP_ALL_ACCESS, 0, 0, capacity);
@ -133,7 +133,6 @@ std::string GetWorkingDirectory() {
std::string NormalizePath(const std::string& path) { std::string NormalizePath(const std::string& path) {
DWORD retval = 0; DWORD retval = 0;
BOOL success = false;
TCHAR buffer[MAX_PATH] = TEXT(""); TCHAR buffer[MAX_PATH] = TEXT("");
TCHAR buf[MAX_PATH] = TEXT(""); TCHAR buf[MAX_PATH] = TEXT("");
TCHAR** lpp_part = { NULL }; TCHAR** lpp_part = { NULL };
@ -172,7 +171,7 @@ void SetCurrentThreadName(const std::string& thread_name) {
THREADNAME_INFO info; THREADNAME_INFO info;
info.dwType = 0x1000; info.dwType = 0x1000;
info.szName = thread_name.c_str(); info.szName = thread_name.c_str();
info.dwThreadID = -1; info.dwThreadID = (DWORD)-1;
info.dwFlags = 0; info.dwFlags = 0;
__try { __try {

View File

@ -12,16 +12,16 @@ const char* SkipAfter(const char* input, char skip_after) {
Position::Position() {} Position::Position() {}
Position::Position(int32_t line, int32_t column) Position::Position(int16_t line, int16_t column)
: line(line), column(column) {} : line(line), column(column) {}
Position::Position(const char* encoded) { Position::Position(const char* encoded) {
assert(encoded); assert(encoded);
line = atoi(encoded); line = (int16_t)atoi(encoded);
encoded = SkipAfter(encoded, ':'); encoded = SkipAfter(encoded, ':');
assert(encoded); assert(encoded);
column = atoi(encoded); column = (int16_t)atoi(encoded);
} }
std::string Position::ToString() { std::string Position::ToString() {
@ -78,19 +78,19 @@ Range::Range(Position start, Position end) : start(start), end(end) {}
Range::Range(const char* encoded) { Range::Range(const char* encoded) {
end = start; end = start;
start.line = atoi(encoded); start.line = (int16_t)atoi(encoded);
encoded = SkipAfter(encoded, ':'); encoded = SkipAfter(encoded, ':');
assert(encoded); assert(encoded);
start.column = atoi(encoded); start.column = (int16_t)atoi(encoded);
encoded = SkipAfter(encoded, '-'); encoded = SkipAfter(encoded, '-');
assert(encoded); assert(encoded);
end.line = atoi(encoded); end.line = (int16_t)atoi(encoded);
encoded = SkipAfter(encoded, ':'); encoded = SkipAfter(encoded, ':');
assert(encoded); assert(encoded);
end.column = atoi(encoded); end.column = (int16_t)atoi(encoded);
} }
bool Range::Contains(int line, int column) const { bool Range::Contains(int line, int column) const {

View File

@ -11,7 +11,7 @@ struct Position {
int16_t column = -1; int16_t column = -1;
Position(); Position();
Position(int32_t line, int32_t column); Position(int16_t line, int16_t column);
explicit Position(const char* encoded); explicit Position(const char* encoded);
std::string ToString(); std::string ToString();

View File

@ -287,8 +287,8 @@ std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
unsigned num_args = clang_CompileCommand_getNumArgs(cx_command); unsigned num_args = clang_CompileCommand_getNumArgs(cx_command);
entry.args.reserve(num_args); entry.args.reserve(num_args);
for (unsigned i = 0; i < num_args; ++i) for (unsigned j = 0; j < num_args; ++j)
entry.args.push_back(clang::ToString(clang_CompileCommand_getArg(cx_command, i))); entry.args.push_back(clang::ToString(clang_CompileCommand_getArg(cx_command, j)));
result.push_back(GetCompilationEntryFromCompileCommandEntry(quote_includes, angle_includes, extra_flags, entry)); result.push_back(GetCompilationEntryFromCompileCommandEntry(quote_includes, angle_includes, extra_flags, entry));
} }

View File

@ -315,7 +315,7 @@ QueryTypeId IdMap::ToQuery(IndexTypeId id) const {
return QueryTypeId(cached_type_ids_.find(id)->second); return QueryTypeId(cached_type_ids_.find(id)->second);
} }
QueryFuncId IdMap::ToQuery(IndexFuncId id) const { 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()); assert(cached_func_ids_.find(id) != cached_func_ids_.end());
return QueryFuncId(cached_func_ids_.find(id)->second); return QueryFuncId(cached_func_ids_.find(id)->second);
} }

View File

@ -37,7 +37,7 @@ struct QueryLocation {
QueryLocation(QueryFileId path, Range range) QueryLocation(QueryFileId path, Range range)
: path(path), range(range) {} : path(path), range(range) {}
QueryLocation OffsetStartColumn(int offset) const { QueryLocation OffsetStartColumn(int16_t offset) const {
QueryLocation result = *this; QueryLocation result = *this;
result.range.start.column += offset; result.range.start.column += offset;
return result; return result;
@ -65,7 +65,7 @@ struct SymbolIdx {
SymbolKind kind; SymbolKind kind;
size_t idx; 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) {} SymbolIdx(SymbolKind kind, uint64_t idx) : kind(kind), idx(idx) {}
bool operator==(const SymbolIdx& that) const { bool operator==(const SymbolIdx& that) const {
@ -172,7 +172,7 @@ struct QueryFile {
using DefUpdate = Def; using DefUpdate = Def;
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; } QueryFile(const std::string& path) { def.path = path; }
}; };
@ -188,7 +188,7 @@ struct QueryType {
std::vector<QueryTypeId> derived; std::vector<QueryTypeId> derived;
std::vector<QueryVarId> instances; std::vector<QueryVarId> instances;
std::vector<QueryLocation> uses; std::vector<QueryLocation> uses;
size_t detailed_name_idx = -1; size_t detailed_name_idx = (size_t)-1;
QueryType(const Usr& usr) : def(usr) {} QueryType(const Usr& usr) : def(usr) {}
}; };
@ -203,7 +203,7 @@ struct QueryFunc {
std::vector<QueryLocation> declarations; std::vector<QueryLocation> declarations;
std::vector<QueryFuncId> derived; std::vector<QueryFuncId> derived;
std::vector<QueryFuncRef> callers; std::vector<QueryFuncRef> callers;
size_t detailed_name_idx = -1; size_t detailed_name_idx = (size_t)-1;
QueryFunc(const Usr& usr) : def(usr) {} QueryFunc(const Usr& usr) : def(usr) {}
}; };
@ -214,7 +214,7 @@ struct QueryVar {
DefUpdate def; DefUpdate def;
std::vector<QueryLocation> uses; std::vector<QueryLocation> uses;
size_t detailed_name_idx = -1; size_t detailed_name_idx = (size_t)-1;
QueryVar(const Usr& usr) : def(usr) {} QueryVar(const Usr& usr) : def(usr) {}
}; };

View File

@ -8,7 +8,7 @@ bool gTestOutputMode = false;
// int16_t // int16_t
void Reflect(Reader& visitor, int16_t& value) { void Reflect(Reader& visitor, int16_t& value) {
value = visitor.GetInt(); value = (int16_t)visitor.GetInt();
} }
void Reflect(Writer& visitor, int16_t& value) { void Reflect(Writer& visitor, int16_t& value) {
visitor.Int(value); visitor.Int(value);

View File

@ -193,7 +193,7 @@ void RunTests() {
std::cout << "[Enter to continue - type u to update test, a to update all]"; std::cout << "[Enter to continue - type u to update test, a to update all]";
char c = 'u'; char c = 'u';
if (!update_all) { if (!update_all) {
c = std::cin.get(); c = (char)std::cin.get();
std::cin.get(); std::cin.get();
} }

View File

@ -10,7 +10,7 @@ namespace {
lsPosition GetPositionForOffset(const std::string& content, int offset) { lsPosition GetPositionForOffset(const std::string& content, int offset) {
if (offset >= content.size()) if (offset >= content.size())
offset = content.size() - 1; offset = (int)content.size() - 1;
lsPosition result; lsPosition result;
int i = 0; int i = 0;