diff options
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index d3d4bb14fdb..715cbf0a483 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1775,9 +1775,22 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, const FormatToken &Left = *Right.Previous; if (Right.NewlinesBefore > 1) return true; + + // If the last token before a '}' is a comma or a trailing comment, the + // intention is to insert a line break after it in order to make shuffling + // around entries easier. + const FormatToken *BeforeClosingBrace = nullptr; + if (Left.is(tok::l_brace) && Left.BlockKind != BK_Block && Left.MatchingParen) + BeforeClosingBrace = Left.MatchingParen->Previous; + else if (Right.is(tok::r_brace) && Right.BlockKind != BK_Block) + BeforeClosingBrace = &Left; + if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) || + BeforeClosingBrace->isTrailingComment())) + return true; + if (Right.is(tok::comment)) { - return Right.Previous->BlockKind != BK_BracedInit && - Right.Previous->Type != TT_CtorInitializerColon && + return Left.BlockKind != BK_BracedInit && + Left.Type != TT_CtorInitializerColon && (Right.NewlinesBefore > 0 && Right.HasUnescapedNewline); } else if (Right.Previous->isTrailingComment() || (Right.isStringLiteral() && Right.Previous->isStringLiteral())) { @@ -1826,18 +1839,6 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, return true; } - // If the last token before a '}' is a comma or a trailing comment, the - // intention is to insert a line break after it in order to make shuffling - // around entries easier. - const FormatToken *BeforeClosingBrace = nullptr; - if (Left.is(tok::l_brace) && Left.MatchingParen) - BeforeClosingBrace = Left.MatchingParen->Previous; - else if (Right.is(tok::r_brace)) - BeforeClosingBrace = Right.Previous; - if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) || - BeforeClosingBrace->isTrailingComment())) - return true; - if (Style.Language == FormatStyle::LK_JavaScript) { // FIXME: This might apply to other languages and token kinds. if (Right.is(tok::char_constant) && Left.is(tok::plus) && Left.Previous && |