Annotation of GNUtools/cc/objc/objc-api.h, revision 1.1.1.1

1.1       root        1: /* GNU Objective-C Runtime API.
                      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 it
                      7: under the terms of the GNU General Public License as published by the
                      8: Free Software Foundation; either version 2, or (at your option) any
                      9: later version.
                     10: 
                     11: GNU CC is distributed in the hope that it will be useful, but WITHOUT
                     12: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     13: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
                     14: 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 compiled
                     21:    with GCC to produce an executable, this does not cause the resulting
                     22:    executable to be covered by the GNU General Public License.  This
                     23:    exception does not however invalidate any other reasons why the
                     24:    executable file might be covered by the GNU General Public License. */
                     25: 
                     26: #ifndef __objc_api_INCLUDE_GNU
                     27: #define __objc_api_INCLUDE_GNU
                     28: 
                     29: #include "objc/objc.h"
                     30: #include "objc/hash.h"
                     31: #include <stdio.h>
                     32: 
                     33: /* For functions which return Method_t */
                     34: #define METHOD_NULL    (Method_t)0
                     35:                                                 /* Boolean typedefs */
                     36: /*
                     37: ** Method descriptor returned by introspective Object methods.
                     38: ** This is really just the first part of the more complete objc_method
                     39: ** structure defined below and used internally by the runtime.
                     40: */
                     41: struct objc_method_description
                     42: {
                     43:     SEL name;                  /* this is a selector, not a string */
                     44:     char *types;               /* type encoding */
                     45: };
                     46: 
                     47: 
                     48: 
                     49: /* Filer types used to describe Ivars and Methods.  */
                     50: #define _C_ID       '@'
                     51: #define _C_CLASS    '#'
                     52: #define _C_SEL      ':'
                     53: #define _C_CHR      'c'
                     54: #define _C_UCHR     'C'
                     55: #define _C_SHT      's'
                     56: #define _C_USHT     'S'
                     57: #define _C_INT      'i'
                     58: #define _C_UINT     'I'
                     59: #define _C_LNG      'l'
                     60: #define _C_ULNG     'L'
                     61: #define _C_FLT      'f'
                     62: #define _C_DBL      'd'
                     63: #define _C_BFLD     'b'
                     64: #define _C_VOID     'v'
                     65: #define _C_UNDEF    '?'
                     66: #define _C_PTR      '^'
                     67: #define _C_CHARPTR  '*'
                     68: #define _C_ATOM     '%'
                     69: #define _C_ARY_B    '['
                     70: #define _C_ARY_E    ']'
                     71: #define _C_UNION_B  '('
                     72: #define _C_UNION_E  ')'
                     73: #define _C_STRUCT_B '{'
                     74: #define _C_STRUCT_E '}'
                     75: 
                     76: 
                     77: 
                     78: /*
                     79: ** Set this variable nonzero to print a line describing each
                     80: ** message that is sent.  (this is currently disabled)
                     81: */
                     82: extern BOOL objc_trace;
                     83: 
                     84: 
                     85: /*
                     86: ** Whereas a Module (defined further down) is the root (typically) of a file,
                     87: ** a Symtab is the root of the class and category definitions within the
                     88: ** module.  
                     89: ** 
                     90: ** A Symtab contains a variable length array of pointers to classes and
                     91: ** categories  defined in the module. 
                     92: */
                     93: typedef struct objc_symtab {
                     94:   unsigned long sel_ref_cnt;                     /* Unknown. */
                     95:   SEL       *refs;                              /* Unknown. */
                     96:   unsigned short cls_def_cnt;                   /* Number of classes compiled
                     97:                                                   (defined) in the module. */
                     98:   unsigned short cat_def_cnt;                   /* Number of categories 
                     99:                                                   compiled (defined) in the 
                    100:                                                   module. */
                    101:   void      *defs[1];                           /* Variable array of pointers.
                    102:                                                   cls_def_cnt of type Class* 
                    103:                                                   followed by cat_def_cnt of
                    104:                                                   type Category_t. */
                    105: } Symtab,   *Symtab_t;
                    106: 
                    107: 
                    108: /*
                    109: ** The compiler generates one of these structures for each module that
                    110: ** composes the executable (eg main.m).  
                    111: ** 
                    112: ** This data structure is the root of the definition tree for the module.  
                    113: ** 
                    114: ** A collect program runs between ld stages and creates a ObjC ctor array. 
                    115: ** That array holds a pointer to each module structure of the executable. 
                    116: */
                    117: typedef struct objc_module {
                    118:   unsigned long version;                        /* Compiler revision. */
                    119:   unsigned long size;                           /* sizeof(Module). */
                    120:   const char* name;                             /* Name of the file where the 
                    121:                                                   module was generated.   The 
                    122:                                                   name includes the path. */
                    123:   Symtab_t    symtab;                           /* Pointer to the Symtab of
                    124:                                                   the module.  The Symtab
                    125:                                                   holds an array of pointers to 
                    126:                                                   the classes and categories 
                    127:                                                   defined in the module. */
                    128: } Module, *Module_t;
                    129: 
                    130: 
                    131: /*
                    132: ** The compiler generates one of these structures for a class that has
                    133: ** instance variables defined in its specification. 
                    134: */
                    135: typedef struct objc_ivar* Ivar_t;
                    136: typedef struct objc_ivar_list {
                    137:   int   ivar_count;                             /* Number of structures (Ivar) 
                    138:                                                   contained in the list.  One
                    139:                                                   structure per instance 
                    140:                                                   variable defined in the
                    141:                                                   class. */
                    142:   struct objc_ivar {
                    143:     const char* ivar_name;                      /* Name of the instance
                    144:                                                   variable as entered in the
                    145:                                                   class definition. */
                    146:     const char* ivar_type;                      /* Description of the Ivar's
                    147:                                                   type.  Useful for 
                    148:                                                   debuggers. */
                    149:     int        ivar_offset;                    /* Byte offset from the base 
                    150:                                                   address of the instance 
                    151:                                                   structure to the variable. */
                    152: 
                    153:   } ivar_list[1];                               /* Variable length 
                    154:                                                   structure. */
                    155: } IvarList, *IvarList_t;
                    156: 
                    157: 
                    158: /*
                    159: ** The compiler generates one (or more) of these structures for a class that
                    160: ** has methods defined in its specification. 
                    161: ** 
                    162: ** The implementation of a class can be broken into separate pieces in a file
                    163: ** and categories can break them across modules. To handle this problem is a
                    164: ** singly linked list of methods. 
                    165: */
                    166: typedef struct objc_method Method;
                    167: typedef Method* Method_t;
                    168: typedef struct objc_method_list {
                    169:   struct objc_method_list*  method_next;      /* This variable is used to link 
                    170:                                                 a method list to another.  It 
                    171:                                                 is a singly linked list. */
                    172:   int            method_count;               /* Number of methods defined in 
                    173:                                                 this structure. */
                    174:   struct objc_method {
                    175:     SEL         method_name;                  /* This variable is the method's 
                    176:                                                 name.  It is a char*. 
                    177:                                                   The unique integer passed to 
                    178:                                                 objc_msg_send is a char* too.  
                    179:                                                 It is compared against 
                    180:                                                 method_name using strcmp. */
                    181:     const char* method_types;                 /* Description of the method's
                    182:                                                 parameter list.  Useful for
                    183:                                                 debuggers. */
                    184:     IMP         method_imp;                   /* Address of the method in the 
                    185:                                                 executable. */
                    186:   } method_list[1];                           /* Variable length 
                    187:                                                 structure. */
                    188: } MethodList, *MethodList_t;
                    189: 
                    190: struct objc_protocol_list {
                    191:   struct objc_protocol_list *next;
                    192:   int count;
                    193:   Protocol *list[1];
                    194: };
                    195: 
                    196: /*
                    197: ** This is used to assure consistent access to the info field of 
                    198: ** classes
                    199: */
                    200: #ifndef HOST_BITS_PER_LONG
                    201: #define HOST_BITS_PER_LONG  (sizeof(long)*8)
                    202: #endif 
                    203: 
                    204: #define __CLS_INFO(cls) ((cls)->info)
                    205: #define __CLS_ISINFO(cls, mask) ((__CLS_INFO(cls)&mask)==mask)
                    206: #define __CLS_SETINFO(cls, mask) (__CLS_INFO(cls) |= mask)
                    207: 
                    208: /* The structure is of type MetaClass* */
                    209: #define _CLS_META 0x2L
                    210: #define CLS_ISMETA(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_META))
                    211: 
                    212: 
                    213: /* The structure is of type Class* */
                    214: #define _CLS_CLASS 0x1L
                    215: #define CLS_ISCLASS(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_CLASS))
                    216: 
                    217: /*
                    218: ** The class is initialized within the runtime.  This means that 
                    219: ** it has had correct super and sublinks assigned
                    220: */
                    221: #define _CLS_RESOLV 0x8L
                    222: #define CLS_ISRESOLV(cls) __CLS_ISINFO(cls, _CLS_RESOLV)
                    223: #define CLS_SETRESOLV(cls) __CLS_SETINFO(cls, _CLS_RESOLV)
                    224: 
                    225: /*
                    226: ** The class has been send a +initialize message or a such is not 
                    227: ** defined for this class
                    228: */
                    229: #define _CLS_INITIALIZED 0x04L
                    230: #define CLS_ISINITIALIZED(cls) __CLS_ISINFO(cls, _CLS_INITIALIZED)
                    231: #define CLS_SETINITIALIZED(cls) __CLS_SETINFO(cls, _CLS_INITIALIZED)
                    232: 
                    233: /*
                    234: ** The class number of this class.  This must be the same for both the 
                    235: ** class and it's meta class object
                    236: */
                    237: #define CLS_GETNUMBER(cls) (__CLS_INFO(cls) >> (HOST_BITS_PER_LONG/2))
                    238: #define CLS_SETNUMBER(cls, num) \
                    239:   ({ (cls)->info <<= (HOST_BITS_PER_LONG/2); \
                    240:      (cls)->info >>= (HOST_BITS_PER_LONG/2); \
                    241:      __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); })
                    242: 
                    243: /*
                    244: ** The compiler generates one of these structures for each category.  A class
                    245: ** may have many categories and contain both instance and factory methods.  
                    246: */
                    247: typedef struct objc_category {
                    248:   const char*   category_name;                /* Name of the category.  Name
                    249:                                                 contained in the () of the
                    250:                                                 category definition. */
                    251:   const char*   class_name;                   /* Name of the class to which
                    252:                                                 the category belongs. */
                    253:   MethodList_t  instance_methods;             /* Linked list of instance
                    254:                                                 methods defined in the 
                    255:                                                 category. NULL indicates no
                    256:                                                 instance methods defined. */
                    257:   MethodList_t  class_methods;                /* Linked list of factory 
                    258:                                                 methods defined in the
                    259:                                                 category.  NULL indicates no
                    260:                                                 class methods defined. */
                    261:   struct objc_protocol_list *protocols;              /* List of Protocols 
                    262:                                                 conformed to */
                    263: } Category, *Category_t;
                    264: 
                    265: /*
                    266: ** Structure used when a message is send to a class's super class.  The
                    267: ** compiler generates one of these structures and passes it to
                    268: ** objc_msg_super.
                    269: */
                    270: typedef struct objc_super {
                    271:   id      self;                           /* Id of the object sending
                    272:                                                 the message. */
                    273:   Class* class;                              /* Object's super class. */
                    274: } Super, *Super_t;
                    275: 
                    276: IMP objc_msg_lookup_super(Super_t super, SEL sel);
                    277: 
                    278: retval_t objc_msg_sendv(id, SEL, arglist_t);
                    279: 
                    280: 
                    281: 
                    282: /*
                    283: ** This is a hook which is called by objc_lookup_class and
                    284: ** objc_get_class if the runtime is not able to find the class.
                    285: ** This may e.g. try to load in the class using dynamic loading.
                    286: ** The function is guaranteed to be passed a non-NULL name string.
                    287: */
                    288: extern Class* (*_objc_lookup_class)(const char *name);
                    289: 
                    290: extern id (*_objc_object_alloc)(Class* class);
                    291: 
                    292: extern id (*_objc_object_copy)(id object);
                    293: 
                    294: extern id (*_objc_object_dispose)(id object);
                    295: 
                    296: Method_t class_get_class_method(MetaClass* class, SEL aSel);
                    297: 
                    298: Method_t class_get_instance_method(Class* class, SEL aSel);
                    299: 
                    300: Class* class_pose_as(Class* impostor, Class* superclass);
                    301: 
                    302: Class* objc_get_class(const char *name);
                    303: 
                    304: Class* objc_lookup_class(const char *name);
                    305: 
                    306: const char *sel_get_name(SEL selector);
                    307: 
                    308: SEL sel_get_uid(const char *name);
                    309: 
                    310: SEL sel_register_name(const char *name);
                    311: 
                    312: BOOL sel_is_mapped (SEL aSel);
                    313: 
                    314: extern id class_create_instance(Class* class);
                    315: 
                    316: static inline const char *
                    317: class_get_class_name(Class* class)
                    318: {
                    319:   return CLS_ISCLASS(class)?class->name:((class==Nil)?"Nil":0);
                    320: }
                    321: 
                    322: static inline long
                    323: class_get_instance_size(Class* class)
                    324: {
                    325:   return CLS_ISCLASS(class)?class->instance_size:0;
                    326: }
                    327: 
                    328: static inline MetaClass*
                    329: class_get_meta_class(Class* class)
                    330: {
                    331:   return CLS_ISCLASS(class)?class->class_pointer:Nil;
                    332: }
                    333: 
                    334: static inline Class*
                    335: class_get_super_class(Class* class)
                    336: {
                    337:   return CLS_ISCLASS(class)?class->super_class:Nil;
                    338: }
                    339: 
                    340: static inline int
                    341: class_get_version(Class* class)
                    342: {
                    343:   return CLS_ISCLASS(class)?class->version:-1;
                    344: }
                    345: 
                    346: static inline BOOL
                    347: class_is_class(Class* class)
                    348: {
                    349:   return CLS_ISCLASS(class);
                    350: }
                    351: 
                    352: static inline BOOL
                    353: class_is_meta_class(Class* class)
                    354: {
                    355:   return CLS_ISMETA(class);
                    356: }
                    357: 
                    358: 
                    359: static inline void
                    360: class_set_version(Class* class, long version)
                    361: {
                    362:   if (CLS_ISCLASS(class))
                    363:     class->version = version;
                    364: }
                    365: 
                    366: static inline IMP
                    367: method_get_imp(Method_t method)
                    368: {
                    369:   return (method!=METHOD_NULL)?method->method_imp:(IMP)0;
                    370: }
                    371: 
                    372: IMP get_imp (Class* class, SEL sel);
                    373: 
                    374: id object_copy(id object);
                    375: 
                    376: id object_dispose(id object);
                    377: 
                    378: static inline Class*
                    379: object_get_class(id object)
                    380: {
                    381:   return ((object!=nil)
                    382:          ? (CLS_ISCLASS(object->class_pointer)
                    383:             ? object->class_pointer
                    384:             : (CLS_ISMETA(object->class_pointer)
                    385:                ? (Class*)object
                    386:                : Nil))
                    387:          : Nil);
                    388: }
                    389: 
                    390: static inline const char *
                    391: object_get_class_name(id object)
                    392: {
                    393:   return ((object!=nil)?(CLS_ISCLASS(object->class_pointer)
                    394:                          ?object->class_pointer->name
                    395:                          :((Class*)object)->name)
                    396:                        :"Nil");
                    397: }
                    398: 
                    399: static inline MetaClass*
                    400: object_get_meta_class(id object)
                    401: {
                    402:   return ((object!=nil)?(CLS_ISCLASS(object->class_pointer)
                    403:                          ?object->class_pointer->class_pointer
                    404:                          :(CLS_ISMETA(object->class_pointer)
                    405:                            ?object->class_pointer
                    406:                            :Nil))
                    407:                        :Nil);
                    408: }
                    409: 
                    410: static inline Class*
                    411: object_get_super_class
                    412: (id object)
                    413: {
                    414:   return ((object!=nil)?(CLS_ISCLASS(object->class_pointer)
                    415:                          ?object->class_pointer->super_class
                    416:                          :(CLS_ISMETA(object->class_pointer)
                    417:                            ?((Class*)object)->super_class
                    418:                            :Nil))
                    419:                        :Nil);
                    420: }
                    421: 
                    422: static inline BOOL
                    423: object_is_class(id object)
                    424: {
                    425:   return CLS_ISCLASS((Class*)object);
                    426: }
                    427: 
                    428: static inline BOOL
                    429: object_is_instance(id object)
                    430: {
                    431:   return (object!=nil)&&CLS_ISCLASS(object->class_pointer);
                    432: }
                    433: 
                    434: static inline BOOL
                    435: object_is_meta_class(id object)
                    436: {
                    437:   return CLS_ISMETA((Class*)object);
                    438: }
                    439: 
                    440: #endif /* not __objc_api_INCLUDE_GNU */
                    441: 
                    442: 
                    443: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.