OSDN Git Service

In libobjc/:
[pf3gnuchains/gcc-fork.git] / libobjc / objc / objc-api.h
index d3e22f2..89c5fcd 100644 (file)
@@ -1,46 +1,49 @@
 /* GNU Objective-C Runtime API.
-   Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1993, 1995, 1996, 1997, 2001, 2002, 2003, 2004, 2005,
+   2007, 2009 Free Software Foundation, Inc.
 
-This file is part of GNU CC.
+This file is part of GCC.
 
-GNU CC is free software; you can redistribute it and/or modify it
+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 2, or (at your option) any
+Free Software Foundation; either version 3, or (at your option) any
 later version.
 
-GNU CC is distributed in the hope that it will be useful, but WITHOUT
+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.
 
-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, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+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/>.  */
 
-/* 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 to be covered by the GNU General Public License.  This
-   exception does not however invalidate any other reasons why the
-   executable file might be covered by the GNU General Public License. */
 
 #ifndef __objc_api_INCLUDE_GNU
 #define __objc_api_INCLUDE_GNU
 
-#include "objc/objc.h"
-#include "objc/hash.h"
-#include "objc/thr.h"
+#include "objc.h"
+#include "hash.h"
+#include "thr.h"
+#include "objc-decls.h"
 #include <stdio.h>
 #include <stdarg.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
 /* For functions which return Method_t */
 #define METHOD_NULL    (Method_t)0
                                                 /* Boolean typedefs */
