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 /*****************************************************************************/
61 T_TYPE_FLOAT = 0x0004,
62 T_TYPE_DOUBLE = 0x0005,
64 T_TYPE_STRUCT = 0x0007,
65 T_TYPE_UNION = 0x0008,
66 T_TYPE_ARRAY = 0x0009,
72 T_CLASS_NONE = 0x0000,
74 T_CLASS_FLOAT = 0x0040,
76 T_CLASS_STRUCT = 0x0080,
77 T_CLASS_FUNC = 0x00A0,
78 T_MASK_CLASS = 0x00E0,
82 T_SIGN_UNSIGNED = 0x0100,
83 T_SIGN_SIGNED = 0x0200,
86 // Type size modifiers
88 T_SIZE_SHORT = 0x0400,
90 T_SIZE_LONGLONG = 0x0C00,
95 T_QUAL_CONST = 0x1000,
96 T_QUAL_VOLATILE = 0x2000,
100 T_CHAR = T_TYPE_CHAR | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_NONE,
101 T_SCHAR = T_TYPE_CHAR | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_NONE,
102 T_UCHAR = T_TYPE_CHAR | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_NONE,
103 T_SHORT = T_TYPE_INT | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_SHORT,
104 T_USHORT = T_TYPE_INT | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_SHORT,
105 T_INT = T_TYPE_INT | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_NONE,
106 T_UINT = T_TYPE_INT | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_NONE,
107 T_LONG = T_TYPE_INT | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_LONG,
108 T_ULONG = T_TYPE_INT | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_LONG,
109 T_LONGLONG = T_TYPE_INT | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_LONGLONG,
110 T_ULONGLONG = T_TYPE_INT | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_LONGLONG,
111 T_ENUM = T_TYPE_ENUM | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_NONE,
112 T_FLOAT = T_TYPE_FLOAT | T_CLASS_FLOAT | T_SIGN_NONE | T_SIZE_NONE,
113 T_DOUBLE = T_TYPE_DOUBLE | T_CLASS_FLOAT | T_SIGN_NONE | T_SIZE_NONE,
114 T_VOID = T_TYPE_VOID | T_CLASS_NONE | T_SIGN_NONE | T_SIZE_NONE,
115 T_STRUCT = T_TYPE_STRUCT | T_CLASS_STRUCT | T_SIGN_NONE | T_SIZE_NONE,
116 T_UNION = T_TYPE_UNION | T_CLASS_STRUCT | T_SIGN_NONE | T_SIZE_NONE,
117 T_ARRAY = T_TYPE_ARRAY | T_CLASS_PTR | T_SIGN_NONE | T_SIZE_NONE,
118 T_PTR = T_TYPE_PTR | T_CLASS_PTR | T_SIGN_NONE | T_SIZE_NONE,
119 T_FUNC = T_TYPE_FUNC | T_CLASS_FUNC | T_SIGN_NONE | T_SIZE_NONE,
127 #define T_CHAR 0x0011
129 #define T_SHORT 0x0013
130 #define T_LONG 0x0014
131 #define T_ENUM 0x0015
132 #define T_UCHAR 0x0019
133 #define T_UINT 0x001A
134 #define T_USHORT 0x001B
135 #define T_ULONG 0x001C
137 #define T_FLOAT 0x0025
138 #define T_DOUBLE 0x0026
140 #define T_VOID 0x0001 /* void parameter list */
141 #define T_FUNC 0x0002 /* Function */
143 #define T_UNSIGNED 0x0008 /* Class */
144 #define T_INTEGER 0x0010 /* Class */
145 #define T_REAL 0x0020 /* Class */
146 #define T_POINTER 0x0040 /* Class */
148 #define T_ARRAY 0x004A
149 #define T_STRUCT 0x0080
150 #define T_UNION 0x0081
151 #define T_SMASK 0x003F
155 /* Forward for a symbol entry */
159 typedef unsigned short type;
161 /* Maximum length of a type string */
162 #define MAXTYPELEN 30
164 /* type elements needed for Encode/Decode */
165 #define DECODE_SIZE 5
167 /* Predefined type strings */
168 extern type type_int [];
169 extern type type_uint [];
170 extern type type_long [];
171 extern type type_ulong [];
172 extern type type_void [];
173 extern type type_pschar [];
174 extern type type_puchar [];
178 /*****************************************************************************/
180 /*****************************************************************************/
184 unsigned TypeLen (const type* Type);
185 /* Return the length of the type string */
187 int TypeCmp (const type* T1, const type* T2);
188 /* Compare two type strings */
190 type* TypeCpy (type* Dest, const type* Src);
191 /* Copy a type string */
193 type* TypeCat (type* Dest, const type* Src);
196 type* TypeDup (const type* Type);
197 /* Create a copy of the given type on the heap */
199 type* TypeAlloc (unsigned Len);
200 /* Allocate memory for a type string of length Len. Len *must* include the
204 void TypeFree (type* Type);
205 /* Free a type string */
207 type GetDefaultChar (void);
208 /* Return the default char type (signed/unsigned) depending on the settings */
210 type* GetCharArrayType (unsigned Len);
211 /* Return the type for a char array of the given length */
213 type* GetImplicitFuncType (void);
214 /* Return a type string for an inplicitly declared function */
216 void PrintType (FILE* F, const type* Type);
217 /* Output translation of type array. */
219 void PrintRawType (FILE* F, const type* Type);
220 /* Print a type string in raw format (for debugging) */
222 void Encode (type* Type, unsigned long Val);
223 /* Encode an unsigned long into a type array */
225 void EncodePtr (type* Type, void* P);
226 /* Encode a pointer into a type array */
228 unsigned long Decode (const type* Type);
229 /* Decode an unsigned long from a type array */
231 void* DecodePtr (const type* Type);
232 /* Decode a pointer from a type array */
234 int HasEncode (const type* Type);
235 /* Return true if the given type has encoded data */
237 void CopyEncode (const type* Source, type* Target);
238 /* Copy encoded data from Source to Target */
240 unsigned SizeOf (const type* Type);
241 /* Compute size of object represented by type array. */
243 unsigned PSizeOf (const type* Type);
244 /* Compute size of pointer object. */
246 unsigned TypeOf (const type* Type);
247 /* Get the code generator base type of the object */
249 type* Indirect (type* Type);
250 /* Do one indirection for the given type, that is, return the type where the
251 * given type points to.
254 int IsVoid (const type* Type);
255 /* Return true if this is a void type */
257 int IsPtr (const type* Type);
258 /* Return true if this is a pointer type */
260 int IsChar (const type* Type);
261 /* Return true if this is a character type */
263 int IsInt (const type* Type);
264 /* Return true if this is an integer type */
266 int IsLong (const type* Type);
267 /* Return true if this is a long type (signed or unsigned) */
269 int IsUnsigned (const type* Type);
270 /* Return true if this is an unsigned type */
272 int IsStruct (const type* Type);
273 /* Return true if this is a struct type */
275 int IsFunc (const type* Type);
276 /* Return true if this is a function type */
278 int IsFastCallFunc (const type* Type);
279 /* Return true if this is a function type with __fastcall__ calling conventions */
281 int IsFuncPtr (const type* Type);
282 /* Return true if this is a function pointer */
284 int IsArray (const type* Type);
285 /* Return true if this is an array type */
287 struct FuncDesc* GetFuncDesc (const type* Type);
288 /* Get the FuncDesc pointer from a function or pointer-to-function type */
292 /* End of datatype.h */