From 45c4812851436ea3e762b0ac2fc3102c8ee48fa0 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 28 Jun 2015 01:06:16 +0000 Subject: [PATCH] clang-format: Support @autoreleasepool. Format @autoreleasepool properly for the Attach brace style by recognizing @autoreleasepool as a block introducer. Patch from Strager Neds! http://reviews.llvm.org/D10372 llvm-svn: 240896 --- clang/lib/Format/UnwrappedLineParser.cpp | 10 ++++++++++ clang/unittests/Format/FormatTest.cpp | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index ea1ca39..72652a7 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -656,6 +656,16 @@ void UnwrappedLineParser::parseStructuralElement() { nextToken(); addUnwrappedLine(); return; + case tok::objc_autoreleasepool: + nextToken(); + if (FormatTok->Tok.is(tok::l_brace)) { + if (Style.BreakBeforeBraces == FormatStyle::BS_Allman || + Style.BreakBeforeBraces == FormatStyle::BS_GNU) + addUnwrappedLine(); + parseBlock(/*MustBeDeclaration=*/false); + } + addUnwrappedLine(); + return; case tok::objc_try: // This branch isn't strictly necessary (the kw_try case below would // do this too after the tok::at is parsed above). But be explicit. diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index ed2658b..445b5a94 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2391,6 +2391,27 @@ TEST_F(FormatTest, FormatObjCTryCatch) { "});\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, StaticInitializers) { verifyFormat("static SomeClass SC = {1, 'a'};"); -- 2.7.4