Skip to content

Commit fb81721

Browse files
tbaederrJaddyen
authored andcommitted
[clang][NFC] Clean up ASTContext.cpp (llvm#140847)
Use BuiltinType::{isInteger,isSignedInteger,isUnsignedInteger} instead of doing the comparisons here.
1 parent 4dfcc02 commit fb81721

File tree

2 files changed

+18
-32
lines changed

2 files changed

+18
-32
lines changed

clang/include/clang/AST/Type.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8583,8 +8583,7 @@ bool IsEnumDeclScoped(EnumDecl *);
85838583

85848584
inline bool Type::isIntegerType() const {
85858585
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8586-
return BT->getKind() >= BuiltinType::Bool &&
8587-
BT->getKind() <= BuiltinType::Int128;
8586+
return BT->isInteger();
85888587
if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
85898588
// Incomplete enum types are not treated as integer types.
85908589
// FIXME: In C++, enum types are never integer types.
@@ -8658,8 +8657,7 @@ inline bool Type::isScalarType() const {
86588657

86598658
inline bool Type::isIntegralOrEnumerationType() const {
86608659
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8661-
return BT->getKind() >= BuiltinType::Bool &&
8662-
BT->getKind() <= BuiltinType::Int128;
8660+
return BT->isInteger();
86638661

86648662
// Check for a complete enum type; incomplete enum types are not properly an
86658663
// enumeration type in the sense required here.

clang/lib/AST/Type.cpp

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,8 +2108,7 @@ bool Type::hasIntegerRepresentation() const {
21082108
/// \returns true if the type is considered an integral type, false otherwise.
21092109
bool Type::isIntegralType(const ASTContext &Ctx) const {
21102110
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2111-
return BT->getKind() >= BuiltinType::Bool &&
2112-
BT->getKind() <= BuiltinType::Int128;
2111+
return BT->isInteger();
21132112

21142113
// Complete enum types are integral in C.
21152114
if (!Ctx.getLangOpts().CPlusPlus)
@@ -2121,8 +2120,7 @@ bool Type::isIntegralType(const ASTContext &Ctx) const {
21212120

21222121
bool Type::isIntegralOrUnscopedEnumerationType() const {
21232122
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2124-
return BT->getKind() >= BuiltinType::Bool &&
2125-
BT->getKind() <= BuiltinType::Int128;
2123+
return BT->isInteger();
21262124

21272125
if (isBitIntType())
21282126
return true;
@@ -2211,10 +2209,8 @@ bool Type::isUnicodeCharacterType() const {
22112209
/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
22122210
/// an enum decl which has a signed representation
22132211
bool Type::isSignedIntegerType() const {
2214-
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2215-
return BT->getKind() >= BuiltinType::Char_S &&
2216-
BT->getKind() <= BuiltinType::Int128;
2217-
}
2212+
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2213+
return BT->isSignedInteger();
22182214

22192215
if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
22202216
// Incomplete enum types are not treated as integer types.
@@ -2232,15 +2228,12 @@ bool Type::isSignedIntegerType() const {
22322228
}
22332229

22342230
bool Type::isSignedIntegerOrEnumerationType() const {
2235-
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2236-
return BT->getKind() >= BuiltinType::Char_S &&
2237-
BT->getKind() <= BuiltinType::Int128;
2238-
}
2231+
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2232+
return BT->isSignedInteger();
22392233

2240-
if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2241-
if (ET->getDecl()->isComplete())
2242-
return ET->getDecl()->getIntegerType()->isSignedIntegerType();
2243-
}
2234+
if (const auto *ET = dyn_cast<EnumType>(CanonicalType);
2235+
ET && ET->getDecl()->isComplete())
2236+
return ET->getDecl()->getIntegerType()->isSignedIntegerType();
22442237

22452238
if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
22462239
return IT->isSigned();
@@ -2261,10 +2254,8 @@ bool Type::hasSignedIntegerRepresentation() const {
22612254
/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
22622255
/// decl which has an unsigned representation
22632256
bool Type::isUnsignedIntegerType() const {
2264-
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2265-
return BT->getKind() >= BuiltinType::Bool &&
2266-
BT->getKind() <= BuiltinType::UInt128;
2267-
}
2257+
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2258+
return BT->isUnsignedInteger();
22682259

22692260
if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
22702261
// Incomplete enum types are not treated as integer types.
@@ -2282,15 +2273,12 @@ bool Type::isUnsignedIntegerType() const {
22822273
}
22832274

22842275
bool Type::isUnsignedIntegerOrEnumerationType() const {
2285-
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2286-
return BT->getKind() >= BuiltinType::Bool &&
2287-
BT->getKind() <= BuiltinType::UInt128;
2288-
}
2276+
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2277+
return BT->isUnsignedInteger();
22892278

2290-
if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2291-
if (ET->getDecl()->isComplete())
2292-
return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
2293-
}
2279+
if (const auto *ET = dyn_cast<EnumType>(CanonicalType);
2280+
ET && ET->getDecl()->isComplete())
2281+
return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
22942282

22952283
if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
22962284
return IT->isUnsigned();

0 commit comments

Comments
 (0)