[clang-format] Don't reflow across comment pragmas.
Summary:
The comment reflower wasn't taking comment pragmas as reflow stoppers. This patch fixes that.
source:
```
// long long long long
// IWYU pragma:
```
format with column limit = 20 before:
```
// long long long
// long IWYU pragma:
```
format with column limit = 20 after:
```
// long long long
// long
// IWYU pragma:
```
Reviewers: djasper
Reviewed By: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D29450
llvm-svn: 293898
diff --git a/clang/lib/Format/BreakableToken.h b/clang/lib/Format/BreakableToken.h
index cf81053..b9004fc 100644
--- a/clang/lib/Format/BreakableToken.h
+++ b/clang/lib/Format/BreakableToken.h
@@ -21,6 +21,7 @@
#include "Encoding.h"
#include "TokenAnnotator.h"
#include "WhitespaceManager.h"
+#include "llvm/Support/Regex.h"
#include <utility>
namespace clang {
@@ -118,7 +119,8 @@
/// needs to be reformatted before any breaks are made.
virtual Split getSplitBefore(unsigned LineIndex,
unsigned PreviousEndColumn,
- unsigned ColumnLimit) const {
+ unsigned ColumnLimit,
+ llvm::Regex& CommentPragmasRegex) const {
return Split(StringRef::npos, 0);
}
@@ -238,7 +240,8 @@
// Checks if the content of line LineIndex may be reflown with the previous
// line.
- bool mayReflow(unsigned LineIndex) const;
+ virtual bool mayReflow(unsigned LineIndex,
+ llvm::Regex &CommentPragmasRegex) const = 0;
// Contains the original text of the lines of the block comment.
//
@@ -307,7 +310,8 @@
void insertBreak(unsigned LineIndex, unsigned TailOffset, Split Split,
WhitespaceManager &Whitespaces) override;
Split getSplitBefore(unsigned LineIndex, unsigned PreviousEndColumn,
- unsigned ColumnLimit) const override;
+ unsigned ColumnLimit,
+ llvm::Regex &CommentPragmasRegex) const override;
unsigned getLineLengthAfterSplitBefore(unsigned LineIndex,
unsigned TailOffset,
unsigned PreviousEndColumn,
@@ -317,6 +321,8 @@
unsigned ColumnLimit,
Split SplitBefore,
WhitespaceManager &Whitespaces) override;
+ bool mayReflow(unsigned LineIndex,
+ llvm::Regex &CommentPragmasRegex) const override;
private:
// Rearranges the whitespace between Lines[LineIndex-1] and Lines[LineIndex].
@@ -371,7 +377,8 @@
void insertBreak(unsigned LineIndex, unsigned TailOffset, Split Split,
WhitespaceManager &Whitespaces) override;
Split getSplitBefore(unsigned LineIndex, unsigned PreviousEndColumn,
- unsigned ColumnLimit) const override;
+ unsigned ColumnLimit,
+ llvm::Regex &CommentPragmasRegex) const override;
unsigned getLineLengthAfterSplitBefore(unsigned LineIndex, unsigned TailOffset,
unsigned PreviousEndColumn,
unsigned ColumnLimit,
@@ -380,6 +387,8 @@
unsigned ColumnLimit, Split SplitBefore,
WhitespaceManager &Whitespaces) override;
void updateNextToken(LineState& State) const override;
+ bool mayReflow(unsigned LineIndex,
+ llvm::Regex &CommentPragmasRegex) const override;
private:
unsigned getContentStartColumn(unsigned LineIndex,