Skip to content

Commit d65019b

Browse files
committed
[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.
1 parent f62d413 commit d65019b

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,39 @@ class FormatTokenSource {
6464

6565
namespace {
6666

67+
void printLine(llvm::raw_ostream &OS, const UnwrappedLine &Line,
68+
StringRef Prefix = "", bool PrintText = false) {
69+
OS << Prefix << "Line(" << Line.Level << ", FSC=" << Line.FirstStartColumn
70+
<< ")" << (Line.InPPDirective ? " MACRO" : "") << ": ";
71+
bool NewLine = false;
72+
for (std::list<UnwrappedLineNode>::const_iterator I = Line.Tokens.begin(),
73+
E = Line.Tokens.end();
74+
I != E; ++I) {
75+
if (NewLine) {
76+
OS << Prefix;
77+
NewLine = false;
78+
}
79+
OS << I->Tok->Tok.getName() << "["
80+
<< "T=" << (unsigned)I->Tok->getType()
81+
<< ", OC=" << I->Tok->OriginalColumn << ", \"" << I->Tok->TokenText
82+
<< "\"] ";
83+
for (SmallVectorImpl<UnwrappedLine>::const_iterator
84+
CI = I->Children.begin(),
85+
CE = I->Children.end();
86+
CI != CE; ++CI) {
87+
OS << "\n";
88+
printLine(OS, *CI, (Prefix + " ").str());
89+
NewLine = true;
90+
}
91+
}
92+
if (!NewLine)
93+
OS << "\n";
94+
}
95+
96+
LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line) {
97+
printLine(llvm::dbgs(), Line);
98+
}
99+
67100
class ScopedDeclarationState {
68101
public:
69102
ScopedDeclarationState(UnwrappedLine &Line, llvm::BitVector &Stack,
@@ -4314,23 +4347,6 @@ void UnwrappedLineParser::parseVerilogCaseLabel() {
43144347
Line->Level = OrigLevel;
43154348
}
43164349

4317-
LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line,
4318-
StringRef Prefix = "") {
4319-
llvm::dbgs() << Prefix << "Line(" << Line.Level
4320-
<< ", FSC=" << Line.FirstStartColumn << ")"
4321-
<< (Line.InPPDirective ? " MACRO" : "") << ": ";
4322-
for (const auto &Node : Line.Tokens) {
4323-
llvm::dbgs() << Node.Tok->Tok.getName() << "["
4324-
<< "T=" << static_cast<unsigned>(Node.Tok->getType())
4325-
<< ", OC=" << Node.Tok->OriginalColumn << "] ";
4326-
}
4327-
for (const auto &Node : Line.Tokens)
4328-
for (const auto &ChildNode : Node.Children)
4329-
printDebugInfo(ChildNode, "\nChild: ");
4330-
4331-
llvm::dbgs() << "\n";
4332-
}
4333-
43344350
void UnwrappedLineParser::addUnwrappedLine(LineLevel AdjustLevel) {
43354351
if (Line->Tokens.empty())
43364352
return;

0 commit comments

Comments
 (0)