home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gcc-2.4.5 / objc / objc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-23  |  5.8 KB  |  186 lines

  1. /* Basic data types for Objective C.
  2.    Copyright (C) 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* As a special exception, if you link this library with files
  21.    compiled with GCC to produce an executable, this does not cause
  22.    the resulting executable to be covered by the GNU General Public License.
  23.    This exception does not however invalidate any other reasons why
  24.    the executable file might be covered by the GNU General Public License.  */
  25.  
  26. #ifndef __objc_INCLUDE_GNU
  27. #define __objc_INCLUDE_GNU
  28.  
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32.  
  33. #ifdef IN_GCC
  34. #include "gstddef.h"
  35. #else
  36. #include "stddef.h"
  37. #endif
  38.  
  39. /*
  40. ** Definition of the boolean type.  
  41. */
  42. typedef char  BOOL;
  43. #define YES   (BOOL)1
  44. #define NO    (BOOL)0
  45.  
  46. /*
  47. ** Definition of a selector.  Selectors are really of type unsigned int.
  48. ** The runtime does this mapping from SEL's to names internally in the
  49. ** sel_... operations.  You should never use the fact that it is actually
  50. ** an integer, since other Objective-C implementations use other conventions.
  51. */
  52. typedef void* SEL;
  53.  
  54. /*
  55. ** ObjC uses this typedef for untyped instances.
  56. */
  57. typedef struct objc_object {
  58.   struct objc_class*  class_pointer;
  59. } *id;
  60.  
  61. /*
  62. ** Definition of method type.  When retrieving the implementation of a
  63. ** method, this is type of the pointer returned
  64. */
  65. typedef id (*IMP)(id, SEL, ...); 
  66.  
  67. /*
  68. ** More simple types...
  69. */
  70. #define nil (id)0                               /* id of Nil instance */
  71. #define Nil (Class*)0                          /* id of Nil class */
  72. typedef char *STR;                              /* String alias */
  73.  
  74. /*
  75. ** The compiler generates one of these structures for each class.  
  76. ** 
  77. ** This structure is the definition for classes. 
  78. ** 
  79. ** This structure is generated by the compiler in the executable and used by
  80. ** the run-time during normal messaging operations.  Therefore some members
  81. ** change type. The compiler generates "char* const" and places a string in
  82. ** the following member variables:  super_class. 
  83. */
  84. typedef struct objc_class MetaClass;
  85. typedef struct objc_class Class;
  86. struct objc_class {     
  87.   MetaClass*         class_pointer;          /* Pointer to the class's
  88.                                                 meta class. */
  89.   struct objc_class*  super_class;            /* Pointer to the super 
  90.                                                 class. NULL for class 
  91.                                                 Object. */
  92.   const char*         name;                   /* Name of the class. */
  93.   long                version;                /* Unknown. */
  94.   unsigned long       info;                   /* Bit mask.  See class masks 
  95.                                                 defined above. */
  96.   long                instance_size;          /* Size in bytes of the class.  
  97.                                                 The sum of the class definition 
  98.                                                 and all super class 
  99.                                                 definitions. */
  100.   struct objc_ivar_list* ivars;               /* Pointer to a structure that
  101.                                                 describes the instance 
  102.                                                 variables in the class
  103.                                                 definition.  NULL indicates
  104.                                                 no instance variables.  Does
  105.                                                 not include super class
  106.                                                 variables. */
  107.   struct objc_method_list*  methods;          /* Linked list of instance
  108.                                                 methods defined for the 
  109.                                                 class. */
  110.   struct sarray *    dtable;                  /* Pointer to instance 
  111.                              method dispatch table. */  
  112.   struct objc_class* subclass_list;           /* Subclasses */
  113.   struct objc_class* sibling_class;
  114.  
  115.   struct objc_protocol_list *protocols;          /* Protocols conformed to */
  116. };
  117.  
  118. #ifndef __OBJC__
  119. typedef struct objc_protocol {
  120.   struct objc_class* class_pointer;
  121.   char *protocol_name;
  122.   struct objc_protocol_list *protocol_list;
  123.   struct objc_method_description_list *instance_methods, *class_methods; 
  124. } Protocol; 
  125.  
  126. #else
  127.  
  128. @class Protocol;
  129. #endif 
  130.  
  131. typedef void* retval_t;        /* return value */
  132. typedef void(*apply_t)(void);    /* function pointer */
  133.  
  134. #if defined(REG_ARGS) || defined(STACK_ARGS) 
  135.  
  136. typedef struct {
  137.   char* arg_pointer;
  138. #ifdef STRUCT_RETURN
  139.   void* struct_return;
  140. #endif
  141. #ifdef REG_ARGS
  142.   void* regs[2];
  143. #endif
  144. } *arglist_t;
  145.  
  146. #ifdef REG_ARGS
  147. #define __objc_frame_receiver(FRAME)  (FRAME)->regs[0]
  148. #define __objc_frame_selector(FRAME)  ((SEL)(FRAME)->regs[1])
  149.  
  150. #else
  151. #define __objc_frame_receiver(FRAME) ((id*)(FRAME)->arg_pointer)[0]
  152. #define __objc_frame_selector(FRAME) ((SEL*)(FRAME)->arg_pointer)[1]
  153. #endif
  154. #else
  155.  
  156. typedef void* arglist_t;
  157.  
  158. #endif
  159.  
  160. #if defined(__OBJC__) 
  161.  
  162. #include "objc/sarray.h"
  163.  
  164. static id nil_method(id rcv, SEL op, ...) { return rcv; }
  165.  
  166. extern __inline__ IMP
  167. objc_msg_lookup(id receiver, SEL op)
  168. {
  169.   if(receiver)
  170.     return sarray_get(receiver->class_pointer->dtable, (size_t) op);
  171.   else
  172.     return nil_method;
  173. }
  174.  
  175. #else
  176.  
  177. IMP objc_msg_lookup(id receiver, SEL op);
  178.  
  179. #endif
  180.  
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184.  
  185. #endif /* not __objc_INCLUDE_GNU */
  186.