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

Chandler Carruth chandlerc at gmail.com
Tue Sep 6 22:36:50 PDT 2011


Author: chandlerc
Date: Wed Sep  7 00:36:50 2011
New Revision: 139226

URL: http://llvm.org/viewvc/llvm-project?rev=139226&view=rev
Log:
Hoist the tab expansion into a helper function.

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=139226&r1=139225&r2=139226&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Wed Sep  7 00:36:50 2011
@@ -545,27 +545,7 @@
     else
       CaretLine.push_back('^');
 
-    // Scan the source line, looking for tabs.  If we find any, manually expand
-    // them to spaces and update the CaretLine to match.
-    for (unsigned i = 0; i != SourceLine.size(); ++i) {
-      if (SourceLine[i] != '\t') continue;
-
-      // Replace this tab with at least one space.
-      SourceLine[i] = ' ';
-
-      // Compute the number of spaces we need to insert.
-      unsigned TabStop = DiagOpts.TabStop;
-      assert(0 < TabStop && TabStop <= DiagnosticOptions::MaxTabStop &&
-             "Invalid -ftabstop value");
-      unsigned NumSpaces = ((i+TabStop)/TabStop * TabStop) - (i+1);
-      assert(NumSpaces < TabStop && "Invalid computation of space amt");
-
-      // Insert spaces into the SourceLine.
-      SourceLine.insert(i+1, NumSpaces, ' ');
-
-      // Insert spaces or ~'s into CaretLine.
-      CaretLine.insert(i+1, NumSpaces, CaretLine[i] == '~' ? '~' : ' ');
-    }
+    ExpandTabs(SourceLine, CaretLine);
 
     // If we are in -fdiagnostics-print-source-range-info mode, we are trying
     // to produce easily machine parsable output.  Add a space before the
@@ -689,6 +669,30 @@
     return FixItInsertionLine;
   }
 
+  void ExpandTabs(std::string &SourceLine, std::string &CaretLine) {
+    // Scan the source line, looking for tabs.  If we find any, manually expand
+    // them to spaces and update the CaretLine to match.
+    for (unsigned i = 0; i != SourceLine.size(); ++i) {
+      if (SourceLine[i] != '\t') continue;
+
+      // Replace this tab with at least one space.
+      SourceLine[i] = ' ';
+
+      // Compute the number of spaces we need to insert.
+      unsigned TabStop = DiagOpts.TabStop;
+      assert(0 < TabStop && TabStop <= DiagnosticOptions::MaxTabStop &&
+             "Invalid -ftabstop value");
+      unsigned NumSpaces = ((i+TabStop)/TabStop * TabStop) - (i+1);
+      assert(NumSpaces < TabStop && "Invalid computation of space amt");
+
+      // Insert spaces into the SourceLine.
+      SourceLine.insert(i+1, NumSpaces, ' ');
+
+      // Insert spaces or ~'s into CaretLine.
+      CaretLine.insert(i+1, NumSpaces, CaretLine[i] == '~' ? '~' : ' ');
+    }
+  }
+
   void EmitParseableFixits(ArrayRef<FixItHint> Hints) {
     if (!DiagOpts.ShowParseableFixits)
       return;





More information about the cfe-commits mailing list