Allow unlimited parameters in function declarations

However, definitions are still limited to 8 parameters. This allows
processing of C headers for type information.
This commit is contained in:
Bill Currie 2020-02-19 01:51:24 +09:00
parent e658c0d5cd
commit 501174e14f
5 changed files with 28 additions and 23 deletions

View file

@ -141,7 +141,6 @@ function_t *build_code_function (struct symbol_s *fsym,
struct expr_s *statements);
function_t *build_builtin_function (struct symbol_s *sym,
struct expr_s *bi_val, int far);
void build_function (function_t *f);
void finish_function (function_t *f);
void emit_function (function_t *f, struct expr_s *e);
int function_parms (function_t *f, byte *parm_size);

View file

@ -38,7 +38,7 @@
typedef struct ty_func_s {
struct type_s *type;
int num_params;
struct type_s *param_types[MAX_PARMS];
struct type_s **param_types;
} ty_func_t;
typedef struct ty_fldptr_s {

View file

@ -70,12 +70,14 @@ static hashtab_t *protocol_hash;
// these will be built up further
type_t type_obj_selector = { ev_invalid, 0, 0, ty_struct};
type_t type_SEL = { ev_pointer, "SEL", 1, ty_none, {{&type_obj_selector}}};
type_t *IMP_params[] = {&type_id, &type_SEL};
type_t type_IMP = { ev_func, "IMP", 1, ty_none,
{{&type_id, -3, {&type_id, &type_SEL}}}};
{{&type_id, -3, IMP_params}}};
type_t type_obj_super = { ev_invalid, 0, 0 };
type_t type_SuperPtr = { ev_pointer, 0, 1, ty_none, {{&type_obj_super}}};
type_t *supermsg_params[] = {&type_SuperPtr, &type_SEL};
type_t type_supermsg = { ev_func, ".supermsg", 1, ty_none,
{{&type_id, -3, {&type_SuperPtr, &type_SEL}}}};
{{&type_id, -3, supermsg_params}}};
type_t type_obj_method = { ev_invalid, 0, 0, ty_struct };
type_t type_obj_method_description = { ev_invalid, 0, 0, ty_struct };
type_t type_obj_category = { ev_invalid, 0, 0, ty_struct};
@ -83,8 +85,9 @@ type_t type_obj_ivar = { ev_invalid, 0, 0, ty_struct};
type_t type_obj_module = { ev_invalid, 0, 0, ty_struct};
type_t type_moduleptr = { ev_pointer, 0, 1, ty_none,
{{&type_obj_module}}};
type_t *obj_exec_class_params[] = { &type_moduleptr };
type_t type_obj_exec_class = { ev_func, 0, 1, ty_none,
{{&type_void, 1, { &type_moduleptr }}}};
{{&type_void, 1, obj_exec_class_params}}};
type_t type_obj_object = {ev_invalid, 0, 0, ty_struct};
type_t type_id = { ev_pointer, "id", 1, ty_none, {{&type_obj_object}}};

View file

@ -141,9 +141,6 @@ build_cpp_args (const char *in_name, const char *out_name)
}
}
*arg = 0;
//for (arg = cpp_argv; *arg; arg++)
// printf ("%s ", *arg);
//puts ("");
}
//============================================================================

View file

@ -155,6 +155,7 @@ parse_params (type_t *type, param_t *parms)
{
param_t *p;
type_t *new;
int count;
new = new_type ();
new->type = ev_func;
@ -163,10 +164,12 @@ parse_params (type_t *type, param_t *parms)
new->t.func.num_params = 0;
for (p = parms; p; p = p->next) {
if (new->t.func.num_params > MAX_PARMS) {
error (0, "too many params");
return type;
if (p->type) {
count++;
}
}
new->t.func.param_types = malloc (count * sizeof (type_t));
for (p = parms; p; p = p->next) {
if (!p->selector && !p->type && !p->name) {
if (p->next)
internal_error (0, 0);
@ -581,12 +584,25 @@ begin_function (symbol_t *sym, const char *nicename, symtab_t *parent,
return sym->s.func;
}
static void
build_function (symbol_t *fsym)
{
if (fsym->type->t.func.num_params > MAX_PARMS) {
error (0, "too many params");
}
// FIXME
// f->def->constant = 1;
// f->def->nosave = 1;
// f->def->initialized = 1;
// G_FUNCTION (f->def->ofs) = f->function_num;
}
function_t *
build_code_function (symbol_t *fsym, expr_t *state_expr, expr_t *statements)
{
if (fsym->sy_type != sy_func) // probably in error recovery
return 0;
build_function (fsym->s.func);
build_function (fsym);
if (state_expr) {
state_expr->next = statements;
statements = state_expr;
@ -629,7 +645,7 @@ build_builtin_function (symbol_t *sym, expr_t *bi_val, int far)
bi = expr_float (bi_val);
sym->s.func->builtin = bi;
reloc_def_func (sym->s.func, sym->s.func->def);
build_function (sym->s.func);
build_function (sym);
finish_function (sym->s.func);
// for debug info
@ -638,16 +654,6 @@ build_builtin_function (symbol_t *sym, expr_t *bi_val, int far)
return sym->s.func;
}
void
build_function (function_t *f)
{
// FIXME
// f->def->constant = 1;
// f->def->nosave = 1;
// f->def->initialized = 1;
// G_FUNCTION (f->def->ofs) = f->function_num;
}
void
finish_function (function_t *f)
{