[qfcc] Use pr_type_names to generate is_TYPE

This means basic types will always have a check function automatically.
This commit is contained in:
Bill Currie 2022-01-19 17:48:46 +09:00
parent 380cb3ba7f
commit e11fa77a34
8 changed files with 32 additions and 148 deletions

View file

@ -149,26 +149,17 @@ void dump_dot_type (void *t, const char *filename);
const char *encode_params (const type_t *type);
void encode_type (struct dstring_s *encoding, const type_t *type);
const char *type_get_encoding (const type_t *type);
int is_void (const type_t *type) __attribute__((pure));
#define EV_TYPE(t) int is_##t (const type_t *type) __attribute__((pure));
#include "QF/progs/pr_type_names.h"
int is_enum (const type_t *type) __attribute__((pure));
int is_int (const type_t *type) __attribute__((pure));
int is_uint (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));
int is_scalar (const type_t *type) __attribute__((pure));
int is_vector (const type_t *type) __attribute__((pure));
int is_quaternion (const type_t *type) __attribute__((pure));
int is_math (const type_t *type) __attribute__((pure));
int is_pointer (const type_t *type) __attribute__((pure));
int is_field (const type_t *type) __attribute__((pure));
int is_entity (const type_t *type) __attribute__((pure));
int is_struct (const type_t *type) __attribute__((pure));
int is_array (const type_t *type) __attribute__((pure));
int is_structural (const type_t *type) __attribute__((pure));
int is_func (const type_t *type) __attribute__((pure));
int is_string (const type_t *type) __attribute__((pure));
int type_compatible (const type_t *dst, const type_t *src) __attribute__((pure));
int type_assignable (const type_t *dst, const type_t *src);
int type_same (const type_t *dst, const type_t *src) __attribute__((pure));

View file

