diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
commit | 676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 (patch) | |
tree | 02a1ac369cb734d0abfa5000dd86e5b7797e6a74 /lib/Format/UnwrappedLineFormatter.cpp | |
parent | c7e70c433efc6953dc3888b9fbf9f3512d7da2b0 (diff) |
Diffstat (limited to 'lib/Format/UnwrappedLineFormatter.cpp')
-rw-r--r-- | lib/Format/UnwrappedLineFormatter.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index 906dae40cbee7..6b6a9aff461ab 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -323,6 +323,10 @@ private: kwId == clang::tok::objc_synchronized) return 0; } + // Don't merge block with left brace wrapped after case labels + if (TheLine->First->is(tok::l_brace) && I != AnnotatedLines.begin() && + I[-1]->First->isOneOf(tok::kw_case, tok::kw_default)) + return 0; // Try to merge a block with left brace wrapped that wasn't yet covered if (TheLine->Last->is(tok::l_brace)) { return !Style.BraceWrapping.AfterFunction || @@ -424,6 +428,8 @@ private: if (Limit == 0 || I + 1 == E || I[1]->First->isOneOf(tok::kw_case, tok::kw_default)) return 0; + if (I[0]->Last->is(tok::l_brace) || I[1]->First->is(tok::l_brace)) + return 0; unsigned NumStmts = 0; unsigned Length = 0; bool EndsWithComment = false; @@ -483,6 +489,12 @@ private: if (Line.First->isOneOf(tok::kw_else, tok::kw_case) || (Line.First->Next && Line.First->Next->is(tok::kw_else))) return 0; + // default: in switch statement + if (Line.First->is(tok::kw_default)) { + const FormatToken *Tok = Line.First->getNextNonComment(); + if (Tok && Tok->is(tok::colon)) + return 0; + } if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::kw_try, tok::kw___try, tok::kw_catch, tok::kw___finally, tok::kw_for, tok::r_brace, Keywords.kw___except)) { @@ -529,7 +541,7 @@ private: Tok->SpacesRequiredBefore = 0; Tok->CanBreakBefore = true; return 1; - } else if (Limit != 0 && !Line.startsWith(tok::kw_namespace) && + } else if (Limit != 0 && !Line.startsWithNamespace() && !startsExternCBlock(Line)) { // We don't merge short records. FormatToken *RecordTok = Line.First; @@ -976,8 +988,7 @@ private: Path.push_front(Best); Best = Best->Previous; } - for (std::deque<StateNode *>::iterator I = Path.begin(), E = Path.end(); - I != E; ++I) { + for (auto I = Path.begin(), E = Path.end(); I != E; ++I) { unsigned Penalty = 0; formatChildren(State, (*I)->NewLine, /*DryRun=*/false, Penalty); Penalty += Indenter->addTokenToState(State, (*I)->NewLine, false); @@ -986,8 +997,8 @@ private: printLineState((*I)->Previous->State); if ((*I)->NewLine) { llvm::dbgs() << "Penalty for placing " - << (*I)->Previous->State.NextToken->Tok.getName() << ": " - << Penalty << "\n"; + << (*I)->Previous->State.NextToken->Tok.getName() + << " on a new line: " << Penalty << "\n"; } }); } @@ -1154,7 +1165,7 @@ void UnwrappedLineFormatter::formatFirstToken( // Remove empty lines after "{". if (!Style.KeepEmptyLinesAtTheStartOfBlocks && PreviousLine && PreviousLine->Last->is(tok::l_brace) && - PreviousLine->First->isNot(tok::kw_namespace) && + !PreviousLine->startsWithNamespace() && !startsExternCBlock(*PreviousLine)) Newlines = 1; |