r174314 - Improve handling of trailing block comments
Daniel Jasper
djasper at google.com
Mon Feb 4 00:34:58 PST 2013
Author: djasper
Date: Mon Feb 4 02:34:57 2013
New Revision: 174314
URL: http://llvm.org/viewvc/llvm-project?rev=174314&view=rev
Log:
Improve handling of trailing block comments
This is a follow up to r174309 to actually make it work.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=174314&r1=174313&r2=174314&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Feb 4 02:34:57 2013
@@ -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 &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=174314&r1=174313&r2=174314&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Feb 4 02:34:57 2013
@@ -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) {
More information about the cfe-commits
mailing list