diff options
| author | Daniel Jasper <djasper@google.com> | 2013-11-07 17:52:51 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-11-07 17:52:51 +0000 |
| commit | 4fcc8b91ebdeffbb1e2af531d9f5c8c6ae794939 (patch) | |
| tree | 9f77798ea43b5546a3b64ee5d26217de3819c260 /clang/lib/Format/TokenAnnotator.cpp | |
| parent | bc5cb4e369088a94da2a515b73b6d0d7e0495043 (diff) | |
| download | bcm5719-llvm-4fcc8b91ebdeffbb1e2af531d9f5c8c6ae794939.tar.gz bcm5719-llvm-4fcc8b91ebdeffbb1e2af531d9f5c8c6ae794939.zip | |
clang-format: Improve formatting of constructor initializers.
Before:
Constructor()
: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa(aaaa,
aaaa)) {}
After:
Constructor()
: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaa(aaaa, aaaa)) {}
llvm-svn: 194210
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index f18627ef581..757d3012b63 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1056,6 +1056,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { if (!Line.First->Next) return; FormatToken *Current = Line.First->Next; + bool InFunctionDecl = Line.MightBeFunctionDecl; while (Current != NULL) { if (Current->Type == TT_LineComment) Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments; @@ -1075,11 +1076,15 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { Current->TotalLength = Current->Previous->TotalLength + Current->ColumnWidth + Current->SpacesRequiredBefore; + + if (Current->Type == TT_CtorInitializerColon) + InFunctionDecl = false; + // FIXME: Only calculate this if CanBreakBefore is true once static // initializers etc. are sorted out. // FIXME: Move magic numbers to a better place. - Current->SplitPenalty = - 20 * Current->BindingStrength + splitPenalty(Line, *Current); + Current->SplitPenalty = 20 * Current->BindingStrength + + splitPenalty(Line, *Current, InFunctionDecl); Current = Current->Next; } @@ -1116,7 +1121,8 @@ void TokenAnnotator::calculateUnbreakableTailLengths(AnnotatedLine &Line) { } unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, - const FormatToken &Tok) { + const FormatToken &Tok, + bool InFunctionDecl) { const FormatToken &Left = *Tok.Previous; const FormatToken &Right = Tok; @@ -1132,7 +1138,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, return 3; if (Left.Type == TT_StartOfName) return 20; - if (Line.MightBeFunctionDecl && Right.BindingStrength == 1) + if (InFunctionDecl && Right.BindingStrength == 1) // FIXME: Clean up hack of using BindingStrength to find top-level names. return Style.PenaltyReturnTypeOnItsOwnLine; return 200; @@ -1174,7 +1180,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr) return 20; - if (Left.is(tok::l_paren) && Line.MightBeFunctionDecl) + if (Left.is(tok::l_paren) && InFunctionDecl) return 100; if (Left.opensScope()) return Left.ParameterCount > 1 ? Style.PenaltyBreakBeforeFirstCallParameter |

