]> granicus.if.org Git - clang/commitdiff
Extract the diagnostic message formatting into a helper routine.
authorChandler Carruth <chandlerc@gmail.com>
Mon, 26 Sep 2011 00:21:47 +0000 (00:21 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 26 Sep 2011 00:21:47 +0000 (00:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140484 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/TextDiagnosticPrinter.cpp

index a947c0e80ea17eacbb6be149910fb9f9d1a90b74..c6b1df9c77f936db344d9a58c4bbb9b3fd666813 100644 (file)
@@ -1086,39 +1086,9 @@ static void PrintDiagnosticLevel(raw_ostream& OS,
     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 @@ void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
     
     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) {