strager updated this revision to Diff 34957. strager added a comment. Rebase. Fix style issues.
http://reviews.llvm.org/D10371 Files: lib/Format/TokenAnnotator.cpp lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp
Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -2419,6 +2419,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'};"); @@ -8373,6 +8397,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); @@ -8408,6 +8436,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" @@ -8460,6 +8492,10 @@ " break;\n" "}", Spaces); + verifyFormat("@synchronized( x ) {\n" + " do_something();\n" + "}", + Spaces); Spaces.SpacesInParentheses = false; Spaces.SpacesInCStyleCastParentheses = true; @@ -8497,6 +8533,10 @@ " break;\n" "}", Spaces); + verifyFormat("@synchronized(x) {\n" + " do_something( );\n" + "}", + Spaces); // Run the first set of tests again with: Spaces.SpaceAfterCStyleCast = true; @@ -8523,6 +8563,10 @@ " break;\n" "}", Spaces); + verifyFormat("@synchronized(x) {\n" + " do_something( );\n" + "}", + Spaces); // Run subset of tests again with: Spaces.SpacesInCStyleCastParentheses = false; @@ -8534,6 +8578,10 @@ " do_something((int) i);\n" "} while (something( ));", Spaces); + verifyFormat("@synchronized((NSLock) x) {\n" + " do_something( );\n" + "}", + Spaces); } TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) { Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -679,8 +679,12 @@ addUnwrappedLine(); return; case tok::objc_autoreleasepool: + case tok::objc_synchronized: nextToken(); - if (FormatTok->Tok.is(tok::l_brace)) { + if (FormatTok->is(tok::l_paren)) { + parseParens(); + } + if (FormatTok->is(tok::l_brace)) { if (Style.BreakBeforeBraces == FormatStyle::BS_Allman || Style.BreakBeforeBraces == FormatStyle::BS_GNU) addUnwrappedLine(); Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -122,7 +122,7 @@ if (Left->Previous && (Left->Previous->isOneOf(tok::kw_static_assert, tok::kw_decltype, tok::kw_if, tok::kw_while, tok::l_paren, - tok::comma) || + tok::comma, Keywords.kw_synchronized) || Left->Previous->is(TT_BinaryOperator))) { // static_assert, if and while usually contain expressions. Contexts.back().IsExpression = true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits