Change the data structure used in clang-format.
This is a first step towards supporting more complex structures such
as #ifs inside unwrapped lines. This patch mostly converts the array-based
UnwrappedLine into a linked-list-based UnwrappedLine. Future changes will
allow multiple children for each Token turning the UnwrappedLine into a
tree.
No functional changes intended.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171856 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index adb5363..9057589 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -74,7 +74,8 @@
UnwrappedLineParser::UnwrappedLineParser(const FormatStyle &Style,
FormatTokenSource &Tokens,
UnwrappedLineConsumer &Callback)
- : Style(Style), Tokens(&Tokens), Callback(Callback) {
+ : RootTokenInitialized(false), Style(Style), Tokens(&Tokens),
+ Callback(Callback) {
}
bool UnwrappedLineParser::parse() {
@@ -493,13 +494,15 @@
}
void UnwrappedLineParser::addUnwrappedLine() {
+ if (!RootTokenInitialized)
+ return;
// Consume trailing comments.
while (!eof() && FormatTok.NewlinesBefore == 0 &&
FormatTok.Tok.is(tok::comment)) {
nextToken();
}
Callback.consumeUnwrappedLine(Line);
- Line.Tokens.clear();
+ RootTokenInitialized = false;
}
bool UnwrappedLineParser::eof() const {
@@ -509,7 +512,14 @@
void UnwrappedLineParser::nextToken() {
if (eof())
return;
- Line.Tokens.push_back(FormatTok);
+ if (RootTokenInitialized) {
+ LastInCurrentLine->Children.push_back(FormatTok);
+ LastInCurrentLine = &LastInCurrentLine->Children.back();
+ } else {
+ Line.RootToken = FormatTok;
+ RootTokenInitialized = true;
+ LastInCurrentLine = &Line.RootToken;
+ }
readToken();
}