[NFC] DiagnosticVerifier: Move 'getColumnNumber' into SourceManager

This commit is contained in:
Anthony Latsis
2022-01-30 20:11:36 +03:00
parent b6a4923470
commit 8e4ea9b01a
4 changed files with 30 additions and 25 deletions

View File

@@ -220,6 +220,23 @@ unsigned SourceManager::getByteDistance(SourceLoc Start, SourceLoc End) const {
return End.Value.getPointer() - Start.Value.getPointer();
}
unsigned SourceManager::getColumnInBuffer(SourceLoc Loc,
unsigned BufferID) const {
assert(Loc.isValid());
const StringRef Buffer = getEntireTextForBuffer(BufferID);
const char *Ptr = static_cast<const char *>(Loc.getOpaquePointerValue());
StringRef UpToLoc = Buffer.slice(0, Ptr - Buffer.data());
size_t ColumnNo = UpToLoc.size();
size_t NewlinePos = UpToLoc.find_last_of("\r\n");
if (NewlinePos != StringRef::npos)
ColumnNo -= NewlinePos;
return static_cast<unsigned>(ColumnNo);
}
StringRef SourceManager::getEntireTextForBuffer(unsigned BufferID) const {
return LLVMSourceMgr.getMemoryBuffer(BufferID)->getBuffer();
}