[PATCH] D19063: clang-format: Fixed line merging of more than two lines
Maxime Beaulieu via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 13 09:10:12 PDT 2016
mxbOctasic created this revision.
mxbOctasic added a reviewer: djasper.
mxbOctasic added subscribers: cameron314, cfe-commits.
Herald added a subscriber: klimek.
`getNextMergedLine` merged pairs of adjacent lines instead of merging them all with the first one.
Consider `AnnotatedLine` `A`, `B` and `C`.
The function merges `A` with `B` then `B` with `C` and returns a pointer to `A`.
`A.Last` is not updated when `B` and `C` are merged together. (`A.Last == B.Last`)
Subsequent lines need to be merged with the first.
By merging `A` with `B` then with `C`, `A.Last` points to the proper token. (`A.Last == C.Last`)
http://reviews.llvm.org/D19063
Files:
lib/Format/UnwrappedLineFormatter.cpp
unittests/Format/FormatTest.cpp
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -273,6 +273,30 @@
"int i;\n"
"\n"
"} // namespace"));
+
+ FormatStyle Style = getLLVMStyle();
+ Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
+ Style.MaxEmptyLinesToKeep = 2;
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+ Style.BraceWrapping.AfterClass = true;
+ Style.BraceWrapping.AfterFunction = true;
+ Style.KeepEmptyLinesAtTheStartOfBlocks = false;
+
+ EXPECT_EQ("class Foo\n"
+ "{\n"
+ " Foo() {}\n"
+ "\n"
+ " void funk() {}\n"
+ "};",
+ format("class Foo\n"
+ "{\n"
+ " Foo()\n"
+ " {\n"
+ " }\n"
+ "\n"
+ " void funk() {}\n"
+ "};",
+ Style));
}
TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) {
Index: lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -150,7 +150,7 @@
MergedLines = 0;
if (!DryRun)
for (unsigned i = 0; i < MergedLines; ++i)
- join(*Next[i], *Next[i + 1]);
+ join(*Next[0], *Next[i + 1]);
Next = Next + MergedLines + 1;
return Current;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19063.53572.patch
Type: text/x-patch
Size: 1559 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160413/0e7169d7/attachment-0001.bin>
More information about the cfe-commits
mailing list