diff options
author | Daniel Jasper <djasper@google.com> | 2015-05-15 09:41:59 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-05-15 09:41:59 +0000 |
commit | 731dde91db80686eec141cc3ee0ef9594e1a85c6 (patch) | |
tree | 80f6a43e8495dfde5c14903b7f1df2e864600a78 /clang/lib/Format | |
parent | 06d2855fb3fd7dcc623f14c2d0469bc173ca00c0 (diff) | |
download | bcm5719-llvm-731dde91db80686eec141cc3ee0ef9594e1a85c6.tar.gz bcm5719-llvm-731dde91db80686eec141cc3ee0ef9594e1a85c6.zip |
clang-format: Don't use column layout in lists that have separating
comments. At some point, we might to want to a layout with a different
number of columns instead, but at the moment, this causes more
confusion than it's worth.
llvm-svn: 237427
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/FormatToken.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index 2f0b32971b6..42036666b0b 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -153,10 +153,13 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) { // trailing comments which are otherwise ignored for column alignment. SmallVector<unsigned, 8> EndOfLineItemLength; + bool HasSeparatingComment = false; for (unsigned i = 0, e = Commas.size() + 1; i != e; ++i) { // Skip comments on their own line. - while (ItemBegin->HasUnescapedNewline && ItemBegin->isTrailingComment()) + while (ItemBegin->HasUnescapedNewline && ItemBegin->isTrailingComment()) { ItemBegin = ItemBegin->Next; + HasSeparatingComment = i > 0; + } MustBreakBeforeItem.push_back(ItemBegin->MustBreakBefore); if (ItemBegin->is(tok::l_brace)) @@ -193,10 +196,9 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) { ItemBegin = ItemEnd->Next; } - // If this doesn't have a nested list, we require at least 6 elements in order - // create a column layout. If it has a nested list, column layout ensures one - // list element per line. - if (Commas.size() < 5 || Token->NestingLevel != 0) + // Don't use column layout for nested lists, lists with few elements and in + // presence of separating comments. + if (Token->NestingLevel != 0 || Commas.size() < 5 || HasSeparatingComment) return; // We can never place more than ColumnLimit / 3 items in a row (because of the |