[PATCH] D151075: [clang][Diagnostics] Simplify emitSnippet()

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


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

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151075

Files:
  clang/lib/Frontend/TextDiagnostic.cpp


Index: clang/lib/Frontend/TextDiagnostic.cpp
===================================================================
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1314,30 +1314,27 @@
     OS << " | ";
   }
 
+  // Print the source line one character at a time.
   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 && WasPrintable == PrintReversed) {
-      if (PrintReversed)
-        OS.reverseColor();
-      OS << ToPrint;
-      ToPrint.clear();
-      if (DiagOpts->ShowColors)
-        OS.resetColor();
+    // Toggle inverted colors on or off for this character.
+    if (DiagOpts->ShowColors) {
+      if (WasPrintable == PrintReversed) {
+        PrintReversed = !PrintReversed;
+        if (PrintReversed)
+          OS.reverseColor();
+        else
+          OS.resetColor();
+      }
     }
-
-    PrintReversed = !WasPrintable;
-    ToPrint += Str;
+    OS << Str;
   }
 
-  if (PrintReversed && DiagOpts->ShowColors)
-    OS.reverseColor();
-  OS << ToPrint;
-  if (PrintReversed && DiagOpts->ShowColors)
+  if (DiagOpts->ShowColors)
     OS.resetColor();
 
   OS << '\n';


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151075.526939.patch
Type: text/x-patch
Size: 1319 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230531/7cbcaf64/attachment.bin>


More information about the cfe-commits mailing list