[cfe-commits] r49403 - /cfe/trunk/Driver/HTMLDiagnostics.cpp

Ted Kremenek kremenek at apple.com
Tue Apr 8 14:29:20 PDT 2008


Author: kremenek
Date: Tue Apr  8 16:29:14 2008
New Revision: 49403

URL: http://llvm.org/viewvc/llvm-project?rev=49403&view=rev
Log:
Improve range highlighting in HTMLDiagnostic to correctly highlight ranges
that span multiple lines by inserting multiple "</span>" and "<span>" tags.

Modified:
    cfe/trunk/Driver/HTMLDiagnostics.cpp

Modified: cfe/trunk/Driver/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/HTMLDiagnostics.cpp?rev=49403&r1=49402&r2=49403&view=diff

==============================================================================
--- cfe/trunk/Driver/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/Driver/HTMLDiagnostics.cpp Tue Apr  8 16:29:14 2008
@@ -312,4 +312,60 @@
   
   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>");
+  }
 }





More information about the cfe-commits mailing list