]> git.sur5r.net Git - cc65/blob - src/cc65/datatype.h
Working on the new parser
[cc65] / src / cc65 / datatype.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                datatype.h                                 */
4 /*                                                                           */
5 /*               Type string handling for the cc65 C compiler                */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef DATATYPE_H
37 #define DATATYPE_H
38
39
40
41 #include <stdio.h>
42
43 /* common */
44 #include "attrib.h"
45
46
47
48 /*****************************************************************************/
49 /*                                   Data                                    */
50 /*****************************************************************************/
51
52
53
54
55 // Basic data types
56 enum {
57     T_END           = 0x0000,
58
59     // Basic types
60     T_TYPE_NONE     = 0x0000,
61     T_TYPE_CHAR     = 0x0001,
62     T_TYPE_SHORT    = 0x0002,
63     T_TYPE_INT      = 0x0003,
64     T_TYPE_LONG     = 0x0004,
65     T_TYPE_LONGLONG = 0x0005,
66     T_TYPE_ENUM     = 0x0006,
67     T_TYPE_FLOAT    = 0x0007,
68     T_TYPE_DOUBLE   = 0x0008,
69     T_TYPE_VOID     = 0x0009,
70     T_TYPE_STRUCT   = 0x000A,
71     T_TYPE_UNION    = 0x000B,
72     T_TYPE_ARRAY    = 0x000C,
73     T_TYPE_PTR      = 0x000D,
74     T_TYPE_FUNC     = 0x000E,
75     T_MASK_TYPE     = 0x001F,
76
77     // Type classes
78     T_CLASS_NONE    = 0x0000,
79     T_CLASS_INT     = 0x0020,
80     T_CLASS_FLOAT   = 0x0040,
81     T_CLASS_PTR     = 0x0060,
82     T_CLASS_STRUCT  = 0x0080,
83     T_CLASS_FUNC    = 0x00A0,
84     T_MASK_CLASS    = 0x00E0,
85
86     // Type signedness
87     T_SIGN_NONE     = 0x0000,
88     T_SIGN_UNSIGNED = 0x0100,
89     T_SIGN_SIGNED   = 0x0200,
90     T_MASK_SIGN     = 0x0300,
91
92     // Type size modifiers
93     T_SIZE_NONE     = 0x0000,
94     T_SIZE_SHORT    = 0x0400,
95     T_SIZE_LONG     = 0x0800,
96     T_SIZE_LONGLONG = 0x0C00,
97     T_MASK_SIZE     = 0x0C00,
98
99     // Type qualifiers
100     T_QUAL_NONE     = 0x0000,
101     T_QUAL_CONST    = 0x1000,
102     T_QUAL_VOLATILE = 0x2000,
103     T_MASK_QUAL     = 0x3000,
104
105     // Types
106     T_CHAR      = T_TYPE_CHAR     | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_NONE,
107     T_SCHAR     = T_TYPE_CHAR     | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_NONE,
108     T_UCHAR     = T_TYPE_CHAR     | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_NONE,
109     T_SHORT     = T_TYPE_SHORT    | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_SHORT,
110     T_USHORT    = T_TYPE_SHORT    | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_SHORT,
111     T_INT       = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_NONE,
112     T_UINT      = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_NONE,
113     T_LONG      = T_TYPE_LONG     | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_LONG,
114     T_ULONG     = T_TYPE_LONG     | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_LONG,
115     T_LONGLONG  = T_TYPE_LONGLONG | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_LONGLONG,
116     T_ULONGLONG = T_TYPE_LONGLONG | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_LONGLONG,
117     T_ENUM      = T_TYPE_ENUM     | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_NONE,
118     T_FLOAT     = T_TYPE_FLOAT    | T_CLASS_FLOAT  | T_SIGN_NONE     | T_SIZE_NONE,
119     T_DOUBLE    = T_TYPE_DOUBLE   | T_CLASS_FLOAT  | T_SIGN_NONE     | T_SIZE_NONE,
120     T_VOID      = T_TYPE_VOID     | T_CLASS_NONE   | T_SIGN_NONE     | T_SIZE_NONE,
121     T_STRUCT    = T_TYPE_STRUCT   | T_CLASS_STRUCT | T_SIGN_NONE     | T_SIZE_NONE,
122     T_UNION     = T_TYPE_UNION    | T_CLASS_STRUCT | T_SIGN_NONE     | T_SIZE_NONE,
123     T_ARRAY     = T_TYPE_ARRAY    | T_CLASS_PTR    | T_SIGN_NONE     | T_SIZE_NONE,
124     T_PTR       = T_TYPE_PTR      | T_CLASS_PTR    | T_SIGN_NONE     | T_SIZE_NONE,
125     T_FUNC      = T_TYPE_FUNC     | T_CLASS_FUNC   | T_SIGN_NONE     | T_SIZE_NONE,
126
127 };
128
129
130
131 /* Forward for a symbol entry */
132 struct SymEntry;
133
134 /* Type entry */
135 typedef unsigned short type;
136
137 /* Maximum length of a type string */
138 #define MAXTYPELEN      30
139
140 /* type elements needed for Encode/Decode */
141 #define DECODE_SIZE     5
142
143 /* Predefined type strings */
144 extern type type_uchar [];
145 extern type type_int [];
146 extern type type_uint [];
147 extern type type_long [];
148 extern type type_ulong [];
149 extern type type_void [];
150 extern type type_size_t [];
151
152
153
154 /*****************************************************************************/
155 /*                                   Code                                    */
156 /*****************************************************************************/
157
158
159
160 unsigned TypeLen (const type* Type);
161 /* Return the length of the type string */
162
163 type* TypeCpy (type* Dest, const type* Src);
164 /* Copy a type string */
165
166 type* TypeCat (type* Dest, const type* Src);
167 /* Append Src */
168
169 type* TypeDup (const type* Type);
170 /* Create a copy of the given type on the heap */
171
172 type* TypeAlloc (unsigned Len);
173 /* Allocate memory for a type string of length Len. Len *must* include the
174  * trailing T_END.
175  */
176
177 void TypeFree (type* Type);
178 /* Free a type string */
179
180 type GetDefaultChar (void);
181 /* Return the default char type (signed/unsigned) depending on the settings */
182
183 type* GetCharArrayType (unsigned Len);
184 /* Return the type for a char array of the given length */
185
186 type* GetImplicitFuncType (void);
187 /* Return a type string for an inplicitly declared function */
188
189 type* PointerTo (const type* T);
190 /* Return a type string that is "pointer to T". The type string is allocated
191  * on the heap and may be freed after use.
192  */
193
194 void PrintType (FILE* F, const type* Type);
195 /* Output translation of type array. */
196
197 void PrintRawType (FILE* F, const type* Type);
198 /* Print a type string in raw format (for debugging) */
199
200 void Encode (type* Type, unsigned long Val);
201 /* Encode an unsigned long into a type array */
202
203 void EncodePtr (type* Type, void* P);
204 /* Encode a pointer into a type array */
205
206 unsigned long Decode (const type* Type);
207 /* Decode an unsigned long from a type array */
208
209 void* DecodePtr (const type* Type);
210 /* Decode a pointer from a type array */
211
212 int HasEncode (const type* Type);
213 /* Return true if the given type has encoded data */
214
215 void CopyEncode (const type* Source, type* Target);
216 /* Copy encoded data from Source to Target */
217
218 type UnqualifiedType (type T);
219 /* Return the unqalified type */
220
221 unsigned SizeOf (const type* Type);
222 /* Compute size of object represented by type array. */
223
224 unsigned PSizeOf (const type* Type);
225 /* Compute size of pointer object. */
226
227 unsigned TypeOf (const type* Type);
228 /* Get the code generator base type of the object */
229
230 type* Indirect (type* Type);
231 /* Do one indirection for the given type, that is, return the type where the
232  * given type points to.
233  */
234
235 int IsTypeChar (const type* T) attribute ((const));
236 /* Return true if this is a character type */
237
238 int IsTypeInt (const type* T) attribute ((const));
239 /* Return true if this is an int type (signed or unsigned) */
240
241 int IsTypeLong (const type* T) attribute ((const));
242 /* Return true if this is a long type (signed or unsigned) */
243
244 int IsTypeFloat (const type* T) attribute ((const));
245 /* Return true if this is a float type */
246
247 int IsTypeDouble (const type* T) attribute ((const));
248 /* Return true if this is a double type */
249
250 int IsTypePtr (const type* Type) attribute ((const));
251 /* Return true if this is a pointer type */
252
253 int IsTypeArray (const type* Type) attribute ((const));
254 /* Return true if this is an array type */
255
256 int IsTypeVoid (const type* Type) attribute ((const));
257 /* Return true if this is a void type */
258
259 int IsTypeFunc (const type* Type) attribute ((const));
260 /* Return true if this is a function class */
261
262 int IsClassInt (const type* Type) attribute ((const));
263 /* Return true if this is an integer type */
264
265 int IsClassFloat (const type* Type) attribute ((const));
266 /* Return true if this is a float type */
267
268 int IsClassPtr (const type* Type) attribute ((const));
269 /* Return true if this is a pointer type */
270
271 int IsClassStruct (const type* Type) attribute ((const));
272 /* Return true if this is a struct type */
273
274 int IsSignUnsigned (const type* Type) attribute ((const));
275 /* Return true if this is an unsigned type */
276
277 int IsQualConst (const type* T) attribute ((const));
278 /* Return true if the given type has a const memory image */
279
280 int IsQualVolatile (const type* T) attribute ((const));
281 /* Return true if the given type has a volatile type qualifier */
282
283 int IsFastCallFunc (const type* T) attribute ((const));
284 /* Return true if this is a function type with __fastcall__ calling conventions */
285
286 int IsTypeFuncPtr (const type* T) attribute ((const));
287 /* Return true if this is a function pointer */
288
289 type GetType (const type* T) attribute ((const));
290 /* Get the raw type */
291
292 type GetClass (const type* T) attribute ((const));
293 /* Get the class of a type string */
294
295 type GetSignedness (const type* T) attribute ((const));
296 /* Get the sign of a type */
297
298 type GetSizeModifier (const type* T) attribute ((const));
299 /* Get the size modifier of a type */
300
301 type GetQualifier (const type* T) attribute ((const));
302 /* Get the qualifier from the given type string */
303
304 struct FuncDesc* GetFuncDesc (const type* T) attribute ((const));
305 /* Get the FuncDesc pointer from a function or pointer-to-function type */
306
307
308
309 /* End of datatype.h */
310
311 #endif
312
313
314