diff options
author | Daniel Jasper <djasper@google.com> | 2013-04-09 17:46:55 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-04-09 17:46:55 +0000 |
commit | 5999f7634e80daf849a036aa830fc0e4b1e03555 (patch) | |
tree | c832dbaafb1e26aba4b3a867153765367bcd972c /lib/Format | |
parent | 99b0e14691b61d8db4f1d239a11615957071fb45 (diff) |
Fix comments before labels.
Before:
switch (...) {
// a
// b
// c
case first:
break;
}
After:
switch (...) {
// a
// b
// c
case first:
break;
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179107 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format')
-rw-r--r-- | lib/Format/Format.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index c78b5b680d..84609d164e 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1396,14 +1396,21 @@ public: deriveLocalStyle(); for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) { Annotator.calculateFormattingInformation(AnnotatedLines[i]); + } - // Adapt level to the next line if this is a comment. - // FIXME: Can/should this be done in the UnwrappedLineParser? - if (i + 1 != e && AnnotatedLines[i].First.is(tok::comment) && - AnnotatedLines[i].First.Children.empty() && - AnnotatedLines[i + 1].First.isNot(tok::r_brace)) - AnnotatedLines[i].Level = AnnotatedLines[i + 1].Level; + // Adapt level to the next line if this is a comment. + // FIXME: Can/should this be done in the UnwrappedLineParser? + const AnnotatedLine* NextNoneCommentLine = NULL; + for (unsigned i = AnnotatedLines.size() - 1; i > 0; --i) { + if (NextNoneCommentLine && AnnotatedLines[i].First.is(tok::comment) && + AnnotatedLines[i].First.Children.empty()) + AnnotatedLines[i].Level = NextNoneCommentLine->Level; + else + NextNoneCommentLine = AnnotatedLines[i].First.isNot(tok::r_brace) + ? &AnnotatedLines[i] + : NULL; } + std::vector<int> IndentForLevel; bool PreviousLineWasTouched = false; const AnnotatedToken *PreviousLineLastToken = 0; |