[llvm] [NFC][LLVM][Support] Misc code cleanup in ScopedPrinter (PR #161462)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 30 20:35:19 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
- Use character instead of a single character string.
- Add missing header to ScopedPrinter.cpp and adjust the code to conform to LLVM coding standards.
---
Full diff: https://github.com/llvm/llvm-project/pull/161462.diff
2 Files Affected:
- (modified) llvm/include/llvm/Support/ScopedPrinter.h (+20-20)
- (modified) llvm/lib/Support/ScopedPrinter.cpp (+16-8)
``````````diff
diff --git a/llvm/include/llvm/Support/ScopedPrinter.h b/llvm/include/llvm/Support/ScopedPrinter.h
index a08cc8fd31fd2..49b09f9a453ea 100644
--- a/llvm/include/llvm/Support/ScopedPrinter.h
+++ b/llvm/include/llvm/Support/ScopedPrinter.h
@@ -220,59 +220,59 @@ class LLVM_ABI ScopedPrinter {
}
virtual void printNumber(StringRef Label, char Value) {
- startLine() << Label << ": " << static_cast<int>(Value) << "\n";
+ startLine() << Label << ": " << static_cast<int>(Value) << '\n';
}
virtual void printNumber(StringRef Label, signed char Value) {
- startLine() << Label << ": " << static_cast<int>(Value) << "\n";
+ startLine() << Label << ": " << static_cast<int>(Value) << '\n';
}
virtual void printNumber(StringRef Label, unsigned char Value) {
- startLine() << Label << ": " << static_cast<unsigned>(Value) << "\n";
+ startLine() << Label << ": " << static_cast<unsigned>(Value) << '\n';
}
virtual void printNumber(StringRef Label, short Value) {
- startLine() << Label << ": " << Value << "\n";
+ startLine() << Label << ": " << Value << '\n';
}
virtual void printNumber(StringRef Label, unsigned short Value) {
- startLine() << Label << ": " << Value << "\n";
+ startLine() << Label << ": " << Value << '\n';
}
virtual void printNumber(StringRef Label, int Value) {
- startLine() << Label << ": " << Value << "\n";
+ startLine() << Label << ": " << Value << '\n';
}
virtual void printNumber(StringRef Label, unsigned int Value) {
- startLine() << Label << ": " << Value << "\n";
+ startLine() << Label << ": " << Value << '\n';
}
virtual void printNumber(StringRef Label, long Value) {
- startLine() << Label << ": " << Value << "\n";
+ startLine() << Label << ": " << Value << '\n';
}
virtual void printNumber(StringRef Label, unsigned long Value) {
- startLine() << Label << ": " << Value << "\n";
+ startLine() << Label << ": " << Value << '\n';
}
virtual void printNumber(StringRef Label, long long Value) {
- startLine() << Label << ": " << Value << "\n";
+ startLine() << Label << ": " << Value << '\n';
}
virtual void printNumber(StringRef Label, unsigned long long Value) {
- startLine() << Label << ": " << Value << "\n";
+ startLine() << Label << ": " << Value << '\n';
}
virtual void printNumber(StringRef Label, const APSInt &Value) {
- startLine() << Label << ": " << Value << "\n";
+ startLine() << Label << ": " << Value << '\n';
}
virtual void printNumber(StringRef Label, float Value) {
- startLine() << Label << ": " << format("%5.1f", Value) << "\n";
+ startLine() << Label << ": " << format("%5.1f", Value) << '\n';
}
virtual void printNumber(StringRef Label, double Value) {
- startLine() << Label << ": " << format("%5.1f", Value) << "\n";
+ startLine() << Label << ": " << format("%5.1f", Value) << '\n';
}
template <typename T>
@@ -287,7 +287,7 @@ class LLVM_ABI ScopedPrinter {
template <typename... T> void printVersion(StringRef Label, T... Version) {
startLine() << Label << ": ";
printVersionInternal(Version...);
- getOStream() << "\n";
+ getOStream() << '\n';
}
template <typename T>
@@ -379,10 +379,10 @@ class LLVM_ABI ScopedPrinter {
printSymbolOffsetImpl(Label, Symbol, hex(Value));
}
- virtual void printString(StringRef Value) { startLine() << Value << "\n"; }
+ virtual void printString(StringRef Value) { startLine() << Value << '\n'; }
virtual void printString(StringRef Label, StringRef Value) {
- startLine() << Label << ": " << Value << "\n";
+ startLine() << Label << ": " << Value << '\n';
}
void printStringEscaped(StringRef Label, StringRef Value) {
@@ -460,7 +460,7 @@ class LLVM_ABI ScopedPrinter {
template <typename S, typename T, typename... TArgs>
void printVersionInternal(S Value, T Value2, TArgs... Args) {
- getOStream() << Value << ".";
+ getOStream() << Value << '.';
printVersionInternal(Value2, Args...);
}
@@ -506,7 +506,7 @@ class LLVM_ABI ScopedPrinter {
}
virtual void printHexImpl(StringRef Label, HexNumber Value) {
- startLine() << Label << ": " << Value << "\n";
+ startLine() << Label << ": " << Value << '\n';
}
virtual void printHexImpl(StringRef Label, StringRef Str, HexNumber Value) {
@@ -557,7 +557,7 @@ template <>
inline void
ScopedPrinter::printHex<support::ulittle16_t>(StringRef Label,
support::ulittle16_t Value) {
- startLine() << Label << ": " << hex(Value) << "\n";
+ startLine() << Label << ": " << hex(Value) << '\n';
}
struct DelimitedScope {
diff --git a/llvm/lib/Support/ScopedPrinter.cpp b/llvm/lib/Support/ScopedPrinter.cpp
index a17e397c0aa58..8d077ee421b40 100644
--- a/llvm/lib/Support/ScopedPrinter.cpp
+++ b/llvm/lib/Support/ScopedPrinter.cpp
@@ -1,12 +1,22 @@
-#include "llvm/Support/ScopedPrinter.h"
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementation of ScopedPrinter.
+//
+//===----------------------------------------------------------------------===//
+#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/Format.h"
+using namespace llvm;
using namespace llvm::support;
-namespace llvm {
-
-raw_ostream &operator<<(raw_ostream &OS, const HexNumber &Value) {
+raw_ostream &llvm::operator<<(raw_ostream &OS, const HexNumber &Value) {
OS << "0x" << utohexstr(Value.Value);
return OS;
}
@@ -28,9 +38,9 @@ void ScopedPrinter::printBinaryImpl(StringRef Label, StringRef Str,
<< "\n";
startLine() << ")\n";
} else {
- startLine() << Label << ":";
+ startLine() << Label << ':';
if (!Str.empty())
- OS << " " << Str;
+ OS << ' ' << Str;
OS << " (" << format_bytes(Data, std::nullopt, Data.size(), 1, 0, true)
<< ")\n";
}
@@ -45,5 +55,3 @@ JSONScopedPrinter::JSONScopedPrinter(
if (this->OuterScope)
this->OuterScope->setPrinter(*this);
}
-
-} // namespace llvm
``````````
</details>
https://github.com/llvm/llvm-project/pull/161462
More information about the llvm-commits
mailing list