r183851 - Preserve newlines before block comments in static initializers.
Alexander Kornienko
alexfh at google.com
Wed Jun 12 12:04:12 PDT 2013
Author: alexfh
Date: Wed Jun 12 14:04:12 2013
New Revision: 183851
URL: http://llvm.org/viewvc/llvm-project?rev=183851&view=rev
Log:
Preserve newlines before block comments in static initializers.
Summary:
Basically, don't special-case line comments in this regard. And fixed
an incorrect test, that relied on the wrong behavior.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D962
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.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=183851&r1=183850&r2=183851&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jun 12 14:04:12 2013
@@ -556,7 +556,7 @@ private:
if (!DryRun) {
unsigned NewLines = 1;
- if (Current.Type == TT_LineComment)
+ if (Current.is(tok::comment))
NewLines = std::max(
NewLines,
std::min(Current.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1));
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=183851&r1=183850&r2=183851&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Jun 12 14:04:12 2013
@@ -902,7 +902,7 @@ void TokenAnnotator::calculateFormatting
spaceRequiredBefore(Line, *Current) ? 1 : 0;
if (Current->MustBreakBefore) {
- } else if (Current->Type == TT_LineComment) {
+ } else if (Current->is(tok::comment)) {
Current->MustBreakBefore = Current->NewlinesBefore > 0;
} else if (Current->Previous->isTrailingComment() ||
(Current->is(tok::string_literal) &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=183851&r1=183850&r2=183851&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jun 12 14:04:12 2013
@@ -1181,11 +1181,20 @@ TEST_F(FormatTest, CommentsInStaticIniti
" // Comment after empty line\n"
" b\n"
"}"));
- EXPECT_EQ("S s = { a, b };", format("S s = {\n"
- " a,\n"
- "\n"
- " b\n"
- "};"));
+ EXPECT_EQ("S s = {\n"
+ " /* Some comment */\n"
+ " a,\n"
+ "\n"
+ " /* Comment after empty line */\n"
+ " b\n"
+ "}",
+ format("S s = {\n"
+ " /* Some comment */\n"
+ " a,\n"
+ " \n"
+ " /* Comment after empty line */\n"
+ " b\n"
+ "}"));
verifyFormat("const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = {\n"
" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
@@ -1530,6 +1539,11 @@ TEST_F(FormatTest, StaticInitializers) {
verifyFormat("static int LooooooooooooooooooooooooongVariable[1] = {\n"
" 100000000000000000000000\n"
"};");
+ EXPECT_EQ("S s = { a, b };", format("S s = {\n"
+ " a,\n"
+ "\n"
+ " b\n"
+ "};"));
// FIXME: This would fit into the column limit if we'd fit "{ {" on the first
// line. However, the formatting looks a bit off and this probably doesn't
@@ -3855,15 +3869,13 @@ TEST_F(FormatTest, BlockCommentsAtEndOfL
EXPECT_EQ("a = {\n"
" 1111 /* */\n"
"};",
- format("a = {1111\n"
- "/* */\n"
+ format("a = {1111 /* */\n"
"};",
getLLVMStyleWithColumns(15)));
EXPECT_EQ("a = {\n"
" 1111 /* */\n"
"};",
- format("a = {1111\n"
- "/* */\n"
+ format("a = {1111 /* */\n"
"};",
getLLVMStyleWithColumns(15)));
@@ -3872,8 +3884,7 @@ TEST_F(FormatTest, BlockCommentsAtEndOfL
" 1111 /* a\n"
" */\n"
"};",
- format("a = {1111\n"
- "/* a */\n"
+ format("a = {1111 /* a */\n"
"};",
getLLVMStyleWithColumns(15)));
}
More information about the cfe-commits
mailing list