forked from MaskRay/ccls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposition.hh
82 lines (66 loc) · 1.94 KB
/
position.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2017-2018 ccls Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "utils.hh"
#include <stdint.h>
#include <string>
namespace ccls {
struct Pos {
uint16_t line = 0;
int16_t column = -1;
static Pos fromString(const std::string &encoded);
bool valid() const { return column >= 0; }
std::string toString();
// Compare two Positions and check if they are equal. Ignores the value of
// |interesting|.
bool operator==(const Pos &o) const {
return line == o.line && column == o.column;
}
bool operator<(const Pos &o) const {
if (line != o.line)
return line < o.line;
return column < o.column;
}
bool operator<=(const Pos &o) const { return !(o < *this); }
};
struct Range {
Pos start;
Pos end;
static Range fromString(const std::string &encoded);
bool valid() const { return start.valid(); }
bool contains(int line, int column) const;
std::string toString();
bool operator==(const Range &o) const {
return start == o.start && end == o.end;
}
bool operator<(const Range &o) const {
return !(start == o.start) ? start < o.start : end < o.end;
}
};
// reflection
struct JsonReader;
struct JsonWriter;
struct BinaryReader;
struct BinaryWriter;
void reflect(JsonReader &visitor, Pos &value);
void reflect(JsonReader &visitor, Range &value);
void reflect(JsonWriter &visitor, Pos &value);
void reflect(JsonWriter &visitor, Range &value);
void reflect(BinaryReader &visitor, Pos &value);
void reflect(BinaryReader &visitor, Range &value);
void reflect(BinaryWriter &visitor, Pos &value);
void reflect(BinaryWriter &visitor, Range &value);
} // namespace ccls
namespace std {
template <> struct hash<ccls::Range> {
std::size_t operator()(ccls::Range x) const {
union {
ccls::Range range;
uint64_t u64;
} u{x};
static_assert(sizeof(ccls::Range) == 8);
return hash<uint64_t>()(u.u64);
}
};
} // namespace std
MAKE_HASHABLE(ccls::Pos, t.line, t.column);