Skip to content

Commit a8279a8

Browse files
authored
[clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (#80101)
So that it can be used by clang-format.
1 parent f8be7f2 commit a8279a8

File tree

6 files changed

+50
-49
lines changed

6 files changed

+50
-49
lines changed

clang/include/clang/Lex/Token.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace clang {
2323

2424
class IdentifierInfo;
25+
class LangOptions;
2526

2627
/// Token - This structure provides full information about a lexed token.
2728
/// It is not intended to be space efficient, it is intended to return as much
@@ -288,6 +289,8 @@ class Token {
288289
/// Return the ObjC keyword kind.
289290
tok::ObjCKeywordKind getObjCKeywordID() const;
290291

292+
bool isSimpleTypeSpecifier(const LangOptions &LangOpts) const;
293+
291294
/// Return true if this token has trigraphs or escaped newlines in it.
292295
bool needsCleaning() const { return getFlag(NeedsCleaning); }
293296

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,8 +2683,6 @@ class Sema final {
26832683

26842684
void DiagnoseUseOfUnimplementedSelectors();
26852685

2686-
bool isSimpleTypeSpecifier(const Token &Tok) const;
2687-
26882686
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
26892687
Scope *S, CXXScopeSpec *SS = nullptr,
26902688
bool isClassName = false, bool HasTrailingDot = false,

clang/lib/Lex/Lexer.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,51 @@ tok::ObjCKeywordKind Token::getObjCKeywordID() const {
7474
return specId ? specId->getObjCKeywordID() : tok::objc_not_keyword;
7575
}
7676

77+
/// Determine whether the token kind starts a simple-type-specifier.
78+
bool Token::isSimpleTypeSpecifier(const LangOptions &LangOpts) const {
79+
switch (getKind()) {
80+
case tok::annot_typename:
81+
case tok::annot_decltype:
82+
case tok::annot_pack_indexing_type:
83+
return true;
84+
85+
case tok::kw_short:
86+
case tok::kw_long:
87+
case tok::kw___int64:
88+
case tok::kw___int128:
89+
case tok::kw_signed:
90+
case tok::kw_unsigned:
91+
case tok::kw_void:
92+
case tok::kw_char:
93+
case tok::kw_int:
94+
case tok::kw_half:
95+
case tok::kw_float:
96+
case tok::kw_double:
97+
case tok::kw___bf16:
98+
case tok::kw__Float16:
99+
case tok::kw___float128:
100+
case tok::kw___ibm128:
101+
case tok::kw_wchar_t:
102+
case tok::kw_bool:
103+
case tok::kw__Bool:
104+
case tok::kw__Accum:
105+
case tok::kw__Fract:
106+
case tok::kw__Sat:
107+
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
108+
#include "clang/Basic/TransformTypeTraits.def"
109+
case tok::kw___auto_type:
110+
case tok::kw_char16_t:
111+
case tok::kw_char32_t:
112+
case tok::kw_typeof:
113+
case tok::kw_decltype:
114+
case tok::kw_char8_t:
115+
return getIdentifierInfo()->isKeyword(LangOpts);
116+
117+
default:
118+
return false;
119+
}
120+
}
121+
77122
//===----------------------------------------------------------------------===//
78123
// Lexer Class Implementation
79124
//===----------------------------------------------------------------------===//

clang/lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
16091609
if (TryAnnotateTypeOrScopeToken())
16101610
return ExprError();
16111611

1612-
if (!Actions.isSimpleTypeSpecifier(Tok))
1612+
if (!Tok.isSimpleTypeSpecifier(getLangOpts()))
16131613
// We are trying to parse a simple-type-specifier but might not get such
16141614
// a token after error recovery.
16151615
return ExprError();

clang/lib/Parse/ParseObjc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2971,7 +2971,7 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) {
29712971
tok::annot_cxxscope))
29722972
TryAnnotateTypeOrScopeToken();
29732973

2974-
if (!Actions.isSimpleTypeSpecifier(Tok)) {
2974+
if (!Tok.isSimpleTypeSpecifier(getLangOpts())) {
29752975
// objc-receiver:
29762976
// expression
29772977
// Make sure any typos in the receiver are corrected or diagnosed, so that

clang/lib/Sema/SemaDecl.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -127,51 +127,6 @@ class TypeNameValidatorCCC final : public CorrectionCandidateCallback {
127127

128128
} // end anonymous namespace
129129

130-
/// Determine whether the token kind starts a simple-type-specifier.
131-
bool Sema::isSimpleTypeSpecifier(const Token &Tok) const {
132-
switch (Tok.getKind()) {
133-
case tok::annot_typename:
134-
case tok::annot_decltype:
135-
case tok::annot_pack_indexing_type:
136-
return true;
137-
138-
case tok::kw_short:
139-
case tok::kw_long:
140-
case tok::kw___int64:
141-
case tok::kw___int128:
142-
case tok::kw_signed:
143-
case tok::kw_unsigned:
144-
case tok::kw_void:
145-
case tok::kw_char:
146-
case tok::kw_int:
147-
case tok::kw_half:
148-
case tok::kw_float:
149-
case tok::kw_double:
150-
case tok::kw___bf16:
151-
case tok::kw__Float16:
152-
case tok::kw___float128:
153-
case tok::kw___ibm128:
154-
case tok::kw_wchar_t:
155-
case tok::kw_bool:
156-
case tok::kw__Bool:
157-
case tok::kw__Accum:
158-
case tok::kw__Fract:
159-
case tok::kw__Sat:
160-
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
161-
#include "clang/Basic/TransformTypeTraits.def"
162-
case tok::kw___auto_type:
163-
case tok::kw_char16_t:
164-
case tok::kw_char32_t:
165-
case tok::kw_typeof:
166-
case tok::kw_decltype:
167-
case tok::kw_char8_t:
168-
return Tok.getIdentifierInfo()->isKeyword(getLangOpts());
169-
170-
default:
171-
return false;
172-
}
173-
}
174-
175130
namespace {
176131
enum class UnqualifiedTypeNameLookupResult {
177132
NotFound,

0 commit comments

Comments
 (0)