Rebase.
http://reviews.llvm.org/D10371 Files: lib/Format/TokenAnnotator.cpp lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp EMAIL PREFERENCES http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -121,7 +121,8 @@ if (Left->Previous && (Left->Previous->isOneOf(tok::kw_static_assert, tok::kw_if, - tok::kw_while, tok::l_paren, tok::comma) || + tok::kw_while, tok::l_paren, tok::comma, + tok::objc_synchronized) || Left->Previous->is(TT_BinaryOperator))) { // static_assert, if and while usually contain expressions. Contexts.back().IsExpression = true; Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -657,7 +657,12 @@ addUnwrappedLine(); return; case tok::objc_autoreleasepool: + case tok::objc_synchronized: nextToken(); + 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 @@ -2412,6 +2412,30 @@ Style); } +TEST_F(FormatTest, FormatObjCSynchronized) { + FormatStyle Style = getLLVMStyleWithColumns(32); + verifyFormat("@synchronized(foo) {\n" + " f();\n" + "}\n", + Style); + verifyFormat("@synchronized([self\n" + " veryLongMethodNameWithParameters:\n" + " YES]) {\n" + " f();\n" + "}\n", + Style); + Style.BreakBeforeBraces = FormatStyle::BS_Allman; + verifyFormat("@synchronized(foo)\n" + "{\n" + " f();\n" + "}\n" + "@synchronized(foo)\n" + "{\n" + " f();\n" + "}\n", + Style); +} + TEST_F(FormatTest, StaticInitializers) { verifyFormat("static SomeClass SC = {1, 'a'};"); @@ -8169,6 +8193,10 @@ " break;\n" "}", NoSpace); + verifyFormat("@synchronized(x) {\n" + " do_something();\n" + "}", + NoSpace); verifyFormat("auto i = std::make_unique<int>(5);", NoSpace); verifyFormat("size_t x = sizeof(x);", NoSpace); verifyFormat("auto f(int x) -> decltype(x);", NoSpace); @@ -8202,6 +8230,10 @@ " break;\n" "}", Space); + verifyFormat("@synchronized (x) {\n" + " do_something ();\n" + "}", + Space); verifyFormat("A::A () : a (1) {}", Space); verifyFormat("void f () __attribute__ ((asdf));", Space); verifyFormat("*(&a + 1);\n" @@ -8252,6 +8284,10 @@ " break;\n" "}", Spaces); + verifyFormat("@synchronized( x ) {\n" + " do_something();\n" + "}", + Spaces); Spaces.SpacesInParentheses = false; Spaces.SpacesInCStyleCastParentheses = true; @@ -8289,6 +8325,10 @@ " break;\n" "}", Spaces); + verifyFormat("@synchronized(x) {\n" + " do_something( );\n" + "}", + Spaces); // Run the first set of tests again with: Spaces.SpaceAfterCStyleCast = true; @@ -8315,6 +8355,10 @@ " break;\n" "}", Spaces); + verifyFormat("@synchronized(x) {\n" + " do_something( );\n" + "}", + Spaces); // Run subset of tests again with: Spaces.SpacesInCStyleCastParentheses = false; @@ -8326,6 +8370,10 @@ " do_something((int) i);\n" "} while (something( ));", Spaces); + verifyFormat("@synchronized((NSLock) x) {\n" + " do_something( );\n" + "}", + Spaces); } TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
_______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits