r181877 - Break function declarations after multi-line return types.
Daniel Jasper
djasper at google.com
Wed May 15 02:35:08 PDT 2013
Author: djasper
Date: Wed May 15 04:35:08 2013
New Revision: 181877
URL: http://llvm.org/viewvc/llvm-project?rev=181877&view=rev
Log:
Break function declarations after multi-line return types.
Before:
template <typename A>
SomeLoooooooooooooooooooooongType<
typename some_namespace::SomeOtherType<A>::Type> Function() {}
After:
template <typename A>
SomeLoooooooooooooooooooooongType<
typename some_namespace::SomeOtherType<A>::Type>
Function() {}
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=181877&r1=181876&r2=181877&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed May 15 04:35:08 2013
@@ -504,6 +504,8 @@ private:
!State.Stack.back().AvoidBinPacking) ||
Previous.Type == TT_BinaryOperator)
State.Stack.back().BreakBeforeParameter = false;
+ if (Previous.Type == TT_TemplateCloser && State.ParenLevel == 0)
+ State.Stack.back().BreakBeforeParameter = false;
if (!DryRun) {
unsigned NewLines = 1;
@@ -531,6 +533,7 @@ private:
}
const AnnotatedToken *TokenBefore = Current.getPreviousNoneComment();
if (TokenBefore && !TokenBefore->isOneOf(tok::comma, tok::semi) &&
+ TokenBefore->Type != TT_TemplateCloser &&
TokenBefore->Type != TT_BinaryOperator && !TokenBefore->opensScope())
State.Stack.back().BreakBeforeParameter = true;
@@ -1017,6 +1020,10 @@ private:
getRemainingLength(State) + State.Column > getColumnLimit() &&
State.ParenLevel < State.StartOfLineLevel)
return true;
+
+ if (Current.Type == TT_StartOfName && Line.MightBeFunctionDecl &&
+ State.Stack.back().BreakBeforeParameter && State.ParenLevel == 0)
+ return true;
return false;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=181877&r1=181876&r2=181877&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed May 15 04:35:08 2013
@@ -2002,7 +2002,7 @@ TEST_F(FormatTest, FormatsBuilderPattern
" .StartsWith(\".eh_frame\", ORDER_EH_FRAME).StartsWith(\".init\", ORDER_INIT)\n"
" .StartsWith(\".fini\", ORDER_FINI).StartsWith(\".hash\", ORDER_HASH)\n"
" .Default(ORDER_TEXT);\n");
-
+
verifyFormat("return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa() <\n"
" aaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();");
verifyFormat(
@@ -2835,6 +2835,10 @@ TEST_F(FormatTest, BreaksLongDeclaration
" ReallyReallyLongParameterName,\n"
" const SomeType<string, SomeOtherTemplateParameter> &\n"
" AnotherLongParameterName) {}");
+ verifyFormat("template <typename A>\n"
+ "SomeLoooooooooooooooooooooongType<\n"
+ " typename some_namespace::SomeOtherType<A>::Type>\n"
+ "Function() {}");
verifyFormat(
"aaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaa<aaaaaaaaaaaaa, aaaaaaaaaaaa>\n"
" aaaaaaaaaaaaaaaaaaaaaaa;");
More information about the cfe-commits
mailing list