Use more type checking helper functions

This commit is contained in:
Bill Currie 2020-02-19 21:13:36 +09:00
parent a6003ed08a
commit fd2b7ee6f9
3 changed files with 36 additions and 5 deletions

View file

@ -163,6 +163,9 @@ const char *type_get_encoding (const type_t *type);
const type_t *unalias_type (const type_t *type) __attribute__((pure));
int is_void (const type_t *type) __attribute__((pure));
int is_enum (const type_t *type) __attribute__((pure));
int is_integer (const type_t *type) __attribute__((pure));
int is_uinteger (const type_t *type) __attribute__((pure));
int is_short (const type_t *type) __attribute__((pure));
int is_integral (const type_t *type) __attribute__((pure));
int is_double (const type_t *type) __attribute__((pure));
int is_float (const type_t *type) __attribute__((pure));

View file

@ -1459,15 +1459,15 @@ convert_from_bool (expr_t *e, type_t *type)
expr_t *one;
expr_t *cond;
if (type == &type_float) {
if (is_float (type)) {
one = new_float_expr (1);
zero = new_float_expr (0);
} else if (type == &type_integer) {
} else if (is_integer (type)) {
one = new_integer_expr (1);
zero = new_integer_expr (0);
} else if (is_enum (type) && enum_as_bool (type, &zero, &one)) {
// don't need to do anything
} else if (type == &type_uinteger) {
} else if (is_uinteger (type)) {
one = new_uinteger_expr (1);
zero = new_uinteger_expr (0);
} else {

View file

@ -750,11 +750,39 @@ is_enum (const type_t *type)
}
int
is_integral (const type_t *type)
is_integer (const type_t *type)
{
etype_t t = type->type;
if (t == ev_integer || t == ev_uinteger || t == ev_short)
if (t == ev_integer)
return 1;
return is_enum (type);
}
int
is_uinteger (const type_t *type)
{
etype_t t = type->type;
if (t == ev_uinteger)
return 1;
return is_enum (type);
}
int
is_short (const type_t *type)
{
etype_t t = type->type;
if (t == ev_short)
return 1;
return is_enum (type);
}
int
is_integral (const type_t *type)
{
if (is_integer (type) || is_uinteger (type) || is_short (type))
return 1;
return is_enum (type);
}