Re: [PATCH] D13811: [clang-format] AllowShortFunctionsOnASingleLine: true/Empty didn't work with BreakBeforeBraces: Linux/Allman.

2015-11-09 Thread Marek Kurdej via cfe-commits
curdeius added a comment.

Ping?


http://reviews.llvm.org/D13811



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13811: [clang-format] AllowShortFunctionsOnASingleLine: true/Empty didn't work with BreakBeforeBraces: Linux/Allman.

2015-10-20 Thread Marek Kurdej via cfe-commits
curdeius updated this revision to Diff 37832.
curdeius added a comment.

- AllowShortFunctionsOnASingleLine: true didn't work with BreakBeforeBraces: 
Linux/Allman.
- Add test checking that non-empty functions in styles with 
`BraceWrapping.AfterFunction = true` don't get merged into one line. Fix the 
merge condition.


http://reviews.llvm.org/D13811

Files:
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6518,6 +6518,21 @@
"  return 42;\n"
"}",
MergeInlineOnly);
+
+  FormatStyle MergeEmptyCustom = getLLVMStyle();
+  MergeEmptyCustom.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
+  MergeEmptyCustom.BreakBeforeBraces = FormatStyle::BS_Custom;
+  MergeEmptyCustom.BraceWrapping.AfterFunction = true;
+  verifyFormat("class C {\n"
+   "  int f() {}\n"
+   "};",
+   MergeEmptyCustom);
+  verifyFormat("int f() {}", MergeEmptyCustom);
+  verifyFormat("int f()\n"
+   "{\n"
+   "  return 0;\n"
+   "}",
+   MergeEmptyCustom);
 }
 
 TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -185,14 +185,18 @@
 ? 0
 : Limit - TheLine->Last->TotalLength;
 
+bool EmptyFunction =
+(Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty) &&
+(((Style.BraceWrapping.AfterFunction && (I + 2 != E)) ? I[2] : I[1])
+ ->First->is(tok::r_brace));
 // FIXME: TheLine->Level != 0 might or might not be the right check to do.
 // If necessary, change to something smarter.
+bool InlineFunction =
+(Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline) &&
+(TheLine->Level != 0);
 bool MergeShortFunctions =
 Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All ||
-(Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty &&
- I[1]->First->is(tok::r_brace)) ||
-(Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline &&
- TheLine->Level != 0);
+EmptyFunction || InlineFunction;
 
 if (TheLine->Last->is(TT_FunctionLBrace) &&
 TheLine->First != TheLine->Last) {


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6518,6 +6518,21 @@
"  return 42;\n"
"}",
MergeInlineOnly);
+
+  FormatStyle MergeEmptyCustom = getLLVMStyle();
+  MergeEmptyCustom.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
+  MergeEmptyCustom.BreakBeforeBraces = FormatStyle::BS_Custom;
+  MergeEmptyCustom.BraceWrapping.AfterFunction = true;
+  verifyFormat("class C {\n"
+   "  int f() {}\n"
+   "};",
+   MergeEmptyCustom);
+  verifyFormat("int f() {}", MergeEmptyCustom);
+  verifyFormat("int f()\n"
+   "{\n"
+   "  return 0;\n"
+   "}",
+   MergeEmptyCustom);
 }
 
 TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -185,14 +185,18 @@
 ? 0
 : Limit - TheLine->Last->TotalLength;
 
+bool EmptyFunction =
+(Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty) &&
+(((Style.BraceWrapping.AfterFunction && (I + 2 != E)) ? I[2] : I[1])
+ ->First->is(tok::r_brace));
 // FIXME: TheLine->Level != 0 might or might not be the right check to do.
 // If necessary, change to something smarter.
+bool InlineFunction =
+(Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline) &&
+(TheLine->Level != 0);
 bool MergeShortFunctions =
 Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All ||
-(Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty &&
- I[1]->First->is(tok::r_brace)) ||
-(Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline &&
- TheLine->Level != 0);
+EmptyFunction || InlineFunction;
 
 if (TheLine->Last->is(TT_FunctionLBrace) &&
 TheLine->First != TheLine->Last) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits