home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Headers / objc / objc-class.h < prev    next >
Text File  |  1996-12-19  |  7KB  |  285 lines

  1. /*
  2.  *    objc-class.h
  3.  *    Copyright 1988-1996, NeXT Software, Inc.
  4.  */
  5.  
  6. #ifndef _OBJC_CLASS_H_
  7. #define _OBJC_CLASS_H_
  8.  
  9. #import <objc/objc.h>
  10. #import <objc/zone.h>
  11. /* 
  12.  *    Class Template
  13.  */
  14. struct objc_class {            
  15.     struct objc_class *isa;    
  16.     struct objc_class *super_class;    
  17.     const char *name;        
  18.     long version;
  19.     long info;
  20.     long instance_size;
  21.     struct objc_ivar_list *ivars;
  22.  
  23. #if defined(Release3CompatibilityBuild)
  24.     struct objc_method_list *methods;
  25. #else
  26.     struct objc_method_list **methodLists;
  27. #endif
  28.  
  29.     struct objc_cache *cache;
  30.      struct objc_protocol_list *protocols;
  31. };
  32. #define CLS_GETINFO(cls,infomask)    ((cls)->info & infomask)
  33. #define CLS_SETINFO(cls,infomask)    ((cls)->info |= infomask)
  34.  
  35. #define CLS_CLASS        0x1L
  36. #define CLS_META        0x2L
  37. #define CLS_INITIALIZED        0x4L
  38. #define CLS_POSING        0x8L
  39. #define CLS_MAPPED        0x10L
  40. #define CLS_FLUSH_CACHE        0x20L
  41. #define CLS_GROW_CACHE        0x40L
  42. #define CLS_METHOD_ARRAY        0x100L
  43. /* 
  44.  *    Category Template
  45.  */
  46. typedef struct objc_category *Category;
  47.  
  48. struct objc_category {
  49.     char *category_name;
  50.     char *class_name;
  51.     struct objc_method_list *instance_methods;
  52.     struct objc_method_list *class_methods;
  53.      struct objc_protocol_list *protocols;
  54. };
  55. /* 
  56.  *    Instance Variable Template
  57.  */
  58. typedef struct objc_ivar *Ivar;
  59.  
  60. struct objc_ivar_list {
  61.     int ivar_count;
  62. #ifdef __alpha__
  63.     int space;
  64. #endif
  65.     struct objc_ivar {
  66.         char *ivar_name;
  67.         char *ivar_type;
  68.         int ivar_offset;
  69. #ifdef __alpha__
  70.         int space;
  71. #endif
  72.     } ivar_list[1];            /* variable length structure */
  73. };
  74.  
  75. OBJC_EXPORT Ivar object_setInstanceVariable(id, const char *name, void *);
  76. OBJC_EXPORT Ivar object_getInstanceVariable(id, const char *name, void **);
  77.  
  78. /* 
  79.  *    Method Template
  80.  */
  81. typedef struct objc_method *Method;
  82.  
  83. struct objc_method_list {
  84. #if defined(Release3CompatibilityBuild)
  85.         struct objc_method_list *method_next;
  86. #else
  87.     struct objc_method_list *obsolete;
  88. #endif
  89.  
  90.     int method_count;
  91. #ifdef __alpha__
  92.     int space;
  93. #endif
  94.     struct objc_method {
  95.         SEL method_name;
  96.         char *method_types;
  97.                 IMP method_imp;
  98.     } method_list[1];        /* variable length structure */
  99. };
  100.  
  101. /* Protocol support */
  102.  
  103. @class Protocol;
  104.  
  105. struct objc_protocol_list {
  106.     struct objc_protocol_list *next;
  107.     int count;
  108.     Protocol *list[1];
  109. };
  110.  
  111. /* Definitions of filer types */
  112.  
  113. #define _C_ID        '@'
  114. #define _C_CLASS    '#'
  115. #define _C_SEL        ':'
  116. #define _C_CHR        'c'
  117. #define _C_UCHR        'C'
  118. #define _C_SHT        's'
  119. #define _C_USHT        'S'
  120. #define _C_INT        'i'
  121. #define _C_UINT        'I'
  122. #define _C_LNG        'l'
  123. #define _C_ULNG        'L'
  124. #define _C_FLT        'f'
  125. #define _C_DBL        'd'
  126. #define _C_BFLD        'b'
  127. #define _C_VOID        'v'
  128. #define _C_UNDEF    '?'
  129. #define _C_PTR        '^'
  130. #define _C_CHARPTR    '*'
  131. #define _C_ARY_B    '['
  132. #define _C_ARY_E    ']'
  133. #define _C_UNION_B    '('
  134. #define _C_UNION_E    ')'
  135. #define _C_STRUCT_B    '{'
  136. #define _C_STRUCT_E    '}'
  137.  
  138. /* Structure for method cache - allocated/sized at runtime */
  139.  
  140. typedef struct objc_cache *Cache;
  141.  
  142. #ifdef OBJC_COPY_CACHE
  143.  
  144. #define CACHE_BUCKET_NAME(B)  ((B).method_name)
  145. #define CACHE_BUCKET_IMP(B)   ((B).method_imp)
  146. #define CACHE_BUCKET_VALID(B) ((B).method_name)
  147. struct objc_cache_bucket {
  148.   SEL method_name;
  149.   IMP method_imp;
  150. };
  151.  
  152. struct objc_cache {
  153.     unsigned int mask;            /* total = mask + 1 */
  154.     unsigned int occupied;        
  155.     struct objc_cache_bucket buckets[1];
  156. };
  157.  
  158. #else
  159.  
  160. #define CACHE_BUCKET_NAME(B)  ((B)->method_name)
  161. #define CACHE_BUCKET_IMP(B)   ((B)->method_imp)
  162. #define CACHE_BUCKET_VALID(B) (B)
  163. struct objc_cache {
  164.     unsigned int mask;            /* total = mask + 1 */
  165.     unsigned int occupied;        
  166.     Method buckets[1];
  167. };
  168. #endif
  169.  
  170. /* operations */
  171.  
  172. OBJC_EXPORT id class_createInstance(Class, unsigned idxIvars);
  173. OBJC_EXPORT id class_createInstanceFromZone(Class, unsigned idxIvars, NXZone *zone);
  174.  
  175. OBJC_EXPORT void class_setVersion(Class, int);
  176. OBJC_EXPORT int class_getVersion(Class);
  177.  
  178. OBJC_EXPORT Ivar class_getInstanceVariable(Class, const char *);
  179. OBJC_EXPORT Method class_getInstanceMethod(Class, SEL);
  180. OBJC_EXPORT Method class_getClassMethod(Class, SEL);
  181.  
  182. OBJC_EXPORT void class_addMethods(Class, struct objc_method_list *);
  183. OBJC_EXPORT void class_removeMethods(Class, struct objc_method_list *);
  184.  
  185. OBJC_EXPORT Class class_poseAs(Class imposter, Class original);
  186.  
  187. OBJC_EXPORT unsigned method_getNumberOfArguments(Method);
  188. OBJC_EXPORT unsigned method_getSizeOfArguments(Method);
  189. OBJC_EXPORT unsigned method_getArgumentInfo(Method m, int arg, const char **type, int *offset);
  190. OBJC_EXPORT const char * NSModulePathForClass (Class aClass);
  191.  
  192. // usage for nextMethodList
  193. //
  194. // void *iterator = 0;
  195. // struct objc_method_list *mlist;
  196. // while ( mlist = class_nextMethodList( cls, &iterator ) )
  197. //    ;
  198. #define OBJC_NEXT_METHOD_LIST 1
  199. OBJC_EXPORT struct objc_method_list *class_nextMethodList(Class, void **);
  200.  
  201. typedef void *marg_list;
  202.  
  203. #if hppa
  204.  
  205. #define marg_malloc(margs, method) \
  206.     do { \
  207.         unsigned int _sz = (7 + method_getSizeOfArguments(method)) & ~7; \
  208.         char *_ml = (char *)malloc(_sz + sizeof(marg_list)); \
  209.         void    **_z ; \
  210.         margs = (marg_list *)(_ml + _sz); \
  211.         _z = margs; \
  212.         *_z = (marg_list)_ml; \
  213.     } while (0)
  214.  
  215. #define marg_free(margs) \
  216.     do { \
  217.         void    **_z = margs; \
  218.         free(*_z); \
  219.     } while (0)
  220.     
  221. #define marg_adjustedOffset(method, offset) \
  222.     ( (!offset) ? -(sizeof(id)) : offset)
  223.  
  224. #else
  225.  
  226. #define marg_malloc(margs, method) \
  227.     do { \
  228.         margs = (marg_list *)malloc ((7 + method_getSizeOfArguments(method)) & ~7); \
  229.     } while (0)
  230.  
  231.  
  232. #define marg_free(margs) \
  233.     do { \
  234.         free(margs); \
  235.     } while (0)
  236.     
  237. #define marg_adjustedOffset(method, offset) \
  238.     (offset)
  239.  
  240. #endif /* hppa */
  241.  
  242.  
  243. #define marg_getRef(margs, offset, type) \
  244.     ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
  245.  
  246. #define marg_getValue(margs, offset, type) \
  247.     ( *marg_getRef(margs, offset, type) )
  248.  
  249. #define marg_setValue(margs, offset, type, value) \
  250.     ( marg_getValue(margs, offset, type) = (value) )
  251.  
  252. /* Load categories and non-referenced classes from libraries. */
  253. #if defined(NeXT_PDO)
  254. #if defined(hpux)
  255.  
  256. #define OBJC_REGISTER_SYMBOL(NAME) asm("._" #NAME "=0\n .globl ._" #NAME "\n")
  257. #define OBJC_REFERENCE_SYMBOL(NAME) asm(".word ._" #NAME "\n")
  258. #define OBJC_REGISTER_CATEGORY(NAME) asm("._" #NAME "=0\n .globl ._" #NAME "\n")
  259. #define OBJC_REFERENCE_CATEGORY(NAME) asm(".word ._" #NAME "\n")
  260. #define OBJC_REFERENCE_CLASS_CATEGORY(CL, CAT) asm(".word .objc_category_name_" #CL "_" #CAT "\n")
  261. #define OBJC_REFERENCE_CLASS(NAME) asm(".word .objc_class_name_" #NAME "\n")
  262.  
  263. #elif defined(__osf__)
  264.  
  265. #define OBJC_REGISTER_SYMBOL(NAME) asm(".globl ._" #NAME "\n\t.align 3\n._" #NAME ":\n\t.quad 0\n")
  266. #define OBJC_REFERENCE_SYMBOL(NAME) asm(".align 3\n\t.quad ._" #NAME "\n")
  267. #define OBJC_REGISTER_CATEGORY(NAME) asm(".globl ._" #NAME "\n\t.align 3\n._" #NAME ":\n\t.quad 0\n")
  268. #define OBJC_REFERENCE_CATEGORY(NAME) asm(".align 3\n\t.quad ._" #NAME "\n")
  269. #define OBJC_REFERENCE_CLASS_CATEGORY(CL, CAT) asm(".align 3\n\t.quad .objc_category_name_" #CL "_" #CAT "\n")
  270. #define OBJC_REFERENCE_CLASS(NAME) asm(".quad .objc_class_name_" #NAME "\n")
  271.  
  272. #else    /* Solaris || SunOS */
  273.  
  274. #define OBJC_REGISTER_SYMBOL(NAME) asm("._" #NAME "=0\n .globl ._" #NAME "\n")
  275. #define OBJC_REFERENCE_SYMBOL(NAME) asm(".global ._" #NAME "\n")
  276. #define OBJC_REGISTER_CATEGORY(NAME) asm("._" #NAME "=0\n .globl ._" #NAME "\n")
  277. #define OBJC_REFERENCE_CATEGORY(NAME) asm(".global ._" #NAME "\n")
  278. #define OBJC_REFERENCE_CLASS_CATEGORY(CL, CAT) asm(".global .objc_category_name_" #CL "_" #CAT "\n")
  279. #define OBJC_REFERENCE_CLASS(NAME) asm(".global .objc_class_name_" #NAME "\n")
  280.  
  281. #endif /* hpux */
  282. #endif /* NeXT_PDO */
  283.  
  284. #endif /* _OBJC_CLASS_H_ */
  285.