r237233 - clang-format: Support column layout with comment after {.
Daniel Jasper
djasper at google.com
Wed May 13 01:16:01 PDT 2015
Author: djasper
Date: Wed May 13 03:16:00 2015
New Revision: 237233
URL: http://llvm.org/viewvc/llvm-project?rev=237233&view=rev
Log:
clang-format: Support column layout with comment after {.
Before:
vector<int> iiiiiiiiiiiiiii = { //
1111111111, 2222222222, 33333333333, 4444444444, //
111111111, 222222222, 3333333333, 444444444, //
11111111, 22222222, 333333333, 44444444};
After:
vector<int> iiiiiiiiiiiiiii = { //
1111111111, 2222222222, 33333333333, 4444444444, //
111111111, 222222222, 3333333333, 444444444, //
11111111, 22222222, 333333333, 44444444};
Modified:
cfe/trunk/lib/Format/FormatToken.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/FormatToken.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.cpp?rev=237233&r1=237232&r2=237233&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.cpp (original)
+++ cfe/trunk/lib/Format/FormatToken.cpp Wed May 13 03:16:00 2015
@@ -60,13 +60,13 @@ void TokenRole::precomputeFormattingInfo
unsigned CommaSeparatedList::formatAfterToken(LineState &State,
ContinuationIndenter *Indenter,
bool DryRun) {
- if (State.NextToken == nullptr || !State.NextToken->Previous ||
- !State.NextToken->Previous->Previous)
+ if (State.NextToken == nullptr || !State.NextToken->Previous)
return 0;
// Ensure that we start on the opening brace.
- const FormatToken *LBrace = State.NextToken->Previous->Previous;
- if (LBrace->isNot(tok::l_brace) || LBrace->BlockKind == BK_Block ||
+ const FormatToken *LBrace =
+ State.NextToken->Previous->getPreviousNonComment();
+ if (!LBrace || LBrace->isNot(tok::l_brace) || LBrace->BlockKind == BK_Block ||
LBrace->Type == TT_DictLiteral ||
LBrace->Next->Type == TT_DesignatedInitializerPeriod)
return 0;
@@ -145,6 +145,8 @@ void CommaSeparatedList::precomputeForma
return;
FormatToken *ItemBegin = Token->Next;
+ while (ItemBegin->isTrailingComment())
+ ItemBegin = ItemBegin->Next;
SmallVector<bool, 8> MustBreakBeforeItem;
// The lengths of an item if it is put at the end of the line. This includes
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=237233&r1=237232&r2=237233&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed May 13 03:16:00 2015
@@ -6368,6 +6368,12 @@ TEST_F(FormatTest, FormatsBracedListsInC
" /**/ /**/};",
getLLVMStyleWithColumns(39));
+ // Trailing comment in the first line.
+ verifyFormat("vector<int> iiiiiiiiiiiiiii = { //\n"
+ " 1111111111, 2222222222, 33333333333, 4444444444, //\n"
+ " 111111111, 222222222, 3333333333, 444444444, //\n"
+ " 11111111, 22222222, 333333333, 44444444};");
+
// With nested lists, we should either format one item per line or all nested
// lists one on line.
// FIXME: For some nested lists, we can do better.
More information about the cfe-commits
mailing list