[llvm] f88de01 - [Option] Avoid excessive newlines when printing Arg and Option

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 16:30:52 PDT 2023


Author: Justin Bogner
Date: 2023-08-09T16:29:43-07:00
New Revision: f88de010ba68b5e30292f6fab6759579a8441df3

URL: https://github.com/llvm/llvm-project/commit/f88de010ba68b5e30292f6fab6759579a8441df3
DIFF: https://github.com/llvm/llvm-project/commit/f88de010ba68b5e30292f6fab6759579a8441df3.diff

LOG: [Option] Avoid excessive newlines when printing Arg and Option

Arg::print calls Option::print and Option::print calls itself
recursively. Add a flag so we can avoid seemingly random breaks in the
print output of an argument list.

No tests since this only affects debug output.

Added: 
    

Modified: 
    llvm/include/llvm/Option/Option.h
    llvm/lib/Option/Arg.cpp
    llvm/lib/Option/Option.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Option/Option.h b/llvm/include/llvm/Option/Option.h
index 2460bbedd21f58..2c90745cd3bcd5 100644
--- a/llvm/include/llvm/Option/Option.h
+++ b/llvm/include/llvm/Option/Option.h
@@ -225,7 +225,7 @@ class Option {
                                       unsigned &Index) const;
 
 public:
-  void print(raw_ostream &O) const;
+  void print(raw_ostream &O, bool AddNewLine = true) const;
   void dump() const;
 };
 

diff  --git a/llvm/lib/Option/Arg.cpp b/llvm/lib/Option/Arg.cpp
index 48d173accdac21..b6384d0db65b1d 100644
--- a/llvm/lib/Option/Arg.cpp
+++ b/llvm/lib/Option/Arg.cpp
@@ -45,10 +45,8 @@ Arg::~Arg() {
 }
 
 void Arg::print(raw_ostream& O) const {
-  O << "<";
-
-  O << " Opt:";
-  Opt.print(O);
+  O << "<Opt:";
+  Opt.print(O, /*AddNewLine=*/false);
 
   O << " Index:" << Index;
 

diff  --git a/llvm/lib/Option/Option.cpp b/llvm/lib/Option/Option.cpp
index c570b02b08ce75..500768588bc9b3 100644
--- a/llvm/lib/Option/Option.cpp
+++ b/llvm/lib/Option/Option.cpp
@@ -38,7 +38,7 @@ Option::Option(const OptTable::Info *info, const OptTable *owner)
   }
 }
 
-void Option::print(raw_ostream &O) const {
+void Option::print(raw_ostream &O, bool AddNewLine) const {
   O << "<";
   switch (getKind()) {
 #define P(N) case N: O << #N; break
@@ -70,19 +70,21 @@ void Option::print(raw_ostream &O) const {
   const Option Group = getGroup();
   if (Group.isValid()) {
     O << " Group:";
-    Group.print(O);
+    Group.print(O, /*AddNewLine=*/false);
   }
 
   const Option Alias = getAlias();
   if (Alias.isValid()) {
     O << " Alias:";
-    Alias.print(O);
+    Alias.print(O, /*AddNewLine=*/false);
   }
 
   if (getKind() == MultiArgClass)
     O << " NumArgs:" << getNumArgs();
 
-  O << ">\n";
+  O << ">";
+  if (AddNewLine)
+    O << "\n";
 }
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)


        


More information about the llvm-commits mailing list