Wolfgang Thallergcc16 merge934c3885 months agoHistory
1272 lines · 30.2 KB · C
RawDownload
/* Encoding of types for Objective C.   Copyright (C) 1993-2026 Free Software Foundation, Inc.   Contributed by Kresten Krab Thorup   Bitfield support by Ovidiu Predescu This file is part of GCC. GCC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 3, or (at your option)any later version. GCC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details. Under Section 7 of GPL version 3, you are granted additionalpermissions described in the GCC Runtime Library Exception, version3.1, as published by the Free Software Foundation. You should have received a copy of the GNU General Public License anda copy of the GCC Runtime Library Exception along with this program;see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see<http://www.gnu.org/licenses/>.  */ /* FIXME: This file has no business including tm.h.  */ /* FIXME: This file contains functions that will abort the entire   program if they fail.  Is that really needed ?  */ #include "config.h"#include "objc-private/common.h"#include "objc-private/error.h"#include "tconfig.h"#include "coretypes.h"#include "tm.h"#include "objc/runtime.h"#include "objc-private/module-abi-8.h" /* For struct objc_method */#include <stdlib.h>#include <ctype.h>#include <string.h>                    /* For memcpy.  */ #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); })  /* Various hacks for objc_layout_record. These are used by the target   macros. */ #define TREE_CODE(TYPE) *(TYPE)#define TREE_TYPE(TREE) (TREE) #define RECORD_TYPE     _C_STRUCT_B#define UNION_TYPE      _C_UNION_B#define QUAL_UNION_TYPE _C_UNION_B#define ARRAY_TYPE      _C_ARY_B#define RECORD_OR_UNION_TYPE_P(TYPE)			\	((TREE_CODE (TYPE) == RECORD_TYPE)		\	 || (TREE_CODE (TYPE) == UNION_TYPE)		\	 || (TREE_CODE (TYPE) == QUAL_UNION_TYPE))#define VECTOR_TYPE_P(TYPE) (TREE_CODE (TYPE) == VECTOR_TYPE) #define REAL_TYPE       _C_DBL #define VECTOR_TYPE	_C_VECTOR #define TYPE_FIELDS(TYPE)           ({const char *_field = (TYPE)+1; \    while (*_field != _C_STRUCT_E && *_field != _C_STRUCT_B \           && *_field != _C_UNION_B && *_field++ != '=') \    /* do nothing */; \    _field;}) #define DECL_MODE(TYPE) *(TYPE)#define TYPE_MODE(TYPE) *(TYPE) #undef  DFmode#define DFmode          _C_DBL #define strip_array_types(TYPE)      ({const char *_field = (TYPE); \  while (*_field == _C_ARY_B)\    {\      while (isdigit ((unsigned char)*++_field))\	;\    }\    _field;}) /* Some ports (eg ARM) allow the structure size boundary to be   selected at compile-time.  We override the normal definition with   one that has a constant value for this compilation.  */#undef  STRUCTURE_SIZE_BOUNDARY#define STRUCTURE_SIZE_BOUNDARY (__CHAR_BIT__ * sizeof (struct{char a;})) /* Some ROUND_TYPE_ALIGN macros use TARGET_foo, and consequently   target_flags.  Define a dummy entry here to so we don't die.   We have to rename it because target_flags may already have been   declared extern.  */#define target_flags not_target_flagsstatic int __attribute__ ((__unused__)) not_target_flags = 0; /* Some ROUND_TYPE_ALIGN use ALTIVEC_VECTOR_MODE (rs6000 darwin).   Define a dummy ALTIVEC_VECTOR_MODE so it will not die.  */#undef ALTIVEC_VECTOR_MODE#define ALTIVEC_VECTOR_MODE(MODE) (0) /* Replace TARGET_VSX, TARGET_ALTIVEC, and TARGET_64BIT with constants based on   the current switches, rather than looking in the options structure.  */#ifdef _ARCH_PPC#undef TARGET_VSX#undef TARGET_ALTIVEC#undef TARGET_64BIT #ifdef __VSX__#define TARGET_VSX 1#else#define TARGET_VSX 0#endif #ifdef __ALTIVEC__#define TARGET_ALTIVEC 1#else#define TARGET_ALTIVEC 0#endif #ifdef _ARCH_PPC64#define TARGET_64BIT 1#else#define TARGET_64BIT 0#endif#endif /* Furthermore, some (powerpc) targets also use TARGET_ALIGN_NATURAL in their alignment macros. Currently[4.5/6], rs6000.h points this to a static variable, initialized by target overrides. This is reset in linux64.h but not in darwin64.h.  The macro is not used by *86*.  */ #if __MACH__ # if __LP64__#  undef TARGET_ALIGN_NATURAL#  define TARGET_ALIGN_NATURAL 1# endif/* On Darwin32, we need to recurse until we find the starting struct type.  */static int _darwin_rs6000_special_round_type_align (const char *struc, int comp, int spec){  const char *_stp , *_fields = TYPE_FIELDS (struc);  if (!_fields)    return MAX (comp, spec);  _stp = strip_array_types (_fields);  if (TYPE_MODE(_stp) == _C_COMPLEX)   _stp++;  switch (TYPE_MODE(_stp))    {      case RECORD_TYPE:      case UNION_TYPE:	return MAX (MAX (comp, spec), objc_alignof_type (_stp) * __CHAR_BIT__);	break;      case DFmode:      case _C_LNG_LNG:      case _C_ULNG_LNG:	return MAX (MAX (comp, spec), 64);	break;       default:	return MAX (comp, spec);	break;    }} /* See comment below.  */#define darwin_rs6000_special_round_type_align(S,C,S2)			\  (_darwin_rs6000_special_round_type_align ((char*)(S), (int)(C), (int)(S2)))#endif /*  FIXME: while this file has no business including tm.h, this    definitely has no business defining this macro but it    is only way around without really rewriting this file,    should look after the branch of 3.4 to fix this.   */#define rs6000_special_round_type_align(STRUCT, COMPUTED, SPECIFIED)	\  ({ const char *_fields = TYPE_FIELDS (STRUCT);			\  ((_fields != 0							\    && TYPE_MODE (strip_array_types (TREE_TYPE (_fields))) == DFmode)	\   ? MAX (MAX (COMPUTED, SPECIFIED), 64)				\   : MAX (COMPUTED, SPECIFIED));}) #define rs6000_special_adjust_field_align_p(FIELD, COMPUTED) 0 /* Skip a variable name, enclosed in quotes (").  */static inlineconst char *objc_skip_variable_name (const char *type){  /* Skip the variable name if any.  */  if (*type == '"')    {      /* FIXME: How do we know we won't read beyond the end of the	 string.  Here and in the rest of the file!  */      /* Skip '"'.  */      type++;      /* Skip to the next '"'.  */      while (*type != '"')	type++;      /* Skip '"'.  */      type++;    }   return type;} intobjc_sizeof_type (const char *type){  type = objc_skip_variable_name (type);   switch (*type) {  case _C_BOOL:    return sizeof (_Bool);    break;   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_LNG_DBL:    return sizeof (long 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_VECTOR:    {      /* Skip the '!'.  */      type++;      /* Skip the '['.  */      type++;       /* The size in bytes is the following number.  */      int size = atoi (type);      return size;    }    break;   case _C_BFLD:    {      /* The GNU encoding of bitfields is: b 'position' 'type'	 'size'.  */      int position, size;      int startByte, endByte;       position = atoi (type + 1);      while (isdigit ((unsigned char)*++type))	;      size = atoi (type + 1);       startByte = position / __CHAR_BIT__;      endByte = (position + size) / __CHAR_BIT__;      return endByte - startByte;    }   case _C_UNION_B:  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_COMPLEX:    {      type++; /* Skip after the 'j'. */      switch (*type)        {	    case _C_CHR:	      return sizeof (_Complex char);	      break; 	    case _C_UCHR:	      return sizeof (_Complex unsigned char);	      break; 	    case _C_SHT:	      return sizeof (_Complex short);	      break; 	    case _C_USHT:	      return sizeof (_Complex unsigned short);	      break; 	    case _C_INT:	      return sizeof (_Complex int);	      break; 	    case _C_UINT:	      return sizeof (_Complex unsigned int);	      break; 	    case _C_LNG:	      return sizeof (_Complex long);	      break; 	    case _C_ULNG:	      return sizeof (_Complex unsigned long);	      break; 	    case _C_LNG_LNG:	      return sizeof (_Complex long long);	      break; 	    case _C_ULNG_LNG:	      return sizeof (_Complex unsigned long long);	      break; 	    case _C_FLT:	      return sizeof (_Complex float);	      break; 	    case _C_DBL:	      return sizeof (_Complex double);	      break; 	    case _C_LNG_DBL:	      return sizeof (_Complex long double);	      break;	    	    default:	      {		/* FIXME: Is this so bad that we have to abort the		   entire program ?  (it applies to all the other		   _objc_abort calls in this file).		*/		_objc_abort ("unknown complex type %s\n", type);		return 0;	      }	}    }   default:    {      _objc_abort ("unknown type %s\n", type);      return 0;    }  }} intobjc_alignof_type (const char *type){  type = objc_skip_variable_name (type);   switch (*type) {  case _C_BOOL:    return __alignof__ (_Bool);    break;   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:    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;

Lines 1–500 of 1272.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t