forked from OSchip/llvm-project
Fix comments before labels.
Before: switch (...) { // a // b // c case first: break; } After: switch (...) { // a // b // c case first: break; } llvm-svn: 179107
This commit is contained in:
parent
bbae991db6
commit
b67cc423eb
|
@ -1396,14 +1396,21 @@ public:
|
||||||
deriveLocalStyle();
|
deriveLocalStyle();
|
||||||
for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
|
for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
|
||||||
Annotator.calculateFormattingInformation(AnnotatedLines[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;
|
std::vector<int> IndentForLevel;
|
||||||
bool PreviousLineWasTouched = false;
|
bool PreviousLineWasTouched = false;
|
||||||
const AnnotatedToken *PreviousLineLastToken = 0;
|
const AnnotatedToken *PreviousLineLastToken = 0;
|
||||||
|
|
|
@ -432,6 +432,7 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
|
||||||
" // Do nothing.\n"
|
" // Do nothing.\n"
|
||||||
"}");
|
"}");
|
||||||
verifyFormat("switch (x) {\n"
|
verifyFormat("switch (x) {\n"
|
||||||
|
"// comment\n"
|
||||||
"// if 1, do f()\n"
|
"// if 1, do f()\n"
|
||||||
"case 1:\n"
|
"case 1:\n"
|
||||||
" f();\n"
|
" f();\n"
|
||||||
|
|
Loading…
Reference in New Issue