clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
//===--- FormatToken.cpp - Format C++ code --------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief This file implements specific functions of \c FormatTokens and their
|
|
|
|
/// roles.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "FormatToken.h"
|
|
|
|
#include "ContinuationIndenter.h"
|
|
|
|
#include "clang/Format/Format.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace format {
|
|
|
|
|
|
|
|
TokenRole::~TokenRole() {}
|
|
|
|
|
|
|
|
void TokenRole::precomputeFormattingInfos(const FormatToken *Token) {}
|
|
|
|
|
|
|
|
unsigned CommaSeparatedList::format(LineState &State,
|
|
|
|
ContinuationIndenter *Indenter,
|
|
|
|
bool DryRun) {
|
|
|
|
if (!State.NextToken->Previous || !State.NextToken->Previous->Previous ||
|
|
|
|
Commas.size() <= 2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Ensure that we start on the opening brace.
|
|
|
|
const FormatToken *LBrace = State.NextToken->Previous->Previous;
|
|
|
|
if (LBrace->isNot(tok::l_brace) ||
|
2013-09-13 09:20:45 +00:00
|
|
|
LBrace->BlockKind == BK_Block ||
|
2013-10-24 10:31:50 +00:00
|
|
|
LBrace->Type == TT_DictLiteral ||
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
LBrace->Next->Type == TT_DesignatedInitializerPeriod)
|
|
|
|
return 0;
|
|
|
|
|
2013-08-27 08:43:47 +00:00
|
|
|
// Calculate the number of code points we have to format this list. As the
|
|
|
|
// first token is already placed, we have to subtract it.
|
|
|
|
unsigned RemainingCodePoints = Style.ColumnLimit - State.Column +
|
2013-09-10 09:38:25 +00:00
|
|
|
State.NextToken->Previous->ColumnWidth;
|
2013-08-27 08:43:47 +00:00
|
|
|
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
// Find the best ColumnFormat, i.e. the best number of columns to use.
|
2013-08-27 08:43:47 +00:00
|
|
|
const ColumnFormat *Format = getColumnFormat(RemainingCodePoints);
|
clang-format: Prefer column layout if possible.
Add a severe penalty for not using column layout for braced lists. If
there are solutions with column layout, these are generally preferable
over bin-packed solutions.
Before:
std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{ aaaaaaa, aaaaaaaaaa, aaaaa,
aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a,
aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaa +
aaaaaaaaaaaaaaaaaaa,
aaaaaaa, a };
After:
std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{
aaaaaaa, aaaaaaaaaa,
aaaaa, aaaaaaaaaaaaaaa,
aaa, aaaaaaaaaa,
a, aaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa,
aaaaaaa, a
};
llvm-svn: 195546
2013-11-23 10:22:59 +00:00
|
|
|
// If no ColumnFormat can be used, the braced list would generally be
|
|
|
|
// bin-packed. Add a severe penalty to this so that column layouts are
|
2013-12-05 16:25:25 +00:00
|
|
|
// preferred if possible.
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
if (!Format)
|
clang-format: Prefer column layout if possible.
Add a severe penalty for not using column layout for braced lists. If
there are solutions with column layout, these are generally preferable
over bin-packed solutions.
Before:
std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{ aaaaaaa, aaaaaaaaaa, aaaaa,
aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a,
aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaa +
aaaaaaaaaaaaaaaaaaa,
aaaaaaa, a };
After:
std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{
aaaaaaa, aaaaaaaaaa,
aaaaa, aaaaaaaaaaaaaaa,
aaa, aaaaaaaaaa,
a, aaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa,
aaaaaaa, a
};
llvm-svn: 195546
2013-11-23 10:22:59 +00:00
|
|
|
return 10000;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
|
|
|
|
// Format the entire list.
|
|
|
|
unsigned Penalty = 0;
|
|
|
|
unsigned Column = 0;
|
|
|
|
unsigned Item = 0;
|
|
|
|
while (State.NextToken != LBrace->MatchingParen) {
|
|
|
|
bool NewLine = false;
|
|
|
|
unsigned ExtraSpaces = 0;
|
|
|
|
|
|
|
|
// If the previous token was one of our commas, we are now on the next item.
|
|
|
|
if (Item < Commas.size() && State.NextToken->Previous == Commas[Item]) {
|
|
|
|
if (!State.NextToken->isTrailingComment()) {
|
|
|
|
ExtraSpaces += Format->ColumnSizes[Column] - ItemLengths[Item];
|
|
|
|
++Column;
|
|
|
|
}
|
|
|
|
++Item;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Column == Format->Columns || State.NextToken->MustBreakBefore) {
|
|
|
|
Column = 0;
|
|
|
|
NewLine = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place token using the continuation indenter and store the penalty.
|
|
|
|
Penalty += Indenter->addTokenToState(State, NewLine, DryRun, ExtraSpaces);
|
|
|
|
}
|
|
|
|
return Penalty;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the lengths in code points between Begin and End (both included),
|
|
|
|
// assuming that the entire sequence is put on a single line.
|
|
|
|
static unsigned CodePointsBetween(const FormatToken *Begin,
|
|
|
|
const FormatToken *End) {
|
2013-08-26 08:10:17 +00:00
|
|
|
assert(End->TotalLength >= Begin->TotalLength);
|
2013-09-10 09:38:25 +00:00
|
|
|
return End->TotalLength - Begin->TotalLength + Begin->ColumnWidth;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
|
2013-08-26 08:10:17 +00:00
|
|
|
// FIXME: At some point we might want to do this for other lists, too.
|
clang-format: Be more conservative about braced list column layout.
Specifically disable it for nested braced lists as it commonly can look
really weird. Eventually, we'll want to become smarter and format some of
the nested lists better.
Before:
SomeStruct my_struct_array = {
{ aaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa,
aaaaaaaaaa, aaaaaaaaaa, aaaaaaa, aaa },
{ aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa },
{ aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaa, a, aaaaaaaaaa,
aaaaaaaaa, aaa },
};
After:
SomeStruct my_struct_array = {
{ aaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa, aaaaaaaaaa,
aaaaaaaaaaaa, aaaaaaa, aaa },
{ aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa },
{ aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa },
};
llvm-svn: 196783
2013-12-09 14:40:19 +00:00
|
|
|
if (!Token->MatchingParen || Token->isNot(tok::l_brace) ||
|
|
|
|
Token->NestingLevel != 0)
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
FormatToken *ItemBegin = Token->Next;
|
|
|
|
SmallVector<bool, 8> MustBreakBeforeItem;
|
|
|
|
|
|
|
|
// The lengths of an item if it is put at the end of the line. This includes
|
|
|
|
// trailing comments which are otherwise ignored for column alignment.
|
|
|
|
SmallVector<unsigned, 8> EndOfLineItemLength;
|
|
|
|
|
2013-10-24 14:14:49 +00:00
|
|
|
bool HasNestedBracedList = false;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
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);
|
2013-10-24 14:14:49 +00:00
|
|
|
if (ItemBegin->is(tok::l_brace))
|
|
|
|
HasNestedBracedList = true;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
const FormatToken *ItemEnd = NULL;
|
|
|
|
if (i == Commas.size()) {
|
|
|
|
ItemEnd = Token->MatchingParen;
|
|
|
|
const FormatToken *NonCommentEnd = ItemEnd->getPreviousNonComment();
|
|
|
|
ItemLengths.push_back(CodePointsBetween(ItemBegin, NonCommentEnd));
|
|
|
|
if (Style.Cpp11BracedListStyle) {
|
|
|
|
// In Cpp11 braced list style, the } and possibly other subsequent
|
|
|
|
// tokens will need to stay on a line with the last element.
|
|
|
|
while (ItemEnd->Next && !ItemEnd->Next->CanBreakBefore)
|
|
|
|
ItemEnd = ItemEnd->Next;
|
|
|
|
} else {
|
|
|
|
// In other braced lists styles, the "}" can be wrapped to the new line.
|
|
|
|
ItemEnd = Token->MatchingParen->Previous;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ItemEnd = Commas[i];
|
|
|
|
// The comma is counted as part of the item when calculating the length.
|
2013-08-26 08:10:17 +00:00
|
|
|
ItemLengths.push_back(CodePointsBetween(ItemBegin, ItemEnd));
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
// Consume trailing comments so the are included in EndOfLineItemLength.
|
|
|
|
if (ItemEnd->Next && !ItemEnd->Next->HasUnescapedNewline &&
|
|
|
|
ItemEnd->Next->isTrailingComment())
|
|
|
|
ItemEnd = ItemEnd->Next;
|
|
|
|
}
|
|
|
|
EndOfLineItemLength.push_back(CodePointsBetween(ItemBegin, ItemEnd));
|
2013-08-26 08:10:17 +00:00
|
|
|
// 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 (ItemEnd->getNextNonComment() == Token->MatchingParen)
|
|
|
|
break;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
ItemBegin = ItemEnd->Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can never place more than ColumnLimit / 3 items in a row (because of the
|
|
|
|
// spaces and the comma).
|
|
|
|
for (unsigned Columns = 1; Columns <= Style.ColumnLimit / 3; ++Columns) {
|
|
|
|
ColumnFormat Format;
|
|
|
|
Format.Columns = Columns;
|
|
|
|
Format.ColumnSizes.resize(Columns);
|
2013-10-24 14:14:49 +00:00
|
|
|
Format.LineCount = 1;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
bool HasRowWithSufficientColumns = false;
|
|
|
|
unsigned Column = 0;
|
|
|
|
for (unsigned i = 0, e = ItemLengths.size(); i != e; ++i) {
|
2013-10-11 21:25:45 +00:00
|
|
|
assert(i < MustBreakBeforeItem.size());
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
if (MustBreakBeforeItem[i] || Column == Columns) {
|
|
|
|
++Format.LineCount;
|
|
|
|
Column = 0;
|
|
|
|
}
|
|
|
|
if (Column == Columns - 1)
|
|
|
|
HasRowWithSufficientColumns = true;
|
|
|
|
unsigned length =
|
|
|
|
(Column == Columns - 1) ? EndOfLineItemLength[i] : ItemLengths[i];
|
|
|
|
Format.ColumnSizes[Column] =
|
|
|
|
std::max(Format.ColumnSizes[Column], length);
|
|
|
|
++Column;
|
|
|
|
}
|
|
|
|
// If all rows are terminated early (e.g. by trailing comments), we don't
|
|
|
|
// need to look further.
|
|
|
|
if (!HasRowWithSufficientColumns)
|
|
|
|
break;
|
|
|
|
Format.TotalWidth = Columns - 1; // Width of the N-1 spaces.
|
|
|
|
for (unsigned i = 0; i < Columns; ++i) {
|
|
|
|
Format.TotalWidth += Format.ColumnSizes[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore layouts that are bound to violate the column limit.
|
|
|
|
if (Format.TotalWidth > Style.ColumnLimit)
|
|
|
|
continue;
|
|
|
|
|
2013-10-24 14:14:49 +00:00
|
|
|
// 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;
|
|
|
|
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 15:00:41 +00:00
|
|
|
Formats.push_back(Format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const CommaSeparatedList::ColumnFormat *
|
|
|
|
CommaSeparatedList::getColumnFormat(unsigned RemainingCharacters) const {
|
|
|
|
const ColumnFormat *BestFormat = NULL;
|
|
|
|
for (SmallVector<ColumnFormat, 4>::const_reverse_iterator
|
|
|
|
I = Formats.rbegin(),
|
|
|
|
E = Formats.rend();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (I->TotalWidth <= RemainingCharacters) {
|
|
|
|
if (BestFormat && I->LineCount > BestFormat->LineCount)
|
|
|
|
break;
|
|
|
|
BestFormat = &*I;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return BestFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace format
|
|
|
|
} // namespace clang
|