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

Ted Kremenek kremenek at apple.com
Tue May 6 16:42:19 PDT 2008


Author: kremenek
Date: Tue May  6 18:42:18 2008
New Revision: 50783

URL: http://llvm.org/viewvc/llvm-project?rev=50783&view=rev
Log:
Improve HTMLDiagnostics by understanding the "Below" hint.

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=50783&r1=50782&r2=50783&view=diff

==============================================================================
--- cfe/trunk/Driver/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/Driver/HTMLDiagnostics.cpp Tue May  6 18:42:18 2008
@@ -285,25 +285,39 @@
   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 @@
   
   // Insert the new html.
   
-  const llvm::MemoryBuffer *Buf = SM.getBuffer(FileID);
-  const char* FileStart = Buf->getBufferStart();
+  unsigned DisplayPos = 0;
   
-  R.InsertStrBefore(SourceLocation::getFileLoc(FileID, LineStart - FileStart),
-                    os.str());
+  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.
   





More information about the cfe-commits mailing list