aboutsummaryrefslogtreecommitdiff
path: root/Driver/HTMLDiagnostics.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-05-06 23:42:18 +0000
committerTed Kremenek <kremenek@apple.com>2008-05-06 23:42:18 +0000
commitea17d6afeffc9805f10110a49f78cef5fc726b90 (patch)
treeefb0660d5dd7f4de26cadfd8e39374fc6e108c5e /Driver/HTMLDiagnostics.cpp
parent9f525970bec0e29f32cec6141aa3baa245c5ae82 (diff)
Improve HTMLDiagnostics by understanding the "Below" hint.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50783 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/HTMLDiagnostics.cpp')
-rw-r--r--Driver/HTMLDiagnostics.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/Driver/HTMLDiagnostics.cpp b/Driver/HTMLDiagnostics.cpp
index 22e2538482..760ef25379 100644
--- a/Driver/HTMLDiagnostics.cpp
+++ b/Driver/HTMLDiagnostics.cpp
@@ -285,25 +285,39 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R,
SourceManager& SM = R.getSourceMgr();
FullSourceLoc LPos = Pos.getLogicalLoc();
unsigned FileID = SM.getCanonicalFileID(LPos.getLocation());
-
+
assert (&LPos.getManager() == &SM && "SourceManagers are different!");
if (!SM.isFromMainFile(LPos.getLocation()))
return;
+ const llvm::MemoryBuffer *Buf = SM.getBuffer(FileID);
+ const char* FileStart = Buf->getBufferStart();
+
+
// Compute the column number. Rewind from the current position to the start
// of the line.
unsigned ColNo = LPos.getColumnNumber();
const char *TokLogicalPtr = LPos.getCharacterData();
const char *LineStart = TokLogicalPtr-ColNo;
+
+ // Only compute LineEnd if we display below a line.
+ const char *LineEnd = TokLogicalPtr;
+
+ if (P.getDisplayHint() == PathDiagnosticPiece::Below) {
+ const char* FileEnd = Buf->getBufferEnd();
+
+ while (*LineEnd != '\n' && LineEnd != FileEnd)
+ ++LineEnd;
+ }
// Compute the margin offset by counting tabs and non-tabs.
unsigned PosNo = 0;
for (const char* c = LineStart; c != TokLogicalPtr; ++c)
- PosNo += *c == '\t' ? 4 : 1;
+ PosNo += *c == '\t' ? 8 : 1;
// Create the html for the message.
@@ -327,11 +341,20 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R,
// Insert the new html.
- const llvm::MemoryBuffer *Buf = SM.getBuffer(FileID);
- const char* FileStart = Buf->getBufferStart();
-
- R.InsertStrBefore(SourceLocation::getFileLoc(FileID, LineStart - FileStart),
- os.str());
+ unsigned DisplayPos = 0;
+
+ switch (P.getDisplayHint()) {
+ case PathDiagnosticPiece::Above:
+ DisplayPos = LineStart - FileStart;
+ break;
+ case PathDiagnosticPiece::Below:
+ DisplayPos = LineEnd - FileStart;
+ break;
+ default:
+ assert (false && "Unhandled hint.");
+ }
+
+ R.InsertStrBefore(SourceLocation::getFileLoc(FileID, DisplayPos), os.str());
// Now highlight the ranges.