r182757 - Fixes indentation of empty lines in block comments.
Manuel Klimek
klimek at google.com
Tue May 28 01:55:02 PDT 2013
Author: klimek
Date: Tue May 28 03:55:01 2013
New Revision: 182757
URL: http://llvm.org/viewvc/llvm-project?rev=182757&view=rev
Log:
Fixes indentation of empty lines in block comments.
Block comment indentation of empty lines regressed, as we did not
have a test for it.
/* Comment with...
*
* empty line. */
is now formatted correctly again.
Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=182757&r1=182756&r2=182757&view=diff
==============================================================================
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Tue May 28 03:55:01 2013
@@ -321,8 +321,17 @@ BreakableBlockComment::replaceWhitespace
if (LineIndex == 0)
return;
StringRef Prefix = Decoration;
- if (LineIndex + 1 == Lines.size() && Lines[LineIndex].empty())
- Prefix = "";
+ if (Lines[LineIndex].empty()) {
+ if (LineIndex + 1 == Lines.size()) {
+ // If the last line is empty, we don't need a prefix, as the */ will line
+ // up with the decoration (if it exists).
+ Prefix = "";
+ } else if (!Decoration.empty()) {
+ // For other empty lines, if we do have a decoration, adapt it to not
+ // contain a trailing whitespace.
+ Prefix = Prefix.substr(0, 1);
+ }
+ }
unsigned WhitespaceOffsetInToken =
Lines[LineIndex].data() - Tok.TokenText.data() -
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=182757&r1=182756&r2=182757&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue May 28 03:55:01 2013
@@ -771,6 +771,13 @@ TEST_F(FormatTest, AlignsMultiLineCommen
format(" /*\n"
" Don't try to outdent if there's not enough inentation.\n"
" */"));
+
+ EXPECT_EQ("int i; /* Comment with empty...\n"
+ " *\n"
+ " * line. */",
+ format("int i; /* Comment with empty...\n"
+ " *\n"
+ " * line. */"));
}
TEST_F(FormatTest, SplitsLongCxxComments) {
More information about the cfe-commits
mailing list