Fix type chaining when dealing with decls.

This commit is contained in:
Bill Currie 2011-02-03 21:32:58 +09:00
parent 54c8a10fe4
commit f44a26e268
2 changed files with 61 additions and 41 deletions

View file

@ -154,15 +154,15 @@ type_t *
parse_params (type_t *type, param_t *parms) parse_params (type_t *type, param_t *parms)
{ {
param_t *p; param_t *p;
type_t new; type_t *new;
memset (&new, 0, sizeof (new)); new = new_type ();
new.type = ev_func; new->type = ev_func;
new.t.func.type = type; new->t.func.type = type;
new.t.func.num_params = 0; new->t.func.num_params = 0;
for (p = parms; p; p = p->next) { for (p = parms; p; p = p->next) {
if (new.t.func.num_params > MAX_PARMS) { if (new->t.func.num_params > MAX_PARMS) {
error (0, "too many params"); error (0, "too many params");
return type; return type;
} }
@ -171,19 +171,13 @@ parse_params (type_t *type, param_t *parms)
error (0, "internal error"); error (0, "internal error");
abort (); abort ();
} }
new.t.func.num_params = -(new.t.func.num_params + 1); new->t.func.num_params = -(new->t.func.num_params + 1);
} else if (p->type) { } else if (p->type) {
new.t.func.param_types[new.t.func.num_params] = p->type; new->t.func.param_types[new->t.func.num_params] = p->type;
new.t.func.num_params++; new->t.func.num_params++;
} }
} }
//print_type (&new); puts(""); return new;
//return find_type (&new);
{
type_t *n = new_type ();
*n = new;
return n;
}
} }
param_t * param_t *
@ -230,6 +224,8 @@ get_function (const char *name, type_t *type, int overload, int create)
func = Hash_Find (overloaded_functions, full_name); func = Hash_Find (overloaded_functions, full_name);
if (func) { if (func) {
if (func->type != type) { if (func->type != type) {
print_type (func->type); printf (" %p\n", func->type);
print_type (type); printf (" %p\n", type);
error (0, "can't overload on return types"); error (0, "can't overload on return types");
return func; return func;
} }

View file

@ -307,50 +307,74 @@ find_type (type_t *type)
type_t * type_t *
field_type (type_t *aux) field_type (type_t *aux)
{ {
type_t new; type_t _new;
type_t *new = &_new;
memset (&new, 0, sizeof (new)); if (aux)
new.type = ev_field; memset (&_new, 0, sizeof (_new));
new.t.fldptr.type = aux; else
return find_type (&new); new = new_type ();
new->type = ev_field;
new->t.fldptr.type = aux;
if (aux)
new = find_type (new);
return new;
} }
type_t * type_t *
pointer_type (type_t *aux) pointer_type (type_t *aux)
{ {
type_t new; type_t _new;
type_t *new = &_new;
memset (&new, 0, sizeof (new)); if (aux)
new.type = ev_pointer; memset (&_new, 0, sizeof (_new));
new.t.fldptr.type = aux; else
return find_type (&new); new = new_type ();
new->type = ev_pointer;
new->t.fldptr.type = aux;
if (aux)
new = find_type (new);
return new;
} }
type_t * type_t *
array_type (type_t *aux, int size) array_type (type_t *aux, int size)
{ {
type_t new; type_t _new;
type_t *new = &_new;
memset (&new, 0, sizeof (new)); if (aux)
new.type = ev_invalid; memset (&_new, 0, sizeof (_new));
new.ty = ty_array; else
new.t.array.type = aux; new = new_type ();
new.t.array.size = size; new->type = ev_invalid;
return find_type (&new); new->ty = ty_array;
new->t.array.type = aux;
new->t.array.size = size;
if (aux)
new = find_type (new);
return new;
} }
type_t * type_t *
based_array_type (type_t *aux, int base, int top) based_array_type (type_t *aux, int base, int top)
{ {
type_t new; type_t _new;
type_t *new = &_new;
memset (&new, 0, sizeof (new)); if (aux)
new.type = ev_invalid; memset (&_new, 0, sizeof (_new));
new.ty = ty_array; else
new.t.array.type = aux; new = new_type ();
new.t.array.base = base; new->type = ev_invalid;
new.t.array.size = top - base + 1; new->ty = ty_array;
return find_type (&new); new->t.array.type = aux;
new->t.array.base = base;
new->t.array.size = top - base + 1;
if (aux)
new = find_type (new);
return new;
} }
void void