next_mapping.h

来自「xml大全 可读写调用率很高 xml大全 可读写调用率很高」· C头文件 代码 · 共 852 行 · 第 1/2 页

H
852
字号
/* This file "renames" various ObjC GNU runtime entry points   (and fakes the existence of several others)   if the NeXT runtime is being used.  *//* Author: Ziemowit Laski <zlaski@apple.com>  */#ifdef __NEXT_RUNTIME__#include <objc/objc-class.h>#include <ctype.h>#define objc_get_class(C)			objc_getClass(C)#define objc_get_meta_class(C)			objc_getMetaClass(C)#define class_get_class_method(C, S)		class_getClassMethod(C, S)#define class_get_instance_method(C, S)		class_getInstanceMethod(C, S)#define method_get_imp(M)			(((Method)M)->method_imp)#define sel_get_name(S)				sel_getName(S)#define class_create_instance(C)		class_createInstance(C, 0)#define	class_get_class_name(C)			object_getClassName(C)#define class_get_super_class(C)		(((struct objc_class *)C)->super_class)#define object_get_super_class(O)		class_get_super_class(*(struct objc_class **)O)#define objc_lookup_class(N)			objc_lookUpClass(N)#define object_get_class(O)			(*(struct objc_class **)O)#define class_is_class(C)			(CLS_GETINFO((struct objc_class *)C, CLS_CLASS)? YES: NO)#define class_is_meta_class(C)			(CLS_GETINFO((struct objc_class *)C, CLS_META)? YES: NO)#define object_is_class(O)			class_is_meta_class(*(struct objc_class **)O)#define object_is_meta_class(O)			(class_is_meta_class(O) && class_is_meta_class(*(struct objc_class **)O))/* You need either an empty +initialize method or an empty -forward:: method.    The NeXT runtime unconditionally sends +initialize to classes when they are    first used, and unconditionally tries to forward methods that the class    doesn't understand (including +initialize). If you have neither +initialize    nor -forward::, the runtime complains.     The simplest workaround is to add      + initialize { return self; }   to every root class @implementation.  */#ifndef NULL#define NULL 0#endif/* The following is necessary to "cover" the bf*.m test cases on NeXT.  */#undef  MAX#define MAX(X, Y)                    \  ({ typeof (X) __x = (X), __y = (Y); \     (__x > __y ? __x : __y); })#undef  MIN#define MIN(X, Y)                    \  ({ typeof (X) __x = (X), __y = (Y); \     (__x < __y ? __x : __y); })  #undef  ROUND#define ROUND(V, A) \  ({ typeof (V) __v = (V); typeof (A) __a = (A); \     __a * ((__v+__a - 1)/__a); })#define BITS_PER_UNIT __CHAR_BIT__#define STRUCTURE_SIZE_BOUNDARY (BITS_PER_UNIT * sizeof (struct{char a;}))/* Not sure why the following are missing from NeXT objc headers... */#ifndef _C_LNG_LNG#define _C_LNG_LNG  'q'#endif#ifndef _C_ULNG_LNG#define _C_ULNG_LNG 'Q'#endif#ifndef _C_ATOM#define _C_ATOM     '%'#endif#ifndef _C_BOOL#define _C_BOOL     'B'#endif#define _C_CONST        'r'#define _C_IN           'n'#define _C_INOUT        'N'#define _C_OUT          'o'#define _C_BYCOPY       'O'#define _C_BYREF        'R'#define _C_ONEWAY       'V'#define _C_GCINVISIBLE  '!'   #define _F_CONST        0x01#define _F_IN           0x01#define _F_OUT          0x02#define _F_INOUT        0x03#define _F_BYCOPY       0x04  #define _F_BYREF        0x08  #define _F_ONEWAY       0x10#define _F_GCINVISIBLE  0x20struct objc_struct_layout{  const char *original_type;  const char *type;  const char *prev_type;  unsigned int record_size;   unsigned int record_align;};typedef union {  char *arg_ptr;  char arg_regs[sizeof (char*)];} *arglist_t;                   /* argument frame */const char *objc_skip_typespec (const char *type);void objc_layout_structure_get_info (struct objc_struct_layout *layout,    unsigned int *offset, unsigned int *align, const char **type);void objc_layout_structure (const char *type,    struct objc_struct_layout *layout);BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout);void objc_layout_finish_structure (struct objc_struct_layout *layout,    unsigned int *size, unsigned int *align);/*  return the size of an object specified by type*/intobjc_sizeof_type (const char *type){  /* Skip the variable name if any */  if (*type == '"')    {      for (type++; *type++ != '"';)	/* do nothing */;    }  switch (*type) {  case _C_ID:    return sizeof (id);    break;  case _C_CLASS:    return sizeof (Class);    break;  case _C_SEL:    return sizeof (SEL);    break;  case _C_CHR:    return sizeof (char);    break;  case _C_UCHR:    return sizeof (unsigned char);    break;  case _C_SHT:    return sizeof (short);    break;  case _C_USHT:    return sizeof (unsigned short);    break;  case _C_INT:    return sizeof (int);    break;  case _C_UINT:    return sizeof (unsigned int);    break;  case _C_LNG:    return sizeof (long);    break;  case _C_ULNG:    return sizeof (unsigned long);    break;  case _C_LNG_LNG:    return sizeof (long long);    break;  case _C_ULNG_LNG:    return sizeof (unsigned long long);    break;  case _C_FLT:    return sizeof (float);    break;  case _C_DBL:    return sizeof (double);    break;  case _C_VOID:    return sizeof (void);    break;  case _C_PTR:  case _C_ATOM:  case _C_CHARPTR:    return sizeof (char *);    break;  case _C_ARY_B:    {      int len = atoi (type + 1);      while (isdigit ((unsigned char)*++type))	;      return len * objc_aligned_size (type);    }    break;  case _C_BFLD:    {      /* The NeXT encoding of bitfields is _still_: b 'size' */      int size = atoi (type + 1);      /* Return an upper bound on byte size */      return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;    }  case _C_STRUCT_B:    {      struct objc_struct_layout layout;      unsigned int size;      objc_layout_structure (type, &layout);      while (objc_layout_structure_next_member (&layout))        /* do nothing */ ;      objc_layout_finish_structure (&layout, &size, NULL);      return size;    }  case _C_UNION_B:    {      int max_size = 0;      while (*type != _C_UNION_E && *type++ != '=')	/* do nothing */;      while (*type != _C_UNION_E)	{	  /* Skip the variable name if any */	  if (*type == '"')	    {	      for (type++; *type++ != '"';)		/* do nothing */;	    }	  max_size = MAX (max_size, objc_sizeof_type (type));	  type = objc_skip_typespec (type);	}      return max_size;    }  }  return 0; /* error */}/*  Return the alignment of an object specified by type*/intobjc_alignof_type (const char *type){  /* Skip the variable name if any */  if (*type == '"')    {      for (type++; *type++ != '"';)	/* do nothing */;    }  switch (*type) {  case _C_ID:    return __alignof__ (id);    break;  case _C_CLASS:    return __alignof__ (Class);    break;  case _C_SEL:    return __alignof__ (SEL);    break;  case _C_CHR:    return __alignof__ (char);    break;  case _C_UCHR:    return __alignof__ (unsigned char);    break;  case _C_SHT:    return __alignof__ (short);    break;  case _C_USHT:    return __alignof__ (unsigned short);    break;  case _C_INT:  case _C_BFLD: /* This is for the NeXT only */    return __alignof__ (int);    break;  case _C_UINT:    return __alignof__ (unsigned int);    break;  case _C_LNG:    return __alignof__ (long);    break;  case _C_ULNG:    return __alignof__ (unsigned long);    break;  case _C_LNG_LNG:    return __alignof__ (long long);    break;  case _C_ULNG_LNG:    return __alignof__ (unsigned long long);    break;  case _C_FLT:    return __alignof__ (float);    break;  case _C_DBL:    return __alignof__ (double);    break;  case _C_PTR:  case _C_ATOM:  case _C_CHARPTR:    return __alignof__ (char *);    break;  case _C_ARY_B:    while (isdigit ((unsigned char)*++type))      /* do nothing */;    return objc_alignof_type (type);  case _C_STRUCT_B:    {      struct objc_struct_layout layout;      unsigned int align;      objc_layout_structure (type, &layout);      while (objc_layout_structure_next_member (&layout))        /* do nothing */;      objc_layout_finish_structure (&layout, NULL, &align);      return align;    }  case _C_UNION_B:    {      int maxalign = 0;      while (*type != _C_UNION_E && *type++ != '=')	/* do nothing */;      while (*type != _C_UNION_E)	{	  /* Skip the variable name if any */	  if (*type == '"')	    {	      for (type++; *type++ != '"';)		/* do nothing */;	    }	  maxalign = MAX (maxalign, objc_alignof_type (type));	  type = objc_skip_typespec (type);	}      return maxalign;    }  }  return 0; /* error */}/*  The aligned size if the size rounded up to the nearest alignment.*/intobjc_aligned_size (const char *type){  int size, align;  /* Skip the variable name */  if (*type == '"')    {      for (type++; *type++ != '"';)	/* do nothing */;    }  size = objc_sizeof_type (type);  align = objc_alignof_type (type);  return ROUND (size, align);}/*  The size rounded up to the nearest integral of the wordsize, taken  to be the size of a void *.*/intobjc_promoted_size (const char *type){  int size, wordsize;  /* Skip the variable name */  if (*type == '"')    {      for (type++; *type++ != '"';)	/* do nothing */;    }  size = objc_sizeof_type (type);  wordsize = sizeof (void *);  return ROUND (size, wordsize);}/*  Skip type qualifiers.  These may eventually precede typespecs  occurring in method prototype encodings.*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?