Add Location (#88)
This commit is contained in:
@@ -22,6 +22,24 @@ struct LocalSourceRange {
|
||||
constexpr bool intersects(const LocalSourceRange& other) const {
|
||||
return begin <= other.end && end >= other.begin;
|
||||
}
|
||||
|
||||
constexpr bool valid() const {
|
||||
return begin != -1 && end != -1;
|
||||
}
|
||||
};
|
||||
|
||||
struct Location {
|
||||
/// The file path.
|
||||
std::string file;
|
||||
|
||||
/// The range in the file.
|
||||
LocalSourceRange range;
|
||||
|
||||
constexpr bool operator== (const Location& other) const = default;
|
||||
|
||||
constexpr bool valid() const {
|
||||
return !file.empty() && range.valid();
|
||||
}
|
||||
};
|
||||
|
||||
/// Get the content of the file with the given file ID.
|
||||
|
||||
@@ -124,6 +124,14 @@ public:
|
||||
/// files, we cut off the range at the end of the first file.
|
||||
std::pair<clang::FileID, LocalSourceRange> toLocalRange(clang::SourceRange range);
|
||||
|
||||
Location toLocation(clang::SourceRange range) {
|
||||
auto [fid, localRange] = toLocalRange(range);
|
||||
return Location{
|
||||
.file = getFilePath(fid).str(),
|
||||
.range = localRange,
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
/// The interested file ID.
|
||||
clang::FileID interested;
|
||||
@@ -150,7 +158,7 @@ private:
|
||||
|
||||
/// Cache for file path. It is used to avoid multiple file path lookup.
|
||||
llvm::DenseMap<clang::FileID, llvm::StringRef> pathCache;
|
||||
|
||||
|
||||
llvm::BumpPtrAllocator pathStorage;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user