diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2018-10-22 18:51:29 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2018-10-22 18:51:29 +0000 |
commit | 036e54d32ef9ad7f8e1f7f277ec96338bc26eac5 (patch) | |
tree | 15663fba1f64e26078ab83726cb0e34b16a21da7 /llvm/lib | |
parent | 49cc6171198b39899ebd893dd67593551517aeb9 (diff) | |
download | bcm5719-llvm-036e54d32ef9ad7f8e1f7f277ec96338bc26eac5.tar.gz bcm5719-llvm-036e54d32ef9ad7f8e1f7f277ec96338bc26eac5.zip |
Revert r344930 as it broke some of the bots on Windows.
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/739
llvm-svn: 344935
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Support/SourceMgr.cpp | 108 | ||||
-rw-r--r-- | llvm/lib/Support/WithColor.cpp | 63 |
2 files changed, 79 insertions, 92 deletions
diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp index a55ad881d01..582e2cf6c11 100644 --- a/llvm/lib/Support/SourceMgr.cpp +++ b/llvm/lib/Support/SourceMgr.cpp @@ -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); +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 (ProgName && ProgName[0]) - S << ProgName << ": "; + if (ShowColors) + S.changeColor(raw_ostream::SAVEDCOLOR, true); - if (!Filename.empty()) { - if (Filename == "-") - S << "<stdin>"; - else - S << Filename; + if (ProgName && ProgName[0]) + S << ProgName << ": "; - if (LineNo != -1) { - S << ':' << LineNo; - if (ColumnNo != -1) - S << ':' << (ColumnNo + 1); - } - S << ": "; + 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 *ProgName, raw_ostream &OS, // 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 *ProgName, raw_ostream &OS, // 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 *ProgName, raw_ostream &OS, 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 *ProgName, raw_ostream &OS, ++OutCol; } while (((OutCol % TabStop) != 0) && i != e); } - OS << '\n'; + S << '\n'; } diff --git a/llvm/lib/Support/WithColor.cpp b/llvm/lib/Support/WithColor.cpp index cf4c10956f2..d2e13f0e86d 100644 --- a/llvm/lib/Support/WithColor.cpp +++ b/llvm/lib/Support/WithColor.cpp @@ -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, HighlightColor Color, bool DisableColors) 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() { return warning(errs()); } 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(); } |