1 /*****************************************************************************/
5 /* Type string handling for the cc65 C compiler */
9 /* (C) 1998 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
45 /*****************************************************************************/
47 /*****************************************************************************/
59 T_TYPE_SHORT = 0x0002,
62 T_TYPE_LONGLONG = 0x0005,
64 T_TYPE_FLOAT = 0x0007,
65 T_TYPE_DOUBLE = 0x0008,
67 T_TYPE_STRUCT = 0x000A,
68 T_TYPE_UNION = 0x000B,
69 T_TYPE_ARRAY = 0x000C,
75 T_CLASS_NONE = 0x0000,
77 T_CLASS_FLOAT = 0x0040,
79 T_CLASS_STRUCT = 0x0080,
80 T_CLASS_FUNC = 0x00A0,
81 T_MASK_CLASS = 0x00E0,
85 T_SIGN_UNSIGNED = 0x0100,
86 T_SIGN_SIGNED = 0x0200,
89 // Type size modifiers
91 T_SIZE_SHORT = 0x0400,
93 T_SIZE_LONGLONG = 0x0C00,
98 T_QUAL_CONST = 0x1000,
99 T_QUAL_VOLATILE = 0x2000,
100 T_MASK_QUAL = 0x3000,
103 T_CHAR = T_TYPE_CHAR | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_NONE,
104 T_SCHAR = T_TYPE_CHAR | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_NONE,
105 T_UCHAR = T_TYPE_CHAR | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_NONE,
106 T_SHORT = T_TYPE_SHORT | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_SHORT,
107 T_USHORT = T_TYPE_SHORT | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_SHORT,
108 T_INT = T_TYPE_INT | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_NONE,
109 T_UINT = T_TYPE_INT | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_NONE,
110 T_LONG = T_TYPE_LONG | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_LONG,
111 T_ULONG = T_TYPE_LONG | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_LONG,
112 T_LONGLONG = T_TYPE_LONGLONG | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_LONGLONG,
113 T_ULONGLONG = T_TYPE_LONGLONG | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_LONGLONG,
114 T_ENUM = T_TYPE_ENUM | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_NONE,
115 T_FLOAT = T_TYPE_FLOAT | T_CLASS_FLOAT | T_SIGN_NONE | T_SIZE_NONE,
116 T_DOUBLE = T_TYPE_DOUBLE | T_CLASS_FLOAT | T_SIGN_NONE | T_SIZE_NONE,
117 T_VOID = T_TYPE_VOID | T_CLASS_NONE | T_SIGN_NONE | T_SIZE_NONE,
118 T_STRUCT = T_TYPE_STRUCT | T_CLASS_STRUCT | T_SIGN_NONE | T_SIZE_NONE,
119 T_UNION = T_TYPE_UNION | T_CLASS_STRUCT | T_SIGN_NONE | T_SIZE_NONE,
120 T_ARRAY = T_TYPE_ARRAY | T_CLASS_PTR | T_SIGN_NONE | T_SIZE_NONE,
121 T_PTR = T_TYPE_PTR | T_CLASS_PTR | T_SIGN_NONE | T_SIZE_NONE,
122 T_FUNC = T_TYPE_FUNC | T_CLASS_FUNC | T_SIGN_NONE | T_SIZE_NONE,
128 /* Forward for a symbol entry */
132 typedef unsigned short type;
134 /* Maximum length of a type string */
135 #define MAXTYPELEN 30
137 /* type elements needed for Encode/Decode */
138 #define DECODE_SIZE 5
140 /* Predefined type strings */
141 extern type type_int [];
142 extern type type_uint [];
143 extern type type_long [];
144 extern type type_ulong [];
145 extern type type_void [];
146 extern type type_pschar [];
147 extern type type_puchar [];
151 /*****************************************************************************/
153 /*****************************************************************************/
157 unsigned TypeLen (const type* Type);
158 /* Return the length of the type string */
160 int TypeCmp (const type* T1, const type* T2);
161 /* Compare two type strings */
163 type* TypeCpy (type* Dest, const type* Src);
164 /* Copy a type string */
166 type* TypeCat (type* Dest, const type* Src);
169 type* TypeDup (const type* Type);
170 /* Create a copy of the given type on the heap */
172 type* TypeAlloc (unsigned Len);
173 /* Allocate memory for a type string of length Len. Len *must* include the
177 void TypeFree (type* Type);
178 /* Free a type string */
180 type GetDefaultChar (void);
181 /* Return the default char type (signed/unsigned) depending on the settings */
183 type* GetCharArrayType (unsigned Len);
184 /* Return the type for a char array of the given length */
186 type* GetImplicitFuncType (void);
187 /* Return a type string for an inplicitly declared function */
189 void PrintType (FILE* F, const type* Type);
190 /* Output translation of type array. */
192 void PrintRawType (FILE* F, const type* Type);
193 /* Print a type string in raw format (for debugging) */
195 void Encode (type* Type, unsigned long Val);
196 /* Encode an unsigned long into a type array */
198 void EncodePtr (type* Type, void* P);
199 /* Encode a pointer into a type array */
201 unsigned long Decode (const type* Type);
202 /* Decode an unsigned long from a type array */
204 void* DecodePtr (const type* Type);
205 /* Decode a pointer from a type array */
207 int HasEncode (const type* Type);
208 /* Return true if the given type has encoded data */
210 void CopyEncode (const type* Source, type* Target);
211 /* Copy encoded data from Source to Target */
213 type UnqualifiedType (type T);
214 /* Return the unqalified type */
216 unsigned SizeOf (const type* Type);
217 /* Compute size of object represented by type array. */
219 unsigned PSizeOf (const type* Type);
220 /* Compute size of pointer object. */
222 unsigned TypeOf (const type* Type);
223 /* Get the code generator base type of the object */
225 type* Indirect (type* Type);
226 /* Do one indirection for the given type, that is, return the type where the
227 * given type points to.
230 int IsConst (const type* T);
231 /* Return true if the given type has a const memory image */
233 int IsTypeVoid (const type* Type);
234 /* Return true if this is a void type */
236 int IsClassPtr (const type* Type);
237 /* Return true if this is a pointer type */
239 int IsTypeChar (const type* Type);
240 /* Return true if this is a character type */
242 int IsClassInt (const type* Type);
243 /* Return true if this is an integer type */
245 int IsTypeLong (const type* Type);
246 /* Return true if this is a long type (signed or unsigned) */
248 int IsUnsigned (const type* Type);
249 /* Return true if this is an unsigned type */
251 int IsClassStruct (const type* Type);
252 /* Return true if this is a struct type */
254 int IsTypeFunc (const type* Type);
255 /* Return true if this is a function class */
257 int IsFastCallFunc (const type* Type);
258 /* Return true if this is a function type with __fastcall__ calling conventions */
260 int IsTypeFuncPtr (const type* Type);
261 /* Return true if this is a function pointer */
263 int IsTypeArray (const type* Type);
264 /* Return true if this is an array type */
266 struct FuncDesc* GetFuncDesc (const type* Type);
267 /* Get the FuncDesc pointer from a function or pointer-to-function type */
271 /* End of datatype.h */