diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-08 14:56:18 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-08 14:56:18 +0000 |
commit | 26f7e78018ed6ce8aa11b5eef94c772ca4ee48bf (patch) | |
tree | f627e70e015c8f988ebf0258fe99caaa07f25324 /lib/Format/UnwrappedLineParser.cpp | |
parent | f8a6cb1f755fe1530a0fcdf3c4cb1706d7fce822 (diff) |
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
Diffstat (limited to 'lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | lib/Format/UnwrappedLineParser.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index adb536324a..905758993e 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -74,7 +74,8 @@ private: 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::parseStructOrClass() { } 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 @@ bool UnwrappedLineParser::eof() const { 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(); } |