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

Douglas Gregor dgregor at apple.com
Sun May 3 23:27:32 PDT 2009


Author: dgregor
Date: Mon May  4 01:27:32 2009
New Revision: 70831

URL: http://llvm.org/viewvc/llvm-project?rev=70831&view=rev
Log:
Tweak the extraction of the "interesting" part of a source range in two ways: 

  1) First of all, we treat _ as part of an identifier and not as
  punctuation (oops).
  2) Second of all, always make sure that the token that the ^ is
  pointing at is fully within the "interesting" part of the range.


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=70831&r1=70830&r2=70831&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Mon May  4 01:27:32 2009
@@ -113,11 +113,19 @@
   return c == ')' || c == ']' || c == '}';
 }
 
+/// \brief Determine whether this character is part of an identifier.
+static inline bool isIdentifierChar(char c) {
+  return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') ||
+    (c >= 'A' && c <= 'Z') || c == '_';
+    
+}
+
 /// \brief When the source code line we want to print is too long for
 /// the terminal, select the "interesting" region.
 static void SelectInterestingSourceRegion(std::string &SourceLine,
                                           std::string &CaretLine,
                                           std::string &FixItInsertionLine,
+                                          unsigned EndOfCaretToken,
                                           unsigned Columns) {
   if (CaretLine.size() > SourceLine.size())
     SourceLine.resize(CaretLine.size(), ' ');
@@ -132,7 +140,12 @@
   for (; CaretEnd != CaretStart; --CaretEnd)
     if (!isspace(CaretLine[CaretEnd - 1]))
       break;
-   
+
+  // Make sure we don't chop the string shorter than the caret token
+  // itself.
+  if (CaretEnd < EndOfCaretToken)
+    CaretEnd = EndOfCaretToken;
+
   // If we have a fix-it line, make sure the slice includes all of the
   // fix-it information.
   if (!FixItInsertionLine.empty()) {
@@ -208,7 +221,7 @@
           // the middle of or at the end of an expression. In these
           // cases, we either keep bringing in more "interesting" text
           // to try to get to a somewhat-complete slice of the code.
-          BadStart = ispunct(SourceLine[NewStart]);
+          BadStart = !isIdentifierChar(SourceLine[NewStart]);
         }
       } while (BadStart);
 
@@ -314,7 +327,9 @@
   const char *BufStart = BufferInfo.first;
 
   unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
-  
+  unsigned CaretEndColNo 
+    = ColNo + Lexer::MeasureTokenLength(Loc, SM, *LangOpts);
+
   // Rewind from the current position to the start of the line.
   const char *TokPtr = BufStart+FileOffset;
   const char *LineStart = TokPtr-ColNo+1; // Column # is 1-based.
@@ -408,7 +423,7 @@
   // "interesting" source region within that line.
   if (Columns && SourceLine.size() > Columns)
     SelectInterestingSourceRegion(SourceLine, CaretLine, FixItInsertionLine,
-                                  Columns);    
+                                  CaretEndColNo, Columns);
 
   // AvoidColumn tells us which column we should avoid when printing
   // the source line. If the source line would start at or near that





More information about the cfe-commits mailing list