[PATCH] D53197: [clang-format] Fix BraceWrapping AfterFunction for ObjC methods

Marcus Hultman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 12 07:33:32 PDT 2018


hultman created this revision.
Herald added a subscriber: cfe-commits.

> clang-format --version
>  clang-format version 7.0.0 (tags/RELEASE_700/final)
>  echo "@implementation Foo\n- (void)foo:(id)bar\n{\n}\n at end\n" |clang-format -style='{BreakBeforeBraces: Custom, BraceWrapping: {AfterFunction: true}}'

  @implementation Foo
  - (void)foo:(id)bar {
  }
  @end

with patch:

> bin/clang-format --version
>  clang-format version 8.0.0 (trunk 344285)
>  echo "@implementation Foo\n- (void)foo:(id)bar\n{\n}\n at end\n" |bin/clang-format -style='{BreakBeforeBraces: Custom, BraceWrapping: {AfterFunction: true}}'

  @implementation Foo
  - (void)foo:(id)bar
  {
  }
  @end


Repository:
  rC Clang

https://reviews.llvm.org/D53197

Files:
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===================================================================
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -584,6 +584,16 @@
                "             aaaaa:(a)yyy\n"
                "               bbb:(d)cccc;");
   verifyFormat("- (void)drawRectOn:(id)surface ofSize:(aaa)height:(bbb)width;");
+
+  // BraceWrapping AfterFunction is respected for ObjC methods 
+  Style = getGoogleStyle(FormatStyle::LK_ObjC);
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  verifyFormat("@implementation Foo\n"
+               "- (void)foo:(id)bar\n"
+               "{\n"
+               "}\n"
+               "@end\n");
 }
 
 TEST_F(FormatTestObjC, FormatObjCMethodExpr) {
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -2164,6 +2164,8 @@
       addUnwrappedLine();
       return;
     } else if (FormatTok->Tok.is(tok::l_brace)) {
+      if (Style.BraceWrapping.AfterFunction)
+        addUnwrappedLine();
       parseBlock(/*MustBeDeclaration=*/false);
       addUnwrappedLine();
       return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53197.169398.patch
Type: text/x-patch
Size: 1274 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181012/d7e7dac1/attachment.bin>


More information about the cfe-commits mailing list