summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2024-01-31 20:16:18 -0800
committerGitHub <noreply@github.com>2024-01-31 20:16:18 -0800
commita8279a8bc541b6027087dd497daa63b6602b7f4b (patch)
tree6fabee69eba4bd7571e117780999a48fee6c6f07
parentf8be7f29ede5369b96056d3879c57de54781c9cf (diff)
[clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (#80101)
So that it can be used by clang-format.
-rw-r--r--clang/include/clang/Lex/Token.h3
-rw-r--r--clang/include/clang/Sema/Sema.h2
-rw-r--r--clang/lib/Lex/Lexer.cpp45
-rw-r--r--clang/lib/Parse/ParseExpr.cpp2
-rw-r--r--clang/lib/Parse/ParseObjc.cpp2
-rw-r--r--clang/lib/Sema/SemaDecl.cpp45
6 files changed, 50 insertions, 49 deletions
diff --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h
index 1409e2c58b55..36ec5ddaa29a 100644
--- a/clang/include/clang/Lex/Token.h
+++ b/clang/include/clang/Lex/Token.h
@@ -22,6 +22,7 @@
namespace clang {
class IdentifierInfo;
+class LangOptions;
/// Token - This structure provides full information about a lexed token.
/// It is not intended to be space efficient, it is intended to return as much
@@ -288,6 +289,8 @@ public:
/// Return the ObjC keyword kind.
tok::ObjCKeywordKind getObjCKeywordID() const;
+ bool isSimpleTypeSpecifier(const LangOptions &LangOpts) const;
+
/// Return true if this token has trigraphs or escaped newlines in it.
bool needsCleaning() const { return getFlag(NeedsCleaning); }
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1ac2a465a0d5..b780cee86c3c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2683,8 +2683,6 @@ public:
void DiagnoseUseOfUnimplementedSelectors();
- bool isSimpleTypeSpecifier(const Token &Tok) const;
-
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
Scope *S, CXXScopeSpec *SS = nullptr,
bool isClassName = false, bool HasTrailingDot = false,
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 50b56265f6e1..d927f28b47c2 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -74,6 +74,51 @@ tok::ObjCKeywordKind Token::getObjCKeywordID() const {
return specId ? specId->getObjCKeywordID() : tok::objc_not_keyword;
}
+/// Determine whether the token kind starts a simple-type-specifier.
+bool Token::isSimpleTypeSpecifier(const LangOptions &LangOpts) const {
+ switch (getKind()) {
+ case tok::annot_typename:
+ case tok::annot_decltype:
+ case tok::annot_pack_indexing_type:
+ return true;
+
+ 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:
+ case tok::kw__Bool:
+ case tok::kw__Accum:
+ case tok::kw__Fract:
+ case tok::kw__Sat:
+#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
+#include "clang/Basic/TransformTypeTraits.def"
+ case tok::kw___auto_type:
+ case tok::kw_char16_t:
+ case tok::kw_char32_t:
+ case tok::kw_typeof:
+ case tok::kw_decltype:
+ case tok::kw_char8_t:
+ return getIdentifierInfo()->isKeyword(LangOpts);
+
+ default:
+ return false;
+ }
+}
+
//===----------------------------------------------------------------------===//
// Lexer Class Implementation
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e5d4285b9918..52cebdb6f64b 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1609,7 +1609,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
if (TryAnnotateTypeOrScopeToken())
return ExprError();
- if (!Actions.isSimpleTypeSpecifier(Tok))
+ if (!Tok.isSimpleTypeSpecifier(getLangOpts()))
// We are trying to parse a simple-type-specifier but might not get such
// a token after error recovery.
return ExprError();
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 4771b69eadb3..88bab0eb27a3 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -2971,7 +2971,7 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) {
tok::annot_cxxscope))
TryAnnotateTypeOrScopeToken();
- if (!Actions.isSimpleTypeSpecifier(Tok)) {
+ if (!Tok.isSimpleTypeSpecifier(getLangOpts())) {
// objc-receiver:
// expression
// Make sure any typos in the receiver are corrected or diagnosed, so that
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 00c750e42285..fd1c47008d68 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -127,51 +127,6 @@ class TypeNameValidatorCCC final : public CorrectionCandidateCallback {
} // end anonymous namespace
-/// Determine whether the token kind starts a simple-type-specifier.
-bool Sema::isSimpleTypeSpecifier(const Token &Tok) const {
- switch (Tok.getKind()) {
- case tok::annot_typename:
- case tok::annot_decltype:
- case tok::annot_pack_indexing_type:
- return true;
-
- 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:
- case tok::kw__Bool:
- case tok::kw__Accum:
- case tok::kw__Fract:
- case tok::kw__Sat:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
- case tok::kw___auto_type:
- case tok::kw_char16_t:
- case tok::kw_char32_t:
- case tok::kw_typeof:
- case tok::kw_decltype:
- case tok::kw_char8_t:
- return Tok.getIdentifierInfo()->isKeyword(getLangOpts());
-
- default:
- return false;
- }
-}
-
namespace {
enum class UnqualifiedTypeNameLookupResult {
NotFound,