Skip to content

Commit a165026

Browse files
authored
fix(parser): Implemented __is_floating_point
1 parent 927b7c8 commit a165026

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/cxx/semantics.cc

+11-1
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,12 @@ void Semantics::visit(TypeTraitsExpressionAST* ast) {
683683
break;
684684
}
685685

686+
case TokenKind::T___IS_FLOATING_POINT: {
687+
ast->constValue = std::uint64_t(
688+
Type::is<FloatingPointType>(ast->typeIdList->value->type));
689+
break;
690+
}
691+
686692
case TokenKind::T___IS_ENUM: {
687693
auto ty = ast->typeIdList->value->type;
688694
ast->constValue =
@@ -1450,11 +1456,15 @@ void Semantics::visit(IntegralTypeSpecifierAST* ast) {
14501456
break;
14511457

14521458
case TokenKind::T_LONG: {
1453-
auto ty = dynamic_cast<const IntegerType*>(specifiers_->type.type());
1459+
auto ty = Type::cast<IntegerType>(specifiers_->type);
14541460

14551461
if (ty && ty->kind() == IntegerKind::kLong) {
14561462
specifiers_->type.setType(types_->integerType(IntegerKind::kLongLong,
14571463
specifiers_->isUnsigned));
1464+
} else if (auto floatTy =
1465+
Type::cast<FloatingPointType>(specifiers_->type)) {
1466+
specifiers_->type.setType(
1467+
types_->floatingPointType(FloatingPointKind::kLongDouble));
14581468
} else {
14591469
specifiers_->type.setType(
14601470
types_->integerType(IntegerKind::kLong, specifiers_->isUnsigned));

tests/unit_tests/parser/type_traits.001.cc

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %cxx -verify -fsyntax-only %s -o -
22

3+
// __is_void
4+
35
static_assert(__is_void(int) == false);
46
static_assert(__is_void(void) == true);
57
static_assert(__is_void(void*) == false);
@@ -8,9 +10,22 @@ static_assert(__is_void(volatile void) == true);
810
static_assert(__is_void(const volatile void) == true);
911

1012
static_assert(__is_same(decltype(__is_void(void)), bool) == true);
11-
1213
static_assert(__is_same(decltype(__is_void(void)), int) == false);
1314

15+
// __is_floating_point
16+
17+
static_assert(__is_floating_point(float) == true);
18+
static_assert(__is_floating_point(double) == true);
19+
static_assert(__is_floating_point(long double) == true);
20+
static_assert(__is_floating_point(double long) == true);
21+
static_assert(__is_floating_point(const float) == true);
22+
static_assert(__is_floating_point(const double) == true);
23+
static_assert(__is_floating_point(const long double) == true);
24+
static_assert(__is_floating_point(float*) == false);
25+
static_assert(__is_floating_point(float&) == false);
26+
27+
// __is_pointer
28+
1429
static_assert(__is_pointer(void*) == true);
1530

1631
int* p;
@@ -166,7 +181,7 @@ static_assert(__is_member_object_pointer(decltype(intField)) == true);
166181
static_assert(__is_member_object_pointer(IntFieldT) == true);
167182
static_assert(__is_member_object_pointer(int(Class::*)) == true);
168183

169-
static_assert(__is_member_object_pointer(int (Class::*)()) == false);
184+
static_assert(__is_member_object_pointer(int(Class::*)()) == false);
170185

171186
namespace ns {
172187
struct list {

0 commit comments

Comments
 (0)