Skip to content

Conversation

jurahul
Copy link
Contributor

@jurahul jurahul commented Oct 1, 2025

Add missing file header to ScopedPrinter.cpp and adjust the code to conform to LLVM coding standards.

@jurahul jurahul marked this pull request as ready for review October 1, 2025 03:34
@jurahul jurahul requested a review from kazutakahirata October 1, 2025 03:35
@llvmbot
Copy link
Member

llvmbot commented Oct 1, 2025

@llvm/pr-subscribers-llvm-support

Author: Rahul Joshi (jurahul)

Changes
  • 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 --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

@jurahul jurahul requested a review from nikic October 1, 2025 15:17
- Use character instead of a single character string.
- Add missing header to ScopedPrinter.cpp and adjust the code to
  conform to LLVM coding standards.
@jurahul jurahul force-pushed the scopedprinter_cleanup branch from 67d94aa to 46000da Compare October 1, 2025 15:50
@jurahul jurahul requested a review from nikic October 1, 2025 15:52
Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jurahul jurahul merged commit c4788bf into llvm:main Oct 1, 2025
9 checks passed
@jurahul jurahul deleted the scopedprinter_cleanup branch October 1, 2025 20:58
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
Add missing file header to ScopedPrinter.cpp and adjust the code to
conform to LLVM coding standards.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants