replace @argc and @argv with @args.count and @args.list. @args is of type

@va_list making it possible (though not yet: need to implement structure
copy) to pass ... params around.
This commit is contained in:
Bill Currie 2002-10-16 02:28:08 +00:00
parent 27effb5075
commit 7542a2457f
5 changed files with 46 additions and 14 deletions

View file

@ -72,6 +72,7 @@ extern type_t type_Method;
extern type_t *type_category; extern type_t *type_category;
extern type_t *type_ivar; extern type_t *type_ivar;
extern type_t *type_module; extern type_t *type_module;
extern type_t type_va_list;
extern type_t *vector_struct; extern type_t *vector_struct;

View file

@ -141,18 +141,15 @@ build_scope (function_t *f, def_t *func, param_t *params)
int i; int i;
def_t *def; def_t *def;
param_t *p; param_t *p;
def_t *argv = 0; def_t *args = 0;
int parm_ofs[MAX_PARMS]; int parm_ofs[MAX_PARMS];
f->scope = new_scope (sc_params, new_defspace (), pr.scope); f->scope = new_scope (sc_params, new_defspace (), pr.scope);
if (func->type->num_parms < 0) { if (func->type->num_parms < 0) {
def = get_def (&type_integer, ".argc", f->scope, st_local); args = get_def (&type_va_list, ".args", f->scope, st_local);
def->used = 1; args->used = 1;
def_initialized (def); def_initialized (args);
argv = get_def (&type_pointer, ".argv", f->scope, st_local);
argv->used = 1;
def_initialized (argv);
} }
for (p = params, i = 0; p; p = p->next) { for (p = params, i = 0; p; p = p->next) {
@ -172,12 +169,10 @@ build_scope (function_t *f, def_t *func, param_t *params)
i++; i++;
} }
if (argv) { if (args) {
while (i < MAX_PARMS) { while (i < MAX_PARMS) {
def = get_def (&type_vector, 0, f->scope, st_local); def = get_def (&type_vector, 0, f->scope, st_local);
def->used = 1; def->used = 1;
if (argv->type == &type_pointer)
argv->type = array_type (&type_vector, MAX_PARMS - i);
i++; i++;
} }
} }

View file

