diff options
author | Daniel Jasper <djasper@google.com> | 2013-02-24 18:54:32 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-02-24 18:54:32 +0000 |
commit | 3c08a818a6ac9115fe8880af9bbf5a0a87bdffaa (patch) | |
tree | 71d8f4b480a6ebe59924a08aee7323aa08318d60 /lib/Format/Format.cpp | |
parent | 960876cd88a9aba546345dec49a1cf9a4f248356 (diff) |
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) {}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175999 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r-- | lib/Format/Format.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index d8784c126e..60fe957a12 100644 --- a/lib/Format/Format.cpp +++ b/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; |