[qfcc] Use count for number of array elements

I got tired of seeing size when count is the real intent (mistake copied
from C++).
This commit is contained in:
Bill Currie 2024-11-17 15:25:29 +09:00
parent 2115e962fe
commit d082d39e17
18 changed files with 42 additions and 41 deletions

View file

@ -107,7 +107,7 @@ typedef struct qfot_struct_s {
typedef struct qfot_array_s {
pr_ptr_t type; ///< element type
pr_int_t base; ///< start index of array
pr_int_t size; ///< number of elements in array
pr_int_t count; ///< number of elements in array
} qfot_array_t;
typedef struct qfot_algebra_s {

View file

@ -260,7 +260,7 @@ pr_debug_type_size (const progs_t *pr, const qfot_type_t *type)
case ty_array:
aux_type = &G_STRUCT (pr, qfot_type_t, type->array.type);
size = pr_debug_type_size (pr, aux_type);
return type->array.size * size;
return type->array.count * size;
case ty_class:
return 1; //FIXME or should it return sizeof class struct?
case ty_alias:
@ -1610,11 +1610,11 @@ pr_debug_array_view (qfot_type_t *type, pr_type_t *value, void *_data)
dstring_appendstr (dstr, "{");
int offset = 0;
for (int i = 0; i < array->size; i++, offset += val_size) {
for (int i = 0; i < array->count; i++, offset += val_size) {
pr_type_t *val = value + offset;
dasprintf (dstr, "[%d]=", array->base + i);
value_string (data, val_type, val);
if (i < array->size - 1) {
if (i < array->count - 1) {
dstring_appendstr (dstr, ", ");
}
}

View file

@ -18,7 +18,7 @@
return nil;
}
ele_type = [Type fromType: type.array.type];
ele_count = type.array.size;
ele_count = type.array.count;
return self;
}

View file

@ -66,7 +66,7 @@ typedef struct qfot_struct_s {
typedef struct qfot_array_s {
struct qfot_type_s *type;
int base;
int size;
int count;
} qfot_array_t;
typedef struct qfot_algebra_s {

View file

@ -228,7 +228,7 @@ error:
break;
case ty_array:
aux_type = type.array.type;
size = type.array.size * [TypeEncodings typeSize:aux_type];
size = type.array.count * [TypeEncodings typeSize:aux_type];
break;
case ty_struct:
for (int i = 0; i < type.strct.num_fields; i++) {

View file

@ -14,12 +14,12 @@
return nil;
}
self.data = (unsigned *)(data + def.offset);
element_views = obj_malloc (type.array.size);
element_rows = obj_malloc (type.array.size);
element_views = obj_malloc (type.array.count);
element_rows = obj_malloc (type.array.count);
element_rows[0] = 0;
qfot_type_t *element_type = type.array.type;
int element_size = [TypeEncodings typeSize:element_type];
for (int i = 0; i < type.array.size; i++) {
for (int i = 0; i < type.array.count; i++) {
qdb_def_t def = {
0, // XXX type/size not needed at this stage
i * element_size,
@ -32,7 +32,7 @@
target:target] retain];
element_rows[i + 1] = [element_views[i] rows];
}
prefixsum (element_rows, type.array.size + 1);
prefixsum (element_rows, type.array.count + 1);
return self;
}
@ -44,7 +44,7 @@
-setTarget:(qdb_target_t)target
{
[super setTarget:target];
for (int i = 0; i < type.array.size; i++) {
for (int i = 0; i < type.array.count; i++) {
[element_views[i] setTarget:target];
}
return self;
@ -52,7 +52,7 @@
-(void)dealloc
{
for (int i = 0; i < type.array.size; i++) {
for (int i = 0; i < type.array.count; i++) {
[element_views[i] release];
}
obj_free (element_views);
@ -65,7 +65,7 @@
[super draw];
string val = sprintf ("%s[%d..%d]", type.array.type.encoding,
type.array.base,
type.array.base + type.array.size - 1);
type.array.base + type.array.count - 1);
[self mvprintf:{0, 0}, "%*.*s", xlen, xlen, val];
return self;
}
@ -74,17 +74,17 @@
{
[super fetchData];
element_rows[0] = 0;
for (int i = 0; i < type.array.size; i++) {
for (int i = 0; i < type.array.count; i++) {
[element_views[i] fetchData];
element_rows[i + 1] = [element_views[i] rows];
}
prefixsum (element_rows, type.array.size + 1);
prefixsum (element_rows, type.array.count + 1);
return self;
}
-(int) rows
{
return 1 + element_rows[type.array.size];
return 1 + element_rows[type.array.count];
}
-(View *) viewAtRow:(int)row forColumn:(TableViewColumn *)column
@ -99,7 +99,7 @@
row -= 1;
View *view = nil;
int *index = fbsearch (&row, element_rows, type.array.size, 1, nil);
int *index = fbsearch (&row, element_rows, type.array.count, 1, nil);
if ([column name] == "name") {
return [IndexView withIndex:index - element_rows + type.array.base];

View file

@ -60,7 +60,7 @@ typedef struct ty_fldptr_s {
typedef struct ty_array_s {
const struct type_s *type;
int base;
int size;
int count;
} ty_array_t;
typedef struct ty_alias_s {

View file

@ -1522,7 +1522,7 @@ emit_symtab_ref_cnt (def_t *def, void *data, int index)
internal_error (0, "%s: expected int def", __FUNCTION__);
D_INT (def) = 0;
if (da->refs)
D_INT (def) = da->refs->type->array.size;
D_INT (def) = da->refs->type->array.count;
}
static void

View file

@ -197,10 +197,10 @@ print_array (dstring_t *dstr, const type_t *t, int level, set_t *seen)
dasprintf (dstr, "%*st_%p -> \"t_%p\";\n", indent, "", t, type);
if (t->array.base) {
dasprintf (dstr, "%*st_%p [label=\"[%d..%d]\"];\n", indent, "", t,
t->array.base, t->array.base + t->array.size - 1);
t->array.base, t->array.base + t->array.count - 1);
} else {
dasprintf (dstr, "%*st_%p [label=\"[%d]\"];\n", indent, "", t,
t->array.size);
t->array.count);
}
}

View file

@ -555,7 +555,7 @@ dump_qfo_types (qfo_t *qfo, int base_address)
break;
case ty_array:
printf (" %-5x %d %d\n", type->array.type,
type->array.base, type->array.size);
type->array.base, type->array.count);
break;
case ty_class:
printf (" %-5x\n", type->class);

View file

@ -2340,10 +2340,10 @@ array_expr (const expr_t *array, const expr_t *index)
if (is_int_val (index))
ind = expr_int (index);
if (is_array (array_type)
&& array_type->array.size
&& array_type->array.count
&& is_constant (index)
&& (ind < array_type->array.base
|| ind - array_type->array.base >= array_type->array.size)) {
|| ind - array_type->array.base >= array_type->array.count)) {
return error (index, "array index out of bounds");
}
if (is_nonscalar (array_type) && !is_matrix (array_type)

View file

@ -123,7 +123,7 @@ designator_field (const designator_t *des, const type_t *type)
}
static int
designator_index (const designator_t *des, int ele_size, int array_size)
designator_index (const designator_t *des, int ele_size, int array_count)
{
if (des->field) {
error (des->field, "field designator in array initializer");
@ -136,7 +136,7 @@ designator_index (const designator_t *des, int ele_size, int array_size)
return -1;
}
int index = expr_integral (des->index);
if (index <= 0 || index >= array_size) {
if (index <= 0 || index >= array_count) {
error (des->index, "designator index out of bounds");
return -1;
}
@ -161,9 +161,9 @@ get_designated_offset (const type_t *type, const designator_t *des)
offset = field->offset;
ele_type = field->type;
} else if (is_array (type)) {
int array_size = type->array.size;
int array_count = type->array.count;
ele_type = dereference_type (type);
offset = designator_index (des, type_size (ele_type), array_size);
offset = designator_index (des, type_size (ele_type), array_count);
} else if (is_nonscalar (type)) {
ele_type = ev_types[type->type];
if (type->symtab && des->field) {

View file

@ -760,7 +760,7 @@ get_type_size (qfo_t *qfo, pr_ptr_t type)
case ty_enum:
return pr_type_size[ev_int];
case ty_array:
return type_def->array.size
return type_def->array.count
* get_type_size (qfo, type_def->array.type);
case ty_class:
case ty_algebra:

View file

@ -240,7 +240,7 @@ qfo_encode_array (const type_t *type, defspace_t *space)
enc = D_POINTER (qfot_type_t, def);
ENC_DEF (enc->array.type, array_type_def);
enc->array.base = type->array.base;
enc->array.size = type->array.size;
enc->array.count = type->array.count;
return def;
}

View file

@ -688,7 +688,7 @@ statement_get_targetlist (statement_t *s)
count = 1;
} else if (statement_is_jumpb (s)) {
table = s->opa->def;
count = table->type->array.size;
count = table->type->array.count;
}
target_list = malloc ((count + 1) * sizeof (sblock_t *));
target_list[count] = 0;

View file

@ -430,7 +430,7 @@ emit_structure (const char *name, int su, struct_def_t *defs,
} else {
if (is_array (field_def.type)) {
auto type = dereference_type (field_def.type);
for (j = 0; j < field_def.type->array.size; j++) {
for (j = 0; j < field_def.type->array.count; j++) {
defs[i].emit (&field_def, data, j);
field_def.offset += type_size (type);
}

View file

@ -233,7 +233,8 @@ make_symbol (const char *name, const type_t *type, defspace_t *space,
sym = new_symbol_type (name, type);
}
if (sym->type != type) {
if (is_array (sym->type) && is_array (type) && !sym->type->array.size) {
if (is_array (sym->type) && is_array (type)
&& !sym->type->array.count) {
sym->type = type;
} else {
error (0, "%s redefined", name);

View file

@ -894,7 +894,7 @@ array_type (const type_t *aux, int size)
new->alignment = aux->alignment;
new->width = aux->width;
}
new->array.size = size;
new->array.count = size;
if (aux) {
return find_type (append_type (new, aux));
}
@ -919,7 +919,7 @@ based_array_type (const type_t *aux, int base, int top)
new->meta = ty_array;
new->array.type = aux;
new->array.base = base;
new->array.size = top - base + 1;
new->array.count = top - base + 1;
if (aux) {
return find_type (new);
}
@ -1015,9 +1015,9 @@ print_type_str (dstring_t *str, const type_t *type)
print_type_str (str, type->array.type);
if (type->array.base) {
dasprintf (str, "[%d..%d]", type->array.base,
type->array.base + type->array.size - 1);
type->array.base + type->array.count - 1);
} else {
dasprintf (str, "[%d]", type->array.size);
dasprintf (str, "[%d]", type->array.count);
}
return;
case ty_bool:
@ -1228,7 +1228,7 @@ encode_type (dstring_t *encoding, const type_t *type)
return;
case ty_array:
dasprintf (encoding, "[");
dasprintf (encoding, "%d", type->array.size);
dasprintf (encoding, "%d", type->array.count);
if (type->array.base)
dasprintf (encoding, ":%d", type->array.base);
dasprintf (encoding, "=");
@ -1480,7 +1480,7 @@ is_nonscalar (const type_t *type)
if (type->width < 2) {
return false;
}
return is_real (type) || is_integral (type);
return is_real (type) || is_integral (type) || is_boolean (type);
}
bool
@ -1706,7 +1706,7 @@ type_size (const type_t *type)
return 0;
return type_size (&type_int);
case ty_array:
return type->array.size * type_size (type->array.type);
return type->array.count * type_size (type->array.type);
case ty_class:
{
class_t *class = type->class;