From b7e5cb1f9a3a5226f22bb81c865214be81dce940 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Wed, 17 May 2023 20:23:06 +0200 Subject: [PATCH] [clang][NFC] Refactor emitSnippet() Rename parameters and local variables and reorder things a bit to be closer to their first point of use. Differential Revision: https://reviews.llvm.org/D150840 --- clang/lib/Frontend/TextDiagnostic.cpp | 38 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp index baf9b01..51b9011 100644 --- a/clang/lib/Frontend/TextDiagnostic.cpp +++ b/clang/lib/Frontend/TextDiagnostic.cpp @@ -1298,16 +1298,12 @@ void TextDiagnostic::emitSnippetAndCaret( 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 @@ void TextDiagnostic::emitSnippet(StringRef line, unsigned MaxLineNoDisplayWidth, OS << " | "; } - while (i,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'; -- 2.7.4