[llvm] r330094 - [Support] Extend WithColor helpers

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 15 01:44:16 PDT 2018


Author: jdevlieghere
Date: Sun Apr 15 01:44:15 2018
New Revision: 330094

URL: http://llvm.org/viewvc/llvm-project?rev=330094&view=rev
Log:
[Support] Extend WithColor helpers

Although printing warnings and errors to stderr is by far the most
common case, this patch makes it possible to specify any stream.

Modified:
    llvm/trunk/include/llvm/Support/WithColor.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp
    llvm/trunk/lib/Support/WithColor.cpp

Modified: llvm/trunk/include/llvm/Support/WithColor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/WithColor.h?rev=330094&r1=330093&r2=330094&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/WithColor.h (original)
+++ llvm/trunk/include/llvm/Support/WithColor.h Sun Apr 15 01:44:15 2018
@@ -44,12 +44,17 @@ public:
 
   /// Convenience method for printing "error: " to stderr.
   static raw_ostream &error();
-
   /// Convenience method for printing "warning: " to stderr.
   static raw_ostream &warning();
-
   /// Convenience method for printing "note: " to stderr.
   static raw_ostream &note();
+
+  /// Convenience method for printing "error: " to the given stream.
+  static raw_ostream &error(raw_ostream &OS);
+  /// Convenience method for printing "warning: " to the given stream.
+  static raw_ostream &warning(raw_ostream &OS);
+  /// Convenience method for printing "note: " to the given stream.
+  static raw_ostream &note(raw_ostream &OS);
 };
 
 } // end namespace llvm

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp?rev=330094&r1=330093&r2=330094&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp Sun Apr 15 01:44:15 2018
@@ -1196,14 +1196,8 @@ bool DWARFVerifier::handleAccelTables()
   return NumErrors == 0;
 }
 
-raw_ostream &DWARFVerifier::error() const {
-  return WithColor(OS, HighlightColor::Error).get() << "error: ";
-}
+raw_ostream &DWARFVerifier::error() const { return WithColor::error(OS); }
 
-raw_ostream &DWARFVerifier::warn() const {
-  return WithColor(OS, HighlightColor::Warning).get() << "warning: ";
-}
+raw_ostream &DWARFVerifier::warn() const { return WithColor::warning(OS); }
 
-raw_ostream &DWARFVerifier::note() const {
-  return WithColor(OS, HighlightColor::Note).get() << "note: ";
-}
+raw_ostream &DWARFVerifier::note() const { return WithColor::note(OS); }

Modified: llvm/trunk/lib/Support/WithColor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/WithColor.cpp?rev=330094&r1=330093&r2=330094&view=diff
==============================================================================
--- llvm/trunk/lib/Support/WithColor.cpp (original)
+++ llvm/trunk/lib/Support/WithColor.cpp Sun Apr 15 01:44:15 2018
@@ -59,16 +59,22 @@ WithColor::WithColor(raw_ostream &OS, Hi
   }
 }
 
-raw_ostream &WithColor::error() {
-  return WithColor(errs(), HighlightColor::Error).get() << "error: ";
+raw_ostream &WithColor::error() { return error(errs()); }
+
+raw_ostream &WithColor::warning() { return warning(errs()); }
+
+raw_ostream &WithColor::note() { return note(errs()); }
+
+raw_ostream &WithColor::error(raw_ostream &OS) {
+  return WithColor(OS, HighlightColor::Error).get() << "error: ";
 }
 
-raw_ostream &WithColor::warning() {
-  return WithColor(errs(), HighlightColor::Warning).get() << "warning: ";
+raw_ostream &WithColor::warning(raw_ostream &OS) {
+  return WithColor(OS, HighlightColor::Warning).get() << "warning: ";
 }
 
-raw_ostream &WithColor::note() {
-  return WithColor(errs(), HighlightColor::Note).get() << "note: ";
+raw_ostream &WithColor::note(raw_ostream &OS) {
+  return WithColor(OS, HighlightColor::Note).get() << "note: ";
 }
 
 WithColor::~WithColor() {




More information about the llvm-commits mailing list