diff options
author | Daniel Jasper <djasper@google.com> | 2014-08-26 09:37:52 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-08-26 09:37:52 +0000 |
commit | 610381ff07c74e3461bfd76e5b8fe0b37365b4bb (patch) | |
tree | 41f35383d736b8acb0021e19972ebcf48465f6fa /clang/lib | |
parent | 4919bbe29d04db5e437b90268be9f84594199c37 (diff) | |
download | bcm5719-llvm-610381ff07c74e3461bfd76e5b8fe0b37365b4bb.tar.gz bcm5719-llvm-610381ff07c74e3461bfd76e5b8fe0b37365b4bb.zip |
clang-format: Improve handling of block comments in braced lists.
Before:
std::vector<int> v = {
1, 0 /* comment */
};
After:
std::vector<int> v = {1, 0 /* comment */};
llvm-svn: 216445
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Format/FormatToken.h | 3 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 22 |
2 files changed, 13 insertions, 12 deletions
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 528cab78cc0..38f157776f3 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -350,7 +350,8 @@ struct FormatToken { } bool isTrailingComment() const { - return is(tok::comment) && (!Next || Next->NewlinesBefore > 0); + return is(tok::comment) && + (Type == TT_LineComment || !Next || Next->NewlinesBefore > 0); } /// \brief Returns \c true if this is a keyword that can be used diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 4c6be9f98c1..be22fee9b2a 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1561,6 +1561,12 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return false; if (Left.is(tok::colon)) return Left.Type != TT_ObjCMethodExpr; + if (Left.is(tok::l_brace) && Right.is(tok::r_brace)) + return !Left.Children.empty(); // No spaces in "{}". + if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) || + (Right.is(tok::r_brace) && Right.MatchingParen && + Right.MatchingParen->BlockKind != BK_Block)) + return !Style.Cpp11BracedListStyle; if (Left.Type == TT_BlockComment) return !Left.TokenText.endswith("=*/"); if (Right.is(tok::l_paren)) { @@ -1578,12 +1584,6 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, } if (Left.is(tok::at) && Right.Tok.getObjCKeywordID() != tok::objc_not_keyword) return false; - if (Left.is(tok::l_brace) && Right.is(tok::r_brace)) - return !Left.Children.empty(); // No spaces in "{}". - if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) || - (Right.is(tok::r_brace) && Right.MatchingParen && - Right.MatchingParen->BlockKind != BK_Block)) - return !Style.Cpp11BracedListStyle; if (Right.Type == TT_UnaryOperator) return !Left.isOneOf(tok::l_paren, tok::l_square, tok::at) && (Left.isNot(tok::colon) || Left.Type != TT_ObjCMethodExpr); @@ -1717,16 +1717,16 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, return true; } - // If the last token before a '}' is a comma or a comment, the intention is to - // insert a line break after it in order to make shuffling around entries - // easier. + // 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->isOneOf(tok::comma, tok::comment)) + if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) || + BeforeClosingBrace->isTrailingComment())) return true; if (Style.Language == FormatStyle::LK_JavaScript) { |