[qfcc] Dereference most array types properly

This should prevent some fun bugs in the future (it's what necessitated
the const-correct patch).
This commit is contained in:
Bill Currie 2024-02-13 23:13:01 +09:00
parent f0dfe47a32
commit 192eb11235
7 changed files with 13 additions and 12 deletions

View file

@ -310,7 +310,7 @@ emit_instance_defs (def_t *def, void *data, int index)
{
obj_static_instances_data_t *da = (obj_static_instances_data_t *)data;
if (!is_array (def->type) || def->type->t.array.type->type != ev_ptr)
if (!is_array (def->type) || !is_ptr (dereference_type (def->type)))
internal_error (0, "%s: expected array of pointers def", __FUNCTION__);
if (index < 0 || index >= da->num_instances + 1)
internal_error (0, "%s: out of bounds index: %d %d",
@ -1535,7 +1535,7 @@ emit_symtab_defs (def_t *def, void *data, int index)
{
obj_symtab_data_t *da = (obj_symtab_data_t *)data;
if (!is_array (def->type) || def->type->t.array.type->type != ev_ptr)
if (!is_array (def->type) || !is_ptr (dereference_type (def->type)))
internal_error (0, "%s: expected array of pointers def", __FUNCTION__);
if (index < 0 || index >= da->cls_def_cnt + da->cat_def_cnt + 1)
internal_error (0, "%s: out of bounds index: %d %d",
@ -1843,7 +1843,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_ptr(def->type->t.array.type)) {
if (!is_array (def->type) || !is_ptr(dereference_type (def->type))) {
internal_error (0, "%s: expected array of pointer def", __FUNCTION__);
}
if (index < 0 || index >= protocols->count) {

View file

@ -173,7 +173,7 @@ emit_num_files (def_t *def, void *data, int index)
static void
emit_files_item (def_t *def, void *data, int index)
{
if (!is_array (def->type) || !is_string (def->type->t.array.type)) {
if (!is_array (def->type) || !is_string (dereference_type (def->type))) {
internal_error (0, "%s: expected array of string def", __FUNCTION__);
}
if ((unsigned) index >= pr.comp_files.size) {

View file

@ -153,7 +153,8 @@ new_def (const char *name, const type_t *type, defspace_t *space,
if (!space && storage != sc_extern)
internal_error (0, "non-external def with no storage space");
if (is_class (type) || (is_array (type) && is_class(type->t.array.type))) {
if (is_class (type)
|| (is_array (type) && is_class(dereference_type (type)))) {
error (0, "statically allocated instance of class %s",
type->t.class->name);
return def;

View file

@ -2590,7 +2590,7 @@ array_expr (const expr_t *array, const expr_t *index)
return error (index, "array index out of bounds");
}
if (is_array (array_type)) {
ele_type = array_type->t.array.type;
ele_type = dereference_type (array_type);
base = new_int_expr (array_type->t.array.base);
} else if (is_ptr (array_type)) {
ele_type = array_type->t.fldptr.type;

View file

@ -1341,11 +1341,11 @@ binary_expr (int op, const expr_t *e1, const expr_t *e2)
e2 = cast_expr (t2, e2);
}
if (is_array (t1) && (is_ptr (t2) || is_integral (t2))) {
t1 = pointer_type (t1->t.array.type);
t1 = pointer_type (dereference_type (t1));
e1 = cast_expr (t1, e1);
}
if (is_array (t2) && (is_ptr (t1) || is_integral (t1))) {
t2 = pointer_type (t2->t.array.type);
t1 = pointer_type (dereference_type (t2));
e2 = cast_expr (t2, e2);
}

View file

@ -162,7 +162,7 @@ get_designated_offset (const type_t *type, const designator_t *des)
ele_type = field->type;
} else if (is_array (type)) {
int array_size = type->t.array.size;
ele_type = type->t.array.type;
ele_type = dereference_type (type);
offset = designator_index (des, type_size (ele_type), array_size);
} else if (is_nonscalar (type)) {
ele_type = ev_types[type->type];
@ -230,7 +230,7 @@ build_element_chain (element_chain_t *element_chain, const type_t *type,
state.offset = state.field->s.offset;
}
} else if (is_array (type)) {
state.type = type->t.array.type;
state.type = dereference_type (type);
} else {
internal_error (eles, "invalid initialization");
}

View file

@ -558,7 +558,7 @@ emit_methods_list_item (def_t *def, void *data, int index)
method_t *m;
pr_method_t *meth;
if (!is_array (def->type) || !is_method(def->type->t.array.type))
if (!is_array (def->type) || !is_method(dereference_type (def->type)))
internal_error (0, "%s: expected array of method def",
__FUNCTION__);
if (index < 0 || index >= methods->count)
@ -638,7 +638,7 @@ emit_method_list_item (def_t *def, void *data, int index)
pr_method_description_t *desc;
if (!is_array (def->type)
|| !is_method_description(def->type->t.array.type)) {
|| !is_method_description(dereference_type (def->type))) {
internal_error (0, "%s: expected array of method_description def",
__FUNCTION__);
}