Fix test diff on Phabricator.
http://reviews.llvm.org/D10371 Files: docs/ClangFormatStyleOptions.rst include/clang/Format/Format.h lib/Format/Format.cpp lib/Format/TokenAnnotator.cpp lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp EMAIL PREFERENCES http://reviews.llvm.org/settings/panel/emailpreferences/
Index: docs/ClangFormatStyleOptions.rst =================================================================== --- docs/ClangFormatStyleOptions.rst +++ docs/ClangFormatStyleOptions.rst @@ -417,6 +417,10 @@ Add a space after ``@property`` in Objective-C, i.e. use ``\@property (readonly)`` instead of ``\@property(readonly)``. +**ObjCSpaceAfterSynchronized** (``bool``) + Add a space after ``@synchronized`` in Objective-C, i.e. use + ``\@synchronized (lock)`` instead of ``\@synchronized(lock)``. + **ObjCSpaceBeforeProtocolList** (``bool``) Add a space in front of an Objective-C protocol list, i.e. use ``Foo <Protocol>`` instead of ``Foo<Protocol>``. Index: include/clang/Format/Format.h =================================================================== --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -226,6 +226,10 @@ /// <tt>\@property (readonly)</tt> instead of <tt>\@property(readonly)</tt>. bool ObjCSpaceAfterProperty; + /// Add a space after \c @synchronized in Objective-C, i.e. use + /// <tt>\@synchronized (lock)</tt> instead of <tt>\@synchronized(lock)</tt>. + bool ObjCSpaceAfterSynchronized; + /// \brief Add a space in front of an Objective-C protocol list, i.e. use /// <tt>Foo <Protocol></tt> instead of \c Foo<Protocol>. bool ObjCSpaceBeforeProtocolList; @@ -477,6 +481,7 @@ NamespaceIndentation == R.NamespaceIndentation && ObjCBlockIndentWidth == R.ObjCBlockIndentWidth && ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty && + ObjCSpaceAfterSynchronized == R.ObjCSpaceAfterSynchronized && ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList && PenaltyBreakComment == R.PenaltyBreakComment && PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess && Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -222,6 +222,8 @@ IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation); IO.mapOptional("ObjCBlockIndentWidth", Style.ObjCBlockIndentWidth); IO.mapOptional("ObjCSpaceAfterProperty", Style.ObjCSpaceAfterProperty); + IO.mapOptional("ObjCSpaceAfterSynchronized", + Style.ObjCSpaceAfterSynchronized); IO.mapOptional("ObjCSpaceBeforeProtocolList", Style.ObjCSpaceBeforeProtocolList); IO.mapOptional("PenaltyBreakBeforeFirstCallParameter", @@ -369,6 +371,7 @@ LLVMStyle.NamespaceIndentation = FormatStyle::NI_None; LLVMStyle.ObjCBlockIndentWidth = 2; LLVMStyle.ObjCSpaceAfterProperty = false; + LLVMStyle.ObjCSpaceAfterSynchronized = false; LLVMStyle.ObjCSpaceBeforeProtocolList = true; LLVMStyle.PointerAlignment = FormatStyle::PAS_Right; LLVMStyle.SpacesBeforeTrailingComments = 1; 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; @@ -1845,6 +1846,8 @@ (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch, tok::kw_new, tok::kw_delete) && (!Left.Previous || Left.Previous->isNot(tok::period))))) || + (Style.ObjCSpaceAfterSynchronized && + Left.is(tok::objc_synchronized)) || (Style.SpaceBeforeParens == FormatStyle::SBPO_Always && (Left.is(tok::identifier) || Left.isFunctionLikeKeyword() || Left.is(tok::r_paren)) && Line.Type != LT_PreprocessorDirective); Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -657,6 +657,18 @@ nextToken(); addUnwrappedLine(); return; + case tok::objc_synchronized: + nextToken(); + if (FormatTok->Tok.is(tok::l_paren)) + parseParens(); + 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. Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -2497,6 +2497,54 @@ "});\n"); } +TEST_F(FormatTest, FormatObjCSynchronized) { + FormatStyle Style = getLLVMStyleWithColumns(32); + EXPECT_FALSE(Style.ObjCSpaceAfterSynchronized); + Style.BreakBeforeBraces = FormatStyle::BS_Attach; + Style.ObjCSpaceAfterSynchronized = false; + verifyFormat("@synchronized(foo) {\n" + " f();\n" + "}\n", + Style); + verifyFormat("@synchronized([self\n" + " veryLongMethodNameWithParameters:\n" + " YES]) {\n" + " f();\n" + "}\n", + Style); + Style.BreakBeforeBraces = FormatStyle::BS_Attach; + Style.ObjCSpaceAfterSynchronized = true; + verifyFormat("@synchronized (foo) {\n" + " f();\n" + "}\n" + "@synchronized (foo) {\n" + " f();\n" + "}\n", + Style); + Style.BreakBeforeBraces = FormatStyle::BS_Allman; + Style.ObjCSpaceAfterSynchronized = false; + verifyFormat("@synchronized(foo)\n" + "{\n" + " f();\n" + "}\n" + "@synchronized(foo)\n" + "{\n" + " f();\n" + "}\n", + Style); + Style.BreakBeforeBraces = FormatStyle::BS_Allman; + Style.ObjCSpaceAfterSynchronized = true; + 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'};");
_______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits