]> git.sur5r.net Git - cc65/blob - src/cc65/datatype.h
This commit was generated by cvs2svn to compensate for changes in r2,
[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
44
45 /*****************************************************************************/
46 /*                                   Data                                    */
47 /*****************************************************************************/
48
49
50
51 /* Data types */
52 #define T_END           0x0000
53 #define T_CHAR          0x0011
54 #define T_INT           0x0012
55 #define T_SHORT         0x0013
56 #define T_LONG          0x0014
57 #define T_ENUM          0x0015
58 #define T_UCHAR         0x0019
59 #define T_UINT          0x001A
60 #define T_USHORT        0x001B
61 #define T_ULONG         0x001C
62
63 #define T_FLOAT         0x0025
64 #define T_DOUBLE        0x0026
65
66 #define T_VOID          0x0001          /* void parameter list */
67 #define T_FUNC          0x0002          /* Function */
68
69 #define T_UNSIGNED      0x0008          /* Class */
70 #define T_INTEGER       0x0010          /* Class */
71 #define T_REAL          0x0020          /* Class */
72 #define T_POINTER       0x0040          /* Class */
73 #define T_PTR           0x0049
74 #define T_ARRAY         0x004A
75 #define T_STRUCT        0x0080
76 #define T_UNION         0x0081
77 #define T_SMASK         0x003F
78
79
80
81 /* Forward for a symbol entry */
82 struct SymEntry;
83
84 /* Type entry */
85 typedef unsigned short type;
86
87 /* Maximum length of a type string */
88 #define MAXTYPELEN      30
89
90 /* type elements needed for Encode/Decode */
91 #define DECODE_SIZE     5
92
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 [];
101
102
103
104 /*****************************************************************************/
105 /*                                   Code                                    */
106 /*****************************************************************************/
107
108
109
110 unsigned TypeLen (const type* Type);
111 /* Return the length of the type string */
112
113 int TypeCmp (const type* T1, const type* T2);
114 /* Compare two type strings */
115
116 type* TypeCpy (type* Dest, const type* Src);
117 /* Copy a type string */
118
119 type* TypeCat (type* Dest, const type* Src);
120 /* Append Src */
121
122 type* TypeDup (const type* Type);
123 /* Create a copy of the given type on the heap */
124
125 type* TypeAlloc (unsigned Len);
126 /* Allocate memory for a type string of length Len. Len *must* include the
127  * trailing T_END.
128  */
129
130 void TypeFree (type* Type);
131 /* Free a type string */
132
133 type GetDefaultChar (void);
134 /* Return the default char type (signed/unsigned) depending on the settings */
135
136 type* GetCharArrayType (unsigned Len);
137 /* Return the type for a char array of the given length */
138
139 type* GetImplicitFuncType (void);
140 /* Return a type string for an inplicitly declared function */
141
142 void PrintType (FILE* F, const type* Type);
143 /* Output translation of type array. */
144
145 void PrintRawType (FILE* F, const type* Type);
146 /* Print a type string in raw format (for debugging) */
147
148 void Encode (type* Type, unsigned long Val);
149 /* Encode an unsigned long into a type array */
150
151 void EncodePtr (type* Type, void* P);
152 /* Encode a pointer into a type array */
153
154 unsigned long Decode (const type* Type);
155 /* Decode an unsigned long from a type array */
156
157 void* DecodePtr (const type* Type);
158 /* Decode a pointer from a type array */
159
160 int HasEncode (const type* Type);
161 /* Return true if the given type has encoded data */
162     
163 void CopyEncode (const type* Source, type* Target);
164 /* Copy encoded data from Source to Target */
165
166 unsigned SizeOf (const type* Type);
167 /* Compute size of object represented by type array. */
168
169 unsigned PSizeOf (const type* Type);
170 /* Compute size of pointer object. */
171
172 unsigned TypeOf (const type* Type);
173 /* Get the code generator base type of the object */
174
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.
178  */
179
180 int IsVoid (const type* Type);
181 /* Return true if this is a void type */
182
183 int IsPtr (const type* Type);
184 /* Return true if this is a pointer type */
185
186 int IsChar (const type* Type);
187 /* Return true if this is a character type */
188
189 int IsInt (const type* Type);
190 /* Return true if this is an integer type */
191
192 int IsLong (const type* Type);
193 /* Return true if this is a long type (signed or unsigned) */
194
195 int IsUnsigned (const type* Type);
196 /* Return true if this is an unsigned type */
197
198 int IsStruct (const type* Type);
199 /* Return true if this is a struct type */
200
201 int IsFunc (const type* Type);
202 /* Return true if this is a function type */
203
204 int IsFastCallFunc (const type* Type);
205 /* Return true if this is a function type with __fastcall__ calling conventions */
206
207 int IsFuncPtr (const type* Type);
208 /* Return true if this is a function pointer */
209
210 int IsArray (const type* Type);
211 /* Return true if this is an array type */
212
213 struct FuncDesc* GetFuncDesc (const type* Type);
214 /* Get the FuncDesc pointer from a function or pointer-to-function type */
215
216
217
218 /* End of datatype.h */
219
220 #endif
221
222
223