Improve handling of trailing block comments

This is a follow up to r174309 to actually make it work.

llvm-svn: 174314
This commit is contained in:
Daniel Jasper 2013-02-04 08:34:57 +00:00
parent d91ae4d960
commit 14e40ec828
2 changed files with 10 additions and 5 deletions

View File

@ -204,6 +204,11 @@ private:
tooling::Replacements Replaces; tooling::Replacements Replaces;
}; };
static bool isTrailingComment(const AnnotatedToken &Tok) {
return Tok.is(tok::comment) &&
(Tok.Children.empty() || Tok.Children[0].MustBreakBefore);
}
class UnwrappedLineFormatter { class UnwrappedLineFormatter {
public: public:
UnwrappedLineFormatter(const FormatStyle &Style, SourceManager &SourceMgr, UnwrappedLineFormatter(const FormatStyle &Style, SourceManager &SourceMgr,
@ -464,7 +469,7 @@ private:
(Previous.is(tok::l_paren) || Previous.is(tok::l_brace) || (Previous.is(tok::l_paren) || Previous.is(tok::l_brace) ||
State.NextToken->Parent->Type == TT_TemplateOpener)) State.NextToken->Parent->Type == TT_TemplateOpener))
State.Stack[ParenLevel].Indent = State.Column + Spaces; State.Stack[ParenLevel].Indent = State.Column + Spaces;
if (Previous.is(tok::comma) && Current.Type != TT_LineComment) if (Previous.is(tok::comma) && !isTrailingComment(Current))
State.Stack[ParenLevel].HasMultiParameterLine = true; State.Stack[ParenLevel].HasMultiParameterLine = true;
State.Column += Spaces; State.Column += Spaces;
@ -690,8 +695,7 @@ private:
return true; return true;
if (State.NextToken->Parent->is(tok::comma) && if (State.NextToken->Parent->is(tok::comma) &&
State.Stack.back().BreakAfterComma && State.Stack.back().BreakAfterComma &&
(State.NextToken->isNot(tok::comment) || !isTrailingComment(*State.NextToken))
!State.NextToken->Children[0].MustBreakBefore))
return true; return true;
if ((State.NextToken->Type == TT_CtorInitializerColon || if ((State.NextToken->Type == TT_CtorInitializerColon ||
(State.NextToken->Parent->ClosesTemplateDeclaration && (State.NextToken->Parent->ClosesTemplateDeclaration &&

View File

@ -1919,11 +1919,12 @@ TEST_F(FormatTest, BlockComments) {
EXPECT_EQ("someFunction(1, /* comment 1 */\n" EXPECT_EQ("someFunction(1, /* comment 1 */\n"
" 2, /* comment 2 */\n" " 2, /* comment 2 */\n"
" 3, /* comment 3 */\n" " 3, /* comment 3 */\n"
" aaaa);", " aaaa,\n"
" bbbb);",
format("someFunction (1, /* comment 1 */\n" format("someFunction (1, /* comment 1 */\n"
" 2, /* comment 2 */ \n" " 2, /* comment 2 */ \n"
" 3, /* comment 3 */\n" " 3, /* comment 3 */\n"
"aaaa );", getGoogleStyle())); "aaaa, bbbb );", getGoogleStyle()));
} }
TEST_F(FormatTest, FormatStarDependingOnContext) { TEST_F(FormatTest, FormatStarDependingOnContext) {