diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-09-25 23:51:01 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-09-25 23:51:01 +0000 |
commit | 99c4e5bcb93ec0b053bdba48b56939479562f11d (patch) | |
tree | 6075249a40d911503ec4a2db9bb69494a6f0197a /lib/Frontend/TextDiagnosticPrinter.cpp | |
parent | f40c0ac1238a0ef2010238a43cb078465401239a (diff) |
Extract the logic for printing a colorful level name into a helper
function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140481 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r-- | lib/Frontend/TextDiagnosticPrinter.cpp | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index 1dc9d72bd5..a947c0e80e 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -1059,6 +1059,33 @@ void TextDiagnosticPrinter::EmitDiagnosticLoc(DiagnosticsEngine::Level Level, OS << ' '; } +static void PrintDiagnosticLevel(raw_ostream& OS, + DiagnosticsEngine::Level Level, + bool ShowColors) { + if (ShowColors) { + // Print diagnostic category in bold and color + switch (Level) { + case DiagnosticsEngine::Ignored: + llvm_unreachable("Invalid diagnostic type"); + case DiagnosticsEngine::Note: OS.changeColor(noteColor, true); break; + case DiagnosticsEngine::Warning: OS.changeColor(warningColor, true); break; + case DiagnosticsEngine::Error: OS.changeColor(errorColor, true); break; + case DiagnosticsEngine::Fatal: OS.changeColor(fatalColor, true); break; + } + } + + switch (Level) { + case DiagnosticsEngine::Ignored: llvm_unreachable("Invalid diagnostic type"); + case DiagnosticsEngine::Note: OS << "note: "; break; + case DiagnosticsEngine::Warning: OS << "warning: "; break; + case DiagnosticsEngine::Error: OS << "error: "; break; + case DiagnosticsEngine::Fatal: OS << "fatal error: "; break; + } + + if (ShowColors) + OS.resetColor(); +} + void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, const DiagnosticInfo &Info) { // Default implementation (Warnings/errors count). @@ -1089,27 +1116,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, OS.resetColor(); } - if (DiagOpts->ShowColors) { - // Print diagnostic category in bold and color - switch (Level) { - case DiagnosticsEngine::Ignored: llvm_unreachable("Invalid diagnostic type"); - case DiagnosticsEngine::Note: OS.changeColor(noteColor, true); break; - case DiagnosticsEngine::Warning: OS.changeColor(warningColor, true); break; - case DiagnosticsEngine::Error: OS.changeColor(errorColor, true); break; - case DiagnosticsEngine::Fatal: OS.changeColor(fatalColor, true); break; - } - } - - switch (Level) { - case DiagnosticsEngine::Ignored: llvm_unreachable("Invalid diagnostic type"); - case DiagnosticsEngine::Note: OS << "note: "; break; - case DiagnosticsEngine::Warning: OS << "warning: "; break; - case DiagnosticsEngine::Error: OS << "error: "; break; - case DiagnosticsEngine::Fatal: OS << "fatal error: "; break; - } - - if (DiagOpts->ShowColors) - OS.resetColor(); + PrintDiagnosticLevel(OS, Level, DiagOpts->ShowColors); llvm::SmallString<100> OutStr; Info.FormatDiagnostic(OutStr); |