[PATCH] D16066: Add BeforeWhileInDoWhile BraceWrapping option

Eric Baker via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 11 07:38:12 PST 2016


ebaker355 updated this revision to Diff 44506.
ebaker355 added a comment.

Remove unintended blank line change.


http://reviews.llvm.org/D16066

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

Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9823,6 +9823,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterUnion);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeWhileInDoWhile);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
 }
 
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1472,7 +1472,10 @@
     parseStructuralElement();
     --Line->Level;
   }
-
+  if (FormatTok->Tok.is(tok::kw_while) &&
+      Style.BraceWrapping.BeforeWhileInDoWhile) {
+    addUnwrappedLine();
+  }
   // FIXME: Add error handling.
   if (!FormatTok->Tok.is(tok::kw_while)) {
     addUnwrappedLine();
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -347,6 +347,7 @@
     IO.mapOptional("AfterUnion", Wrapping.AfterUnion);
     IO.mapOptional("BeforeCatch", Wrapping.BeforeCatch);
     IO.mapOptional("BeforeElse", Wrapping.BeforeElse);
+    IO.mapOptional("BeforeWhileInDoWhile", Wrapping.BeforeWhileInDoWhile);
     IO.mapOptional("IndentBraces", Wrapping.IndentBraces);
   }
 };
@@ -418,7 +419,7 @@
     return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-                            false, false, false, false, false};
+                            false, false, false, false, false, false};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
     Expanded.BraceWrapping.AfterClass = true;
@@ -450,7 +451,7 @@
     break;
   case FormatStyle::BS_GNU:
     Expanded.BraceWrapping = {true, true, true, true, true, true,
-                              true, true, true, true, true};
+                              true, true, true, true, true, true};
     break;
   case FormatStyle::BS_WebKit:
     Expanded.BraceWrapping.AfterFunction = true;
@@ -487,7 +488,7 @@
   LLVMStyle.BreakBeforeTernaryOperators = true;
   LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
   LLVMStyle.BraceWrapping = {false, false, false, false, false, false,
-                             false, false, false, false, false};
+                             false, false, false, false, false, false};
   LLVMStyle.BreakConstructorInitializersBeforeComma = false;
   LLVMStyle.BreakAfterJavaFieldAnnotations = false;
   LLVMStyle.ColumnLimit = 80;
Index: include/clang/Format/Format.h
===================================================================
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -265,6 +265,8 @@
     bool BeforeCatch;
     /// \brief Wrap before \c else.
     bool BeforeElse;
+    /// \brief Wrap before \c while in do...while.
+    bool BeforeWhileInDoWhile;
     /// \brief Indent the wrapped braces themselves.
     bool IndentBraces;
   };
Index: docs/ClangFormatStyleOptions.rst
===================================================================
--- docs/ClangFormatStyleOptions.rst
+++ docs/ClangFormatStyleOptions.rst
@@ -324,6 +324,7 @@
   * ``bool AfterUnion`` Wrap union definitions.
   * ``bool BeforeCatch`` Wrap before ``catch``.
   * ``bool BeforeElse`` Wrap before ``else``.
+  * ``bool BeforeWhileInDoWhile`` Wrap before ``while`` in do...while.
   * ``bool IndentBraces`` Indent the wrapped braces themselves.
 
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16066.44506.patch
Type: text/x-patch
Size: 3635 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160111/6380c7e8/attachment.bin>


More information about the cfe-commits mailing list