r237241 - clang-format: [ObjC] Make IndentWrappedFunctionNames work with ObjC functions
Daniel Jasper
djasper at google.com
Wed May 13 02:38:25 PDT 2015
Author: djasper
Date: Wed May 13 04:38:25 2015
New Revision: 237241
URL: http://llvm.org/viewvc/llvm-project?rev=237241&view=rev
Log:
clang-format: [ObjC] Make IndentWrappedFunctionNames work with ObjC functions
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=237241&r1=237240&r2=237241&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed May 13 04:38:25 2015
@@ -421,7 +421,11 @@ unsigned ContinuationIndenter::addTokenO
State.Stack.back().AlignColons = false;
} else {
State.Stack.back().ColonPos =
- State.Stack.back().Indent + NextNonComment->LongestObjCSelectorName;
+ (Style.IndentWrappedFunctionNames
+ ? std::max(State.Stack.back().Indent,
+ State.FirstIndent + Style.ContinuationIndentWidth)
+ : State.Stack.back().Indent) +
+ NextNonComment->LongestObjCSelectorName;
}
} else if (State.Stack.back().AlignColons &&
State.Stack.back().ColonPos <= NextNonComment->ColumnWidth) {
@@ -572,7 +576,10 @@ unsigned ContinuationIndenter::getNewLin
if (!State.Stack.back().ObjCSelectorNameFound) {
if (NextNonComment->LongestObjCSelectorName == 0)
return State.Stack.back().Indent;
- return State.Stack.back().Indent +
+ return (Style.IndentWrappedFunctionNames
+ ? std::max(State.Stack.back().Indent,
+ State.FirstIndent + Style.ContinuationIndentWidth)
+ : State.Stack.back().Indent) +
NextNonComment->LongestObjCSelectorName -
NextNonComment->ColumnWidth;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=237241&r1=237240&r2=237241&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed May 13 04:38:25 2015
@@ -6863,6 +6863,21 @@ TEST_F(FormatTest, FormatForObjectiveCMe
" outRange8:(NSRange)out_range8\n"
" outRange9:(NSRange)out_range9;");
+ // When the function name has to be wrapped.
+ FormatStyle Style = getLLVMStyle();
+ Style.IndentWrappedFunctionNames = false;
+ verifyFormat("- (SomeLooooooooooooooooooooongType *)\n"
+ "veryLooooooooooongName:(NSString)aaaaaaaaaaaaaa\n"
+ " anotherName:(NSString)bbbbbbbbbbbbbb {\n"
+ "}",
+ Style);
+ Style.IndentWrappedFunctionNames = true;
+ verifyFormat("- (SomeLooooooooooooooooooooongType *)\n"
+ " veryLooooooooooongName:(NSString)aaaaaaaaaaaaaa\n"
+ " anotherName:(NSString)bbbbbbbbbbbbbb {\n"
+ "}",
+ Style);
+
verifyFormat("- (int)sum:(vector<int>)numbers;");
verifyGoogleFormat("- (void)setDelegate:(id<Protocol>)delegate;");
// FIXME: In LLVM style, there should be a space in front of a '<' for ObjC
More information about the cfe-commits
mailing list