-/*
-** Method descriptor returned by introspective Object methods.
-** This is really just the first part of the more complete objc_method
-** structure defined below and used internally by the runtime.
-*/
+/* Method descriptor returned by introspective Object methods.
+   This is really just the first part of the more complete objc_method
+   structure defined below and used internally by the runtime.  */
 struct objc_method_description
 {
     SEL name;                  /* this is a selector, not a string */
@@ -64,6 +67,7 @@ struct objc_method_description
 #define _C_FLT      'f'
 #define _C_DBL      'd'
 #define _C_BFLD     'b'
+#define _C_BOOL            'B'
 #define _C_VOID     'v'
 #define _C_UNDEF    '?'
 #define _C_PTR      '^'
@@ -75,67 +79,11 @@ struct objc_method_description
 #define _C_UNION_E  ')'
 #define _C_STRUCT_B '{'
 #define _C_STRUCT_E '}'
+#define _C_VECTOR   '!'
+#define _C_COMPLEX   'j'
 
 
-/*
-** Error handling
-**
-** Call objc_error() or objc_verror() to record an error; this error
-** routine will generally exit the program but not necessarily if the
-** user has installed his own error handler.
-**
-** Call objc_set_error_handler to assign your own function for
-** handling errors.  The function should return YES if it is ok
-** to continue execution, or return NO or just abort if the
-** program should be stopped.  The default error handler is just to
-** print a message on stderr.
-**
-** The error handler function should be of type objc_error_handler
-** The first parameter is an object instance of relevance.
-** The second parameter is an error code.
-** The third parameter is a format string in the printf style.
-** The fourth parameter is a variable list of arguments.
-*/
-extern void objc_error(id object, int code, const char* fmt, ...);
-extern void objc_verror(id object, int code, const char* fmt, va_list ap);
-typedef BOOL (*objc_error_handler)(id, int code, const char *fmt, va_list ap);
-objc_error_handler objc_set_error_handler(objc_error_handler func);
-
-/*
-** Error codes
-** These are used by the runtime library, and your
-** error handling may use them to determine if the error is
-** hard or soft thus whether execution can continue or abort.
-*/
-#define OBJC_ERR_UNKNOWN 0             /* Generic error */
-
-#define OBJC_ERR_OBJC_VERSION 1        /* Incorrect runtime version */
-#define OBJC_ERR_GCC_VERSION 2         /* Incorrect compiler version */
-#define OBJC_ERR_MODULE_SIZE 3         /* Bad module size */
-#define OBJC_ERR_PROTOCOL_VERSION 4    /* Incorrect protocol version */
-
-#define OBJC_ERR_MEMORY 10             /* Out of memory */
-
-#define OBJC_ERR_RECURSE_ROOT 20       /* Attempt to archive the root
-                                         object more than once. */
-#define OBJC_ERR_BAD_DATA 21           /* Didn't read expected data */
-#define OBJC_ERR_BAD_KEY 22            /* Bad key for object */
-#define OBJC_ERR_BAD_CLASS 23          /* Unknown class */
-#define OBJC_ERR_BAD_TYPE 24           /* Bad type specification */
-#define OBJC_ERR_NO_READ 25            /* Cannot read stream */
-#define OBJC_ERR_NO_WRITE 26           /* Cannot write stream */
-#define OBJC_ERR_STREAM_VERSION 27     /* Incorrect stream version */
-#define OBJC_ERR_BAD_OPCODE 28         /* Bad opcode */
-
-#define OBJC_ERR_UNIMPLEMENTED 30      /* Method is not implemented */
-
-#define OBJC_ERR_BAD_STATE 40          /* Bad thread state */
-
-/*
-** Set this variable nonzero to print a line describing each
-** message that is sent.  (this is currently disabled)
-*/
-extern BOOL objc_trace;
+#include "deprecated/objc_error.h"
 
 
 /* For every class which happens to have statically allocated instances in
@@ -145,17 +93,19 @@ extern BOOL objc_trace;
 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. 
-*/
+/* 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.   */
 typedef struct objc_symtab {
   unsigned long sel_ref_cnt;                     /* Unknown. */
   SEL        refs;                              /* Unknown. */
@@ -184,18 +134,18 @@ typedef struct objc_symtab {
 ** That array holds a pointer to each module structure of the executable. 
 */
 typedef struct objc_module {
-  unsigned long version;                        /* Compiler revision. */
-  unsigned long size;                           /* sizeof(Module). */
-  const char* name;                             /* Name of the file where the 
-                                                  module was generated.   The 
-                                                  name includes the path. */
-
-  Symtab_t    symtab;                           /* Pointer to the Symtab of
-                                                  the module.  The Symtab
-                                                  holds an array of 
-                                                 pointers to 
-                                                  the classes and categories 
-                                                  defined in the 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.  */
+  Symtab_t    symtab;    /* Pointer to the Symtab of the module.  The
+                           Symtab holds an array of pointers to the
+                           classes and categories defined in the
+                           module. */
 } Module, *Module_t;
 
 
@@ -203,14 +153,7 @@ typedef struct objc_module {
 ** The compiler generates one of these structures for a class that has
 ** instance variables defined in its specification. 
 */
-typedef struct objc_ivar* Ivar_t;
-typedef 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 {
+typedef struct objc_ivar {
     const char* ivar_name;                      /* Name of the instance
                                                   variable as entered in the
                                                   class definition. */
@@ -220,8 +163,15 @@ typedef struct objc_ivar_list {
     int        ivar_offset;                    /* Byte offset from the base 
                                                   address of the instance 
                                                   structure to the variable. */
+} *Ivar_t;
 
-  } ivar_list[1];                               /* Variable length 
+typedef 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. */
 } IvarList, *IvarList_t;
 
@@ -234,33 +184,33 @@ typedef struct objc_ivar_list {
 ** and categories can break them across modules. To handle this problem is a
 ** singly linked list of methods. 
 */
-typedef struct objc_method Method;
-typedef Method* Method_t;
+typedef 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. */
+} Method, *Method_t;
+
 typedef 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 {
-    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. */
-  } method_list[1];                           /* Variable length 
-                                                structure. */
+  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. */
+  Method method_list[1];                    /* Variable length 
+                                               structure. */
 } MethodList, *MethodList_t;
 
 struct objc_protocol_list {
   struct objc_protocol_list *next;
-  int count;
+  size_t count;
   Protocol *list[1];
 };
 
@@ -341,7 +291,11 @@ typedef struct objc_category {
 typedef struct objc_super {
   id      self;                           /* Id of the object sending
                                                 the message. */
+#ifdef __cplusplus
+  Class super_class;
+#else
   Class class;                              /* Object's super class. */
+#endif
 } Super, *Super_t;
 
 IMP objc_msg_lookup_super(Super_t super, SEL sel);
@@ -356,7 +310,7 @@ retval_t objc_msg_sendv(id, SEL, arglist_t);
 ** This may e.g. try to load in the class using dynamic loading.
 ** The function is guaranteed to be passed a non-NULL name string.
 */
-extern Class (*_objc_lookup_class)(const char *name);
+objc_EXPORT Class (*_objc_lookup_class)(const char *name);
 
 /*
 ** This is a hook which is called by __objc_exec_class every time a class
@@ -364,14 +318,14 @@ extern Class (*_objc_lookup_class)(const char *name);
 ** dynamic loader determine the classes that have been loaded when
 ** an object file is dynamically linked in.
 */
-extern void (*_objc_load_callback)(Class class, Category* category);
+objc_EXPORT void (*_objc_load_callback)(Class _class, Category* category);
 
 /*
 ** Hook functions for allocating, copying and disposing of instances
 */
-extern id (*_objc_object_alloc)(Class class);
-extern id (*_objc_object_copy)(id object);
-extern id (*_objc_object_dispose)(id object);
+objc_EXPORT id (*_objc_object_alloc)(Class _class);
+objc_EXPORT id (*_objc_object_copy)(id object);
+objc_EXPORT id (*_objc_object_dispose)(id object);
 
 /*
 ** Standard functions for memory allocation and disposal.
@@ -407,23 +361,28 @@ objc_free(void *mem);
 ** Users should call the normal objc routines above for
 ** memory allocation and disposal within their programs.
 */
-extern void *(*_objc_malloc)(size_t);
-extern void *(*_objc_atomic_malloc)(size_t);
-extern void *(*_objc_valloc)(size_t);
-extern void *(*_objc_realloc)(void *, size_t);
-extern void *(*_objc_calloc)(size_t, size_t);
-extern void (*_objc_free)(void *);
+objc_EXPORT void *(*_objc_malloc)(size_t);
+objc_EXPORT void *(*_objc_atomic_malloc)(size_t);
+objc_EXPORT void *(*_objc_valloc)(size_t);
+objc_EXPORT void *(*_objc_realloc)(void *, size_t);
+objc_EXPORT void *(*_objc_calloc)(size_t, size_t);
+objc_EXPORT void (*_objc_free)(void *);
 
 /*
-**  Hook for method forwarding. This makes it easy to substitute a
+**  Hooks for method forwarding. This makes it easy to substitute a
 **  library, such as ffcall, that implements closures, thereby avoiding
-**  gcc's __builtin_apply problems.
+**  gcc's __builtin_apply problems.  __objc_msg_forward2's result will
+**  be preferred over that of __objc_msg_forward if both are set and
+**  return non-NULL.
 */
-extern IMP (*__objc_msg_forward)(SEL);
+objc_EXPORT IMP (*__objc_msg_forward)(SEL);
+objc_EXPORT IMP (*__objc_msg_forward2)(id, SEL);
+
+#include "deprecated/objc_unexpected_exception.h"
 
-Method_t class_get_class_method(MetaClass class, SEL aSel);
+Method_t class_get_class_method(MetaClass _class, SEL aSel);
 
-Method_t class_get_instance_method(Class class, SEL aSel);
+Method_t class_get_instance_method(Class _class, SEL aSel);
 
 Class class_pose_as(Class impostor, Class superclass);
 
@@ -452,66 +411,66 @@ SEL sel_register_typed_name(const char *name, const char*type);
 
 BOOL sel_is_mapped (SEL aSel);
 
-extern id class_create_instance(Class class);
+extern id class_create_instance(Class _class);
 
 static inline const char *
-class_get_class_name(Class class)
+class_get_class_name(Class _class)
 {
-  return CLS_ISCLASS(class)?class->name:((class==Nil)?"Nil":0);
+  return CLS_ISCLASS(_class)?_class->name:((_class==Nil)?"Nil":0);
 }
 
 static inline long
-class_get_instance_size(Class class)
+class_get_instance_size(Class _class)
 {
-  return CLS_ISCLASS(class)?class->instance_size:0;
+  return CLS_ISCLASS(_class)?_class->instance_size:0;
 }
 
 static inline MetaClass
-class_get_meta_class(Class class)
+class_get_meta_class(Class _class)
 {
-  return CLS_ISCLASS(class)?class->class_pointer:Nil;
+  return CLS_ISCLASS(_class)?_class->class_pointer:Nil;
 }
 
 static inline Class
-class_get_super_class(Class class)
+class_get_super_class(Class _class)
 {
-  return CLS_ISCLASS(class)?class->super_class:Nil;
+  return CLS_ISCLASS(_class)?_class->super_class:Nil;
 }
 
 static inline int
-class_get_version(Class class)
+class_get_version(Class _class)
 {
-  return CLS_ISCLASS(class)?class->version:-1;
+  return CLS_ISCLASS(_class)?_class->version:-1;
 }
 
 static inline BOOL
-class_is_class(Class class)
+class_is_class(Class _class)
 {
-  return CLS_ISCLASS(class);
+  return CLS_ISCLASS(_class);
 }
 
 static inline BOOL
-class_is_meta_class(Class class)
+class_is_meta_class(Class _class)
 {
-  return CLS_ISMETA(class);
+  return CLS_ISMETA(_class);
 }
 
 
 static inline void
-class_set_version(Class class, long version)
+class_set_version(Class _class, long version)
 {
-  if (CLS_ISCLASS(class))
-    class->version = version;
+  if (CLS_ISCLASS(_class))
+    _class->version = version;
 }
 
 static inline void *
-class_get_gc_object_type (Class class)
+class_get_gc_object_type (Class _class)
 {
-  return CLS_ISCLASS(class) ? class->gc_object_type : NULL;
+  return CLS_ISCLASS(_class) ? _class->gc_object_type : NULL;
 }
 
 /* Mark the instance variable as innaccessible to the garbage collector */
-extern void class_ivar_set_gcinvisible (Class class,
+extern void class_ivar_set_gcinvisible (Class _class,
                                        const char* ivarname,
                                        BOOL gcInvisible);
 
@@ -521,13 +480,7 @@ method_get_imp(Method_t method)
   return (method!=METHOD_NULL)?method->method_imp:(IMP)0;
 }
 
-IMP get_imp (Class class, SEL sel);
-
-/* Redefine on NeXTSTEP so as not to conflict with system function */
-#ifdef __NeXT__
-#define object_copy    gnu_object_copy
-#define object_dispose gnu_object_dispose
-#endif
+IMP get_imp (Class _class, SEL sel);
 
 id object_copy(id object);
 
@@ -578,26 +531,32 @@ object_get_super_class
 }
 
 static inline BOOL
-object_is_class(id object)
+object_is_class (id object)
 {
-  return CLS_ISCLASS((Class)object);
+  return ((object != nil)  &&  CLS_ISMETA (object->class_pointer));
 }
-
 static inline BOOL
-object_is_instance(id object)
+object_is_instance (id object)
 {
-  return (object!=nil)&&CLS_ISCLASS(object->class_pointer);
+  return ((object != nil)  &&  CLS_ISCLASS (object->class_pointer));
 }
 
 static inline BOOL
-object_is_meta_class(id object)
+object_is_meta_class (id object)
 {
-  return CLS_ISMETA((Class)object);
+  return ((object != nil)
+         &&  !object_is_instance (object)  
+         &&  !object_is_class (object));
 }
 
 struct sarray* 
 objc_get_uninstalled_dtable(void);
 
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
 #endif /* not __objc_api_INCLUDE_GNU */