diff options
author | Daniel Jasper <djasper@google.com> | 2015-10-28 01:08:22 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-10-28 01:08:22 +0000 |
commit | a1036e5d081dd800c71bdbdf858908b99eed03a4 (patch) | |
tree | b35dd26dec1d3ae5090e6e51389e3c42670af6b3 /clang/lib/Format/UnwrappedLineFormatter.cpp | |
parent | f6bd01097a04635343c97818d157450a8df863b9 (diff) | |
download | bcm5719-llvm-a1036e5d081dd800c71bdbdf858908b99eed03a4.tar.gz bcm5719-llvm-a1036e5d081dd800c71bdbdf858908b99eed03a4.zip |
clang-format: When a line is formatted, also format subsequence lines if their indent is off.
Summary: This is especially important so that if a change is solely inserting a block around a few statements, clang-format-diff.py will still clean up and add indentation to the inner parts.
Reviewers: klimek
Subscribers: cfe-commits, klimek
Differential Revision: http://reviews.llvm.org/D14105
llvm-svn: 251474
Diffstat (limited to 'clang/lib/Format/UnwrappedLineFormatter.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineFormatter.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 8225a0375b4..fcf45c9286f 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -812,13 +812,14 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines, AdditionalIndent); const AnnotatedLine *PreviousLine = nullptr; const AnnotatedLine *NextLine = nullptr; + bool PreviousLineFormatted = false; for (const AnnotatedLine *Line = Joiner.getNextMergedLine(DryRun, IndentTracker); Line; Line = NextLine) { const AnnotatedLine &TheLine = *Line; unsigned Indent = IndentTracker.getIndent(); - bool FixIndentation = - FixBadIndentation && (Indent != TheLine.First->OriginalColumn); + bool FixIndentation = (FixBadIndentation || PreviousLineFormatted) && + Indent != TheLine.First->OriginalColumn; bool ShouldFormat = TheLine.Affected || FixIndentation; // We cannot format this line; if the reason is that the line had a // parsing error, remember that. @@ -845,6 +846,7 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines, else Penalty += OptimizingLineFormatter(Indenter, Whitespaces, Style, this) .formatLine(TheLine, Indent, DryRun); + PreviousLineFormatted = true; } else { // If no token in the current line is affected, we still need to format // affected children. @@ -875,6 +877,7 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines, Whitespaces->addUntouchableToken(*Tok, TheLine.InPPDirective); } NextLine = Joiner.getNextMergedLine(DryRun, IndentTracker); + PreviousLineFormatted = false; } if (!DryRun) markFinalized(TheLine.First); |