[cfe-commits] r70655 - /cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp

Douglas Gregor dgregor at apple.com
Sat May 2 21:12:51 PDT 2009


Author: dgregor
Date: Sat May  2 23:12:51 2009
New Revision: 70655

URL: http://llvm.org/viewvc/llvm-project?rev=70655&view=rev
Log:
When we truncate a source line to fit it within the terminal width,
show an ellipsis where we have removed text. An example:

/Users/dgregor/Projects/llvm/tools/clang/test/Misc/message-length.c:18:120:
warning: 
      comparison of distinct pointer types ('int *' and 'float *')
  ...a_func_to_call(ip == FloatPointer, ip[ALongIndexName], ...
                    ~~ ^  ~~~~~~~~~~~~


Modified:
    cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp

Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=70655&r1=70654&r2=70655&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Sat May  2 23:12:51 2009
@@ -143,7 +143,7 @@
   if (CaretEnd < Columns)
     CaretStart = 0;
 
-  unsigned TargetColumns = Columns - 4; // Give us a little extra room.
+  unsigned TargetColumns = Columns - 8; // Give us extra room for the ellipses.
   unsigned SourceLength = SourceLine.size();
   bool StartIsFixed = false;
   while (CaretEnd - CaretStart < TargetColumns) {
@@ -231,16 +231,17 @@
   // [CaretStart, CaretEnd) is the slice we want. Update the various
   // output lines to show only this slice, with two-space padding
   // before the lines so that it looks nicer.
-  SourceLine.erase(CaretEnd, std::string::npos);
+  if (CaretEnd < SourceLine.size())
+    SourceLine.replace(CaretEnd, std::string::npos, "...");
   CaretLine.erase(CaretEnd, std::string::npos);
   if (FixItInsertionLine.size() > CaretEnd)
     FixItInsertionLine.erase(CaretEnd, std::string::npos);
   
   if (CaretStart > 2) {
-    SourceLine.replace(0, CaretStart, "  ");
-    CaretLine.replace(0, CaretStart, "  ");
+    SourceLine.replace(0, CaretStart, "  ...");
+    CaretLine.replace(0, CaretStart, "     ");
     if (FixItInsertionLine.size() >= CaretStart)
-      FixItInsertionLine.replace(0, CaretStart, "  ");
+      FixItInsertionLine.replace(0, CaretStart, "     ");
   }
 }
 





More information about the cfe-commits mailing list