mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 01:11:45 +00:00
[qfcc] Make type encoding union anonymous
I'd do more, but things get messy with direct access to unions that I want to be anonymous.
This commit is contained in:
parent
eccf1cb962
commit
ddec80edc1
8 changed files with 83 additions and 83 deletions
|
@ -112,7 +112,7 @@ typedef struct qfot_type_s {
|
|||
qfot_array_t array; ///< ty_array
|
||||
string_t class; ///< ty_class
|
||||
qfot_alias_t alias; ///< ty_alias
|
||||
} t;
|
||||
};
|
||||
} qfot_type_t;
|
||||
|
||||
typedef struct qfot_type_encodings_s {
|
||||
|
|
|
@ -215,12 +215,12 @@ pr_debug_type_size (const progs_t *pr, const qfot_type_t *type)
|
|||
qfot_type_t *aux_type;
|
||||
switch (type->meta) {
|
||||
case ty_basic:
|
||||
return pr_type_size[type->t.type];
|
||||
return pr_type_size[type->type];
|
||||
case ty_struct:
|
||||
case ty_union:
|
||||
size = 0;
|
||||
for (pr_int_t i = 0; i < type->t.strct.num_fields; i++) {
|
||||
const qfot_var_t *field = &type->t.strct.fields[i];
|
||||
for (pr_int_t i = 0; i < type->strct.num_fields; i++) {
|
||||
const qfot_var_t *field = &type->strct.fields[i];
|
||||
aux_type = &G_STRUCT (pr, qfot_type_t, field->type);
|
||||
size = max (size,
|
||||
field->offset + pr_debug_type_size (pr, aux_type));
|
||||
|
@ -229,13 +229,13 @@ pr_debug_type_size (const progs_t *pr, const qfot_type_t *type)
|
|||
case ty_enum:
|
||||
return pr_type_size[ev_integer];
|
||||
case ty_array:
|
||||
aux_type = &G_STRUCT (pr, qfot_type_t, type->t.array.type);
|
||||
aux_type = &G_STRUCT (pr, qfot_type_t, type->array.type);
|
||||
size = pr_debug_type_size (pr, aux_type);
|
||||
return type->t.array.size * size;
|
||||
return type->array.size * size;
|
||||
case ty_class:
|
||||
return 1; //FIXME or should it return sizeof class struct?
|
||||
case ty_alias:
|
||||
aux_type = &G_STRUCT (pr, qfot_type_t, type->t.alias.aux_type);
|
||||
aux_type = &G_STRUCT (pr, qfot_type_t, type->alias.aux_type);
|
||||
return pr_debug_type_size (pr, aux_type);
|
||||
}
|
||||
return 0;
|
||||
|
@ -248,7 +248,7 @@ get_def_type (progs_t *pr, pr_def_t *def, qfot_type_t *type)
|
|||
// no type encoding, so use basic type data to fill in and return
|
||||
// the dummy encoding
|
||||
memset (type, 0, sizeof (*type));
|
||||
type->t.type = def->type;
|
||||
type->type = def->type;
|
||||
} else {
|
||||
type = &G_STRUCT (pr, qfot_type_t, def->type_encoding);
|
||||
if (!def->size) {
|
||||
|
@ -543,8 +543,8 @@ PR_LoadDebug (progs_t *pr)
|
|||
type_ptr += type->size) {
|
||||
type = &G_STRUCT (pr, qfot_type_t, type_encodings + type_ptr);
|
||||
if (type->meta == ty_basic
|
||||
&& type->t.type >= 0 && type->t.type < ev_type_count) {
|
||||
res->type_encodings[type->t.type] = type;
|
||||
&& type->type >= 0 && type->type < ev_type_count) {
|
||||
res->type_encodings[type->type] = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -826,7 +826,7 @@ value_string (pr_debug_data_t *data, qfot_type_t *type, pr_type_t *value)
|
|||
{
|
||||
switch (type->meta) {
|
||||
case ty_basic:
|
||||
switch (type->t.type) {
|
||||
switch (type->type) {
|
||||
case ev_void:
|
||||
raw_type_view.void_view (type, value, data);
|
||||
break;
|
||||
|
@ -887,7 +887,7 @@ value_string (pr_debug_data_t *data, qfot_type_t *type, pr_type_t *value)
|
|||
raw_type_view.class_view (type, value, data);
|
||||
break;
|
||||
case ty_alias://XXX
|
||||
type = &G_STRUCT (data->pr, qfot_type_t, type->t.alias.aux_type);
|
||||
type = &G_STRUCT (data->pr, qfot_type_t, type->alias.aux_type);
|
||||
return value_string (data, type, value);
|
||||
}
|
||||
return data->dstr->str;
|
||||
|
@ -928,7 +928,7 @@ global_string (pr_debug_data_t *data, pointer_t offset, qfot_type_t *type,
|
|||
|
||||
dstring_clearstr (dstr);
|
||||
|
||||
if (type && type->meta == ty_basic && type->t.type == ev_short) {
|
||||
if (type && type->meta == ty_basic && type->type == ev_short) {
|
||||
dsprintf (dstr, "%04x", (short) offset);
|
||||
return dstr->str;
|
||||
}
|
||||
|
@ -961,7 +961,7 @@ global_string (pr_debug_data_t *data, pointer_t offset, qfot_type_t *type,
|
|||
if (!type) {
|
||||
if (def) {
|
||||
if (!def->type_encoding) {
|
||||
dummy_type.t.type = def->type;
|
||||
dummy_type.type = def->type;
|
||||
type = &dummy_type;
|
||||
} else {
|
||||
type = &G_STRUCT (pr, qfot_type_t, def->type_encoding);
|
||||
|
@ -1176,7 +1176,7 @@ pr_dump_struct (qfot_type_t *type, pr_type_t *value, void *_data,
|
|||
__auto_type data = (pr_debug_data_t *) _data;
|
||||
progs_t *pr = data->pr;
|
||||
dstring_t *dstr = data->dstr;
|
||||
qfot_struct_t *strct = &type->t.strct;
|
||||
qfot_struct_t *strct = &type->strct;
|
||||
|
||||
dstring_appendstr (dstr, "{");
|
||||
for (int i = 0; i < strct->num_fields; i++) {
|
||||
|
@ -1609,7 +1609,7 @@ PR_Debug_Init (progs_t *pr)
|
|||
res->void_type.meta = ty_basic;
|
||||
res->void_type.size = 4;
|
||||
res->void_type.encoding = 0;
|
||||
res->void_type.t.type = ev_void;
|
||||
res->void_type.type = ev_void;
|
||||
for (int i = 0; i < ev_type_count; i++ ) {
|
||||
res->type_encodings[i] = &res->void_type;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ typedef struct qfot_type_s {
|
|||
qfot_array_t array;
|
||||
string class;
|
||||
qfot_alias_t alias;
|
||||
} t;
|
||||
};
|
||||
} qfot_type_t;
|
||||
|
||||
typedef struct qfot_type_encodings_s {
|
||||
|
|
|
@ -548,46 +548,46 @@ dump_qfo_types (qfo_t *qfo, int base_address)
|
|||
}
|
||||
switch ((ty_meta_e) type->meta) {
|
||||
case ty_basic:
|
||||
printf (" %-10s", (type->t.type < 0
|
||||
|| type->t.type >= ev_type_count)
|
||||
printf (" %-10s", (type->type < 0
|
||||
|| type->type >= ev_type_count)
|
||||
? "invalid type"
|
||||
: pr_type_name[type->t.type]);
|
||||
if (type->t.type == ev_func) {
|
||||
printf (" %4x %d", type->t.func.return_type,
|
||||
count = type->t.func.num_params);
|
||||
: pr_type_name[type->type]);
|
||||
if (type->type == ev_func) {
|
||||
printf (" %4x %d", type->func.return_type,
|
||||
count = type->func.num_params);
|
||||
if (count < 0)
|
||||
count = ~count; //ones complement
|
||||
for (i = 0; i < count; i++)
|
||||
printf (" %x", type->t.func.param_types[i]);
|
||||
} else if (type->t.type == ev_pointer
|
||||
|| type->t.type == ev_field) {
|
||||
printf (" %4x", type->t.fldptr.aux_type);
|
||||
printf (" %x", type->func.param_types[i]);
|
||||
} else if (type->type == ev_pointer
|
||||
|| type->type == ev_field) {
|
||||
printf (" %4x", type->fldptr.aux_type);
|
||||
}
|
||||
printf ("\n");
|
||||
break;
|
||||
case ty_struct:
|
||||
case ty_union:
|
||||
case ty_enum:
|
||||
printf (" %s\n", QFO_GETSTR (qfo, type->t.strct.tag));
|
||||
for (i = 0; i < type->t.strct.num_fields; i++) {
|
||||
printf (" %s\n", QFO_GETSTR (qfo, type->strct.tag));
|
||||
for (i = 0; i < type->strct.num_fields; i++) {
|
||||
printf (" %-5x %4x %s\n",
|
||||
type->t.strct.fields[i].type,
|
||||
type->t.strct.fields[i].offset,
|
||||
QFO_GETSTR (qfo, type->t.strct.fields[i].name));
|
||||
type->strct.fields[i].type,
|
||||
type->strct.fields[i].offset,
|
||||
QFO_GETSTR (qfo, type->strct.fields[i].name));
|
||||
}
|
||||
break;
|
||||
case ty_array:
|
||||
printf (" %-5x %d %d\n", type->t.array.type,
|
||||
type->t.array.base, type->t.array.size);
|
||||
printf (" %-5x %d %d\n", type->array.type,
|
||||
type->array.base, type->array.size);
|
||||
break;
|
||||
case ty_class:
|
||||
printf (" %-5x\n", type->t.class);
|
||||
printf (" %-5x\n", type->class);
|
||||
break;
|
||||
case ty_alias:
|
||||
printf (" %s %d %5x %5x\n",
|
||||
QFO_GETSTR (qfo, type->t.alias.name),
|
||||
type->t.alias.type, type->t.alias.aux_type,
|
||||
type->t.alias.full_type);
|
||||
QFO_GETSTR (qfo, type->alias.name),
|
||||
type->alias.type, type->alias.aux_type,
|
||||
type->alias.full_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ qfo_set_func_data (qfo_t *qfo, qfo_func_t *func, func_data_t *func_data)
|
|||
func_data->source_line = func->line;
|
||||
//FIXME check type
|
||||
type = QFO_POINTER (qfo, qfo_type_space, qfot_type_t, func->type);
|
||||
func_data->return_type = type->t.func.return_type;
|
||||
func_data->return_type = type->func.return_type;
|
||||
func_data->num_locals = -1;
|
||||
if (func->locals_space < qfo->num_spaces) {
|
||||
func_data->num_locals = qfo->spaces[func->locals_space].num_defs;
|
||||
|
|
|
@ -296,11 +296,11 @@ resolve_external_def (defref_t *ext, defref_t *def)
|
|||
}
|
||||
ext_type = WORKTYPE (REF(ext)->type);
|
||||
if (ext_type->meta == ty_alias) {
|
||||
ext_type = WORKTYPE (ext_type->t.alias.aux_type);
|
||||
ext_type = WORKTYPE (ext_type->alias.aux_type);
|
||||
}
|
||||
def_type = WORKTYPE (REF (def)->type);
|
||||
if (def_type->meta == ty_alias) {
|
||||
def_type = WORKTYPE (def_type->t.alias.aux_type);
|
||||
def_type = WORKTYPE (def_type->alias.aux_type);
|
||||
}
|
||||
if (ext_type != def_type) {
|
||||
linker_type_mismatch (REF (ext), REF (def));
|
||||
|
@ -428,7 +428,7 @@ process_type_def (defref_t *ref, qfo_mspace_t *space, qfo_def_t *old)
|
|||
// new address in the encoding's class field so def and function types
|
||||
// can be updated easily.
|
||||
old_type->meta = -1;
|
||||
old_type->t.class = REF (ref)->offset;
|
||||
old_type->class = REF (ref)->offset;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,7 +510,7 @@ add_defs (qfo_t *qfo, qfo_mspace_t *space, qfo_mspace_t *dest_space,
|
|||
}
|
||||
// Type encodings have no type (type = 0) so setting the type
|
||||
// to the idef type class has no effect.
|
||||
odef->type = type->t.class; // pointer to type in work
|
||||
odef->type = type->class; // pointer to type in work
|
||||
// don't add unused (no attached relocs) external defs to the work
|
||||
// defref list so they will not cause unused object files to be
|
||||
// pulled in from libraries
|
||||
|
@ -920,7 +920,7 @@ process_funcs (qfo_t *qfo)
|
|||
while (work->num_funcs < size) {
|
||||
func = work->funcs + work->num_funcs++;
|
||||
type = QFOTYPE(func->type);
|
||||
func->type = type->t.class;
|
||||
func->type = type->class;
|
||||
func->name = linker_add_string (QFOSTR (qfo, func->name));
|
||||
func->file = linker_add_string (QFOSTR (qfo, func->file));
|
||||
if (func->code > 0)
|
||||
|
|
|
@ -653,7 +653,7 @@ get_def_type (qfo_t *qfo, pointer_t type)
|
|||
case ty_basic:
|
||||
// field, pointer and function types store their basic type in
|
||||
// the same location.
|
||||
return type_def->t.type;
|
||||
return type_def->type;
|
||||
case ty_struct:
|
||||
case ty_union:
|
||||
return ev_invalid;
|
||||
|
@ -678,19 +678,19 @@ get_type_size (qfo_t *qfo, pointer_t type)
|
|||
type_def = QFO_POINTER (qfo, qfo_type_space, qfot_type_t, type);
|
||||
switch ((ty_meta_e)type_def->meta) {
|
||||
case ty_alias:
|
||||
return get_type_size (qfo, type_def->t.alias.aux_type);
|
||||
return get_type_size (qfo, type_def->alias.aux_type);
|
||||
case ty_basic:
|
||||
// field, pointer and function types store their basic type in
|
||||
// the same location.
|
||||
return pr_type_size[type_def->t.type];
|
||||
return pr_type_size[type_def->type];
|
||||
case ty_struct:
|
||||
for (i = size = 0; i < type_def->t.strct.num_fields; i++)
|
||||
size += get_type_size (qfo, type_def->t.strct.fields[i].type);
|
||||
for (i = size = 0; i < type_def->strct.num_fields; i++)
|
||||
size += get_type_size (qfo, type_def->strct.fields[i].type);
|
||||
return size;
|
||||
case ty_union:
|
||||
for (i = size = 0; i < type_def->t.strct.num_fields; i++) {
|
||||
for (i = size = 0; i < type_def->strct.num_fields; i++) {
|
||||
int s;
|
||||
s = get_type_size (qfo, type_def->t.strct.fields[i].type);
|
||||
s = get_type_size (qfo, type_def->strct.fields[i].type);
|
||||
if (s > size)
|
||||
size = s;
|
||||
}
|
||||
|
@ -698,8 +698,8 @@ get_type_size (qfo_t *qfo, pointer_t type)
|
|||
case ty_enum:
|
||||
return pr_type_size[ev_integer];
|
||||
case ty_array:
|
||||
return type_def->t.array.size
|
||||
* get_type_size (qfo, type_def->t.array.type);
|
||||
return type_def->array.size
|
||||
* get_type_size (qfo, type_def->array.type);
|
||||
case ty_class:
|
||||
return 0; // FIXME
|
||||
}
|
||||
|
@ -728,15 +728,15 @@ get_type_alignment_log (qfo_t *qfo, pointer_t type)
|
|||
type_def = QFO_POINTER (qfo, qfo_type_space, qfot_type_t, type);
|
||||
switch ((ty_meta_e)type_def->meta) {
|
||||
case ty_alias:
|
||||
return get_type_alignment_log (qfo, type_def->t.alias.aux_type);
|
||||
return get_type_alignment_log (qfo, type_def->alias.aux_type);
|
||||
case ty_basic:
|
||||
// field, pointer and function types store their basic type in
|
||||
// the same location.
|
||||
return qfo_log2 (ev_types[type_def->t.type]->alignment);
|
||||
return qfo_log2 (ev_types[type_def->type]->alignment);
|
||||
case ty_struct:
|
||||
case ty_union:
|
||||
for (i = alignment = 0; i < type_def->t.strct.num_fields; i++) {
|
||||
qfot_var_t *field = type_def->t.strct.fields + i;
|
||||
for (i = alignment = 0; i < type_def->strct.num_fields; i++) {
|
||||
qfot_var_t *field = type_def->strct.fields + i;
|
||||
int a;
|
||||
a = get_type_alignment_log (qfo, field->type);
|
||||
if (a > alignment) {
|
||||
|
@ -747,7 +747,7 @@ get_type_alignment_log (qfo_t *qfo, pointer_t type)
|
|||
case ty_enum:
|
||||
return qfo_log2 (ev_types[ev_integer]->alignment);
|
||||
case ty_array:
|
||||
return get_type_alignment_log (qfo, type_def->t.array.type);
|
||||
return get_type_alignment_log (qfo, type_def->array.type);
|
||||
case ty_class:
|
||||
return 0; // FIXME
|
||||
}
|
||||
|
@ -776,15 +776,15 @@ function_params (qfo_t *qfo, qfo_func_t *func, dfunction_t *df)
|
|||
type = QFO_POINTER (qfo, qfo_type_space, qfot_type_t, func->type);
|
||||
if (type->meta == ty_alias) {
|
||||
type = QFO_POINTER (qfo, qfo_type_space, qfot_type_t,
|
||||
type->t.alias.aux_type);
|
||||
type->alias.aux_type);
|
||||
}
|
||||
if (type->meta != ty_basic || type->t.type != ev_func)
|
||||
if (type->meta != ty_basic || type->type != ev_func)
|
||||
return;
|
||||
df->numparms = num_params = type->t.func.num_params;
|
||||
df->numparms = num_params = type->func.num_params;
|
||||
if (num_params < 0)
|
||||
num_params = ~num_params;
|
||||
for (i = 0; i < num_params; i++) {
|
||||
df->parm_size[i] = get_parmsize (qfo, type->t.func.param_types[i]);
|
||||
df->parm_size[i] = get_parmsize (qfo, type->func.param_types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1234,9 +1234,9 @@ qfo_to_sym (qfo_t *qfo, int *size)
|
|||
type = QFO_POINTER (qfo, qfo_type_space, qfot_type_t, func->type);
|
||||
if (type->meta == ty_alias) {
|
||||
type = QFO_POINTER (qfo, qfo_type_space, qfot_type_t,
|
||||
type->t.alias.aux_type);
|
||||
type->alias.aux_type);
|
||||
}
|
||||
aux->return_type = type->t.func.return_type;
|
||||
aux->return_type = type->func.return_type;
|
||||
aux++;
|
||||
}
|
||||
memcpy (linenos, qfo->lines, qfo->num_lines * sizeof (pr_lineno_t));
|
||||
|
|
|
@ -80,7 +80,7 @@ qfo_new_encoding (type_t *type, int size, defspace_t *space)
|
|||
qfot_type_t *enc;
|
||||
def_t *def;
|
||||
|
||||
size += sizeof (qfot_type_t) - sizeof (enc->t);
|
||||
size += field_offset (qfot_type_t, type);
|
||||
size /= sizeof (pr_type_t);
|
||||
|
||||
def = new_def (type->encoding, 0, space, sc_static);
|
||||
|
@ -117,7 +117,7 @@ qfo_encode_func (type_t *type, defspace_t *space)
|
|||
|
||||
def = qfo_new_encoding (type, size, space);
|
||||
enc = D_POINTER (qfot_type_t, def);
|
||||
func = &enc->t.func;
|
||||
func = &enc->func;
|
||||
func->type = ev_func;
|
||||
ENC_DEF (func->return_type, return_type_def);
|
||||
func->num_params = type->t.func.num_params;
|
||||
|
@ -134,10 +134,10 @@ qfo_encode_fldptr (type_t *type, defspace_t *space)
|
|||
def_t *type_def;
|
||||
|
||||
type_def = qfo_encode_type (type->t.fldptr.type, space);
|
||||
def = qfo_new_encoding (type, sizeof (enc->t.fldptr), space);
|
||||
def = qfo_new_encoding (type, sizeof (enc->fldptr), space);
|
||||
enc = D_POINTER (qfot_type_t, def);
|
||||
enc->t.fldptr.type = type->type;
|
||||
ENC_DEF (enc->t.fldptr.aux_type, type_def);
|
||||
enc->fldptr.type = type->type;
|
||||
ENC_DEF (enc->fldptr.aux_type, type_def);
|
||||
return def;
|
||||
}
|
||||
|
||||
|
@ -152,9 +152,9 @@ qfo_encode_basic (type_t *type, defspace_t *space)
|
|||
else if (type->type == ev_pointer || type->type == ev_field)
|
||||
return qfo_encode_fldptr (type, space);
|
||||
|
||||
def = qfo_new_encoding (type, sizeof (enc->t.type), space);
|
||||
def = qfo_new_encoding (type, sizeof (enc->type), space);
|
||||
enc = D_POINTER (qfot_type_t, def);
|
||||
enc->t.type = type->type;
|
||||
enc->type = type->type;
|
||||
return def;
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ qfo_encode_struct (type_t *type, defspace_t *space)
|
|||
size = field_offset (qfot_struct_t, fields[num_fields]);
|
||||
def = qfo_new_encoding (type, size, space);
|
||||
enc = D_POINTER (qfot_type_t, def);
|
||||
strct = &enc->t.strct;
|
||||
strct = &enc->strct;
|
||||
ENC_STR (strct->tag, type->name);
|
||||
strct->num_fields = num_fields;
|
||||
|
||||
|
@ -234,11 +234,11 @@ qfo_encode_array (type_t *type, defspace_t *space)
|
|||
|
||||
array_type_def = qfo_encode_type (type->t.array.type, space);
|
||||
|
||||
def = qfo_new_encoding (type, sizeof (enc->t.array), space);
|
||||
def = qfo_new_encoding (type, sizeof (enc->array), space);
|
||||
enc = D_POINTER (qfot_type_t, def);
|
||||
ENC_DEF (enc->t.array.type, array_type_def);
|
||||
enc->t.array.base = type->t.array.base;
|
||||
enc->t.array.size = type->t.array.size;
|
||||
ENC_DEF (enc->array.type, array_type_def);
|
||||
enc->array.base = type->t.array.base;
|
||||
enc->array.size = type->t.array.size;
|
||||
return def;
|
||||
}
|
||||
|
||||
|
@ -248,9 +248,9 @@ qfo_encode_class (type_t *type, defspace_t *space)
|
|||
qfot_type_t *enc;
|
||||
def_t *def;
|
||||
|
||||
def = qfo_new_encoding (type, sizeof (enc->t.class), space);
|
||||
def = qfo_new_encoding (type, sizeof (enc->class), space);
|
||||
enc = D_POINTER (qfot_type_t, def);
|
||||
ENC_STR (enc->t.class, type->t.class->name);
|
||||
ENC_STR (enc->class, type->t.class->name);
|
||||
return def;
|
||||
}
|
||||
|
||||
|
@ -265,13 +265,13 @@ qfo_encode_alias (type_t *type, defspace_t *space)
|
|||
type_def = qfo_encode_type (type->t.alias.aux_type, space);
|
||||
full_def = qfo_encode_type (type->t.alias.full_type, space);
|
||||
|
||||
def = qfo_new_encoding (type, sizeof (enc->t.alias), space);
|
||||
def = qfo_new_encoding (type, sizeof (enc->alias), space);
|
||||
enc = D_POINTER (qfot_type_t, def);
|
||||
enc->t.alias.type = type->type;
|
||||
ENC_DEF (enc->t.alias.aux_type, type_def);
|
||||
ENC_DEF (enc->t.alias.full_type, full_def);
|
||||
enc->alias.type = type->type;
|
||||
ENC_DEF (enc->alias.aux_type, type_def);
|
||||
ENC_DEF (enc->alias.full_type, full_def);
|
||||
if (type->name) {
|
||||
ENC_STR (enc->t.alias.name, type->name);
|
||||
ENC_STR (enc->alias.name, type->name);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue