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

Chandler Carruth chandlerc at gmail.com
Sun Sep 25 17:21:47 PDT 2011


Author: chandlerc
Date: Sun Sep 25 19:21:47 2011
New Revision: 140484

URL: http://llvm.org/viewvc/llvm-project?rev=140484&view=rev
Log:
Extract the diagnostic message formatting into a helper routine.

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=140484&r1=140483&r2=140484&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Sun Sep 25 19:21:47 2011
@@ -1086,39 +1086,9 @@
     OS.resetColor();
 }
 
-void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
-                                             const DiagnosticInfo &Info) {
-  // Default implementation (Warnings/errors count).
-  DiagnosticConsumer::HandleDiagnostic(Level, Info);
-
-  // Keeps track of the the starting position of the location
-  // information (e.g., "foo.c:10:4:") that precedes the error
-  // message. We use this information to determine how long the
-  // file+line+column number prefix is.
-  uint64_t StartOfLocationInfo = OS.tell();
-
-  if (!Prefix.empty())
-    OS << Prefix << ": ";
-
-  if (Info.getLocation().isValid()) {
-    const SourceManager &SM = Info.getSourceManager();
-    PresumedLoc PLoc = getDiagnosticPresumedLoc(SM, Info.getLocation());
-
-    // First, if this diagnostic is not in the main file, print out the
-    // "included from" lines.
-    PrintIncludeStack(Level, PLoc.getIncludeLoc(), SM);
-    StartOfLocationInfo = OS.tell();
-
-    // Next emit the location of this particular diagnostic.
-    EmitDiagnosticLoc(Level, Info, SM, PLoc);
-
-    if (DiagOpts->ShowColors)
-      OS.resetColor();
-  }
-
-  PrintDiagnosticLevel(OS, Level, DiagOpts->ShowColors);
-
-  llvm::SmallString<100> OutStr;
+static void FormatDiagnosticMessage(const Diagnostic &Info,
+                                    const DiagnosticOptions &DiagOpts,
+                                    SmallVectorImpl<char> &OutStr) {
   Info.FormatDiagnostic(OutStr);
 
   if (DiagOpts->ShowNames &&
@@ -1186,8 +1156,43 @@
     
     OutStr += "]";
   }
+}
+
+void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
+                                             const DiagnosticInfo &Info) {
+  // Default implementation (Warnings/errors count).
+  DiagnosticConsumer::HandleDiagnostic(Level, Info);
+
+  // Keeps track of the the starting position of the location
+  // information (e.g., "foo.c:10:4:") that precedes the error
+  // message. We use this information to determine how long the
+  // file+line+column number prefix is.
+  uint64_t StartOfLocationInfo = OS.tell();
+
+  if (!Prefix.empty())
+    OS << Prefix << ": ";
+
+  if (Info.getLocation().isValid()) {
+    const SourceManager &SM = Info.getSourceManager();
+    PresumedLoc PLoc = getDiagnosticPresumedLoc(SM, Info.getLocation());
+
+    // First, if this diagnostic is not in the main file, print out the
+    // "included from" lines.
+    PrintIncludeStack(Level, PLoc.getIncludeLoc(), SM);
+    StartOfLocationInfo = OS.tell();
+
+    // Next emit the location of this particular diagnostic.
+    EmitDiagnosticLoc(Level, Info, SM, PLoc);
+
+    if (DiagOpts->ShowColors)
+      OS.resetColor();
+  }
+
+  PrintDiagnosticLevel(OS, Level, DiagOpts->ShowColors);
+
+  llvm::SmallString<100> OutStr;
+  FormatDiagnosticMessage(Info, *Diagopts, OutStr);
 
-  
   if (DiagOpts->ShowColors) {
     // Print warnings, errors and fatal errors in bold, no color
     switch (Level) {





More information about the cfe-commits mailing list