summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-02-24 18:54:32 +0000
committerDaniel Jasper <djasper@google.com>2013-02-24 18:54:32 +0000
commit26d1b1db23babd59003f7c79219894b07fac32bb (patch)
tree604a09518c9025cdd36b0cec35e3290c4e5139ff /clang/lib/Format/Format.cpp
parentc68c6df88485b7521133103c848393b8a13842af (diff)
downloadbcm5719-llvm-26d1b1db23babd59003f7c79219894b07fac32bb.tar.gz
bcm5719-llvm-26d1b1db23babd59003f7c79219894b07fac32bb.zip
Allow breaking between a type and name in variable declarations.
This fixes llvm.org/PR14967 and is generall necessary to avoid situations where the column limit is exceeded. The challenge is restricting such lines splits, otherwise clang-format suddenly starts breaking at bad places. Before: ReallyLongReturnType<TemplateParam1, TemplateParam2> ReallyReallyLongFunctionName( const std::string &SomeParameter, const SomeType<string, SomeOtherTemplateParameter> &ReallyReallyLongParameterName, const SomeType<string, SomeOtherTemplateParameter> &AnotherLongParameterName) {} After: ReallyLongReturnType<TemplateParam1, TemplateParam2> ReallyReallyLongFunctionName( const std::string &SomeParameter, const SomeType<string, SomeOtherTemplateParameter> & ReallyReallyLongParameterName, const SomeType<string, SomeOtherTemplateParameter> & AnotherLongParameterName) {} llvm-svn: 175999
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp16
1 files changed, 5 insertions, 11 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d8784c126e6..60fe957a126 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -258,12 +258,6 @@ private:
tooling::Replacements Replaces;
};
-static bool isVarDeclName(const AnnotatedToken &Tok) {
- return Tok.Parent != NULL && Tok.is(tok::identifier) &&
- (Tok.Parent->Type == TT_PointerOrReference ||
- Tok.Parent->is(tok::identifier));
-}
-
class UnwrappedLineFormatter {
public:
UnwrappedLineFormatter(const FormatStyle &Style, SourceManager &SourceMgr,
@@ -498,8 +492,8 @@ private:
((RootToken.is(tok::kw_for) && State.ParenLevel == 1) ||
State.ParenLevel == 0)) {
State.Column = State.VariablePos;
- } else if (State.NextToken->Parent->ClosesTemplateDeclaration ||
- Current.Type == TT_StartOfName) {
+ } else if (Previous.ClosesTemplateDeclaration ||
+ (Current.Type == TT_StartOfName && State.ParenLevel == 0)) {
State.Column = State.Stack.back().Indent - 4;
} else if (Current.Type == TT_ObjCSelectorName) {
if (State.Stack.back().ColonPos > Current.FormatTok.TokenLength) {
@@ -510,7 +504,8 @@ private:
State.Stack.back().ColonPos =
State.Column + Current.FormatTok.TokenLength;
}
- } else if (Previous.Type == TT_ObjCMethodExpr || isVarDeclName(Current)) {
+ } else if (Previous.Type == TT_ObjCMethodExpr ||
+ Current.Type == TT_StartOfName) {
State.Column = State.Stack.back().Indent + 4;
} else {
State.Column = State.Stack.back().Indent;
@@ -551,8 +546,7 @@ private:
if (State.Stack.back().AvoidBinPacking) {
// If we are breaking after '(', '{', '<', this is not bin packing
// unless AllowAllParametersOfDeclarationOnNextLine is false.
- if ((Previous.isNot(tok::l_paren) && Previous.isNot(tok::l_brace) &&
- Previous.Type != TT_TemplateOpener) ||
+ if ((Previous.isNot(tok::l_paren) && Previous.isNot(tok::l_brace)) ||
(!Style.AllowAllParametersOfDeclarationOnNextLine &&
Line.MustBeDeclaration))
State.Stack.back().BreakBeforeParameter = true;
OpenPOWER on IntegriCloud