aboutsummaryrefslogtreecommitdiff
path: root/libobjc
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2010-10-10 17:43:07 +0000
committerNicola Pero <nicola@gcc.gnu.org>2010-10-10 17:43:07 +0000
commite4d508663e3f14ba9b976f45808b1398a534bf2c (patch)
tree31297c7b7c90562ff7778443d3b2187fc4b64092 /libobjc
parente9acb3234d6fe8d8fbbc3f6d94cc2cda45d4b11b (diff)
downloadgcc-e4d508663e3f14ba9b976f45808b1398a534bf2c.zip
gcc-e4d508663e3f14ba9b976f45808b1398a534bf2c.tar.gz
gcc-e4d508663e3f14ba9b976f45808b1398a534bf2c.tar.bz2
In libobjc/: 2010-10-10 Nicola Pero <nicola.pero@meta-innovation.com>
In libobjc/: 2010-10-10 Nicola Pero <nicola.pero@meta-innovation.com> * objc/objc-api.h: Define Method, Method_t, Category and Category_t. Prevent including this file at the same time as objc/runtime.h. Updated comments. * objc/deprecated/struct_objc_method.h: Do not define Method, Method_t. * objc/deprecated/struct_objc_category.h: Do not define Category, Category_t. * objc-private/module-abi-8.h: New file containing a copy of all the structure definitions. Not used yet. * objc/encoding.h (objc_aligned_size): Removed duplicate declaration. Updated comments. * objc/runtime.h: Added Ivar, objc_property_t, Property, Method, Category, struct objc_method_description, _C_ID and similar, _C_CONST and similar and _F_CONST and similar. Added objc_sizeof_type, objc_alignof_type, objc_aligned_size, objc_promoted_size, objc_skip_type_qualifier, objc_skip_typespec, objc_skip_offset, objc_skip_argspec, objc_get_type_qualifiers, struct objc_struct_layout, objc_layout_structure, objc_layout_structure_next_member, objc_layout_finish_structure, objc_layout_structure_get_info. Prevent including this file at the same time as objc/objc-api.h. From-SVN: r165256
Diffstat (limited to 'libobjc')
-rw-r--r--libobjc/ChangeLog24
-rw-r--r--libobjc/objc-private/module-abi-8.h176
-rw-r--r--libobjc/objc/deprecated/struct_objc_category.h4
-rw-r--r--libobjc/objc/deprecated/struct_objc_method.h5
-rw-r--r--libobjc/objc/encoding.h10
-rw-r--r--libobjc/objc/objc-api.h17
-rw-r--r--libobjc/objc/runtime.h201
7 files changed, 422 insertions, 15 deletions
diff --git a/libobjc/ChangeLog b/libobjc/ChangeLog
index 99f09c0..a07be1c 100644
--- a/libobjc/ChangeLog
+++ b/libobjc/ChangeLog
@@ -1,5 +1,29 @@
2010-10-10 Nicola Pero <nicola.pero@meta-innovation.com>
+ * objc/objc-api.h: Define Method, Method_t, Category and
+ Category_t. Prevent including this file at the same time as
+ objc/runtime.h. Updated comments.
+ * objc/deprecated/struct_objc_method.h: Do not define Method,
+ Method_t.
+ * objc/deprecated/struct_objc_category.h: Do not define Category,
+ Category_t.
+ * objc-private/module-abi-8.h: New file containing a copy of all
+ the structure definitions. Not used yet.
+ * objc/encoding.h (objc_aligned_size): Removed duplicate
+ declaration. Updated comments.
+ * objc/runtime.h: Added Ivar, objc_property_t, Property, Method,
+ Category, struct objc_method_description, _C_ID and similar,
+ _C_CONST and similar and _F_CONST and similar. Added
+ objc_sizeof_type, objc_alignof_type, objc_aligned_size,
+ objc_promoted_size, objc_skip_type_qualifier, objc_skip_typespec,
+ objc_skip_offset, objc_skip_argspec, objc_get_type_qualifiers,
+ struct objc_struct_layout, objc_layout_structure,
+ objc_layout_structure_next_member, objc_layout_finish_structure,
+ objc_layout_structure_get_info. Prevent including this file at
+ the same time as objc/objc-api.h.
+
+2010-10-10 Nicola Pero <nicola.pero@meta-innovation.com>
+
* Makefile.in (OBJC_DEPRECATED_H): Added struct_objc_category.h,
struct_objc_ivar.h, struct_objc_ivar_list.h, struct_objc_method.h,
struct_objc_method_list.h, struct_objc_module.h,
diff --git a/libobjc/objc-private/module-abi-8.h b/libobjc/objc-private/module-abi-8.h
new file mode 100644
index 0000000..7296273
--- /dev/null
+++ b/libobjc/objc-private/module-abi-8.h
@@ -0,0 +1,176 @@
+/* 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; /* Unknown. */
+ SEL refs; /* Unknown. */
+ 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. It
+ is a char*. The unique integer passed
+ to objc_msg_send is a char* too. It is
+ compared against method_name using
+ strcmp. */
+ const char* method_types; /* Description of the method's parameter
+ list. Useful for debuggers. */
+ 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. */
+};
+
+struct objc_protocol_list
+{
+ struct objc_protocol_list *next;
+ size_t count;
+ Protocol *list[1];
+};
+
+/* 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/deprecated/struct_objc_category.h b/libobjc/objc/deprecated/struct_objc_category.h
index 2b7a74b..6de3980 100644
--- a/libobjc/objc/deprecated/struct_objc_category.h
+++ b/libobjc/objc/deprecated/struct_objc_category.h
@@ -2,7 +2,7 @@
** The compiler generates one of these structures for each category. A class
** may have many categories and contain both instance and factory methods.
*/
-typedef struct objc_category {
+struct objc_category {
const char* category_name; /* Name of the category. Name
contained in the () of the
category definition. */
@@ -18,4 +18,4 @@ typedef struct objc_category {
class methods defined. */
struct objc_protocol_list *protocols; /* List of Protocols
conformed to */
-} Category, *Category_t;
+};
diff --git a/libobjc/objc/deprecated/struct_objc_method.h b/libobjc/objc/deprecated/struct_objc_method.h
index 10a3b3b..af83c07 100644
--- a/libobjc/objc/deprecated/struct_objc_method.h
+++ b/libobjc/objc/deprecated/struct_objc_method.h
@@ -6,7 +6,7 @@
** and categories can break them across modules. To handle this problem is a
** singly linked list of methods.
*/
-typedef struct objc_method {
+struct objc_method {
SEL method_name; /* This variable is the method's
name. It is a char*.
The unique integer passed to
@@ -18,4 +18,5 @@ typedef struct objc_method {
debuggers. */
IMP method_imp; /* Address of the method in the
executable. */
-} Method, *Method_t;
+};
+
diff --git a/libobjc/objc/encoding.h b/libobjc/objc/encoding.h
index 177ef72..523b129 100644
--- a/libobjc/objc/encoding.h
+++ b/libobjc/objc/encoding.h
@@ -28,6 +28,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#ifndef __encoding_INCLUDE_GNU
#define __encoding_INCLUDE_GNU
+/* This file is to be used with the "traditional" GNU Objective-C
+ Runtime API (the one declared in objc/objc-api.h). If you are
+ using the "modern" GNU Objective-C Runtime API, then the useful
+ functions from this file are declared in objc/runtime.h.
+*/
+
#include "objc-api.h"
#include <ctype.h>
@@ -35,6 +41,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
extern "C" {
#endif /* __cplusplus */
+/* The following are used in encode strings to describe some
+ qualifiers of method and ivar types. */
#define _C_CONST 'r'
#define _C_IN 'n'
#define _C_INOUT 'N'
@@ -44,6 +52,7 @@ extern "C" {
#define _C_ONEWAY 'V'
#define _C_GCINVISIBLE '|'
+/* The same when used as flags. */
#define _F_CONST 0x01
#define _F_IN 0x01
#define _F_OUT 0x02
@@ -53,7 +62,6 @@ extern "C" {
#define _F_ONEWAY 0x10
#define _F_GCINVISIBLE 0x20
-int objc_aligned_size (const char *type);
int objc_sizeof_type (const char *type);
int objc_alignof_type (const char *type);
int objc_aligned_size (const char *type);
diff --git a/libobjc/objc/objc-api.h b/libobjc/objc/objc-api.h
index fb60d591..eced869 100644
--- a/libobjc/objc/objc-api.h
+++ b/libobjc/objc/objc-api.h
@@ -41,11 +41,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
Objective-C Runtime API) or objc/runtime.h (to use the modern GNU
Objective-C Runtime API), but not both.
*/
-/*
#ifdef __objc_runtime_INCLUDE_GNU
# error You can not include both objc/objc-api.h and objc/runtime.h. Include objc/objc-api.h for the traditional GNU Objective-C Runtime API and objc/runtime.h for the modern one.
#endif
-*/
#include "objc.h"
#ifndef GNU_LIBOBJC_COMPILING_LIBOBJC_ITSELF
@@ -71,7 +69,8 @@ struct objc_method_description
char *types; /* type encoding */
};
-/* Filer types used to describe Ivars and Methods. */
+/* The following are used in encode strings to describe the type of
+ Ivars and Methods. */
#define _C_ID '@'
#define _C_CLASS '#'
#define _C_SEL ':'
@@ -103,12 +102,10 @@ struct objc_method_description
#define _C_VECTOR '!'
#define _C_COMPLEX 'j'
-/* The following one is never generated by the compiler. You can
- treat it as equivalent to "*".
-*/
+/* _C_ATOM is never generated by the compiler. You can treat it as
+ equivalent to "*". */
#define _C_ATOM '%'
-
#include "deprecated/objc_error.h"
#include "deprecated/struct_objc_static_instances.h"
@@ -117,6 +114,8 @@ struct objc_method_description
#include "deprecated/struct_objc_ivar.h"
#include "deprecated/struct_objc_ivar_list.h"
#include "deprecated/struct_objc_method.h"
+typedef struct objc_method Method, *Method_t;
+
#include "deprecated/struct_objc_method_list.h"
#include "deprecated/struct_objc_protocol_list.h"
@@ -169,9 +168,11 @@ struct objc_method_description
#include "deprecated/struct_objc_category.h"
+typedef struct objc_category Category, *Category_t;
+
/* We include message.h for compatibility with the old objc-api.h
which included the declarations currently in message.h. The
- Apple/NeXT runtime does not do this and only include message.h in
+ Apple/NeXT runtime does not do this and only includes message.h in
objc-runtime.h. It does not matter that much since most of the
definitions in message.h are runtime-specific. */
#include "message.h"
diff --git a/libobjc/objc/runtime.h b/libobjc/objc/runtime.h
index c46fe67..6f25ec8 100644
--- a/libobjc/objc/runtime.h
+++ b/libobjc/objc/runtime.h
@@ -41,16 +41,112 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
Objective-C Runtime API) or objc/runtime.h (to use the modern GNU
Objective-C Runtime API), but not both.
*/
-/*
#ifdef __objc_api_INCLUDE_GNU
# error You can not include both objc/objc-api.h and objc/runtime.h. Include objc/objc-api.h for the traditional GNU Objective-C Runtime API and objc/runtime.h for the modern one.
#endif
-*/
/* TODO: This file is incomplete. */
#include "objc.h"
+/* An 'Ivar' represents an instance variable. It holds information
+ about the name, type and offset of the instance variable. */
+typedef struct objc_ivar *Ivar;
+
+/* A 'Property' represents a property. It holds information about the
+ name of the property, and its attributes.
+
+ Compatibility Note: the Apple/NeXT runtime defines this as
+ objc_property_t, so we define it that way as well, but obviously
+ Property is the right name. */
+typedef struct objc_property *Property;
+typedef struct objc_property *objc_property_t;
+
+/* A 'Method' represents a method. It holds information about the
+ name, types and the IMP of the method. */
+typedef struct objc_method *Method;
+
+/* A 'Category' represents a category. It holds information about the
+ name of the category, the class it belongs to, and the methods,
+ protocols and such like provided by the category. */
+typedef struct objc_category *Category;
+
+/* 'Protocol' is defined in objc/objc.h (which is included by this
+ file). */
+
+/* Method descriptor returned by introspective Object methods. At the
+ moment, this is really just the first part of the more complete
+ objc_method structure used internally by the runtime. (PS: In the
+ GNU Objective-C Runtime, selectors already include a type, so an
+ objc_method_description does not add much to a SEL. But in other
+ runtimes, that is not the case, which is why
+ objc_method_description exists). */
+struct objc_method_description
+{
+ SEL name; /* Selector (name and signature) */
+ char *types; /* Type encoding */
+};
+
+/* The following are used in encode strings to describe the type of
+ Ivars and Methods. */
+#define _C_ID '@'
+#define _C_CLASS '#'
+#define _C_SEL ':'
+#define _C_CHR 'c'
+#define _C_UCHR 'C'
+#define _C_SHT 's'
+#define _C_USHT 'S'
+#define _C_INT 'i'
+#define _C_UINT 'I'
+#define _C_LNG 'l'
+#define _C_ULNG 'L'
+#define _C_LNG_LNG 'q'
+#define _C_ULNG_LNG 'Q'
+#define _C_FLT 'f'
+#define _C_DBL 'd'
+#define _C_LNG_DBL 'D'
+#define _C_BFLD 'b'
+#define _C_BOOL 'B'
+#define _C_VOID 'v'
+#define _C_UNDEF '?'
+#define _C_PTR '^'
+#define _C_CHARPTR '*'
+#define _C_ARY_B '['
+#define _C_ARY_E ']'
+#define _C_UNION_B '('
+#define _C_UNION_E ')'
+#define _C_STRUCT_B '{'
+#define _C_STRUCT_E '}'
+#define _C_VECTOR '!'
+#define _C_COMPLEX 'j'
+
+/* _C_ATOM is never generated by the compiler. You can treat it as
+ equivalent to "*". */
+#define _C_ATOM '%'
+
+/* The following are used in encode strings to describe some
+ qualifiers of method and ivar types. */
+#define _C_CONST 'r'
+#define _C_IN 'n'
+#define _C_INOUT 'N'
+#define _C_OUT 'o'
+#define _C_BYCOPY 'O'
+#define _C_BYREF 'R'
+#define _C_ONEWAY 'V'
+#define _C_GCINVISIBLE '|'
+
+/* The same when used as flags. */
+#define _F_CONST 0x01
+#define _F_IN 0x01
+#define _F_OUT 0x02
+#define _F_INOUT 0x03
+#define _F_BYCOPY 0x04
+#define _F_BYREF 0x08
+#define _F_ONEWAY 0x10
+#define _F_GCINVISIBLE 0x20
+
+/* TODO: Add all the functions in the API. */
+
/* 'objc_enumerationMutation()' is called when a collection is
mutated while being "fast enumerated". That is a hard error, and
objc_enumerationMutation is called to deal with it. 'collection'
@@ -102,4 +198,105 @@ struct __objcFastEnumerationState
};
*/
+
+/* Traditional GNU Objective-C Runtime functions that are currently
+ used to implement method forwarding.
+*/
+
+/* Return the size of a variable which has the specified 'type'
+ encoding. */
+int objc_sizeof_type (const char *type);
+
+/* Return the align of a variable which has the specified 'type'
+ encoding. */
+int objc_alignof_type (const char *type);
+
+/* Return the aligned size of a variable which has the specified
+ 'type' encoding. The aligned size is the size rounded up to the
+ nearest alignment. */
+int objc_aligned_size (const char *type);
+
+/* Return the promoted size of a variable which has the specified
+ 'type' encoding. This is the size rounded up to the nearest
+ integral of the wordsize, taken to be the size of a void *. */
+int objc_promoted_size (const char *type);
+
+
+/* The following functions are used when parsing the type encoding of
+ methods, to skip over parts that are ignored. They take as
+ argument a pointer to a location inside the type encoding of a
+ method (which is a string) and return a new pointer, pointing to a
+ new location inside the string after having skipped the unwanted
+ information. */
+
+/* Skip some type qualifiers (_C_CONST, _C_IN, etc). These may
+ eventually precede typespecs occurring in method prototype
+ encodings. */
+const char *objc_skip_type_qualifiers (const char *type);
+
+/* Skip one typespec element (_C_CLASS, _C_SEL, etc). If the typespec
+ is prepended by type qualifiers, these are skipped as well. */
+const char *objc_skip_typespec (const char *type);
+
+/* Skip an offset. */
+const char *objc_skip_offset (const char *type);
+
+/* Skip an argument specification (ie, skipping a typespec, which may
+ include qualifiers, and an offset too). */
+const char *objc_skip_argspec (const char *type);
+
+/* Read type qualifiers (_C_CONST, _C_IN, etc) from string 'type'
+ (stopping at the first non-type qualifier found) and return an
+ unsigned int which is the logical OR of all the corresponding flags
+ (_F_CONST, _F_IN etc). */
+unsigned objc_get_type_qualifiers (const char *type);
+
+
+/* Note that the following functions work for very simple structures,
+ but get easily confused by more complicated ones (for example,
+ containing vectors). A better solution is required.
+*/
+
+/* The following three functions can be used to determine how a
+ structure is laid out by the compiler. For example:
+
+ struct objc_struct_layout layout;
+ int i;
+
+ objc_layout_structure (type, &layout);
+ while (objc_layout_structure_next_member (&layout))
+ {
+ int position, align;
+ const char *type;
+
+ objc_layout_structure_get_info (&layout, &position, &align, &type);
+ printf ("element %d has offset %d, alignment %d\n",
+ i++, position, align);
+ }
+
+ These functions are used by objc_sizeof_type and objc_alignof_type
+ functions to compute the size and alignment of structures. The
+ previous method of computing the size and alignment of a structure
+ was not working on some architectures, particulary on AIX, and in
+ the presence of bitfields inside the structure. */
+struct objc_struct_layout
+{
+ const char *original_type;
+ const char *type;
+ const char *prev_type;
+ unsigned int record_size;
+ unsigned int record_align;
+};
+
+void objc_layout_structure (const char *type,
+ struct objc_struct_layout *layout);
+BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout);
+void objc_layout_finish_structure (struct objc_struct_layout *layout,
+ unsigned int *size,
+ unsigned int *align);
+void objc_layout_structure_get_info (struct objc_struct_layout *layout,
+ unsigned int *offset,
+ unsigned int *align,
+ const char **type);
+
#endif