[clang] [clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (PR #80101)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/80101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (PR #80101)
https://github.com/cor3ntin approved this pull request. https://github.com/llvm/llvm-project/pull/80101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (PR #80101)
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/80101 >From f3ad3ceebba663615e75b5a6fc8969f4a98a03ea Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Tue, 30 Jan 2024 19:11:30 -0800 Subject: [PATCH 1/2] [clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token So that it can be used by clang-format. --- clang/include/clang/Lex/Token.h | 3 +++ clang/include/clang/Sema/Sema.h | 2 -- clang/lib/Lex/Lexer.cpp | 45 + clang/lib/Parse/ParseExpr.cpp | 2 +- clang/lib/Parse/ParseObjc.cpp | 2 +- clang/lib/Sema/SemaDecl.cpp | 45 - 6 files changed, 50 insertions(+), 49 deletions(-) diff --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h index 1409e2c58b550..0a9c73d120de2 100644 --- a/clang/include/clang/Lex/Token.h +++ b/clang/include/clang/Lex/Token.h @@ -13,6 +13,7 @@ #ifndef LLVM_CLANG_LEX_TOKEN_H #define LLVM_CLANG_LEX_TOKEN_H +#include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/TokenKinds.h" #include "llvm/ADT/ArrayRef.h" @@ -288,6 +289,8 @@ class Token { /// Return the ObjC keyword kind. tok::ObjCKeywordKind getObjCKeywordID() const; + bool isSimpleTypeSpecifier(const LangOptions ) 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 490df817ddfa2..3b42850a7a85a 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2683,8 +2683,6 @@ class Sema final { void DiagnoseUseOfUnimplementedSelectors(); - bool isSimpleTypeSpecifier(const Token ) const; - ParsedType getTypeName(const IdentifierInfo , 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 50b56265f6e16..d927f28b47c27 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 ) 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 e5d4285b99183..52cebdb6f64ba 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 4771b69eadb34..88bab0eb27a3e 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -2971,7 +2971,7 @@ bool Parser::ParseObjCXXMessageReceiver(bool , void *) { 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 00c750e42285c..fd1c47008d685 100644 ---
[clang] [clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (PR #80101)
@@ -13,6 +13,7 @@ #ifndef LLVM_CLANG_LEX_TOKEN_H #define LLVM_CLANG_LEX_TOKEN_H +#include "clang/Basic/LangOptions.h" tbaederr wrote: I think we can get by with a forward-declaration of `LangOptions` instead of the include here? https://github.com/llvm/llvm-project/pull/80101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (PR #80101)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Owen Pan (owenca) Changes So that it can be used by clang-format. --- Full diff: https://github.com/llvm/llvm-project/pull/80101.diff 6 Files Affected: - (modified) clang/include/clang/Lex/Token.h (+3) - (modified) clang/include/clang/Sema/Sema.h (-2) - (modified) clang/lib/Lex/Lexer.cpp (+45) - (modified) clang/lib/Parse/ParseExpr.cpp (+1-1) - (modified) clang/lib/Parse/ParseObjc.cpp (+1-1) - (modified) clang/lib/Sema/SemaDecl.cpp (-45) ``diff diff --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h index 1409e2c58b550..0a9c73d120de2 100644 --- a/clang/include/clang/Lex/Token.h +++ b/clang/include/clang/Lex/Token.h @@ -13,6 +13,7 @@ #ifndef LLVM_CLANG_LEX_TOKEN_H #define LLVM_CLANG_LEX_TOKEN_H +#include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/TokenKinds.h" #include "llvm/ADT/ArrayRef.h" @@ -288,6 +289,8 @@ class Token { /// Return the ObjC keyword kind. tok::ObjCKeywordKind getObjCKeywordID() const; + bool isSimpleTypeSpecifier(const LangOptions ) 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 490df817ddfa2..3b42850a7a85a 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2683,8 +2683,6 @@ class Sema final { void DiagnoseUseOfUnimplementedSelectors(); - bool isSimpleTypeSpecifier(const Token ) const; - ParsedType getTypeName(const IdentifierInfo , 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 50b56265f6e16..d927f28b47c27 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 ) 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 e5d4285b99183..52cebdb6f64ba 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 4771b69eadb34..88bab0eb27a3e 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -2971,7 +2971,7 @@ bool Parser::ParseObjCXXMessageReceiver(bool , void *) { 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 00c750e42285c..fd1c47008d685 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -127,51 +127,6 @@ class TypeNameValidatorCCC final : public CorrectionCandidateCallback { } // end anonymous
[clang] [clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (PR #80101)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/80101 So that it can be used by clang-format. >From f3ad3ceebba663615e75b5a6fc8969f4a98a03ea Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Tue, 30 Jan 2024 19:11:30 -0800 Subject: [PATCH] [clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token So that it can be used by clang-format. --- clang/include/clang/Lex/Token.h | 3 +++ clang/include/clang/Sema/Sema.h | 2 -- clang/lib/Lex/Lexer.cpp | 45 + clang/lib/Parse/ParseExpr.cpp | 2 +- clang/lib/Parse/ParseObjc.cpp | 2 +- clang/lib/Sema/SemaDecl.cpp | 45 - 6 files changed, 50 insertions(+), 49 deletions(-) diff --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h index 1409e2c58b550..0a9c73d120de2 100644 --- a/clang/include/clang/Lex/Token.h +++ b/clang/include/clang/Lex/Token.h @@ -13,6 +13,7 @@ #ifndef LLVM_CLANG_LEX_TOKEN_H #define LLVM_CLANG_LEX_TOKEN_H +#include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/TokenKinds.h" #include "llvm/ADT/ArrayRef.h" @@ -288,6 +289,8 @@ class Token { /// Return the ObjC keyword kind. tok::ObjCKeywordKind getObjCKeywordID() const; + bool isSimpleTypeSpecifier(const LangOptions ) 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 490df817ddfa2..3b42850a7a85a 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2683,8 +2683,6 @@ class Sema final { void DiagnoseUseOfUnimplementedSelectors(); - bool isSimpleTypeSpecifier(const Token ) const; - ParsedType getTypeName(const IdentifierInfo , 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 50b56265f6e16..d927f28b47c27 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 ) 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 e5d4285b99183..52cebdb6f64ba 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 4771b69eadb34..88bab0eb27a3e 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -2971,7 +2971,7 @@ bool Parser::ParseObjCXXMessageReceiver(bool , void *) { 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