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,9 +602,12 @@ 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) {
607+ // llvm::errs() << "Columns: " << Columns << '\n';
608+ // llvm::errs() << "Column: " << Column << '\n';
608609 const unsigned Length = std::min (Str.find (' \n ' ), Str.size ());
610+ // llvm::errs() << "textLength: " << Length << '\n';
609611 bool TextNormal = true ;
610612
611613 bool Wrapped = false ;
@@ -651,7 +653,8 @@ static bool printWordWrapped(raw_ostream &OS, StringRef Str, unsigned Columns,
651653 return Wrapped;
652654}
653655
654- TextDiagnostic::TextDiagnostic (raw_ostream &OS, const LangOptions &LangOpts,
656+ TextDiagnostic::TextDiagnostic (formatted_raw_ostream &OS,
657+ const LangOptions &LangOpts,
655658 DiagnosticOptions &DiagOpts,
656659 const Preprocessor *PP)
657660 : DiagnosticRenderer(LangOpts, DiagOpts), OS(OS), PP(PP) {}
@@ -662,7 +665,7 @@ void TextDiagnostic::emitDiagnosticMessage(
662665 FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level,
663666 StringRef Message, ArrayRef<clang::CharSourceRange> Ranges,
664667 DiagOrStoredDiag D) {
665- uint64_t StartOfLocationInfo = OS.tell ();
668+ uint64_t StartOfLocationInfo = OS.getColumn ();
666669
667670 // Emit the location of this particular diagnostic.
668671 if (Loc.isValid ())
@@ -675,24 +678,34 @@ void TextDiagnostic::emitDiagnosticMessage(
675678 printDiagnosticLevel (OS, Level, DiagOpts.ShowColors );
676679 printDiagnosticMessage (OS,
677680 /* IsSupplemental*/ Level == DiagnosticsEngine::Note,
678- Message, OS.tell () - StartOfLocationInfo,
681+ Message, OS.getColumn () - StartOfLocationInfo,
679682 DiagOpts.MessageLength , DiagOpts.ShowColors );
680683}
681684
682685/* static*/ void
683- TextDiagnostic::printDiagnosticLevel (raw_ostream &OS,
686+ TextDiagnostic::printDiagnosticLevel (formatted_raw_ostream &OS,
684687 DiagnosticsEngine::Level Level,
685688 bool ShowColors) {
686689 if (ShowColors) {
687690 // Print diagnostic category in bold and color
688691 switch (Level) {
689692 case DiagnosticsEngine::Ignored:
690693 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 ;
694+ case DiagnosticsEngine::Note:
695+ OS.changeColor (noteColor, true , false );
696+ break ;
697+ case DiagnosticsEngine::Remark:
698+ OS.changeColor (remarkColor, true , false );
699+ break ;
700+ case DiagnosticsEngine::Warning:
701+ OS.changeColor (warningColor, true , false );
702+ break ;
703+ case DiagnosticsEngine::Error:
704+ OS.changeColor (errorColor, true , false );
705+ break ;
706+ case DiagnosticsEngine::Fatal:
707+ OS.changeColor (fatalColor, true , false );
708+ break ;
696709 }
697710 }
698711
@@ -711,7 +724,7 @@ TextDiagnostic::printDiagnosticLevel(raw_ostream &OS,
711724}
712725
713726/* static*/
714- void TextDiagnostic::printDiagnosticMessage (raw_ostream &OS,
727+ void TextDiagnostic::printDiagnosticMessage (formatted_raw_ostream &OS,
715728 bool IsSupplemental,
716729 StringRef Message,
717730 unsigned CurrentColumn,
@@ -720,7 +733,7 @@ void TextDiagnostic::printDiagnosticMessage(raw_ostream &OS,
720733 if (ShowColors && !IsSupplemental) {
721734 // Print primary diagnostic messages in bold and without color, to visually
722735 // indicate the transition from continuation notes and other output.
723- OS.changeColor (savedColor, true );
736+ OS.changeColor (savedColor, true , false );
724737 Bold = true ;
725738 }
726739
@@ -798,7 +811,7 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
798811 return ;
799812
800813 if (DiagOpts.ShowColors )
801- OS.changeColor (savedColor, true );
814+ OS.changeColor (savedColor, true , false );
802815
803816 emitFilename (PLoc.getFilename (), Loc.getManager ());
804817 switch (DiagOpts.getFormat ()) {
@@ -1423,7 +1436,7 @@ void TextDiagnostic::emitSnippetAndCaret(
14231436 if (!CaretLine.empty ()) {
14241437 indentForLineNumbers ();
14251438 if (DiagOpts.ShowColors )
1426- OS.changeColor (caretColor, true );
1439+ OS.changeColor (caretColor, true , false );
14271440 OS << CaretLine << ' \n ' ;
14281441 if (DiagOpts.ShowColors )
14291442 OS.resetColor ();
@@ -1433,7 +1446,7 @@ void TextDiagnostic::emitSnippetAndCaret(
14331446 indentForLineNumbers ();
14341447 if (DiagOpts.ShowColors )
14351448 // Print fixit line in color
1436- OS.changeColor (fixitColor, false );
1449+ OS.changeColor (fixitColor, false , false );
14371450 if (DiagOpts.ShowSourceRanges )
14381451 OS << ' ' ;
14391452 OS << FixItInsertionLine << ' \n ' ;
@@ -1459,7 +1472,7 @@ void TextDiagnostic::emitSnippet(StringRef SourceLine,
14591472
14601473 // Print the source line one character at a time.
14611474 bool PrintReversed = false ;
1462- std::optional<llvm::raw_ostream ::Colors> CurrentColor;
1475+ std::optional<llvm::formatted_raw_ostream ::Colors> CurrentColor;
14631476 size_t I = 0 ;
14641477 while (I < SourceLine.size ()) {
14651478 auto [Str, WasPrintable] =
@@ -1485,7 +1498,7 @@ void TextDiagnostic::emitSnippet(StringRef SourceLine,
14851498 if (CharStyle != Styles.end ()) {
14861499 if (!CurrentColor ||
14871500 (CurrentColor && *CurrentColor != CharStyle->Color )) {
1488- OS.changeColor (CharStyle->Color , false );
1501+ OS.changeColor (CharStyle->Color , false , false );
14891502 CurrentColor = CharStyle->Color ;
14901503 }
14911504 } else if (CurrentColor) {
0 commit comments