[llvm] r344935 - Revert r344930 as it broke some of the bots on Windows.

Aaron Ballman via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 22 11:51:29 PDT 2018


Author: aaronballman
Date: Mon Oct 22 11:51:29 2018
New Revision: 344935

URL: http://llvm.org/viewvc/llvm-project?rev=344935&view=rev
Log:
Revert r344930 as it broke some of the bots on Windows.

http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/739

Removed:
    llvm/trunk/test/FileCheck/opt-color.txt
Modified:
    llvm/trunk/docs/CommandGuide/FileCheck.rst
    llvm/trunk/include/llvm/Support/WithColor.h
    llvm/trunk/lib/Support/SourceMgr.cpp
    llvm/trunk/lib/Support/WithColor.cpp

Modified: llvm/trunk/docs/CommandGuide/FileCheck.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/FileCheck.rst?rev=344935&r1=344934&r2=344935&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/FileCheck.rst (original)
+++ llvm/trunk/docs/CommandGuide/FileCheck.rst Mon Oct 22 11:51:29 2018
@@ -116,10 +116,6 @@ OPTIONS
   as old tests are migrated to the new non-overlapping ``CHECK-DAG:``
   implementation.
 
-.. option:: --color
-
-  Use colors in output (autodetected by default).
-
 EXIT STATUS
 -----------
 

Modified: llvm/trunk/include/llvm/Support/WithColor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/WithColor.h?rev=344935&r1=344934&r2=344935&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/WithColor.h (original)
+++ llvm/trunk/include/llvm/Support/WithColor.h Mon Oct 22 11:51:29 2018
@@ -29,49 +29,23 @@ enum class HighlightColor {
   Macro,
   Error,
   Warning,
-  Note,
-  Remark
+  Note
 };
 
 /// An RAII object that temporarily switches an output stream to a specific
 /// color.
 class WithColor {
   raw_ostream &OS;
-  bool DisableColors;
+  /// Determine whether colors should be displayed.
+  bool colorsEnabled(raw_ostream &OS);
 
 public:
   /// To be used like this: WithColor(OS, HighlightColor::String) << "text";
-  /// @param OS The output stream
-  /// @param S Symbolic name for syntax element to color
-  /// @param DisableColors Whether to ignore color changes regardless of -color
-  /// and support in OS
-  WithColor(raw_ostream &OS, HighlightColor S, bool DisableColors = false);
-  /// To be used like this: WithColor(OS, raw_ostream::Black) << "text";
-  /// @param OS The output stream
-  /// @param Color ANSI color to use, the special SAVEDCOLOR can be used to
-  /// change only the bold attribute, and keep colors untouched
-  /// @param Bold Bold/brighter text, default false
-  /// @param BG If true, change the background, default: change foreground
-  /// @param DisableColors Whether to ignore color changes regardless of -color
-  /// and support in OS
-  WithColor(raw_ostream &OS,
-            raw_ostream::Colors Color = raw_ostream::SAVEDCOLOR,
-            bool Bold = false, bool BG = false, bool DisableColors = false)
-      : OS(OS), DisableColors(DisableColors) {
-    changeColor(Color, Bold, BG);
-  }
+  WithColor(raw_ostream &OS, HighlightColor S);
   ~WithColor();
 
   raw_ostream &get() { return OS; }
   operator raw_ostream &() { return OS; }
-  template <typename T> WithColor &operator<<(T &O) {
-    OS << O;
-    return *this;
-  }
-  template <typename T> WithColor &operator<<(const T &O) {
-    OS << O;
-    return *this;
-  }
 
   /// Convenience method for printing "error: " to stderr.
   static raw_ostream &error();
@@ -79,36 +53,13 @@ public:
   static raw_ostream &warning();
   /// Convenience method for printing "note: " to stderr.
   static raw_ostream &note();
-  /// Convenience method for printing "remark: " to stderr.
-  static raw_ostream &remark();
 
   /// Convenience method for printing "error: " to the given stream.
-  static raw_ostream &error(raw_ostream &OS, StringRef Prefix = "",
-                            bool DisableColors = false);
+  static raw_ostream &error(raw_ostream &OS, StringRef Prefix = "");
   /// Convenience method for printing "warning: " to the given stream.
-  static raw_ostream &warning(raw_ostream &OS, StringRef Prefix = "",
-                              bool DisableColors = false);
+  static raw_ostream &warning(raw_ostream &OS, StringRef Prefix = "");
   /// Convenience method for printing "note: " to the given stream.
-  static raw_ostream &note(raw_ostream &OS, StringRef Prefix = "",
-                           bool DisableColors = false);
-  /// Convenience method for printing "remark: " to the given stream.
-  static raw_ostream &remark(raw_ostream &OS, StringRef Prefix = "",
-                             bool DisableColors = false);
-
-  /// Determine whether colors are displayed.
-  bool colorsEnabled();
-
-  /// Change the color of text that will be output from this point forward.
-  /// @param Color ANSI color to use, the special SAVEDCOLOR can be used to
-  /// change only the bold attribute, and keep colors untouched
-  /// @param Bold Bold/brighter text, default false
-  /// @param BG If true, change the background, default: change foreground
-  WithColor &changeColor(raw_ostream::Colors Color, bool Bold = false,
-                         bool BG = false);
-
-  /// Reset the colors to terminal defaults. Call this when you are done
-  /// outputting colored text, or before program exit.
-  WithColor &resetColor();
+  static raw_ostream &note(raw_ostream &OS, StringRef Prefix = "");
 };
 
 } // end namespace llvm

