fixes for methods in categories or not in an interface

This is an imperfect revision of history.
This commit is contained in:
Bill Currie 2004-11-02 11:56:00 +00:00 committed by Jeff Teunissen
parent 2cb81b37f9
commit 9f52181e34

View file

@ -85,6 +85,7 @@ void
class_init (void) class_init (void)
{ {
class_Class.super_class = get_class ("Object", 1); class_Class.super_class = get_class ("Object", 1);
class_Class.methods = new_methodlist ();
} }
def_t * def_t *
@ -130,6 +131,7 @@ get_class (const char *name, int create)
new = *type_Class.aux_type; new = *type_Class.aux_type;
new.s.class = c; new.s.class = c;
c->type = pointer_type (find_type (&new)); c->type = pointer_type (find_type (&new));
c->methods = new_methodlist ();
c->class_type.is_class = 1; c->class_type.is_class = 1;
c->class_type.c.class = c; c->class_type.c.class = c;
if (name) if (name)
@ -438,12 +440,10 @@ class_find_method (class_type_t *class_type, method_t *method)
error (0, "method type mismatch"); error (0, "method type mismatch");
if (methods != start_methods) { if (methods != start_methods) {
m = copy_method (m); m = copy_method (m);
if (m->instance) set_self_type (start_class, m);
m->params->type = start_class->type;
else
m->params->type = &type_Class;
add_method (start_methods, m); add_method (start_methods, m);
} }
method_set_param_names (m, method);
return m; return m;
} }
if (class->methods == methods) if (class->methods == methods)
@ -459,11 +459,8 @@ class_find_method (class_type_t *class_type, method_t *method)
sel->str, class_name, sel->str, class_name,
category_name ? va (" (%s)", category_name) : ""); category_name ? va (" (%s)", category_name) : "");
} }
set_self_type (start_class, method);
add_method (start_methods, method); add_method (start_methods, method);
if (method->instance)
method->params->type = start_class->type;
else
method->params->type = &type_Class;
dstring_delete (sel); dstring_delete (sel);
return method; return method;
} }
@ -492,7 +489,6 @@ class_message_response (class_t *class, int class_msg, expr_t *sel)
return 0; return 0;
} else { } else {
while (c) { while (c) {
if (c->methods) {
for (cat = c->categories; cat; cat = cat->next) { for (cat = c->categories; cat; cat = cat->next) {
for (m = cat->methods->head; m; m = m->next) { for (m = cat->methods->head; m; m = m->next) {
if (strcmp (selector->name, m->name) == 0) if (strcmp (selector->name, m->name) == 0)
@ -503,7 +499,6 @@ class_message_response (class_t *class, int class_msg, expr_t *sel)
if (strcmp (selector->name, m->name) == 0) if (strcmp (selector->name, m->name) == 0)
return m; return m;
} }
}
c = c->super_class; c = c->super_class;
} }
//FIXME right option? //FIXME right option?
@ -593,6 +588,7 @@ get_category (const char *class_name, const char *category_name, int create)
class->categories = category; class->categories = category;
category->name = category_name; category->name = category_name;
category->class = class; category->class = class;
category->methods = new_methodlist ();
category->class_type.is_class = 0; category->class_type.is_class = 0;
category->class_type.c.category = category; category->class_type.c.category = category;
if (class_name && category_name) if (class_name && category_name)
@ -605,11 +601,11 @@ category_add_methods (category_t *category, methodlist_t *methods)
{ {
if (!methods) if (!methods)
return; return;
if (!category->methods)
category->methods = new_methodlist ();
*category->methods->tail = methods->head; *category->methods->tail = methods->head;
category->methods->tail = methods->tail; category->methods->tail = methods->tail;
free (methods); free (methods);
methods_set_self_type (category->class, category->methods);
} }
void void