[cfe-commits] r64754 - in /cfe/trunk: include/clang/Driver/TextDiagnosticPrinter.h lib/Driver/TextDiagnosticPrinter.cpp
Chris Lattner
sabre at nondot.org
Mon Feb 16 23:51:54 PST 2009
Author: lattner
Date: Tue Feb 17 01:51:53 2009
New Revision: 64754
URL: http://llvm.org/viewvc/llvm-project?rev=64754&view=rev
Log:
break down EmitCaretDiagnostic to use more primitive calls.
Modified:
cfe/trunk/include/clang/Driver/TextDiagnosticPrinter.h
cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp
Modified: cfe/trunk/include/clang/Driver/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/TextDiagnosticPrinter.h?rev=64754&r1=64753&r2=64754&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/include/clang/Driver/TextDiagnosticPrinter.h Tue Feb 17 01:51:53 2009
@@ -46,7 +46,8 @@
std::string &CaretLine,
const std::string &SourceLine);
- void EmitCaretDiagnostic(FullSourceLoc Loc, const DiagnosticInfo &Info);
+ void EmitCaretDiagnostic(const DiagnosticInfo &Info,
+ SourceLocation Loc, SourceManager &SM);
virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
const DiagnosticInfo &Info);
Modified: cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp?rev=64754&r1=64753&r2=64754&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp Tue Feb 17 01:51:53 2009
@@ -101,18 +101,31 @@
CaretLine[i] = '~';
}
-void TextDiagnosticPrinter::EmitCaretDiagnostic(FullSourceLoc ILoc,
- const DiagnosticInfo &Info) {
- unsigned ColNo = ILoc.getInstantiationColumnNumber();
+void TextDiagnosticPrinter::EmitCaretDiagnostic(const DiagnosticInfo &Info,
+ SourceLocation Loc,
+ SourceManager &SM) {
+ assert(Loc.isFileID() && "Shouldn't have instantiation locs here");
+
+ // Decompose the location into a FID/Offset pair.
+ std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
+ FileID FID = LocInfo.first;
+ unsigned FileOffset = LocInfo.second;
+
+ // Get information about the buffer it points into.
+ std::pair<const char*, const char*> BufferInfo = SM.getBufferData(FID);
+ const char *BufStart = BufferInfo.first;
+ const char *BufEnd = BufferInfo.second;
+
+ unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
// Rewind from the current position to the start of the line.
- const char *TokInstantiationPtr = ILoc.getCharacterData();
- const char *LineStart = TokInstantiationPtr-ColNo+1; // Column # is 1-based.
+ const char *TokPtr = BufStart+FileOffset;
+ const char *LineStart = TokPtr-ColNo+1; // Column # is 1-based.
+
// Compute the line end. Scan forward from the error position to the end of
// the line.
- const char *BufEnd = ILoc.getBufferData().second;
- const char *LineEnd = TokInstantiationPtr;
+ const char *LineEnd = TokPtr;
while (LineEnd != BufEnd &&
*LineEnd != '\n' && *LineEnd != '\r')
++LineEnd;
@@ -125,10 +138,12 @@
std::string CaretLine(LineEnd-LineStart, ' ');
// Highlight all of the characters covered by Ranges with ~ characters.
- for (unsigned i = 0; i != Info.getNumRanges(); ++i)
- HighlightRange(Info.getRange(i), ILoc.getManager(),
- ILoc.getInstantiationLineNumber(),
- ILoc.getFileID(), CaretLine, SourceLine);
+ if (Info.getNumRanges()) {
+ unsigned LineNo = SM.getLineNumber(FID, FileOffset);
+
+ for (unsigned i = 0; i != Info.getNumRanges(); ++i)
+ HighlightRange(Info.getRange(i), SM, LineNo, FID, CaretLine, SourceLine);
+ }
// Next, insert the caret itself.
if (ColNo-1 < CaretLine.size())
@@ -216,8 +231,7 @@
// Inspect the actual instantiation point of the diagnostic, we don't care
// about presumed locations anymore.
FullSourceLoc ILoc = Info.getLocation().getInstantiationLoc();
-
- EmitCaretDiagnostic(ILoc, Info);
+ EmitCaretDiagnostic(Info, ILoc, ILoc.getManager());
}
OS.flush();
More information about the cfe-commits
mailing list