[PATCH] Implemented GNU-style formatting for compound statements.

Daniel Jasper djasper at google.com
Wed Dec 11 02:45:51 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
----------------
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.

================
Comment at: unittests/Format/FormatTest.cpp:6941
@@ +6940,3 @@
+  BreakBeforeBrace.BreakBeforeBraces = FormatStyle::BS_GNU;
+  verifyFormat("namespace a\n"
+               "{\n"
----------------
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;
    }
  }

================
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);
----------------
This exact part is repeated many times now. Can we pull it out into a function?

================
Comment at: unittests/Format/FormatTest.cpp:6939
@@ +6938,3 @@
+TEST_F(FormatTest, GNUBraceBreaking) {
+  FormatStyle BreakBeforeBrace = getLLVMStyle();
+  BreakBeforeBrace.BreakBeforeBraces = FormatStyle::BS_GNU;
----------------
nit: Maybe s/BreakBeforeBrace/GNUBraceStyle/


http://llvm-reviews.chandlerc.com/D2372



More information about the cfe-commits mailing list