|
|
1.1 ! root 1: /* Declare functions used within Objective C runtime support. ! 2: Copyright (C) 1992 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: ! 27: #ifndef __objc_proto_INCLUDE_GNU ! 28: #define __objc_proto_INCLUDE_GNU ! 29: ! 30: /* This used to be #ifndef __OBJC__, but it turns out that ! 31: object.m needs these declarations. I don't understand why one ! 32: might want to avoid them in object.m. */ ! 33: ! 34: #if 1 ! 35: /* ! 36: * objc_getClass returns the id of the class ! 37: * object for the aClassName class. The class ! 38: * object holds information used by instances of ! 39: * the class. ! 40: * ! 41: * Print a message to the standard error stream if ! 42: * aClassName isn't part of the executable image. ! 43: */ ! 44: Class_t objc_getClass (const char *); ! 45: ! 46: /* ! 47: * objc_getMetaClass returns the id of the ! 48: * meta class object for the aClassName class. ! 49: * The meta class object holds information used ! 50: * by the class object, just as the class ! 51: * object holds information used by instances ! 52: * of the class. ! 53: * ! 54: * Print a message to the standard error stream ! 55: * if aClassName isn't part of the executable image. ! 56: */ ! 57: MetaClass_t objc_getMetaClass (const char *); ! 58: ! 59: /* ! 60: * The compiler converts every message expression into a ! 61: * call on one of these two functions. Messages to ! 62: * super are converted to calls on objc_msgSendSuper; ! 63: * all others are converted to calls on objc_msgSend. ! 64: * ! 65: * These functions return the address of the method ! 66: * implementation. The compiler then generates calls ! 67: * to those methods passing the full argument array. ! 68: * ! 69: * Calls to objc_msgSend and objc_msgSendSuper ! 70: * should be generated only by the compiler. You shouldn't ! 71: * call them directly in the Objective-C code you write. ! 72: */ ! 73: IMP objc_msgSend (id, SEL); ! 74: ! 75: IMP objc_msgSendSuper (Super_t, SEL); ! 76: #endif ! 77: ! 78: /* ! 79: * Given the name of a variable within a class's ! 80: * definition, return a pointer to a structure that ! 81: * describes it. ! 82: */ ! 83: Ivar_t object_getIvarAddress (id obj, const char *variableName); ! 84: ! 85: /* ! 86: * Given a class and a selector, return a pointer to the method's method ! 87: * structure. Return NULL if not found. ! 88: * ! 89: * This is a method internal to the run-time. ! 90: */ ! 91: Method_t searchForMethodInHierarchy (Class_t, SEL); ! 92: ! 93: ! 94: /* ! 95: * The first function, sel_getUid, returns a selector that's ! 96: * used at run time to identify the aName method. Whenever ! 97: * possible, you should use the @selector directive to ! 98: * ask the compiler, rather than the run-time system, ! 99: * to provide the selector for a method. This function ! 100: * should be used only if the name isn't known at compile ! 101: * time. ! 102: * ! 103: * The second function, sel_getName, is the inverse ! 104: * of the first. It returns the name that was mapped to ! 105: * aSelector. ! 106: */ ! 107: SEL sel_getUid (const STR); ! 108: ! 109: const STR sel_getName (SEL); ! 110: ! 111: /* ! 112: * This function returns the number of arguments that METHOD ! 113: * the takes. This will be at least two, since it ! 114: * includes the �hidden� arguments, self and _cmd, ! 115: * which are the first two arguments passed to every ! 116: * method implementation. ! 117: */ ! 118: unsigned int method_getNumberOfArguments (Method_t method); ! 119: ! 120: /* This functiontakes an index into METHOD's argument ! 121: * list and returns, by reference, the type of the argument ! 122: * and the offset to the location of that argument in the ! 123: * list. Indices begin with 0. The �hidden� arguments ! 124: * self and _cmd are indexed at 0 and 1; method-specific ! 125: * arguments begin at index 2. The offset is measured in ! 126: * bytes and depends on the size of arguments preceding the ! 127: * indexed argument in the argument list. The type is ! 128: * encoded according to the conventions of the @encode ! 129: * compiler directive. ! 130: */ ! 131: unsigned int method_getArgumentInfo (Method_t, int indx, ! 132: const char **type, int *offset); ! 133: ! 134: /* ! 135: * This function is used to support archiving when a unknown class is to read ! 136: * from a archive. This function returns a instantiated object. To further ! 137: * dearchive the object it should be sent: -readFrom:. ! 138: * ! 139: * This function positions the file pointer just past class Object's class ! 140: * data. ! 141: */ ! 142: id objc_objectFromFile (int fd); ! 143: ! 144: /* ! 145: * class_getInstanceMethod returns a pointer ! 146: * to the data structure that describes the method. ! 147: * ! 148: * The selector must identify an ! 149: * instance method. ! 150: * ! 151: * Return a NULL pointer if SEL doesn't ! 152: * identify a method defined in or inherited ! 153: * by CLASS. ! 154: */ ! 155: static inline Method_t ! 156: class_getInstanceMethod (Class_t class, SEL sel) ! 157: { ! 158: return searchForMethodInHierarchy (class, sel); ! 159: } ! 160: ! 161: /* ! 162: * class_getClassMethod returns a pointer to ! 163: * the data structure that describes the method. ! 164: * ! 165: * The selector must identify a class (factory) method. ! 166: * ! 167: * Return a NULL pointer if SEL doesn't ! 168: * identify a method defined in or inherited by CLASS. ! 169: */ ! 170: static inline Method_t ! 171: class_getClassMethod (MetaClass_t class, SEL sel) ! 172: { ! 173: return searchForMethodInHierarchy ((Class_t)class, sel); ! 174: } ! 175: ! 176: /* ! 177: * This function returns the name of OBJ's ! 178: * class. anObject should be an instance ! 179: * object, not a class object. ! 180: */ ! 181: static inline const char * ! 182: object_getClassName (id obj) ! 183: { ! 184: return obj->class_pointer->name; ! 185: } ! 186: ! 187: /* ! 188: * This function returns the name of the ! 189: * class. ! 190: */ ! 191: static inline const char * ! 192: class_getClassName (Class_t class) ! 193: { ! 194: return class->name; ! 195: } ! 196: ! 197: /* ! 198: * Add a class to the class hash table and assign it a class number. ! 199: */ ! 200: void addClassToHash (Class_t class); ! 201: ! 202: /* ! 203: * This function takes a list of methods and adds them to the method list of ! 204: * a class. The method list must remain intact during the lifetime of the ! 205: * class. ! 206: */ ! 207: void addMethodsToClass (Class_t, MethodList_t); ! 208: ! 209: /* ! 210: * This function creates a new instance of CLASS, initializes its class_pointer ! 211: * instance variable to point to the class, and return the new instance. ! 212: * ! 213: * All other instance variables are initialized to 0. ! 214: */ ! 215: static inline id ! 216: class_createInstance (Class_t class) ! 217: { ! 218: return (*_alloc)(class); ! 219: } ! 220: ! 221: /* ! 222: * object_dispose frees the memory occupied by OBJ after setting its ! 223: * class_pointer instance variable to nil, and returns nil. The function it calls to ! 224: * do this work can be changed by reassigning the _dealloc variable. ! 225: */ ! 226: static inline id ! 227: object_dispose (id obj) ! 228: { ! 229: return (*_dealloc)(obj); ! 230: } ! 231: ! 232: /* ! 233: * object_copy creates a new object that's an exact copy of anObject and ! 234: * return the new object. The second argument, indexedIvarBytes, specifies ! 235: * the number of additional bytes that should be allocated for the copy to ! 236: * accommodate indexed instance variables; it serves the same purpose as the ! 237: * second argument to class_createInstance. The function that ! 238: * object_copy calls to do this work can be changed by reassigning the ! 239: * _copy variable. ! 240: */ ! 241: static inline id ! 242: object_copy (id obj) ! 243: { ! 244: return (*_copy)(obj); ! 245: } ! 246: ! 247: /* ! 248: * object_realloc reallocates storage for anObject, adding numBytes if ! 249: * possible. The memory previously occupied by anObject is freed if it can't ! 250: * be reused, and a pointer to the new location of anObject is returned. The ! 251: * function that object_realloc calls to do this work can be changed by ! 252: * reassigning the _realloc variable. ! 253: */ ! 254: static inline id ! 255: object_realloc (id obj, unsigned int size) ! 256: { ! 257: return (*_realloc)(obj, size); ! 258: } ! 259: ! 260: /* ! 261: * This function causes one class to pose as its super class. Messages sent ! 262: * to the super class will actually be sent to the posing class. ! 263: * ! 264: * Instance variables should not be declared in the posing class. The posing ! 265: * class can add new methods to the class or override existing methods in the ! 266: * super class. ! 267: */ ! 268: Class_t class_poseAs (Class_t, Class_t); ! 269: ! 270: ! 271: /* These functions set and return the class version number. */ ! 272: static inline void ! 273: class_setVersion (Class_t class, long version) ! 274: { ! 275: class->version = version ; ! 276: class->class_pointer->version = version ; ! 277: } ! 278: ! 279: static inline long ! 280: class_getVersion (Class_t class) ! 281: { ! 282: return class->version ; ! 283: } ! 284: ! 285: ! 286: /* ! 287: * Class numbers are stored in the class's info variable. This is temporary. ! 288: * Eventually we will allocate a member to the class so that some efficiency ! 289: * can be gained by not shifting. ! 290: */ ! 291: #define CLASS_LOCATION_SHIFT (HOST_BITS_PER_LONG / 2) ! 292: ! 293: static inline void ! 294: setClassNumber (Class_t class, unsigned long number) ! 295: { ! 296: class->info |= number << CLASS_LOCATION_SHIFT; ! 297: } ! 298: ! 299: static inline unsigned long ! 300: getClassNumber (Class_t class) ! 301: { ! 302: return class->info >> CLASS_LOCATION_SHIFT; ! 303: } ! 304: ! 305: /* ! 306: * class_addInstanceMethods adds methods that can be ! 307: * used by instances of the class and class_addClassMethods ! 308: * adds methods used by the class object. Before adding a ! 309: * method, both functions check for duplicates. A warning ! 310: * is sent to the standard error stream if any ambiguities exist. ! 311: * ! 312: * The passed structure and its contents must exist for the the ! 313: * duration of the program. These functions don't support ! 314: * linked structures. ! 315: */ ! 316: static inline void ! 317: class_addInstanceMethods (Class_t class, MethodList_t method_list) ! 318: { ! 319: addMethodsToClass (class, method_list); ! 320: } ! 321: ! 322: static inline void ! 323: class_addClassMethods (Class_t class, MethodList_t method_list) ! 324: { ! 325: addMethodsToClass ((Class_t)class->class_pointer, method_list); ! 326: } ! 327: ! 328: /* ! 329: * This function returns the number of bytes that all of METHOD's ! 330: * arguments, taken together, would occupy on the stack. ! 331: */ ! 332: static inline unsigned int ! 333: method_getSizeOfArguments (Method_t method) ! 334: { ! 335: return atoi (&method->method_types[1]); ! 336: } ! 337: ! 338: /* ! 339: * This function returns the size in bytes of a ! 340: * instance of OBJ. ! 341: */ ! 342: static inline long ! 343: objc_classSize (id obj) ! 344: { ! 345: return obj->class_pointer->instance_size; ! 346: } ! 347: ! 348: /* Some functions that I've been told are useful by Henry Flurry */ ! 349: ! 350: /* Returns a C string representing the ASCII rep of the selector. */ ! 351: static inline const char * ! 352: SELNAME (SEL sel) ! 353: { ! 354: return sel_getName (sel); ! 355: } ! 356: ! 357: /* ! 358: * Converts a C string to a SEL that can be used in perform: methods, ! 359: * objc_msgSend, etc. ! 360: */ ! 361: static inline SEL ! 362: SELUID (const STR str) ! 363: { ! 364: return sel_getUid (str); ! 365: } ! 366: ! 367: /* ! 368: * Returns the class name of the object (or meta class name of a class ! 369: * object), or some _nilName if obj is nil. ! 370: */ ! 371: static inline const char * ! 372: NAMEOF (id obj) ! 373: { ! 374: const char *name = 0; ! 375: ! 376: if (obj) ! 377: { ! 378: if (obj->class_pointer->info & CLS_CLASS) ! 379: name = object_getClassName (obj); ! 380: else if (((Class_t)obj)->class_pointer->info & CLS_META) ! 381: name = class_getClassName ((Class_t)obj); ! 382: } ! 383: ! 384: return name; ! 385: } ! 386: ! 387: /* ! 388: * These functions add and remove methods in a list from a class. These ! 389: * functions perform the actual work required for those functions. ! 390: * ! 391: * The appropriate run-time is to provide the user callable functions to ! 392: * perform these functions. Typically those functions perform something ! 393: * specific to their run-time type and call these functions to perform the ! 394: * actual work. ! 395: */ ! 396: void class_removeMethods (Class_t class, MethodList_t method_list); ! 397: ! 398: /* ! 399: * Find the named method in a linked list of methods. ! 400: */ ! 401: Method_t searchForMethodInList (MethodList_t list, const char *name); ! 402: ! 403: /* ! 404: * printf is used if we're debugging. If DEBUG isn't defined then this ! 405: * def isn't defined thereby causing the compiler to eliminate the parameter ! 406: * decl. ! 407: */ ! 408: #ifdef DEBUG ! 409: #define DEBUG_PRINTF printf ! 410: #else ! 411: #define DEBUG_PRINTF ! 412: #endif ! 413: ! 414: ! 415: /* ! 416: * Function that dumps information about all of the classes to stdout. ! 417: */ ! 418: void debug_dump_classes (void); ! 419: ! 420: #endif /* not __objc_proto_INCLUDE_GNU */ ! 421:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.