This is objcTypeDecode.h in view mode; [Download] [Up]
/*+++* * title: objcTypeDecode.h * abstract: objc-encoded type decoding functions. * author: Tom Hageman <tom@basil.icce.rug.nl> * created: December 1998 * modified: (see RCS Log at end) * copyright: * * Copyright (C) 1998 Tom R. Hageman. * * You may freely copy, distribute, and reuse the code in this file. * * NO WARRANTY: * ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A * PARTICULAR PURPOSE IS HEREBY DISCLAIMED. IN NO EVENT WILL THE * AFOREMENTIONED PARTIES BE LIABLE FOR DAMAGES, INCLUDING ANY * GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING * OUT OF THE USE OF OR INABILITY TO USE THIS CODE. * * description: * * Some functions to yield human-readable type / value descriptions, * given its runtime argument description. * * XXX the GNU runtime support is untested and probably incomplete. *---*/ #ifndef _objcTypeDecode_H_ #define _objcTypeDecode_H_ #ifdef RCS_objcTypeDecode_ID static const char * const RCS_h_id = ((void)&RCS_h_id, "@(#)objcTypeDecode.h,v 1.9 1999/01/10 13:58:26 tom Exp"); #endif #import <objc/Object.h> #include <sys/types.h> #include <objc/objc-class.h> #if !defined(GNU_RUNTIME) && !defined(NeXT_RUNTIME) # if ((__NeXT__ && _NEXT_SOURCE) || __APPLE_CC__) # define NeXT_RUNTIME 1 # elif __GNUC__ # define GNU_RUNTIME 1 # endif #endif #if (GNU_RUNTIME) # import <objc/encoding.h> #endif #if (NeXT_RUNTIME) /* Backward-compatibility hacks. NS <-> OS. */ /* NEXTSTEP does not define this function; OPENSTEP does. */ # ifndef OBJC_NEXT_METHOD_LIST # define class_nextMethodList(CLASS, ITER) \ ({ struct objc_method_list**__iter=(struct objc_method_list**)(ITER); \ (*__iter) = (*__iter) ? (*__iter)->method_next : (CLASS)->methods; }) # endif /* NEXTSTEP marg_getRef() does not seem to handle hppa, ppc argument offsets correctly. (The hopefully correct values were taken from the OPENSTEP objc/objc-class.h header.) */ # ifndef marg_adjustedOffset # if hppa # define marg_adjustedOffset(M,offset) ((!offset) ? -sizeof(id) : (offset)) # elif ppc # define marg_adjustedOffset(M,offset) ((offset) + 128) # endif # ifdef marg_adjustedOffset # undef marg_getRef # define marg_getRef(margs, offset, type) \ ((type *)((char *)margs + marg_adjustedOffset(method, offset))) # endif # endif #endif /* These constant definitions are missing from NeXT's objc runtime headers. */ #ifndef _C_CONST #define _C_CONST 'r' #endif #ifndef _C_IN #define _C_IN 'n' #endif #ifndef _C_INOUT #define _C_INOUT 'N' #endif #ifndef _C_OUT #define _C_OUT 'o' #endif #ifndef _C_BYCOPY #define _C_BYCOPY 'O' #endif #ifndef _C_ONEWAY #define _C_ONEWAY 'V' #endif #ifndef _C_ATOM #define _C_ATOM '%' #endif /* These (long long) specifiers seem to be supported in the latest gcc-2.8.x gnu-objc runtime (but not defined even there yet.). */ #ifndef _C_LLNG #define _C_LLNG 'q' #endif #ifndef _C_ULLNG #define _C_ULLNG 'Q' #endif #ifndef CLS_ISMETA # define CLS_ISMETA(cls) CLS_GETINFO((cls), CLS_META) #endif #define IS_VALID_POINTER_OF_TYPE(ptr, type) \ ({ \ type __ptr = (type)(ptr); \ (__ptr != NULL && (((unsigned)(__ptr) % __alignof__(*__ptr))) == 0); \ }) /* Support macro; check that pointer `ptr' of type `type' can be relatively safely dereferenced (barring memory access errors.) NB. this does not work with pointers to incompletely defined types, like SEL. */ #define _OBJECT_ISA(obj) (((struct {@defs(Object);} *)(obj))->isa) /* Evil typecast needed to suppress various compiler warnings/errors. */ #define IS_CLASS(obj) \ ({ \ id __obj = (obj); \ (IS_VALID_POINTER_OF_TYPE(__obj, id) && \ IS_VALID_POINTER_OF_TYPE(_OBJECT_ISA(__obj), Class) && \ CLS_ISMETA(_OBJECT_ISA(__obj))); \ }) /* Determine if `obj' is in reality a Class object instead of an instance. (It is a class iff its `isa' points to a meta-class.) */ extern const char *decode_objc_encoded_type(char *buf, size_t bufsize, const char *type, unsigned options); /* decode ObjC-@encoded `type' string into a human-readable C-style type declaration. Result is deposited into string buffer `buf' of maximum size `bufsize'; if the result would be too long it is silently truncated (XXX do something about that). (XXX describe options). Returns updated position of type string pointer (skipped past a single type spec). */ extern void decode_objc_encoded_value_for_type(char *buf, size_t bufsize, const char *type, const void *valptr, unsigned options); /* Return a human-readable C-style representation of the value pointed at by `valptr', assuming it is of type given by ObjC-@encoded `type'. Result is deposited into string buffer `buf' of maximum size `bufsize'; if the result would be too long it is silently truncated (XXX do something about that.) (but not always; XXX do something about that too...) (XXX describe options). */ /* Options. */ #define DECODE_OBJC_METHOD_TYPE 0x0 #define DECODE_OBJC_IVAR_TYPE 0x1 #define DECODE_OBJC_KIND_MASK 0x7 #define DECODE_OBJC_TERSE 0x0 #define DECODE_OBJC_VERBOSE 0x8 #endif /* _objcTypeDecode_H_ */
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.