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/Support/SourceMgr.cpp | |
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/Support/SourceMgr.cpp')
-rw-r--r-- | llvm/lib/Support/SourceMgr.cpp | 108 |
1 files changed, 63 insertions, 45 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'; } |