1 /* Encoding of types for Objective C.
2 Copyright (C) 1993, 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2009
3 Free Software Foundation, Inc.
4 Contributed by Kresten Krab Thorup
5 Bitfield support by Ovidiu Predescu
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
28 /* FIXME: This file has no business including tm.h. */
30 /* FIXME: This file contains functions that will abort the entire
31 program if they fail. Is that really needed ? */
33 #include "objc-private/common.h"
34 #include "objc-private/error.h"
36 #include "coretypes.h"
38 #include "objc/runtime.h"
39 #include "objc-private/module-abi-8.h" /* For struct objc_method */
42 #include <string.h> /* For memcpy. */
46 ({ typeof (X) __x = (X), __y = (Y); \
47 (__x > __y ? __x : __y); })
51 ({ typeof (X) __x = (X), __y = (Y); \
52 (__x < __y ? __x : __y); })
56 ({ typeof (V) __v = (V); typeof (A) __a = (A); \
57 __a * ((__v+__a - 1)/__a); })
60 /* Various hacks for objc_layout_record. These are used by the target
63 #define TREE_CODE(TYPE) *(TYPE)
64 #define TREE_TYPE(TREE) (TREE)
66 #define RECORD_TYPE _C_STRUCT_B
67 #define UNION_TYPE _C_UNION_B
68 #define QUAL_UNION_TYPE _C_UNION_B
69 #define ARRAY_TYPE _C_ARY_B
71 #define REAL_TYPE _C_DBL
73 #define VECTOR_TYPE _C_VECTOR
75 #define TYPE_FIELDS(TYPE) ({const char *_field = (TYPE)+1; \
76 while (*_field != _C_STRUCT_E && *_field != _C_STRUCT_B \
77 && *_field != _C_UNION_B && *_field++ != '=') \
81 #define DECL_MODE(TYPE) *(TYPE)
82 #define TYPE_MODE(TYPE) *(TYPE)
86 #define strip_array_types(TYPE) ({const char *_field = (TYPE); \
87 while (*_field == _C_ARY_B)\
89 while (isdigit ((unsigned char)*++_field))\
94 /* Some ports (eg ARM) allow the structure size boundary to be
95 selected at compile-time. We override the normal definition with
96 one that has a constant value for this compilation. */
98 #define BITS_PER_UNIT 8
100 #undef STRUCTURE_SIZE_BOUNDARY
101 #define STRUCTURE_SIZE_BOUNDARY (BITS_PER_UNIT * sizeof (struct{char a;}))
103 /* Some ROUND_TYPE_ALIGN macros use TARGET_foo, and consequently
104 target_flags. Define a dummy entry here to so we don't die.
105 We have to rename it because target_flags may already have been
107 #define target_flags not_target_flags
108 static int __attribute__ ((__unused__
)) not_target_flags
= 0;
110 /* Some ROUND_TYPE_ALIGN use ALTIVEC_VECTOR_MODE (rs6000 darwin).
111 Define a dummy ALTIVEC_VECTOR_MODE so it will not die. */
112 #undef ALTIVEC_VECTOR_MODE
113 #define ALTIVEC_VECTOR_MODE(MODE) (0)
115 /* Furthermore, some (powerpc) targets also use TARGET_ALIGN_NATURAL
116 in their alignment macros. Currently[4.5/6], rs6000.h points this
117 to a static variable, initialized by target overrides. This is reset
118 in linux64.h but not in darwin64.h. The macro is not used by *86*. */
120 #if __MACH__ && __LP64__
121 # undef TARGET_ALIGN_NATURAL
122 # define TARGET_ALIGN_NATURAL 1
125 /* FIXME: while this file has no business including tm.h, this
126 definitely has no business defining this macro but it
127 is only way around without really rewritting this file,
128 should look after the branch of 3.4 to fix this.
129 FIXME1: It's also out of date, darwin no longer has the same alignment
130 'special' as aix - this is probably the origin of the m32 breakage. */
131 #define rs6000_special_round_type_align(STRUCT, COMPUTED, SPECIFIED) \
132 ({ const char *_fields = TYPE_FIELDS (STRUCT); \
134 && TYPE_MODE (strip_array_types (TREE_TYPE (_fields))) == DFmode) \
135 ? MAX (MAX (COMPUTED, SPECIFIED), 64) \
136 : MAX (COMPUTED, SPECIFIED));})
137 /* FIXME: The word 'fixme' is insufficient to explain the wrong-ness
138 of this next macro definition. */
139 #define darwin_rs6000_special_round_type_align(S,C,S2) \
140 rs6000_special_round_type_align(S,C,S2)
143 /* Skip a variable name, enclosed in quotes ("). */
146 objc_skip_variable_name (const char *type
)
148 /* Skip the variable name if any. */
151 /* FIXME: How do we know we won't read beyond the end of the
152 string. Here and in the rest of the file! */
155 /* Skip to the next '"'. */
166 objc_sizeof_type (const char *type
)
168 type
= objc_skip_variable_name (type
);
172 return sizeof (_Bool
);
180 return sizeof (Class
);
188 return sizeof (char);
192 return sizeof (unsigned char);
196 return sizeof (short);
200 return sizeof (unsigned short);
208 return sizeof (unsigned int);
212 return sizeof (long);
216 return sizeof (unsigned long);
220 return sizeof (long long);
224 return sizeof (unsigned long long);
228 return sizeof (float);
232 return sizeof (double);
236 return sizeof (long double);
240 return sizeof (void);
246 return sizeof (char *);
251 int len
= atoi (type
+ 1);
252 while (isdigit ((unsigned char)*++type
))
254 return len
* objc_aligned_size (type
);
265 /* The size in bytes is the following number. */
266 int size
= atoi (type
);
273 /* The GNU encoding of bitfields is: b 'position' 'type'
276 int startByte
, endByte
;
278 position
= atoi (type
+ 1);
279 while (isdigit ((unsigned char)*++type
))
281 size
= atoi (type
+ 1);
283 startByte
= position
/ BITS_PER_UNIT
;
284 endByte
= (position
+ size
) / BITS_PER_UNIT
;
285 return endByte
- startByte
;
291 struct objc_struct_layout layout
;
294 objc_layout_structure (type
, &layout
);
295 while (objc_layout_structure_next_member (&layout
))
297 objc_layout_finish_structure (&layout
, &size
, NULL
);
304 type
++; /* Skip after the 'j'. */
308 return sizeof (_Complex
char);
312 return sizeof (_Complex
unsigned char);
316 return sizeof (_Complex
short);
320 return sizeof (_Complex
unsigned short);
324 return sizeof (_Complex
int);
328 return sizeof (_Complex
unsigned int);
332 return sizeof (_Complex
long);
336 return sizeof (_Complex
unsigned long);
340 return sizeof (_Complex
long long);
344 return sizeof (_Complex
unsigned long long);
348 return sizeof (_Complex
float);
352 return sizeof (_Complex
double);
356 return sizeof (_Complex
long double);
361 /* FIXME: Is this so bad that we have to abort the
362 entire program ? (it applies to all the other
363 _objc_abort calls in this file).
365 _objc_abort ("unknown complex type %s\n", type
);
373 _objc_abort ("unknown type %s\n", type
);
380 objc_alignof_type (const char *type
)
382 type
= objc_skip_variable_name (type
);
386 return __alignof__ (_Bool
);
390 return __alignof__ (id
);
394 return __alignof__ (Class
);
398 return __alignof__ (SEL
);
402 return __alignof__ (char);
406 return __alignof__ (unsigned char);
410 return __alignof__ (short);
414 return __alignof__ (unsigned short);
418 return __alignof__ (int);
422 return __alignof__ (unsigned int);
426 return __alignof__ (long);
430 return __alignof__ (unsigned long);
434 return __alignof__ (long long);
438 return __alignof__ (unsigned long long);
442 return __alignof__ (float);
446 return __alignof__ (double);
450 return __alignof__ (long double);
456 return __alignof__ (char *);
460 while (isdigit ((unsigned char)*++type
))
462 return objc_alignof_type (type
);
472 while (isdigit ((unsigned char)*type
))
478 /* The alignment in bytes is the following number. */
484 struct objc_struct_layout layout
;
487 objc_layout_structure (type
, &layout
);
488 while (objc_layout_structure_next_member (&layout
))
490 objc_layout_finish_structure (&layout
, NULL
, &align
);
498 type
++; /* Skip after the 'j'. */
502 return __alignof__ (_Complex
char);
506 return __alignof__ (_Complex
unsigned char);
510 return __alignof__ (_Complex
short);
514 return __alignof__ (_Complex
unsigned short);
518 return __alignof__ (_Complex
int);
522 return __alignof__ (_Complex
unsigned int);
526 return __alignof__ (_Complex
long);
530 return __alignof__ (_Complex
unsigned long);
534 return __alignof__ (_Complex
long long);
538 return __alignof__ (_Complex
unsigned long long);
542 return __alignof__ (_Complex
float);
546 return __alignof__ (_Complex
double);
550 return __alignof__ (_Complex
long double);
555 _objc_abort ("unknown complex type %s\n", type
);
563 _objc_abort ("unknown type %s\n", type
);
570 objc_aligned_size (const char *type
)
574 type
= objc_skip_variable_name (type
);
575 size
= objc_sizeof_type (type
);
576 align
= objc_alignof_type (type
);
578 return ROUND (size
, align
);
582 objc_promoted_size (const char *type
)
586 type
= objc_skip_variable_name (type
);
587 size
= objc_sizeof_type (type
);
588 wordsize
= sizeof (void *);
590 return ROUND (size
, wordsize
);
595 objc_skip_type_qualifiers (const char *type
)
597 while (*type
== _C_CONST
601 || *type
== _C_BYCOPY
603 || *type
== _C_ONEWAY
604 || *type
== _C_GCINVISIBLE
)
613 objc_skip_typespec (const char *type
)
615 type
= objc_skip_variable_name (type
);
616 type
= objc_skip_type_qualifiers (type
);
621 /* An id may be annotated by the actual type if it is known
622 with the @"ClassName" syntax */
628 while (*++type
!= '"')
633 /* The following are one character type codes */
662 /* skip digits, typespec and closing ']' */
663 while (isdigit ((unsigned char)*++type
))
665 type
= objc_skip_typespec (type
);
666 if (*type
== _C_ARY_E
)
670 _objc_abort ("bad array type %s\n", type
);
679 /* Skip digits (size) */
680 while (isdigit ((unsigned char)*type
))
684 /* Skip digits (alignment) */
685 while (isdigit ((unsigned char)*type
))
688 type
= objc_skip_typespec (type
);
689 /* Skip closing ']'. */
690 if (*type
== _C_ARY_E
)
694 _objc_abort ("bad vector type %s\n", type
);
699 /* The GNU encoding of bitfields is: b 'position' 'type'
701 while (isdigit ((unsigned char)*++type
))
702 ; /* skip position */
703 while (isdigit ((unsigned char)*++type
))
704 ; /* skip type and size */
708 /* skip name, and elements until closing '}' */
710 while (*type
!= _C_STRUCT_E
&& *type
++ != '=')
712 while (*type
!= _C_STRUCT_E
)
714 type
= objc_skip_typespec (type
);
719 /* skip name, and elements until closing ')' */
721 while (*type
!= _C_UNION_E
&& *type
++ != '=')
723 while (*type
!= _C_UNION_E
)
725 type
= objc_skip_typespec (type
);
730 /* Just skip the following typespec */
732 return objc_skip_typespec (++type
);
736 _objc_abort ("unknown type %s\n", type
);
744 objc_skip_offset (const char *type
)
746 /* The offset is prepended by a '+' if the argument is passed in
747 registers. PS: The compiler stopped generating this '+' in
752 /* Some people claim that on some platforms, where the stack grows
753 backwards, the compiler generates negative offsets (??). Skip a
754 '-' for such a negative offset. */
758 /* Skip the digits that represent the offset. */
759 while (isdigit ((unsigned char) *type
))
766 objc_skip_argspec (const char *type
)
768 type
= objc_skip_typespec (type
);
769 type
= objc_skip_offset (type
);
774 method_copyReturnType (struct objc_method
*method
)
781 size_t returnValueSize
;
783 /* Determine returnValueSize. */
785 /* Find the end of the first argument. We want to return the
786 first argument spec, plus 1 byte for the \0 at the end. */
787 const char *type
= method
->method_types
;
790 type
= objc_skip_argspec (type
);
791 returnValueSize
= type
- method
->method_types
+ 1;
794 /* Copy the first argument into returnValue. */
795 returnValue
= malloc (sizeof (char) * returnValueSize
);
796 memcpy (returnValue
, method
->method_types
, returnValueSize
);
797 returnValue
[returnValueSize
- 1] = '\0';
804 method_copyArgumentType (struct objc_method
* method
, unsigned int argumentNumber
)
811 const char *returnValueStart
;
812 size_t returnValueSize
;
814 /* Determine returnValueStart and returnValueSize. */
816 const char *type
= method
->method_types
;
818 /* Skip the first argument (return type). */
819 type
= objc_skip_argspec (type
);
821 /* Now keep skipping arguments until we get to
823 while (argumentNumber
> 0)
825 /* We are supposed to skip an argument, but the string is
826 finished. This means we were asked for a non-existing
831 type
= objc_skip_argspec (type
);
835 /* If the argument does not exist, return NULL. */
839 returnValueStart
= type
;
840 type
= objc_skip_argspec (type
);
841 returnValueSize
= type
- returnValueStart
+ 1;
844 /* Copy the argument into returnValue. */
845 returnValue
= malloc (sizeof (char) * returnValueSize
);
846 memcpy (returnValue
, returnValueStart
, returnValueSize
);
847 returnValue
[returnValueSize
- 1] = '\0';
853 void method_getReturnType (struct objc_method
* method
, char *returnValue
,
854 size_t returnValueSize
)
856 if (returnValue
== NULL
|| returnValueSize
== 0)
859 /* Zero the string; we'll then write the argument type at the
860 beginning of it, if needed. */
861 memset (returnValue
, 0, returnValueSize
);
867 size_t argumentTypeSize
;
869 /* Determine argumentTypeSize. */
871 /* Find the end of the first argument. We want to return the
872 first argument spec. */
873 const char *type
= method
->method_types
;
876 type
= objc_skip_argspec (type
);
877 argumentTypeSize
= type
- method
->method_types
;
878 if (argumentTypeSize
> returnValueSize
)
879 argumentTypeSize
= returnValueSize
;
881 /* Copy the argument at the beginning of the string. */
882 memcpy (returnValue
, method
->method_types
, argumentTypeSize
);
886 void method_getArgumentType (struct objc_method
* method
, unsigned int argumentNumber
,
887 char *returnValue
, size_t returnValueSize
)
889 if (returnValue
== NULL
|| returnValueSize
== 0)
892 /* Zero the string; we'll then write the argument type at the
893 beginning of it, if needed. */
894 memset (returnValue
, 0, returnValueSize
);
900 const char *returnValueStart
;
901 size_t argumentTypeSize
;
903 /* Determine returnValueStart and argumentTypeSize. */
905 const char *type
= method
->method_types
;
907 /* Skip the first argument (return type). */
908 type
= objc_skip_argspec (type
);
910 /* Now keep skipping arguments until we get to
912 while (argumentNumber
> 0)
914 /* We are supposed to skip an argument, but the string is
915 finished. This means we were asked for a non-existing
920 type
= objc_skip_argspec (type
);
924 /* If the argument does not exist, it's game over. */
928 returnValueStart
= type
;
929 type
= objc_skip_argspec (type
);
930 argumentTypeSize
= type
- returnValueStart
;
931 if (argumentTypeSize
> returnValueSize
)
932 argumentTypeSize
= returnValueSize
;
934 /* Copy the argument at the beginning of the string. */
935 memcpy (returnValue
, returnValueStart
, argumentTypeSize
);
940 method_getNumberOfArguments (struct objc_method
*method
)
947 const char *type
= method
->method_types
;
950 type
= objc_skip_argspec (type
);
956 /* This could only happen if method_types is invalid; in
957 that case, return 0. */
962 /* Remove the return type. */
969 method_get_number_of_arguments (struct objc_method
*mth
)
971 return method_getNumberOfArguments (mth
);
974 /* Return the size of the argument block needed on the stack to invoke
975 the method MTH. This may be zero, if all arguments are passed in
978 method_get_sizeof_arguments (struct objc_method
*mth
)
980 const char *type
= objc_skip_typespec (mth
->method_types
);
985 Return a pointer to the next argument of ARGFRAME. type points to
986 the last argument. Typical use of this look like:
990 for (datum = method_get_first_argument (method, argframe, &type);
991 datum; datum = method_get_next_argument (argframe, &type))
993 unsigned flags = objc_get_type_qualifiers (type);
994 type = objc_skip_type_qualifiers (type);
996 [portal encodeData: datum ofType: type];
999 if ((flags & _F_IN) == _F_IN)
1000 [portal encodeData: *(char **) datum ofType: ++type];
1006 method_get_next_argument (arglist_t argframe
, const char **type
)
1008 const char *t
= objc_skip_argspec (*type
);
1014 t
= objc_skip_typespec (t
);
1017 return argframe
->arg_regs
+ atoi (++t
);
1019 return argframe
->arg_ptr
+ atoi (t
);
1022 /* Return a pointer to the value of the first argument of the method
1023 described in M with the given argumentframe ARGFRAME. The type
1024 is returned in TYPE. type must be passed to successive calls of
1025 method_get_next_argument. */
1027 method_get_first_argument (struct objc_method
*m
,
1031 *type
= m
->method_types
;
1032 return method_get_next_argument (argframe
, type
);
1035 /* Return a pointer to the ARGth argument of the method
1036 M from the frame ARGFRAME. The type of the argument
1037 is returned in the value-result argument TYPE. */
1039 method_get_nth_argument (struct objc_method
*m
,
1040 arglist_t argframe
, int arg
,
1043 const char *t
= objc_skip_argspec (m
->method_types
);
1045 if (arg
> method_get_number_of_arguments (m
))
1049 t
= objc_skip_argspec (t
);
1052 t
= objc_skip_typespec (t
);
1055 return argframe
->arg_regs
+ atoi (++t
);
1057 return argframe
->arg_ptr
+ atoi (t
);
1061 objc_get_type_qualifiers (const char *type
)
1069 case _C_CONST
: res
|= _F_CONST
; break;
1070 case _C_IN
: res
|= _F_IN
; break;
1071 case _C_INOUT
: res
|= _F_INOUT
; break;
1072 case _C_OUT
: res
|= _F_OUT
; break;
1073 case _C_BYCOPY
: res
|= _F_BYCOPY
; break;
1074 case _C_BYREF
: res
|= _F_BYREF
; break;
1075 case _C_ONEWAY
: res
|= _F_ONEWAY
; break;
1076 case _C_GCINVISIBLE
: res
|= _F_GCINVISIBLE
; break;
1083 /* The following three functions can be used to determine how a
1084 structure is laid out by the compiler. For example:
1086 struct objc_struct_layout layout;
1089 objc_layout_structure (type, &layout);
1090 while (objc_layout_structure_next_member (&layout))
1092 int position, align;
1095 objc_layout_structure_get_info (&layout, &position, &align, &type);
1096 printf ("element %d has offset %d, alignment %d\n",
1097 i++, position, align);
1100 These functions are used by objc_sizeof_type and objc_alignof_type
1101 functions to compute the size and alignment of structures. The
1102 previous method of computing the size and alignment of a structure
1103 was not working on some architectures, particulary on AIX, and in
1104 the presence of bitfields inside the structure. */
1106 objc_layout_structure (const char *type
,
1107 struct objc_struct_layout
*layout
)
1111 if (*type
!= _C_UNION_B
&& *type
!= _C_STRUCT_B
)
1113 _objc_abort ("record (or union) type expected in objc_layout_structure, got %s\n",
1118 layout
->original_type
= type
;
1120 /* Skip "<name>=" if any. Avoid embedded structures and unions. */
1122 while (*ntype
!= _C_STRUCT_E
&& *ntype
!= _C_STRUCT_B
&& *ntype
!= _C_UNION_B
1126 /* If there's a "<name>=", ntype - 1 points to '='; skip the the name */
1127 if (*(ntype
- 1) == '=')
1130 layout
->type
= type
;
1131 layout
->prev_type
= NULL
;
1132 layout
->record_size
= 0;
1133 layout
->record_align
= BITS_PER_UNIT
;
1135 layout
->record_align
= MAX (layout
->record_align
, STRUCTURE_SIZE_BOUNDARY
);
1139 objc_layout_structure_next_member (struct objc_struct_layout
*layout
)
1141 register int desired_align
= 0;
1143 /* The following are used only if the field is a bitfield */
1144 register const char *bfld_type
= 0;
1145 register int bfld_type_align
= 0, bfld_field_size
= 0;
1147 /* The current type without the type qualifiers */
1149 BOOL unionp
= layout
->original_type
[-1] == _C_UNION_B
;
1151 /* Add the size of the previous field to the size of the record. */
1152 if (layout
->prev_type
)
1154 type
= objc_skip_type_qualifiers (layout
->prev_type
);
1156 layout
->record_size
= MAX (layout
->record_size
,
1157 objc_sizeof_type (type
) * BITS_PER_UNIT
);
1159 else if (*type
!= _C_BFLD
)
1160 layout
->record_size
+= objc_sizeof_type (type
) * BITS_PER_UNIT
;
1162 /* Get the bitfield's type */
1163 for (bfld_type
= type
+ 1;
1164 isdigit ((unsigned char)*bfld_type
);
1168 bfld_type_align
= objc_alignof_type (bfld_type
) * BITS_PER_UNIT
;
1169 bfld_field_size
= atoi (objc_skip_typespec (bfld_type
));
1170 layout
->record_size
+= bfld_field_size
;
1174 if ((unionp
&& *layout
->type
== _C_UNION_E
)
1175 || (!unionp
&& *layout
->type
== _C_STRUCT_E
))
1178 /* Skip the variable name if any */
1179 layout
->type
= objc_skip_variable_name (layout
->type
);
1180 type
= objc_skip_type_qualifiers (layout
->type
);
1182 if (*type
!= _C_BFLD
)
1183 desired_align
= objc_alignof_type (type
) * BITS_PER_UNIT
;
1187 /* Skip the bitfield's offset */
1188 for (bfld_type
= type
+ 1;
1189 isdigit ((unsigned char) *bfld_type
);
1193 bfld_type_align
= objc_alignof_type (bfld_type
) * BITS_PER_UNIT
;
1194 bfld_field_size
= atoi (objc_skip_typespec (bfld_type
));
1197 /* The following won't work for vectors. */
1198 #ifdef BIGGEST_FIELD_ALIGNMENT
1199 desired_align
= MIN (desired_align
, BIGGEST_FIELD_ALIGNMENT
);
1201 #ifdef ADJUST_FIELD_ALIGN
1202 desired_align
= ADJUST_FIELD_ALIGN (type
, desired_align
);
1205 /* Record must have at least as much alignment as any field.
1206 Otherwise, the alignment of the field within the record
1208 #ifndef PCC_BITFIELD_TYPE_MATTERS
1209 layout
->record_align
= MAX (layout
->record_align
, desired_align
);
1210 #else /* PCC_BITFIELD_TYPE_MATTERS */
1211 if (*type
== _C_BFLD
)
1213 /* For these machines, a zero-length field does not
1214 affect the alignment of the structure as a whole.
1215 It does, however, affect the alignment of the next field
1216 within the structure. */
1217 if (bfld_field_size
)
1218 layout
->record_align
= MAX (layout
->record_align
, desired_align
);
1220 desired_align
= objc_alignof_type (bfld_type
) * BITS_PER_UNIT
;
1222 /* A named bit field of declared type `int'
1223 forces the entire structure to have `int' alignment.
1224 Q1: How is encoded this thing and how to check for it?
1225 Q2: How to determine maximum_field_alignment at runtime? */
1227 /* if (DECL_NAME (field) != 0) */
1229 int type_align
= bfld_type_align
;
1231 if (maximum_field_alignment
!= 0)
1232 type_align
= MIN (type_align
, maximum_field_alignment
);
1233 else if (DECL_PACKED (field
))
1234 type_align
= MIN (type_align
, BITS_PER_UNIT
);
1237 layout
->record_align
= MAX (layout
->record_align
, type_align
);
1241 layout
->record_align
= MAX (layout
->record_align
, desired_align
);
1242 #endif /* PCC_BITFIELD_TYPE_MATTERS */
1244 /* Does this field automatically have alignment it needs
1245 by virtue of the fields that precede it and the record's
1248 if (*type
== _C_BFLD
)
1249 layout
->record_size
= atoi (type
+ 1);
1250 else if (layout
->record_size
% desired_align
!= 0)
1252 /* No, we need to skip space before this field.
1253 Bump the cumulative size to multiple of field alignment. */
1254 layout
->record_size
= ROUND (layout
->record_size
, desired_align
);
1257 /* Jump to the next field in record. */
1259 layout
->prev_type
= layout
->type
;
1260 layout
->type
= objc_skip_typespec (layout
->type
); /* skip component */
1265 void objc_layout_finish_structure (struct objc_struct_layout
*layout
,
1267 unsigned int *align
)
1269 BOOL unionp
= layout
->original_type
[-1] == _C_UNION_B
;
1271 && ((!unionp
&& *layout
->type
== _C_STRUCT_E
)
1272 || (unionp
&& *layout
->type
== _C_UNION_E
)))
1274 /* Work out the alignment of the record as one expression and store
1275 in the record type. Round it up to a multiple of the record's
1277 #if defined (ROUND_TYPE_ALIGN) && ! defined (__sparc__)
1278 layout
->record_align
= ROUND_TYPE_ALIGN (layout
->original_type
-1,
1280 layout
->record_align
);
1282 layout
->record_align
= MAX (1, layout
->record_align
);
1285 #ifdef ROUND_TYPE_SIZE
1286 layout
->record_size
= ROUND_TYPE_SIZE (layout
->original_type
,
1287 layout
->record_size
,
1288 layout
->record_align
);
1290 /* Round the size up to be a multiple of the required alignment */
1291 layout
->record_size
= ROUND (layout
->record_size
, layout
->record_align
);
1294 layout
->type
= NULL
;
1297 *size
= layout
->record_size
/ BITS_PER_UNIT
;
1299 *align
= layout
->record_align
/ BITS_PER_UNIT
;
1302 void objc_layout_structure_get_info (struct objc_struct_layout
*layout
,
1303 unsigned int *offset
,
1304 unsigned int *align
,
1308 *offset
= layout
->record_size
/ BITS_PER_UNIT
;
1310 *align
= layout
->record_align
/ BITS_PER_UNIT
;
1312 *type
= layout
->prev_type
;