@ -391,7 +391,7 @@ is_method_description (const type_t *type)
static protocollist_t *
obj_get_class_protos (const type_t *type)
{
if (is_pointer (type))
if (is_ptr (type))
type = type->t.fldptr.type;
if (is_class (type))
return type->t.class->protocols;
@ -401,7 +401,7 @@ obj_get_class_protos (const type_t *type)
static protocollist_t *
obj_get_protos (const type_t *type)
{
if (is_pointer (type))
if (is_ptr (type))
type = type->t.fldptr.type;
return type->protos;
}
@ -409,7 +409,7 @@ obj_get_protos (const type_t *type)
static category_t *
obj_get_categories (const type_t *type)
{
if (is_pointer (type))
if (is_ptr (type))
type = type->t.fldptr.type;
if (is_class (type))
return type->t.class->categories;
@ -430,7 +430,7 @@ obj_classname (const type_t *type)
} else if (is_Class (type)) {
dstring_copystr (str, "Class");
} else {
if (is_pointer (type))
if (is_ptr (type))
type = type->t.fldptr.type;
if (is_class (type))
dstring_copystr (str, type->t.class->name);
@ -1738,7 +1738,7 @@ emit_protocol (protocol_t *protocol)
static void
emit_protocol_next (def_t *def, void *data, int index)
{
if (!is_pointer(def->type)) {
if (!is_ptr(def->type)) {
internal_error (0, "%s: expected pointer def", __FUNCTION__);
}
D_INT (def) = 0;
@ -1761,7 +1761,7 @@ emit_protocol_list_item (def_t *def, void *data, int index)
protocollist_t *protocols = (protocollist_t *) data;
protocol_t *protocol = protocols->list[index];
if (!is_array (def->type) || !is_pointer(def->type->t.array.type)) {
if (!is_array (def->type) || !is_ptr(def->type->t.array.type)) {
internal_error (0, "%s: expected array of pointer def", __FUNCTION__);
}
if (index < 0 || index >= protocols->count) {

View file

@ -90,8 +90,7 @@ get_value_def (expr_t *expr, ex_value_t *value, type_t *type)
def->offset = value->v.short_val;
return def;
}
if (is_pointer (type) && value->v.pointer.tempop
&& !value->v.pointer.def) {
if (is_ptr (type) && value->v.pointer.tempop && !value->v.pointer.def) {
value->v.pointer.def = get_tempop_def (expr, value->v.pointer.tempop,
type->t.fldptr.type);
}

View file

@ -2816,15 +2816,14 @@ cast_expr (type_t *dstType, expr_t *e)
if ((dstType == type_default && is_enum (srcType))
|| (is_enum (dstType) && srcType == type_default))
return e;
if ((is_pointer (dstType) && is_string (srcType))
|| (is_string (dstType) && is_pointer (srcType))) {
if ((is_ptr (dstType) && is_string (srcType))
|| (is_string (dstType) && is_ptr (srcType))) {
c = new_alias_expr (dstType, e);
return c;
}
if (!(is_pointer (dstType)
&& (is_pointer (srcType) || is_integral (srcType)
if (!(is_ptr (dstType) && (is_ptr (srcType) || is_integral (srcType)
|| is_array (srcType)))
&& !(is_integral (dstType) && is_pointer (srcType))
&& !(is_integral (dstType) && is_ptr (srcType))
&& !(is_func (dstType) && is_func (srcType))
&& !(is_scalar (dstType) && is_scalar (srcType))) {
return cast_error (e, srcType, dstType);

View file

@ -329,7 +329,7 @@ assign_expr (expr_t *dst, expr_t *src)
internal_error (src, "src_type broke in assign_expr");
}
if (is_pointer (dst_type) && is_array (src_type)) {
if (is_ptr (dst_type) && is_array (src_type)) {
// assigning an array to a pointer is the same as taking the address of
// the array but using the type of the array elements
src = address_expr (src, 0, src_type->t.fldptr.type);

View file

@ -646,10 +646,10 @@ pointer_arithmetic (int op, expr_t *e1, expr_t *e2)
expr_t *psize;
type_t *ptype;
if (!is_pointer (t1) && !is_pointer (t2)) {
if (!is_ptr (t1) && !is_ptr (t2)) {
internal_error (e1, "pointer arithmetic on non-pointers");
}
if (is_pointer (t1) && is_pointer (t2)) {
if (is_ptr (t1) && is_ptr (t2)) {
if (op != '-') {
return error (e2, "invalid pointer operation");
}
@ -661,11 +661,11 @@ pointer_arithmetic (int op, expr_t *e1, expr_t *e2)
e2 = cast_expr (&type_int, e2);
psize = new_int_expr (type_size (t1->t.fldptr.type));
return binary_expr ('/', binary_expr ('-', e1, e2), psize);
} else if (is_pointer (t1)) {
} else if (is_ptr (t1)) {
offset = cast_expr (&type_int, e2);
ptr = cast_expr (&type_int, e1);
ptype = t1;
} else if (is_pointer (t2)) {
} else if (is_ptr (t2)) {
offset = cast_expr (&type_int, e1);
ptr = cast_expr (&type_int, e2);
ptype = t2;

View file

@ -533,7 +533,7 @@ emit_selectors (void)
static void
emit_methods_next (def_t *def, void *data, int index)
{
if (!is_pointer(def->type))
if (!is_ptr(def->type))
internal_error (0, "%s: expected pointer def", __FUNCTION__);
D_INT (def) = 0;
}

View file

@ -554,7 +554,7 @@ unalias_type (const type_t *type)
const type_t *
dereference_type (const type_t *type)
{
if (!is_pointer (type) && !is_field (type)) {
if (!is_ptr (type) && !is_field (type)) {
internal_error (0, "dereference non pointer/field type");
}
if (type->meta == ty_alias) {
@ -836,12 +836,13 @@ encode_type (dstring_t *encoding, const type_t *type)
internal_error (0, "bad type meta:type %d:%d", type->meta, type->type);
}
int
is_void (const type_t *type)
{
type = unalias_type (type);
return type->type == ev_void;
#define EV_TYPE(t) \
int is_##t (const type_t *type) \
{ \
type = unalias_type (type); \
return type->type == ev_##t; \
}
#include "QF/progs/pr_type_names.h"
int
is_enum (const type_t *type)
@ -852,39 +853,6 @@ is_enum (const type_t *type)
return 0;
}
int
is_int (const type_t *type)
{
type = unalias_type (type);
etype_t t = type->type;
if (t == ev_int)
return 1;
return is_enum (type);
}
int
is_uint (const type_t *type)
{
type = unalias_type (type);
etype_t t = type->type;
if (t == ev_uint)
return 1;
return is_enum (type);
}
int
is_short (const type_t *type)
{
type = unalias_type (type);
etype_t t = type->type;
if (t == ev_short)
return 1;
return is_enum (type);
}
int
is_integral (const type_t *type)
{
@ -894,20 +862,6 @@ is_integral (const type_t *type)
return is_enum (type);
}
int
is_double (const type_t *type)
{
type = unalias_type (type);
return type->type == ev_double;
}
int
is_float (const type_t *type)
{
type = unalias_type (type);
return type->type == ev_float;
}
int
is_scalar (const type_t *type)
{
@ -915,20 +869,6 @@ is_scalar (const type_t *type)
return is_float (type) || is_integral (type) || is_double (type);
}
int
is_vector (const type_t *type)
{
type = unalias_type (type);
return type->type == ev_vector;
}
int
is_quaternion (const type_t *type)
{
type = unalias_type (type);
return type->type == ev_quaternion;
}
int
is_math (const type_t *type)
{
@ -948,33 +888,6 @@ is_struct (const type_t *type)
return 0;
}
int
is_pointer (const type_t *type)
{
type = unalias_type (type);
if (type->type == ev_ptr)
return 1;
return 0;
}
int
is_field (const type_t *type)
{
type = unalias_type (type);
if (type->type == ev_field)
return 1;
return 0;
}
int
is_entity (const type_t *type)
{
type = unalias_type (type);
if (type->type == ev_entity)
return 1;
return 0;
}
int
is_array (const type_t *type)
{
@ -984,15 +897,6 @@ is_array (const type_t *type)
return 0;
}
int
is_func (const type_t *type)
{
type = unalias_type (type);
if (type->type == ev_func)
return 1;
return 0;
}
int
is_structural (const type_t *type)
{
@ -1000,15 +904,6 @@ is_structural (const type_t *type)
return is_struct (type) || is_array (type);
}
int
is_string (const type_t *type)
{
type = unalias_type (type);
if (type->type == ev_string)
return 1;
return 0;
}
int
type_compatible (const type_t *dst, const type_t *src)
{
@ -1022,7 +917,7 @@ type_compatible (const type_t *dst, const type_t *src)
if (is_func (dst) && is_func (src)) {
return 1;
}
if (is_pointer (dst) && is_pointer (src)) {
if (is_ptr (dst) && is_ptr (src)) {
return 1;
}
return 0;
@ -1042,12 +937,12 @@ type_assignable (const type_t *dst, const type_t *src)
if (dst->type == ev_field && src->type == ev_field)
return 1;
// pointer = array
if (is_pointer (dst) && is_array (src)) {
if (is_ptr (dst) && is_array (src)) {
if (dst->t.fldptr.type == src->t.array.type)
return 1;
return 0;
}
if (!is_pointer (dst) || !is_pointer (src))
if (!is_ptr (dst) || !is_ptr (src))
return is_scalar (dst) && is_scalar (src);
// pointer = pointer