[qfcc] Make the type union anonymous

This one has bothered me for a long time. I don't remember why it was
difficult at one stage, maybe I had some poor name choices.
This commit is contained in:
Bill Currie 2024-08-16 17:23:29 +09:00
parent e5bd2591c2
commit 561f4c2ea0
24 changed files with 279 additions and 282 deletions

View file

@ -84,7 +84,7 @@ typedef struct type_s {
struct algebra_s *algebra; struct algebra_s *algebra;
struct multivector_s *multivec; struct multivector_s *multivec;
ty_alias_t alias; ty_alias_t alias;
} t; };
struct type_s *next; struct type_s *next;
int freeable; int freeable;
int allocated; int allocated;

View file

@ -327,7 +327,7 @@ algebra_init (algebra_t *a)
} }
} }
auto type = algebra_mvec_type (a, (1 << a->layout.count) - 1); auto type = algebra_mvec_type (a, (1 << a->layout.count) - 1);
a->mvec_sym = type->t.multivec->mvec_sym; a->mvec_sym = type->multivec->mvec_sym;
} }
bool bool
@ -406,7 +406,7 @@ algebra_type (const type_t *type, const expr_t *params)
t->meta = ty_algebra; t->meta = ty_algebra;
t->type = ev_invalid; t->type = ev_invalid;
t->alignment = (dim > 1 ? 4 : 2) * type->alignment; t->alignment = (dim > 1 ? 4 : 2) * type->alignment;
t->t.algebra = algebra; t->algebra = algebra;
algebra->algebra_type = t; algebra->algebra_type = t;
return find_type (t); return find_type (t);
} }
@ -435,7 +435,7 @@ algebra_subtype (const type_t *type, attribute_t *attr)
} }
return algebra_mvec_type (algebra, mask); return algebra_mvec_type (algebra, mask);
} }
auto symtab = algebra->mvec_sym->type->t.symtab; auto symtab = algebra->mvec_sym->type->symtab;
auto field = symtab_lookup (symtab, attr->name); auto field = symtab_lookup (symtab, attr->name);
if (field) { if (field) {
return field->type; return field->type;
@ -524,7 +524,7 @@ algebra_mvec_type (algebra_t *algebra, pr_uint_t group_mask)
.alignment = algebra_alignment (algebra->type, components), .alignment = algebra_alignment (algebra->type, components),
.width = components, .width = components,
.meta = ty_algebra, .meta = ty_algebra,
.t.algebra = (algebra_t *) mvec, .algebra = (algebra_t *) mvec,
.freeable = true, .freeable = true,
.allocated = true, .allocated = true,
}; };
@ -662,7 +662,7 @@ algebra_scope (const type_t *type, symtab_t *curscope)
return scope; return scope;
} }
scope->procsymbol = algebra_symbol; scope->procsymbol = algebra_symbol;
scope->procsymbol_data = unalias_type (type)->t.algebra; scope->procsymbol_data = unalias_type (type)->algebra;
return scope; return scope;
} }
@ -671,9 +671,9 @@ algebra_get (const type_t *type)
{ {
type = unalias_type (type); type = unalias_type (type);
if (type->type == ev_invalid) { if (type->type == ev_invalid) {
return type->t.algebra; return type->algebra;
} else { } else {
return type->t.multivec->algebra; return type->multivec->algebra;
} }
} }
@ -700,11 +700,11 @@ void
algebra_print_type_str (dstring_t *str, const type_t *type) algebra_print_type_str (dstring_t *str, const type_t *type)
{ {
if (type->type == ev_invalid) { if (type->type == ev_invalid) {
auto a = type->t.algebra; auto a = type->algebra;
dasprintf (str, " algebra(%s(%d,%d,%d))", a->type->name, dasprintf (str, " algebra(%s(%d,%d,%d))", a->type->name,
a->plus, a->minus, a->zero); a->plus, a->minus, a->zero);
} else if (type->type == ev_float || type->type == ev_double) { } else if (type->type == ev_float || type->type == ev_double) {
auto m = type->t.multivec; auto m = type->multivec;
auto a = m->algebra; auto a = m->algebra;
dasprintf (str, " algebra(%s(%d,%d,%d):%04x)", a->type->name, dasprintf (str, " algebra(%s(%d,%d,%d):%04x)", a->type->name,
a->plus, a->minus, a->zero, m->group_mask); a->plus, a->minus, a->zero, m->group_mask);
@ -717,12 +717,12 @@ void
algebra_encode_type (dstring_t *encoding, const type_t *type) algebra_encode_type (dstring_t *encoding, const type_t *type)
{ {
if (type->type == ev_invalid) { if (type->type == ev_invalid) {
auto a = type->t.algebra; auto a = type->algebra;
dasprintf (encoding, "{∧"); dasprintf (encoding, "{∧");
encode_type (encoding, a->type); encode_type (encoding, a->type);
dasprintf (encoding, "(%d,%d,%d)}", a->plus, a->minus, a->zero); dasprintf (encoding, "(%d,%d,%d)}", a->plus, a->minus, a->zero);
} else if (type->type == ev_float || type->type == ev_double) { } else if (type->type == ev_float || type->type == ev_double) {
auto m = type->t.multivec; auto m = type->multivec;
auto a = m->algebra; auto a = m->algebra;
dasprintf (encoding, "{∧"); dasprintf (encoding, "{∧");
encode_type (encoding, a->type); encode_type (encoding, a->type);
@ -737,10 +737,10 @@ int
algebra_type_size (const type_t *type) algebra_type_size (const type_t *type)
{ {
if (type->type == ev_invalid) { if (type->type == ev_invalid) {
auto a = type->t.algebra; auto a = type->algebra;
return a->num_components * type_size (a->type); return a->num_components * type_size (a->type);
} else if (type->type == ev_float || type->type == ev_double) { } else if (type->type == ev_float || type->type == ev_double) {
auto m = type->t.multivec; auto m = type->multivec;
int size = 0; int size = 0;
if (m->group_mask & (m->group_mask - 1)) { if (m->group_mask & (m->group_mask - 1)) {
if (!m->mvec_sym) { if (!m->mvec_sym) {
@ -762,7 +762,7 @@ algebra_type_width (const type_t *type)
if (type->type == ev_invalid) { if (type->type == ev_invalid) {
return 0; return 0;
} else if (type->type == ev_float || type->type == ev_double) { } else if (type->type == ev_float || type->type == ev_double) {
auto m = type->t.multivec; auto m = type->multivec;
return m->num_components; return m->num_components;
} else { } else {
internal_error (0, "invalid algebra type"); internal_error (0, "invalid algebra type");
@ -793,7 +793,7 @@ algebra_type_assignable (const type_t *dst, const type_t *src)
if (src->meta != ty_algebra) { if (src->meta != ty_algebra) {
return 0; return 0;
} }
if (src->t.multivec->algebra != dst->t.algebra) { if (src->multivec->algebra != dst->algebra) {
return 0; return 0;
} }
// the multivec is a member of the destination algebra // the multivec is a member of the destination algebra
@ -801,10 +801,10 @@ algebra_type_assignable (const type_t *dst, const type_t *src)
} }
if (!is_algebra (src)) { if (!is_algebra (src)) {
if (is_scalar (src)) { if (is_scalar (src)) {
auto algebra = dst->t.multivec->algebra; auto algebra = dst->multivec->algebra;
auto layout = &algebra->layout; auto layout = &algebra->layout;
int group = layout->group_map[layout->mask_map[0]][0]; int group = layout->group_map[layout->mask_map[0]][0];
if (dst->t.multivec->group_mask & (1u << group)) { if (dst->multivec->group_mask & (1u << group)) {
// the source scalar is a member of the destination // the source scalar is a member of the destination
// multi-vector // multi-vector
return 1; return 1;
@ -812,10 +812,10 @@ algebra_type_assignable (const type_t *dst, const type_t *src)
} }
return 0; return 0;
} }
if (dst->t.multivec->algebra != src->t.multivec->algebra) { if (dst->multivec->algebra != src->multivec->algebra) {
return 0; return 0;
} }
if (src->t.multivec->group_mask & ~dst->t.multivec->group_mask) { if (src->multivec->group_mask & ~dst->multivec->group_mask) {
return 0; return 0;
} }
// the source multi-vector is a subset of the destinatin multi-vector // the source multi-vector is a subset of the destinatin multi-vector
@ -826,7 +826,7 @@ const type_t *
algebra_base_type (const type_t *type) algebra_base_type (const type_t *type)
{ {
if (type->type == ev_invalid) { if (type->type == ev_invalid) {
return type->t.algebra->type; return type->algebra->type;
} }
return ev_types[type->type]; return ev_types[type->type];
} }
@ -837,9 +837,9 @@ algebra_struct_type (const type_t *type)
symbol_t *sym = 0; symbol_t *sym = 0;
if (type->type == ev_invalid) { if (type->type == ev_invalid) {
sym = type->t.algebra->mvec_sym; sym = type->algebra->mvec_sym;
} else { } else {
sym = type->t.multivec->mvec_sym; sym = type->multivec->mvec_sym;
} }
return sym ? sym->type : 0; return sym ? sym->type : 0;
} }
@ -861,7 +861,7 @@ is_mono_grade (const type_t *type)
} }
auto alg = algebra_get (type); auto alg = algebra_get (type);
auto layout = &alg->layout; auto layout = &alg->layout;
auto multivec = type->t.multivec; auto multivec = type->multivec;
int grade = -1; int grade = -1;
for (int i = 0; i < layout->count; i++) { for (int i = 0; i < layout->count; i++) {
pr_uint_t mask = 1u << i; pr_uint_t mask = 1u << i;
@ -892,7 +892,7 @@ algebra_get_grade (const type_t *type)
} }
auto alg = algebra_get (type); auto alg = algebra_get (type);
auto layout = &alg->layout; auto layout = &alg->layout;
auto multivec = type->t.multivec; auto multivec = type->multivec;
for (int i = 0; i < layout->count; i++) { for (int i = 0; i < layout->count; i++) {
pr_uint_t mask = 1u << i; pr_uint_t mask = 1u << i;
if (mask & multivec->group_mask) { if (mask & multivec->group_mask) {

View file

@ -415,10 +415,10 @@ is_id (const type_t *type)
// a qualified obj_object struct // a qualified obj_object struct
if (type->type != ev_ptr) if (type->type != ev_ptr)
return 0; return 0;
if (!is_struct (type->t.fldptr.type)) if (!is_struct (type->fldptr.type))
return 0; return 0;
// if the the symtabs match, then type is id in disguise // if the the symtabs match, then type is id in disguise
if (type->t.fldptr.type->t.symtab == type_object.t.symtab) if (type->fldptr.type->symtab == type_object.symtab)
return 1; return 1;
return 0; return 0;
} }
@ -447,7 +447,7 @@ is_classptr (const type_t *type)
return 1; return 1;
if (type->type != ev_ptr) if (type->type != ev_ptr)
return 0; return 0;
type = type->t.fldptr.type; type = type->fldptr.type;
if (is_class (type)) if (is_class (type))
return 1; return 1;
return 0; return 0;
@ -481,9 +481,9 @@ static protocollist_t *
obj_get_class_protos (const type_t *type) obj_get_class_protos (const type_t *type)
{ {
if (is_ptr (type)) if (is_ptr (type))
type = type->t.fldptr.type; type = type->fldptr.type;
if (is_class (type)) if (is_class (type))
return type->t.class->protocols; return type->class->protocols;
return 0; return 0;
} }
@ -491,7 +491,7 @@ static protocollist_t *
obj_get_protos (const type_t *type) obj_get_protos (const type_t *type)
{ {
if (is_ptr (type)) if (is_ptr (type))
type = type->t.fldptr.type; type = type->fldptr.type;
return type->protos; return type->protos;
} }
@ -499,9 +499,9 @@ static category_t *
obj_get_categories (const type_t *type) obj_get_categories (const type_t *type)
{ {
if (is_ptr (type)) if (is_ptr (type))
type = type->t.fldptr.type; type = type->fldptr.type;
if (is_class (type)) if (is_class (type))
return type->t.class->categories; return type->class->categories;
return 0; return 0;
} }
@ -520,9 +520,9 @@ obj_classname (const type_t *type)
dstring_copystr (str, "Class"); dstring_copystr (str, "Class");
} else { } else {
if (is_ptr (type)) if (is_ptr (type))
type = type->t.fldptr.type; type = type->fldptr.type;
if (is_class (type)) if (is_class (type))
dstring_copystr (str, type->t.class->name); dstring_copystr (str, type->class->name);
} }
if ((protos = obj_get_protos (type))) if ((protos = obj_get_protos (type)))
print_protocollist (str, protos); print_protocollist (str, protos);
@ -595,9 +595,9 @@ obj_types_assignable (const type_t *dst, const type_t *src)
return 1; return 1;
// check dst is a base class of src // check dst is a base class of src
dst_class = dst->t.fldptr.type->t.class; dst_class = dst->fldptr.type->class;
if (src->t.fldptr.type->meta == ty_class) { if (src->fldptr.type->meta == ty_class) {
src_class = src->t.fldptr.type->t.class; src_class = src->fldptr.type->class;
} }
//printf ("%s %s\n", dst_class->name, src_class->name); //printf ("%s %s\n", dst_class->name, src_class->name);
while (dst_class != src_class && src_class) { while (dst_class != src_class && src_class) {
@ -714,7 +714,7 @@ get_class (symbol_t *sym, int create)
new.type = ev_invalid; new.type = ev_invalid;
new.name = c->name; new.name = c->name;
new.meta = ty_class; new.meta = ty_class;
new.t.class = c; new.class = c;
c->type = find_type (&new); c->type = find_type (&new);
if (sym) if (sym)
sym->type = c->type; sym->type = c->type;
@ -913,7 +913,7 @@ begin_class (class_t *class)
// root class of the hierachy. // root class of the hierachy.
// NOTE: type_class is not actually a class // NOTE: type_class is not actually a class
EMIT_DEF (space, meta->ivars, EMIT_DEF (space, meta->ivars,
emit_ivars (type_class.t.symtab, "Class")); emit_ivars (type_class.symtab, "Class"));
} else { } else {
meta->ivars = 0; meta->ivars = 0;
} }
@ -1254,7 +1254,7 @@ class_message_response (const type_t *clstype, int class_msg, const expr_t *sel)
return 0; return 0;
} }
if (is_id (clstype)) { if (is_id (clstype)) {
protocollist_t *protos = clstype->t.fldptr.type->protos; protocollist_t *protos = clstype->fldptr.type->protos;
if (protos) { if (protos) {
if ((m = protocollist_find_method (protos, selector, !class_msg))) { if ((m = protocollist_find_method (protos, selector, !class_msg))) {
return m; return m;
@ -1267,9 +1267,9 @@ class_message_response (const type_t *clstype, int class_msg, const expr_t *sel)
} }
} else { } else {
if (is_class (clstype)) { if (is_class (clstype)) {
class = clstype->t.class; class = clstype->class;
} else if (is_class (clstype->t.fldptr.type)) { } else if (is_class (clstype->fldptr.type)) {
class = clstype->t.fldptr.type->t.class; class = clstype->fldptr.type->class;
} }
if (class && !is_object(class->type)) { if (class && !is_object(class->type)) {
if (!class->interface_declared) { if (!class->interface_declared) {
@ -1503,7 +1503,7 @@ emit_symtab_ref_cnt (def_t *def, void *data, int index)
internal_error (0, "%s: expected int def", __FUNCTION__); internal_error (0, "%s: expected int def", __FUNCTION__);
D_INT (def) = 0; D_INT (def) = 0;
if (da->refs) if (da->refs)
D_INT (def) = da->refs->type->t.array.size; D_INT (def) = da->refs->type->array.size;
} }
static void static void

View file

@ -155,7 +155,7 @@ new_def (const char *name, const type_t *type, defspace_t *space,
if (is_class (type) if (is_class (type)
|| (is_array (type) && is_class(dereference_type (type)))) { || (is_array (type) && is_class(dereference_type (type)))) {
error (0, "statically allocated instance of class %s", error (0, "statically allocated instance of class %s",
type->t.class->name); type->class->name);
return def; return def;
} }
@ -300,7 +300,7 @@ def_to_ddef (def_t *def, ddef_t *ddef, int aux)
const type_t *type = unalias_type (def->type); const type_t *type = unalias_type (def->type);
if (aux) if (aux)
type = type->t.fldptr.type; // aux is true only for fields type = type->fldptr.type; // aux is true only for fields
ddef->type = type->type; ddef->type = type->type;
ddef->ofs = def->offset; ddef->ofs = def->offset;
ddef->name = ReuseString (def->name); ddef->name = ReuseString (def->name);

View file

@ -56,7 +56,7 @@ static void
print_pointer (dstring_t *dstr, const type_t *t, int level, int id) print_pointer (dstring_t *dstr, const type_t *t, int level, int id)
{ {
int indent = level * 2 + 2; int indent = level * 2 + 2;
auto aux = t->t.fldptr.type; auto aux = t->fldptr.type;
dot_print_type (dstr, aux, level, id); dot_print_type (dstr, aux, level, id);
dasprintf (dstr, "%*st_%p -> \"t_%p\";\n", indent, "", t, aux); dasprintf (dstr, "%*st_%p -> \"t_%p\";\n", indent, "", t, aux);
@ -81,7 +81,7 @@ static void
print_function (dstring_t *dstr, const type_t *t, int level, int id) print_function (dstring_t *dstr, const type_t *t, int level, int id)
{ {
int indent = level * 2 + 2; int indent = level * 2 + 2;
const ty_func_t *func = &t->t.func; const ty_func_t *func = &t->func;
const type_t *ret = func->ret_type; const type_t *ret = func->ret_type;
const type_t *param; const type_t *param;
@ -132,7 +132,7 @@ static void
print_struct (dstring_t *dstr, const type_t *t, int level, int id) print_struct (dstring_t *dstr, const type_t *t, int level, int id)
{ {
int indent = level * 2 + 2; int indent = level * 2 + 2;
const symtab_t *symtab = t->t.symtab; const symtab_t *symtab = t->symtab;
const symbol_t *sym; const symbol_t *sym;
int pnum; int pnum;
static const char *struct_type_names[3] = {"struct", "union", "enum"}; static const char *struct_type_names[3] = {"struct", "union", "enum"};
@ -189,17 +189,16 @@ static void
print_array (dstring_t *dstr, const type_t *t, int level, int id) print_array (dstring_t *dstr, const type_t *t, int level, int id)
{ {
int indent = level * 2 + 2; int indent = level * 2 + 2;
auto type = t->t.array.type; auto type = t->array.type;
dot_print_type (dstr, type, level, id); dot_print_type (dstr, type, level, id);
dasprintf (dstr, "%*st_%p -> \"t_%p\";\n", indent, "", t, type); dasprintf (dstr, "%*st_%p -> \"t_%p\";\n", indent, "", t, type);
if (t->t.array.base) { if (t->array.base) {
dasprintf (dstr, "%*st_%p [label=\"[%d..%d]\"];\n", indent, "", t, dasprintf (dstr, "%*st_%p [label=\"[%d..%d]\"];\n", indent, "", t,
t->t.array.base, t->array.base, t->array.base + t->array.size - 1);
t->t.array.base + t->t.array.size - 1);
} else { } else {
dasprintf (dstr, "%*st_%p [label=\"[%d]\"];\n", indent, "", t, dasprintf (dstr, "%*st_%p [label=\"[%d]\"];\n", indent, "", t,
t->t.array.size); t->array.size);
} }
} }
@ -208,15 +207,15 @@ print_class (dstring_t *dstr, const type_t *t, int level, int id)
{ {
int indent = level * 2 + 2; int indent = level * 2 + 2;
dasprintf (dstr, "%*st_%p [label=\"class '%s'\"];\n", indent, "", t, dasprintf (dstr, "%*st_%p [label=\"class '%s'\"];\n", indent, "", t,
t->t.class->name); t->class->name);
} }
static void static void
print_alias (dstring_t *dstr, const type_t *t, int level, int id) print_alias (dstring_t *dstr, const type_t *t, int level, int id)
{ {
int indent = level * 2 + 2; int indent = level * 2 + 2;
auto aux = t->t.alias.aux_type; auto aux = t->alias.aux_type;
auto full = t->t.alias.full_type; auto full = t->alias.full_type;
dot_print_type (dstr, aux, level, id); dot_print_type (dstr, aux, level, id);
dot_print_type (dstr, full, level, id); dot_print_type (dstr, full, level, id);

View file

@ -92,7 +92,7 @@ get_value_def (const expr_t *expr, ex_value_t *value, const type_t *type)
} }
if (is_ptr (type) && value->pointer.tempop && !value->pointer.def) { if (is_ptr (type) && value->pointer.tempop && !value->pointer.def) {
value->pointer.def = get_tempop_def (expr, value->pointer.tempop, value->pointer.def = get_tempop_def (expr, value->pointer.tempop,
type->t.fldptr.type); type->fldptr.type);
} }
def = emit_value (value, 0); def = emit_value (value, 0);
if (type != def->type) if (type != def->type)

View file

@ -1466,7 +1466,7 @@ get_name (const expr_t *e)
symbol_t * symbol_t *
get_struct_field (const type_t *t1, const expr_t *e1, const expr_t *e2) get_struct_field (const type_t *t1, const expr_t *e1, const expr_t *e2)
{ {
symtab_t *strct = t1->t.symtab; symtab_t *strct = t1->symtab;
symbol_t *sym = get_name (e2); symbol_t *sym = get_name (e2);
symbol_t *field; symbol_t *field;
@ -1527,15 +1527,15 @@ field_expr (const expr_t *e1, const expr_t *e2)
return e2; return e2;
if (t2->type == ev_field) { if (t2->type == ev_field) {
e = new_binary_expr ('.', e1, e2); e = new_binary_expr ('.', e1, e2);
e->expr.type = t2->t.fldptr.type; e->expr.type = t2->fldptr.type;
return e; return e;
} }
} }
} else if (is_ptr (t1)) { } else if (is_ptr (t1)) {
if (is_struct (t1->t.fldptr.type) || is_union (t1->t.fldptr.type)) { if (is_struct (t1->fldptr.type) || is_union (t1->fldptr.type)) {
symbol_t *field; symbol_t *field;
field = get_struct_field (t1->t.fldptr.type, e1, e2); field = get_struct_field (t1->fldptr.type, e1, e2);
if (!field) if (!field)
return e1; return e1;
@ -1546,8 +1546,8 @@ field_expr (const expr_t *e1, const expr_t *e2)
} }
e1 = cast_expr (pointer_type (field->type), e1); e1 = cast_expr (pointer_type (field->type), e1);
return unary_expr ('.', e1); return unary_expr ('.', e1);
} else if (is_class (t1->t.fldptr.type)) { } else if (is_class (t1->fldptr.type)) {
class_t *class = t1->t.fldptr.type->t.class; class_t *class = t1->fldptr.type->class;
symbol_t *sym = e2->symbol;//FIXME need to check symbol_t *sym = e2->symbol;//FIXME need to check
symbol_t *ivar; symbol_t *ivar;
int protected = class_access (current_class, class); int protected = class_access (current_class, class);
@ -2115,7 +2115,7 @@ bitnot_expr:
return error (e, "invalid type for unary ."); return error (e, "invalid type for unary .");
scoped_src_loc (e); scoped_src_loc (e);
auto new = new_unary_expr ('.', e); auto new = new_unary_expr ('.', e);
new->expr.type = get_type (e)->t.fldptr.type; new->expr.type = get_type (e)->fldptr.type;
return new; return new;
} }
case '+': case '+':
@ -2169,24 +2169,24 @@ build_function_call (const expr_t *fexpr, const type_t *ftype, const expr_t *par
return error (fexpr, "more than %d parameters", PR_MAX_PARAMS); return error (fexpr, "more than %d parameters", PR_MAX_PARAMS);
} }
if (ftype->t.func.num_params < -1) { if (ftype->func.num_params < -1) {
if (-arg_count > ftype->t.func.num_params + 1) { if (-arg_count > ftype->func.num_params + 1) {
if (!options.traditional) if (!options.traditional)
return error (fexpr, "too few arguments"); return error (fexpr, "too few arguments");
if (options.warnings.traditional) if (options.warnings.traditional)
warning (fexpr, "too few arguments"); warning (fexpr, "too few arguments");
} }
param_count = -ftype->t.func.num_params - 1; param_count = -ftype->func.num_params - 1;
} else if (ftype->t.func.num_params >= 0) { } else if (ftype->func.num_params >= 0) {
if (arg_count > ftype->t.func.num_params) { if (arg_count > ftype->func.num_params) {
return error (fexpr, "too many arguments"); return error (fexpr, "too many arguments");
} else if (arg_count < ftype->t.func.num_params) { } else if (arg_count < ftype->func.num_params) {
if (!options.traditional) if (!options.traditional)
return error (fexpr, "too few arguments"); return error (fexpr, "too few arguments");
if (options.warnings.traditional) if (options.warnings.traditional)
warning (fexpr, "too few arguments"); warning (fexpr, "too few arguments");
} }
param_count = ftype->t.func.num_params; param_count = ftype->func.num_params;
} }
const type_t *arg_types[arg_count + 1]; const type_t *arg_types[arg_count + 1];
@ -2197,7 +2197,7 @@ build_function_call (const expr_t *fexpr, const type_t *ftype, const expr_t *par
if (e->type == ex_compound) { if (e->type == ex_compound) {
if (i < param_count) { if (i < param_count) {
t = ftype->t.func.param_types[i]; t = ftype->func.param_types[i];
} else { } else {
return error (e, "cannot pass compound initializer " return error (e, "cannot pass compound initializer "
"through ..."); "through ...");
@ -2219,16 +2219,16 @@ build_function_call (const expr_t *fexpr, const type_t *ftype, const expr_t *par
} }
if (i < param_count) { if (i < param_count) {
if (e->type == ex_nil) if (e->type == ex_nil)
e = convert_nil (e, t = ftype->t.func.param_types[i]); e = convert_nil (e, t = ftype->func.param_types[i]);
if (e->type == ex_bool) if (e->type == ex_bool)
e = convert_from_bool (e, ftype->t.func.param_types[i]); e = convert_from_bool (e, ftype->func.param_types[i]);
if (e->type == ex_error) if (e->type == ex_error)
return e; return e;
if (!type_assignable (ftype->t.func.param_types[i], t)) { if (!type_assignable (ftype->func.param_types[i], t)) {
err = param_mismatch (e, i + 1, fexpr->symbol->name, err = param_mismatch (e, i + 1, fexpr->symbol->name,
ftype->t.func.param_types[i], t); ftype->func.param_types[i], t);
} }
t = ftype->t.func.param_types[i]; t = ftype->func.param_types[i];
} else { } else {
if (e->type == ex_nil) if (e->type == ex_nil)
e = convert_nil (e, t = type_nil); e = convert_nil (e, t = type_nil);
@ -2261,8 +2261,8 @@ build_function_call (const expr_t *fexpr, const type_t *ftype, const expr_t *par
} }
bool emit_args = false; bool emit_args = false;
if (ftype->t.func.num_params < 0) { if (ftype->func.num_params < 0) {
emit_args = !ftype->t.func.no_va_list; emit_args = !ftype->func.no_va_list;
} }
scoped_src_loc (fexpr); scoped_src_loc (fexpr);
call = new_block_expr (0); call = new_block_expr (0);
@ -2314,7 +2314,7 @@ build_function_call (const expr_t *fexpr, const type_t *ftype, const expr_t *par
arg_exprs[arg_expr_count - 1][0]); arg_exprs[arg_expr_count - 1][0]);
append_expr (call, e); append_expr (call, e);
} }
auto ret_type = ftype->t.func.ret_type; auto ret_type = ftype->func.ret_type;
call->block.result = call_expr (fexpr, args, ret_type); call->block.result = call_expr (fexpr, args, ret_type);
return call; return call;
} }
@ -2430,7 +2430,7 @@ const expr_t *
return_expr (function_t *f, const expr_t *e) return_expr (function_t *f, const expr_t *e)
{ {
const type_t *t; const type_t *t;
const type_t *ret_type = unalias_type (f->type->t.func.ret_type); const type_t *ret_type = unalias_type (f->type->func.ret_type);
e = convert_name (e); e = convert_name (e);
if (!e) { if (!e) {
@ -2500,7 +2500,7 @@ return_expr (function_t *f, const expr_t *e)
} else { } else {
if (ret_type != t) { if (ret_type != t) {
e = cast_expr ((type_t *) ret_type, e);//FIXME cast e = cast_expr ((type_t *) ret_type, e);//FIXME cast
t = f->sym->type->t.func.ret_type; t = f->sym->type->func.ret_type;
} }
} }
if (e->type == ex_vector) { if (e->type == ex_vector) {
@ -2515,7 +2515,7 @@ return_expr (function_t *f, const expr_t *e)
const expr_t * const expr_t *
at_return_expr (function_t *f, const expr_t *e) at_return_expr (function_t *f, const expr_t *e)
{ {
const type_t *ret_type = unalias_type (f->type->t.func.ret_type); const type_t *ret_type = unalias_type (f->type->func.ret_type);
if (!is_void(ret_type)) { if (!is_void(ret_type)) {
return error (e, "use of @return in non-void function"); return error (e, "use of @return in non-void function");
@ -2528,7 +2528,7 @@ at_return_expr (function_t *f, const expr_t *e)
} }
const expr_t *call_expr = e->block.result->branch.target; const expr_t *call_expr = e->block.result->branch.target;
const auto call_type = get_type (call_expr); const auto call_type = get_type (call_expr);
if (!is_func (call_type) && !call_type->t.func.void_return) { if (!is_func (call_type) && !call_type->func.void_return) {
return error (e, "@return function not void_return"); return error (e, "@return function not void_return");
} }
expr_t *ret_expr = new_return_expr (e); expr_t *ret_expr = new_return_expr (e);
@ -2651,10 +2651,10 @@ array_expr (const expr_t *array, const expr_t *index)
if (is_int_val (index)) if (is_int_val (index))
ind = expr_int (index); ind = expr_int (index);
if (is_array (array_type) if (is_array (array_type)
&& array_type->t.array.size && array_type->array.size
&& is_constant (index) && is_constant (index)
&& (ind < array_type->t.array.base && (ind < array_type->array.base
|| ind - array_type->t.array.base >= array_type->t.array.size)) { || ind - array_type->array.base >= array_type->array.size)) {
return error (index, "array index out of bounds"); return error (index, "array index out of bounds");
} }
if (is_nonscalar (array_type) if (is_nonscalar (array_type)
@ -2664,9 +2664,9 @@ array_expr (const expr_t *array, const expr_t *index)
} }
if (is_array (array_type)) { if (is_array (array_type)) {
ele_type = dereference_type (array_type); ele_type = dereference_type (array_type);
base = new_int_expr (array_type->t.array.base, false); base = new_int_expr (array_type->array.base, false);
} else if (is_ptr (array_type)) { } else if (is_ptr (array_type)) {
ele_type = array_type->t.fldptr.type; ele_type = array_type->fldptr.type;
base = new_int_expr (0, false); base = new_int_expr (0, false);
} else { } else {
ele_type = ev_types[array_type->type]; ele_type = ev_types[array_type->type];
@ -2735,7 +2735,7 @@ offset_pointer_expr (const expr_t *pointer, const expr_t *offset)
if (pointer->address.offset) { if (pointer->address.offset) {
offset = binary_expr ('+', pointer->address.offset, offset); offset = binary_expr ('+', pointer->address.offset, offset);
} }
ptr = new_address_expr (ptr_type->t.fldptr.type, ptr = new_address_expr (ptr_type->fldptr.type,
pointer->address.lvalue, offset); pointer->address.lvalue, offset);
return ptr; return ptr;
} else { } else {
@ -3059,8 +3059,8 @@ think_expr (symbol_t *think_sym)
sym = symtab_lookup (current_symtab, "think"); sym = symtab_lookup (current_symtab, "think");
if (sym && sym->sy_type == sy_var && sym->type if (sym && sym->sy_type == sy_var && sym->type
&& sym->type->type == ev_field && sym->type->type == ev_field
&& sym->type->t.fldptr.type->type == ev_func) { && sym->type->fldptr.type->type == ev_func) {
think_sym->type = sym->type->t.fldptr.type; think_sym->type = sym->type->fldptr.type;
} else { } else {
think_sym->type = &type_func; think_sym->type = &type_func;
} }

View file

@ -53,7 +53,7 @@ get_group (const type_t *type, algebra_t *algebra)
} }
pr_uint_t group_mask = (1u << layout->count) - 1; pr_uint_t group_mask = (1u << layout->count) - 1;
if (type->type != ev_invalid) { if (type->type != ev_invalid) {
group_mask = type->t.multivec->group_mask; group_mask = type->multivec->group_mask;
} }
if (group_mask & (group_mask - 1)) { if (group_mask & (group_mask - 1)) {
internal_error (0, "multi-group mult-vector"); internal_error (0, "multi-group mult-vector");
@ -72,7 +72,7 @@ get_group_mask (const type_t *type, algebra_t *algebra)
if (type->type == ev_invalid) { if (type->type == ev_invalid) {
return (1 << algebra->layout.count) - 1; return (1 << algebra->layout.count) - 1;
} }
return type->t.multivec->group_mask; return type->multivec->group_mask;
} }
} }
@ -246,11 +246,11 @@ get_mvec_struct (const type_t *type)
{ {
symbol_t *sym = 0; symbol_t *sym = 0;
if (type->type == ev_invalid) { if (type->type == ev_invalid) {
sym = type->t.algebra->mvec_sym; sym = type->algebra->mvec_sym;
} else { } else {
sym = type->t.multivec->mvec_sym; sym = type->multivec->mvec_sym;
} }
return sym ? sym->type->t.symtab : 0; return sym ? sym->type->symtab : 0;
} }
static symbol_t * static symbol_t *
@ -309,7 +309,7 @@ mvec_expr (const expr_t *expr, algebra_t *algebra)
auto layout = &algebra->layout; auto layout = &algebra->layout;
pr_uint_t group_mask = (1u << layout->count) - 1; pr_uint_t group_mask = (1u << layout->count) - 1;
if (mvtype->type != ev_invalid) { if (mvtype->type != ev_invalid) {
group_mask = mvtype->t.multivec->group_mask; group_mask = mvtype->multivec->group_mask;
} }
if (!(group_mask & (group_mask - 1))) { if (!(group_mask & (group_mask - 1))) {
return expr; return expr;
@ -346,7 +346,7 @@ mvec_scatter (const expr_t **components, const expr_t *mvec, algebra_t *algebra)
if (type->type == ev_invalid) { if (type->type == ev_invalid) {
internal_error (mvec, "full algebra in mvec_scatter"); internal_error (mvec, "full algebra in mvec_scatter");
} }
pr_uint_t mask = type->t.multivec->group_mask; pr_uint_t mask = type->multivec->group_mask;
if (mask & (mask - 1)) { if (mask & (mask - 1)) {
internal_error (mvec, "bare multivector in mvec_scatter"); internal_error (mvec, "bare multivector in mvec_scatter");
} }
@ -361,7 +361,7 @@ mvec_scatter (const expr_t **components, const expr_t *mvec, algebra_t *algebra)
if (!is_algebra (ct)) { if (!is_algebra (ct)) {
group = layout->group_map[layout->mask_map[0]][0]; group = layout->group_map[layout->mask_map[0]][0];
} else if (ct->meta == ty_algebra && ct->type != ev_invalid) { } else if (ct->meta == ty_algebra && ct->type != ev_invalid) {
pr_uint_t mask = ct->t.multivec->group_mask; pr_uint_t mask = ct->multivec->group_mask;
if (mask & (mask - 1)) { if (mask & (mask - 1)) {
internal_error (mvec, "multivector in multivec expression"); internal_error (mvec, "multivector in multivec expression");
} }
@ -3023,7 +3023,7 @@ algebra_field_expr (const expr_t *mvec, const expr_t *field_name)
auto mvec_struct = get_mvec_struct (mvec_type); auto mvec_struct = get_mvec_struct (mvec_type);
auto field = mvec_struct ? symtab_lookup (mvec_struct, field_sym->name) : 0; auto field = mvec_struct ? symtab_lookup (mvec_struct, field_sym->name) : 0;
if (!field) { if (!field) {
mvec_struct = algebra->mvec_sym->type->t.symtab; mvec_struct = algebra->mvec_sym->type->symtab;
field = symtab_lookup (mvec_struct, field_sym->name); field = symtab_lookup (mvec_struct, field_sym->name);
if (field) { if (field) {
debug (field_name, "'%s' not in sub-type '%s' of '%s', " debug (field_name, "'%s' not in sub-type '%s' of '%s', "

View file

@ -366,7 +366,7 @@ assign_expr (const expr_t *dst, const expr_t *src)
if (is_ptr (dst_type) && is_array (src_type)) { if (is_ptr (dst_type) && is_array (src_type)) {
// assigning an array to a pointer is the same as taking the address of // assigning an array to a pointer is the same as taking the address of
// the array but using the type of the array elements // the array but using the type of the array elements
src = address_expr (src, src_type->t.fldptr.type); src = address_expr (src, src_type->fldptr.type);
src_type = get_type (src); src_type = get_type (src);
} }
if (src->type == ex_bool) { if (src->type == ex_bool) {

View file

@ -924,7 +924,7 @@ pointer_arithmetic (int op, const expr_t *e1, const expr_t *e2)
} }
e1 = cast_expr (&type_int, e1); e1 = cast_expr (&type_int, e1);
e2 = cast_expr (&type_int, e2); e2 = cast_expr (&type_int, e2);
psize = new_int_expr (type_size (t1->t.fldptr.type), false); psize = new_int_expr (type_size (t1->fldptr.type), false);
return binary_expr ('/', binary_expr ('-', e1, e2), psize); return binary_expr ('/', binary_expr ('-', e1, e2), psize);
} else if (is_ptr (t1)) { } else if (is_ptr (t1)) {
offset = cast_expr (&type_int, e2); offset = cast_expr (&type_int, e2);
@ -936,7 +936,7 @@ pointer_arithmetic (int op, const expr_t *e1, const expr_t *e2)
ptype = t2; ptype = t2;
} }
// op is known to be + or - // op is known to be + or -
psize = new_int_expr (type_size (ptype->t.fldptr.type), false); psize = new_int_expr (type_size (ptype->fldptr.type), false);
offset = unary_expr (op, binary_expr ('*', offset, psize)); offset = unary_expr (op, binary_expr ('*', offset, psize));
return offset_pointer_expr (ptr, offset); return offset_pointer_expr (ptr, offset);
} }

View file

@ -130,7 +130,7 @@ cast_expr (const type_t *dstType, const expr_t *e)
return cast_error (e, srcType, dstType); return cast_error (e, srcType, dstType);
} }
if (is_array (srcType)) { if (is_array (srcType)) {
return address_expr (e, dstType->t.fldptr.type); return address_expr (e, dstType->fldptr.type);
} }
if (is_short (srcType)) { if (is_short (srcType)) {
e = new_int_expr (expr_short (e), false); e = new_int_expr (expr_short (e), false);

View file

@ -108,7 +108,7 @@ designator_field (const designator_t *des, const type_t *type)
error (des->index, "designator index in non-array"); error (des->index, "designator index in non-array");
return 0; return 0;
} }
symtab_t *symtab = type->t.symtab; symtab_t *symtab = type->symtab;
symbol_t *sym = des->field->symbol; symbol_t *sym = des->field->symbol;
symbol_t *field = symtab_lookup (symtab, sym->name); symbol_t *field = symtab_lookup (symtab, sym->name);
if (!field) { if (!field) {
@ -161,12 +161,12 @@ get_designated_offset (const type_t *type, const designator_t *des)
offset = field->offset; offset = field->offset;
ele_type = field->type; ele_type = field->type;
} else if (is_array (type)) { } else if (is_array (type)) {
int array_size = type->t.array.size; int array_size = type->array.size;
ele_type = dereference_type (type); ele_type = dereference_type (type);
offset = designator_index (des, type_size (ele_type), array_size); offset = designator_index (des, type_size (ele_type), array_size);
} else if (is_nonscalar (type)) { } else if (is_nonscalar (type)) {
ele_type = ev_types[type->type]; ele_type = ev_types[type->type];
if (type->t.symtab && des->field) { if (type->symtab && des->field) {
field = designator_field (des, type); field = designator_field (des, type);
offset = field->offset; offset = field->offset;
} else { } else {
@ -220,8 +220,8 @@ build_element_chain (element_chain_t *element_chain, const type_t *type,
} }
type = t; type = t;
} else if (is_struct (type) || is_union (type) } else if (is_struct (type) || is_union (type)
|| (is_nonscalar (type) && type->t.symtab)) { || (is_nonscalar (type) && type->symtab)) {
state.field = type->t.symtab->symbols; state.field = type->symtab->symbols;
while (state.field && skip_field (state.field)) { while (state.field && skip_field (state.field)) {
state.field = state.field->next; state.field = state.field->next;
} }

View file

@ -99,13 +99,13 @@ selector_expr (keywordarg_t *selector)
selector = (keywordarg_t *) reverse_params ((param_t *) selector); selector = (keywordarg_t *) reverse_params ((param_t *) selector);
selector_name (sel_id, selector); selector_name (sel_id, selector);
index = selector_index (sel_id->str); index = selector_index (sel_id->str);
index *= type_size (type_SEL.t.fldptr.type); index *= type_size (type_SEL.fldptr.type);
sel_sym = make_symbol ("_OBJ_SELECTOR_TABLE_PTR", &type_SEL, sel_sym = make_symbol ("_OBJ_SELECTOR_TABLE_PTR", &type_SEL,
pr.near_data, sc_static); pr.near_data, sc_static);
if (!sel_sym->table) { if (!sel_sym->table) {
symtab_addsymbol (pr.symtab, sel_sym); symtab_addsymbol (pr.symtab, sel_sym);
sel_table = make_symbol ("_OBJ_SELECTOR_TABLE", sel_table = make_symbol ("_OBJ_SELECTOR_TABLE",
array_type (type_SEL.t.fldptr.type, 0), array_type (type_SEL.fldptr.type, 0),
pr.far_data, sc_extern); pr.far_data, sc_extern);
if (!sel_table->table) if (!sel_table->table)
symtab_addsymbol (pr.symtab, sel_table); symtab_addsymbol (pr.symtab, sel_table);
@ -211,7 +211,7 @@ message_expr (const expr_t *receiver, keywordarg_t *message)
} else if (receiver->symbol->sy_type == sy_class) { } else if (receiver->symbol->sy_type == sy_class) {
class_t *class; class_t *class;
rec_type = receiver->symbol->type; rec_type = receiver->symbol->type;
class = rec_type->t.class; class = rec_type->class;
class_msg = 1; class_msg = 1;
receiver = new_symbol_expr (class_pointer_symbol (class)); receiver = new_symbol_expr (class_pointer_symbol (class));
} }
@ -226,7 +226,7 @@ message_expr (const expr_t *receiver, keywordarg_t *message)
return_type = &type_id; return_type = &type_id;
method = class_message_response (rec_type, class_msg, selector); method = class_message_response (rec_type, class_msg, selector);
if (method) if (method)
return_type = method->type->t.func.ret_type; return_type = method->type->func.ret_type;
scoped_src_loc (receiver); scoped_src_loc (receiver);
expr_t *args = new_list_expr (0); expr_t *args = new_list_expr (0);

View file

@ -278,7 +278,7 @@ parse_generic_function (const char *name, specifier_t spec)
// fake parameter for the return type // fake parameter for the return type
param_t ret_param = { param_t ret_param = {
.next = spec.sym->params, .next = spec.sym->params,
.type = spec.sym->type->t.func.ret_type, .type = spec.sym->type->func.ret_type,
.type_expr = spec.type_expr, .type_expr = spec.type_expr,
}; };
int num_params = 0; int num_params = 0;
@ -448,8 +448,8 @@ parse_params (const type_t *return_type, param_t *parms)
new->alignment = 1; new->alignment = 1;
new->width = 1; new->width = 1;
new->columns = 1; new->columns = 1;
new->t.func.ret_type = return_type; new->func.ret_type = return_type;
new->t.func.num_params = 0; new->func.num_params = 0;
for (p = parms; p; p = p->next) { for (p = parms; p; p = p->next) {
if (p->type) { if (p->type) {
@ -457,21 +457,21 @@ parse_params (const type_t *return_type, param_t *parms)
} }
} }
if (count) { if (count) {
new->t.func.param_types = malloc (count * sizeof (type_t)); new->func.param_types = malloc (count * sizeof (type_t));
} }
for (p = parms; p; p = p->next) { for (p = parms; p; p = p->next) {
if (!p->selector && !p->type && !p->name) { if (!p->selector && !p->type && !p->name) {
if (p->next) if (p->next)
internal_error (0, 0); internal_error (0, 0);
new->t.func.num_params = -(new->t.func.num_params + 1); new->func.num_params = -(new->func.num_params + 1);
} else if (p->type) { } else if (p->type) {
if (is_class (p->type)) { if (is_class (p->type)) {
error (0, "cannot use an object as a parameter (forgot *?)"); error (0, "cannot use an object as a parameter (forgot *?)");
p->type = &type_id; p->type = &type_id;
} }
auto ptype = unalias_type (p->type); auto ptype = unalias_type (p->type);
new->t.func.param_types[new->t.func.num_params] = ptype; new->func.param_types[new->func.num_params] = ptype;
new->t.func.num_params++; new->func.num_params++;
} }
} }
return new; return new;
@ -596,8 +596,8 @@ func_compare (const void *a, const void *b)
overloaded_function_t *fb = *(overloaded_function_t **) b; overloaded_function_t *fb = *(overloaded_function_t **) b;
const type_t *ta = fa->type; const type_t *ta = fa->type;
const type_t *tb = fb->type; const type_t *tb = fb->type;
int na = ta->t.func.num_params; int na = ta->func.num_params;
int nb = tb->t.func.num_params; int nb = tb->func.num_params;
int ret, i; int ret, i;
if (na < 0) if (na < 0)
@ -606,10 +606,10 @@ func_compare (const void *a, const void *b)
nb = ~nb; nb = ~nb;
if (na != nb) if (na != nb)
return nb - na; return nb - na;
if ((ret = (tb->t.func.num_params - ta->t.func.num_params))) if ((ret = (tb->func.num_params - ta->func.num_params)))
return ret; return ret;
for (i = 0; i < na && i < nb; i++) { for (i = 0; i < na && i < nb; i++) {
auto diff = tb->t.func.param_types[i] - ta->t.func.param_types[i]; auto diff = tb->func.param_types[i] - ta->func.param_types[i];
if (diff) { if (diff) {
return diff < 0 ? -1 : 1; return diff < 0 ? -1 : 1;
} }
@ -663,8 +663,8 @@ find_generic_function (const expr_t *fexpr, genfunc_t **genfuncs,
for (auto gf = genfuncs; *gf; gf++, num_funcs++) continue; for (auto gf = genfuncs; *gf; gf++, num_funcs++) continue;
unsigned costs[num_funcs] = {}; unsigned costs[num_funcs] = {};
int num_params = call_type->t.func.num_params; int num_params = call_type->func.num_params;
auto call_params = call_type->t.func.param_types; auto call_params = call_type->func.param_types;
for (int j = 0; j < num_funcs; j++) { for (int j = 0; j < num_funcs; j++) {
auto g = genfuncs[j]; auto g = genfuncs[j];
if (g->num_params != num_params) { if (g->num_params != num_params) {
@ -742,7 +742,7 @@ find_generic_function (const expr_t *fexpr, genfunc_t **genfuncs,
type_t ftype = { type_t ftype = {
.type = ev_func, .type = ev_func,
.t.func = { .func = {
.ret_type = return_type, .ret_type = return_type,
.num_params = num_params, .num_params = num_params,
.param_types = param_types, .param_types = param_types,
@ -791,7 +791,7 @@ find_function (const expr_t *fexpr, const expr_t *params)
type_t call_type = { type_t call_type = {
.type = ev_func, .type = ev_func,
.t.func = { .func = {
.num_params = num_params, .num_params = num_params,
.param_types = arg_types, .param_types = arg_types,
}, },
@ -813,7 +813,7 @@ find_function (const expr_t *fexpr, const expr_t *params)
return fexpr; return fexpr;
} }
} }
call_type.t.func.ret_type = funcs[0]->type->t.func.ret_type; call_type.func.ret_type = funcs[0]->type->func.ret_type;
dummy.type = find_type (&call_type); dummy.type = find_type (&call_type);
qsort (funcs, func_count, sizeof (void *), func_compare); qsort (funcs, func_count, sizeof (void *), func_compare);
@ -831,9 +831,9 @@ find_function (const expr_t *fexpr, const expr_t *params)
} }
for (int i = 0; i < func_count; i++) { for (int i = 0; i < func_count; i++) {
auto f = (overloaded_function_t *) funcs[i]; auto f = (overloaded_function_t *) funcs[i];
parm_count = f->type->t.func.num_params; parm_count = f->type->func.num_params;
if ((parm_count >= 0 && parm_count != call_type.t.func.num_params) if ((parm_count >= 0 && parm_count != call_type.func.num_params)
|| (parm_count < 0 && ~parm_count > call_type.t.func.num_params)) { || (parm_count < 0 && ~parm_count > call_type.func.num_params)) {
funcs[i] = 0; funcs[i] = 0;
continue; continue;
} }
@ -841,8 +841,8 @@ find_function (const expr_t *fexpr, const expr_t *params)
parm_count = ~parm_count; parm_count = ~parm_count;
int j; int j;
for (j = 0; j < parm_count; j++) { for (j = 0; j < parm_count; j++) {
if (!type_assignable (f->type->t.func.param_types[j], if (!type_assignable (f->type->func.param_types[j],
call_type.t.func.param_types[j])) { call_type.func.param_types[j])) {
funcs[i] = 0; funcs[i] = 0;
break; break;
} }
@ -899,14 +899,14 @@ check_function (symbol_t *fsym)
param_t *p; param_t *p;
int i; int i;
if (!type_size (fsym->type->t.func.ret_type)) { if (!type_size (fsym->type->func.ret_type)) {
error (0, "return type is an incomplete type"); error (0, "return type is an incomplete type");
//fsym->type->t.func.type = &type_void;//FIXME better type? //fsym->type->func.type = &type_void;//FIXME better type?
} }
if (value_too_large (fsym->type->t.func.ret_type)) { if (value_too_large (fsym->type->func.ret_type)) {
error (0, "return value too large to be passed by value (%d)", error (0, "return value too large to be passed by value (%d)",
type_size (&type_param)); type_size (&type_param));
//fsym->type->t.func.type = &type_void;//FIXME better type? //fsym->type->func.type = &type_void;//FIXME better type?
} }
for (p = params, i = 0; p; p = p->next, i++) { for (p = params, i = 0; p; p = p->next, i++) {
if (!p->selector && !p->type && !p->name) if (!p->selector && !p->type && !p->name)
@ -934,7 +934,7 @@ build_v6p_scope (symbol_t *fsym)
symtab_t *parameters = fsym->func->parameters; symtab_t *parameters = fsym->func->parameters;
symtab_t *locals = fsym->func->locals; symtab_t *locals = fsym->func->locals;
if (fsym->func->type->t.func.num_params < 0) { if (fsym->func->type->func.num_params < 0) {
args = new_symbol_type (".args", &type_va_list); args = new_symbol_type (".args", &type_va_list);
initialize_def (args, 0, parameters->space, sc_param, locals); initialize_def (args, 0, parameters->space, sc_param, locals);
} }
@ -1129,7 +1129,7 @@ static void
build_function (symbol_t *fsym) build_function (symbol_t *fsym)
{ {
const type_t *func_type = fsym->func->type; const type_t *func_type = fsym->func->type;
if (func_type->t.func.num_params > PR_MAX_PARAMS) { if (func_type->func.num_params > PR_MAX_PARAMS) {
error (0, "too many params"); error (0, "too many params");
} }
} }
@ -1327,7 +1327,7 @@ int
function_parms (function_t *f, byte *parm_size) function_parms (function_t *f, byte *parm_size)
{ {
int count, i; int count, i;
auto func = &f->sym->type->t.func; auto func = &f->sym->type->func;
if (func->num_params >= 0) if (func->num_params >= 0)
count = func->num_params; count = func->num_params;

View file

@ -496,7 +496,7 @@ get_selector (const expr_t *sel)
return 0; return 0;
} }
_sel.index = expr_short (sel->address.offset); _sel.index = expr_short (sel->address.offset);
_sel.index /= type_size (type_SEL.t.fldptr.type); _sel.index /= type_size (type_SEL.fldptr.type);
return (selector_t *) Hash_FindElement (sel_index_hash, &_sel); return (selector_t *) Hash_FindElement (sel_index_hash, &_sel);
} }
@ -512,7 +512,7 @@ emit_selectors (void)
if (!sel_index) if (!sel_index)
return 0; return 0;
sel_type = array_type (type_SEL.t.fldptr.type, sel_index); sel_type = array_type (type_SEL.fldptr.type, sel_index);
sel_sym = make_symbol ("_OBJ_SELECTOR_TABLE", sel_type, sel_sym = make_symbol ("_OBJ_SELECTOR_TABLE", sel_type,
pr.far_data, sc_static); pr.far_data, sc_static);
if (!sel_sym->table) if (!sel_sym->table)
@ -707,25 +707,25 @@ method_check_params (method_t *method, const expr_t *args)
const expr_t *err = 0; const expr_t *err = 0;
auto mtype = method->type; auto mtype = method->type;
if (mtype->t.func.num_params == -1) if (mtype->func.num_params == -1)
return 0; return 0;
if (mtype->t.func.num_params >= 0) if (mtype->func.num_params >= 0)
param_count = mtype->t.func.num_params; param_count = mtype->func.num_params;
else else
param_count = -mtype->t.func.num_params - 1; param_count = -mtype->func.num_params - 1;
int count = list_count (&args->list); int count = list_count (&args->list);
if (count < param_count) if (count < param_count)
return error (args, "too few arguments"); return error (args, "too few arguments");
if (mtype->t.func.num_params >= 0 && count > mtype->t.func.num_params) if (mtype->func.num_params >= 0 && count > mtype->func.num_params)
return error (args, "too many arguments"); return error (args, "too many arguments");
const expr_t *arg_list[count]; const expr_t *arg_list[count];
list_scatter_rev (&args->list, arg_list); list_scatter_rev (&args->list, arg_list);
for (i = 2; i < count; i++) { for (i = 2; i < count; i++) {
const expr_t *e = arg_list[i]; const expr_t *e = arg_list[i];
const type_t *arg_type = i < param_count ? mtype->t.func.param_types[i] const type_t *arg_type = i < param_count ? mtype->func.param_types[i]
: nullptr; : nullptr;
if (e->type == ex_compound) { if (e->type == ex_compound) {
scoped_src_loc (e); scoped_src_loc (e);

View file

@ -106,14 +106,13 @@ qfo_encode_func (const type_t *type, defspace_t *space)
def_t *def; def_t *def;
int i; int i;
param_count = type->t.func.num_params; param_count = type->func.num_params;
if (param_count < 0) if (param_count < 0)
param_count = ~param_count; param_count = ~param_count;
param_type_defs = alloca (param_count * sizeof (def_t *)); param_type_defs = alloca (param_count * sizeof (def_t *));
return_type_def = qfo_encode_type (type->t.func.ret_type, space); return_type_def = qfo_encode_type (type->func.ret_type, space);
for (i = 0; i < param_count; i++) for (i = 0; i < param_count; i++)
param_type_defs[i] = qfo_encode_type (type->t.func.param_types[i], param_type_defs[i] = qfo_encode_type (type->func.param_types[i], space);
space);
size = field_offset (qfot_func_t, param_types[param_count]); size = field_offset (qfot_func_t, param_types[param_count]);
def = qfo_new_encoding (type, size, space); def = qfo_new_encoding (type, size, space);
@ -121,7 +120,7 @@ qfo_encode_func (const type_t *type, defspace_t *space)
func = &enc->func; func = &enc->func;
func->type = ev_func; func->type = ev_func;
ENC_DEF (func->return_type, return_type_def); ENC_DEF (func->return_type, return_type_def);
func->num_params = type->t.func.num_params; func->num_params = type->func.num_params;
for (i = 0; i < param_count; i++) for (i = 0; i < param_count; i++)
ENC_DEF (func->param_types[i], param_type_defs[i]); ENC_DEF (func->param_types[i], param_type_defs[i]);
return def; return def;
@ -134,7 +133,7 @@ qfo_encode_fldptr (const type_t *type, defspace_t *space)
def_t *def; def_t *def;
def_t *type_def; def_t *type_def;
type_def = qfo_encode_type (type->t.fldptr.type, space); type_def = qfo_encode_type (type->fldptr.type, space);
def = qfo_new_encoding (type, sizeof (enc->fldptr), space); def = qfo_new_encoding (type, sizeof (enc->fldptr), space);
enc = D_POINTER (qfot_type_t, def); enc = D_POINTER (qfot_type_t, def);
enc->fldptr.type = type->type; enc->fldptr.type = type->type;
@ -178,11 +177,11 @@ qfo_encode_struct (const type_t *type, defspace_t *space)
sy = sy_var; sy = sy_var;
if (type->meta == ty_enum) if (type->meta == ty_enum)
sy = sy_const; sy = sy_const;
if (!type->t.symtab) { if (!type->symtab) {
def = new_def (type->encoding, 0, pr.type_data, sc_extern); def = new_def (type->encoding, 0, pr.type_data, sc_extern);
return def; return def;
} }
for (num_fields = 0, sym = type->t.symtab->symbols; sym; sym = sym->next) { for (num_fields = 0, sym = type->symtab->symbols; sym; sym = sym->next) {
if (sym->sy_type != sy) if (sym->sy_type != sy)
continue; continue;
num_fields++; num_fields++;
@ -198,7 +197,7 @@ qfo_encode_struct (const type_t *type, defspace_t *space)
((type_t *)type)->type_def = def; // avoid infinite recursion ((type_t *)type)->type_def = def; // avoid infinite recursion
field_types = alloca (num_fields * sizeof (def_t *)); field_types = alloca (num_fields * sizeof (def_t *));
for (i = 0, sym = type->t.symtab->symbols; sym; sym = sym->next) { for (i = 0, sym = type->symtab->symbols; sym; sym = sym->next) {
if (sym->sy_type != sy) if (sym->sy_type != sy)
continue; continue;
if (i == num_fields) if (i == num_fields)
@ -211,7 +210,7 @@ qfo_encode_struct (const type_t *type, defspace_t *space)
i++; i++;
} }
for (i = 0, sym = type->t.symtab->symbols; sym; sym = sym->next) { for (i = 0, sym = type->symtab->symbols; sym; sym = sym->next) {
if (sym->sy_type != sy) if (sym->sy_type != sy)
continue; continue;
if (i == num_fields) if (i == num_fields)
@ -235,13 +234,13 @@ qfo_encode_array (const type_t *type, defspace_t *space)
def_t *def; def_t *def;
def_t *array_type_def; def_t *array_type_def;
array_type_def = qfo_encode_type (type->t.array.type, space); array_type_def = qfo_encode_type (type->array.type, space);
def = qfo_new_encoding (type, sizeof (enc->array), space); def = qfo_new_encoding (type, sizeof (enc->array), space);
enc = D_POINTER (qfot_type_t, def); enc = D_POINTER (qfot_type_t, def);
ENC_DEF (enc->array.type, array_type_def); ENC_DEF (enc->array.type, array_type_def);
enc->array.base = type->t.array.base; enc->array.base = type->array.base;
enc->array.size = type->t.array.size; enc->array.size = type->array.size;
return def; return def;
} }
@ -253,7 +252,7 @@ qfo_encode_class (const type_t *type, defspace_t *space)
def = qfo_new_encoding (type, sizeof (enc->class), space); def = qfo_new_encoding (type, sizeof (enc->class), space);
enc = D_POINTER (qfot_type_t, def); enc = D_POINTER (qfot_type_t, def);
ENC_STR (enc->class, type->t.class->name); ENC_STR (enc->class, type->class->name);
return def; return def;
} }
@ -265,8 +264,8 @@ qfo_encode_alias (const type_t *type, defspace_t *space)
def_t *type_def; def_t *type_def;
def_t *full_def; def_t *full_def;
type_def = qfo_encode_type (type->t.alias.aux_type, space); type_def = qfo_encode_type (type->alias.aux_type, space);
full_def = qfo_encode_type (type->t.alias.full_type, space); full_def = qfo_encode_type (type->alias.full_type, space);
def = qfo_new_encoding (type, sizeof (enc->alias), space); def = qfo_new_encoding (type, sizeof (enc->alias), space);
enc = D_POINTER (qfot_type_t, def); enc = D_POINTER (qfot_type_t, def);
@ -300,7 +299,7 @@ qfo_encode_algebra (const type_t *type, defspace_t *space)
def_t *algebra_type_def = 0; def_t *algebra_type_def = 0;
if (type->type != ev_invalid) { if (type->type != ev_invalid) {
auto m = (multivector_t *) type->t.algebra; auto m = (multivector_t *) type->algebra;
algebra_type_def = qfo_encode_type (m->algebra->type, space); algebra_type_def = qfo_encode_type (m->algebra->type, space);
} }

View file

@ -451,7 +451,7 @@ qc_function_spec (specifier_t spec, param_t *params)
// .float () foo; is a field holding a function variable rather // .float () foo; is a field holding a function variable rather
// than a function that returns a float field. // than a function that returns a float field.
for (type = &spec.type; *type && is_field (*type); for (type = &spec.type; *type && is_field (*type);
type = (const type_t **) &(*type)->t.fldptr.type) { type = (const type_t **) &(*type)->fldptr.type) {
} }
const type_t *ret_type = *type; const type_t *ret_type = *type;
*type = 0; *type = 0;
@ -527,7 +527,7 @@ is_anonymous_struct (specifier_t spec)
if (!is_struct (spec.type) && !is_union (spec.type)) { if (!is_struct (spec.type) && !is_union (spec.type)) {
return 0; return 0;
} }
if (!spec.type->t.symtab || spec.type->t.symtab->parent) { if (!spec.type->symtab || spec.type->symtab->parent) {
return 0; return 0;
} }
// struct and union type names always begin with "tag ". Untagged s/u // struct and union type names always begin with "tag ". Untagged s/u
@ -1042,7 +1042,7 @@ typespec_nonreserved
| OBJECT_NAME protocolrefs | OBJECT_NAME protocolrefs
{ {
if ($2) { if ($2) {
type_t type = *type_id.t.fldptr.type; type_t type = *type_id.fldptr.type;
type.next = 0; type.next = 0;
type.protos = $2; type.protos = $2;
$$ = type_spec (pointer_type (find_type (&type))); $$ = type_spec (pointer_type (find_type (&type)));
@ -1288,7 +1288,7 @@ enum_init
{ {
$$ = find_enum ($<symbol>-1); $$ = find_enum ($<symbol>-1);
start_enum ($$); start_enum ($$);
current_symtab = $$->type->t.symtab; current_symtab = $$->type->symtab;
} }
; ;
@ -1381,7 +1381,7 @@ struct_defs
// replace the struct symbol table with one built from // replace the struct symbol table with one built from
// the class ivars and the current struct fields. ivars // the class ivars and the current struct fields. ivars
// will replace any fields of the same name. // will replace any fields of the same name.
current_symtab = class_to_struct ($3->type->t.class, current_symtab = class_to_struct ($3->type->class,
current_symtab); current_symtab);
} }
} }
@ -2110,7 +2110,7 @@ class_name
error (0, "`%s' is not a class", $1->name); error (0, "`%s' is not a class", $1->name);
$$ = get_class (0, 1); $$ = get_class (0, 1);
} else { } else {
$$ = $1->type->t.class; $$ = $1->type->class;
} }
} }
; ;

View file

@ -186,10 +186,10 @@ static symbol_t *
function_value (function_t *func) function_value (function_t *func)
{ {
symbol_t *ret = 0; symbol_t *ret = 0;
if (func->type->t.func.ret_type) { if (func->type->func.ret_type) {
ret = symtab_lookup (func->locals, ".ret"); ret = symtab_lookup (func->locals, ".ret");
if (!ret || ret->table != func->locals) { if (!ret || ret->table != func->locals) {
ret = new_symbol_type (".ret", func->type->t.func.ret_type); ret = new_symbol_type (".ret", func->type->func.ret_type);
initialize_def (ret, 0, func->locals->space, sc_local, initialize_def (ret, 0, func->locals->space, sc_local,
func->locals); func->locals);
} }

View file

@ -686,7 +686,7 @@ statement_get_targetlist (statement_t *s)
count = 1; count = 1;
} else if (statement_is_jumpb (s)) { } else if (statement_is_jumpb (s)) {
table = s->opa->def; table = s->opa->def;
count = table->type->t.array.size; count = table->type->array.size;
} }
target_list = malloc ((count + 1) * sizeof (sblock_t *)); target_list = malloc ((count + 1) * sizeof (sblock_t *));
target_list[count] = 0; target_list[count] = 0;
@ -1349,7 +1349,7 @@ ptr_addressing_mode (sblock_t *sblock, const expr_t *ref,
offs = lvalue->alias.offset; offs = lvalue->alias.offset;
} }
} }
type = type->t.fldptr.type; type = type->fldptr.type;
if (offs) { if (offs) {
const expr_t *lv = lvalue->alias.expr; const expr_t *lv = lvalue->alias.expr;
auto lvtype = get_type (lv); auto lvtype = get_type (lv);
@ -2627,7 +2627,7 @@ check_final_block (sblock_t *sblock)
if (statement_is_return (s)) if (statement_is_return (s))
return; return;
} }
if (!is_void(current_func->sym->type->t.func.ret_type)) if (!is_void(current_func->sym->type->func.ret_type))
warning (0, "control reaches end of non-void function"); warning (0, "control reaches end of non-void function");
if (s && s->type >= st_func) { if (s && s->type >= st_func) {
// func and flow end blocks, so we need to add a new block to take the // func and flow end blocks, so we need to add a new block to take the

View file

@ -114,7 +114,7 @@ start_struct (int *su, symbol_t *tag, symtab_t *parent)
tag->type = sym->type; tag->type = sym->type;
} }
if (sym->type->meta == ty_enum if (sym->type->meta == ty_enum
|| (sym->type->meta == ty_struct && sym->type->t.symtab)) { || (sym->type->meta == ty_struct && sym->type->symtab)) {
error (0, "%s %s redefined", error (0, "%s %s redefined",
*su == 's' ? "struct" : "union", tag->name); *su == 's' ? "struct" : "union", tag->name);
*su = 0; *su = 0;
@ -166,7 +166,7 @@ build_struct (int su, symbol_t *tag, symtab_t *symtab, const type_t *type,
symtab->parent = 0; // disconnect struct's symtab from parent scope symtab->parent = 0; // disconnect struct's symtab from parent scope
if (sym->table == current_symtab && sym->type->t.symtab) { if (sym->table == current_symtab && sym->type->symtab) {
error (0, "%s defined as wrong kind of tag", tag->name); error (0, "%s defined as wrong kind of tag", tag->name);
return sym; return sym;
} }
@ -175,7 +175,7 @@ build_struct (int su, symbol_t *tag, symtab_t *symtab, const type_t *type,
continue; continue;
if (is_class (s->type)) { if (is_class (s->type)) {
error (0, "statically allocated instance of class %s", error (0, "statically allocated instance of class %s",
s->type->t.class->name); s->type->class->name);
} }
if (su == 's') { if (su == 's') {
symtab->size = RUP (symtab->size + base, s->type->alignment) - base; symtab->size = RUP (symtab->size + base, s->type->alignment) - base;
@ -198,7 +198,7 @@ build_struct (int su, symbol_t *tag, symtab_t *symtab, const type_t *type,
if (!is_struct (s->type) && !is_union (s->type)) { if (!is_struct (s->type) && !is_union (s->type)) {
internal_error (0, "non-struct/union anonymous field"); internal_error (0, "non-struct/union anonymous field");
} }
anonymous = s->type->t.symtab; anonymous = s->type->symtab;
for (as = anonymous->symbols; as; as = as->next) { for (as = anonymous->symbols; as; as = as->next) {
if (as->visibility == vis_anonymous || as->sy_type!= sy_var) { if (as->visibility == vis_anonymous || as->sy_type!= sy_var) {
continue; continue;
@ -220,7 +220,7 @@ build_struct (int su, symbol_t *tag, symtab_t *symtab, const type_t *type,
} }
if (!type) if (!type)
sym->type = find_type (sym->type); // checks the tag, not the symtab sym->type = find_type (sym->type); // checks the tag, not the symtab
((type_t *) sym->type)->t.symtab = symtab; ((type_t *) sym->type)->symtab = symtab;
if (alignment > sym->type->alignment) { if (alignment > sym->type->alignment) {
((type_t *) sym->type)->alignment = alignment; ((type_t *) sym->type)->alignment = alignment;
} }
@ -239,15 +239,15 @@ find_enum (symbol_t *tag)
symtab_t * symtab_t *
start_enum (symbol_t *sym) start_enum (symbol_t *sym)
{ {
if (sym->table == current_symtab && sym->type->t.symtab) { if (sym->table == current_symtab && sym->type->symtab) {
error (0, "%s defined as wrong kind of tag", sym->name); error (0, "%s defined as wrong kind of tag", sym->name);
sym = find_enum (0); sym = find_enum (0);
} }
((type_t *) sym->type)->t.symtab = new_symtab (current_symtab, stab_enum); ((type_t *) sym->type)->symtab = new_symtab (current_symtab, stab_enum);
((type_t *) sym->type)->alignment = 1; ((type_t *) sym->type)->alignment = 1;
((type_t *) sym->type)->width = 1; ((type_t *) sym->type)->width = 1;
((type_t *) sym->type)->columns = 1; ((type_t *) sym->type)->columns = 1;
return sym->type->t.symtab; return sym->type->symtab;
} }
symbol_t * symbol_t *
@ -258,7 +258,7 @@ finish_enum (symbol_t *sym)
symtab_t *enum_tab; symtab_t *enum_tab;
auto enum_type = sym->type = find_type (sym->type); auto enum_type = sym->type = find_type (sym->type);
enum_tab = enum_type->t.symtab; enum_tab = enum_type->symtab;
for (name = enum_tab->symbols; name; name = name->next) { for (name = enum_tab->symbols; name; name = name->next) {
name->type = sym->type; name->type = sym->type;
@ -275,7 +275,7 @@ void
add_enum (symbol_t *enm, symbol_t *name, const expr_t *val) add_enum (symbol_t *enm, symbol_t *name, const expr_t *val)
{ {
auto enum_type = enm->type; auto enum_type = enm->type;
symtab_t *enum_tab = enum_type->t.symtab; symtab_t *enum_tab = enum_type->symtab;
int value; int value;
if (name->table == current_symtab || name->table == enum_tab) if (name->table == current_symtab || name->table == enum_tab)
@ -303,7 +303,7 @@ add_enum (symbol_t *enm, symbol_t *name, const expr_t *val)
int int
enum_as_bool (const type_t *enm, expr_t **zero, expr_t **one) enum_as_bool (const type_t *enm, expr_t **zero, expr_t **one)
{ {
symtab_t *symtab = enm->t.symtab; symtab_t *symtab = enm->symtab;
symbol_t *zero_sym = 0; symbol_t *zero_sym = 0;
symbol_t *one_sym = 0; symbol_t *one_sym = 0;
symbol_t *sym; symbol_t *sym;
@ -377,7 +377,7 @@ emit_structure (const char *name, int su, struct_def_t *defs,
type = make_structure (0, su, defs, 0)->type; type = make_structure (0, su, defs, 0)->type;
if ((su == 's' && !is_struct (type)) || (su == 'u' && !is_union (type))) if ((su == 's' && !is_struct (type)) || (su == 'u' && !is_union (type)))
internal_error (0, "structure %s type mismatch", name); internal_error (0, "structure %s type mismatch", name);
for (i = 0, field_sym = type->t.symtab->symbols; field_sym; for (i = 0, field_sym = type->symtab->symbols; field_sym;
i++, field_sym = field_sym->next) { i++, field_sym = field_sym->next) {
if (!defs[i].name) if (!defs[i].name)
internal_error (0, "structure %s unexpected end of defs", name); internal_error (0, "structure %s unexpected end of defs", name);
@ -407,7 +407,7 @@ emit_structure (const char *name, int su, struct_def_t *defs,
struct_def->initialized = struct_def->constant = 1; struct_def->initialized = struct_def->constant = 1;
struct_def->nosave = 1; struct_def->nosave = 1;
for (i = 0, field_sym = type->t.symtab->symbols; field_sym; for (i = 0, field_sym = type->symtab->symbols; field_sym;
i++, field_sym = field_sym->next) { i++, field_sym = field_sym->next) {
field_def.type = field_sym->type; field_def.type = field_sym->type;
field_def.name = save_string (va (0, "%s.%s", name, field_sym->name)); field_def.name = save_string (va (0, "%s.%s", name, field_sym->name));
@ -422,7 +422,7 @@ emit_structure (const char *name, int su, struct_def_t *defs,
} else { } else {
if (is_array (field_def.type)) { if (is_array (field_def.type)) {
auto type = dereference_type (field_def.type); auto type = dereference_type (field_def.type);
for (j = 0; j < field_def.type->t.array.size; j++) { for (j = 0; j < field_def.type->array.size; j++) {
defs[i].emit (&field_def, data, j); defs[i].emit (&field_def, data, j);
field_def.offset += type_size (type); field_def.offset += type_size (type);
} }

View file

@ -381,7 +381,7 @@ check_enum_switch (switch_block_t *switch_block)
symbol_t *enum_val; symbol_t *enum_val;
auto type = get_type (switch_block->test); auto type = get_type (switch_block->test);
for (enum_val = type->t.symtab->symbols; enum_val; for (enum_val = type->symtab->symbols; enum_val;
enum_val = enum_val->next) { enum_val = enum_val->next) {
cl.value = new_int_expr (enum_val->value->int_val, false); cl.value = new_int_expr (enum_val->value->int_val, false);
if (!Hash_FindElement (switch_block->labels, &cl)) { if (!Hash_FindElement (switch_block->labels, &cl)) {

View file

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

View file

@ -306,14 +306,14 @@ free_type (type_t *type)
break; break;
case ev_field: case ev_field:
case ev_ptr: case ev_ptr:
free_type ((type_t *) type->t.fldptr.type); free_type ((type_t *) type->fldptr.type);
break; break;
case ev_func: case ev_func:
free_type ((type_t *) type->t.func.ret_type); free_type ((type_t *) type->func.ret_type);
break; break;
case ev_invalid: case ev_invalid:
if (type->meta == ty_array) if (type->meta == ty_array)
free_type ((type_t *) type->t.array.type); free_type ((type_t *) type->array.type);
break; break;
} }
memset (type, 0, sizeof (*type)); memset (type, 0, sizeof (*type));
@ -350,12 +350,12 @@ copy_chain (type_t *type, type_t *append)
internal_error (0, "copy basic type"); internal_error (0, "copy basic type");
case ev_field: case ev_field:
case ev_ptr: case ev_ptr:
n = (type_t **) &(*n)->t.fldptr.type; n = (type_t **) &(*n)->fldptr.type;
type = (type_t *) type->t.fldptr.type; type = (type_t *) type->fldptr.type;
break; break;
case ev_func: case ev_func:
n = (type_t **) &(*n)->t.func.ret_type; n = (type_t **) &(*n)->func.ret_type;
type = (type_t *) type->t.func.ret_type; type = (type_t *) type->func.ret_type;
break; break;
case ev_invalid: case ev_invalid:
internal_error (0, "invalid basic type"); internal_error (0, "invalid basic type");
@ -363,8 +363,8 @@ copy_chain (type_t *type, type_t *append)
} }
break; break;
case ty_array: case ty_array:
n = (type_t **) &(*n)->t.array.type; n = (type_t **) &(*n)->array.type;
type = (type_t *) type->t.array.type; type = (type_t *) type->array.type;
break; break;
case ty_struct: case ty_struct:
case ty_union: case ty_union:
@ -408,13 +408,13 @@ append_type (const type_t *type, const type_t *new)
internal_error (0, "append to basic type"); internal_error (0, "append to basic type");
case ev_field: case ev_field:
case ev_ptr: case ev_ptr:
t = (const type_t **) &(*t)->t.fldptr.type; t = (const type_t **) &(*t)->fldptr.type;
((type_t *) type)->alignment = 1; ((type_t *) type)->alignment = 1;
((type_t *) type)->width = 1; ((type_t *) type)->width = 1;
((type_t *) type)->columns = 1; ((type_t *) type)->columns = 1;
break; break;
case ev_func: case ev_func:
t = (const type_t **) &(*t)->t.func.ret_type; t = (const type_t **) &(*t)->func.ret_type;
((type_t *) type)->alignment = 1; ((type_t *) type)->alignment = 1;
((type_t *) type)->width = 1; ((type_t *) type)->width = 1;
((type_t *) type)->columns = 1; ((type_t *) type)->columns = 1;
@ -425,7 +425,7 @@ append_type (const type_t *type, const type_t *new)
} }
break; break;
case ty_array: case ty_array:
t = (const type_t **) &(*t)->t.array.type; t = (const type_t **) &(*t)->array.type;
((type_t *) type)->alignment = new->alignment; ((type_t *) type)->alignment = new->alignment;
((type_t *) type)->width = new->width; ((type_t *) type)->width = new->width;
((type_t *) type)->columns = new->columns; ((type_t *) type)->columns = new->columns;
@ -443,7 +443,7 @@ append_type (const type_t *type, const type_t *new)
} }
if (type && new->meta == ty_alias) { if (type && new->meta == ty_alias) {
auto chain = find_type (copy_chain ((type_t *) type, (type_t *) new)); auto chain = find_type (copy_chain ((type_t *) type, (type_t *) new));
*t = new->t.alias.aux_type; *t = new->alias.aux_type;
type = alias_type (type, chain, 0); type = alias_type (type, chain, 0);
} else { } else {
*t = new; *t = new;
@ -454,8 +454,8 @@ append_type (const type_t *type, const type_t *new)
void void
set_func_type_attrs (const type_t *func, specifier_t spec) set_func_type_attrs (const type_t *func, specifier_t spec)
{ {
((type_t *) func)->t.func.no_va_list = spec.no_va_list;//FIXME ((type_t *) func)->func.no_va_list = spec.no_va_list;//FIXME
((type_t *) func)->t.func.void_return = spec.void_return; ((type_t *) func)->func.void_return = spec.void_return;
} }
specifier_t specifier_t
@ -554,16 +554,16 @@ find_type (const type_t *type)
switch (type->type) { switch (type->type) {
case ev_field: case ev_field:
case ev_ptr: case ev_ptr:
((type_t *) type)->t.fldptr.type = find_type (type->t.fldptr.type); ((type_t *) type)->fldptr.type = find_type (type->fldptr.type);
break; break;
case ev_func: case ev_func:
((type_t *) type)->t.func.ret_type = find_type (type->t.func.ret_type); ((type_t *) type)->func.ret_type = find_type (type->func.ret_type);
count = type->t.func.num_params; count = type->func.num_params;
if (count < 0) if (count < 0)
count = ~count; // param count is one's complement count = ~count; // param count is one's complement
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
((type_t *) type)->t.func.param_types[i] ((type_t *) type)->func.param_types[i]
= find_type (type->t.func.param_types[i]); = find_type (type->func.param_types[i]);
break; break;
default: // other types don't have aux data default: // other types don't have aux data
break; break;
@ -574,13 +574,13 @@ find_type (const type_t *type)
case ty_enum: case ty_enum:
break; break;
case ty_array: case ty_array:
((type_t *) type)->t.array.type = find_type (type->t.array.type); ((type_t *) type)->array.type = find_type (type->array.type);
break; break;
case ty_class: case ty_class:
break; break;
case ty_alias: case ty_alias:
((type_t *) type)->t.alias.aux_type = find_type (type->t.alias.aux_type); ((type_t *) type)->alias.aux_type = find_type (type->alias.aux_type);
((type_t *) type)->t.alias.full_type = find_type (type->t.alias.full_type); ((type_t *) type)->alias.full_type = find_type (type->alias.full_type);
break; break;
case ty_handle: case ty_handle:
break; break;
@ -600,16 +600,16 @@ find_type (const type_t *type)
check = new_type (); check = new_type ();
*check = *type; *check = *type;
if (is_func (type)) { if (is_func (type)) {
check->t.func.param_types = 0; check->func.param_types = 0;
const type_t *t = unalias_type (type); const type_t *t = unalias_type (type);
int num_params = t->t.func.num_params; int num_params = t->func.num_params;
if (num_params < 0) { if (num_params < 0) {
num_params = ~num_params; num_params = ~num_params;
} }
if (num_params) { if (num_params) {
check->t.func.param_types = malloc (sizeof (type_t *) * num_params); check->func.param_types = malloc (sizeof (type_t *) * num_params);
for (int i = 0; i < num_params; i++) { for (int i = 0; i < num_params; i++) {
check->t.func.param_types[i] = t->t.func.param_types[i]; check->func.param_types[i] = t->func.param_types[i];
} }
} }
} }
@ -799,7 +799,7 @@ array_type (const type_t *aux, int size)
new->alignment = aux->alignment; new->alignment = aux->alignment;
new->width = aux->width; new->width = aux->width;
} }
new->t.array.size = size; new->array.size = size;
if (aux) { if (aux) {
return find_type (append_type (new, aux)); return find_type (append_type (new, aux));
} }
@ -822,9 +822,9 @@ based_array_type (const type_t *aux, int base, int top)
new->width = aux->width; new->width = aux->width;
} }
new->meta = ty_array; new->meta = ty_array;
new->t.array.type = aux; new->array.type = aux;
new->t.array.base = base; new->array.base = base;
new->t.array.size = top - base + 1; new->array.size = top - base + 1;
if (aux) { if (aux) {
return find_type (new); return find_type (new);
} }
@ -842,15 +842,15 @@ alias_type (const type_t *type, const type_t *alias_chain, const char *name)
if (type == alias_chain && type->meta == ty_alias) { if (type == alias_chain && type->meta == ty_alias) {
// typedef of a type that contains a typedef somewhere // typedef of a type that contains a typedef somewhere
// grab the alias-free branch for type // grab the alias-free branch for type
type = alias_chain->t.alias.aux_type; type = alias_chain->alias.aux_type;
if (!alias_chain->name) { if (!alias_chain->name) {
// the other typedef is further inside, so replace the unnamed // the other typedef is further inside, so replace the unnamed
// alias node with the typedef // alias node with the typedef
alias_chain = alias_chain->t.alias.full_type; alias_chain = alias_chain->alias.full_type;
} }
} }
alias->t.alias.aux_type = type; alias->alias.aux_type = type;
alias->t.alias.full_type = alias_chain; alias->alias.full_type = alias_chain;
if (name) { if (name) {
alias->name = save_string (name); alias->name = save_string (name);
} }
@ -861,7 +861,7 @@ const type_t *
unalias_type (const type_t *type) unalias_type (const type_t *type)
{ {
if (type->meta == ty_alias) { if (type->meta == ty_alias) {
type = type->t.alias.aux_type; type = type->alias.aux_type;
if (type->meta == ty_alias) { if (type->meta == ty_alias) {
internal_error (0, "alias type node in alias-free chain"); internal_error (0, "alias type node in alias-free chain");
} }
@ -876,9 +876,9 @@ dereference_type (const type_t *type)
internal_error (0, "dereference non pointer/field/array type"); internal_error (0, "dereference non pointer/field/array type");
} }
if (type->meta == ty_alias) { if (type->meta == ty_alias) {
type = type->t.alias.full_type; type = type->alias.full_type;
} }
return type->t.fldptr.type; return type->fldptr.type;
} }
void void
@ -899,11 +899,11 @@ print_type_str (dstring_t *str, const type_t *type)
return; return;
case ty_alias: case ty_alias:
dasprintf (str, "({%s=", type->name); dasprintf (str, "({%s=", type->name);
print_type_str (str, type->t.alias.aux_type); print_type_str (str, type->alias.aux_type);
dstring_appendstr (str, "})"); dstring_appendstr (str, "})");
return; return;
case ty_class: case ty_class:
dasprintf (str, " %s", type->t.class->name); dasprintf (str, " %s", type->class->name);
if (type->protos) if (type->protos)
print_protocollist (str, type->protos); print_protocollist (str, type->protos);
return; return;
@ -917,12 +917,12 @@ print_type_str (dstring_t *str, const type_t *type)
dasprintf (str, " union %s", type->name); dasprintf (str, " union %s", type->name);
return; return;
case ty_array: case ty_array:
print_type_str (str, type->t.array.type); print_type_str (str, type->array.type);
if (type->t.array.base) { if (type->array.base) {
dasprintf (str, "[%d..%d]", type->t.array.base, dasprintf (str, "[%d..%d]", type->array.base,
type->t.array.base + type->t.array.size - 1); type->array.base + type->array.size - 1);
} else { } else {
dasprintf (str, "[%d]", type->t.array.size); dasprintf (str, "[%d]", type->array.size);
} }
return; return;
case ty_bool: case ty_bool:
@ -934,32 +934,32 @@ print_type_str (dstring_t *str, const type_t *type)
switch (type->type) { switch (type->type) {
case ev_field: case ev_field:
dasprintf (str, ".("); dasprintf (str, ".(");
print_type_str (str, type->t.fldptr.type); print_type_str (str, type->fldptr.type);
dasprintf (str, ")"); dasprintf (str, ")");
return; return;
case ev_func: case ev_func:
print_type_str (str, type->t.func.ret_type); print_type_str (str, type->func.ret_type);
if (type->t.func.num_params == -1) { if (type->func.num_params == -1) {
dasprintf (str, "(...)"); dasprintf (str, "(...)");
} else { } else {
int c, i; int c, i;
dasprintf (str, "("); dasprintf (str, "(");
if ((c = type->t.func.num_params) < 0) if ((c = type->func.num_params) < 0)
c = ~c; // num_params is one's compliment c = ~c; // num_params is one's compliment
for (i = 0; i < c; i++) { for (i = 0; i < c; i++) {
if (i) if (i)
dasprintf (str, ", "); dasprintf (str, ", ");
print_type_str (str, type->t.func.param_types[i]); print_type_str (str, type->func.param_types[i]);
} }
if (type->t.func.num_params < 0) if (type->func.num_params < 0)
dasprintf (str, ", ..."); dasprintf (str, ", ...");
dasprintf (str, ")"); dasprintf (str, ")");
} }
return; return;
case ev_ptr: case ev_ptr:
if (type->t.fldptr.type) { if (type->fldptr.type) {
if (is_id (type)) { if (is_id (type)) {
__auto_type ptr = type->t.fldptr.type; __auto_type ptr = type->fldptr.type;
dasprintf (str, "id"); dasprintf (str, "id");
if (ptr->protos) if (ptr->protos)
print_protocollist (str, ptr->protos); print_protocollist (str, ptr->protos);
@ -971,7 +971,7 @@ print_type_str (dstring_t *str, const type_t *type)
} }
} }
dasprintf (str, "(*"); dasprintf (str, "(*");
print_type_str (str, type->t.fldptr.type); print_type_str (str, type->fldptr.type);
dasprintf (str, ")"); dasprintf (str, ")");
return; return;
case ev_void: case ev_void:
@ -1035,13 +1035,13 @@ encode_params (const type_t *type)
dstring_t *encoding = dstring_newstr (); dstring_t *encoding = dstring_newstr ();
int i, count; int i, count;
if (type->t.func.num_params < 0) if (type->func.num_params < 0)
count = -type->t.func.num_params - 1; count = -type->func.num_params - 1;
else else
count = type->t.func.num_params; count = type->func.num_params;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
encode_type (encoding, unalias_type (type->t.func.param_types[i])); encode_type (encoding, unalias_type (type->func.param_types[i]));
if (type->t.func.num_params < 0) if (type->func.num_params < 0)
dasprintf (encoding, "."); dasprintf (encoding, ".");
ret = save_string (encoding->str); ret = save_string (encoding->str);
@ -1052,7 +1052,7 @@ encode_params (const type_t *type)
static void static void
encode_class (dstring_t *encoding, const type_t *type) encode_class (dstring_t *encoding, const type_t *type)
{ {
class_t *class = type->t.class; class_t *class = type->class;
const char *name ="?"; const char *name ="?";
if (class->name) if (class->name)
@ -1101,7 +1101,7 @@ encode_type (dstring_t *encoding, const type_t *type)
return; return;
case ty_alias: case ty_alias:
dasprintf (encoding, "{%s>", type->name ? type->name : ""); dasprintf (encoding, "{%s>", type->name ? type->name : "");
encode_type (encoding, type->t.alias.full_type); encode_type (encoding, type->alias.full_type);
dasprintf (encoding, "}"); dasprintf (encoding, "}");
return; return;
case ty_class: case ty_class:
@ -1116,11 +1116,11 @@ encode_type (dstring_t *encoding, const type_t *type)
return; return;
case ty_array: case ty_array:
dasprintf (encoding, "["); dasprintf (encoding, "[");
dasprintf (encoding, "%d", type->t.array.size); dasprintf (encoding, "%d", type->array.size);
if (type->t.array.base) if (type->array.base)
dasprintf (encoding, ":%d", type->t.array.base); dasprintf (encoding, ":%d", type->array.base);
dasprintf (encoding, "="); dasprintf (encoding, "=");
encode_type (encoding, type->t.array.type); encode_type (encoding, type->array.type);
dasprintf (encoding, "]"); dasprintf (encoding, "]");
return; return;
case ty_bool: case ty_bool:
@ -1167,11 +1167,11 @@ encode_type (dstring_t *encoding, const type_t *type)
return; return;
case ev_field: case ev_field:
dasprintf (encoding, "F"); dasprintf (encoding, "F");
encode_type (encoding, type->t.fldptr.type); encode_type (encoding, type->fldptr.type);
return; return;
case ev_func: case ev_func:
dasprintf (encoding, "("); dasprintf (encoding, "(");
encode_type (encoding, type->t.func.ret_type); encode_type (encoding, type->func.ret_type);
dasprintf (encoding, "%s)", encode_params (type)); dasprintf (encoding, "%s)", encode_params (type));
return; return;
case ev_ptr: case ev_ptr:
@ -1187,7 +1187,7 @@ encode_type (dstring_t *encoding, const type_t *type)
dasprintf (encoding, "#"); dasprintf (encoding, "#");
return; return;
} }
type = type->t.fldptr.type; type = type->fldptr.type;
dasprintf (encoding, "^"); dasprintf (encoding, "^");
encode_type (encoding, type); encode_type (encoding, type);
return; return;
@ -1407,8 +1407,8 @@ type_assignable (const type_t *dst, const type_t *src)
return 1; return 1;
// pointer = array // pointer = array
if (is_ptr (dst) && is_array (src)) { if (is_ptr (dst) && is_array (src)) {
if (is_void (dst->t.fldptr.type) if (is_void (dst->fldptr.type)
|| dst->t.fldptr.type == src->t.array.type) || dst->fldptr.type == src->array.type)
return 1; return 1;
return 0; return 0;
} }
@ -1434,8 +1434,8 @@ type_assignable (const type_t *dst, const type_t *src)
if (ret >= 0) if (ret >= 0)
return ret; return ret;
dst = dst->t.fldptr.type; dst = dst->fldptr.type;
src = src->t.fldptr.type; src = src->fldptr.type;
if (dst == src) { if (dst == src) {
return 1; return 1;
} }
@ -1507,18 +1507,18 @@ type_size (const type_t *type)
return pr_type_size[type->type] * type->width; return pr_type_size[type->type] * type->width;
case ty_struct: case ty_struct:
case ty_union: case ty_union:
if (!type->t.symtab) if (!type->symtab)
return 0; return 0;
return type->t.symtab->size; return type->symtab->size;
case ty_enum: case ty_enum:
if (!type->t.symtab) if (!type->symtab)
return 0; return 0;
return type_size (&type_int); return type_size (&type_int);
case ty_array: case ty_array:
return type->t.array.size * type_size (type->t.array.type); return type->array.size * type_size (type->array.type);
case ty_class: case ty_class:
{ {
class_t *class = type->t.class; class_t *class = type->class;
int size; int size;
if (!class->ivars) if (!class->ivars)
return 0; return 0;
@ -1528,7 +1528,7 @@ type_size (const type_t *type)
return size; return size;
} }
case ty_alias: case ty_alias:
return type_size (type->t.alias.aux_type); return type_size (type->alias.aux_type);
case ty_algebra: case ty_algebra:
return algebra_type_size (type); return algebra_type_size (type);
case ty_meta_count: case ty_meta_count:
@ -1555,15 +1555,15 @@ type_width (const type_t *type)
case ty_union: case ty_union:
return 1; return 1;
case ty_enum: case ty_enum:
if (!type->t.symtab) if (!type->symtab)
return 0; return 0;
return type_width (&type_int); return type_width (&type_int);
case ty_array: case ty_array:
return type_width (type->t.array.type); return type_width (type->array.type);
case ty_class: case ty_class:
return 1; return 1;
case ty_alias: case ty_alias:
return type_width (type->t.alias.aux_type); return type_width (type->alias.aux_type);
case ty_algebra: case ty_algebra:
return algebra_type_width (type); return algebra_type_width (type);
case ty_meta_count: case ty_meta_count:
@ -1602,7 +1602,7 @@ type_aligned_size (const type_t *type)
static void static void
chain_basic_types (void) chain_basic_types (void)
{ {
type_entity.t.symtab = pr.entity_fields; type_entity.symtab = pr.entity_fields;
if (options.code.progsversion == PROG_VERSION) { if (options.code.progsversion == PROG_VERSION) {
type_quaternion.alignment = 4; type_quaternion.alignment = 4;
} }
@ -1789,11 +1789,11 @@ init_types (void)
sym = new_symbol_type ("v", &type_vector); sym = new_symbol_type ("v", &type_vector);
sym->offset = 0; sym->offset = 0;
symtab_addsymbol (type_quaternion.t.symtab, sym); symtab_addsymbol (type_quaternion.symtab, sym);
sym = new_symbol_type ("s", &type_float); sym = new_symbol_type ("s", &type_float);
sym->offset = 3; sym->offset = 3;
symtab_addsymbol (type_quaternion.t.symtab, sym); symtab_addsymbol (type_quaternion.symtab, sym);
} }
#define VEC_TYPE(type_name, base_type) build_vector_struct (&type_##type_name); #define VEC_TYPE(type_name, base_type) build_vector_struct (&type_##type_name);
#include "tools/qfcc/include/vec_types.h" #include "tools/qfcc/include/vec_types.h"

View file

@ -280,7 +280,7 @@ new_nil_val (const type_t *type)
val.lltype = type_nil->type; val.lltype = type_nil->type;
} }
if (val.lltype == ev_ptr || val.lltype == ev_field ) if (val.lltype == ev_ptr || val.lltype == ev_field )
val.pointer.type = type->t.fldptr.type; val.pointer.type = type->fldptr.type;
if (val.lltype == ev_func) if (val.lltype == ev_func)
val.func_val.type = type; val.func_val.type = type;
return find_value (&val); return find_value (&val);