diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-06-07 16:02:52 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-06-07 16:02:52 +0000 |
commit | dd7ece53a2958ab3910007f6521bbb078b33505c (patch) | |
tree | 8b16bfa4d9034dc88a102d1683c1ef6d1f937cba /clang/lib/Format/BreakableToken.h | |
parent | cead69d4a3f80fa8684f5636a9469d043f4f7285 (diff) | |
download | bcm5719-llvm-dd7ece53a2958ab3910007f6521bbb078b33505c.tar.gz bcm5719-llvm-dd7ece53a2958ab3910007f6521bbb078b33505c.zip |
Fixed calculation of penalty when breaking tokens.
Summary:
Introduced two new style parameters: PenaltyBreakComment and
PenaltyBreakString. Add penalty for each character of a breakable token beyond
the column limit (this relates mainly to comments, as they are broken only on
whitespace). Tuned PenaltyBreakComment to prefer comment breaking over breaking
inside most binary expressions.
Fixed a bug that prevented *, & and && from being considered TT_BinaryOperator
in the presense of adjacent comments.
Reviewers: klimek, djasper
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D933
llvm-svn: 183530
Diffstat (limited to 'clang/lib/Format/BreakableToken.h')
-rw-r--r-- | clang/lib/Format/BreakableToken.h | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/clang/lib/Format/BreakableToken.h b/clang/lib/Format/BreakableToken.h index 157bff4c42f..100bb19dc5d 100644 --- a/clang/lib/Format/BreakableToken.h +++ b/clang/lib/Format/BreakableToken.h @@ -33,7 +33,7 @@ struct FormatStyle; /// strategy into the class, instead of controlling it from the outside. class BreakableToken { public: - // Contains starting character index and length of split. + /// \brief Contains starting character index and length of split. typedef std::pair<StringRef::size_type, unsigned> Split; virtual ~BreakableToken() {} @@ -41,13 +41,15 @@ public: /// \brief Returns the number of lines in this token in the original code. virtual unsigned getLineCount() const = 0; - /// \brief Returns the rest of the length of the line at \p LineIndex, - /// when broken at \p TailOffset. + /// \brief Returns the number of columns required to format the piece of line + /// at \p LineIndex, from byte offset \p Offset with length \p Length. /// - /// Note that previous breaks are not taken into account. \p TailOffset - /// is always specified from the start of the (original) line. - virtual unsigned getLineLengthAfterSplit(unsigned LineIndex, - unsigned TailOffset) const = 0; + /// Note that previous breaks are not taken into account. \p Offset is always + /// specified from the start of the (original) line. + /// \p Length can be set to StringRef::npos, which means "to the end of line". + virtual unsigned + getLineLengthAfterSplit(unsigned LineIndex, unsigned Offset, + StringRef::size_type Length) const = 0; /// \brief Returns a range (offset, length) at which to break the line at /// \p LineIndex, if previously broken at \p TailOffset. If possible, do not @@ -80,7 +82,8 @@ class BreakableSingleLineToken : public BreakableToken { public: virtual unsigned getLineCount() const; virtual unsigned getLineLengthAfterSplit(unsigned LineIndex, - unsigned TailOffset) const; + unsigned TailOffset, + StringRef::size_type Length) const; virtual void insertBreak(unsigned LineIndex, unsigned TailOffset, Split Split, bool InPPDirective, WhitespaceManager &Whitespaces); @@ -139,7 +142,8 @@ public: virtual unsigned getLineCount() const; virtual unsigned getLineLengthAfterSplit(unsigned LineIndex, - unsigned TailOffset) const; + unsigned TailOffset, + StringRef::size_type Length) const; virtual Split getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit) const; virtual void insertBreak(unsigned LineIndex, unsigned TailOffset, Split Split, |