ghvg1313 updated this revision to Diff 232177. ghvg1313 marked an inline comment as done. ghvg1313 added a comment.
- Move documents from release notes to header and proper rst, register test Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D70926/new/ https://reviews.llvm.org/D70926 Files: clang/docs/ClangFormatStyleOptions.rst clang/docs/ReleaseNotes.rst clang/include/clang/Format/Format.h clang/lib/Format/ContinuationIndenter.cpp clang/lib/Format/Format.cpp clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -12548,6 +12548,7 @@ CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks); CHECK_PARSE_BOOL(ObjCSpaceAfterProperty); CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList); + CHECK_PARSE_BOOL(ObjCBreakBeforeNestedBlockParam); CHECK_PARSE_BOOL(Cpp11BracedListStyle); CHECK_PARSE_BOOL(ReflowComments); CHECK_PARSE_BOOL(SortIncludes); @@ -14444,6 +14445,29 @@ verifyFormat("include \"a.td\"\ninclude \"b.td\"", Style); } +TEST_F(FormatTest, DoNotBreakLineBeforeNestedBlockParam) { + FormatStyle Style = getLLVMStyle(); + Style.ObjCBreakBeforeNestedBlockParam = false; + Style.ColumnLimit = 0; + + verifyFormat("[self.test1 t:self callback:^(typeof(self) self, " \ + "NSNumber *u, NSNumber *v) {\n u = v;\n}]", Style); + + verifyFormat("[self.test1 t:self w:self callback:^(typeof(self) self, " \ + "NSNumber *u, NSNumber *v) {\n u = v;\n}]", Style); + + verifyFormat("[self.test1 t:self w:self callback:^(typeof(self) self, " \ + "NSNumber *u, NSNumber *v) {\n u = c;\n} w:self " \ + "callback2:^(typeof(self) self, NSNumber *a, NSNumber *b, " \ + "NSNumber *c) {\n b = c;\n}]", Style); + + Style.ColumnLimit = 80; + verifyFormat("[self.test_method a:self b:self\n" \ + " callback:^(typeof(self) self, NSNumber *u, " \ + "NSNumber *v) {\n" \ + " u = v;\n" \" }]", Style); +} + TEST_F(FormatTest, ArrayOfTemplates) { EXPECT_EQ("auto a = new unique_ptr<int>[10];", format("auto a = new unique_ptr<int > [ 10];")); Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -497,6 +497,8 @@ IO.mapOptional("NamespaceMacros", Style.NamespaceMacros); IO.mapOptional("ObjCBinPackProtocolList", Style.ObjCBinPackProtocolList); IO.mapOptional("ObjCBlockIndentWidth", Style.ObjCBlockIndentWidth); + IO.mapOptional("ObjCBreakBeforeNestedBlockParam", + Style.ObjCBreakBeforeNestedBlockParam); IO.mapOptional("ObjCSpaceAfterProperty", Style.ObjCSpaceAfterProperty); IO.mapOptional("ObjCSpaceBeforeProtocolList", Style.ObjCSpaceBeforeProtocolList); @@ -792,6 +794,7 @@ LLVMStyle.NamespaceIndentation = FormatStyle::NI_None; LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto; LLVMStyle.ObjCBlockIndentWidth = 2; + LLVMStyle.ObjCBreakBeforeNestedBlockParam = true; LLVMStyle.ObjCSpaceAfterProperty = false; LLVMStyle.ObjCSpaceBeforeProtocolList = true; LLVMStyle.PointerAlignment = FormatStyle::PAS_Right; Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -1380,7 +1380,8 @@ (!BinPackInconclusiveFunctions && Current.PackingKind == PPK_Inconclusive))); - if (Current.is(TT_ObjCMethodExpr) && Current.MatchingParen) { + if (Current.is(TT_ObjCMethodExpr) && Current.MatchingParen && + Style.ObjCBreakBeforeNestedBlockParam) { if (Style.ColumnLimit) { // If this '[' opens an ObjC call, determine whether all parameters fit // into one line and put one per line if they don't. Index: clang/include/clang/Format/Format.h =================================================================== --- clang/include/clang/Format/Format.h +++ clang/include/clang/Format/Format.h @@ -1646,6 +1646,28 @@ /// ``@property (readonly)`` instead of ``@property(readonly)``. bool ObjCSpaceAfterProperty; + /// Break parameters list into lines when there is nested block + /// parameters in a fuction call. + /// \code + /// false: + /// - (void)_aMethod + /// { + /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber *u, NSNumber *v) { + /// u = c; + /// }] + /// } + /// true: + /// - (void)_aMethod + /// { + /// [self.test1 t:self + /// w:self + /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) { + /// u = c; + /// }] + /// } + /// \endcode + bool ObjCBreakBeforeNestedBlockParam; + /// Add a space in front of an Objective-C protocol list, i.e. use /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``. bool ObjCSpaceBeforeProtocolList; @@ -2126,6 +2148,7 @@ NamespaceMacros == R.NamespaceMacros && ObjCBinPackProtocolList == R.ObjCBinPackProtocolList && ObjCBlockIndentWidth == R.ObjCBlockIndentWidth && + ObjCBreakBeforeNestedBlockParam == R.ObjCBreakBeforeNestedBlockParam && ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty && ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList && PenaltyBreakAssignment == R.PenaltyBreakAssignment && Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -337,6 +337,9 @@ int a [5]; vs int a[5]; +- Option ``ObjCBreakBeforeNestedBlockParam`` has been added to optionally apply + linebreaks for function arguments declarations before nested blocks. + - Clang-format now supports JavaScript null operators. .. code-block:: c++ Index: clang/docs/ClangFormatStyleOptions.rst =================================================================== --- clang/docs/ClangFormatStyleOptions.rst +++ clang/docs/ClangFormatStyleOptions.rst @@ -1993,6 +1993,29 @@ [self onOperationDone]; }]; +**ObjCBreakBeforeNestedBlockParam** (``bool``) + Break parameters list into lines when there is nested block + parameters in a fuction call. + + .. code-block:: c++ + + false: + - (void)_aMethod + { + [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber *u, NSNumber *v) { + u = c; + }] + } + true: + - (void)_aMethod + { + [self.test1 t:self + w:self + callback:^(typeof(self) self, NSNumber *u, NSNumber *v) { + u = c; + }] + } + **ObjCSpaceAfterProperty** (``bool``) Add a space after ``@property`` in Objective-C, i.e. use ``@property (readonly)`` instead of ``@property(readonly)``.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits