From: Ted Kremenek Date: Tue, 8 Apr 2008 21:29:14 +0000 (+0000) Subject: Improve range highlighting in HTMLDiagnostic to correctly highlight ranges X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dab4ead0831f99c22b32b4046ee26e4b0ebcb419;p=clang Improve range highlighting in HTMLDiagnostic to correctly highlight ranges that span multiple lines by inserting multiple "" and "" tags. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49403 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/HTMLDiagnostics.cpp b/Driver/HTMLDiagnostics.cpp index 8c89e6270a..870628963a 100644 --- a/Driver/HTMLDiagnostics.cpp +++ b/Driver/HTMLDiagnostics.cpp @@ -312,4 +312,60 @@ void HTMLDiagnostics::HighlightRange(Rewriter& R, SourceRange Range, R.InsertCStrBefore(LogicalStart, ""); R.InsertCStrAfter(E, ""); + + if (EndLineNo == StartLineNo) + return; + + // Add in 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, ""); + } + else if (buf[Pos] == '\n') + R.InsertCStrBefore(L, ""); + } }