diff options
author | Owen Pan <owenpiano@gmail.com> | 2025-01-30 19:33:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-30 19:33:15 -0800 |
commit | 1a25bea852cd4f7d99e644953c31278f7f257ccd (patch) | |
tree | 9901dd770d58c51d6584d32664d80eaad01912df /clang/lib/Format/UnwrappedLineParser.cpp | |
parent | 45f538ecba1a51768002a5bc0c194b5af4cd9c27 (diff) | |
download | llvm-1a25bea852cd4f7d99e644953c31278f7f257ccd.zip llvm-1a25bea852cd4f7d99e644953c31278f7f257ccd.tar.gz llvm-1a25bea852cd4f7d99e644953c31278f7f257ccd.tar.bz2 |
[clang-format] Add ClassHeadName to help annotating StartOfName (#124891)
Fixes #124574.
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 120922d..1411197 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -4029,7 +4029,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) { const FormatToken &InitialToken = *FormatTok; nextToken(); - const FormatToken *ClassName = nullptr; + FormatToken *ClassName = nullptr; bool IsDerived = false; auto IsNonMacroIdentifier = [](const FormatToken *Tok) { return Tok->is(tok::identifier) && Tok->TokenText != Tok->TokenText.upper(); @@ -4059,7 +4059,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) { } if (FormatTok->is(tok::l_square) && handleCppAttributes()) continue; - const auto *Previous = FormatTok; + auto *Previous = FormatTok; nextToken(); switch (FormatTok->Tok.getKind()) { case tok::l_paren: @@ -4074,9 +4074,12 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) { case tok::hashhash: break; default: - if (!JSPastExtendsOrImplements && !ClassName && - Previous->is(tok::identifier) && Previous->isNot(TT_AttributeMacro) && - Previous->TokenText != Previous->TokenText.upper()) { + if (JSPastExtendsOrImplements || ClassName || + Previous->isNot(tok::identifier) || Previous->is(TT_AttributeMacro)) { + break; + } + if (const auto Text = Previous->TokenText; + Text.size() == 1 || Text != Text.upper()) { ClassName = Previous; } } @@ -4160,6 +4163,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) { if (FormatTok->is(tok::l_brace)) { if (IsListInitialization()) return; + if (ClassName) + ClassName->setFinalizedType(TT_ClassHeadName); auto [OpenBraceType, ClosingBraceType] = GetBraceTypes(InitialToken); FormatTok->setFinalizedType(OpenBraceType); if (ParseAsExpr) { |