r194491 - Do not insert backslashes, when breaking line comments after preprocessor directives.
Alexander Kornienko
alexfh at google.com
Tue Nov 12 09:30:50 PST 2013
Author: alexfh
Date: Tue Nov 12 11:30:49 2013
New Revision: 194491
URL: http://llvm.org/viewvc/llvm-project?rev=194491&view=rev
Log:
Do not insert backslashes, when breaking line comments after preprocessor directives.
Summary: This solves http://llvm.org/PR17536
Reviewers: klimek, djasper
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2142
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=194491&r1=194490&r2=194491&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Nov 12 11:30:49 2013
@@ -734,6 +734,7 @@ unsigned ContinuationIndenter::breakProt
llvm::OwningPtr<BreakableToken> Token;
unsigned StartColumn = State.Column - Current.ColumnWidth;
+ unsigned ColumnLimit = getColumnLimit(State);
if (Current.isOneOf(tok::string_literal, tok::wide_string_literal,
tok::utf8_string_literal, tok::utf16_string_literal,
@@ -778,16 +779,17 @@ unsigned ContinuationIndenter::breakProt
(Current.Previous == NULL ||
Current.Previous->Type != TT_ImplicitStringLiteral)) {
Token.reset(new BreakableLineComment(Current, State.Line->Level,
- StartColumn, State.Line->InPPDirective,
+ StartColumn, /*InPPDirective=*/false,
Encoding, Style));
+ // We don't insert backslashes when breaking line comments.
+ ColumnLimit = Style.ColumnLimit;
} else {
return 0;
}
- if (Current.UnbreakableTailLength >= getColumnLimit(State))
+ if (Current.UnbreakableTailLength >= ColumnLimit)
return 0;
- unsigned RemainingSpace =
- getColumnLimit(State) - Current.UnbreakableTailLength;
+ unsigned RemainingSpace = ColumnLimit - Current.UnbreakableTailLength;
bool BreakInserted = false;
unsigned Penalty = 0;
unsigned RemainingTokenColumns = 0;
@@ -800,7 +802,7 @@ unsigned ContinuationIndenter::breakProt
Token->getLineLengthAfterSplit(LineIndex, TailOffset, StringRef::npos);
while (RemainingTokenColumns > RemainingSpace) {
BreakableToken::Split Split =
- Token->getSplit(LineIndex, TailOffset, getColumnLimit(State));
+ Token->getSplit(LineIndex, TailOffset, ColumnLimit);
if (Split.first == StringRef::npos) {
// The last line's penalty is handled in addNextStateToQueue().
if (LineIndex < EndIndex - 1)
@@ -817,9 +819,8 @@ unsigned ContinuationIndenter::breakProt
Penalty += Current.SplitPenalty;
unsigned ColumnsUsed =
Token->getLineLengthAfterSplit(LineIndex, TailOffset, Split.first);
- if (ColumnsUsed > getColumnLimit(State)) {
- Penalty += Style.PenaltyExcessCharacter *
- (ColumnsUsed - getColumnLimit(State));
+ if (ColumnsUsed > ColumnLimit) {
+ Penalty += Style.PenaltyExcessCharacter * (ColumnsUsed - ColumnLimit);
}
TailOffset += Split.first + Split.second;
RemainingTokenColumns = NewRemainingTokenColumns;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=194491&r1=194490&r2=194491&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Nov 12 11:30:49 2013
@@ -1005,6 +1005,14 @@ TEST_F(FormatTest, SplitsLongCxxComments
EXPECT_EQ("//\t aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
format("//\t aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
getLLVMStyleWithColumns(20)));
+ EXPECT_EQ(
+ "#define XXX // a b c d\n"
+ " // e f g h",
+ format("#define XXX // a b c d e f g h", getLLVMStyleWithColumns(22)));
+ EXPECT_EQ(
+ "#define XXX // q w e r\n"
+ " // t y u i",
+ format("#define XXX //q w e r t y u i", getLLVMStyleWithColumns(22)));
}
TEST_F(FormatTest, DontSplitLineCommentsWithEscapedNewlines) {
More information about the cfe-commits
mailing list