@ -297,8 +297,10 @@ static keyword_t keywords[] = {
{"@selector", SELECTOR, 0, 0, PROG_VERSION}, {"@selector", SELECTOR, 0, 0, PROG_VERSION},
{"@self", SELF, 0, 0, PROG_VERSION}, {"@self", SELF, 0, 0, PROG_VERSION},
{"@this", THIS, 0, 0, PROG_VERSION}, {"@this", THIS, 0, 0, PROG_VERSION},
{"@args", ARGS, 0, 0, PROG_VERSION},
{"@argc", ARGC, 0, 0, PROG_VERSION}, {"@argc", ARGC, 0, 0, PROG_VERSION},
{"@argv", ARGV, 0, 0, PROG_VERSION}, {"@argv", ARGV, 0, 0, PROG_VERSION},
{"@va_list", TYPE, &type_va_list, 0, PROG_VERSION},
{"@extern", EXTERN, 0, 1, PROG_ID_VERSION}, {"@extern", EXTERN, 0, 1, PROG_ID_VERSION},
{"@static", STATIC, 0, 1, PROG_ID_VERSION}, {"@static", STATIC, 0, 1, PROG_ID_VERSION},
{"@system", SYSTEM, 0, 1, PROG_ID_VERSION}, {"@system", SYSTEM, 0, 1, PROG_ID_VERSION},

View file

@ -86,6 +86,9 @@ hashtab_t *merge_local_inits (hashtab_t *dl_1, hashtab_t *dl_2);
void restore_local_inits (hashtab_t *def_list); void restore_local_inits (hashtab_t *def_list);
void free_local_inits (hashtab_t *def_list); void free_local_inits (hashtab_t *def_list);
expr_t *argc_expr (void);
expr_t *argv_expr (void);
%} %}
%union { %union {
@ -128,7 +131,7 @@ void free_local_inits (hashtab_t *def_list);
%token LOCAL RETURN WHILE DO IF ELSE FOR BREAK CONTINUE ELLIPSIS NIL %token LOCAL RETURN WHILE DO IF ELSE FOR BREAK CONTINUE ELLIPSIS NIL
%token IFBE IFB IFAE IFA %token IFBE IFB IFAE IFA
%token SWITCH CASE DEFAULT STRUCT UNION ENUM TYPEDEF SUPER SELF THIS %token SWITCH CASE DEFAULT STRUCT UNION ENUM TYPEDEF SUPER SELF THIS
%token ARGC ARGV EXTERN STATIC SYSTEM SIZEOF %token ARGS ARGC ARGV EXTERN STATIC SYSTEM SIZEOF
%token ELE_START %token ELE_START
%token <type> TYPE %token <type> TYPE
%token CLASS DEFS ENCODE END IMPLEMENTATION INTERFACE PRIVATE PROTECTED %token CLASS DEFS ENCODE END IMPLEMENTATION INTERFACE PRIVATE PROTECTED
@ -823,8 +826,9 @@ expr
| expr INCOP { $$ = incop_expr ($2, $1, 1); } | expr INCOP { $$ = incop_expr ($2, $1, 1); }
| obj_expr { $$ = $1; } | obj_expr { $$ = $1; }
| NAME { $$ = new_name_expr ($1); } | NAME { $$ = new_name_expr ($1); }
| ARGC { $$ = new_name_expr (".argc"); } | ARGS { $$ = new_name_expr (".args"); }
| ARGV { $$ = new_name_expr (".argv"); } | ARGC { $$ = argc_expr (); }
| ARGV { $$ = argv_expr (); }
| SELF { $$ = new_self_expr (); } | SELF { $$ = new_self_expr (); }
| THIS { $$ = new_this_expr (); } | THIS { $$ = new_this_expr (); }
| SIZEOF '(' expr ')' { $$ = sizeof_expr ($3, 0); } | SIZEOF '(' expr ')' { $$ = sizeof_expr ($3, 0); }
@ -1390,3 +1394,17 @@ free_local_inits (hashtab_t *def_list)
{ {
Hash_DelTable (def_list); Hash_DelTable (def_list);
} }
expr_t *
argc_expr (void)
{
warning (0, "@argc deprecated: use @args.count");
return binary_expr ('.', new_name_expr (".args"), new_name_expr ("count"));
}
expr_t *
argv_expr (void)
{
warning (0, "@argv deprecated: use @args.list");
return binary_expr ('.', new_name_expr (".args"), new_name_expr ("list"));
}

View file

@ -68,7 +68,7 @@ type_t type_string = { ev_string, "string" };
type_t type_float = { ev_float, "float" }; type_t type_float = { ev_float, "float" };
type_t type_vector = { ev_vector, "vector" }; type_t type_vector = { ev_vector, "vector" };
type_t type_entity = { ev_entity, "entity" }; type_t type_entity = { ev_entity, "entity" };
type_t type_field = { ev_field, "field" }; type_t type_field = { ev_field, "field", NULL, &type_void };
// type_function is a void() function used for state defs // type_function is a void() function used for state defs
type_t type_function = { ev_func, "function", NULL, &type_void }; type_t type_function = { ev_func, "function", NULL, &type_void };
@ -90,6 +90,7 @@ type_t type_Method = { ev_pointer, "Method" };
type_t *type_category; type_t *type_category;
type_t *type_ivar; type_t *type_ivar;
type_t *type_module; type_t *type_module;
type_t type_va_list;
type_t *vector_struct; type_t *vector_struct;
@ -565,6 +566,7 @@ type_size (type_t *type)
case ev_type_count: case ev_type_count:
return pr_type_size[type->type]; return pr_type_size[type->type];
case ev_struct: case ev_struct:
return type->num_parms;
case ev_object: case ev_object:
case ev_class: case ev_class:
for (size = 0, field = type->struct_head; for (size = 0, field = type->struct_head;
@ -645,6 +647,20 @@ init_types (void)
new_struct_field (type, &type_string, "ivar_name", vis_public); new_struct_field (type, &type_string, "ivar_name", vis_public);
new_struct_field (type, &type_string, "ivar_type", vis_public); new_struct_field (type, &type_string, "ivar_type", vis_public);
new_struct_field (type, &type_integer, "ivar_offset", vis_public); new_struct_field (type, &type_integer, "ivar_offset", vis_public);
init_struct (malloc (sizeof (struct_t)), &type_va_list, 0);
new_struct_field (&type_va_list, &type_integer, "count", vis_public);
type = new_union (0);
new_struct_field (type, &type_string, "string_val", vis_public);
new_struct_field (type, &type_float, "float_val", vis_public);
new_struct_field (type, &type_vector, "vector_val", vis_public);
new_struct_field (type, &type_entity, "entity_val", vis_public);
new_struct_field (type, &type_field, "field_val", vis_public);
new_struct_field (type, &type_function, "func_val", vis_public);
new_struct_field (type, &type_pointer, "pointer_val", vis_public);
new_struct_field (type, &type_integer, "integer_val", vis_public);
new_struct_field (type, &type_uinteger, "uinteger_val", vis_public);
new_struct_field (&type_va_list, pointer_type (type), "list", vis_public);
#if 0 #if 0
type = type_module = new_struct ("obj_module_t"); type = type_module = new_struct ("obj_module_t");
new_struct_field (type, &type_integer, "version", vis_public); new_struct_field (type, &type_integer, "version", vis_public);