source: trunk/src/gcc/libobjc/encoding.c@ 2254

Last change on this file since 2254 was 1392, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 21.9 KB
Line 
1/* Encoding of types for Objective C.
2 Copyright (C) 1993, 1995, 1996, 1997, 1998, 2000, 2002
3 Free Software Foundation, Inc.
4 Contributed by Kresten Krab Thorup
5 Bitfield support by Ovidiu Predescu
6
7This file is part of GNU CC.
8
9GNU CC is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2, or (at your option)
12any later version.
13
14GNU CC is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with GNU CC; see the file COPYING. If not, write to
21the Free Software Foundation, 59 Temple Place - Suite 330,
22Boston, MA 02111-1307, USA. */
23
24/* As a special exception, if you link this library with files
25 compiled with GCC to produce an executable, this does not cause
26 the resulting executable to be covered by the GNU General Public License.
27 This exception does not however invalidate any other reasons why
28 the executable file might be covered by the GNU General Public License. */
29
30#include "tconfig.h"
31#include "objc-api.h"
32#include "encoding.h"
33#include <stdlib.h>
34
35#undef MAX
36#define MAX(X, Y) \
37 ({ typeof (X) __x = (X), __y = (Y); \
38 (__x > __y ? __x : __y); })
39
40#undef MIN
41#define MIN(X, Y) \
42 ({ typeof (X) __x = (X), __y = (Y); \
43 (__x < __y ? __x : __y); })
44
45#undef ROUND
46#define ROUND(V, A) \
47 ({ typeof (V) __v = (V); typeof (A) __a = (A); \
48 __a * ((__v+__a - 1)/__a); })
49
50
51/* Various hacks for objc_layout_record. These are used by the target
52 macros. */
53
54#define TREE_CODE(TYPE) *(TYPE)
55#define TREE_TYPE(TREE) (TREE)
56
57#define RECORD_TYPE _C_STRUCT_B
58#define UNION_TYPE _C_UNION_B
59#define QUAL_UNION_TYPE _C_UNION_B
60#define ARRAY_TYPE _C_ARY_B
61
62#define REAL_TYPE _C_DBL
63
64#define VECTOR_TYPE _C_VECTOR
65
66#define TYPE_FIELDS(TYPE) objc_skip_typespec (TYPE)
67
68#define DECL_MODE(TYPE) *(TYPE)
69#define TYPE_MODE(TYPE) *(TYPE)
70
71#define DFmode _C_DBL
72
73#define get_inner_array_type(TYPE) ((TYPE) + 1)
74
75/* Some ports (eg ARM) allow the structure size boundary to be
76 selected at compile-time. We override the normal definition with
77 one that has a constant value for this compilation. */
78#undef STRUCTURE_SIZE_BOUNDARY
79#define STRUCTURE_SIZE_BOUNDARY (BITS_PER_UNIT * sizeof (struct{char a;}))
80
81/* Some ROUND_TYPE_ALIGN macros use TARGET_foo, and consequently
82 target_flags. Define a dummy entry here to so we don't die. */
83/* ??? FIXME: As of 2002-06-21, the attribute `unused' doesn't seem to
84 eliminate the warning. */
85static int __attribute__ ((__unused__)) target_flags = 0;
86
87/*
88 return the size of an object specified by type
89*/
90
91int
92objc_sizeof_type (const char *type)
93{
94 /* Skip the variable name if any */
95 if (*type == '"')
96 {
97 for (type++; *type++ != '"';)
98 /* do nothing */;
99 }
100
101 switch (*type) {
102 case _C_ID:
103 return sizeof (id);
104 break;
105
106 case _C_CLASS:
107 return sizeof (Class);
108 break;
109
110 case _C_SEL:
111 return sizeof (SEL);
112 break;
113
114 case _C_CHR:
115 return sizeof (char);
116 break;
117
118 case _C_UCHR:
119 return sizeof (unsigned char);
120 break;
121
122 case _C_SHT:
123 return sizeof (short);
124 break;
125
126 case _C_USHT:
127 return sizeof (unsigned short);
128 break;
129
130 case _C_INT:
131 return sizeof (int);
132 break;
133
134 case _C_UINT:
135 return sizeof (unsigned int);
136 break;
137
138 case _C_LNG:
139 return sizeof (long);
140 break;
141
142 case _C_ULNG:
143 return sizeof (unsigned long);
144 break;
145
146 case _C_LNG_LNG:
147 return sizeof (long long);
148 break;
149
150 case _C_ULNG_LNG:
151 return sizeof (unsigned long long);
152 break;
153
154 case _C_FLT:
155 return sizeof (float);
156 break;
157
158 case _C_DBL:
159 return sizeof (double);
160 break;
161
162 case _C_VOID:
163 return sizeof (void);
164 break;
165
166 case _C_PTR:
167 case _C_ATOM:
168 case _C_CHARPTR:
169 return sizeof (char *);
170 break;
171
172 case _C_ARY_B:
173 {
174 int len = atoi (type + 1);
175 while (isdigit ((unsigned char)*++type))
176 ;
177 return len * objc_aligned_size (type);
178 }
179 break;
180
181 case _C_BFLD:
182 {
183 /* The new encoding of bitfields is: b 'position' 'type' 'size' */
184 int position, size;
185 int startByte, endByte;
186
187 position = atoi (type + 1);
188 while (isdigit ((unsigned char)*++type))
189 ;
190 size = atoi (type + 1);
191
192 startByte = position / BITS_PER_UNIT;
193 endByte = (position + size) / BITS_PER_UNIT;