r182608 - Fix aligning of comments.
Manuel Klimek
klimek at google.com
Thu May 23 13:46:07 PDT 2013
Author: klimek
Date: Thu May 23 15:46:07 2013
New Revision: 182608
URL: http://llvm.org/viewvc/llvm-project?rev=182608&view=rev
Log:
Fix aligning of comments.
Previously we started sequences to align for single line comments when
the previous line had a trailing comment, but the sequence was broken
for other reasons.
Now we re-format:
// a
// b
f(); // c
to:
// a
// b
f(); // c
Modified:
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=182608&r1=182607&r2=182608&view=diff
==============================================================================
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Thu May 23 15:46:07 2013
@@ -170,10 +170,11 @@ void WhitespaceManager::alignTrailingCom
MinColumn = std::max(MinColumn, ChangeMinColumn);
MaxColumn = std::min(MaxColumn, ChangeMaxColumn);
}
- BreakBeforeNext = (i == 0) || (Changes[i].NewlinesBefore > 1) ||
- (Changes[i].NewlinesBefore == 1 &&
- !Changes[i - 1].IsTrailingComment) ||
- WasAlignedWithStartOfNextLine;
+ BreakBeforeNext =
+ (i == 0) || (Changes[i].NewlinesBefore > 1) ||
+ // Never start a sequence with a comment at the beginning of
+ // the line.
+ (Changes[i].NewlinesBefore == 1 && StartOfSequence == i);
Newlines = 0;
}
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=182608&r1=182607&r2=182608&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu May 23 15:46:07 2013
@@ -657,6 +657,26 @@ TEST_F(FormatTest, UnderstandsSingleLine
format("lineWith(); // comment\n"
"// at start\n"
"otherLine(); // comment"));
+ EXPECT_EQ("lineWith();\n"
+ "// at start\n"
+ "otherLine(); // comment",
+ format("lineWith();\n"
+ " // at start\n"
+ "otherLine(); // comment"));
+ EXPECT_EQ("// first\n"
+ "// at start\n"
+ "otherLine(); // comment",
+ format("// first\n"
+ " // at start\n"
+ "otherLine(); // comment"));
+ EXPECT_EQ("f();\n"
+ "// first\n"
+ "// at start\n"
+ "otherLine(); // comment",
+ format("f();\n"
+ "// first\n"
+ " // at start\n"
+ "otherLine(); // comment"));
}
TEST_F(FormatTest, CanFormatCommentsLocally) {
More information about the cfe-commits
mailing list