1717#include " llvm/Support/ConvertUTF.h"
1818#include " llvm/Support/ErrorHandling.h"
1919#include " llvm/Support/Locale.h"
20- #include " llvm/Support/raw_ostream.h"
2120#include < algorithm>
2221#include < optional>
2322
@@ -49,7 +48,7 @@ static constexpr raw_ostream::Colors LiteralColor = raw_ostream::GREEN;
4948static constexpr raw_ostream::Colors KeywordColor = raw_ostream::BLUE;
5049
5150// / Add highlights to differences in template strings.
52- static void applyTemplateHighlighting (raw_ostream &OS, StringRef Str,
51+ static void applyTemplateHighlighting (formatted_raw_ostream &OS, StringRef Str,
5352 bool &Normal, bool Bold) {
5453 while (true ) {
5554 size_t Pos = Str.find (ToggleHighlight);
@@ -59,11 +58,11 @@ static void applyTemplateHighlighting(raw_ostream &OS, StringRef Str,
5958
6059 Str = Str.substr (Pos + 1 );
6160 if (Normal)
62- OS.changeColor (templateColor, true );
61+ OS.changeColor (templateColor, true , false );
6362 else {
6463 OS.resetColor ();
6564 if (Bold)
66- OS.changeColor (savedColor, true );
65+ OS.changeColor (savedColor, true , false );
6766 }
6867 Normal = !Normal;
6968 }
@@ -603,8 +602,8 @@ static unsigned findEndOfWord(unsigned Start, StringRef Str,
603602// / \param Bold if the current text should be bold
604603// / \returns true if word-wrapping was required, or false if the
605604// / string fit on the first line.
606- static bool printWordWrapped (raw_ostream &OS, StringRef Str, unsigned Columns ,
607- unsigned Column, bool Bold) {
605+ static bool printWordWrapped (formatted_raw_ostream &OS, StringRef Str,
606+ unsigned Columns, unsigned Column, bool Bold) {
608607 const unsigned Length = std::min (Str.find (' \n ' ), Str.size ());
609608 bool TextNormal = true ;
610609
@@ -651,7 +650,8 @@ static bool printWordWrapped(raw_ostream &OS, StringRef Str, unsigned Columns,
651650 return Wrapped;
652651}
653652
654- TextDiagnostic::TextDiagnostic (raw_ostream &OS, const LangOptions &LangOpts,
653+ TextDiagnostic::TextDiagnostic (formatted_raw_ostream &OS,
654+ const LangOptions &LangOpts,
655655 DiagnosticOptions &DiagOpts,
656656 const Preprocessor *PP)
657657 : DiagnosticRenderer(LangOpts, DiagOpts), OS(OS), PP(PP) {}
@@ -662,7 +662,7 @@ void TextDiagnostic::emitDiagnosticMessage(
662662 FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level,
663663 StringRef Message, ArrayRef<clang::CharSourceRange> Ranges,
664664 DiagOrStoredDiag D) {
665- uint64_t StartOfLocationInfo = OS.tell ();
665+ uint64_t StartOfLocationInfo = OS.getColumn ();
666666
667667 // Emit the location of this particular diagnostic.
668668 if (Loc.isValid ())
@@ -675,24 +675,34 @@ void TextDiagnostic::emitDiagnosticMessage(
675675 printDiagnosticLevel (OS, Level, DiagOpts.ShowColors );
676676 printDiagnosticMessage (OS,
677677 /* IsSupplemental*/ Level == DiagnosticsEngine::Note,
678- Message, OS.tell () - StartOfLocationInfo,
678+ Message, OS.getColumn () - StartOfLocationInfo,
679679 DiagOpts.MessageLength , DiagOpts.ShowColors );
680680}
681681
682682/* static*/ void
683- TextDiagnostic::printDiagnosticLevel (raw_ostream &OS,
683+ TextDiagnostic::printDiagnosticLevel (formatted_raw_ostream &OS,
684684 DiagnosticsEngine::Level Level,
685685 bool ShowColors) {
686686 if (ShowColors) {
687687 // Print diagnostic category in bold and color
688688 switch (Level) {
689689 case DiagnosticsEngine::Ignored:
690690 llvm_unreachable (" Invalid diagnostic type" );
691- case DiagnosticsEngine::Note: OS.changeColor (noteColor, true ); break ;
692- case DiagnosticsEngine::Remark: OS.changeColor (remarkColor, true ); break ;
693- case DiagnosticsEngine::Warning: OS.changeColor (warningColor, true ); break ;
694- case DiagnosticsEngine::Error: OS.changeColor (errorColor, true ); break ;
695- case DiagnosticsEngine::Fatal: OS.changeColor (fatalColor, true ); break ;
691+ case DiagnosticsEngine::Note:
692+ OS.changeColor (noteColor, true , false );
693+ break ;
694+ case DiagnosticsEngine::Remark:
695+ OS.changeColor (remarkColor, true , false );
696+ break ;
697+ case DiagnosticsEngine::Warning:
698+ OS.changeColor (warningColor, true , false );
699+ break ;
700+ case DiagnosticsEngine::Error:
701+ OS.changeColor (errorColor, true , false );
702+ break ;
703+ case DiagnosticsEngine::Fatal:
704+ OS.changeColor (fatalColor, true , false );
705+ break ;
696706 }
697707 }
698708
@@ -711,7 +721,7 @@ TextDiagnostic::printDiagnosticLevel(raw_ostream &OS,
711721}
712722
713723/* static*/
714- void TextDiagnostic::printDiagnosticMessage (raw_ostream &OS,
724+ void TextDiagnostic::printDiagnosticMessage (formatted_raw_ostream &OS,
715725 bool IsSupplemental,
716726 StringRef Message,
717727 unsigned CurrentColumn,
@@ -720,7 +730,7 @@ void TextDiagnostic::printDiagnosticMessage(raw_ostream &OS,
720730 if (ShowColors && !IsSupplemental) {
721731 // Print primary diagnostic messages in bold and without color, to visually
722732 // indicate the transition from continuation notes and other output.
723- OS.changeColor (savedColor, true );
733+ OS.changeColor (savedColor, true , false );
724734 Bold = true ;
725735 }
726736
@@ -798,7 +808,7 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
798808 return ;
799809
800810 if (DiagOpts.ShowColors )
801- OS.changeColor (savedColor, true );
811+ OS.changeColor (savedColor, true , false );
802812
803813 emitFilename (PLoc.getFilename (), Loc.getManager ());
804814 switch (DiagOpts.getFormat ()) {
@@ -1423,7 +1433,7 @@ void TextDiagnostic::emitSnippetAndCaret(
14231433 if (!CaretLine.empty ()) {
14241434 indentForLineNumbers ();
14251435 if (DiagOpts.ShowColors )
1426- OS.changeColor (caretColor, true );
1436+ OS.changeColor (caretColor, true , false );
14271437 OS << CaretLine << ' \n ' ;
14281438 if (DiagOpts.ShowColors )
14291439 OS.resetColor ();
@@ -1433,7 +1443,7 @@ void TextDiagnostic::emitSnippetAndCaret(
14331443 indentForLineNumbers ();
14341444 if (DiagOpts.ShowColors )
14351445 // Print fixit line in color
1436- OS.changeColor (fixitColor, false );
1446+ OS.changeColor (fixitColor, false , false );
14371447 if (DiagOpts.ShowSourceRanges )
14381448 OS << ' ' ;
14391449 OS << FixItInsertionLine << ' \n ' ;
@@ -1459,7 +1469,7 @@ void TextDiagnostic::emitSnippet(StringRef SourceLine,
14591469
14601470 // Print the source line one character at a time.
14611471 bool PrintReversed = false ;
1462- std::optional<llvm:: raw_ostream::Colors> CurrentColor;
1472+ std::optional<raw_ostream::Colors> CurrentColor;
14631473 size_t I = 0 ;
14641474 while (I < SourceLine.size ()) {
14651475 auto [Str, WasPrintable] =
@@ -1485,7 +1495,7 @@ void TextDiagnostic::emitSnippet(StringRef SourceLine,
14851495 if (CharStyle != Styles.end ()) {
14861496 if (!CurrentColor ||
14871497 (CurrentColor && *CurrentColor != CharStyle->Color )) {
1488- OS.changeColor (CharStyle->Color , false );
1498+ OS.changeColor (CharStyle->Color , false , false );
14891499 CurrentColor = CharStyle->Color ;
14901500 }
14911501 } else if (CurrentColor) {
0 commit comments