[PATCH] D150840: [clang][NFC] Refactor emitSnippet()

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 31 00:21:58 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb7e5cb1f9a3a: [clang][NFC] Refactor emitSnippet() (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150840/new/

https://reviews.llvm.org/D150840

Files:
  clang/lib/Frontend/TextDiagnostic.cpp


Index: clang/lib/Frontend/TextDiagnostic.cpp
===================================================================
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1298,16 +1298,12 @@
   emitParseableFixits(Hints, SM);
 }
 
-void TextDiagnostic::emitSnippet(StringRef line, unsigned MaxLineNoDisplayWidth,
+void TextDiagnostic::emitSnippet(StringRef SourceLine,
+                                 unsigned MaxLineNoDisplayWidth,
                                  unsigned LineNo) {
-  if (line.empty())
+  if (SourceLine.empty())
     return;
 
-  size_t i = 0;
-
-  std::string to_print;
-  bool print_reversed = false;
-
   // Emit line number.
   if (MaxLineNoDisplayWidth > 0) {
     unsigned LineNoDisplayWidth = getNumDisplayWidth(LineNo);
@@ -1318,28 +1314,30 @@
     OS << " | ";
   }
 
-  while (i<line.size()) {
-    std::pair<SmallString<16>,bool> res
-        = printableTextForNextCharacter(line, &i, DiagOpts->TabStop);
-    bool was_printable = res.second;
+  bool PrintReversed = false;
+  std::string ToPrint;
+  size_t I = 0;
+  while (I < SourceLine.size()) {
+    auto [Str, WasPrintable] =
+        printableTextForNextCharacter(SourceLine, &I, DiagOpts->TabStop);
 
-    if (DiagOpts->ShowColors && was_printable == print_reversed) {
-      if (print_reversed)
+    if (DiagOpts->ShowColors && WasPrintable == PrintReversed) {
+      if (PrintReversed)
         OS.reverseColor();
-      OS << to_print;
-      to_print.clear();
+      OS << ToPrint;
+      ToPrint.clear();
       if (DiagOpts->ShowColors)
         OS.resetColor();
     }
 
-    print_reversed = !was_printable;
-    to_print += res.first.str();
+    PrintReversed = !WasPrintable;
+    ToPrint += Str;
   }
 
-  if (print_reversed && DiagOpts->ShowColors)
+  if (PrintReversed && DiagOpts->ShowColors)
     OS.reverseColor();
-  OS << to_print;
-  if (print_reversed && DiagOpts->ShowColors)
+  OS << ToPrint;
+  if (PrintReversed && DiagOpts->ShowColors)
     OS.resetColor();
 
   OS << '\n';


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150840.526934.patch
Type: text/x-patch
Size: 2023 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230531/9edcc915/attachment.bin>


More information about the cfe-commits mailing list