Skip to content

Commit 3e0c377

Browse files
authored
fix(parser): Implemented __is_arithmetic
1 parent 1891675 commit 3e0c377

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

Diff for: src/cxx/semantics.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,13 @@ void Semantics::visit(TypeTraitsExpressionAST* ast) {
691691

692692
case TokenKind::T___IS_INTEGRAL: {
693693
auto ty = ast->typeIdList->value->type;
694+
ast->constValue = std::uint64_t(ty->isIntegral());
695+
break;
696+
}
694697

695-
ast->constValue = std::uint64_t(Type::is<BooleanType>(ty) ||
696-
Type::is<CharacterType>(ty) ||
697-
Type::is<IntegerType>(ty));
698+
case TokenKind::T___IS_ARITHMETIC: {
699+
auto ty = ast->typeIdList->value->type;
700+
ast->constValue = std::uint64_t(ty->isArithmetic());
698701
break;
699702
}
700703

Diff for: src/cxx/types.cc

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ namespace cxx {
2525

2626
Type::~Type() {}
2727

28+
bool Type::isIntegral() const {
29+
return Type::is<BooleanType>(this) || Type::is<CharacterType>(this) ||
30+
Type::is<IntegerType>(this);
31+
}
32+
33+
bool Type::isArithmetic() const {
34+
return isIntegral() || Type::is<FloatingPointType>(this);
35+
}
36+
2837
const UndefinedType* UndefinedType::get() {
2938
static UndefinedType type;
3039
return &type;

Diff for: src/cxx/types.h

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class Type {
3434

3535
virtual void accept(TypeVisitor* visitor) const = 0;
3636

37+
bool isIntegral() const;
38+
bool isArithmetic() const;
39+
3740
template <typename T>
3841
static const T* cast(const QualifiedType& qualType) {
3942
return dynamic_cast<const T*>(qualType.type());

Diff for: tests/unit_tests/parser/type_traits.001.cc

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// RUN: %cxx -verify -fsyntax-only %s -o -
22

3+
enum ee {};
4+
enum class sc {};
5+
6+
struct F;
7+
struct S {};
8+
class C {};
9+
10+
union V;
11+
union U {};
12+
313
// __is_void
414

515
static_assert(__is_void(int) == false);
@@ -32,6 +42,8 @@ static_assert(__is_integral(float) == false);
3242
static_assert(__is_integral(double) == false);
3343
static_assert(__is_integral(long double) == false);
3444
static_assert(__is_integral(void*) == false);
45+
static_assert(__is_integral(ee) == false);
46+
static_assert(__is_integral(sc) == false);
3547

3648
// __is_floating_point
3749

@@ -129,9 +141,6 @@ static_assert(__is_unsigned(long long) == false);
129141

130142
// __is_enum and __is_scoped_enum
131143

132-
enum ee {};
133-
enum class sc {};
134-
135144
static_assert(__is_enum(ee) == true);
136145
static_assert(__is_enum(sc) == true);
137146

@@ -140,13 +149,6 @@ static_assert(__is_scoped_enum(ee) == false);
140149

141150
// __is_class and __is_union
142151

143-
struct F;
144-
struct S {};
145-
class C {};
146-
147-
union V;
148-
union U {};
149-
150152
static_assert(__is_class(F) == true);
151153
static_assert(__is_class(S) == true);
152154
static_assert(__is_class(C) == true);
@@ -213,3 +215,11 @@ struct list {
213215
} // namespace ns
214216

215217
static_assert(__is_member_object_pointer(int(ns::list::iterator::*)) == true);
218+
219+
// __is_artithmetic
220+
221+
static_assert(__is_arithmetic(bool) == true);
222+
static_assert(__is_arithmetic(int) == true);
223+
static_assert(__is_arithmetic(float) == true);
224+
static_assert(__is_arithmetic(double) == true);
225+
static_assert(__is_arithmetic(int*) == false);

0 commit comments

Comments
 (0)