diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-06-19 19:50:11 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-06-19 19:50:11 +0000 |
commit | a3555e24169781d7b923a4c928313420ee1a4a8e (patch) | |
tree | e40ba6b8c61c0bed84f828b462af6b9be05327e6 /clang/lib/Format/Format.cpp | |
parent | d5dcec1181c1981f1baf7fe5b22ce0c21c4a1bd1 (diff) | |
download | bcm5719-llvm-a3555e24169781d7b923a4c928313420ee1a4a8e.tar.gz bcm5719-llvm-a3555e24169781d7b923a4c928313420ee1a4a8e.zip |
Fixed long-standing issue with incorrect length calculation of multi-line comments.
Summary:
A trailing block comment having multiple lines would cause extremely
high penalties if the summary length of its lines is more than the column limit.
Fixed by always considering only the last line of a multi-line block comment.
Removed a long-standing FIXME from relevant tests and added a motivating test
modelled after problem cases from real code.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1010
llvm-svn: 184340
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 14337e9760e..86437d4c18e 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -832,17 +832,17 @@ private: } if (Current.UnbreakableTailLength >= getColumnLimit()) return 0; - unsigned RemainingSpace = getColumnLimit() - Current.UnbreakableTailLength; + unsigned RemainingSpace = getColumnLimit() - Current.UnbreakableTailLength; bool BreakInserted = false; unsigned Penalty = 0; - unsigned PositionAfterLastLineInToken = 0; + unsigned RemainingTokenColumns = 0; for (unsigned LineIndex = 0, EndIndex = Token->getLineCount(); LineIndex != EndIndex; ++LineIndex) { if (!DryRun) Token->replaceWhitespaceBefore(LineIndex, Whitespaces); unsigned TailOffset = 0; - unsigned RemainingTokenColumns = Token->getLineLengthAfterSplit( + RemainingTokenColumns = Token->getLineLengthAfterSplit( LineIndex, TailOffset, StringRef::npos); while (RemainingTokenColumns > RemainingSpace) { BreakableToken::Split Split = @@ -868,11 +868,11 @@ private: RemainingTokenColumns = NewRemainingTokenColumns; BreakInserted = true; } - PositionAfterLastLineInToken = RemainingTokenColumns; } + State.Column = RemainingTokenColumns; + if (BreakInserted) { - State.Column = PositionAfterLastLineInToken; // If we break the token inside a parameter list, we need to break before // the next parameter on all levels, so that the next parameter is clearly // visible. Line comments already introduce a break. |