[llvm] r324935 - Factor out common condition into an easier to understand helper function (NFC).

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 12 13:11:14 PST 2018


Author: adrian
Date: Mon Feb 12 13:11:14 2018
New Revision: 324935

URL: http://llvm.org/viewvc/llvm-project?rev=324935&view=rev
Log:
Factor out common condition into an easier to understand helper function (NFC).

Modified:
    llvm/trunk/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp
    llvm/trunk/lib/DebugInfo/DWARF/SyntaxHighlighting.h

Modified: llvm/trunk/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp?rev=324935&r1=324934&r2=324935&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp Mon Feb 12 13:11:14 2018
@@ -20,9 +20,17 @@ static cl::opt<cl::boolOrDefault>
              cl::desc("use colored syntax highlighting (default=autodetect)"),
              cl::init(cl::BOU_UNSET));
 
+bool WithColor::colorsEnabled(raw_ostream &OS) {
+  switch (UseColor) {
+  case cl::BOU_UNSET: return OS.has_colors();
+  case cl::BOU_TRUE:  return true;
+  case cl::BOU_FALSE: return false;
+  }
+}
+
 WithColor::WithColor(raw_ostream &OS, enum HighlightColor Type) : OS(OS) {
   // Detect color from terminal type unless the user passed the --color option.
-  if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE) {
+  if (colorsEnabled(OS)) {
     switch (Type) {
     case Address:    OS.changeColor(raw_ostream::YELLOW);         break;
     case String:     OS.changeColor(raw_ostream::GREEN);          break;
@@ -38,6 +46,6 @@ WithColor::WithColor(raw_ostream &OS, en
 }
 
 WithColor::~WithColor() {
-  if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE)
+  if (colorsEnabled(OS))
     OS.resetColor();
 }

Modified: llvm/trunk/lib/DebugInfo/DWARF/SyntaxHighlighting.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/SyntaxHighlighting.h?rev=324935&r1=324934&r2=324935&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/SyntaxHighlighting.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/SyntaxHighlighting.h Mon Feb 12 13:11:14 2018
@@ -34,6 +34,8 @@ enum HighlightColor {
 /// specific color.
 class WithColor {
   raw_ostream &OS;
+  /// Determine whether colors should be displayed.
+  bool colorsEnabled(raw_ostream &OS);
 
 public:
   /// To be used like this: WithColor(OS, syntax::String) << "text";




More information about the llvm-commits mailing list