summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-07-01 13:42:42 +0000
committerAlexander Kornienko <alexfh@google.com>2013-07-01 13:42:42 +0000
commitaa620e187e33b0cf358382ece026d052ac217bf4 (patch)
tree7f020626c8d0570694f6f26d31ffc51eddb73514 /clang/lib/Format/Format.cpp
parentd2bbdf05e0b88524226589d89ffb2bfdc53ef3c8 (diff)
downloadbcm5719-llvm-aa620e187e33b0cf358382ece026d052ac217bf4.tar.gz
bcm5719-llvm-aa620e187e33b0cf358382ece026d052ac217bf4.zip
Avoid column limit violation in block comments in certain cases.
Summary: Add penalty when an excessively long line in a block comment can not be broken on a leading whitespace. Lack of this addition can lead to severe column width violations when they can be easily avoided. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1071 llvm-svn: 185337
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 7b9950a43b0..9cfb04162e8 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -806,9 +806,10 @@ private:
///
/// \returns An extra penalty if a token was broken, otherwise 0.
///
- /// Note that the penalty of the token protruding the allowed line length is
- /// already handled in \c addNextStateToQueue; the returned penalty will only
- /// cover the cost of the additional line breaks.
+ /// The returned penalty will cover the cost of the additional line breaks and
+ /// column limit violation in all lines except for the last one. The penalty
+ /// for the column limit violation in the last line (and in single line
+ /// tokens) is handled in \c addNextStateToQueue.
unsigned breakProtrudingToken(const FormatToken &Current, LineState &State,
bool DryRun) {
llvm::OwningPtr<BreakableToken> Token;
@@ -854,8 +855,13 @@ private:
while (RemainingTokenColumns > RemainingSpace) {
BreakableToken::Split Split =
Token->getSplit(LineIndex, TailOffset, getColumnLimit());
- if (Split.first == StringRef::npos)
+ if (Split.first == StringRef::npos) {
+ // The last line's penalty is handled in addNextStateToQueue().
+ if (LineIndex < EndIndex - 1)
+ Penalty += Style.PenaltyExcessCharacter *
+ (RemainingTokenColumns - RemainingSpace);
break;
+ }
assert(Split.first != 0);
unsigned NewRemainingTokenColumns = Token->getLineLengthAfterSplit(
LineIndex, TailOffset + Split.first + Split.second,
OpenPOWER on IntegriCloud