| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOLLOCATION_H |
| 10 |
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOLLOCATION_H |
| 11 |
|
| 12 |
#include "llvm/ADT/StringRef.h" |
| 13 |
#include "llvm/Support/raw_ostream.h" |
| 14 |
#include <cstdint> |
| 15 |
|
| 16 |
namespace clang { |
| 17 |
namespace clangd { |
| 18 |
|
| 19 |
struct SymbolLocation { |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
struct Position { |
| 33 |
Position() : LineColumnPacked(0) {} |
| 34 |
void setLine(uint32_t Line); |
| 35 |
uint32_t line() const { return LineColumnPacked >> ColumnBits; } |
| 36 |
void setColumn(uint32_t Column); |
| 37 |
uint32_t column() const { return LineColumnPacked & MaxColumn; } |
| 38 |
uint32_t rep() const { return LineColumnPacked; } |
| 39 |
|
| 40 |
bool hasOverflow() const { |
| 41 |
return line() == MaxLine || column() == MaxColumn; |
| 42 |
} |
| 43 |
|
| 44 |
static constexpr unsigned ColumnBits = 12; |
| 45 |
static constexpr uint32_t MaxLine = (1 << (32 - ColumnBits)) - 1; |
| 46 |
static constexpr uint32_t MaxColumn = (1 << ColumnBits) - 1; |
| 47 |
|
| 48 |
private: |
| 49 |
uint32_t LineColumnPacked; |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
Position Start; |
| 54 |
Position End; |
| 55 |
|
| 56 |
explicit operator bool() const { return !llvm::StringRef(FileURI).empty(); } |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
const char *FileURI = ""; |
| 65 |
}; |
| 66 |
|
| 67 |
inline bool operator==(const SymbolLocation::Position &L, |
| 68 |
const SymbolLocation::Position &R) { |
| 69 |
return std::make_tuple(L.line(), L.column()) == |
| 70 |
std::make_tuple(R.line(), R.column()); |
| 71 |
} |
| 72 |
inline bool operator<(const SymbolLocation::Position &L, |
| 73 |
const SymbolLocation::Position &R) { |
| 74 |
return std::make_tuple(L.line(), L.column()) < |
| 75 |
std::make_tuple(R.line(), R.column()); |
| 76 |
} |
| 77 |
inline bool operator==(const SymbolLocation &L, const SymbolLocation &R) { |
| 78 |
assert(L.FileURI && R.FileURI); |
| 79 |
return !std::strcmp(L.FileURI, R.FileURI) && |
| 80 |
std::tie(L.Start, L.End) == std::tie(R.Start, R.End); |
| 81 |
} |
| 82 |
inline bool operator<(const SymbolLocation &L, const SymbolLocation &R) { |
| 83 |
assert(L.FileURI && R.FileURI); |
| 84 |
int Cmp = std::strcmp(L.FileURI, R.FileURI); |
| 85 |
if (Cmp != 0) |
| 86 |
return Cmp < 0; |
| 87 |
return std::tie(L.Start, L.End) < std::tie(R.Start, R.End); |
| 88 |
} |
| 89 |
|
| 90 |
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolLocation &); |
| 91 |
|
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
#endif |