diff options
author | Richard Trieu <rtrieu@google.com> | 2012-06-28 22:39:03 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2012-06-28 22:39:03 +0000 |
commit | b956e5a2439bce94ba2e1da264471859632eb11f (patch) | |
tree | e667868582a7bb699f3e9a317fdc10a59421b723 /lib/Frontend/TextDiagnostic.cpp | |
parent | db2a685287e57d9dfec09c867152c465af6fc6b0 (diff) |
When applying a template diff highlighting to a diagnostic message, remember
to reapply the bold formatting when needed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159386 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/TextDiagnostic.cpp')
-rw-r--r-- | lib/Frontend/TextDiagnostic.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/Frontend/TextDiagnostic.cpp b/lib/Frontend/TextDiagnostic.cpp index bd766d354c..ae1396672b 100644 --- a/lib/Frontend/TextDiagnostic.cpp +++ b/lib/Frontend/TextDiagnostic.cpp @@ -41,15 +41,18 @@ static const enum raw_ostream::Colors savedColor = /// \brief Add highlights to differences in template strings. static void applyTemplateHighlighting(raw_ostream &OS, StringRef Str, - bool &Normal) { + bool &Normal, bool Bold) { for (unsigned i = 0, e = Str.size(); i < e; ++i) if (Str[i] != ToggleHighlight) { OS << Str[i]; } else { if (Normal) OS.changeColor(templateColor, true); - else + else { OS.resetColor(); + if (Bold) + OS.changeColor(savedColor, true); + } Normal = !Normal; } } @@ -586,6 +589,7 @@ static unsigned findEndOfWord(unsigned Start, StringRef Str, /// \param Column the column number at which the first character of \p /// Str will be printed. This will be non-zero when part of the first /// line has already been printed. +/// \param Bold if the current text should be bold /// \param Indentation the number of spaces to indent any lines beyond /// the first line. /// \returns true if word-wrapping was required, or false if the @@ -593,6 +597,7 @@ static unsigned findEndOfWord(unsigned Start, StringRef Str, static bool printWordWrapped(raw_ostream &OS, StringRef Str, unsigned Columns, unsigned Column = 0, + bool Bold = false, unsigned Indentation = WordWrapIndentation) { const unsigned Length = std::min(Str.find('\n'), Str.size()); bool TextNormal = true; @@ -620,7 +625,7 @@ static bool printWordWrapped(raw_ostream &OS, StringRef Str, Column += 1; } applyTemplateHighlighting(OS, Str.substr(WordStart, WordLength), - TextNormal); + TextNormal, Bold); Column += WordLength; continue; } @@ -630,13 +635,13 @@ static bool printWordWrapped(raw_ostream &OS, StringRef Str, OS << '\n'; OS.write(&IndentStr[0], Indentation); applyTemplateHighlighting(OS, Str.substr(WordStart, WordLength), - TextNormal); + TextNormal, Bold); Column = Indentation + WordLength; Wrapped = true; } // Append any remaning text from the message with its existing formatting. - applyTemplateHighlighting(OS, Str.substr(Length), TextNormal); + applyTemplateHighlighting(OS, Str.substr(Length), TextNormal, Bold); assert(TextNormal && "Text highlighted at end of diagnostic message."); @@ -708,21 +713,25 @@ TextDiagnostic::printDiagnosticMessage(raw_ostream &OS, StringRef Message, unsigned CurrentColumn, unsigned Columns, bool ShowColors) { + bool Bold = false; if (ShowColors) { // Print warnings, errors and fatal errors in bold, no color switch (Level) { - case DiagnosticsEngine::Warning: OS.changeColor(savedColor, true); break; - case DiagnosticsEngine::Error: OS.changeColor(savedColor, true); break; - case DiagnosticsEngine::Fatal: OS.changeColor(savedColor, true); break; + case DiagnosticsEngine::Warning: + case DiagnosticsEngine::Error: + case DiagnosticsEngine::Fatal: + OS.changeColor(savedColor, true); + Bold = true; + break; default: break; //don't bold notes } } if (Columns) - printWordWrapped(OS, Message, Columns, CurrentColumn); + printWordWrapped(OS, Message, Columns, CurrentColumn, Bold); else { bool Normal = true; - applyTemplateHighlighting(OS, Message, Normal); + applyTemplateHighlighting(OS, Message, Normal, Bold); assert(Normal && "Formatting should have returned to normal"); } |