Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc"
This reverts commit 305684.
This patch breaks extra/tools/clang-tidy
llvm-svn: 305688
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp
index 1e12ea5..a24d576 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -672,16 +672,20 @@
TextDiagnostic::~TextDiagnostic() {}
-void TextDiagnostic::emitDiagnosticMessage(
- FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level,
- StringRef Message, ArrayRef<clang::CharSourceRange> Ranges,
- DiagOrStoredDiag D) {
+void
+TextDiagnostic::emitDiagnosticMessage(SourceLocation Loc,
+ PresumedLoc PLoc,
+ DiagnosticsEngine::Level Level,
+ StringRef Message,
+ ArrayRef<clang::CharSourceRange> Ranges,
+ const SourceManager *SM,
+ DiagOrStoredDiag D) {
uint64_t StartOfLocationInfo = OS.tell();
// Emit the location of this particular diagnostic.
if (Loc.isValid())
- emitDiagnosticLoc(Loc, PLoc, Level, Ranges);
-
+ emitDiagnosticLoc(Loc, PLoc, Level, Ranges, *SM);
+
if (DiagOpts->ShowColors)
OS.resetColor();
@@ -783,16 +787,17 @@
/// This includes extracting as much location information as is present for
/// the diagnostic and printing it, as well as any include stack or source
/// ranges necessary.
-void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
+void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
DiagnosticsEngine::Level Level,
- ArrayRef<CharSourceRange> Ranges) {
+ ArrayRef<CharSourceRange> Ranges,
+ const SourceManager &SM) {
if (PLoc.isInvalid()) {
// At least print the file name if available:
- FileID FID = Loc.getFileID();
+ FileID FID = SM.getFileID(Loc);
if (FID.isValid()) {
- const FileEntry *FE = Loc.getFileEntry();
+ const FileEntry* FE = SM.getFileEntryForID(FID);
if (FE && FE->isValid()) {
- emitFilename(FE->getName(), Loc.getManager());
+ emitFilename(FE->getName(), SM);
if (FE->isInPCH())
OS << " (in PCH)";
OS << ": ";
@@ -808,7 +813,7 @@
if (DiagOpts->ShowColors)
OS.changeColor(savedColor, true);
- emitFilename(PLoc.getFilename(), Loc.getManager());
+ emitFilename(PLoc.getFilename(), SM);
switch (DiagOpts->getFormat()) {
case DiagnosticOptions::Clang: OS << ':' << LineNo; break;
case DiagnosticOptions::MSVC: OS << '(' << LineNo; break;
@@ -843,7 +848,8 @@
}
if (DiagOpts->ShowSourceRanges && !Ranges.empty()) {
- FileID CaretFileID = Loc.getExpansionLoc().getFileID();
+ FileID CaretFileID =
+ SM.getFileID(SM.getExpansionLoc(Loc));
bool PrintedRange = false;
for (ArrayRef<CharSourceRange>::const_iterator RI = Ranges.begin(),
@@ -852,10 +858,8 @@
// Ignore invalid ranges.
if (!RI->isValid()) continue;
- FullSourceLoc B =
- FullSourceLoc(RI->getBegin(), Loc.getManager()).getExpansionLoc();
- FullSourceLoc E =
- FullSourceLoc(RI->getEnd(), Loc.getManager()).getExpansionLoc();
+ SourceLocation B = SM.getExpansionLoc(RI->getBegin());
+ SourceLocation E = SM.getExpansionLoc(RI->getEnd());
// If the End location and the start location are the same and are a
// macro location, then the range was something that came from a
@@ -863,12 +867,10 @@
// best we can do is to highlight the range. If this is a
// function-like macro, we'd also like to highlight the arguments.
if (B == E && RI->getEnd().isMacroID())
- E = FullSourceLoc(RI->getEnd(), Loc.getManager())
- .getExpansionRange()
- .second;
+ E = SM.getExpansionRange(RI->getEnd()).second;
- std::pair<FileID, unsigned> BInfo = B.getDecomposedLoc();
- std::pair<FileID, unsigned> EInfo = E.getDecomposedLoc();
+ std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(B);
+ std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(E);
// If the start or end of the range is in another file, just discard
// it.
@@ -879,10 +881,13 @@
// tokens.
unsigned TokSize = 0;
if (RI->isTokenRange())
- TokSize = Lexer::MeasureTokenLength(E, E.getManager(), LangOpts);
+ TokSize = Lexer::MeasureTokenLength(E, SM, LangOpts);
- OS << '{' << B.getLineNumber() << ':' << B.getColumnNumber() << '-'
- << E.getLineNumber() << ':' << (E.getColumnNumber() + TokSize) << '}';
+ OS << '{' << SM.getLineNumber(BInfo.first, BInfo.second) << ':'
+ << SM.getColumnNumber(BInfo.first, BInfo.second) << '-'
+ << SM.getLineNumber(EInfo.first, EInfo.second) << ':'
+ << (SM.getColumnNumber(EInfo.first, EInfo.second)+TokSize)
+ << '}';
PrintedRange = true;
}
@@ -892,7 +897,9 @@
OS << ' ';
}
-void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
+void TextDiagnostic::emitIncludeLocation(SourceLocation Loc,
+ PresumedLoc PLoc,
+ const SourceManager &SM) {
if (DiagOpts->ShowLocation && PLoc.isValid())
OS << "In file included from " << PLoc.getFilename() << ':'
<< PLoc.getLine() << ":\n";
@@ -900,8 +907,9 @@
OS << "In included file:\n";
}
-void TextDiagnostic::emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
- StringRef ModuleName) {
+void TextDiagnostic::emitImportLocation(SourceLocation Loc, PresumedLoc PLoc,
+ StringRef ModuleName,
+ const SourceManager &SM) {
if (DiagOpts->ShowLocation && PLoc.isValid())
OS << "In module '" << ModuleName << "' imported from "
<< PLoc.getFilename() << ':' << PLoc.getLine() << ":\n";
@@ -909,9 +917,10 @@
OS << "In module '" << ModuleName << "':\n";
}
-void TextDiagnostic::emitBuildingModuleLocation(FullSourceLoc Loc,
+void TextDiagnostic::emitBuildingModuleLocation(SourceLocation Loc,
PresumedLoc PLoc,
- StringRef ModuleName) {
+ StringRef ModuleName,
+ const SourceManager &SM) {
if (DiagOpts->ShowLocation && PLoc.isValid())
OS << "While building module '" << ModuleName << "' imported from "
<< PLoc.getFilename() << ':' << PLoc.getLine() << ":\n";
@@ -1125,8 +1134,10 @@
/// \param Ranges The underlined ranges for this code snippet.
/// \param Hints The FixIt hints active for this diagnostic.
void TextDiagnostic::emitSnippetAndCaret(
- FullSourceLoc Loc, DiagnosticsEngine::Level Level,
- SmallVectorImpl<CharSourceRange> &Ranges, ArrayRef<FixItHint> Hints) {
+ SourceLocation Loc, DiagnosticsEngine::Level Level,
+ SmallVectorImpl<CharSourceRange>& Ranges,
+ ArrayRef<FixItHint> Hints,
+ const SourceManager &SM) {
assert(Loc.isValid() && "must have a valid source location here");
assert(Loc.isFileID() && "must have a file location here");
@@ -1143,18 +1154,18 @@
return;
// Decompose the location into a FID/Offset pair.
- std::pair<FileID, unsigned> LocInfo = Loc.getDecomposedLoc();
+ std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
FileID FID = LocInfo.first;
- const SourceManager &SM = Loc.getManager();
+ unsigned CaretFileOffset = LocInfo.second;
// Get information about the buffer it points into.
bool Invalid = false;
- StringRef BufData = Loc.getBufferData(&Invalid);
+ StringRef BufData = SM.getBufferData(FID, &Invalid);
if (Invalid)
return;
- unsigned CaretLineNo = Loc.getLineNumber();
- unsigned CaretColNo = Loc.getColumnNumber();
+ unsigned CaretLineNo = SM.getLineNumber(FID, CaretFileOffset);
+ unsigned CaretColNo = SM.getColumnNumber(FID, CaretFileOffset);
// Arbitrarily stop showing snippets when the line is too long.
static const size_t MaxLineLengthToPrint = 4096;