diff options
author | Daniel Jasper <djasper@google.com> | 2015-05-13 08:16:00 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-05-13 08:16:00 +0000 |
commit | 202c7cf413d2fe00b84d751c988f9e4360748254 (patch) | |
tree | 1258d8ce73562895f255aa64d53bfbb36219ddc7 /lib/Format/FormatToken.cpp | |
parent | 9e2794b1fea6b67f98c822129c24a61b371af67c (diff) |
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};
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237233 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/FormatToken.cpp')
-rw-r--r-- | lib/Format/FormatToken.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/Format/FormatToken.cpp b/lib/Format/FormatToken.cpp index bbc0fa8b0b..2f0b32971b 100644 --- a/lib/Format/FormatToken.cpp +++ b/lib/Format/FormatToken.cpp @@ -60,13 +60,13 @@ void TokenRole::precomputeFormattingInfos(const FormatToken *Token) {} 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::precomputeFormattingInfos(const FormatToken *Token) { 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 |