| 1 | /* GNU Objective C Runtime selector related functions
|
|---|
| 2 | Copyright (C) 1993, 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
|
|---|
| 3 | Contributed by Kresten Krab Thorup
|
|---|
| 4 |
|
|---|
| 5 | This file is part of GNU CC.
|
|---|
| 6 |
|
|---|
| 7 | GNU CC is free software; you can redistribute it and/or modify it under the
|
|---|
| 8 | terms of the GNU General Public License as published by the Free Software
|
|---|
| 9 | Foundation; either version 2, or (at your option) any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|---|
| 12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|---|
| 13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|---|
| 14 | details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License along with
|
|---|
| 17 | GNU CC; see the file COPYING. If not, write to the Free Software
|
|---|
| 18 | Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 19 |
|
|---|
| 20 | /* As a special exception, if you link this library with files compiled with
|
|---|
| 21 | GCC to produce an executable, this does not cause the resulting executable
|
|---|
| 22 | to be covered by the GNU General Public License. This exception does not
|
|---|
| 23 | however invalidate any other reasons why the executable file might be
|
|---|
| 24 | covered by the GNU General Public License. */
|
|---|
| 25 |
|
|---|
| 26 | #include "runtime.h"
|
|---|
| 27 | #include "sarray.h"
|
|---|
| 28 | #include "encoding.h"
|
|---|
| 29 |
|
|---|
| 30 | /* Initial selector hash table size. Value doesn't matter much */
|
|---|
| 31 | #define SELECTOR_HASH_SIZE 128
|
|---|
| 32 |
|
|---|
| 33 | /* Tables mapping selector names to uid and opposite */
|
|---|
| 34 | static struct sarray *__objc_selector_array = 0; /* uid -> sel !T:MUTEX */
|
|---|
| 35 | static struct sarray *__objc_selector_names = 0; /* uid -> name !T:MUTEX */
|
|---|
| 36 | static cache_ptr __objc_selector_hash = 0; /* name -> uid !T:MUTEX */
|
|---|
| 37 |
|
|---|
| 38 | static void register_selectors_from_list (MethodList_t);
|
|---|
| 39 |
|
|---|
| 40 | /* Number of selectors stored in each of the above tables */
|
|---|
| 41 | unsigned int __objc_selector_max_index = 0; /* !T:MUTEX */
|
|---|
| 42 |
|
|---|
| 43 | void __objc_init_selector_tables ()
|
|---|
| 44 | {
|
|---|
| 45 | __objc_selector_array = sarray_new (SELECTOR_HASH_SIZE, 0);
|
|---|
| 46 | __objc_selector_names = sarray_new (SELECTOR_HASH_SIZE, 0);
|
|---|
| 47 | __objc_selector_hash
|
|---|
| 48 | = hash_new (SELECTOR_HASH_SIZE,
|
|---|
| 49 | (hash_func_type) hash_string,
|
|---|
| 50 | (compare_func_type) compare_strings);
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | /* This routine is given a class and records all of the methods in its class
|
|---|
| 54 | structure in the record table. */
|
|---|
| 55 | void
|
|---|
| 56 | __objc_register_selectors_from_class (Class class)
|
|---|
| 57 | {
|
|---|
| 58 | MethodList_t method_list;
|
|---|
| 59 |
|
|---|
| 60 | method_list = class->methods;
|
|---|
| 61 | while (method_list)
|
|---|
| 62 | {
|
|---|
| 63 | register_selectors_from_list (method_list);
|
|---|
| 64 | method_list = method_list->method_next;
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | /* This routine is given a list of methods and records each of the methods in
|
|---|
| 70 | the record table. This is the routine that does the actual recording
|
|---|
| 71 | work.
|
|---|
| 72 |
|
|---|
| 73 | This one is only called for Class objects. For categories,
|
|---|
| 74 | class_add_method_list is called.
|
|---|
| 75 | */
|
|---|
| 76 | static void
|
|---|
| 77 | register_selectors_from_list (MethodList_t method_list)
|
|---|
| 78 | {
|
|---|
|
|---|