--- gcc/objc/sendmsg.c 2018/04/24 18:20:08 1.1.1.3 +++ gcc/objc/sendmsg.c 2018/04/24 18:26:42 1.1.1.4 @@ -1,22 +1,22 @@ /* GNU Objective C Runtime message lookup - Copyright (C) 1993 Free Software Foundation, Inc. - -Author: Kresten Krab Thorup + Copyright (C) 1993, 1995 Free Software Foundation, Inc. + Contributed by Kresten Krab Thorup This file is part of GNU CC. GNU CC is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 2, or (at your option) any later version. +terms of the GNU General Public License as published by the Free Software +Foundation; either version 2, or (at your option) any later version. GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. You should have received a copy of the GNU General Public License along with - GNU CC; see the file COPYING. If not, write to the Free Software - Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +GNU CC; see the file COPYING. If not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ /* As a special exception, if you link this library with files compiled with GCC to produce an executable, this does not cause the resulting executable @@ -43,9 +43,9 @@ You should have received a copy of the G struct sarray* __objc_uninstalled_dtable = 0; /* Send +initialize to class */ -static void __objc_send_initialize(Class*); +static void __objc_send_initialize(Class); -static void __objc_install_dispatch_table_for_class (Class*); +static void __objc_install_dispatch_table_for_class (Class); /* Forward declare some functions */ static void __objc_init_install_dtable(id, SEL); @@ -57,7 +57,7 @@ static __big static id #endif __objc_block_forward(id, SEL, ...); -static Method_t search_for_method_in_hierarchy (Class* class, SEL sel); +static Method_t search_for_method_in_hierarchy (Class class, SEL sel); static Method_t search_for_method_in_list(MethodList_t list, SEL op); id nil_method(id, SEL, ...); @@ -70,7 +70,7 @@ nil_method(id receiver, SEL op, ...) /* Given a class and selector, return the selector's implementation. */ __inline__ IMP -get_imp (Class* class, SEL sel) +get_imp (Class class, SEL sel) { IMP impl; void* res = sarray_get (class->dtable, (size_t) sel->sel_id); @@ -162,7 +162,7 @@ void __objc_init_dispatch_tables() static void __objc_init_install_dtable(id receiver, SEL op) { - __label__ allready_initialized; + __label__ already_initialized; IMP imp; void* args; void* result; @@ -170,7 +170,7 @@ static void __objc_init_install_dtable(i /* This may happen, if the programmer has taken the address of a method before the dtable was initialized... too bad for him! */ if(receiver->class_pointer->dtable != __objc_uninstalled_dtable) - goto allready_initialized; + goto already_initialized; if(CLS_ISCLASS(receiver->class_pointer)) { @@ -187,19 +187,19 @@ static void __objc_init_install_dtable(i else { /* receiver is a class object */ - assert(CLS_ISCLASS((Class*)receiver)); + assert(CLS_ISCLASS((Class)receiver)); assert(CLS_ISMETA(receiver->class_pointer)); /* Install real dtable for factory methods */ __objc_install_dispatch_table_for_class (receiver->class_pointer); if (strcmp (sel_get_name (op), "initialize")) - __objc_send_initialize((Class*)receiver); + __objc_send_initialize((Class)receiver); else - CLS_SETINITIALIZED((Class*)receiver); + CLS_SETINITIALIZED((Class)receiver); } -allready_initialized: +already_initialized: /* Get real method for this in newly installed dtable */ imp = get_imp(receiver->class_pointer, op); @@ -215,14 +215,14 @@ allready_initialized: /* Install dummy table for class which causes the first message to that class (or instances hereof) to be initialized properly */ -void __objc_install_premature_dtable(Class* class) +void __objc_install_premature_dtable(Class class) { assert(__objc_uninstalled_dtable); class->dtable = __objc_uninstalled_dtable; } /* Send +initialize to class if not already done */ -static void __objc_send_initialize(Class* class) +static void __objc_send_initialize(Class class) { /* This *must* be a class object */ assert(CLS_ISCLASS(class)); @@ -237,36 +237,42 @@ static void __objc_send_initialize(Class __objc_send_initialize(class->super_class); { - MethodList_t method_list = class->class_pointer->methods; - SEL op = sel_register_name ("initialize"); + SEL op = sel_register_name ("initialize"); + Class tmpclass = class; + IMP imp = 0; + + while (!imp && tmpclass) { + MethodList_t method_list = tmpclass->class_pointer->methods; - /* If not found then we'll search the list. */ - while (method_list) - { + while(!imp && method_list) { int i; + Method_t method; - /* Search the method list. */ - for (i = 0; i < method_list->method_count; ++i) - { - Method_t method = &method_list->method_list[i]; - - - if (method->method_name->sel_id == op->sel_id) - (*method->method_imp)((id) class, op); + for (i=0;imethod_count;i++) { + method = &(method_list->method_list[i]); + if (method->method_name->sel_id == op->sel_id) { + imp = method->method_imp; + break; } + } - /* The method wasn't found. Follow the link to the next list of - methods. */ method_list = method_list->method_next; + } + + tmpclass = tmpclass->super_class; + } + if (imp) + (*imp)((id)class, op); + } } } static void -__objc_install_dispatch_table_for_class (Class* class) +__objc_install_dispatch_table_for_class (Class class) { - Class* super; + Class super; MethodList_t mlist; int counter; @@ -280,7 +286,7 @@ __objc_install_dispatch_table_for_class if (super != 0 && (super->dtable == __objc_uninstalled_dtable)) __objc_install_dispatch_table_for_class (super); - /* Allocate dtable if nessecary */ + /* Allocate dtable if necessary */ if (super == 0) { class->dtable = sarray_new (__objc_selector_max_index, 0); @@ -302,9 +308,9 @@ __objc_install_dispatch_table_for_class } } -void __objc_update_dispatch_table_for_class (Class* class) +void __objc_update_dispatch_table_for_class (Class class) { - Class* next; + Class next; /* not yet installed -- skip it */ if (class->dtable == __objc_uninstalled_dtable) @@ -326,10 +332,10 @@ void __objc_update_dispatch_table_for_cl such this function does not worry about thread safe issued. This one is only called for categories. Class objects have their - methods installed rightaway, and their selectors are made into + methods installed right away, and their selectors are made into SEL's by the function __objc_register_selectors_from_class. */ void -class_add_method_list (Class* class, MethodList_t list) +class_add_method_list (Class class, MethodList_t list) { int i; static SEL initialize_sel = 0; @@ -346,7 +352,7 @@ class_add_method_list (Class* class, Met if (method->method_name) /* Sometimes these are NULL */ { - /* This is where selector names are transmogriffed to SEL's */ + /* This is where selector names are transmogrified to SEL's */ method->method_name = sel_register_typed_name ((const char*)method->method_name, method->method_types); @@ -370,13 +376,13 @@ class_add_method_list (Class* class, Met Method_t -class_get_instance_method(Class* class, SEL op) +class_get_instance_method(Class class, SEL op) { return search_for_method_in_hierarchy(class, op); } Method_t -class_get_class_method(MetaClass* class, SEL op) +class_get_class_method(MetaClass class, SEL op) { return search_for_method_in_hierarchy(class, op); } @@ -387,10 +393,10 @@ class_get_class_method(MetaClass* class, otherwise. */ static Method_t -search_for_method_in_hierarchy (Class* cls, SEL sel) +search_for_method_in_hierarchy (Class cls, SEL sel) { Method_t method = NULL; - Class* class; + Class class; if (! sel_is_mapped (sel)) return NULL; @@ -470,7 +476,7 @@ __objc_block_forward (id rcv, SEL op, .. } -/* This fuction is installed in the dispatch table for all methods which are +/* This function is installed in the dispatch table for all methods which are not implemented. Thus, it is called when a selector is not recognized. */ static retval_t __objc_forward (id object, SEL sel, arglist_t args)