[PATCH] clang-format: Support @autoreleasepool.

strager strager.nds at gmail.com
Thu Jun 25 19:00:19 PDT 2015


Merge autoreleasepool and synchronized cases.


http://reviews.llvm.org/D10372

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

Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -656,10 +656,13 @@
       nextToken();
       addUnwrappedLine();
       return;
+    case tok::objc_autoreleasepool:
     case tok::objc_synchronized:
       nextToken();
-      if (FormatTok->Tok.is(tok::l_paren))
+      if (FormatTok->Tok.is(tok::l_paren)) {
+        // @synchronized
         parseParens();
+      }
       if (FormatTok->Tok.is(tok::l_brace)) {
         if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
             Style.BreakBeforeBraces == FormatStyle::BS_GNU)
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2391,6 +2391,27 @@
                "});\n");
 }
 
+TEST_F(FormatTest, FormatObjCAutoreleasepool) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("@autoreleasepool {\n"
+               "  f();\n"
+               "}\n"
+               "@autoreleasepool {\n"
+               "  f();\n"
+               "}\n",
+               Style);
+  Style.BreakBeforeBraces = FormatStyle::BS_Allman;
+  verifyFormat("@autoreleasepool\n"
+               "{\n"
+               "  f();\n"
+               "}\n"
+               "@autoreleasepool\n"
+               "{\n"
+               "  f();\n"
+               "}\n",
+               Style);
+}
+
 TEST_F(FormatTest, FormatObjCSynchronized) {
   FormatStyle Style = getLLVMStyleWithColumns(32);
   EXPECT_FALSE(Style.ObjCSpaceAfterSynchronized);

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10372.28523.patch
Type: text/x-patch
Size: 1655 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150626/de7b08b6/attachment.bin>


More information about the cfe-commits mailing list