From 14e40ec82896cc0d18acbec488a384987eb11f33 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 4 Feb 2013 08:34:57 +0000 Subject: [PATCH] Improve handling of trailing block comments This is a follow up to r174309 to actually make it work. llvm-svn: 174314 --- clang/lib/Format/Format.cpp | 10 +++++++--- clang/unittests/Format/FormatTest.cpp | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 91cbc2e..47d6340 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -204,6 +204,11 @@ private: tooling::Replacements Replaces; }; +static bool isTrailingComment(const AnnotatedToken &Tok) { + return Tok.is(tok::comment) && + (Tok.Children.empty() || Tok.Children[0].MustBreakBefore); +} + class UnwrappedLineFormatter { public: UnwrappedLineFormatter(const FormatStyle &Style, SourceManager &SourceMgr, @@ -464,7 +469,7 @@ private: (Previous.is(tok::l_paren) || Previous.is(tok::l_brace) || State.NextToken->Parent->Type == TT_TemplateOpener)) 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.Column += Spaces; @@ -690,8 +695,7 @@ private: return true; if (State.NextToken->Parent->is(tok::comma) && State.Stack.back().BreakAfterComma && - (State.NextToken->isNot(tok::comment) || - !State.NextToken->Children[0].MustBreakBefore)) + !isTrailingComment(*State.NextToken)) return true; if ((State.NextToken->Type == TT_CtorInitializerColon || (State.NextToken->Parent->ClosesTemplateDeclaration && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 3b52569..5b99716 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1919,11 +1919,12 @@ TEST_F(FormatTest, BlockComments) { EXPECT_EQ("someFunction(1, /* comment 1 */\n" " 2, /* comment 2 */\n" " 3, /* comment 3 */\n" - " aaaa);", + " aaaa,\n" + " bbbb);", format("someFunction (1, /* comment 1 */\n" " 2, /* comment 2 */ \n" " 3, /* comment 3 */\n" - "aaaa );", getGoogleStyle())); + "aaaa, bbbb );", getGoogleStyle())); } TEST_F(FormatTest, FormatStarDependingOnContext) { -- 2.7.4