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 /*****************************************************************************/
55 #define T_SHORT 0x0013
58 #define T_UCHAR 0x0019
60 #define T_USHORT 0x001B
61 #define T_ULONG 0x001C
63 #define T_FLOAT 0x0025
64 #define T_DOUBLE 0x0026
66 #define T_VOID 0x0001 /* void parameter list */
67 #define T_FUNC 0x0002 /* Function */
69 #define T_UNSIGNED 0x0008 /* Class */
70 #define T_INTEGER 0x0010 /* Class */
71 #define T_REAL 0x0020 /* Class */
72 #define T_POINTER 0x0040 /* Class */
74 #define T_ARRAY 0x004A
75 #define T_STRUCT 0x0080
76 #define T_UNION 0x0081
77 #define T_SMASK 0x003F
81 /* Forward for a symbol entry */
85 typedef unsigned short type;
87 /* Maximum length of a type string */
90 /* type elements needed for Encode/Decode */
93 /* Predefined type strings */
94 extern type type_int [];
95 extern type type_uint [];
96 extern type type_long [];
97 extern type type_ulong [];
98 extern type type_void [];
99 extern type type_pschar [];
100 extern type type_puchar [];
104 /*****************************************************************************/
106 /*****************************************************************************/
110 unsigned TypeLen (const type* Type);
111 /* Return the length of the type string */
113 int TypeCmp (const type* T1, const type* T2);
114 /* Compare two type strings */
116 type* TypeCpy (type* Dest, const type* Src);
117 /* Copy a type string */
119 type* TypeCat (type* Dest, const type* Src);
122 type* TypeDup (const type* Type);
123 /* Create a copy of the given type on the heap */
125 type* TypeAlloc (unsigned Len);
126 /* Allocate memory for a type string of length Len. Len *must* include the
130 void TypeFree (type* Type);
131 /* Free a type string */
133 type GetDefaultChar (void);
134 /* Return the default char type (signed/unsigned) depending on the settings */
136 type* GetCharArrayType (unsigned Len);
137 /* Return the type for a char array of the given length */
139 type* GetImplicitFuncType (void);
140 /* Return a type string for an inplicitly declared function */
142 void PrintType (FILE* F, const type* Type);
143 /* Output translation of type array. */
145 void PrintRawType (FILE* F, const type* Type);
146 /* Print a type string in raw format (for debugging) */
148 void Encode (type* Type, unsigned long Val);
149 /* Encode an unsigned long into a type array */
151 void EncodePtr (type* Type, void* P);
152 /* Encode a pointer into a type array */
154 unsigned long Decode (const type* Type);
155 /* Decode an unsigned long from a type array */
157 void* DecodePtr (const type* Type);
158 /* Decode a pointer from a type array */
160 int HasEncode (const type* Type);
161 /* Return true if the given type has encoded data */
163 void CopyEncode (const type* Source, type* Target);
164 /* Copy encoded data from Source to Target */
166 unsigned SizeOf (const type* Type);
167 /* Compute size of object represented by type array. */
169 unsigned PSizeOf (const type* Type);
170 /* Compute size of pointer object. */
172 unsigned TypeOf (const type* Type);
173 /* Get the code generator base type of the object */
175 type* Indirect (type* Type);
176 /* Do one indirection for the given type, that is, return the type where the
177 * given type points to.
180 int IsVoid (const type* Type);
181 /* Return true if this is a void type */
183 int IsPtr (const type* Type);
184 /* Return true if this is a pointer type */
186 int IsChar (const type* Type);
187 /* Return true if this is a character type */
189 int IsInt (const type* Type);
190 /* Return true if this is an integer type */
192 int IsLong (const type* Type);
193 /* Return true if this is a long type (signed or unsigned) */
195 int IsUnsigned (const type* Type);
196 /* Return true if this is an unsigned type */
198 int IsStruct (const type* Type);
199 /* Return true if this is a struct type */
201 int IsFunc (const type* Type);
202 /* Return true if this is a function type */
204 int IsFastCallFunc (const type* Type);
205 /* Return true if this is a function type with __fastcall__ calling conventions */
207 int IsFuncPtr (const type* Type);
208 /* Return true if this is a function pointer */
210 int IsArray (const type* Type);
211 /* Return true if this is an array type */
213 struct FuncDesc* GetFuncDesc (const type* Type);
214 /* Get the FuncDesc pointer from a function or pointer-to-function type */
218 /* End of datatype.h */