Define TRUE only if it hasn't been defined before
[reactos.git] / reactos / tools / widl / widltypes.h
1 /*
2 * IDL Compiler
3 *
4 * Copyright 2002 Ove Kaaven
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #ifndef __WIDL_WIDLTYPES_H
22 #define __WIDL_WIDLTYPES_H
23
24 #define S_OK 0
25 #define S_FALSE 1
26 #define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
27 #define TYPE_E_IOERROR ((HRESULT)0x80028CA2L)
28
29 #define max(a, b) ((a) > (b) ? a : b)
30
31 #include <stdarg.h>
32 #include "guiddef.h"
33 #include "wine/rpcfc.h"
34 #include "wine/list.h"
35
36 #ifndef UUID_DEFINED
37 #define UUID_DEFINED
38 typedef GUID UUID;
39 #endif
40
41 #ifndef TRUE
42 #define TRUE 1
43 #endif
44 #define FALSE 0
45
46 typedef struct _attr_t attr_t;
47 typedef struct _expr_t expr_t;
48 typedef struct _type_t type_t;
49 typedef struct _typeref_t typeref_t;
50 typedef struct _var_t var_t;
51 typedef struct _pident_t pident_t;
52 typedef struct _func_t func_t;
53 typedef struct _ifref_t ifref_t;
54 typedef struct _typelib_entry_t typelib_entry_t;
55 typedef struct _importlib_t importlib_t;
56 typedef struct _importinfo_t importinfo_t;
57 typedef struct _typelib_t typelib_t;
58 typedef struct _user_type_t user_type_t;
59 typedef struct _user_type_t context_handle_t;
60
61 typedef struct list attr_list_t;
62 typedef struct list str_list_t;
63 typedef struct list func_list_t;
64 typedef struct list expr_list_t;
65 typedef struct list var_list_t;
66 typedef struct list pident_list_t;
67 typedef struct list ifref_list_t;
68 typedef struct list array_dims_t;
69 typedef struct list user_type_list_t;
70 typedef struct list context_handle_list_t;
71
72 enum attr_type
73 {
74 ATTR_AGGREGATABLE,
75 ATTR_APPOBJECT,
76 ATTR_ASYNC,
77 ATTR_AUTO_HANDLE,
78 ATTR_BINDABLE,
79 ATTR_CALLAS,
80 ATTR_CASE,
81 ATTR_CONTEXTHANDLE,
82 ATTR_CONTROL,
83 ATTR_DEFAULT,
84 ATTR_DEFAULTCOLLELEM,
85 ATTR_DEFAULTVALUE_EXPR,
86 ATTR_DEFAULTVALUE_STRING,
87 ATTR_DEFAULTVTABLE,
88 ATTR_DISPINTERFACE,
89 ATTR_DISPLAYBIND,
90 ATTR_DLLNAME,
91 ATTR_DUAL,
92 ATTR_ENDPOINT,
93 ATTR_ENTRY_ORDINAL,
94 ATTR_ENTRY_STRING,
95 ATTR_EXPLICIT_HANDLE,
96 ATTR_HANDLE,
97 ATTR_HELPCONTEXT,
98 ATTR_HELPFILE,
99 ATTR_HELPSTRING,
100 ATTR_HELPSTRINGCONTEXT,
101 ATTR_HELPSTRINGDLL,
102 ATTR_HIDDEN,
103 ATTR_ID,
104 ATTR_IDEMPOTENT,
105 ATTR_IIDIS,
106 ATTR_IMMEDIATEBIND,
107 ATTR_IMPLICIT_HANDLE,
108 ATTR_IN,
109 ATTR_INPUTSYNC,
110 ATTR_LENGTHIS,
111 ATTR_LOCAL,
112 ATTR_NONBROWSABLE,
113 ATTR_NONCREATABLE,
114 ATTR_NONEXTENSIBLE,
115 ATTR_OBJECT,
116 ATTR_ODL,
117 ATTR_OLEAUTOMATION,
118 ATTR_OPTIONAL,
119 ATTR_OUT,
120 ATTR_POINTERDEFAULT,
121 ATTR_POINTERTYPE,
122 ATTR_PROPGET,
123 ATTR_PROPPUT,
124 ATTR_PROPPUTREF,
125 ATTR_PUBLIC,
126 ATTR_RANGE,
127 ATTR_READONLY,
128 ATTR_REQUESTEDIT,
129 ATTR_RESTRICTED,
130 ATTR_RETVAL,
131 ATTR_SIZEIS,
132 ATTR_SOURCE,
133 ATTR_STRICTCONTEXTHANDLE,
134 ATTR_STRING,
135 ATTR_SWITCHIS,
136 ATTR_SWITCHTYPE,
137 ATTR_TRANSMITAS,
138 ATTR_UUID,
139 ATTR_V1ENUM,
140 ATTR_VARARG,
141 ATTR_VERSION,
142 ATTR_WIREMARSHAL
143 };
144
145 enum expr_type
146 {
147 EXPR_VOID,
148 EXPR_NUM,
149 EXPR_HEXNUM,
150 EXPR_DOUBLE,
151 EXPR_IDENTIFIER,
152 EXPR_NEG,
153 EXPR_NOT,
154 EXPR_PPTR,
155 EXPR_CAST,
156 EXPR_SIZEOF,
157 EXPR_SHL,
158 EXPR_SHR,
159 EXPR_MUL,
160 EXPR_DIV,
161 EXPR_ADD,
162 EXPR_SUB,
163 EXPR_AND,
164 EXPR_OR,
165 EXPR_COND,
166 EXPR_TRUEFALSE,
167 EXPR_ADDRESSOF,
168 };
169
170 enum type_kind
171 {
172 TKIND_PRIMITIVE = -1,
173 TKIND_ENUM,
174 TKIND_RECORD,
175 TKIND_MODULE,
176 TKIND_INTERFACE,
177 TKIND_DISPATCH,
178 TKIND_COCLASS,
179 TKIND_ALIAS,
180 TKIND_UNION,
181 TKIND_MAX
182 };
183
184 struct str_list_entry_t
185 {
186 char *str;
187 struct list entry;
188 };
189
190 struct _attr_t {
191 enum attr_type type;
192 union {
193 unsigned long ival;
194 void *pval;
195 } u;
196 /* parser-internal */
197 struct list entry;
198 };
199
200 struct _expr_t {
201 enum expr_type type;
202 const expr_t *ref;
203 union {
204 long lval;
205 double dval;
206 const char *sval;
207 const expr_t *ext;
208 type_t *tref;
209 } u;
210 const expr_t *ext2;
211 int is_const;
212 long cval;
213 /* parser-internal */
214 struct list entry;
215 };
216
217 struct _type_t {
218 const char *name;
219 enum type_kind kind;
220 unsigned char type;
221 struct _type_t *ref;
222 const attr_list_t *attrs;
223 func_list_t *funcs; /* interfaces and modules */
224 var_list_t *fields; /* interfaces, structures and enumerations */
225 ifref_list_t *ifaces; /* coclasses */
226 unsigned long dim; /* array dimension */
227 expr_t *size_is, *length_is;
228 type_t *orig; /* dup'd types */
229 unsigned int typestring_offset;
230 unsigned int ptrdesc; /* used for complex structs */
231 int typelib_idx;
232 unsigned int declarray : 1; /* if declared as an array */
233 unsigned int ignore : 1;
234 unsigned int is_const : 1;
235 unsigned int defined : 1;
236 unsigned int written : 1;
237 unsigned int user_types_registered : 1;
238 unsigned int tfswrite : 1; /* if the type needs to be written to the TFS */
239 int sign : 2;
240 };
241
242 struct _var_t {
243 char *name;
244 type_t *type;
245 var_list_t *args; /* for function pointers */
246 attr_list_t *attrs;
247 expr_t *eval;
248
249 /* parser-internal */
250 struct list entry;
251 };
252
253 struct _pident_t {
254 var_t *var;
255 int ptr_level;
256
257 /* parser-internal */
258 struct list entry;
259 };
260
261 struct _func_t {
262 var_t *def;
263 var_list_t *args;
264 int ignore, idx;
265
266 /* parser-internal */
267 struct list entry;
268 };
269
270 struct _ifref_t {
271 type_t *iface;
272 attr_list_t *attrs;
273
274 /* parser-internal */
275 struct list entry;
276 };
277
278 struct _typelib_entry_t {
279 type_t *type;
280 struct list entry;
281 };
282
283 struct _importinfo_t {
284 int offset;
285 GUID guid;
286 int flags;
287 int id;
288
289 char *name;
290
291 importlib_t *importlib;
292 };
293
294 struct _importlib_t {
295 char *name;
296
297 int version;
298 GUID guid;
299
300 importinfo_t *importinfos;
301 int ntypeinfos;
302
303 int allocated;
304
305 struct list entry;
306 };
307
308 struct _typelib_t {
309 char *name;
310 char *filename;
311 attr_list_t *attrs;
312 struct list entries;
313 struct list importlibs;
314 };
315
316 struct _user_type_t {
317 struct list entry;
318 const char *name;
319 };
320
321 extern unsigned char pointer_default;
322
323 extern user_type_list_t user_type_list;
324 void check_for_user_types_and_context_handles(const var_list_t *list);
325
326 void init_types(void);
327 type_t *alloc_type(void);
328 void set_all_tfswrite(int val);
329
330 type_t *duptype(type_t *t, int dupname);
331 type_t *alias(type_t *t, const char *name);
332
333 int is_ptr(const type_t *t);
334 int is_array(const type_t *t);
335 int is_var_ptr(const var_t *v);
336 int cant_be_null(const var_t *v);
337 int is_struct(unsigned char tc);
338 int is_union(unsigned char tc);
339
340 #endif