[PATCH] D151078: [clang][Diagnostics] Use llvm::raw_ostream::indent()

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 04:07:59 PDT 2023


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, cjdb.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

TIL that this exists.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151078

Files:
  clang/lib/Frontend/TextDiagnostic.cpp


Index: clang/lib/Frontend/TextDiagnostic.cpp
===================================================================
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -623,9 +623,6 @@
   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) {
@@ -654,7 +651,7 @@
     // 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;
@@ -1196,12 +1193,8 @@
           ? 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 + 4);
   };
 
   for (unsigned LineNo = Lines.first; LineNo != Lines.second + 1;
@@ -1315,9 +1308,7 @@
   // Emit line number.
   if (MaxLineNoDisplayWidth > 0) {
     unsigned LineNoDisplayWidth = getNumDisplayWidth(LineNo);
-    OS << ' ';
-    for (unsigned I = LineNoDisplayWidth; I < MaxLineNoDisplayWidth; ++I)
-      OS << ' ';
+    OS.indent(MaxLineNoDisplayWidth - LineNoDisplayWidth + 1);
     OS << LineNo;
     OS << " | ";
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151078.524232.patch
Type: text/x-patch
Size: 1723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230522/bdc5e3ec/attachment.bin>


More information about the cfe-commits mailing list