mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 01:11:45 +00:00
[qfcc] Remove type alias encoding
It proved to be too fragile in its current implementation. It broke pointers to incomplete structs and switch enum checking, and getting it to work for other things was overly invasive. I still want the encoding, but need to come up with something more robust.a
This commit is contained in:
parent
1033716b2b
commit
caa297b756
11 changed files with 8 additions and 112 deletions
|
@ -47,14 +47,8 @@ typedef enum {
|
|||
ty_enum,
|
||||
ty_array,
|
||||
ty_class,
|
||||
ty_alias,
|
||||
} ty_meta_e;
|
||||
|
||||
typedef struct qfot_alias_s {
|
||||
pr_int_t type; ///< type at end of alias chain
|
||||
pointer_t aux_type; ///< referenced type
|
||||
string_t name; ///< alias name
|
||||
} qfot_alias_t;
|
||||
|
||||
typedef struct qfot_fldptr_s {
|
||||
pr_int_t type; ///< ev_field or ev_pointer
|
||||
|
@ -110,7 +104,6 @@ typedef struct qfot_type_s {
|
|||
qfot_struct_t strct; ///< ty_struct/ty_union/ty_enum
|
||||
qfot_array_t array; ///< ty_array
|
||||
string_t class; ///< ty_class
|
||||
qfot_alias_t alias; ///< ty_alias
|
||||
} t;
|
||||
} qfot_type_t;
|
||||
|
||||
|
|
|
@ -51,10 +51,6 @@ typedef struct ty_array_s {
|
|||
int size;
|
||||
} ty_array_t;
|
||||
|
||||
typedef struct ty_alias_s {
|
||||
struct type_s *type;
|
||||
} ty_alias_t;
|
||||
|
||||
typedef struct type_s {
|
||||
etype_t type; ///< ev_invalid means structure/array etc
|
||||
const char *name;
|
||||
|
@ -68,7 +64,6 @@ typedef struct type_s {
|
|||
ty_array_t array;
|
||||
struct symtab_s *symtab;
|
||||
struct class_s *class;
|
||||
ty_alias_t alias;
|
||||
} t;
|
||||
struct type_s *next;
|
||||
int freeable;
|
||||
|
@ -133,9 +128,8 @@ void chain_type (type_t *type);
|
|||
|
||||
/** Append a type to the end of a type chain.
|
||||
|
||||
The type chain must be made up of only field, pointer, function, array
|
||||
and alias (typedef) types, as other types do not have auxiliary type
|
||||
fields.
|
||||
The type chain must be made up of only field, pointer, function, and
|
||||
array types, as other types do not have auxiliary type fields.
|
||||
|
||||
\param type The type chain to which the type will be appended.
|
||||
\param new The type to be appended. May be any type.
|
||||
|
@ -149,13 +143,11 @@ type_t *field_type (type_t *aux);
|
|||
type_t *pointer_type (type_t *aux);
|
||||
type_t *array_type (type_t *aux, int size);
|
||||
type_t *based_array_type (type_t *aux, int base, int top);
|
||||
type_t *alias_type (type_t *aux, const char *name);
|
||||
void print_type_str (struct dstring_s *str, const type_t *type);
|
||||
void print_type (const type_t *type);
|
||||
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);
|
||||
const type_t *unalias_type (const type_t *type) __attribute__((pure));
|
||||
int is_void (const type_t *type) __attribute__((pure));
|
||||
int is_enum (const type_t *type) __attribute__((pure));
|
||||
int is_integer (const type_t *type) __attribute__((pure));
|
||||
|
|
|
@ -358,7 +358,7 @@ init_elements (struct def_s *def, expr_t *eles)
|
|||
num_elements = i;
|
||||
} else if (is_struct (def->type) || is_vector (def->type)
|
||||
|| is_quaternion (def->type)) {
|
||||
symtab_t *symtab = unalias_type (def->type)->t.symtab;
|
||||
symtab_t *symtab = def->type->t.symtab;
|
||||
symbol_t *field;
|
||||
|
||||
for (i = 0, field = symtab->symbols; field; field = field->next) {
|
||||
|
|
|
@ -547,10 +547,6 @@ dump_qfo_types (qfo_t *qfo, int base_address)
|
|||
printf (" %-5x %d %d\n", type->t.array.type,
|
||||
type->t.array.base, type->t.array.size);
|
||||
break;
|
||||
case ty_alias:
|
||||
printf (" %s %d %-5x\n", QFO_GETSTR (qfo, type->t.alias.name),
|
||||
type->t.alias.type, type->t.alias.aux_type);
|
||||
break;
|
||||
case ty_class:
|
||||
printf (" %-5x\n", type->t.class);
|
||||
break;
|
||||
|
|
|
@ -1140,7 +1140,7 @@ append_expr (expr_t *block, expr_t *e)
|
|||
static symbol_t *
|
||||
get_struct_field (const type_t *t1, expr_t *e1, expr_t *e2)
|
||||
{
|
||||
symtab_t *strct = unalias_type (t1)->t.symtab;
|
||||
symtab_t *strct = t1->t.symtab;
|
||||
symbol_t *sym = e2->e.symbol;//FIXME need to check
|
||||
symbol_t *field;
|
||||
|
||||
|
@ -1165,7 +1165,6 @@ field_expr (expr_t *e1, expr_t *e2)
|
|||
t1 = get_type (e1);
|
||||
if (e1->type == ex_error)
|
||||
return e1;
|
||||
t1 = unalias_type (t1);
|
||||
if (t1->type == ev_entity) {
|
||||
symbol_t *field = 0;
|
||||
|
||||
|
@ -1639,7 +1638,6 @@ build_function_call (expr_t *fexpr, const type_t *ftype, expr_t *params)
|
|||
expr_t *call;
|
||||
expr_t *err = 0;
|
||||
|
||||
ftype = unalias_type (ftype);
|
||||
|
||||
for (e = params; e; e = e->next) {
|
||||
if (e->type == ex_error)
|
||||
|
@ -2375,7 +2373,7 @@ cast_expr (type_t *dstType, expr_t *e)
|
|||
|
||||
srcType = get_type (e);
|
||||
|
||||
if (unalias_type (dstType) == unalias_type (srcType))
|
||||
if (dstType == srcType)
|
||||
return e;
|
||||
|
||||
if ((dstType == type_default && is_enum (srcType))
|
||||
|
|
|
@ -177,10 +177,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) {
|
||||
// FIXME this cast should not be necessary, but making the
|
||||
// type system const-correct would probably take a rewrite
|
||||
type_t *t = (type_t *) unalias_type (p->type);
|
||||
new->t.func.param_types[new->t.func.num_params] = t;
|
||||
new->t.func.param_types[new->t.func.num_params] = p->type;
|
||||
new->t.func.num_params++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -648,10 +648,8 @@ get_def_type (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_basic:
|
||||
case ty_alias:
|
||||
// field, pointer and function types store their basic type in
|
||||
// the same location.
|
||||
// alias types store the basic type at the end of the alias chain
|
||||
return type_def->t.type;
|
||||
case ty_struct:
|
||||
case ty_union:
|
||||
|
@ -676,8 +674,6 @@ get_type_size (qfo_t *qfo, pointer_t type)
|
|||
return 1;
|
||||
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);
|
||||
case ty_basic:
|
||||
// field, pointer and function types store their basic type in
|
||||
// the same location.
|
||||
|
@ -726,8 +722,6 @@ get_type_alignment_log (qfo_t *qfo, pointer_t type)
|
|||
return 0;
|
||||
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);
|
||||
case ty_basic:
|
||||
// field, pointer and function types store their basic type in
|
||||
// the same location.
|
||||
|
|
|
@ -253,23 +253,6 @@ qfo_encode_class (type_t *type)
|
|||
return def;
|
||||
}
|
||||
|
||||
static def_t *
|
||||
qfo_encode_alias (type_t *type)
|
||||
{
|
||||
qfot_type_t *enc;
|
||||
def_t *def;
|
||||
def_t *alias_type_def;
|
||||
|
||||
alias_type_def = qfo_encode_type (type->t.alias.type);
|
||||
|
||||
def = qfo_new_encoding (type, sizeof (enc->t.alias));
|
||||
enc = D_POINTER (qfot_type_t, def);
|
||||
enc->t.alias.type = type->type;
|
||||
ENC_DEF (enc->t.alias.aux_type, alias_type_def);
|
||||
ENC_STR (enc->t.alias.name, type->name);
|
||||
return def;
|
||||
}
|
||||
|
||||
def_t *
|
||||
qfo_encode_type (type_t *type)
|
||||
{
|
||||
|
@ -282,7 +265,6 @@ qfo_encode_type (type_t *type)
|
|||
qfo_encode_struct, // ty_enum
|
||||
qfo_encode_array, // ty_array
|
||||
qfo_encode_class, // ty_class
|
||||
qfo_encode_alias, // ty_alias
|
||||
};
|
||||
|
||||
if (type->type_def && type->type_def->external) {
|
||||
|
|
|
@ -406,7 +406,6 @@ external_decl
|
|||
$1->type = find_type (append_type ($1->type, spec.type));
|
||||
if (spec.is_typedef) {
|
||||
$1->sy_type = sy_type;
|
||||
$1->type = alias_type ($1->type, $1->name);
|
||||
symtab_addsymbol (current_symtab, $1);
|
||||
} else {
|
||||
initialize_def ($1, 0, current_symtab->space, spec.storage);
|
||||
|
@ -422,7 +421,6 @@ external_decl
|
|||
if (spec.is_typedef) {
|
||||
error (0, "typedef %s is initialized", $1->name);
|
||||
$1->sy_type = sy_type;
|
||||
$1->type = alias_type ($1->type, $1->name);
|
||||
symtab_addsymbol (current_symtab, $1);
|
||||
} else {
|
||||
initialize_def ($1, $2, current_symtab->space, spec.storage);
|
||||
|
@ -436,7 +434,6 @@ external_decl
|
|||
$1->type = find_type (append_type ($1->type, spec.type));
|
||||
if (spec.is_typedef) {
|
||||
$1->sy_type = sy_type;
|
||||
$1->type = alias_type ($1->type, $1->name);
|
||||
symtab_addsymbol (current_symtab, $1);
|
||||
} else {
|
||||
$1 = function_symbol ($1, spec.is_overload, 1);
|
||||
|
|
|
@ -297,8 +297,6 @@ types_same (type_t *a, type_t *b)
|
|||
if (a->t.class != b->t.class)
|
||||
return 0;
|
||||
return compare_protocols (a->protos, b->protos);
|
||||
case ty_alias:
|
||||
return !strcmp (a->name, b->name);
|
||||
}
|
||||
internal_error (0, "we be broke");
|
||||
}
|
||||
|
@ -348,9 +346,6 @@ find_type (type_t *type)
|
|||
break;
|
||||
case ty_class:
|
||||
break;
|
||||
case ty_alias:
|
||||
type->t.alias.type = find_type (type->t.alias.type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -450,25 +445,6 @@ based_array_type (type_t *aux, int base, int top)
|
|||
return new;
|
||||
}
|
||||
|
||||
type_t *
|
||||
alias_type (type_t *aux, const char *name)
|
||||
{
|
||||
type_t _new;
|
||||
type_t *new = &_new;
|
||||
|
||||
if (!aux || !name) {
|
||||
internal_error (0, "alias to null type or with no name");
|
||||
}
|
||||
memset (&_new, 0, sizeof (_new));
|
||||
new->name = save_string (name);
|
||||
new->meta = ty_alias;
|
||||
new->type = aux->type;
|
||||
new->alignment = aux->alignment;
|
||||
new->t.alias.type = aux;
|
||||
new = find_type (new);
|
||||
return new;
|
||||
}
|
||||
|
||||
void
|
||||
print_type_str (dstring_t *str, const type_t *type)
|
||||
{
|
||||
|
@ -500,11 +476,6 @@ print_type_str (dstring_t *str, const type_t *type)
|
|||
dasprintf (str, "[%d]", type->t.array.size);
|
||||
}
|
||||
return;
|
||||
case ty_alias:
|
||||
dasprintf (str, "({%s=", type->name);
|
||||
print_type_str (str, type->t.alias.type);
|
||||
dstring_appendstr (str, "})");
|
||||
return;
|
||||
case ty_basic:
|
||||
switch (type->type) {
|
||||
case ev_field:
|
||||
|
@ -658,11 +629,6 @@ encode_type (dstring_t *encoding, const type_t *type)
|
|||
encode_type (encoding, type->t.array.type);
|
||||
dasprintf (encoding, "]");
|
||||
return;
|
||||
case ty_alias:
|
||||
dasprintf (encoding, "{%s>", type->name);
|
||||
encode_type (encoding, type->t.alias.type);
|
||||
dasprintf (encoding, "}");
|
||||
return;
|
||||
case ty_basic:
|
||||
switch (type->type) {
|
||||
case ev_void:
|
||||
|
@ -730,15 +696,6 @@ encode_type (dstring_t *encoding, const type_t *type)
|
|||
internal_error (0, "bad type meta:type %d:%d", type->meta, type->type);
|
||||
}
|
||||
|
||||
const type_t *
|
||||
unalias_type (const type_t *type)
|
||||
{
|
||||
while (type->meta == ty_alias) {
|
||||
type = type->t.alias.type;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
int
|
||||
is_void (const type_t *type)
|
||||
{
|
||||
|
@ -748,7 +705,6 @@ is_void (const type_t *type)
|
|||
int
|
||||
is_enum (const type_t *type)
|
||||
{
|
||||
type = unalias_type (type);
|
||||
if (type->type == ev_invalid && type->meta == ty_enum)
|
||||
return 1;
|
||||
return 0;
|
||||
|
@ -833,7 +789,6 @@ is_math (const type_t *type)
|
|||
int
|
||||
is_struct (const type_t *type)
|
||||
{
|
||||
type = unalias_type (type);
|
||||
if (type->type == ev_invalid
|
||||
&& (type->meta == ty_struct || type->meta == ty_union))
|
||||
return 1;
|
||||
|
@ -859,7 +814,6 @@ is_field (const type_t *type)
|
|||
int
|
||||
is_array (const type_t *type)
|
||||
{
|
||||
type = unalias_type (type);
|
||||
if (type->type == ev_invalid && type->meta == ty_array)
|
||||
return 1;
|
||||
return 0;
|
||||
|
@ -884,8 +838,6 @@ is_string (const type_t *type)
|
|||
int
|
||||
type_compatible (const type_t *dst, const type_t *src)
|
||||
{
|
||||
dst = unalias_type (dst);
|
||||
src = unalias_type (src);
|
||||
// same type
|
||||
if (dst == src) {
|
||||
return 1;
|
||||
|
@ -905,8 +857,6 @@ type_compatible (const type_t *dst, const type_t *src)
|
|||
int
|
||||
type_assignable (const type_t *dst, const type_t *src)
|
||||
{
|
||||
dst = unalias_type (dst);
|
||||
src = unalias_type (src);
|
||||
int ret;
|
||||
|
||||
// same type
|
||||
|
@ -932,8 +882,8 @@ type_assignable (const type_t *dst, const type_t *src)
|
|||
if (ret >= 0)
|
||||
return ret;
|
||||
|
||||
dst = unalias_type (dst->t.fldptr.type);
|
||||
src = unalias_type (src->t.fldptr.type);
|
||||
dst = dst->t.fldptr.type;
|
||||
src = src->t.fldptr.type;
|
||||
if (dst == src) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -972,8 +922,6 @@ type_size (const type_t *type)
|
|||
size += type_size (class->super_class->type);
|
||||
return size;
|
||||
}
|
||||
case ty_alias:
|
||||
return type_size (type->t.alias.type);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ test_progs_dat=\
|
|||
structstruct.dat \
|
||||
swap.dat \
|
||||
triangle.dat \
|
||||
typedef.dat \
|
||||
vecexpr.dat \
|
||||
vecinit.dat \
|
||||
voidfor.dat \
|
||||
|
|
Loading…
Reference in a new issue