diff options
author | Manuel Klimek <klimek@google.com> | 2018-04-23 09:34:26 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2018-04-23 09:34:26 +0000 |
commit | 3a450c607490719048d7e52bb50e18c54066e884 (patch) | |
tree | b697bfd735e810c8b07c4109e5534bac150e4816 /lib/Format/TokenAnnotator.h | |
parent | 41ef6cd00386db07cc02e3b618873e87527170da (diff) |
Format closing braces when reformatting the line containing the opening brace.
This required a couple of yaks to be shaved:
1. MatchingOpeningBlockLineIndex was misused to also store the
closing index; instead, use a second variable, as this doesn't
work correctly for "} else {".
2. We needed to change the API of AffectedRangeManager to not
use iterators; we always passed in begin / end for the whole
container before, so there was no mismatch in generality.
3. We need an extra check to discontinue formatting at the top
level, as we now sometimes change the indent of the closing
brace, but want to bail out immediately afterwards, for
example:
void f() {
if (a) {
}
void g();
Previously:
void f() {
if (a) {
}
void g();
Now:
void f() {
if (a) {
}
void g();
Differential Revision: https://reviews.llvm.org/D45726
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@330573 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/TokenAnnotator.h')
-rw-r--r-- | lib/Format/TokenAnnotator.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/Format/TokenAnnotator.h b/lib/Format/TokenAnnotator.h index 04a18d45b8..7be0753c20 100644 --- a/lib/Format/TokenAnnotator.h +++ b/lib/Format/TokenAnnotator.h @@ -40,6 +40,7 @@ public: AnnotatedLine(const UnwrappedLine &Line) : First(Line.Tokens.front().Tok), Level(Line.Level), MatchingOpeningBlockLineIndex(Line.MatchingOpeningBlockLineIndex), + MatchingClosingBlockLineIndex(Line.MatchingClosingBlockLineIndex), InPPDirective(Line.InPPDirective), MustBeDeclaration(Line.MustBeDeclaration), MightBeFunctionDecl(false), IsMultiVariableDeclStmt(false), Affected(false), @@ -112,6 +113,7 @@ public: LineType Type; unsigned Level; size_t MatchingOpeningBlockLineIndex; + size_t MatchingClosingBlockLineIndex; bool InPPDirective; bool MustBeDeclaration; bool MightBeFunctionDecl; |