diff options
| author | Krasimir Georgiev <krasimir@google.com> | 2017-08-09 09:42:32 +0000 |
|---|---|---|
| committer | Krasimir Georgiev <krasimir@google.com> | 2017-08-09 09:42:32 +0000 |
| commit | 3b86534a63b89d691f03476d209ae196bd778d84 (patch) | |
| tree | d1636bdbd669f3da66325e023219c1c2483a58c7 /clang/lib | |
| parent | 7f569a2d549941aa1fe44d97d5c785661e5ee391 (diff) | |
| download | bcm5719-llvm-3b86534a63b89d691f03476d209ae196bd778d84.tar.gz bcm5719-llvm-3b86534a63b89d691f03476d209ae196bd778d84.zip | |
[clang-format] Put '/**' and '*/' on own lines in jsdocs ending in comment pragmas
Summary:
This handles a case where the trailing '*/' of a multiline jsdoc eding in a
comment pragma wouldn't be put on a new line.
Reviewers: mprobst
Reviewed By: mprobst
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D36359
llvm-svn: 310458
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Format/BreakableToken.cpp | 18 | ||||
| -rw-r--r-- | clang/lib/Format/BreakableToken.h | 8 | ||||
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 4 |
3 files changed, 18 insertions, 12 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index 3844c8e7c01..20e3e5b1dfd 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -681,12 +681,18 @@ void BreakableBlockComment::replaceWhitespaceBefore( InPPDirective, /*Newlines=*/1, ContentColumn[LineIndex] - Prefix.size()); } -BreakableToken::Split BreakableBlockComment::getSplitAfterLastLine( - unsigned TailOffset, unsigned ColumnLimit, - llvm::Regex &CommentPragmasRegex) const { - if (DelimitersOnNewline) - return getSplit(Lines.size() - 1, TailOffset, ColumnLimit, - CommentPragmasRegex); +BreakableToken::Split +BreakableBlockComment::getSplitAfterLastLine(unsigned TailOffset, + unsigned ColumnLimit) const { + if (DelimitersOnNewline) { + // Replace the trailing whitespace of the last line with a newline. + // In case the last line is empty, the ending '*/' is already on its own + // line. + StringRef Line = Content.back().substr(TailOffset); + StringRef TrimmedLine = Line.rtrim(Blanks); + if (!TrimmedLine.empty()) + return Split(TrimmedLine.size(), Line.size() - TrimmedLine.size()); + } return Split(StringRef::npos, 0); } diff --git a/clang/lib/Format/BreakableToken.h b/clang/lib/Format/BreakableToken.h index e5cbe8f197e..630e927e8fc 100644 --- a/clang/lib/Format/BreakableToken.h +++ b/clang/lib/Format/BreakableToken.h @@ -161,8 +161,8 @@ public: /// /// A result having offset == StringRef::npos means that no reformat is /// necessary. - virtual Split getSplitAfterLastLine(unsigned TailOffset, unsigned ColumnLimit, - llvm::Regex &CommentPragmasRegex) const { + virtual Split getSplitAfterLastLine(unsigned TailOffset, + unsigned ColumnLimit) const { return Split(StringRef::npos, 0); } @@ -347,8 +347,8 @@ public: void replaceWhitespaceBefore(unsigned LineIndex, unsigned PreviousEndColumn, unsigned ColumnLimit, Split SplitBefore, WhitespaceManager &Whitespaces) override; - Split getSplitAfterLastLine(unsigned TailOffset, unsigned ColumnLimit, - llvm::Regex &CommentPragmasRegex) const override; + Split getSplitAfterLastLine(unsigned TailOffset, + unsigned ColumnLimit) const override; bool mayReflow(unsigned LineIndex, llvm::Regex &CommentPragmasRegex) const override; diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 25a470474b7..d8ae82c1843 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1383,8 +1383,8 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, } } - BreakableToken::Split SplitAfterLastLine = Token->getSplitAfterLastLine( - TailOffset, ColumnLimit, CommentPragmasRegex); + BreakableToken::Split SplitAfterLastLine = + Token->getSplitAfterLastLine(TailOffset, ColumnLimit); if (SplitAfterLastLine.first != StringRef::npos) { if (!DryRun) Token->replaceWhitespaceAfterLastLine(TailOffset, SplitAfterLastLine, |

