diff options
| author | Ted Kremenek <kremenek@apple.com> | 2008-04-08 21:29:14 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2008-04-08 21:29:14 +0000 |
| commit | d8256ed2fe7581210d74abcb0adc28c2f5913c65 (patch) | |
| tree | 5d33d098db506794cbd066d6a6b5b588614e2899 | |
| parent | dbd1c183b06cbc9e79b4da1f27773e692fcdb624 (diff) | |
| download | bcm5719-llvm-d8256ed2fe7581210d74abcb0adc28c2f5913c65.tar.gz bcm5719-llvm-d8256ed2fe7581210d74abcb0adc28c2f5913c65.zip | |
Improve range highlighting in HTMLDiagnostic to correctly highlight ranges
that span multiple lines by inserting multiple "</span>" and "<span>" tags.
llvm-svn: 49403
| -rw-r--r-- | clang/Driver/HTMLDiagnostics.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/clang/Driver/HTMLDiagnostics.cpp b/clang/Driver/HTMLDiagnostics.cpp index 8c89e6270a8..870628963aa 100644 --- a/clang/Driver/HTMLDiagnostics.cpp +++ b/clang/Driver/HTMLDiagnostics.cpp @@ -312,4 +312,60 @@ void HTMLDiagnostics::HighlightRange(Rewriter& R, SourceRange Range, R.InsertCStrBefore(LogicalStart, "<span class=\"mrange\">"); R.InsertCStrAfter(E, "</span>"); + + if (EndLineNo == StartLineNo) + return; + + // Add in </span><span> tags for intermediate lines. + + const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(MainFileID); + + unsigned Pos = SourceMgr.getFullFilePos(LogicalStart); + unsigned EndPos = SourceMgr.getFullFilePos(E); + const char* buf = Buf->getBufferStart(); + + for (; Pos != EndPos; ++Pos) { + + SourceLocation L = SourceLocation::getFileLoc(MainFileID, Pos); + unsigned Col = SourceMgr.getColumnNumber(L); + + if (Col == 1) { + + // Start if a new line. Scan to see if we hit anything that is not + // whitespace or a newline. + + unsigned PosTmp = Pos; + bool NewLine = false; + + for ( ; PosTmp != EndPos ; ++PosTmp) { + switch (buf[PosTmp]) { + case ' ': + case '\t': continue; + case '\n': + NewLine = true; + break; + default: + break; + } + + break; + } + + if (PosTmp == EndPos) + break; + + Pos = PosTmp; + + // Don't highlight a blank line. + if (NewLine) + continue; + + // This line contains text that we should highlight. + // Ignore leading whitespace. + L = SourceLocation::getFileLoc(MainFileID, Pos); + R.InsertCStrAfter(L, "<span class=\"mrange\">"); + } + else if (buf[Pos] == '\n') + R.InsertCStrBefore(L, "</span>"); + } } |

