home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OpenStep 4.2J (Developer)
/
os42jdev.iso
/
NextDeveloper
/
Headers
/
objc
/
objc-class.h
< prev
next >
Wrap
Text File
|
1996-12-19
|
7KB
|
285 lines
/*
* objc-class.h
* Copyright 1988-1996, NeXT Software, Inc.
*/
#ifndef _OBJC_CLASS_H_
#define _OBJC_CLASS_H_
#import <objc/objc.h>
#import <objc/zone.h>
/*
* Class Template
*/
struct objc_class {
struct objc_class *isa;
struct objc_class *super_class;
const char *name;
long version;
long info;
long instance_size;
struct objc_ivar_list *ivars;
#if defined(Release3CompatibilityBuild)
struct objc_method_list *methods;
#else
struct objc_method_list **methodLists;
#endif
struct objc_cache *cache;
struct objc_protocol_list *protocols;
};
#define CLS_GETINFO(cls,infomask) ((cls)->info & infomask)
#define CLS_SETINFO(cls,infomask) ((cls)->info |= infomask)
#define CLS_CLASS 0x1L
#define CLS_META 0x2L
#define CLS_INITIALIZED 0x4L
#define CLS_POSING 0x8L
#define CLS_MAPPED 0x10L
#define CLS_FLUSH_CACHE 0x20L
#define CLS_GROW_CACHE 0x40L
#define CLS_METHOD_ARRAY 0x100L
/*
* Category Template
*/
typedef struct objc_category *Category;
struct objc_category {
char *category_name;
char *class_name;
struct objc_method_list *instance_methods;
struct objc_method_list *class_methods;
struct objc_protocol_list *protocols;
};
/*
* Instance Variable Template
*/
typedef struct objc_ivar *Ivar;
struct objc_ivar_list {
int ivar_count;
#ifdef __alpha__
int space;
#endif
struct objc_ivar {
char *ivar_name;
char *ivar_type;
int ivar_offset;
#ifdef __alpha__
int space;
#endif
} ivar_list[1]; /* variable length structure */
};
OBJC_EXPORT Ivar object_setInstanceVariable(id, const char *name, void *);
OBJC_EXPORT Ivar object_getInstanceVariable(id, const char *name, void **);
/*
* Method Template
*/
typedef struct objc_method *Method;
struct objc_method_list {
#if defined(Release3CompatibilityBuild)
struct objc_method_list *method_next;
#else
struct objc_method_list *obsolete;
#endif
int method_count;
#ifdef __alpha__
int space;
#endif
struct objc_method {
SEL method_name;
char *method_types;
IMP method_imp;
} method_list[1]; /* variable length structure */
};
/* Protocol support */
@class Protocol;
struct objc_protocol_list {
struct objc_protocol_list *next;
int count;
Protocol *list[1];
};
/* Definitions of filer types */
#define _C_ID '@'
#define _C_CLASS '#'
#define _C_SEL ':'
#define _C_CHR 'c'
#define _C_UCHR 'C'
#define _C_SHT 's'
#define _C_USHT 'S'
#define _C_INT 'i'
#define _C_UINT 'I'
#define _C_LNG 'l'
#define _C_ULNG 'L'
#define _C_FLT 'f'
#define _C_DBL 'd'
#define _C_BFLD 'b'
#define _C_VOID 'v'
#define _C_UNDEF '?'
#define _C_PTR '^'
#define _C_CHARPTR '*'
#define _C_ARY_B '['
#define _C_ARY_E ']'
#define _C_UNION_B '('
#define _C_UNION_E ')'
#define _C_STRUCT_B '{'
#define _C_STRUCT_E '}'
/* Structure for method cache - allocated/sized at runtime */
typedef struct objc_cache *Cache;
#ifdef OBJC_COPY_CACHE
#define CACHE_BUCKET_NAME(B) ((B).method_name)
#define CACHE_BUCKET_IMP(B) ((B).method_imp)
#define CACHE_BUCKET_VALID(B) ((B).method_name)
struct objc_cache_bucket {
SEL method_name;
IMP method_imp;
};
struct objc_cache {
unsigned int mask; /* total = mask + 1 */
unsigned int occupied;
struct objc_cache_bucket buckets[1];
};
#else
#define CACHE_BUCKET_NAME(B) ((B)->method_name)
#define CACHE_BUCKET_IMP(B) ((B)->method_imp)
#define CACHE_BUCKET_VALID(B) (B)
struct objc_cache {
unsigned int mask; /* total = mask + 1 */
unsigned int occupied;
Method buckets[1];
};
#endif
/* operations */
OBJC_EXPORT id class_createInstance(Class, unsigned idxIvars);
OBJC_EXPORT id class_createInstanceFromZone(Class, unsigned idxIvars, NXZone *zone);
OBJC_EXPORT void class_setVersion(Class, int);
OBJC_EXPORT int class_getVersion(Class);
OBJC_EXPORT Ivar class_getInstanceVariable(Class, const char *);
OBJC_EXPORT Method class_getInstanceMethod(Class, SEL);
OBJC_EXPORT Method class_getClassMethod(Class, SEL);
OBJC_EXPORT void class_addMethods(Class, struct objc_method_list *);
OBJC_EXPORT void class_removeMethods(Class, struct objc_method_list *);
OBJC_EXPORT Class class_poseAs(Class imposter, Class original);
OBJC_EXPORT unsigned method_getNumberOfArguments(Method);
OBJC_EXPORT unsigned method_getSizeOfArguments(Method);
OBJC_EXPORT unsigned method_getArgumentInfo(Method m, int arg, const char **type, int *offset);
OBJC_EXPORT const char * NSModulePathForClass (Class aClass);
// usage for nextMethodList
//
// void *iterator = 0;
// struct objc_method_list *mlist;
// while ( mlist = class_nextMethodList( cls, &iterator ) )
// ;
#define OBJC_NEXT_METHOD_LIST 1
OBJC_EXPORT struct objc_method_list *class_nextMethodList(Class, void **);
typedef void *marg_list;
#if hppa
#define marg_malloc(margs, method) \
do { \
unsigned int _sz = (7 + method_getSizeOfArguments(method)) & ~7; \
char *_ml = (char *)malloc(_sz + sizeof(marg_list)); \
void **_z ; \
margs = (marg_list *)(_ml + _sz); \
_z = margs; \
*_z = (marg_list)_ml; \
} while (0)
#define marg_free(margs) \
do { \
void **_z = margs; \
free(*_z); \
} while (0)
#define marg_adjustedOffset(method, offset) \
( (!offset) ? -(sizeof(id)) : offset)
#else
#define marg_malloc(margs, method) \
do { \
margs = (marg_list *)malloc ((7 + method_getSizeOfArguments(method)) & ~7); \
} while (0)
#define marg_free(margs) \
do { \
free(margs); \
} while (0)
#define marg_adjustedOffset(method, offset) \
(offset)
#endif /* hppa */
#define marg_getRef(margs, offset, type) \
( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
#define marg_getValue(margs, offset, type) \
( *marg_getRef(margs, offset, type) )
#define marg_setValue(margs, offset, type, value) \
( marg_getValue(margs, offset, type) = (value) )
/* Load categories and non-referenced classes from libraries. */
#if defined(NeXT_PDO)
#if defined(hpux)
#define OBJC_REGISTER_SYMBOL(NAME) asm("._" #NAME "=0\n .globl ._" #NAME "\n")
#define OBJC_REFERENCE_SYMBOL(NAME) asm(".word ._" #NAME "\n")
#define OBJC_REGISTER_CATEGORY(NAME) asm("._" #NAME "=0\n .globl ._" #NAME "\n")
#define OBJC_REFERENCE_CATEGORY(NAME) asm(".word ._" #NAME "\n")
#define OBJC_REFERENCE_CLASS_CATEGORY(CL, CAT) asm(".word .objc_category_name_" #CL "_" #CAT "\n")
#define OBJC_REFERENCE_CLASS(NAME) asm(".word .objc_class_name_" #NAME "\n")
#elif defined(__osf__)
#define OBJC_REGISTER_SYMBOL(NAME) asm(".globl ._" #NAME "\n\t.align 3\n._" #NAME ":\n\t.quad 0\n")
#define OBJC_REFERENCE_SYMBOL(NAME) asm(".align 3\n\t.quad ._" #NAME "\n")
#define OBJC_REGISTER_CATEGORY(NAME) asm(".globl ._" #NAME "\n\t.align 3\n._" #NAME ":\n\t.quad 0\n")
#define OBJC_REFERENCE_CATEGORY(NAME) asm(".align 3\n\t.quad ._" #NAME "\n")
#define OBJC_REFERENCE_CLASS_CATEGORY(CL, CAT) asm(".align 3\n\t.quad .objc_category_name_" #CL "_" #CAT "\n")
#define OBJC_REFERENCE_CLASS(NAME) asm(".quad .objc_class_name_" #NAME "\n")
#else /* Solaris || SunOS */
#define OBJC_REGISTER_SYMBOL(NAME) asm("._" #NAME "=0\n .globl ._" #NAME "\n")
#define OBJC_REFERENCE_SYMBOL(NAME) asm(".global ._" #NAME "\n")
#define OBJC_REGISTER_CATEGORY(NAME) asm("._" #NAME "=0\n .globl ._" #NAME "\n")
#define OBJC_REFERENCE_CATEGORY(NAME) asm(".global ._" #NAME "\n")
#define OBJC_REFERENCE_CLASS_CATEGORY(CL, CAT) asm(".global .objc_category_name_" #CL "_" #CAT "\n")
#define OBJC_REFERENCE_CLASS(NAME) asm(".global .objc_class_name_" #NAME "\n")
#endif /* hpux */
#endif /* NeXT_PDO */
#endif /* _OBJC_CLASS_H_ */