summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-10-24 14:14:49 +0000
committerDaniel Jasper <djasper@google.com>2013-10-24 14:14:49 +0000
commit7c72d9fef2555e45b5095977a825a4e520c4f8b2 (patch)
tree507d295fb7a083c96ea431232715a1629db2db8c /clang/lib/Format
parente38e57206fd4da7ac721608a229bf802d6fe23b9 (diff)
downloadbcm5719-llvm-7c72d9fef2555e45b5095977a825a4e520c4f8b2.tar.gz
bcm5719-llvm-7c72d9fef2555e45b5095977a825a4e520c4f8b2.zip
clang-format: Be more conservative about column layout formatting.
Specifically, if a braced list has at least one nested braced list, format it either all on one line or in one column (i.e. one item per line). This seems in general to be an improvement as the structure of nested braced lists can make a tightly packed outer braced list hard to read. llvm-svn: 193345
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/FormatToken.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 4ca4edbe158..8ac704a3bb6 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -99,12 +99,15 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
// trailing comments which are otherwise ignored for column alignment.
SmallVector<unsigned, 8> EndOfLineItemLength;
+ bool HasNestedBracedList = false;
for (unsigned i = 0, e = Commas.size() + 1; i != e; ++i) {
// Skip comments on their own line.
while (ItemBegin->HasUnescapedNewline && ItemBegin->isTrailingComment())
ItemBegin = ItemBegin->Next;
MustBreakBeforeItem.push_back(ItemBegin->MustBreakBefore);
+ if (ItemBegin->is(tok::l_brace))
+ HasNestedBracedList = true;
const FormatToken *ItemEnd = NULL;
if (i == Commas.size()) {
ItemEnd = Token->MatchingParen;
@@ -142,7 +145,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
ColumnFormat Format;
Format.Columns = Columns;
Format.ColumnSizes.resize(Columns);
- Format.LineCount = 0;
+ Format.LineCount = 1;
bool HasRowWithSufficientColumns = false;
unsigned Column = 0;
for (unsigned i = 0, e = ItemLengths.size(); i != e; ++i) {
@@ -172,6 +175,11 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
if (Format.TotalWidth > Style.ColumnLimit)
continue;
+ // If this braced list has nested braced list, we format it either with one
+ // element per line or with all elements on one line.
+ if (HasNestedBracedList && Columns > 1 && Format.LineCount > 1)
+ continue;
+
Formats.push_back(Format);
}
}
OpenPOWER on IntegriCloud