[cfe-commits] r171961 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp
Daniel Jasper
djasper at google.com
Wed Jan 9 01:33:39 PST 2013
Author: djasper
Date: Wed Jan 9 03:33:39 2013
New Revision: 171961
URL: http://llvm.org/viewvc/llvm-project?rev=171961&view=rev
Log:
Allow comments in the middle of statements to be on their own line.
This fixes llvm.org/PR14860.
Before, we messed up the format of:
if (DeclaratorInfo.isFunctionDeclarator() &&
//getDeclSpecContextFromDeclaratorContext(Context) == DSC_top_level &&
Tok.is(tok::semi) && NextToken().is(tok::l_brace)) {
}
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=171961&r1=171960&r2=171961&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan 9 03:33:39 2013
@@ -1062,8 +1062,10 @@
if (Left.is(tok::equal) && CurrentLineType == LT_VirtualFunctionDecl)
return false;
+ if (Right.is(tok::comment))
+ return !Right.Children.empty();
if (Right.is(tok::r_paren) || Right.is(tok::l_brace) ||
- Right.is(tok::comment) || Right.is(tok::greater))
+ Right.is(tok::greater))
return false;
return (isBinaryOperator(Left) && Left.isNot(tok::lessless)) ||
Left.is(tok::comma) || Right.is(tok::lessless) ||
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171961&r1=171960&r2=171961&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 9 03:33:39 2013
@@ -290,6 +290,9 @@
verifyFormat(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; // Trailing comment");
+ verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
+ " // Comment inside a statement.\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");
EXPECT_EQ("int i; // single line trailing comment",
format("int i;\\\n// single line trailing comment"));
More information about the cfe-commits
mailing list