[clang] d65019b - [NFC] Clean up printing of UnwrappedLines.

Manuel Klimek via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 25 06:27:30 PST 2022


Author: Manuel Klimek
Date: 2022-11-25T14:26:47Z
New Revision: d65019bbcb0a33502ebfc3cfc492e4d3cee9c7b7

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

LOG: [NFC] Clean up printing of UnwrappedLines.

Move print functions to start of UnwarppedLineParser so they can be
used from everywhere in the file.
Pull out function that doesn't hard-code the stream.

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 4dc70e2d56c70..3bc7d2454c93a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -64,6 +64,39 @@ class FormatTokenSource {
 
 namespace {
 
+void printLine(llvm::raw_ostream &OS, const UnwrappedLine &Line,
+               StringRef Prefix = "", bool PrintText = false) {
+  OS << Prefix << "Line(" << Line.Level << ", FSC=" << Line.FirstStartColumn
+     << ")" << (Line.InPPDirective ? " MACRO" : "") << ": ";
+  bool NewLine = false;
+  for (std::list<UnwrappedLineNode>::const_iterator I = Line.Tokens.begin(),
+                                                    E = Line.Tokens.end();
+       I != E; ++I) {
+    if (NewLine) {
+      OS << Prefix;
+      NewLine = false;
+    }
+    OS << I->Tok->Tok.getName() << "["
+       << "T=" << (unsigned)I->Tok->getType()
+       << ", OC=" << I->Tok->OriginalColumn << ", \"" << I->Tok->TokenText
+       << "\"] ";
+    for (SmallVectorImpl<UnwrappedLine>::const_iterator
+             CI = I->Children.begin(),
+             CE = I->Children.end();
+         CI != CE; ++CI) {
+      OS << "\n";
+      printLine(OS, *CI, (Prefix + "  ").str());
+      NewLine = true;
+    }
+  }
+  if (!NewLine)
+    OS << "\n";
+}
+
+LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line) {
+  printLine(llvm::dbgs(), Line);
+}
+
 class ScopedDeclarationState {
 public:
   ScopedDeclarationState(UnwrappedLine &Line, llvm::BitVector &Stack,
@@ -4314,23 +4347,6 @@ void UnwrappedLineParser::parseVerilogCaseLabel() {
   Line->Level = OrigLevel;
 }
 
-LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line,
-                                                 StringRef Prefix = "") {
-  llvm::dbgs() << Prefix << "Line(" << Line.Level
-               << ", FSC=" << Line.FirstStartColumn << ")"
-               << (Line.InPPDirective ? " MACRO" : "") << ": ";
-  for (const auto &Node : Line.Tokens) {
-    llvm::dbgs() << Node.Tok->Tok.getName() << "["
-                 << "T=" << static_cast<unsigned>(Node.Tok->getType())
-                 << ", OC=" << Node.Tok->OriginalColumn << "] ";
-  }
-  for (const auto &Node : Line.Tokens)
-    for (const auto &ChildNode : Node.Children)
-      printDebugInfo(ChildNode, "\nChild: ");
-
-  llvm::dbgs() << "\n";
-}
-
 void UnwrappedLineParser::addUnwrappedLine(LineLevel AdjustLevel) {
   if (Line->Tokens.empty())
     return;


        


More information about the cfe-commits mailing list