Modified: llvm/trunk/lib/Support/SourceMgr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SourceMgr.cpp?rev=344935&r1=344934&r2=344935&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SourceMgr.cpp (original)
+++ llvm/trunk/lib/Support/SourceMgr.cpp Mon Oct 22 11:51:29 2018
@@ -24,7 +24,6 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SMLoc.h"
-#include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <cassert>
@@ -371,48 +370,65 @@ static bool isNonASCII(char c) {
   return c & 0x80;
 }
 
-void SMDiagnostic::print(const char *ProgName, raw_ostream &OS,
-                         bool ShowColors, bool ShowKindLabel) const {
-  {
-    WithColor S(OS, raw_ostream::SAVEDCOLOR, true, false, !ShowColors);
-
-    if (ProgName && ProgName[0])
-      S << ProgName << ": ";
-
-    if (!Filename.empty()) {
-      if (Filename == "-")
-        S << "<stdin>";
-      else
-        S << Filename;
-
-      if (LineNo != -1) {
-        S << ':' << LineNo;
-        if (ColumnNo != -1)
-          S << ':' << (ColumnNo + 1);
-      }
-      S << ": ";
+void SMDiagnostic::print(const char *ProgName, raw_ostream &S, bool ShowColors,
+                         bool ShowKindLabel) const {
+  // Display colors only if OS supports colors.
+  ShowColors &= S.has_colors();
+
+  if (ShowColors)
+    S.changeColor(raw_ostream::SAVEDCOLOR, true);
+
+  if (ProgName && ProgName[0])
+    S << ProgName << ": ";
+
+  if (!Filename.empty()) {
+    if (Filename == "-")
+      S << "<stdin>";
+    else
+      S << Filename;
+
+    if (LineNo != -1) {
+      S << ':' << LineNo;
+      if (ColumnNo != -1)
+        S << ':' << (ColumnNo+1);
     }
+    S << ": ";
   }
 
   if (ShowKindLabel) {
     switch (Kind) {
     case SourceMgr::DK_Error:
-      WithColor::error(OS, "", !ShowColors);
+      if (ShowColors)
+        S.changeColor(raw_ostream::RED, true);
+      S << "error: ";
       break;
     case SourceMgr::DK_Warning:
-      WithColor::warning(OS, "", !ShowColors);
+      if (ShowColors)
+        S.changeColor(raw_ostream::MAGENTA, true);
+      S << "warning: ";
       break;
     case SourceMgr::DK_Note:
-      WithColor::note(OS, "", !ShowColors);
+      if (ShowColors)
+        S.changeColor(raw_ostream::BLACK, true);
+      S << "note: ";
       break;
     case SourceMgr::DK_Remark:
-      WithColor::remark(OS, "", !ShowColors);
+      if (ShowColors)
+        S.changeColor(raw_ostream::BLUE, true);
+      S << "remark: ";
       break;
     }
+
+    if (ShowColors) {
+      S.resetColor();
+      S.changeColor(raw_ostream::SAVEDCOLOR, true);
+    }
   }
 
-  WithColor(OS, raw_ostream::SAVEDCOLOR, true, false, !ShowColors)
-      << Message << '\n';
+  S << Message << '\n';
+
+  if (ShowColors)
+    S.resetColor();
 
   if (LineNo == -1 || ColumnNo == -1)
     return;
@@ -423,7 +439,7 @@ void SMDiagnostic::print(const char *Pro
   // expanding them later, and bail out rather than show incorrect ranges and
   // misaligned fixits for any other odd characters.
   if (find_if(LineContents, isNonASCII) != LineContents.end()) {
-    printSourceLine(OS, LineContents);
+    printSourceLine(S, LineContents);
     return;
   }
   size_t NumColumns = LineContents.size();
@@ -457,27 +473,29 @@ void SMDiagnostic::print(const char *Pro
   // least.
   CaretLine.erase(CaretLine.find_last_not_of(' ')+1);
 
-  printSourceLine(OS, LineContents);
+  printSourceLine(S, LineContents);
 
-  {
-    WithColor S(OS, raw_ostream::GREEN, true, false, !ShowColors);
+  if (ShowColors)
+    S.changeColor(raw_ostream::GREEN, true);
 
-    // Print out the caret line, matching tabs in the source line.
-    for (unsigned i = 0, e = CaretLine.size(), OutCol = 0; i != e; ++i) {
-      if (i >= LineContents.size() || LineContents[i] != '\t') {
-        S << CaretLine[i];
-        ++OutCol;
-        continue;
-      }
-
-      // Okay, we have a tab.  Insert the appropriate number of characters.
-      do {
-        S << CaretLine[i];
-        ++OutCol;
-      } while ((OutCol % TabStop) != 0);
+  // Print out the caret line, matching tabs in the source line.
+  for (unsigned i = 0, e = CaretLine.size(), OutCol = 0; i != e; ++i) {
+    if (i >= LineContents.size() || LineContents[i] != '\t') {
+      S << CaretLine[i];
+      ++OutCol;
+      continue;
     }
-    S << '\n';
+
+    // Okay, we have a tab.  Insert the appropriate number of characters.
+    do {
+      S << CaretLine[i];
+      ++OutCol;
+    } while ((OutCol % TabStop) != 0);
   }
+  S << '\n';
+
+  if (ShowColors)
+    S.resetColor();
 
   // Print out the replacement line, matching tabs in the source line.
   if (FixItInsertionLine.empty())
@@ -485,14 +503,14 @@ void SMDiagnostic::print(const char *Pro
 
   for (size_t i = 0, e = FixItInsertionLine.size(), OutCol = 0; i < e; ++i) {
     if (i >= LineContents.size() || LineContents[i] != '\t') {
-      OS << FixItInsertionLine[i];
+      S << FixItInsertionLine[i];
       ++OutCol;
       continue;
     }
 
     // Okay, we have a tab.  Insert the appropriate number of characters.
     do {
-      OS << FixItInsertionLine[i];
+      S << FixItInsertionLine[i];
       // FIXME: This is trying not to break up replacements, but then to re-sync
       // with the tabs between replacements. This will fail, though, if two
       // fix-it replacements are exactly adjacent, or if a fix-it contains a
@@ -503,5 +521,5 @@ void SMDiagnostic::print(const char *Pro
       ++OutCol;
     } while (((OutCol % TabStop) != 0) && i != e);
   }
-  OS << '\n';
+  S << '\n';
 }

Modified: llvm/trunk/lib/Support/WithColor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/WithColor.cpp?rev=344935&r1=344934&r2=344935&view=diff
==============================================================================
--- llvm/trunk/lib/Support/WithColor.cpp (original)
+++ llvm/trunk/lib/Support/WithColor.cpp Mon Oct 22 11:51:29 2018
@@ -19,10 +19,15 @@ static cl::opt<cl::boolOrDefault>
              cl::desc("Use colors in output (default=autodetect)"),
              cl::init(cl::BOU_UNSET));
 
-WithColor::WithColor(raw_ostream &OS, HighlightColor Color, bool DisableColors)
-    : OS(OS), DisableColors(DisableColors) {
+bool WithColor::colorsEnabled(raw_ostream &OS) {
+  if (UseColor == cl::BOU_UNSET)
+    return OS.has_colors();
+  return UseColor == cl::BOU_TRUE;
+}
+
+WithColor::WithColor(raw_ostream &OS, HighlightColor Color) : OS(OS) {
   // Detect color from terminal type unless the user passed the --color option.
-  if (colorsEnabled()) {
+  if (colorsEnabled(OS)) {
     switch (Color) {
     case HighlightColor::Address:
       OS.changeColor(raw_ostream::YELLOW);
@@ -51,9 +56,6 @@ WithColor::WithColor(raw_ostream &OS, Hi
     case HighlightColor::Note:
       OS.changeColor(raw_ostream::BLACK, true);
       break;
-    case HighlightColor::Remark:
-      OS.changeColor(raw_ostream::BLUE, true);
-      break;
     }
   }
 }
@@ -64,58 +66,25 @@ raw_ostream &WithColor::warning() { retu
 
 raw_ostream &WithColor::note() { return note(errs()); }
 
-raw_ostream &WithColor::remark() { return remark(errs()); }
-
-raw_ostream &WithColor::error(raw_ostream &OS, StringRef Prefix,
-                              bool DisableColors) {
+raw_ostream &WithColor::error(raw_ostream &OS, StringRef Prefix) {
   if (!Prefix.empty())
     OS << Prefix << ": ";
-  return WithColor(OS, HighlightColor::Error, DisableColors).get()
-         << "error: ";
+  return WithColor(OS, HighlightColor::Error).get() << "error: ";
 }
 
-raw_ostream &WithColor::warning(raw_ostream &OS, StringRef Prefix,
-                                bool DisableColors) {
+raw_ostream &WithColor::warning(raw_ostream &OS, StringRef Prefix) {
   if (!Prefix.empty())
     OS << Prefix << ": ";
-  return WithColor(OS, HighlightColor::Warning, DisableColors).get()
-         << "warning: ";
+  return WithColor(OS, HighlightColor::Warning).get() << "warning: ";
 }
 
-raw_ostream &WithColor::note(raw_ostream &OS, StringRef Prefix,
-                             bool DisableColors) {
+raw_ostream &WithColor::note(raw_ostream &OS, StringRef Prefix) {
   if (!Prefix.empty())
     OS << Prefix << ": ";
-  return WithColor(OS, HighlightColor::Note, DisableColors).get() << "note: ";
+  return WithColor(OS, HighlightColor::Note).get() << "note: ";
 }
 
-raw_ostream &WithColor::remark(raw_ostream &OS, StringRef Prefix,
-                               bool DisableColors) {
-  if (!Prefix.empty())
-    OS << Prefix << ": ";
-  return WithColor(OS, HighlightColor::Remark, DisableColors).get()
-         << "remark: ";
-}
-
-bool WithColor::colorsEnabled() {
-  if (DisableColors)
-    return false;
-  if (UseColor == cl::BOU_UNSET)
-    return OS.has_colors();
-  return UseColor == cl::BOU_TRUE;
-}
-
-WithColor &WithColor::changeColor(raw_ostream::Colors Color, bool Bold,
-                                  bool BG) {
-  if (colorsEnabled())
-    OS.changeColor(Color, Bold, BG);
-  return *this;
-}
-
-WithColor &WithColor::resetColor() {
-  if (colorsEnabled())
+WithColor::~WithColor() {
+  if (colorsEnabled(OS))
     OS.resetColor();
-  return *this;
 }
-
-WithColor::~WithColor() { resetColor(); }

Removed: llvm/trunk/test/FileCheck/opt-color.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FileCheck/opt-color.txt?rev=344934&view=auto
==============================================================================
--- llvm/trunk/test/FileCheck/opt-color.txt (original)
+++ llvm/trunk/test/FileCheck/opt-color.txt (removed)
@@ -1,22 +0,0 @@
-; Create a case that produces a simple diagnostic.
-; RUN: echo foo > %t.in
-; CHECK: bar
-
-; Run without and with -color.  In the former case, FileCheck should suppress
-; color in its diagnostics because stderr is a file.
-; RUN: not FileCheck %s < %t.in 2> %t.no-color
-; RUN: not FileCheck -color %s < %t.in 2> %t.color
-
-; Check whether color was produced.
-; RUN: FileCheck -check-prefix NO-COLOR %s < %t.no-color
-; RUN: FileCheck -check-prefix COLOR %s < %t.color
-
-; Make sure our NO-COLOR and COLOR patterns are sane: they don't match the
-; opposite cases.
-; RUN: not FileCheck -check-prefix COLOR %s < %t.no-color
-; RUN: not FileCheck -check-prefix NO-COLOR %s < %t.color
-
-; I don't know of a good way to check for ANSI color codes, so just make sure
-; some new characters show up where those codes should appear.
-; NO-COLOR: : error: CHECK: expected string not found in input
-; COLOR: : {{.+}}error: {{.+}}CHECK: expected string not found in input




More information about the llvm-commits mailing list