[clang] 1c76548 - [clang][Diagnostics] Use llvm::raw_ostream::indent()
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed May 31 00:45:00 PDT 2023
Author: Timm Bäder
Date: 2023-05-31T09:40:24+02:00
New Revision: 1c765483fd34efe3ff7f71a9d2d5781bdf3d4517
URL: https://github.com/llvm/llvm-project/commit/1c765483fd34efe3ff7f71a9d2d5781bdf3d4517
DIFF: https://github.com/llvm/llvm-project/commit/1c765483fd34efe3ff7f71a9d2d5781bdf3d4517.diff
LOG: [clang][Diagnostics] Use llvm::raw_ostream::indent()
Differential Revision: https://reviews.llvm.org/D151078
Added:
Modified:
clang/lib/Frontend/TextDiagnostic.cpp
Removed:
################################################################################
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp
index 9b11294224ed..930033a7d552 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -615,9 +615,6 @@ static bool printWordWrapped(raw_ostream &OS, StringRef Str,
const unsigned Length = std::min(Str.find('\n'), Str.size());
bool TextNormal = true;
- // The string used to indent each line.
- SmallString<16> IndentStr;
- IndentStr.assign(Indentation, ' ');
bool Wrapped = false;
for (unsigned WordStart = 0, WordEnd; WordStart < Length;
WordStart = WordEnd) {
@@ -646,7 +643,7 @@ static bool printWordWrapped(raw_ostream &OS, StringRef Str,
// This word does not fit on the current line, so wrap to the next
// line.
OS << '\n';
- OS.write(&IndentStr[0], Indentation);
+ OS.indent(Indentation);
applyTemplateHighlighting(OS, Str.substr(WordStart, WordLength),
TextNormal, Bold);
Column = Indentation + WordLength;
@@ -1188,12 +1185,8 @@ void TextDiagnostic::emitSnippetAndCaret(
? std::max(4u, getNumDisplayWidth(DisplayLineNo + MaxLines))
: 0;
auto indentForLineNumbers = [&] {
- if (MaxLineNoDisplayWidth > 0) {
- OS << ' ';
- for (unsigned I = 0; I != MaxLineNoDisplayWidth; ++I)
- OS << ' ';
- OS << " | ";
- }
+ if (MaxLineNoDisplayWidth > 0)
+ OS.indent(MaxLineNoDisplayWidth + 2) << "| ";
};
for (unsigned LineNo = Lines.first; LineNo != Lines.second + 1;
@@ -1307,11 +1300,8 @@ void TextDiagnostic::emitSnippet(StringRef SourceLine,
// Emit line number.
if (MaxLineNoDisplayWidth > 0) {
unsigned LineNoDisplayWidth = getNumDisplayWidth(LineNo);
- OS << ' ';
- for (unsigned I = LineNoDisplayWidth; I < MaxLineNoDisplayWidth; ++I)
- OS << ' ';
- OS << LineNo;
- OS << " | ";
+ OS.indent(MaxLineNoDisplayWidth - LineNoDisplayWidth + 1)
+ << LineNo << " | ";
}
// Print the source line one character at a time.
More information about the cfe-commits
mailing list