mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 06:10:56 +00:00
[qfcc] Clean up simple type checking
All simple type checks are now done using is_* helper functions. This will help hide the implementation details of the type system from the rest of the compiler (especially the changes needed for type aliasing).
This commit is contained in:
parent
8b1e4eea58
commit
ab3d91f0c3
17 changed files with 133 additions and 104 deletions
|
@ -115,10 +115,14 @@ struct method_s;
|
|||
struct symbol_s;
|
||||
struct selector_s;
|
||||
|
||||
int obj_is_id (const struct type_s *type) __attribute__((pure));
|
||||
int obj_is_class (const struct type_s *type) __attribute__((pure));
|
||||
int obj_is_Class (const struct type_s *type) __attribute__((const));
|
||||
int obj_is_classptr (const struct type_s *type) __attribute__((pure));
|
||||
int is_id (const struct type_s *type) __attribute__((pure));
|
||||
int is_class (const struct type_s *type) __attribute__((pure));
|
||||
int is_Class (const struct type_s *type) __attribute__((const));
|
||||
int is_classptr (const struct type_s *type) __attribute__((pure));
|
||||
int is_SEL (const struct type_s *type) __attribute__((pure));
|
||||
int is_object (const struct type_s *type) __attribute__((pure));
|
||||
int is_method (const struct type_s *type) __attribute__((pure));
|
||||
int is_method_description (const struct type_s *type) __attribute__((pure));
|
||||
int obj_types_assignable (const struct type_s *dst, const struct type_s *src);
|
||||
|
||||
class_t *extract_class (class_type_t *class_type) __attribute__((pure));
|
||||
|
|
|
@ -218,7 +218,7 @@ emit_instance_classname (def_t *def, void *data, int index)
|
|||
{
|
||||
obj_static_instances_data_t *da = (obj_static_instances_data_t *)data;
|
||||
|
||||
if (def->type != &type_string)
|
||||
if (!is_string(def->type))
|
||||
internal_error (0, "%s: expected string def", __FUNCTION__);
|
||||
EMIT_STRING (def->space, D_STRING (def), da->class_name);
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ emit_static_instances_list (void)
|
|||
}
|
||||
|
||||
int
|
||||
obj_is_id (const type_t *type)
|
||||
is_id (const type_t *type)
|
||||
{
|
||||
if (type == &type_id)
|
||||
return 1;
|
||||
|
@ -334,7 +334,7 @@ obj_is_id (const type_t *type)
|
|||
}
|
||||
|
||||
int
|
||||
obj_is_class (const type_t *type)
|
||||
is_class (const type_t *type)
|
||||
{
|
||||
if (type->type == ev_invalid && type->meta == ty_class)
|
||||
return 1;
|
||||
|
@ -342,7 +342,7 @@ obj_is_class (const type_t *type)
|
|||
}
|
||||
|
||||
int
|
||||
obj_is_Class (const type_t *type)
|
||||
is_Class (const type_t *type)
|
||||
{
|
||||
if (type == &type_Class)
|
||||
return 1;
|
||||
|
@ -350,25 +350,49 @@ obj_is_Class (const type_t *type)
|
|||
}
|
||||
|
||||
int
|
||||
obj_is_classptr (const type_t *type)
|
||||
is_classptr (const type_t *type)
|
||||
{
|
||||
// easy cases first :)
|
||||
if (obj_is_id (type) || obj_is_Class (type))
|
||||
if (is_id (type) || is_Class (type))
|
||||
return 1;
|
||||
if (type->type != ev_pointer)
|
||||
return 0;
|
||||
type = type->t.fldptr.type;
|
||||
if (obj_is_class (type))
|
||||
if (is_class (type))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
is_SEL (const type_t *type)
|
||||
{
|
||||
return type == &type_SEL;
|
||||
}
|
||||
|
||||
int
|
||||
is_object (const type_t *type)
|
||||
{
|
||||
return type == &type_obj_object;
|
||||
}
|
||||
|
||||
int
|
||||
is_method (const type_t *type)
|
||||
{
|
||||
return type == &type_obj_method;
|
||||
}
|
||||
|
||||
int
|
||||
is_method_description (const type_t *type)
|
||||
{
|
||||
return type == &type_obj_method_description;
|
||||
}
|
||||
|
||||
static protocollist_t *
|
||||
obj_get_class_protos (const type_t *type)
|
||||
{
|
||||
if (is_pointer (type))
|
||||
type = type->t.fldptr.type;
|
||||
if (obj_is_class (type))
|
||||
if (is_class (type))
|
||||
return type->t.class->protocols;
|
||||
return 0;
|
||||
}
|
||||
|
@ -386,7 +410,7 @@ obj_get_categories (const type_t *type)
|
|||
{
|
||||
if (is_pointer (type))
|
||||
type = type->t.fldptr.type;
|
||||
if (obj_is_class (type))
|
||||
if (is_class (type))
|
||||
return type->t.class->categories;
|
||||
return 0;
|
||||
}
|
||||
|
@ -400,14 +424,14 @@ obj_classname (const type_t *type)
|
|||
if (!str)
|
||||
str = dstring_new ();
|
||||
dstring_clearstr (str);
|
||||
if (obj_is_id (type)) {
|
||||
if (is_id (type)) {
|
||||
dstring_copystr (str, "id");
|
||||
} else if (obj_is_Class (type)) {
|
||||
} else if (is_Class (type)) {
|
||||
dstring_copystr (str, "Class");
|
||||
} else {
|
||||
if (is_pointer (type))
|
||||
type = type->t.fldptr.type;
|
||||
if (obj_is_class (type))
|
||||
if (is_class (type))
|
||||
dstring_copystr (str, type->t.class->name);
|
||||
}
|
||||
if ((protos = obj_get_protos (type)))
|
||||
|
@ -437,17 +461,17 @@ obj_types_assignable (const type_t *dst, const type_t *src)
|
|||
int i;
|
||||
|
||||
//puts ("%$$\"$#%");
|
||||
if (!obj_is_classptr (src)) {
|
||||
if (!is_classptr (src)) {
|
||||
// if dst is a class pointer, then the types are not compatible,
|
||||
// otherwise unknown
|
||||
return obj_is_classptr (dst) - 1;
|
||||
return is_classptr (dst) - 1;
|
||||
}
|
||||
if (!obj_is_classptr (dst)) {
|
||||
if (!is_classptr (dst)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
dst_is_proto = obj_is_id (dst) && (dst_protos = obj_get_protos (dst));
|
||||
src_is_proto = obj_is_id (src) && (src_protos = obj_get_protos (src));
|
||||
dst_is_proto = is_id (dst) && (dst_protos = obj_get_protos (dst));
|
||||
src_is_proto = is_id (src) && (src_protos = obj_get_protos (src));
|
||||
|
||||
if (dst_is_proto) {
|
||||
if (src_is_proto) {
|
||||
|
@ -460,7 +484,7 @@ obj_types_assignable (const type_t *dst, const type_t *src)
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
} else if (!obj_is_id (src)) {
|
||||
} else if (!is_id (src)) {
|
||||
src_protos = obj_get_class_protos (src);
|
||||
for (i = 0; i < dst_protos->count; i++) {
|
||||
if (procollist_find_protocol (src_protos, dst_protos->list[i]))
|
||||
|
@ -477,7 +501,7 @@ obj_types_assignable (const type_t *dst, const type_t *src)
|
|||
} else if (src_is_proto) {
|
||||
} else {
|
||||
}
|
||||
if (obj_is_id (dst) || obj_is_id (src))
|
||||
if (is_id (dst) || is_id (src))
|
||||
return 1;
|
||||
|
||||
// check dst is a base class of src
|
||||
|
@ -700,7 +724,7 @@ emit_ivar_count (def_t *def, void *data, int index)
|
|||
{
|
||||
ivar_data_t *ivar_data = (ivar_data_t *) data;
|
||||
|
||||
if (def->type != &type_integer)
|
||||
if (!is_integer(def->type))
|
||||
internal_error (0, "%s: expected integer def", __FUNCTION__);
|
||||
D_INT (def) = ivar_data->count;
|
||||
}
|
||||
|
@ -1132,11 +1156,11 @@ class_message_response (type_t *clstype, int class_msg, expr_t *sel)
|
|||
if (!selector)
|
||||
return 0;
|
||||
|
||||
if (!obj_is_classptr (clstype) && !obj_is_class (clstype)) {
|
||||
if (!is_classptr (clstype) && !is_class (clstype)) {
|
||||
error (0, "neither class nor object");
|
||||
return 0;
|
||||
}
|
||||
if (obj_is_id (clstype)) {
|
||||
if (is_id (clstype)) {
|
||||
protocollist_t *protos = clstype->t.fldptr.type->protos;
|
||||
if (protos) {
|
||||
if ((m = protocollist_find_method (protos, selector, !class_msg))) {
|
||||
|
@ -1149,12 +1173,12 @@ class_message_response (type_t *clstype, int class_msg, expr_t *sel)
|
|||
dstring_delete (dstr);
|
||||
}
|
||||
} else {
|
||||
if (obj_is_class (clstype)) {
|
||||
if (is_class (clstype)) {
|
||||
class = clstype->t.class;
|
||||
} else if (obj_is_class (clstype->t.fldptr.type)) {
|
||||
} else if (is_class (clstype->t.fldptr.type)) {
|
||||
class = clstype->t.fldptr.type->t.class;
|
||||
}
|
||||
if (class && class->type != &type_obj_object) {
|
||||
if (class && !is_object(class->type)) {
|
||||
if (!class->interface_declared) {
|
||||
class->interface_declared = 1;
|
||||
warning (0, "cannot find interface declaration for `%s'",
|
||||
|
@ -1180,7 +1204,7 @@ class_message_response (type_t *clstype, int class_msg, expr_t *sel)
|
|||
}
|
||||
}
|
||||
m = find_method (selector->name);
|
||||
if (!m && (!class || class->type == &type_obj_object)) {
|
||||
if (!m && (!class || is_object(class->type))) {
|
||||
warning (sel, "could not find method for %c%s",
|
||||
class_msg ? '+' : '-', selector->name);
|
||||
}
|
||||
|
@ -1383,7 +1407,7 @@ emit_symtab_ref_cnt (def_t *def, void *data, int index)
|
|||
{
|
||||
obj_symtab_data_t *da = (obj_symtab_data_t *)data;
|
||||
|
||||
if (def->type != &type_integer)
|
||||
if (!is_integer(def->type))
|
||||
internal_error (0, "%s: expected integer def", __FUNCTION__);
|
||||
D_INT (def) = 0;
|
||||
if (da->refs)
|
||||
|
@ -1395,7 +1419,7 @@ emit_symtab_refs (def_t *def, void *data, int index)
|
|||
{
|
||||
obj_symtab_data_t *da = (obj_symtab_data_t *)data;
|
||||
|
||||
if (def->type != &type_SEL)
|
||||
if (!is_SEL(def->type))
|
||||
internal_error (0, "%s: expected SEL def", __FUNCTION__);
|
||||
D_INT (def) = 0;
|
||||
if (da->refs)
|
||||
|
@ -1407,7 +1431,7 @@ emit_symtab_cls_def_cnt (def_t *def, void *data, int index)
|
|||
{
|
||||
obj_symtab_data_t *da = (obj_symtab_data_t *)data;
|
||||
|
||||
if (def->type != &type_integer)
|
||||
if (!is_integer(def->type))
|
||||
internal_error (0, "%s: expected integer def", __FUNCTION__);
|
||||
D_INT (def) = da->cls_def_cnt;
|
||||
}
|
||||
|
@ -1417,7 +1441,7 @@ emit_symtab_cat_def_cnt (def_t *def, void *data, int index)
|
|||
{
|
||||
obj_symtab_data_t *da = (obj_symtab_data_t *)data;
|
||||
|
||||
if (def->type != &type_integer)
|
||||
if (!is_integer(def->type))
|
||||
internal_error (0, "%s: expected integer def", __FUNCTION__);
|
||||
D_INT (def) = da->cat_def_cnt;
|
||||
}
|
||||
|
@ -1716,7 +1740,7 @@ emit_protocol (protocol_t *protocol)
|
|||
static void
|
||||
emit_protocol_next (def_t *def, void *data, int index)
|
||||
{
|
||||
if (def->type != &type_pointer) {
|
||||
if (!is_pointer(def->type)) {
|
||||
internal_error (0, "%s: expected pointer def", __FUNCTION__);
|
||||
}
|
||||
D_INT (def) = 0;
|
||||
|
@ -1727,7 +1751,7 @@ emit_protocol_count (def_t *def, void *data, int index)
|
|||
{
|
||||
protocollist_t *protocols = (protocollist_t *) data;
|
||||
|
||||
if (def->type != &type_integer) {
|
||||
if (!is_integer(def->type)) {
|
||||
internal_error (0, "%s: expected integer def", __FUNCTION__);
|
||||
}
|
||||
D_INT (def) = protocols->count;
|
||||
|
@ -1739,7 +1763,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) || def->type->t.array.type != &type_pointer) {
|
||||
if (!is_array (def->type) || !is_pointer(def->type->t.array.type)) {
|
||||
internal_error (0, "%s: expected array of pointer def", __FUNCTION__);
|
||||
}
|
||||
if (index < 0 || index >= protocols->count) {
|
||||
|
|
|
@ -146,7 +146,7 @@ do_op_string (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
static expr_t *
|
||||
convert_to_float (expr_t *e)
|
||||
{
|
||||
if (get_type (e) == &type_float)
|
||||
if (is_float(get_type (e)))
|
||||
return e;
|
||||
|
||||
switch (e->type) {
|
||||
|
@ -181,7 +181,7 @@ convert_to_float (expr_t *e)
|
|||
static expr_t *
|
||||
convert_to_double (expr_t *e)
|
||||
{
|
||||
if (get_type (e) == &type_double)
|
||||
if (is_double(get_type (e)))
|
||||
return e;
|
||||
|
||||
switch (e->type) {
|
||||
|
@ -227,7 +227,7 @@ do_op_float (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
return error (e1, "invalid operator for float");
|
||||
|
||||
if (op == '=') {
|
||||
if ((type = get_type (e1)) != &type_float) {
|
||||
if (!is_float(type = get_type (e1))) {
|
||||
//FIXME optimize casting a constant
|
||||
e->e.expr.e2 = e2 = cf_cast_expr (type, e2);
|
||||
} else if ((conv = convert_to_float (e2)) != e2) {
|
||||
|
@ -356,7 +356,7 @@ do_op_double (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
return error (e1, "invalid operator for double");
|
||||
|
||||
if (op == '=') {
|
||||
if ((type = get_type (e1)) != &type_double) {
|
||||
if (!is_double(type = get_type (e1))) {
|
||||
//FIXME optimize casting a constant
|
||||
e->e.expr.e2 = e2 = cf_cast_expr (type, e2);
|
||||
} else if ((conv = convert_to_double (e2)) != e2) {
|
||||
|
@ -454,7 +454,7 @@ do_op_vector (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
static int valid[] = {'=', '+', '-', '*', EQ, NE, 0};
|
||||
expr_t *t;
|
||||
|
||||
if (get_type (e1) != &type_vector) {
|
||||
if (!is_vector(get_type (e1))) {
|
||||
|
||||
if (op != '*')
|
||||
return error (e1, "invalid operator for vector");
|
||||
|
@ -463,7 +463,7 @@ do_op_vector (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
e->e.expr.e1 = e1 = e2;
|
||||
e2 = t;
|
||||
}
|
||||
if (get_type (e2) != &type_vector) {
|
||||
if (!is_vector(get_type (e2))) {
|
||||
e->e.expr.e2 = e2 = convert_to_float (e2);
|
||||
if (op != '*' && op != '/')
|
||||
return error (e1, "invalid operator for vector");
|
||||
|
@ -476,7 +476,7 @@ do_op_vector (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
e->e.expr.type = &type_integer;
|
||||
else
|
||||
e->e.expr.type = &type_float;
|
||||
} else if (op == '*' && get_type (e2) == &type_vector) {
|
||||
} else if (op == '*' && is_vector(get_type (e2))) {
|
||||
e->e.expr.type = &type_float;
|
||||
} else if (op == '/' && !is_constant (e1)) {
|
||||
e2 = fold_constants (binary_expr ('/', new_float_expr (1), e2));
|
||||
|
@ -541,7 +541,7 @@ do_op_vector (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
e = new_vector_expr (v);
|
||||
break;
|
||||
case '*':
|
||||
if (get_type (e2) == &type_vector) {
|
||||
if (is_vector(get_type (e2))) {
|
||||
e = new_float_expr (DotProduct (v1, v2));
|
||||
} else {
|
||||
VectorScale (v1, v2[0], v);
|
||||
|
@ -577,7 +577,7 @@ do_op_entity (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
e->e.expr.type = &type_float;
|
||||
return e;
|
||||
}
|
||||
if (op != '=' || type != &type_entity)
|
||||
if (op != '=' || !is_entity(type))
|
||||
return error (e1, "invalid operator for entity");
|
||||
e->e.expr.type = &type_entity;
|
||||
return e;
|
||||
|
@ -649,7 +649,7 @@ do_op_pointer (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
if (op != '.' && op != '&' && op != 'M'
|
||||
&& extract_type (e1) != extract_type (e2))
|
||||
return type_mismatch (e1, e2, op);
|
||||
if ((op == '.' || op == '&') && get_type (e2) == &type_uinteger)
|
||||
if ((op == '.' || op == '&') && is_uinteger(get_type (e2)))
|
||||
e->e.expr.e2 = cf_cast_expr (&type_integer, e2);
|
||||
return e;
|
||||
}
|
||||
|
@ -684,7 +684,7 @@ do_op_quaternion (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
static int valid[] = {'=', '+', '-', '*', EQ, NE, 0};
|
||||
expr_t *t;
|
||||
|
||||
if (get_type (e1) != &type_quaternion) {
|
||||
if (!is_quaternion(get_type (e1))) {
|
||||
|
||||
if (op != '*' && op != '/')
|
||||
return error (e1, "invalid operator for quaternion");
|
||||
|
@ -695,7 +695,7 @@ do_op_quaternion (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
e2 = t;
|
||||
}
|
||||
}
|
||||
if (get_type (e2) != &type_quaternion) {
|
||||
if (!is_quaternion(get_type (e2))) {
|
||||
e->e.expr.e2 = e2 = convert_to_float (e2);
|
||||
if (op != '*' && op != '/')
|
||||
return error (e1, "invalid operator for quaternion");
|
||||
|
@ -765,7 +765,7 @@ do_op_quaternion (int op, expr_t *e, expr_t *e1, expr_t *e2)
|
|||
e = new_quaternion_expr (q);
|
||||
break;
|
||||
case '*':
|
||||
if (get_type (e2) == &type_quaternion) {
|
||||
if (is_quaternion(get_type (e2))) {
|
||||
QuatMult (q1, q2, q);
|
||||
} else {
|
||||
QuatScale (q1, q2[3], q);
|
||||
|
@ -1397,7 +1397,7 @@ uop_float (int op, expr_t *e, expr_t *e1)
|
|||
if (op == '+')
|
||||
return e1;
|
||||
type = get_type (e);
|
||||
if (op == 'C' && type != &type_integer && type != &type_double)
|
||||
if (op == 'C' && !is_integer(type) && !is_double(type))
|
||||
return error (e1, "invalid cast of float");
|
||||
if (!is_constant (e1))
|
||||
return e;
|
||||
|
@ -1410,7 +1410,7 @@ uop_float (int op, expr_t *e, expr_t *e1)
|
|||
case '~':
|
||||
return new_float_expr (~(int) expr_float (e1));
|
||||
case 'C':
|
||||
if (type == &type_integer) {
|
||||
if (is_integer(type)) {
|
||||
return new_integer_expr (expr_float (e1));
|
||||
} else {
|
||||
return new_double_expr (expr_float (e1));
|
||||
|
@ -1549,7 +1549,7 @@ uop_integer (int op, expr_t *e, expr_t *e1)
|
|||
get_op_string (op));
|
||||
if (op == '+')
|
||||
return e1;
|
||||
if (op == 'C' && get_type (e) != &type_float)
|
||||
if (op == 'C' && !is_float(get_type (e)))
|
||||
return error (e1, "invalid cast of int");
|
||||
if (!is_constant (e1))
|
||||
return e;
|
||||
|
@ -1624,7 +1624,7 @@ uop_double (int op, expr_t *e, expr_t *e1)
|
|||
if (op == '+')
|
||||
return e1;
|
||||
type = get_type (e);
|
||||
if (op == 'C' && type != &type_integer && type != &type_float)
|
||||
if (op == 'C' && !is_integer(type) && !is_float(type))
|
||||
return error (e1, "invalid cast of double");
|
||||
if (!is_constant (e1))
|
||||
return e;
|
||||
|
@ -1635,7 +1635,7 @@ uop_double (int op, expr_t *e, expr_t *e1)
|
|||
print_type (get_type (e));
|
||||
return cmp_result_expr (!expr_double (e1));
|
||||
case 'C':
|
||||
if (type == &type_integer) {
|
||||
if (is_integer(type)) {
|
||||
return new_integer_expr (expr_double (e1));
|
||||
} else {
|
||||
return new_float_expr (expr_double (e1));
|
||||
|
|
|
@ -140,7 +140,7 @@ new_def (const char *name, type_t *type, defspace_t *space,
|
|||
if (!space && storage != sc_extern)
|
||||
internal_error (0, "non-external def with no storage space");
|
||||
|
||||
if (obj_is_class (type)) {
|
||||
if (is_class (type)) {
|
||||
error (0, "statically allocated instance of class %s",
|
||||
type->t.class->name);
|
||||
return def;
|
||||
|
@ -498,7 +498,7 @@ init_field_def (def_t *def, expr_t *init, storage_class_t storage)
|
|||
def->nosave = 1;
|
||||
}
|
||||
// no support for initialized field vector componets (yet?)
|
||||
if (type == &type_vector && options.code.vector_components)
|
||||
if (is_vector(type) && options.code.vector_components)
|
||||
init_vector_components (field_sym, 1);
|
||||
} else if (init->type == ex_symbol) {
|
||||
symbol_t *sym = init->e.symbol;
|
||||
|
@ -566,7 +566,7 @@ initialize_def (symbol_t *sym, expr_t *init, defspace_t *space,
|
|||
sym->s.def = new_def (sym->name, sym->type, space, storage);
|
||||
reloc_attach_relocs (relocs, &sym->s.def->relocs);
|
||||
}
|
||||
if (sym->type == &type_vector && options.code.vector_components)
|
||||
if (is_vector(sym->type) && options.code.vector_components)
|
||||
init_vector_components (sym, 0);
|
||||
if (sym->type->type == ev_field && storage != sc_local
|
||||
&& storage != sc_param)
|
||||
|
@ -582,7 +582,7 @@ initialize_def (symbol_t *sym, expr_t *init, defspace_t *space,
|
|||
if (init->type == ex_error)
|
||||
return;
|
||||
if ((is_array (sym->type) || is_struct (sym->type)
|
||||
|| sym->type == &type_vector || sym->type == &type_quaternion)
|
||||
|| is_vector(sym->type) || is_quaternion(sym->type))
|
||||
&& ((init->type == ex_compound)
|
||||
|| init->type == ex_nil)) {
|
||||
init_elements (sym->s.def, init);
|
||||
|
|
|
@ -387,7 +387,7 @@ print_vector (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
|||
{
|
||||
int indent = level * 2 + 2;
|
||||
|
||||
if (e->e.vector.type == &type_vector) {
|
||||
if (is_vector(e->e.vector.type)) {
|
||||
expr_t *x = e->e.vector.list;
|
||||
expr_t *y = x->next;
|
||||
expr_t *z = y->next;
|
||||
|
@ -398,7 +398,7 @@ print_vector (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
|||
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, y);
|
||||
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, z);
|
||||
}
|
||||
if (e->e.vector.type == &type_quaternion) {
|
||||
if (is_quaternion(e->e.vector.type)) {
|
||||
if (e->e.vector.list->next->next) {
|
||||
expr_t *x = e->e.vector.list;
|
||||
expr_t *y = x->next;
|
||||
|
|
|
@ -133,7 +133,7 @@ convert_vector (expr_t *e)
|
|||
|
||||
if (e->type != ex_vector)
|
||||
return e;
|
||||
if (e->e.vector.type == &type_vector) {
|
||||
if (is_vector(e->e.vector.type)) {
|
||||
// guaranteed to have three elements
|
||||
expr_t *x = e->e.vector.list;
|
||||
expr_t *y = x->next;
|
||||
|
@ -155,7 +155,7 @@ convert_vector (expr_t *e)
|
|||
e->e.vector.list = x;
|
||||
return e;
|
||||
}
|
||||
if (e->e.vector.type == &type_quaternion) {
|
||||
if (is_quaternion(e->e.vector.type)) {
|
||||
// guaranteed to have two or four elements
|
||||
if (e->e.vector.list->next->next) {
|
||||
// four vals: x, y, z, w
|
||||
|
@ -1321,7 +1321,7 @@ get_struct_field (const type_t *t1, expr_t *e1, expr_t *e2)
|
|||
return 0;
|
||||
}
|
||||
field = symtab_lookup (strct, sym->name);
|
||||
if (!field && t1 != &type_entity) {
|
||||
if (!field && !is_entity(t1)) {
|
||||
error (e2, "'%s' has no member named '%s'", t1->name + 4, sym->name);
|
||||
e1->type = ex_error;
|
||||
}
|
||||
|
@ -1370,7 +1370,7 @@ field_expr (expr_t *e1, expr_t *e2)
|
|||
e = new_binary_expr ('&', e1, e2);
|
||||
e->e.expr.type = pointer_type (field->type);
|
||||
return unary_expr ('.', e);
|
||||
} else if (obj_is_class (t1->t.fldptr.type)) {
|
||||
} else if (is_class (t1->t.fldptr.type)) {
|
||||
class_t *class = t1->t.fldptr.type->t.class;
|
||||
symbol_t *sym = e2->e.symbol;//FIXME need to check
|
||||
symbol_t *ivar;
|
||||
|
@ -1394,7 +1394,7 @@ field_expr (expr_t *e1, expr_t *e2)
|
|||
return e1;
|
||||
|
||||
if (e1->type == ex_expr && e1->e.expr.op == '.'
|
||||
&& get_type (e1->e.expr.e1) == &type_entity) {
|
||||
&& is_entity(get_type (e1->e.expr.e1))) {
|
||||
// undo the . expression
|
||||
e2 = e1->e.expr.e2;
|
||||
e1 = e1->e.expr.e1;
|
||||
|
@ -1426,7 +1426,7 @@ field_expr (expr_t *e1, expr_t *e2)
|
|||
return new_offset_alias_expr (field->type, e1, field->s.offset);
|
||||
}
|
||||
}
|
||||
} else if (obj_is_class (t1)) {
|
||||
} else if (is_class (t1)) {
|
||||
//Class instance variables aren't allowed and thus declaring one
|
||||
//is treated as an error, so this is a follow-on error.
|
||||
return error (e1, "class instance access");
|
||||
|
@ -1794,8 +1794,8 @@ bitnot_expr:
|
|||
expr_t *n = new_unary_expr (op, e);
|
||||
type_t *t = get_type (e);
|
||||
|
||||
if (t != &type_integer && t != &type_float
|
||||
&& t != &type_quaternion)
|
||||
if (!is_integer(t) && !is_float(t)
|
||||
&& !is_quaternion(t))
|
||||
return error (e, "invalid type for unary ~");
|
||||
n->e.expr.type = t;
|
||||
return n;
|
||||
|
@ -1963,7 +1963,7 @@ build_function_call (expr_t *fexpr, const type_t *ftype, expr_t *params)
|
|||
e = expr_file_line (new_binary_expr ('c', fexpr, args), fexpr);
|
||||
e->e.expr.type = ftype->t.func.type;
|
||||
append_expr (call, e);
|
||||
if (ftype->t.func.type != &type_void) {
|
||||
if (!is_void(ftype->t.func.type)) {
|
||||
call->e.block.result = new_ret_expr (ftype->t.func.type);
|
||||
} else if (options.traditional) {
|
||||
call->e.block.result = new_ret_expr (&type_float);
|
||||
|
@ -2030,7 +2030,7 @@ return_expr (function_t *f, expr_t *e)
|
|||
type_t *ret_type = f->sym->type->t.func.type;
|
||||
|
||||
if (!e) {
|
||||
if (ret_type != &type_void) {
|
||||
if (!is_void(ret_type)) {
|
||||
if (options.traditional) {
|
||||
if (options.warnings.traditional)
|
||||
warning (e,
|
||||
|
@ -2057,7 +2057,7 @@ return_expr (function_t *f, expr_t *e)
|
|||
if (e->type == ex_error) {
|
||||
return e;
|
||||
}
|
||||
if (ret_type == &type_void) {
|
||||
if (is_void(ret_type)) {
|
||||
if (!options.traditional)
|
||||
return error (e, "returning a value for a void function");
|
||||
if (options.warnings.traditional)
|
||||
|
@ -2066,11 +2066,11 @@ return_expr (function_t *f, expr_t *e)
|
|||
if (e->type == ex_bool) {
|
||||
e = convert_from_bool (e, ret_type);
|
||||
}
|
||||
if (ret_type == &type_float && is_integer_val (e)) {
|
||||
if (is_float(ret_type) && is_integer_val (e)) {
|
||||
convert_int (e);
|
||||
t = &type_float;
|
||||
}
|
||||
if (t == &type_void) {
|
||||
if (is_void(t)) {
|
||||
if (e->type == ex_nil) {
|
||||
t = ret_type;
|
||||
convert_nil (e, t);
|
||||
|
|
|
@ -222,7 +222,7 @@ assign_vector_expr (expr_t *dst, expr_t *src)
|
|||
}
|
||||
}
|
||||
if (src->type == ex_vector && dst->type != ex_vector) {
|
||||
if (src->e.vector.type == &type_vector) {
|
||||
if (is_vector(src->e.vector.type)) {
|
||||
// guaranteed to have three elements
|
||||
sx = src->e.vector.list;
|
||||
sy = sx->next;
|
||||
|
@ -237,7 +237,7 @@ assign_vector_expr (expr_t *dst, expr_t *src)
|
|||
block->e.block.result = dst;
|
||||
return block;
|
||||
}
|
||||
if (src->e.vector.type == &type_quaternion) {
|
||||
if (is_quaternion(src->e.vector.type)) {
|
||||
// guaranteed to have two or four elements
|
||||
if (src->e.vector.list->next->next) {
|
||||
// four vals: x, y, z, w
|
||||
|
|
|
@ -96,7 +96,7 @@ test_expr (expr_t *e)
|
|||
case ev_uinteger:
|
||||
case ev_integer:
|
||||
case ev_short:
|
||||
if (type_default != &type_integer) {
|
||||
if (!is_integer(type_default)) {
|
||||
if (is_constant (e)) {
|
||||
return cast_expr (type_default, e);
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ test_expr (expr_t *e)
|
|||
case ev_float:
|
||||
if (options.code.fast_float
|
||||
|| options.code.progsversion == PROG_ID_VERSION) {
|
||||
if (type_default != &type_float) {
|
||||
if (!is_float(type_default)) {
|
||||
if (is_constant (e)) {
|
||||
return cast_expr (type_default, e);
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ convert_bool (expr_t *e, int block)
|
|||
}
|
||||
|
||||
if (e->type == ex_uexpr && e->e.expr.op == '!'
|
||||
&& get_type (e->e.expr.e1) != &type_string) {
|
||||
&& !is_string(get_type (e->e.expr.e1))) {
|
||||
e = convert_bool (e->e.expr.e1, 0);
|
||||
if (e->type == ex_error)
|
||||
return e;
|
||||
|
|
|
@ -172,7 +172,7 @@ parse_params (type_t *type, param_t *parms)
|
|||
type_t *new;
|
||||
int count = 0;
|
||||
|
||||
if (type && obj_is_class (type)) {
|
||||
if (type && is_class (type)) {
|
||||
error (0, "cannot return an object (forgot *?)");
|
||||
type = &type_id;
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ parse_params (type_t *type, param_t *parms)
|
|||
internal_error (0, 0);
|
||||
new->t.func.num_params = -(new->t.func.num_params + 1);
|
||||
} else if (p->type) {
|
||||
if (obj_is_class (p->type)) {
|
||||
if (is_class (p->type)) {
|
||||
error (0, "cannot use an object as a parameter (forgot *?)");
|
||||
p->type = &type_id;
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ check_params (param_t *params)
|
|||
if (!params)
|
||||
return 0;
|
||||
while (p) {
|
||||
if (p->type == &type_void) {
|
||||
if (p->type && is_void(p->type)) {
|
||||
if (p->name) {
|
||||
error (0, "parameter %d ('%s') has incomplete type", num,
|
||||
p->name);
|
||||
|
|
|
@ -480,7 +480,7 @@ get_selector (expr_t *sel)
|
|||
selector_t _sel = {0, 0, 0};
|
||||
|
||||
if (sel->type != ex_expr && sel->e.expr.op != '&'
|
||||
&& sel->e.expr.type != &type_SEL) {
|
||||
&& !is_SEL(sel->e.expr.type)) {
|
||||
error (sel, "not a selector");
|
||||
return 0;
|
||||
}
|
||||
|
@ -525,7 +525,7 @@ emit_selectors (void)
|
|||
static void
|
||||
emit_methods_next (def_t *def, void *data, int index)
|
||||
{
|
||||
if (def->type != &type_pointer)
|
||||
if (!is_pointer(def->type))
|
||||
internal_error (0, "%s: expected pointer def", __FUNCTION__);
|
||||
D_INT (def) = 0;
|
||||
}
|
||||
|
@ -535,7 +535,7 @@ emit_methods_count (def_t *def, void *data, int index)
|
|||
{
|
||||
methodlist_t *methods = (methodlist_t *) data;
|
||||
|
||||
if (def->type != &type_integer)
|
||||
if (!is_integer(def->type))
|
||||
internal_error (0, "%s: expected integer def", __FUNCTION__);
|
||||
D_INT (def) = methods->count;
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ emit_methods_list_item (def_t *def, void *data, int index)
|
|||
method_t *m;
|
||||
pr_method_t *meth;
|
||||
|
||||
if (!is_array (def->type) || def->type->t.array.type != &type_obj_method)
|
||||
if (!is_array (def->type) || !is_method(def->type->t.array.type))
|
||||
internal_error (0, "%s: expected array of method def",
|
||||
__FUNCTION__);
|
||||
if (index < 0 || index >= methods->count)
|
||||
|
@ -614,7 +614,7 @@ emit_method_list_count (def_t *def, void *data, int index)
|
|||
{
|
||||
methodlist_t *methods = (methodlist_t *) data;
|
||||
|
||||
if (def->type != &type_integer)
|
||||
if (!is_integer(def->type))
|
||||
internal_error (0, "%s: expected integer def", __FUNCTION__);
|
||||
D_INT (def) = methods->count;
|
||||
}
|
||||
|
@ -627,7 +627,7 @@ emit_method_list_item (def_t *def, void *data, int index)
|
|||
pr_method_description_t *desc;
|
||||
|
||||
if (!is_array (def->type)
|
||||
|| def->type->t.array.type != &type_obj_method_description) {
|
||||
|| !is_method_description(def->type->t.array.type)) {
|
||||
internal_error (0, "%s: expected array of method_description def",
|
||||
__FUNCTION__);
|
||||
}
|
||||
|
|
|
@ -704,7 +704,7 @@ struct_defs
|
|||
| DEFS '(' identifier ')'
|
||||
{
|
||||
$3 = check_undefined ($3);
|
||||
if (!$3->type || !obj_is_class ($3->type)) {
|
||||
if (!$3->type || !is_class ($3->type)) {
|
||||
error (0, "`%s' is not a class", $3->name);
|
||||
} else {
|
||||
// replace the struct symbol table with one built from
|
||||
|
@ -860,7 +860,7 @@ qc_func_params
|
|||
| '(' ps qc_var_list ')' { $$ = check_params ($3); }
|
||||
| '(' ps TYPE ')'
|
||||
{
|
||||
if ($3 != &type_void)
|
||||
if (!is_void ($3))
|
||||
PARSE_ERROR;
|
||||
$$ = 0;
|
||||
}
|
||||
|
@ -1629,7 +1629,7 @@ class_name
|
|||
if (!$1->table) {
|
||||
symtab_addsymbol (current_symtab, $1);
|
||||
}
|
||||
} else if (!obj_is_class ($1->type)) {
|
||||
} else if (!is_class ($1->type)) {
|
||||
error (0, "`%s' is not a class", $1->name);
|
||||
$$ = get_class (0, 1);
|
||||
} else {
|
||||
|
|
|
@ -1347,7 +1347,7 @@ expr_vector_e (sblock_t *sblock, expr_t *e, operand_t **op)
|
|||
pr.source_line = e->line;
|
||||
|
||||
tmp = new_temp_def_expr (vec_type);
|
||||
if (vec_type == &type_vector) {
|
||||
if (is_vector(vec_type)) {
|
||||
// guaranteed to have three elements
|
||||
x = e->e.vector.list;
|
||||
y = x->next;
|
||||
|
@ -2017,7 +2017,7 @@ check_final_block (sblock_t *sblock)
|
|||
if (statement_is_return (s))
|
||||
return;
|
||||
}
|
||||
if (current_func->sym->type->t.func.type != &type_void)
|
||||
if (!is_void(current_func->sym->type->t.func.type))
|
||||
warning (0, "control reaches end of non-void function");
|
||||
if (s && s->type >= st_func) {
|
||||
// func and flow end blocks, so we need to add a new block to take the
|
||||
|
|
|
@ -125,7 +125,7 @@ build_struct (int su, symbol_t *tag, symtab_t *symtab, type_t *type)
|
|||
for (s = symtab->symbols; s; s = s->next) {
|
||||
if (s->sy_type != sy_var)
|
||||
continue;
|
||||
if (obj_is_class (s->type)) {
|
||||
if (is_class (s->type)) {
|
||||
error (0, "statically allocated instance of class %s",
|
||||
s->type->t.class->name);
|
||||
}
|
||||
|
|
|
@ -45,5 +45,7 @@ __attribute__((const)) symbol_t *new_symbol_type (const char *name, type_t *type
|
|||
__attribute__((const)) def_t *qfo_encode_type (type_t *type) {return 0;}
|
||||
__attribute__((const)) int obj_types_assignable (const type_t *dst, const type_t *src) {return 0;}
|
||||
void print_protocollist (struct dstring_s *dstr, protocollist_t *protocollist) {}
|
||||
int obj_is_id (const type_t *type){return type->type;}
|
||||
int is_id (const type_t *type){return type->type;}
|
||||
int is_SEL (const type_t *type){return type->type;}
|
||||
int is_Class (const type_t *type){return type->type;}
|
||||
int compare_protocols (protocollist_t *protos1, protocollist_t *protos2){return protos1->count - protos2->count;}
|
||||
|
|
|
@ -429,8 +429,7 @@ switch_expr (switch_block_t *switch_block, expr_t *break_label,
|
|||
for (l = labels; *l; l++)
|
||||
num_labels++;
|
||||
if (options.code.progsversion == PROG_ID_VERSION
|
||||
|| (type != &type_string
|
||||
&& type != &type_float && !is_integral (type))
|
||||
|| (!is_string(type) && !is_float(type) && !is_integral (type))
|
||||
|| num_labels < 8) {
|
||||
for (l = labels; *l; l++) {
|
||||
expr_t *cmp = binary_expr (EQ, sw_val, (*l)->value);
|
||||
|
@ -446,7 +445,7 @@ switch_expr (switch_block_t *switch_block, expr_t *break_label,
|
|||
int op;
|
||||
case_node_t *case_tree;
|
||||
|
||||
if (type == &type_string)
|
||||
if (is_string(type))
|
||||
temp = new_temp_def_expr (&type_integer);
|
||||
else
|
||||
temp = new_temp_def_expr (type);
|
||||
|
|
|
@ -513,13 +513,13 @@ print_type_str (dstring_t *str, const type_t *type)
|
|||
}
|
||||
return;
|
||||
case ev_pointer:
|
||||
if (obj_is_id (type)) {
|
||||
if (is_id (type)) {
|
||||
dasprintf (str, "id");
|
||||
if (type->t.fldptr.type->protos)
|
||||
print_protocollist (str, type->t.fldptr.type->protos);
|
||||
return;
|
||||
}
|
||||
if (type == &type_SEL) {
|
||||
if (is_SEL(type)) {
|
||||
dasprintf (str, "SEL");
|
||||
return;
|
||||
}
|
||||
|
@ -674,15 +674,15 @@ encode_type (dstring_t *encoding, const type_t *type)
|
|||
dasprintf (encoding, "%s)", encode_params (type));
|
||||
return;
|
||||
case ev_pointer:
|
||||
if (type == &type_id) {
|
||||
if (is_id(type)) {
|
||||
dasprintf (encoding, "@");
|
||||
return;
|
||||
}
|
||||
if (type == &type_SEL) {
|
||||
if (is_SEL(type)) {
|
||||
dasprintf (encoding, ":");
|
||||
return;
|
||||
}
|
||||
if (type == &type_Class) {
|
||||
if (is_Class(type)) {
|
||||
dasprintf (encoding, "#");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -513,7 +513,7 @@ emit_value (ex_value_t *value, def_t *def)
|
|||
break;
|
||||
case ev_integer:
|
||||
case ev_uinteger:
|
||||
if (!def || def->type != &type_float) {
|
||||
if (!def || !is_float(def->type)) {
|
||||
tab = integer_imm_defs;
|
||||
type = &type_integer;
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue