*type_method to type_Method
emit.c:
	support casting between pointers
expr.c:
	support casting between pointers
method.c:
	correct the type for _cmd
	type_method to type_Method.aux_type
qc-lex.l:
	Method type is a poniter to a method
qc-parse.y:
	support , args to messages (not fully implemented yet)
type.c:
	*type_method to type_Method and make type_Method a pointer to a method
This commit is contained in:
Bill Currie 2002-05-22 05:03:36 +00:00
parent a1fe5efd27
commit 3967f5cf95
7 changed files with 37 additions and 22 deletions

View file

@ -52,7 +52,7 @@ extern type_t type_Protocol;
extern type_t type_SEL; extern type_t type_SEL;
extern type_t type_IMP; extern type_t type_IMP;
extern type_t type_obj_exec_class; extern type_t type_obj_exec_class;
extern type_t *type_method; 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;

View file

@ -353,12 +353,16 @@ emit_sub_expr (expr_t *e, def_t *dest)
d->type = e->e.expr.type; d->type = e->e.expr.type;
return d; return d;
case 'C': case 'C':
def_a = emit_sub_expr (e->e.expr.e1, 0);
if (def_a->type->type == ev_pointer
&& e->e.expr.type->type == ev_pointer) {
return def_a;
}
def_b = &def_void;
if (!dest) { if (!dest) {
dest = PR_GetTempDef (e->e.expr.type, pr_scope); dest = PR_GetTempDef (e->e.expr.type, pr_scope);
dest->users = 2; dest->users = 2;
} }
def_a = emit_sub_expr (e->e.expr.e1, 0);
def_b = &def_void;
operator = "="; operator = "=";
break; break;
default: default:

View file

@ -1935,21 +1935,31 @@ assign_expr (expr_t *e1, expr_t *e2)
} }
expr_t * expr_t *
cast_expr (type_t *t, expr_t *e) cast_expr (type_t *type, expr_t *e)
{ {
expr_t *c; expr_t *c;
type_t *e_type;
convert_name (e);
if (e->type == ex_error) if (e->type == ex_error)
return e; return e;
if ((t != &type_integer && t != &type_uinteger e_type = get_type (e);
&& get_type (e) != &type_float)
&& (t != &type_float && get_type (e) != &type_integer)) { if (type->type == ev_pointer && e_type->type == ev_pointer) {
return error (e, "can not cast from %s to %s", c = new_unary_expr ('C', e);
pr_type_name[extract_type (e)], pr_type_name[t->type]); c->e.expr.type = type;
} else if (((type == &type_integer || type == &type_uinteger)
&& e_type == &type_float)
|| (type == &type_float
&& (e_type == &type_integer || e_type == &type_uinteger))) {
c = new_unary_expr ('C', e);
c->e.expr.type = type;
} else {
c = error (e, "can not cast from %s to %s",
pr_type_name[extract_type (e)], pr_type_name[type->type]);
} }
c = new_unary_expr ('C', e);
c->e.expr.type = t;
return c; return c;
} }

View file

@ -51,7 +51,7 @@ method_t *
new_method (type_t *ret_type, param_t *selector, param_t *opt_parms) new_method (type_t *ret_type, param_t *selector, param_t *opt_parms)
{ {
method_t *meth = malloc (sizeof (method_t)); method_t *meth = malloc (sizeof (method_t));
param_t *cmd = new_param (0, &type_pointer, "_cmd"); param_t *cmd = new_param (0, &type_SEL, "_cmd");
param_t *self = new_param (0, &type_id, "self"); param_t *self = new_param (0, &type_id, "self");
dstring_t *name = dstring_newstr (); dstring_t *name = dstring_newstr ();
dstring_t *types = dstring_newstr (); dstring_t *types = dstring_newstr ();
@ -286,7 +286,7 @@ emit_methods (methodlist_t *_methods, const char *name, int instance)
new_struct_field (method_list, &type_pointer, "method_next", vis_public); new_struct_field (method_list, &type_pointer, "method_next", vis_public);
new_struct_field (method_list, &type_integer, "method_count", vis_public); new_struct_field (method_list, &type_integer, "method_count", vis_public);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
new_struct_field (method_list, type_method, 0, vis_public); new_struct_field (method_list, type_Method.aux_type, 0, vis_public);
methods_def = PR_GetDef (method_list, va ("_OBJ_%s_METHODS_%s", type, name), methods_def = PR_GetDef (method_list, va ("_OBJ_%s_METHODS_%s", type, name),
0, &numpr_globals); 0, &numpr_globals);
methods_def->initialized = methods_def->constant = 1; methods_def->initialized = methods_def->constant = 1;

View file

@ -246,6 +246,7 @@ static keyword_t keywords[] = {
{"id", TYPE, &type_id, 0, PROG_VERSION}, {"id", TYPE, &type_id, 0, PROG_VERSION},
{"Class", TYPE, &type_Class, 0, PROG_VERSION}, {"Class", TYPE, &type_Class, 0, PROG_VERSION},
{"Protocol", TYPE, &type_Protocol, 0, PROG_VERSION}, {"Protocol", TYPE, &type_Protocol, 0, PROG_VERSION},
{"Method", TYPE, &type_Method, 0, PROG_VERSION},
{"SEL", TYPE, &type_SEL, 0, PROG_VERSION}, {"SEL", TYPE, &type_SEL, 0, PROG_VERSION},
{"IMP", TYPE, &type_IMP, 0, PROG_VERSION}, {"IMP", TYPE, &type_IMP, 0, PROG_VERSION},
{"local", LOCAL, 0, 1, PROG_ID_VERSION}, {"local", LOCAL, 0, 1, PROG_ID_VERSION},

View file

@ -1245,8 +1245,8 @@ keywordarglist
; ;
keywordarg keywordarg
: selector ':' expr { $$ = new_keywordarg ($1, $3); } : selector ':' arg_list { $$ = new_keywordarg ($1, $3); }
| ':' expr { $$ = new_keywordarg ("", $2); } | ':' arg_list { $$ = new_keywordarg ("", $2); }
; ;
selectorarg selectorarg

View file

@ -71,7 +71,7 @@ type_t type_Protocol = { ev_pointer };
type_t type_SEL = { ev_pointer }; type_t type_SEL = { ev_pointer };
type_t type_IMP = { ev_func, NULL, &type_id, -3, { &type_id, &type_SEL }}; type_t type_IMP = { ev_func, NULL, &type_id, -3, { &type_id, &type_SEL }};
type_t type_obj_exec_class = { ev_func, NULL, &type_void, 1, { 0 }}; type_t type_obj_exec_class = { ev_func, NULL, &type_void, 1, { 0 }};
type_t *type_method; type_t type_Method = { ev_pointer };
type_t *type_category; type_t *type_category;
type_t *type_ivar; type_t *type_ivar;
type_t *type_module; type_t *type_module;
@ -419,16 +419,16 @@ init_types (void)
chain_type (&type_struct); chain_type (&type_struct);
chain_type (&type_IMP); chain_type (&type_IMP);
type = type_SEL.aux_type = new_struct ("SEL"); type = type_SEL.aux_type = new_struct (0);
new_struct_field (type, &type_string, "sel_id", vis_public); new_struct_field (type, &type_string, "sel_id", vis_public);
new_struct_field (type, &type_string, "sel_types", vis_public); new_struct_field (type, &type_string, "sel_types", vis_public);
chain_type (&type_SEL); chain_type (&type_SEL);
type_method = new_struct (0); type = type_Method.aux_type = new_struct (0);
new_struct_field (type_method, type_SEL.aux_type, "method_name", vis_public); new_struct_field (type, type_SEL.aux_type, "method_name", vis_public);
new_struct_field (type_method, &type_string, "method_types", vis_public); new_struct_field (type, &type_string, "method_types", vis_public);
new_struct_field (type_method, &type_IMP, "method_imp", vis_public); new_struct_field (type, &type_IMP, "method_imp", vis_public);
chain_type (type_method); chain_type (&type_Method);
type = type_Class.aux_type = new_struct (0); type = type_Class.aux_type = new_struct (0);
type->type = ev_class; type->type = ev_class;