summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/BreakableToken.h
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-10-16 09:08:53 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-10-16 09:08:53 +0000
commit35599fdfa034fcc8506986ad3d83fc3bf581014c (patch)
tree1d71413e23349a26cc255bae37c49bb85d780b23 /clang/lib/Format/BreakableToken.h
parentb583a7ead49d6a9ab8de2d2e8e17a8e8fe106ac1 (diff)
downloadbcm5719-llvm-35599fdfa034fcc8506986ad3d83fc3bf581014c.tar.gz
bcm5719-llvm-35599fdfa034fcc8506986ad3d83fc3bf581014c.zip
[clang-format] Break non-trailing comments, try 2
Summary: This patch enables `BreakableToken` to manage the formatting of non-trailing block comments. It is a refinement of https://reviews.llvm.org/D37007. We discovered that the optimizer outsmarts us on cases where breaking the comment costs considerably less than breaking after the comment. This patch addresses this by ensuring that a newline is inserted between a block comment and the next token. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D37695 llvm-svn: 315893
Diffstat (limited to 'clang/lib/Format/BreakableToken.h')
-rw-r--r--clang/lib/Format/BreakableToken.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/lib/Format/BreakableToken.h b/clang/lib/Format/BreakableToken.h
index 630e927e8fc..8c2dc741d1e 100644
--- a/clang/lib/Format/BreakableToken.h
+++ b/clang/lib/Format/BreakableToken.h
@@ -58,6 +58,8 @@ struct FormatStyle;
/// operations that might be executed before the main line breaking occurs:
/// - getSplitBefore, for finding a split such that the content preceding it
/// needs to be specially reflown,
+/// - introducesBreakBefore, for checking if reformatting the beginning
+/// of the content introduces a line break before it,
/// - getLineLengthAfterSplitBefore, for calculating the line length in columns
/// of the remainder of the content after the beginning of the content has
/// been reformatted, and
@@ -135,6 +137,12 @@ public:
return Split(StringRef::npos, 0);
}
+ /// \brief Returns if a break before the content at \p LineIndex will be
+ /// inserted after the whitespace preceding the content has been reformatted.
+ virtual bool introducesBreakBefore(unsigned LineIndex) const {
+ return false;
+ }
+
/// \brief Returns the number of columns required to format the piece of line
/// at \p LineIndex after the content preceding the whitespace range specified
/// \p SplitBefore has been reformatted, but before any breaks are made to
@@ -339,6 +347,7 @@ public:
Split getSplitBefore(unsigned LineIndex, unsigned PreviousEndColumn,
unsigned ColumnLimit,
llvm::Regex &CommentPragmasRegex) const override;
+ bool introducesBreakBefore(unsigned LineIndex) const override;
unsigned getLineLengthAfterSplitBefore(unsigned LineIndex,
unsigned TailOffset,
unsigned PreviousEndColumn,
OpenPOWER on IntegriCloud