Add BeforeWhileInDoWhile BraceWrapping option

2016-01-10 Thread Eric Baker via cfe-commits
Code like this:

do {
// Some code
} while (1);

becomes:

do {
// Some code
}
while (1);

I couldn't think of a better name for the option than BeforeWhileInDoWhile.
I'm open to suggestions!

Also, this is my first attempt at submitting a patch for this project. If
I've done anything wrong, please let me know. Thanks!

--
Thanks,
Eric Baker


BreakBeforeWhileInDoWhile.patch
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16066: Add BeforeWhileInDoWhile BraceWrapping option

2016-01-11 Thread Eric Baker via cfe-commits
ebaker355 created this revision.
ebaker355 added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Adds a new BraceWrapping option called BeforeWhileInDoWhile.

Code like this:

do {
// Some code
} while (1);

becomes:

do {
// Some code
}
while (1);

I couldn't think of a better name for the option than BeforeWhileInDoWhile. I'm 
open to suggestions!

Also, this is my first attempt at submitting a patch for this project. If I've 
done anything wrong, please let me know. Thanks!

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
@@ -6582,7 +6582,7 @@
"   b};");
 
   verifyNoCrash("a<,");
-  
+
   // No braced initializer here.
   verifyFormat("void f() {\n"
"  struct Dummy {};\n"
@@ -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.
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16066: Add BeforeWhileInDoWhile BraceWrapping option

2016-01-11 Thread Eric Baker via cfe-commits
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.
 
 


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

Re: [PATCH] D16066: [clang-format] Add BeforeWhileInDoWhile BraceWrapping option

2016-01-25 Thread Eric Baker via cfe-commits
ebaker355 added a comment.

Ping. Anyone have an opinion on this?


http://reviews.llvm.org/D16066



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


Re: [PATCH] D16066: [clang-format] Add BeforeWhileInDoWhile BraceWrapping option

2016-01-26 Thread Eric Baker via cfe-commits
ebaker355 added a comment.

Thanks for responding, and for the documentation link! It is certainly wise to 
not attempt "to supporting every single style used by a codebase somewhere in 
the wild."

I do not know of a predefined coding style that recommends this format. My 
thinking was:

- it complements the "else on new line" option
- I have seen other code formatters that offer this style option


http://reviews.llvm.org/D16066



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


Re: [PATCH] D16066: [clang-format] Add BeforeWhileInDoWhile BraceWrapping option

2016-01-26 Thread Eric Baker via cfe-commits
ebaker355 abandoned this revision.
ebaker355 added a comment.

Since I cannot meet these criteria:

- be used in a project of significant size (have dozens of contributors)
- have a publicly accessible style guide

I will abandon this revision request. Thank you for considering!


http://reviews.llvm.org/D16066



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


Re: [PATCH] D16066: [clang-format] Add BeforeWhileInDoWhile BraceWrapping option

2016-01-26 Thread Eric Baker via cfe-commits
ebaker355 reclaimed this revision.
ebaker355 added a comment.

Ok, cool! :) Thanks!


http://reviews.llvm.org/D16066



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