summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2018-02-12 21:11:14 +0000
committerAdrian Prantl <aprantl@apple.com>2018-02-12 21:11:14 +0000
commitbaf9c20b0215a0db58aa38a09209929e9289da25 (patch)
tree8372e4c6891b2d39376edfa06a9149724fb514e1 /llvm/lib
parenta6716d9d81466a9639c23bf0c2f4d1b269f416f5 (diff)
downloadbcm5719-llvm-baf9c20b0215a0db58aa38a09209929e9289da25.tar.gz
bcm5719-llvm-baf9c20b0215a0db58aa38a09209929e9289da25.zip
Factor out common condition into an easier to understand helper function (NFC).
llvm-svn: 324935
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp12
-rw-r--r--llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.h2
2 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp b/llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp
index 65d66fc8f51..46c19bcc451 100644
--- a/llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp
+++ b/llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp
@@ -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, enum HighlightColor Type) : OS(OS) {
}
WithColor::~WithColor() {
- if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE)
+ if (colorsEnabled(OS))
OS.resetColor();
}
diff --git a/llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.h b/llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.h
index 686cf2c7760..9aa060472b1 100644
--- a/llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.h
+++ b/llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.h
@@ -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";
OpenPOWER on IntegriCloud