https://github.com/owenca created https://github.com/llvm/llvm-project/pull/85564
None >From 3b9e25b8509aa6847838148fd2959569c94c4a0f Mon Sep 17 00:00:00 2001 From: Owen Pan <owenpi...@gmail.com> Date: Sun, 17 Mar 2024 01:08:07 -0700 Subject: [PATCH] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() --- clang/lib/Format/Format.cpp | 1 - clang/lib/Format/FormatToken.cpp | 41 ++------------------ clang/lib/Format/FormatToken.h | 5 +-- clang/lib/Format/QualifierAlignmentFixer.cpp | 2 +- 4 files changed, 6 insertions(+), 43 deletions(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 470e79660b5db6..53275f110e9def 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -3821,7 +3821,6 @@ LangOptions getFormattingLangOpts(const FormatStyle &Style) { if (LexingStd == FormatStyle::LS_Latest) LexingStd = FormatStyle::LS_Cpp20; - LangOptions LangOpts; LangOpts.CPlusPlus = 1; LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11; LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14; diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index cd94a9df6cff79..84b8f5cc09028b 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -20,6 +20,8 @@ namespace format { bool IsCpp = false; +LangOptions LangOpts; + const char *getTokenTypeName(TokenType Type) { static const char *const TokNames[] = { #define TYPE(X) #X, @@ -33,43 +35,6 @@ const char *getTokenTypeName(TokenType Type) { return nullptr; } -// FIXME: This is copy&pasted from Sema. Put it in a common place and remove -// duplication. -bool FormatToken::isSimpleTypeSpecifier() const { - switch (Tok.getKind()) { - case tok::kw_short: - case tok::kw_long: - case tok::kw___int64: - case tok::kw___int128: - case tok::kw_signed: - case tok::kw_unsigned: - case tok::kw_void: - case tok::kw_char: - case tok::kw_int: - case tok::kw_half: - case tok::kw_float: - case tok::kw_double: - case tok::kw___bf16: - case tok::kw__Float16: - case tok::kw___float128: - case tok::kw___ibm128: - case tok::kw_wchar_t: - case tok::kw_bool: -#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait: -#include "clang/Basic/TransformTypeTraits.def" - case tok::annot_typename: - case tok::kw_char8_t: - case tok::kw_char16_t: - case tok::kw_char32_t: - case tok::kw_typeof: - case tok::kw_decltype: - case tok::kw__Atomic: - return true; - default: - return false; - } -} - // Sorted common C++ non-keyword types. static SmallVector<StringRef> CppNonKeywordTypes = { "clock_t", "int16_t", "int32_t", "int64_t", "int8_t", @@ -78,7 +43,7 @@ static SmallVector<StringRef> CppNonKeywordTypes = { }; bool FormatToken::isTypeName() const { - return is(TT_TypeName) || isSimpleTypeSpecifier() || + return is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts) || (IsCpp && is(tok::identifier) && std::binary_search(CppNonKeywordTypes.begin(), CppNonKeywordTypes.end(), TokenText)); diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 2d6116c43cfad0..db4b4cf44e2fbc 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -27,6 +27,8 @@ namespace format { /// Whether the language is C/C++/Objective-C/Objective-C++. extern bool IsCpp; +extern LangOptions LangOpts; + #define LIST_TOKEN_TYPES \ TYPE(ArrayInitializerLSquare) \ TYPE(ArraySubscriptLSquare) \ @@ -674,9 +676,6 @@ struct FormatToken { isAttribute(); } - /// Determine whether the token is a simple-type-specifier. - [[nodiscard]] bool isSimpleTypeSpecifier() const; - [[nodiscard]] bool isTypeName() const; [[nodiscard]] bool isTypeOrIdentifier() const; diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp index 32d5153fc8151d..d1056e38ba8797 100644 --- a/clang/lib/Format/QualifierAlignmentFixer.cpp +++ b/clang/lib/Format/QualifierAlignmentFixer.cpp @@ -522,7 +522,7 @@ LeftRightQualifierAlignmentFixer::LeftRightQualifierAlignmentFixer( const std::vector<tok::TokenKind> &QualifierTokens, bool RightAlign) : TokenAnalyzer(Env, Style), Qualifier(Qualifier), RightAlign(RightAlign), ConfiguredQualifierTokens(QualifierTokens) { - IsCpp = Style.isCpp(); + getFormattingLangOpts(Style); } std::pair<tooling::Replacements, unsigned> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits