kmensah created this revision. kmensah added a reviewer: djasper. kmensah added a subscriber: cfe-commits. kmensah set the repository for this revision to rL LLVM. Herald added a subscriber: klimek.
clang-format's current output: - (CGFloat)collectionView:(UICollectionView *)collectionView heightForHeaderWithLayout:(GPNCardCollectionViewLayout *)layout { } Output after patch: - (CGFloat)collectionView:(UICollectionView *)collectionView heightForHeaderWithLayout:(GPNCardCollectionViewLayout *)layout { } .clang-format contents BasedOnStyle: Google IndentWrappedFunctionNames: true ColumnLimit: 100 Repository: rL LLVM http://reviews.llvm.org/D11282 Files: lib/Format/ContinuationIndenter.cpp unittests/Format/FormatTest.cpp Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -7105,6 +7105,22 @@ " y:(id<yyyyyyyyyyyyyyyyyyyy>)y\n" " NS_DESIGNATED_INITIALIZER;", getLLVMStyleWithColumns(60)); + + // Continuation indent width should win over aligning colons if the function + // name is long. + FormatStyle continuationStyle = getGoogleStyle(); + continuationStyle.ColumnLimit = 40; + continuationStyle.IndentWrappedFunctionNames = true; + verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n" + " justongKeyword:(NSRect)theRect {\n" + "}", + continuationStyle); + + // Make sure we don't break aligning for short parameter names. + verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n" + " aShortf:(NSRect)theRect {\n" + "}", + continuationStyle); } TEST_F(FormatTest, FormatObjCMethodExpr) { Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -679,8 +679,13 @@ if (Current.isMemberAccess()) State.Stack.back().StartOfFunctionCall = Current.LastOperator ? 0 : State.Column; - if (Current.is(TT_SelectorName)) + if (Current.is(TT_SelectorName)) { State.Stack.back().ObjCSelectorNameFound = true; + if (Style.IndentWrappedFunctionNames) { + State.Stack.back().Indent = + State.FirstIndent + Style.ContinuationIndentWidth; + } + } if (Current.is(TT_CtorInitializerColon)) { // Indent 2 from the column, so: // SomeClass::SomeClass()
Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -7105,6 +7105,22 @@ " y:(id<yyyyyyyyyyyyyyyyyyyy>)y\n" " NS_DESIGNATED_INITIALIZER;", getLLVMStyleWithColumns(60)); + + // Continuation indent width should win over aligning colons if the function + // name is long. + FormatStyle continuationStyle = getGoogleStyle(); + continuationStyle.ColumnLimit = 40; + continuationStyle.IndentWrappedFunctionNames = true; + verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n" + " justongKeyword:(NSRect)theRect {\n" + "}", + continuationStyle); + + // Make sure we don't break aligning for short parameter names. + verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n" + " aShortf:(NSRect)theRect {\n" + "}", + continuationStyle); } TEST_F(FormatTest, FormatObjCMethodExpr) { Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -679,8 +679,13 @@ if (Current.isMemberAccess()) State.Stack.back().StartOfFunctionCall = Current.LastOperator ? 0 : State.Column; - if (Current.is(TT_SelectorName)) + if (Current.is(TT_SelectorName)) { State.Stack.back().ObjCSelectorNameFound = true; + if (Style.IndentWrappedFunctionNames) { + State.Stack.back().Indent = + State.FirstIndent + Style.ContinuationIndentWidth; + } + } if (Current.is(TT_CtorInitializerColon)) { // Indent 2 from the column, so: // SomeClass::SomeClass()
_______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits