[PATCH] Implemented GNU-style formatting for compound statements.
Alexander Kornienko
alexfh at google.com
Wed Dec 11 04:17:56 PST 2013
================
Comment at: include/clang/Format/Format.h:222-223
@@ +221,4 @@
+ BS_Allman,
+ /// Always break before braces and add an extra level of indentation to the
+ /// compound statements.
+ BS_GNU
----------------
Daniel Jasper wrote:
> Maybe be a little more detail here. Maybe:
>
> /// Always break before braces and add an extra level of indentation to
> /// braces of control statements, not to those of class, function
> /// or other definitions.
Yep, it's probably better.
================
Comment at: unittests/Format/FormatTest.cpp:6939
@@ +6938,3 @@
+TEST_F(FormatTest, GNUBraceBreaking) {
+ FormatStyle BreakBeforeBrace = getLLVMStyle();
+ BreakBeforeBrace.BreakBeforeBraces = FormatStyle::BS_GNU;
----------------
Daniel Jasper wrote:
> nit: Maybe s/BreakBeforeBrace/GNUBraceStyle/
Done.
================
Comment at: unittests/Format/FormatTest.cpp:6941
@@ +6940,3 @@
+ BreakBeforeBrace.BreakBeforeBraces = FormatStyle::BS_GNU;
+ verifyFormat("namespace a\n"
+ "{\n"
----------------
Daniel Jasper wrote:
> I think a (possibly interesting) missing case here is a bare compound statement, i.e. I think it needs to be:
>
> void f()
> {
> int a;
> {
> int b;
> }
> }
Added a test for this.
================
Comment at: lib/Format/UnwrappedLineParser.cpp:939-944
@@ -940,4 +938,8 @@
if (FormatTok->Tok.is(tok::l_brace)) {
- if (Style.BreakBeforeBraces == FormatStyle::BS_Allman)
+ if (Style.BreakBeforeBraces == FormatStyle::BS_Allman) {
addUnwrappedLine();
+ } else if (Style.BreakBeforeBraces == FormatStyle::BS_GNU) {
+ addUnwrappedLine();
+ ++Line->Level;
+ }
parseBlock(/*MustBeDeclaration=*/false);
----------------
Daniel Jasper wrote:
> This exact part is repeated many times now. Can we pull it out into a function?
Yeah, I was thinking about this...
Done.
http://llvm-reviews.chandlerc.com/D2372
More information about the cfe-commits
mailing list