Hi djasper, Format @synchronized properly for the Attach brace style by recognizing @synchronized similar to 'while'. Doing this triggers the SpaceBeforeParens rule, so introduce SpaceBeforeObjCSynchronizedParens to permit the old style. (SpaceBeforeObjCSynchronizedParens: false, the default, means use the old behaviour.)
http://reviews.llvm.org/D10371 Files: docs/ClangFormatStyleOptions.rst include/clang/Format/Format.h lib/Format/Format.cpp lib/Format/FormatToken.h 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 @@ -419,6 +419,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 @@ -401,6 +401,9 @@ /// \brief Defines in which cases to put a space before opening parentheses. SpaceBeforeParensOptions SpaceBeforeParens; + /// \brief Defines in which cases to put a space before opening parentheses. + bool ObjCSpaceAfterSynchronized; + /// \brief If \c false, spaces will be removed before assignment operators. bool SpaceBeforeAssignmentOperators; @@ -490,6 +493,7 @@ SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses && SpaceAfterCStyleCast == R.SpaceAfterCStyleCast && SpaceBeforeParens == R.SpaceBeforeParens && + ObjCSpaceAfterSynchronized == R.ObjCSpaceAfterSynchronized && SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators && ContinuationIndentWidth == R.ContinuationIndentWidth && CommentPragmas == R.CommentPragmas && Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -265,6 +265,8 @@ IO.mapOptional("DerivePointerBinding", Style.DerivePointerAlignment); } IO.mapOptional("SpaceBeforeParens", Style.SpaceBeforeParens); + IO.mapOptional("ObjCSpaceAfterSynchronized", + Style.ObjCSpaceAfterSynchronized); IO.mapOptional("DisableFormat", Style.DisableFormat); } }; @@ -381,6 +383,7 @@ LLVMStyle.SpacesInCStyleCastParentheses = false; LLVMStyle.SpaceAfterCStyleCast = false; LLVMStyle.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements; + LLVMStyle.ObjCSpaceAfterSynchronized = false; LLVMStyle.SpaceBeforeAssignmentOperators = true; LLVMStyle.SpacesInAngles = false; Index: lib/Format/FormatToken.h =================================================================== --- lib/Format/FormatToken.h +++ lib/Format/FormatToken.h @@ -284,6 +284,9 @@ bool is(const IdentifierInfo *II) const { return II && II == Tok.getIdentifierInfo(); } + bool is(clang::tok::ObjCKeywordKind Kind) const { + return Tok.getObjCKeywordID() == Kind; + } template <typename A, typename B> bool isOneOf(A K1, B K2) const { return is(K1) || is(K2); } 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; @@ -1846,6 +1847,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.
_______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits