Author: klimek
Date: Thu May 23 14:54:43 2013
New Revision: 182605
URL: http://llvm.org/viewvc/llvm-project?rev=182605&view=rev
Log:
Fix aligning of comments that are at the start of the line.
Now correctly leaves:
f(); // comment
// comment
g(); // comment
... alone if the middle comment was aligned with g() before formatting.
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=182605&r1=182604&r2=182605&view=diff
==============================================================================
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Thu May 23 14:54:43 2013
@@ -170,9 +170,10 @@ 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);
+ BreakBeforeNext = (i == 0) || (Changes[i].NewlinesBefore > 1) ||
+ (Changes[i].NewlinesBefore == 1 &&
+ !Changes[i - 1].IsTrailingComment) ||
+ WasAlignedWithStartOfNextLine;
Newlines = 0;
}
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=182605&r1=182604&r2=182605&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu May 23 14:54:43 2013
@@ -650,6 +650,13 @@ TEST_F(FormatTest, UnderstandsSingleLine
format("lineWith(); // comment\n"
" // at start\n"
"otherLine();"));
+
+ EXPECT_EQ("lineWith(); // comment\n"
+ "// at start\n"
+ "otherLine(); // comment",
+ format("lineWith(); // comment\n"
+ "// at start\n"
+ "otherLine(); // comment"));
}
TEST_F(FormatTest, CanFormatCommentsLocally) {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits