Skip to content

Commit

Permalink
Change Pos::line from int16_t to uint16_t
Browse files Browse the repository at this point in the history
This allows representing line 0 ~ 65535.
  • Loading branch information
MaskRay committed Feb 23, 2019
1 parent 9dea14e commit dcaa5a0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/clang_tu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static Pos Decomposed2LineAndCol(const SourceManager &SM,
while (i < P.size() && (uint8_t)P[i] >= 128 && (uint8_t)P[i] < 192)
i++;
}
return {(int16_t)std::min<int>(l, INT16_MAX),
return {(uint16_t)std::min<int>(l, UINT16_MAX),
(int16_t)std::min<int>(c, INT16_MAX)};
}

Expand Down
4 changes: 2 additions & 2 deletions src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,8 @@ class IndexFrontendAction : public ASTFrontendAction {
};
} // namespace

const int IndexFile::kMajorVersion = 19;
const int IndexFile::kMinorVersion = 1;
const int IndexFile::kMajorVersion = 20;
const int IndexFile::kMinorVersion = 0;

IndexFile::IndexFile(const std::string &path, const std::string &contents)
: path(path), file_contents(contents) {}
Expand Down
4 changes: 2 additions & 2 deletions src/message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ void EmitSemanticHighlight(DB *db, WorkingFile *wfile, QueryFile &file) {
// but we still want to keep the range for jumping to definition.
std::string_view concise_name =
detailed_name.substr(0, detailed_name.find('<'));
int16_t start_line = sym.range.start.line;
uint16_t start_line = sym.range.start.line;
int16_t start_col = sym.range.start.column;
if (start_line < 0 || start_line >= wfile->index_lines.size())
if (start_line >= wfile->index_lines.size())
continue;
std::string_view line = wfile->index_lines[start_line];
sym.range.end.line = start_line;
Expand Down
2 changes: 1 addition & 1 deletion src/messages/ccls_navigate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void MessageHandler::ccls_navigate(JsonReader &reader, ReplyOnce &reply) {
if (auto line =
wf->GetIndexPosFromBufferPos(ls_pos.line, &ls_pos.character, false))
ls_pos.line = *line;
Pos pos{(int16_t)ls_pos.line, (int16_t)ls_pos.character};
Pos pos{(uint16_t)ls_pos.line, (int16_t)ls_pos.character};

Maybe<Range> res;
switch (param.direction[0]) {
Expand Down
8 changes: 4 additions & 4 deletions src/position.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace ccls {
Pos Pos::FromString(const std::string &encoded) {
char *p = const_cast<char *>(encoded.c_str());
int16_t line = int16_t(strtol(p, &p, 10)) - 1;
uint16_t line = uint16_t(strtoul(p, &p, 10) - 1);
assert(*p == ':');
p++;
int16_t column = int16_t(strtol(p, &p, 10)) - 1;
Expand All @@ -32,14 +32,14 @@ std::string Pos::ToString() {
Range Range::FromString(const std::string &encoded) {
Pos start, end;
char *p = const_cast<char *>(encoded.c_str());
start.line = int16_t(strtol(p, &p, 10)) - 1;
start.line = uint16_t(strtoul(p, &p, 10) - 1);
assert(*p == ':');
p++;
start.column = int16_t(strtol(p, &p, 10)) - 1;
assert(*p == '-');
p++;

end.line = int16_t(strtol(p, &p, 10)) - 1;
end.line = uint16_t(strtoul(p, &p, 10) - 1);
assert(*p == ':');
p++;
end.column = int16_t(strtol(p, nullptr, 10)) - 1;
Expand All @@ -49,7 +49,7 @@ Range Range::FromString(const std::string &encoded) {
bool Range::Contains(int line, int column) const {
if (line > INT16_MAX)
return false;
Pos p{(int16_t)line, (int16_t)std::min<int>(column, INT16_MAX)};
Pos p{(uint16_t)line, (int16_t)std::min<int>(column, INT16_MAX)};
return !(p < start) && p < end;
}

Expand Down
4 changes: 2 additions & 2 deletions src/position.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

namespace ccls {
struct Pos {
int16_t line = -1;
uint16_t line = 0;
int16_t column = -1;

static Pos FromString(const std::string &encoded);

bool Valid() const { return line >= 0; }
bool Valid() const { return column >= 0; }
std::string ToString();

// Compare two Positions and check if they are equal. Ignores the value of
Expand Down

0 comments on commit dcaa5a0

Please sign in to comment.