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

Chandler Carruth chandlerc at gmail.com
Thu Sep 1 23:30:31 PDT 2011


Author: chandlerc
Date: Fri Sep  2 01:30:30 2011
New Revision: 139001

URL: http://llvm.org/viewvc/llvm-project?rev=139001&view=rev
Log:
Hoist the emission of parseable fixits into a helper method, simplifying
and reducing indentation through the clever use of early exits. ;]

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=139001&r1=139000&r2=139001&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Fri Sep  2 01:30:30 2011
@@ -677,50 +677,50 @@
         OS.resetColor();
     }
 
-    if (DiagOpts.ShowParseableFixits) {
-
-      // We follow FixItRewriter's example in not (yet) handling
-      // fix-its in macros.
-      bool BadApples = false;
-      for (const FixItHint *Hint = Hints; Hint != Hints + NumHints; ++Hint) {
-        if (Hint->RemoveRange.isInvalid() ||
-            Hint->RemoveRange.getBegin().isMacroID() ||
-            Hint->RemoveRange.getEnd().isMacroID()) {
-          BadApples = true;
-          break;
-        }
-      }
-
-      if (!BadApples) {
-        for (const FixItHint *Hint = Hints; Hint != Hints + NumHints; ++Hint) {
-
-          SourceLocation B = Hint->RemoveRange.getBegin();
-          SourceLocation E = Hint->RemoveRange.getEnd();
-
-          std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(B);
-          std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(E);
+    // Print out any parseable fixit information requested by the options.
+    EmitParseableFixits(Hints, NumHints);
+  }
 
-          // Adjust for token ranges.
-          if (Hint->RemoveRange.isTokenRange())
-            EInfo.second += Lexer::MeasureTokenLength(E, SM, LangOpts);
-
-          // We specifically do not do word-wrapping or tab-expansion here,
-          // because this is supposed to be easy to parse.
-          PresumedLoc PLoc = SM.getPresumedLoc(B);
-          if (PLoc.isInvalid())
-            break;
-
-          OS << "fix-it:\"";
-          OS.write_escaped(SM.getPresumedLoc(B).getFilename());
-          OS << "\":{" << SM.getLineNumber(BInfo.first, BInfo.second)
-            << ':' << SM.getColumnNumber(BInfo.first, BInfo.second)
-            << '-' << SM.getLineNumber(EInfo.first, EInfo.second)
-            << ':' << SM.getColumnNumber(EInfo.first, EInfo.second)
-            << "}:\"";
-          OS.write_escaped(Hint->CodeToInsert);
-          OS << "\"\n";
-        }
-      }
+private:
+  void EmitParseableFixits(const FixItHint *Hints, unsigned NumHints) {
+    if (!DiagOpts.ShowParseableFixits)
+      return;
+
+    // We follow FixItRewriter's example in not (yet) handling
+    // fix-its in macros.
+    for (const FixItHint *Hint = Hints; Hint != Hints + NumHints; ++Hint) {
+      if (Hint->RemoveRange.isInvalid() ||
+          Hint->RemoveRange.getBegin().isMacroID() ||
+          Hint->RemoveRange.getEnd().isMacroID())
+        return;
+    }
+
+    for (const FixItHint *Hint = Hints; Hint != Hints + NumHints; ++Hint) {
+      SourceLocation B = Hint->RemoveRange.getBegin();
+      SourceLocation E = Hint->RemoveRange.getEnd();
+
+      std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(B);
+      std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(E);
+
+      // Adjust for token ranges.
+      if (Hint->RemoveRange.isTokenRange())
+        EInfo.second += Lexer::MeasureTokenLength(E, SM, LangOpts);
+
+      // We specifically do not do word-wrapping or tab-expansion here,
+      // because this is supposed to be easy to parse.
+      PresumedLoc PLoc = SM.getPresumedLoc(B);
+      if (PLoc.isInvalid())
+        break;
+
+      OS << "fix-it:\"";
+      OS.write_escaped(SM.getPresumedLoc(B).getFilename());
+      OS << "\":{" << SM.getLineNumber(BInfo.first, BInfo.second)
+        << ':' << SM.getColumnNumber(BInfo.first, BInfo.second)
+        << '-' << SM.getLineNumber(EInfo.first, EInfo.second)
+        << ':' << SM.getColumnNumber(EInfo.first, EInfo.second)
+        << "}:\"";
+      OS.write_escaped(Hint->CodeToInsert);
+      OS << "\"\n";
     }
   }
 };





More information about the cfe-commits mailing list