diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libobjc/objc-private | |
download | cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.tar.bz2 cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libobjc/objc-private')
-rw-r--r-- | libobjc/objc-private/README | 4 | ||||
-rw-r--r-- | libobjc/objc-private/accessors.h | 32 | ||||
-rw-r--r-- | libobjc/objc-private/common.h | 49 | ||||
-rw-r--r-- | libobjc/objc-private/error.h | 38 | ||||
-rw-r--r-- | libobjc/objc-private/hash.h | 201 | ||||
-rw-r--r-- | libobjc/objc-private/module-abi-8.h | 315 | ||||
-rw-r--r-- | libobjc/objc-private/objc-list.h | 94 | ||||
-rw-r--r-- | libobjc/objc-private/objc-sync.h | 33 | ||||
-rw-r--r-- | libobjc/objc-private/protocols.h | 38 | ||||
-rw-r--r-- | libobjc/objc-private/runtime.h | 79 | ||||
-rw-r--r-- | libobjc/objc-private/sarray.h | 243 | ||||
-rw-r--r-- | libobjc/objc-private/selector.h | 57 |
12 files changed, 1183 insertions, 0 deletions
diff --git a/libobjc/objc-private/README b/libobjc/objc-private/README new file mode 100644 index 000000000..cce1d0416 --- /dev/null +++ b/libobjc/objc-private/README @@ -0,0 +1,4 @@ +This directory contains headers that are private to the runtime and +that are only included while the runtime is being compiled. They are +not installed, so developers using the library can't actually even see +them. diff --git a/libobjc/objc-private/accessors.h b/libobjc/objc-private/accessors.h new file mode 100644 index 000000000..570ae7a85 --- /dev/null +++ b/libobjc/objc-private/accessors.h @@ -0,0 +1,32 @@ +/* GNU Objective C Runtime accessors - Private Declarations + Copyright (C) 2010 Free Software Foundation, Inc. + Contributed by Nicola Pero <nicola.pero@meta-innovation.com> + +This file is part of GCC. + +GCC 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 3, or (at your option) any later version. + +GCC 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_private_accessors_INCLUDE_GNU +#define __objc_private_accessors_INCLUDE_GNU + +/* This function needs to be called at startup by init.c. */ +void +__objc_accessors_init (void); + +#endif /* not __objc_private_accessors_INCLUDE_GNU */ diff --git a/libobjc/objc-private/common.h b/libobjc/objc-private/common.h new file mode 100644 index 000000000..4f4ec5cd0 --- /dev/null +++ b/libobjc/objc-private/common.h @@ -0,0 +1,49 @@ +/* GNU Objective C Runtime Common Private Definitions + Copyright (C) 2010 Free Software Foundation, Inc. + Contributed by Nicola Pero + +This file is part of GCC. + +GCC 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 3, or (at your option) any later version. + +GCC 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_private_common_INCLUDE_GNU +#define __objc_private_common_INCLUDE_GNU + +/* This file contains definitions that should be included by all .c + and .m files in libobjc. */ + +/* This variable allows the public headers to determine when they are + being included by a file inside libobjc itself, or when they are + being included by an external file. */ +#define GNU_LIBOBJC_COMPILING_LIBOBJC_ITSELF 1 + +/* When debugging libobjc, add + + #define DEBUG 1 + + at the very beginning of a file in libobjc (before including this file) to turn + on DEBUG_PRINTF(). */ +#ifdef DEBUG +#include <stdio.h> +#define DEBUG_PRINTF(format, args...) printf (format, ## args) +#else +#define DEBUG_PRINTF(format, args...) +#endif + +#endif /* __objc_private_common_INCLUDE_GNU */ diff --git a/libobjc/objc-private/error.h b/libobjc/objc-private/error.h new file mode 100644 index 000000000..e8673f722 --- /dev/null +++ b/libobjc/objc-private/error.h @@ -0,0 +1,38 @@ +/* GNU Objective C Runtime Common Private Definitions + Copyright (C) 2010 Free Software Foundation, Inc. + Contributed by Nicola Pero + +This file is part of GCC. + +GCC 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 3, or (at your option) any later version. + +GCC 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_private_error_INCLUDE_GNU +#define __objc_private_error_INCLUDE_GNU + +/* Prints an unrecoverable error to stderr, then aborts the program. + This should only be used for errors that really are unrecorevable: + failure to allocate memory, and failure to load an Objective-C + module. All other usages of this function should be converted into + some milder type of error (unless aborting is explicitly required + by the documentation/API). +*/ +void +_objc_abort (const char *fmt, ...) __attribute__ ((noreturn)); + +#endif /* __objc_private_error_INCLUDE_GNU */ diff --git a/libobjc/objc-private/hash.h b/libobjc/objc-private/hash.h new file mode 100644 index 000000000..c330d618e --- /dev/null +++ b/libobjc/objc-private/hash.h @@ -0,0 +1,201 @@ +/* Hash tables for Objective C method dispatch. + Copyright (C) 1993, 1995, 1996, 2004, 2009 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC 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 3, or (at your option) +any later version. + +GCC 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +/* You need to include this file after including objc.h */ + +#ifndef __hash_INCLUDE_GNU +#define __hash_INCLUDE_GNU + +#include <stddef.h> +#include <string.h> + +/* + * This data structure is used to hold items + * stored in a hash table. Each node holds + * a key/value pair. + * + * Items in the cache are really of type void *. + */ +typedef struct cache_node +{ + struct cache_node *next; /* Pointer to next entry on the list. + NULL indicates end of list. */ + const void *key; /* Key used to locate the value. Used + to locate value when more than one + key computes the same hash + value. */ + void *value; /* Value stored for the key. */ +} *node_ptr; + + +/* + * This data type is the function that computes a hash code given a key. + * Therefore, the key can be a pointer to anything and the function specific + * to the key type. + * + * Unfortunately there is a mutual data structure reference problem with this + * typedef. Therefore, to remove compiler warnings the functions passed to + * objc_hash_new will have to be casted to this type. + */ +typedef unsigned int (*hash_func_type) (void *, const void *); + +/* + * This data type is the function that compares two hash keys and returns an + * integer greater than, equal to, or less than 0, according as the first + * parameter is lexicographically greater than, equal to, or less than the + * second. + */ + +typedef int (*compare_func_type) (const void *, const void *); + + +/* + * This data structure is the cache. + * + * It must be passed to all of the hashing routines + * (except for new). + */ +typedef struct cache +{ + /* Variables used to implement the hash itself. */ + node_ptr *node_table; /* Pointer to an array of hash nodes. */ + /* Variables used to track the size of the hash table so to determine + when to resize it. */ + unsigned int size; /* Number of buckets allocated for the hash table + (number of array entries allocated for + "node_table"). Must be a power of two. */ + unsigned int used; /* Current number of entries in the hash table. */ + unsigned int mask; /* Precomputed mask. */ + + /* Variables used to implement indexing through the hash table. */ + + unsigned int last_bucket; /* Tracks which entry in the array where + the last value was returned. */ + /* Function used to compute a hash code given a key. + This function is specified when the hash table is created. */ + hash_func_type hash_func; + /* Function used to compare two hash keys to see if they are equal. */ + compare_func_type compare_func; +} *cache_ptr; + + +/* Allocate and initialize a hash table. */ + +cache_ptr objc_hash_new (unsigned int size, + hash_func_type hash_func, + compare_func_type compare_func); + +/* Deallocate all of the hash nodes and the cache itself. */ + +void objc_hash_delete (cache_ptr cache); + +/* Add the key/value pair to the hash table. If the + hash table reaches a level of fullness then it will be resized. + + assert if the key is already in the hash. */ + +void objc_hash_add (cache_ptr *cachep, const void *key, void *value); + +/* Remove the key/value pair from the hash table. + assert if the key isn't in the table. */ + +void objc_hash_remove (cache_ptr cache, const void *key); + +/* Used to index through the hash table. Start with NULL + to get the first entry. + + Successive calls pass the value returned previously. + ** Don't modify the hash during this operation *** + + Cache nodes are returned such that key or value can + be extracted. */ + +node_ptr objc_hash_next (cache_ptr cache, node_ptr node); + +/* Used to return a value from a hash table using a given key. */ + +void *objc_hash_value_for_key (cache_ptr cache, const void *key); + +/* Used to determine if the given key exists in the hash table */ + +BOOL objc_hash_is_key_in_hash (cache_ptr cache, const void *key); + +/************************************************ + + Useful hashing functions. + + Declared inline for your pleasure. + +************************************************/ + +/* Calculate a hash code by performing some + manipulation of the key pointer. (Use the lowest bits + except for those likely to be 0 due to alignment.) */ + +static inline unsigned int +objc_hash_ptr (cache_ptr cache, const void *key) +{ + return ((size_t)key / sizeof (void *)) & cache->mask; +} + + +/* Calculate a hash code by iterating over a NULL + terminate string. */ +static inline unsigned int +objc_hash_string (cache_ptr cache, const void *key) +{ + unsigned int ret = 0; + unsigned int ctr = 0; + const char *ckey = (const char *) key; + + while (*ckey) { + ret ^= *ckey++ << ctr; + ctr = (ctr + 1) % sizeof (void *); + } + + return ret & cache->mask; +} + + +/* Compare two pointers for equality. */ +static inline int +objc_compare_ptrs (const void *k1, const void *k2) +{ + return (k1 == k2); +} + + +/* Compare two strings. */ +static inline int +objc_compare_strings (const void *k1, const void *k2) +{ + if (k1 == k2) + return 1; + else if (k1 == 0 || k2 == 0) + return 0; + else + return ! strcmp ((const char *) k1, (const char *) k2); +} + +#endif /* not __hash_INCLUDE_GNU */ diff --git a/libobjc/objc-private/module-abi-8.h b/libobjc/objc-private/module-abi-8.h new file mode 100644 index 000000000..0c9574bb4 --- /dev/null +++ b/libobjc/objc-private/module-abi-8.h @@ -0,0 +1,315 @@ +/* Definitions of Module Structures used by ABI version 8 + Copyright (C) 1993, 1995, 1996, 1997, 2001, 2002, 2003, 2004, 2005, + 2007, 2009, 2010 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC 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 3, or (at your option) any later version. + +GCC 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_private_module_abi_8_INCLUDE_GNU +#define __objc_private_module_abi_8_INCLUDE_GNU + +/* For every class which happens to have statically allocated instances in + this module, one OBJC_STATIC_INSTANCES is allocated by the compiler. + INSTANCES is NULL terminated and points to all statically allocated + instances of this class. */ +struct objc_static_instances +{ + char *class_name; +#ifdef __cplusplus + id instances[1]; +#else + id instances[0]; +#endif +}; + +/* Whereas a Module (defined further down) is the root (typically) of a file, + a Symtab is the root of the class and category definitions within the + module. + + A Symtab contains a variable length array of pointers to classes and + categories defined in the module. */ +struct objc_symtab +{ + unsigned long sel_ref_cnt; /* Unused (always set to 0). */ + struct objc_selector *refs; /* The table of selectors referenced in + this module. This is terminated by a + selector with NULL sel_id and NULL + sel_types. Note that we use the type + 'struct objc_selector *' and not + 'SEL' (which is 'const struct + objc_selector *') because the sel_id + of these selectors is patched up by + the runtime when the module is + loaded. */ + unsigned short cls_def_cnt; /* Number of classes compiled (defined) + in the module. */ + unsigned short cat_def_cnt; /* Number of categories compiled + (defined) in the module. */ + void *defs[1]; /* Variable array of pointers. + cls_def_cnt of type Class followed by + cat_def_cnt of type Category_t, + followed by a NULL terminated array + of objc_static_instances. */ +}; + +/* The compiler generates one of these structures for each module that + composes the executable (eg main.m). + + This data structure is the root of the definition tree for the + module. + + A collect program runs between ld stages and creates a ObjC ctor + array. That array holds a pointer to each module structure of the + executable. */ +struct objc_module +{ + unsigned long version; /* Version of the Module data + structure. */ + unsigned long size; /* sizeof(Module) according to the + compiler - only used to sanity check + that it matches sizeof(Module) + according to the runtime. */ + const char* name; /* Name of the file used to compile the + module - not set by modern compilers + for security reasons. */ + struct objc_symtab *symtab; /* Pointer to the Symtab of the module. + The Symtab holds an array of pointers + to the classes and categories defined + in the module. */ +}; + +/* The compiler generates one of these structures for a class that has + instance variables defined in its specification. */ +struct objc_ivar +{ + const char* ivar_name; /* Name of the instance variable as entered + in the class definition. */ + const char* ivar_type; /* Description of the Ivar's type. Useful + for debuggers. */ + int ivar_offset; /* Byte offset from the base address of the + instance structure to the variable. */ +}; + +struct objc_ivar_list +{ + int ivar_count; /* Number of structures (Ivar) + contained in the list. One + structure per instance variable + defined in the class. */ + struct objc_ivar ivar_list[1]; /* Variable length structure. */ +}; + +/* The compiler generates one (or more) of these structures for a + class that has methods defined in its specification. + + The implementation of a class can be broken into separate pieces in + a file and categories can break them across modules. To handle this + problem is a singly linked list of methods. */ +struct objc_method +{ + SEL method_name; /* This variable is the method's name. + The compiler puts a char* here, and + it's replaced by a real SEL at runtime + when the method is registered. */ + const char* method_types; /* Description of the method's parameter + list. Used when registering the + selector with the runtime. When that + happens, method_name will contain the + method's parameter list. */ + IMP method_imp; /* Address of the method in the + executable. */ +}; + +struct objc_method_list +{ + struct objc_method_list* method_next; /* This variable is used to + link a method list to + another. It is a singly + linked list. */ + int method_count; /* Number of methods defined + in this structure. */ + struct objc_method method_list[1]; /* Variable length + structure. */ +}; + +/* Currently defined in Protocol.m (that definition should go away + once we include this file). Note that a 'struct + objc_method_description' as embedded inside a Protocol uses the + same trick as a 'struct objc_method': the method_name is a 'char *' + according to the compiler, who puts the method name as a string in + there. At runtime, the selectors need to be registered, and the + method_name then becomes a SEL. */ +struct objc_method_description_list +{ + int count; + struct objc_method_description list[1]; +}; + +/* Currently defined by objc/objc.h. */ +/* +struct objc_protocol { + struct objc_class* class_pointer; + char *protocol_name; + struct objc_protocol_list *protocol_list; + struct objc_method_description_list *instance_methods, *class_methods; +}; +*/ + +struct objc_protocol_list +{ + struct objc_protocol_list *next; + size_t count; + Protocol *list[1]; +}; + +/* + The compiler generates one of these structures for each class. + + This structure is the definition for classes. + + This structure is generated by the compiler in the executable and + used by the run-time during normal messaging operations. Therefore + some members change type. The compiler generates "char* const" and + places a string in the following member variables: super_class. +*/ +#ifndef __objc_STRUCT_OBJC_CLASS_defined +struct objc_class { + struct objc_class* class_pointer; /* Pointer to the class's meta + class. */ + struct objc_class* super_class; /* Pointer to the super + class. NULL for class + Object. */ + const char* name; /* Name of the class. */ + long version; /* Unknown. */ + unsigned long info; /* Bit mask. See class masks + defined below. */ + long instance_size; /* Size in bytes of the class. + The sum of the class + definition and all super + class definitions. */ +#ifdef _WIN64 + /* We pad the structure manually to prevent warning when -Wpadded is + used. The compiler automatically pads the structures that it + generates, so this manually padded structure still matches the + one generated by the compiler, but if we don't pad manually, + -Wpadded detects that padding is being added and generates + annoying warnings. This hack is necessary as on LLP64 targets + sizeof (long) isn't equal to sizeof (void *). */ + long pad; +#endif + struct objc_ivar_list* ivars; /* Pointer to a structure that + describes the instance + variables in the class + definition. NULL indicates + no instance variables. + Does not include super + class variables. */ + struct objc_method_list* methods; /* Linked list of instance + methods defined for the + class. */ + struct sarray * dtable; /* Pointer to instance method + dispatch table. */ + struct objc_class* subclass_list; /* Subclasses */ + struct objc_class* sibling_class; + + struct objc_protocol_list *protocols; /* Protocols conformed to */ + void* gc_object_type; +}; +#endif /* __objc_STRUCT_OBJC_CLASS_defined */ + +/* This is used to assure consistent access to the info field of + classes. */ +#ifndef HOST_BITS_PER_LONG +# define HOST_BITS_PER_LONG (sizeof(long)*8) +#endif + +#define __CLS_INFO(cls) ((cls)->info) +#define __CLS_ISINFO(cls, mask) ((__CLS_INFO(cls)&mask)==mask) +#define __CLS_SETINFO(cls, mask) (__CLS_INFO(cls) |= mask) +#define __CLS_SETNOTINFO(cls, mask) (__CLS_INFO(cls) &= ~mask) + +/* The structure is of type MetaClass */ +#define _CLS_META 0x2L +#define CLS_ISMETA(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_META)) + +/* The structure is of type Class */ +#define _CLS_CLASS 0x1L +#define CLS_ISCLASS(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_CLASS)) + +/* The class is initialized within the runtime. This means that it + has had correct super and sublinks assigned. */ +#define _CLS_RESOLV 0x8L +#define CLS_ISRESOLV(cls) __CLS_ISINFO(cls, _CLS_RESOLV) +#define CLS_SETRESOLV(cls) __CLS_SETINFO(cls, _CLS_RESOLV) + +/* The class has been send a +initialize message or a such is not + defined for this class. */ +#define _CLS_INITIALIZED 0x04L +#define CLS_ISINITIALIZED(cls) __CLS_ISINFO(cls, _CLS_INITIALIZED) +#define CLS_SETINITIALIZED(cls) __CLS_SETINFO(cls, _CLS_INITIALIZED) + +/* The class is being constructed; it has been allocated using + objc_allocateClassPair(), but has not been registered yet by using + objc_registerClassPair(). This means it is possible to freely add + instance variables to the class, but it can't be used for anything + yet. */ +#define _CLS_IN_CONSTRUCTION 0x10L +#define CLS_IS_IN_CONSTRUCTION(cls) __CLS_ISINFO(cls, _CLS_IN_CONSTRUCTION) +#define CLS_SET_IN_CONSTRUCTION(cls) __CLS_SETINFO(cls, _CLS_IN_CONSTRUCTION) +#define CLS_SET_NOT_IN_CONSTRUCTION(cls) __CLS_SETNOTINFO(cls, _CLS_IN_CONSTRUCTION) + +/* The class number of this class. This must be the same for both the + class and its meta class object. */ +#define CLS_GETNUMBER(cls) (__CLS_INFO(cls) >> (HOST_BITS_PER_LONG/2)) +#define CLS_SETNUMBER(cls, num) \ + ({ (cls)->info <<= (HOST_BITS_PER_LONG/2); \ + (cls)->info >>= (HOST_BITS_PER_LONG/2); \ + __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); }) + + +/* The compiler generates one of these structures for each category. + A class may have many categories and contain both instance and + factory methods. */ +struct objc_category +{ + const char* category_name; /* Name of the category. + Name contained in the + () of the category + definition. */ + const char* class_name; /* Name of the class to + which the category + belongs. */ + struct objc_method_list *instance_methods; /* Linked list of + instance methods + defined in the + category. NULL + indicates no instance + methods defined. */ + struct objc_method_list *class_methods; /* Linked list of + factory methods + defined in the + category. NULL + indicates no class + methods defined. */ + struct objc_protocol_list *protocols; /* List of Protocols + conformed to. */ +}; + +#endif /* __objc_private_module_abi_8_INCLUDE_GNU */ diff --git a/libobjc/objc-private/objc-list.h b/libobjc/objc-private/objc-list.h new file mode 100644 index 000000000..989b9c9d4 --- /dev/null +++ b/libobjc/objc-private/objc-list.h @@ -0,0 +1,94 @@ +/* Generic single linked list to keep various information + Copyright (C) 1993, 1994, 1996, 2009, 2010 Free Software Foundation, Inc. + Contributed by Kresten Krab Thorup. + +This file is part of GCC. + +GCC 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 3, or (at your option) +any later version. + +GCC 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __GNU_OBJC_LIST_H +#define __GNU_OBJC_LIST_H + +struct objc_list +{ + void *head; + struct objc_list *tail; +}; + +/* Return a cons cell produced from (head . tail). */ +static inline struct objc_list* +list_cons (void* head, struct objc_list* tail) +{ + struct objc_list* cell; + + cell = (struct objc_list*)objc_malloc (sizeof (struct objc_list)); + cell->head = head; + cell->tail = tail; + return cell; +} + +/* Remove the element at the head by replacing it by its + successor. */ +static inline void +list_remove_head (struct objc_list** list) +{ + if ((*list)->tail) + { + /* Fetch next. */ + struct objc_list* tail = (*list)->tail; + + /* Copy next to list head. */ + *(*list) = *tail; + + /* Free next. */ + objc_free (tail); + } + else + { + /* Inly one element in list. */ + objc_free (*list); + (*list) = 0; + } +} + + +/* Map FUNCTION over all elements in LIST. */ +static inline void +list_mapcar (struct objc_list* list, void(*function)(void*)) +{ + while (list) + { + (*function) (list->head); + list = list->tail; + } +} + +/* Free list (backwards recursive). */ +static inline void +list_free (struct objc_list* list) +{ + if(list) + { + list_free (list->tail); + objc_free (list); + } +} + +#endif /* not __GNU_OBJC_LIST_H */ diff --git a/libobjc/objc-private/objc-sync.h b/libobjc/objc-private/objc-sync.h new file mode 100644 index 000000000..95eb28b30 --- /dev/null +++ b/libobjc/objc-private/objc-sync.h @@ -0,0 +1,33 @@ +/* GNU Objective C Runtime @synchronized implementation - Private functions + Copyright (C) 2010 Free Software Foundation, Inc. + Contributed by Nicola Pero <nicola.pero@meta-innovation.com> + +This file is part of GCC. + +GCC 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 3, or (at your option) any later version. + +GCC 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_private_objc_sync_INCLUDE_GNU +#define __objc_private_objc_sync_INCLUDE_GNU + +/* This function needs to be called at startup before @synchronized() + can be used. */ +void +__objc_sync_init (void); + +#endif /* not __objc_private_objc_sync_INCLUDE_GNU */ diff --git a/libobjc/objc-private/protocols.h b/libobjc/objc-private/protocols.h new file mode 100644 index 000000000..87f8fc848 --- /dev/null +++ b/libobjc/objc-private/protocols.h @@ -0,0 +1,38 @@ +/* GNU Objective C Runtime protocols - Private functions + Copyright (C) 2010 Free Software Foundation, Inc. + Contributed by Nicola Pero <nicola.pero@meta-innovation.com> + +This file is part of GCC. + +GCC 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 3, or (at your option) any later version. + +GCC 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_private_protocols_INCLUDE_GNU +#define __objc_private_protocols_INCLUDE_GNU + +/* This function needs to be called at startup by init.c. */ +void +__objc_protocols_init (void); + +/* This function adds a protocol to the internal hashtable of + protocols by name, which allows objc_getProtocol(name) to be + implemented efficiently. */ +void +__objc_protocols_add_protocol (const char *name, Protocol *object); + +#endif /* not __objc_private_protocols_INCLUDE_GNU */ diff --git a/libobjc/objc-private/runtime.h b/libobjc/objc-private/runtime.h new file mode 100644 index 000000000..5406294f2 --- /dev/null +++ b/libobjc/objc-private/runtime.h @@ -0,0 +1,79 @@ +/* GNU Objective C Runtime internal declarations + Copyright (C) 1993, 1995, 1996, 1997, 2002, 2004, 2009 Free Software Foundation, Inc. + Contributed by Kresten Krab Thorup + +This file is part of GCC. + +GCC 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 3, or (at your option) any later version. + +GCC 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +/* You need to include this file after including a number of standard ObjC files. + +The original list was: + +#include "objc/objc.h" +#include "objc/objc-api.h" +#include "objc/thr.h" +#include "objc/hash.h" +#include "objc/objc-list.h" + +but can almost certainly be shrinked down. + +Note that you can use this file both with objc/objc-api.h and with +objc/runtime.h. */ + +#ifndef __objc_private_runtime_INCLUDE_GNU +#define __objc_private_runtime_INCLUDE_GNU + +#include <stdarg.h> /* for varargs and va_list's */ + +#include <stdio.h> +#include <ctype.h> + +#include <stddef.h> /* so noone else will get system versions */ +#include <assert.h> + +extern BOOL __objc_add_class_to_hash (Class); /* (objc-class.c) */ +extern void __objc_init_class_tables (void); /* (objc-class.c) */ +extern void __objc_init_dispatch_tables (void); /* (objc-dispatch.c) */ +extern void __objc_install_premature_dtable (Class); /* (objc-dispatch.c) */ +extern void __objc_resolve_class_links (void); /* (objc-class.c) */ +extern void __objc_update_dispatch_table_for_class (Class);/* (objc-msg.c) */ + +extern int __objc_init_thread_system (void); /* thread.c */ +extern int __objc_fini_thread_system (void); /* thread.c */ +extern BOOL __objc_init_class (Class class); /* init.c */ +extern void class_add_method_list (Class, struct objc_method_list *); + +/* Registering instance methods as class methods for root classes */ +extern void __objc_register_instance_methods_to_class (Class); +extern struct objc_method * search_for_method_in_list (struct objc_method_list * list, SEL op); + +extern void +__objc_update_classes_with_methods (struct objc_method *method_a, struct objc_method *method_b); /* class.c */ + +/* Mutex locking __objc_selector_max_index and its arrays. */ +extern objc_mutex_t __objc_runtime_mutex; + +/* Number of threads which are alive. */ +extern int __objc_runtime_threads_alive; + +BOOL __objc_responds_to (id object, SEL sel); /* for internal use only! */ +extern void __objc_generate_gc_type_description (Class); + +#endif /* not __objc_private_runtime_INCLUDE_GNU */ diff --git a/libobjc/objc-private/sarray.h b/libobjc/objc-private/sarray.h new file mode 100644 index 000000000..12fad921f --- /dev/null +++ b/libobjc/objc-private/sarray.h @@ -0,0 +1,243 @@ +/* Sparse Arrays for Objective C dispatch tables + Copyright (C) 1993, 1995, 1996, 2004, 2009, 2010 Free Software Foundation, Inc. + Contributed by Kresten Krab Thorup. + +This file is part of GCC. + +GCC 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 3, or (at your option) +any later version. + +GCC 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __sarray_INCLUDE_GNU +#define __sarray_INCLUDE_GNU + +#define OBJC_SPARSE2 /* 2-level sparse array. */ +/* #define OBJC_SPARSE3 */ /* 3-level sparse array. */ + +#ifdef OBJC_SPARSE2 +extern const char* __objc_sparse2_id; +#endif + +#ifdef OBJC_SPARSE3 +extern const char* __objc_sparse3_id; +#endif + +#include <stddef.h> + +extern int nbuckets; /* for stats */ +extern int nindices; +extern int narrays; +extern int idxsize; + +/* An unsigned integer of same size as a pointer. */ +#define SIZET_BITS (sizeof (size_t) * 8) + +#if defined (__sparc__) || defined (OBJC_SPARSE2) +#define PRECOMPUTE_SELECTORS +#endif + +#ifdef OBJC_SPARSE3 + +/* Buckets are 8 words each. */ +#define BUCKET_BITS 3 +#define BUCKET_SIZE (1 << BUCKET_BITS) +#define BUCKET_MASK (BUCKET_SIZE - 1) + +/* Indices are 16 words each. */ +#define INDEX_BITS 4 +#define INDEX_SIZE (1 << INDEX_BITS) +#define INDEX_MASK (INDEX_SIZE - 1) + +#define INDEX_CAPACITY (BUCKET_SIZE * INDEX_SIZE) + +#else /* OBJC_SPARSE2 */ + +/* Buckets are 32 words each. */ +#define BUCKET_BITS 5 +#define BUCKET_SIZE (1 << BUCKET_BITS) +#define BUCKET_MASK (BUCKET_SIZE - 1) + +#endif /* OBJC_SPARSE2 */ + +typedef size_t sidx; + +#ifdef PRECOMPUTE_SELECTORS + +struct soffset +{ +#ifdef OBJC_SPARSE3 + unsigned int unused : SIZET_BITS / 4; + unsigned int eoffset : SIZET_BITS / 4; + unsigned int boffset : SIZET_BITS / 4; + unsigned int ioffset : SIZET_BITS / 4; +#else /* OBJC_SPARSE2 */ +#ifdef __sparc__ + unsigned long boffset : (SIZET_BITS - 2) - BUCKET_BITS; + unsigned int eoffset : BUCKET_BITS; + unsigned int unused : 2; +#else + unsigned int boffset : SIZET_BITS / 2; + unsigned int eoffset : SIZET_BITS / 2; +#endif +#endif /* OBJC_SPARSE2 */ +}; + +union sofftype +{ + struct soffset off; + sidx idx; +}; + +#endif /* not PRECOMPUTE_SELECTORS */ + +union sversion +{ + int version; + void *next_free; +}; + +struct sbucket +{ + /* Elements stored in array. */ + void* elems[BUCKET_SIZE]; + + /* Used for copy-on-write. */ + union sversion version; +}; + +#ifdef OBJC_SPARSE3 + +struct sindex +{ + struct sbucket* buckets[INDEX_SIZE]; + + /* Used for copy-on-write. */ + union sversion version; +}; + +#endif /* OBJC_SPARSE3 */ + +struct sarray +{ +#ifdef OBJC_SPARSE3 + struct sindex** indices; + struct sindex* empty_index; +#else /* OBJC_SPARSE2 */ + struct sbucket** buckets; +#endif /* OBJC_SPARSE2 */ + struct sbucket* empty_bucket; + + /* Used for copy-on-write. */ + union sversion version; + + short ref_count; + struct sarray* is_copy_of; + size_t capacity; +}; + +struct sarray* sarray_new (int, void* default_element); +void sarray_free (struct sarray*); +struct sarray* sarray_lazy_copy (struct sarray*); +void sarray_realloc (struct sarray*, int new_size); +void sarray_at_put (struct sarray*, sidx indx, void* elem); +void sarray_at_put_safe (struct sarray*, sidx indx, void* elem); + +struct sarray* sarray_hard_copy (struct sarray*); /* ... like the name ? */ +void sarray_remove_garbage (void); + + +#ifdef PRECOMPUTE_SELECTORS +/* Transform soffset values to ints and vice versa. */ +static inline unsigned int +soffset_decode (sidx indx) +{ + union sofftype x; + x.idx = indx; +#ifdef OBJC_SPARSE3 + return x.off.eoffset + + (x.off.boffset * BUCKET_SIZE) + + (x.off.ioffset * INDEX_CAPACITY); +#else /* OBJC_SPARSE2 */ + return x.off.eoffset + (x.off.boffset * BUCKET_SIZE); +#endif /* OBJC_SPARSE2 */ +} + +static inline sidx +soffset_encode (size_t offset) +{ + union sofftype x; + x.off.eoffset = offset % BUCKET_SIZE; +#ifdef OBJC_SPARSE3 + x.off.boffset = (offset / BUCKET_SIZE) % INDEX_SIZE; + x.off.ioffset = offset / INDEX_CAPACITY; +#else /* OBJC_SPARSE2 */ + x.off.boffset = offset / BUCKET_SIZE; +#endif + return (sidx)x.idx; +} + +#else /* not PRECOMPUTE_SELECTORS */ + +static inline size_t +soffset_decode (sidx indx) +{ + return indx; +} + +static inline sidx +soffset_encode (size_t offset) +{ + return offset; +} +#endif /* not PRECOMPUTE_SELECTORS */ + +/* Get element from the Sparse array `array' at offset `indx'. */ +static inline void* sarray_get (struct sarray* array, sidx indx) +{ +#ifdef PRECOMPUTE_SELECTORS + union sofftype x; + x.idx = indx; +#ifdef OBJC_SPARSE3 + return array-> + indices[x.off.ioffset]-> + buckets[x.off.boffset]-> + elems[x.off.eoffset]; +#else /* OBJC_SPARSE2 */ + return array->buckets[x.off.boffset]->elems[x.off.eoffset]; +#endif /* OBJC_SPARSE2 */ +#else /* not PRECOMPUTE_SELECTORS */ +#ifdef OBJC_SPARSE3 + return array-> + indices[indx / INDEX_CAPACITY]-> + buckets[(indx / BUCKET_SIZE) % INDEX_SIZE]-> + elems[indx % BUCKET_SIZE]; +#else /* OBJC_SPARSE2 */ + return array->buckets[indx / BUCKET_SIZE]->elems[indx % BUCKET_SIZE]; +#endif /* not OBJC_SPARSE3 */ +#endif /* not PRECOMPUTE_SELECTORS */ +} + +static inline void* sarray_get_safe (struct sarray* array, sidx indx) +{ + if (soffset_decode (indx) < array->capacity) + return sarray_get (array, indx); + else + return (array->empty_bucket->elems[0]); +} + +#endif /* __sarray_INCLUDE_GNU */ diff --git a/libobjc/objc-private/selector.h b/libobjc/objc-private/selector.h new file mode 100644 index 000000000..490e17105 --- /dev/null +++ b/libobjc/objc-private/selector.h @@ -0,0 +1,57 @@ +/* GNU Objective C Runtime selector implementation - Private functions + Copyright (C) 2010 Free Software Foundation, Inc. + Contributed by Nicola Pero <nicola.pero@meta-innovation.com> + +This file is part of GCC. + +GCC 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 3, or (at your option) any later version. + +GCC 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_private_selector_INCLUDE_GNU +#define __objc_private_selector_INCLUDE_GNU + +/* Private runtime functions that may go away or be rewritten or + replaced. */ + +/* Number of selectors stored in each of the selector tables. */ +extern unsigned int __objc_selector_max_index; + +/* Initialize the selector tables. This must be called by init.c. */ +void __objc_init_selector_tables(void); + +/* Various private functions to register selectors. */ +void __objc_register_selectors_from_class(Class); +void __objc_register_selectors_from_list (struct objc_method_list *); +void __objc_register_selectors_from_description_list +(struct objc_method_description_list *method_list); +void __objc_register_selectors_from_module (struct objc_selector *selectors); + +/* Return whether a selector is mapped or not ("mapped" meaning that + it has been inserted into the selector table). This is private as + only the runtime should ever encounter or need to know about + unmapped selectors. */ +BOOL sel_is_mapped (SEL aSel); + +/* Return selector representing name without registering it if it + doesn't exist. Typically used internally by the runtime when it's + looking up methods that may or may not exist (such as +initialize) + in the most efficient way. */ +SEL +sel_get_any_uid (const char *name); + +#endif /* not __objc_private_selector_INCLUDE_GNU */ |