aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Format/NamespaceEndCommentsFixer.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-12-18 20:30:12 +0000
committerDimitry Andric <dim@FreeBSD.org>2024-04-06 20:11:55 +0000
commit5f757f3ff9144b609b3c433dfd370cc6bdc191ad (patch)
tree1b4e980b866cd26a00af34c0a653eb640bd09caf /contrib/llvm-project/clang/lib/Format/NamespaceEndCommentsFixer.cpp
parent3e1c8a35f741a5d114d0ba670b15191355711fe9 (diff)
parent312c0ed19cc5276a17bacf2120097bec4515b0f1 (diff)
Diffstat (limited to 'contrib/llvm-project/clang/lib/Format/NamespaceEndCommentsFixer.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Format/NamespaceEndCommentsFixer.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/contrib/llvm-project/clang/lib/Format/NamespaceEndCommentsFixer.cpp b/contrib/llvm-project/clang/lib/Format/NamespaceEndCommentsFixer.cpp
index 95eb058d09e1..08f8d6840fe0 100644
--- a/contrib/llvm-project/clang/lib/Format/NamespaceEndCommentsFixer.cpp
+++ b/contrib/llvm-project/clang/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -48,7 +48,7 @@ processTokens(const FormatToken *Tok, tok::TokenKind StartTok,
const FormatToken *skipAttribute(const FormatToken *Tok) {
if (!Tok)
return nullptr;
- if (Tok->is(tok::kw___attribute)) {
+ if (Tok->isAttribute()) {
Tok = Tok->getNextNonComment();
Tok = processTokens(Tok, tok::l_paren, tok::r_paren, nullptr);
} else if (Tok->is(tok::l_square)) {
@@ -170,11 +170,11 @@ bool validEndComment(const FormatToken *RBraceTok, StringRef NamespaceName,
// Valid namespace end comments don't need to be edited.
static const llvm::Regex NamespaceCommentPattern =
llvm::Regex("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
- "namespace( +([a-zA-Z0-9:_]+))?\\.? *(\\*/)?$",
+ "namespace( +([a-zA-Z0-9:_ ]+))?\\.? *(\\*/)?$",
llvm::Regex::IgnoreCase);
static const llvm::Regex NamespaceMacroCommentPattern =
llvm::Regex("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
- "([a-zA-Z0-9_]+)\\(([a-zA-Z0-9:_]*)\\)\\.? *(\\*/)?$",
+ "([a-zA-Z0-9_]+)\\(([a-zA-Z0-9:_]*|\".+\")\\)\\.? *(\\*/)?$",
llvm::Regex::IgnoreCase);
SmallVector<StringRef, 8> Groups;
@@ -189,7 +189,7 @@ bool validEndComment(const FormatToken *RBraceTok, StringRef NamespaceName,
// Comment does not match regex.
return false;
}
- StringRef NamespaceNameInComment = Groups.size() > 5 ? Groups[5] : "";
+ StringRef NamespaceNameInComment = Groups.size() > 5 ? Groups[5].rtrim() : "";
// Anonymous namespace comments must not mention a namespace name.
if (NamespaceName.empty() && !NamespaceNameInComment.empty())
return false;
@@ -359,8 +359,10 @@ std::pair<tooling::Replacements, unsigned> NamespaceEndCommentsFixer::analyze(
computeEndCommentText(NamespaceName, AddNewline, NamespaceTok,
Style.SpacesInLineCommentPrefix.Minimum);
if (!hasEndComment(EndCommentPrevTok)) {
- bool isShort = I - StartLineIndex <= Style.ShortNamespaceLines + 1;
- if (!isShort) {
+ unsigned LineCount = 0;
+ for (auto J = StartLineIndex + 1; J < I; ++J)
+ LineCount += AnnotatedLines[J]->size();
+ if (LineCount > Style.ShortNamespaceLines) {
addEndComment(EndCommentPrevTok,
std::string(Style.SpacesBeforeTrailingComments, ' ') +
EndCommentText,