[cfe-commits] r159386 - /cfe/trunk/lib/Frontend/TextDiagnostic.cpp

David Blaikie dblaikie at gmail.com
Thu Jun 28 15:45:57 PDT 2012


On Thu, Jun 28, 2012 at 3:39 PM, Richard Trieu <rtrieu at google.com> wrote:
> Author: rtrieu
> Date: Thu Jun 28 17:39:03 2012
> New Revision: 159386
>
> URL: http://llvm.org/viewvc/llvm-project?rev=159386&view=rev
> Log:
> When applying a template diff highlighting to a diagnostic message, remember
> to reapply the bold formatting when needed.

I expect there'll be a test case for this when this code is actually
used (when template type diffing applies to error messages)? Sometimes
it's easier to commit this together with the code that makes this
usable/testable (& include the tests) - or at least back-to-back with
it. (No worries, though)

- David

>
> Modified:
>    cfe/trunk/lib/Frontend/TextDiagnostic.cpp
>
> Modified: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnostic.cpp?rev=159386&r1=159385&r2=159386&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/TextDiagnostic.cpp (original)
> +++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp Thu Jun 28 17:39:03 2012
> @@ -41,15 +41,18 @@
>
>  /// \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 @@
>  /// \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 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 @@
>         Column += 1;
>       }
>       applyTemplateHighlighting(OS, Str.substr(WordStart, WordLength),
> -                                TextNormal);
> +                                TextNormal, Bold);
>       Column += WordLength;
>       continue;
>     }
> @@ -630,13 +635,13 @@
>     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 @@
>                                        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");
>   }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list