From fd2b7ee6f9caedc870ef0ea2a1d2d18540a317d6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 19 Feb 2020 21:13:36 +0900 Subject: [PATCH] Use more type checking helper functions --- tools/qfcc/include/type.h | 3 +++ tools/qfcc/source/expr.c | 6 +++--- tools/qfcc/source/type.c | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/tools/qfcc/include/type.h b/tools/qfcc/include/type.h index 098df5e00..17f21665d 100644 --- a/tools/qfcc/include/type.h +++ b/tools/qfcc/include/type.h @@ -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)); diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index da96bd5fc..44032eb5d 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -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 { diff --git a/tools/qfcc/source/type.c b/tools/qfcc/source/type.c index 4453e6284..0622d392e 100644 --- a/tools/qfcc/source/type.c +++ b/tools/qfcc/source/type.c @@ -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); }