[PATCH] D68296: [clang-format] Add ability to wrap braces after multi-line control statements

Mitchell via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 2 13:55:59 PDT 2019


mitchell-stellar updated this revision to Diff 222907.
mitchell-stellar added a comment.

Renamed "OnlyMultiLine" option to "MultiLine", per reviewer request.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68296/new/

https://reviews.llvm.org/D68296

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1445,7 +1445,7 @@
 TEST_F(FormatTest, MultiLineControlStatements) {
   FormatStyle Style = getLLVMStyle();
   Style.BreakBeforeBraces = FormatStyle::BraceBreakingStyle::BS_Custom;
-  Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_OnlyMultiLine;
+  Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_MultiLine;
   Style.ColumnLimit = 20;
   // Short lines should keep opening brace on same line.
   EXPECT_EQ("if (foo) {\n"
@@ -12571,9 +12571,9 @@
 
   Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Never;
   CHECK_PARSE("BraceWrapping:\n"
-              "  AfterControlStatement: OnlyMultiLine",
+              "  AfterControlStatement: MultiLine",
               BraceWrapping.AfterControlStatement,
-              FormatStyle::BWACS_OnlyMultiLine);
+              FormatStyle::BWACS_MultiLine);
   CHECK_PARSE("BraceWrapping:\n"
               "  AfterControlStatement: Always",
               BraceWrapping.AfterControlStatement, FormatStyle::BWACS_Always);
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -311,7 +311,7 @@
          (TheLine->First->is(tok::r_brace) && TheLine->First->Next &&
           TheLine->First->Next->isOneOf(tok::kw_else, tok::kw_catch))) &&
         Style.BraceWrapping.AfterControlStatement ==
-            FormatStyle::BWACS_OnlyMultiLine) {
+            FormatStyle::BWACS_MultiLine) {
       // If possible, merge the next line's wrapped left brace with the current
       // line. Otherwise, leave it on the next line, as this is a multi-line
       // control statement.
@@ -624,7 +624,7 @@
         // }
         if (Line.First == Line.Last &&
             Style.BraceWrapping.AfterControlStatement ==
-                FormatStyle::BWACS_OnlyMultiLine)
+                FormatStyle::BWACS_MultiLine)
           return 0;
 
         return 2;
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -181,7 +181,7 @@
     IO.enumCase(Value, "false", FormatStyle::BWACS_Never);
     IO.enumCase(Value, "true", FormatStyle::BWACS_Always);
     IO.enumCase(Value, "Never", FormatStyle::BWACS_Never);
-    IO.enumCase(Value, "OnlyMultiLine", FormatStyle::BWACS_OnlyMultiLine);
+    IO.enumCase(Value, "MultiLine", FormatStyle::BWACS_MultiLine);
     IO.enumCase(Value, "Always", FormatStyle::BWACS_Always);
   }
 };
Index: clang/include/clang/Format/Format.h
===================================================================
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -803,7 +803,7 @@
     ///   while (foo || bar) {
     ///   }
     /// \endcode
-    BWACS_OnlyMultiLine,
+    BWACS_MultiLine,
     /// Always wrap braces after a control statement.
     /// \code
     ///   if (foo())
Index: clang/docs/ClangFormatStyleOptions.rst
===================================================================
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -794,7 +794,7 @@
         for (int i = 0; i < 10; ++i) {
         }
 
-    * ``BWACS_OnlyMultiLine`` (in configuration: ``OnlyMultiLine``)
+    * ``BWACS_MultiLine`` (in configuration: ``MultiLine``)
       Only wrap braces after a multi-line control statement.
 
       .. code-block:: c++


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68296.222907.patch
Type: text/x-patch
Size: 3686 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191002/378d0ab9/attachment.bin>


More information about the cfe-commits mailing list