From 1b5bf9d176453c0f0e042fcae8e2b8d3be7884ab Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 1 Aug 2003 05:08:15 +0000 Subject: [PATCH] make methods showing up only in the implementation work when overiding an inherited method --- tools/qfcc/include/method.h | 1 + tools/qfcc/source/class.c | 38 +++++++++++++++++++++++++++---------- tools/qfcc/source/method.c | 16 ++++++++++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/tools/qfcc/include/method.h b/tools/qfcc/include/method.h index ea35fa5f9..fbfed5c0b 100644 --- a/tools/qfcc/include/method.h +++ b/tools/qfcc/include/method.h @@ -65,6 +65,7 @@ struct dstring_s; method_t *new_method (struct type_s *ret_type, param_t *selector, param_t *opt_parms); +method_t *copy_method (method_t *method); void add_method (methodlist_t *methodlist, method_t *method); struct def_s *method_def (struct class_type_s *class_type, method_t *method); diff --git a/tools/qfcc/source/class.c b/tools/qfcc/source/class.c index 73b6923e7..df6c0dcb9 100644 --- a/tools/qfcc/source/class.c +++ b/tools/qfcc/source/class.c @@ -390,26 +390,44 @@ class_ivar_expr (class_type_t *class_type, const char *name) method_t * class_find_method (class_type_t *class_type, method_t *method) { - methodlist_t *methods; + methodlist_t *methods, *start_methods;; method_t *m; dstring_t *sel; + class_t *class, *start_class; const char *class_name; const char *category_name = 0; if (!class_type->is_class) { methods = class_type->c.category->methods; category_name = class_type->c.category->name; - class_name = class_type->c.category->class->name; + class = class_type->c.category->class; } else { - methods = class_type->c.class->methods; - class_name = class_type->c.class->name; + class = class_type->c.class; + methods = class->methods; + } + class_name = class->name; + start_methods = methods; + start_class = class; + while (class) { + for (m = methods->head; m; m = m->next) + if (method_compare (method, m)) { + if (m->type != method->type) + error (0, "method type mismatch"); + if (methods != start_methods) { + m = copy_method (m); + if (m->instance) + m->params->type = start_class->type; + else + m->params->type = &type_Class; + add_method (methods, m); + } + return m; + } + if (class->methods == methods) + class = class->super_class; + else + methods = class->methods; } - for (m = methods->head; m; m = m->next) - if (method_compare (method, m)) { - if (m->type != method->type) - error (0, "method type mismatch"); - return m; - } sel = dstring_newstr (); selector_name (sel, (keywordarg_t *)method->selector); if (options.warnings.interface_check) { diff --git a/tools/qfcc/source/method.c b/tools/qfcc/source/method.c index 3ab4f60bc..29a15040a 100644 --- a/tools/qfcc/source/method.c +++ b/tools/qfcc/source/method.c @@ -115,6 +115,22 @@ new_method (type_t *ret_type, param_t *selector, param_t *opt_parms) return meth; } +method_t * +copy_method (method_t *method) +{ + method_t *meth = calloc (sizeof (method_t), 1); + param_t *self = copy_params (method->params); + + meth->next = 0; + meth->instance = method->instance; + meth->selector = self->next->next; + meth->params = self; + meth->type = parse_params (method->type->aux_type, meth->params); + meth->name = method->name; + meth->types = method->types; + return meth; +} + void add_method (methodlist_t *methodlist, method_t *method) {