r174537 - Align trailing block comments like trailing line comments.
Daniel Jasper
djasper at google.com
Wed Feb 6 12:07:36 PST 2013
Author: djasper
Date: Wed Feb 6 14:07:35 2013
New Revision: 174537
URL: http://llvm.org/viewvc/llvm-project?rev=174537&view=rev
Log:
Align trailing block comments like trailing line comments.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=174537&r1=174536&r2=174537&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Feb 6 14:07:35 2013
@@ -80,6 +80,11 @@ FormatStyle getChromiumStyle() {
return ChromiumStyle;
}
+static bool isTrailingComment(const AnnotatedToken &Tok) {
+ return Tok.is(tok::comment) &&
+ (Tok.Children.empty() || Tok.Children[0].MustBreakBefore);
+}
+
/// \brief Manages the whitespaces around tokens and their replacements.
///
/// This includes special handling for certain constructs, e.g. the alignment of
@@ -99,8 +104,7 @@ public:
// Align line comments if they are trailing or if they continue other
// trailing comments.
- if (Tok.Type == TT_LineComment &&
- (Tok.Parent != NULL || !Comments.empty())) {
+ if (isTrailingComment(Tok) && (Tok.Parent != NULL || !Comments.empty())) {
if (Style.ColumnLimit >=
Spaces + WhitespaceStartColumn + Tok.FormatTok.TokenLength) {
Comments.push_back(StoredComment());
@@ -115,7 +119,7 @@ public:
}
// If this line does not have a trailing comment, align the stored comments.
- if (Tok.Children.empty() && Tok.Type != TT_LineComment)
+ if (Tok.Children.empty() && !isTrailingComment(Tok))
alignComments();
storeReplacement(Tok.FormatTok,
std::string(NewLines, '\n') + std::string(Spaces, ' '));
@@ -207,11 +211,6 @@ private:
tooling::Replacements Replaces;
};
-static bool isTrailingComment(const AnnotatedToken &Tok) {
- return Tok.is(tok::comment) &&
- (Tok.Children.empty() || Tok.Children[0].MustBreakBefore);
-}
-
class UnwrappedLineFormatter {
public:
UnwrappedLineFormatter(const FormatStyle &Style, SourceManager &SourceMgr,
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=174537&r1=174536&r2=174537&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Feb 6 14:07:35 2013
@@ -1985,6 +1985,13 @@ TEST_F(FormatTest, BlockComments) {
"bool aaaaaaaaaaaaa = /* trailing comment */\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaa||aaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaa;"));
+ EXPECT_EQ(
+ "int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; /* comment */\n"
+ "int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; /* comment */\n"
+ "int cccccccccccccccccccccccccccccc; /* comment */\n",
+ format("int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; /* comment */\n"
+ "int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; /* comment */\n"
+ "int cccccccccccccccccccccccccccccc; /* comment */\n"));
}
TEST_F(FormatTest, BlockCommentsInMacros) {
More information about the cfe-commits
mailing list