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 | 0dddcf78b89bd062a8de0cd41ce4903ee93b25c0 (patch) | |
tree | 36094549cea8fbbb85914920b955542778e076ee /clang/lib/Format/AffectedRangeManager.h | |
parent | f0f716df8e758dc43836c70a8e2bcb459b42402d (diff) | |
download | bcm5719-llvm-0dddcf78b89bd062a8de0cd41ce4903ee93b25c0.tar.gz bcm5719-llvm-0dddcf78b89bd062a8de0cd41ce4903ee93b25c0.zip |
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
llvm-svn: 330573
Diffstat (limited to 'clang/lib/Format/AffectedRangeManager.h')
-rw-r--r-- | clang/lib/Format/AffectedRangeManager.h | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/clang/lib/Format/AffectedRangeManager.h b/clang/lib/Format/AffectedRangeManager.h index d8d5ee55acd..b9a0cadd40a 100644 --- a/clang/lib/Format/AffectedRangeManager.h +++ b/clang/lib/Format/AffectedRangeManager.h @@ -30,10 +30,9 @@ public: : SourceMgr(SourceMgr), Ranges(Ranges.begin(), Ranges.end()) {} // Determines which lines are affected by the SourceRanges given as input. - // Returns \c true if at least one line between I and E or one of their + // Returns \c true if at least one line in \p Lines or one of their // children is affected. - bool computeAffectedLines(SmallVectorImpl<AnnotatedLine *>::iterator I, - SmallVectorImpl<AnnotatedLine *>::iterator E); + bool computeAffectedLines(SmallVectorImpl<AnnotatedLine *> &Lines); // Returns true if 'Range' intersects with one of the input ranges. bool affectsCharSourceRange(const CharSourceRange &Range); @@ -54,8 +53,8 @@ private: // Determines whether 'Line' is affected by the SourceRanges given as input. // Returns \c true if line or one if its children is affected. - bool nonPPLineAffected(AnnotatedLine *Line, - const AnnotatedLine *PreviousLine); + bool nonPPLineAffected(AnnotatedLine *Line, const AnnotatedLine *PreviousLine, + SmallVectorImpl<AnnotatedLine *> &Lines); const SourceManager &SourceMgr; const SmallVector<CharSourceRange, 8> Ranges; |