diff options
| author | Daniel Jasper <djasper@google.com> | 2013-08-23 10:05:49 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-08-23 10:05:49 +0000 |
| commit | f93551c8b187f90624426543e95489b71c014118 (patch) | |
| tree | 39d34edfe5836e9932ef1461f5d703e535675d87 /clang/lib | |
| parent | bff06ce221671ce0cec97b7677967a3dacf93359 (diff) | |
| download | bcm5719-llvm-f93551c8b187f90624426543e95489b71c014118.tar.gz bcm5719-llvm-f93551c8b187f90624426543e95489b71c014118.zip | |
clang-format: Handle trailing commas in column layout of braced list.
Before, this was causing errors.
Also exit early in breakProtrudingToken() (before the expensive call to
SourceManager::getSpellingColumnNumber()). This makes formatting huge
(100k+-item) braced lists possible.
llvm-svn: 189094
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/Format/FormatToken.cpp | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 8f7bb50060e..005eec82b7b 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -569,6 +569,9 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, LineState &State, bool DryRun) { + if (!Current.isOneOf(tok::string_literal, tok::comment)) + return 0; + llvm::OwningPtr<BreakableToken> Token; unsigned StartColumn = State.Column - Current.CodePointCount; unsigned OriginalStartColumn = diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index 4e232afda52..1b6d3601905 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -92,6 +92,11 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) { SmallVector<unsigned, 8> EndOfLineItemLength; for (unsigned i = 0, e = Commas.size() + 1; i != e; ++i) { + // If there is a trailing comma in the list, the next item will start at the + // closing brace. Don't create an extra item for this. + if (ItemBegin == Token->MatchingParen) + break; + // Skip comments on their own line. while (ItemBegin->HasUnescapedNewline && ItemBegin->isTrailingComment()) ItemBegin = ItemBegin->Next; |

