de1ea3f0ffc757abdfc9feb3b698924c925e8a73
[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 #define RPC_FC_COCLASS 0xfd
47 #define RPC_FC_FUNCTION 0xfe
48
49 typedef struct _loc_info_t loc_info_t;
50 typedef struct _attr_t attr_t;
51 typedef struct _expr_t expr_t;
52 typedef struct _type_t type_t;
53 typedef struct _typeref_t typeref_t;
54 typedef struct _var_t var_t;
55 typedef struct _declarator_t declarator_t;
56 typedef struct _func_t func_t;
57 typedef struct _ifref_t ifref_t;
58 typedef struct _typelib_entry_t typelib_entry_t;
59 typedef struct _importlib_t importlib_t;
60 typedef struct _importinfo_t importinfo_t;
61 typedef struct _typelib_t typelib_t;
62 typedef struct _user_type_t user_type_t;
63 typedef struct _user_type_t context_handle_t;
64 typedef struct _type_list_t type_list_t;
65 typedef struct _statement_t statement_t;
66
67 typedef struct list attr_list_t;
68 typedef struct list str_list_t;
69 typedef struct list func_list_t;
70 typedef struct list expr_list_t;
71 typedef struct list var_list_t;
72 typedef struct list declarator_list_t;
73 typedef struct list ifref_list_t;
74 typedef struct list array_dims_t;
75 typedef struct list user_type_list_t;
76 typedef struct list context_handle_list_t;
77 typedef struct list statement_list_t;
78
79 enum attr_type
80 {
81 ATTR_AGGREGATABLE,
82 ATTR_APPOBJECT,
83 ATTR_ASYNC,
84 ATTR_AUTO_HANDLE,
85 ATTR_BINDABLE,
86 ATTR_BROADCAST,
87 ATTR_CALLAS,
88 ATTR_CALLCONV, /* calling convention pseudo-attribute */
89 ATTR_CASE,
90 ATTR_CONST, /* const pseudo-attribute */
91 ATTR_CONTEXTHANDLE,
92 ATTR_CONTROL,
93 ATTR_DEFAULT,
94 ATTR_DEFAULTCOLLELEM,
95 ATTR_DEFAULTVALUE,
96 ATTR_DEFAULTVTABLE,
97 ATTR_DISPINTERFACE,
98 ATTR_DISPLAYBIND,
99 ATTR_DLLNAME,
100 ATTR_DUAL,
101 ATTR_ENDPOINT,
102 ATTR_ENTRY,
103 ATTR_EXPLICIT_HANDLE,
104 ATTR_HANDLE,
105 ATTR_HELPCONTEXT,
106 ATTR_HELPFILE,
107 ATTR_HELPSTRING,
108 ATTR_HELPSTRINGCONTEXT,
109 ATTR_HELPSTRINGDLL,
110 ATTR_HIDDEN,
111 ATTR_ID,
112 ATTR_IDEMPOTENT,
113 ATTR_IIDIS,
114 ATTR_IMMEDIATEBIND,
115 ATTR_IMPLICIT_HANDLE,
116 ATTR_IN,
117 ATTR_INLINE,
118 ATTR_INPUTSYNC,
119 ATTR_LENGTHIS,
120 ATTR_LIBLCID,
121 ATTR_LOCAL,
122 ATTR_NONBROWSABLE,
123 ATTR_NONCREATABLE,
124 ATTR_NONEXTENSIBLE,
125 ATTR_OBJECT,
126 ATTR_ODL,
127 ATTR_OLEAUTOMATION,
128 ATTR_OPTIONAL,
129 ATTR_OUT,
130 ATTR_POINTERDEFAULT,
131 ATTR_POINTERTYPE,
132 ATTR_PROPGET,
133 ATTR_PROPPUT,
134 ATTR_PROPPUTREF,
135 ATTR_PUBLIC,
136 ATTR_RANGE,
137 ATTR_READONLY,
138 ATTR_REQUESTEDIT,
139 ATTR_RESTRICTED,
140 ATTR_RETVAL,
141 ATTR_SIZEIS,
142 ATTR_SOURCE,
143 ATTR_STRICTCONTEXTHANDLE,
144 ATTR_STRING,
145 ATTR_SWITCHIS,
146 ATTR_SWITCHTYPE,
147 ATTR_TRANSMITAS,
148 ATTR_UUID,
149 ATTR_V1ENUM,
150 ATTR_VARARG,
151 ATTR_VERSION,
152 ATTR_WIREMARSHAL
153 };
154
155 enum expr_type
156 {
157 EXPR_VOID,
158 EXPR_NUM,
159 EXPR_HEXNUM,
160 EXPR_DOUBLE,
161 EXPR_IDENTIFIER,
162 EXPR_NEG,
163 EXPR_NOT,
164 EXPR_PPTR,
165 EXPR_CAST,
166 EXPR_SIZEOF,
167 EXPR_SHL,
168 EXPR_SHR,
169 EXPR_MUL,
170 EXPR_DIV,
171 EXPR_ADD,
172 EXPR_SUB,
173 EXPR_AND,
174 EXPR_OR,
175 EXPR_COND,
176 EXPR_TRUEFALSE,
177 EXPR_ADDRESSOF,
178 EXPR_MEMBER,
179 EXPR_ARRAY,
180 EXPR_MOD,
181 EXPR_LOGOR,
182 EXPR_LOGAND,
183 EXPR_XOR,
184 EXPR_EQUALITY,
185 EXPR_INEQUALITY,
186 EXPR_GTR,
187 EXPR_LESS,
188 EXPR_GTREQL,
189 EXPR_LESSEQL,
190 EXPR_LOGNOT,
191 EXPR_POS,
192 EXPR_STRLIT,
193 EXPR_WSTRLIT,
194 };
195
196 enum type_kind
197 {
198 TKIND_PRIMITIVE = -1,
199 TKIND_ENUM,
200 TKIND_RECORD,
201 TKIND_MODULE,
202 TKIND_INTERFACE,
203 TKIND_DISPATCH,
204 TKIND_COCLASS,
205 TKIND_ALIAS,
206 TKIND_UNION,
207 TKIND_MAX
208 };
209
210 enum storage_class
211 {
212 STG_NONE,
213 STG_STATIC,
214 STG_EXTERN,
215 STG_REGISTER,
216 };
217
218 enum statement_type
219 {
220 STMT_LIBRARY,
221 STMT_DECLARATION,
222 STMT_TYPE,
223 STMT_TYPEREF,
224 STMT_MODULE,
225 STMT_TYPEDEF,
226 STMT_IMPORT,
227 STMT_IMPORTLIB,
228 STMT_CPPQUOTE
229 };
230
231 struct _loc_info_t
232 {
233 const char *input_name;
234 int line_number;
235 const char *near_text;
236 };
237
238 struct str_list_entry_t
239 {
240 char *str;
241 struct list entry;
242 };
243
244 struct _attr_t {
245 enum attr_type type;
246 union {
247 unsigned long ival;
248 void *pval;
249 } u;
250 /* parser-internal */
251 struct list entry;
252 };
253
254 struct _expr_t {
255 enum expr_type type;
256 const expr_t *ref;
257 union {
258 long lval;
259 double dval;
260 const char *sval;
261 const expr_t *ext;
262 type_t *tref;
263 } u;
264 const expr_t *ext2;
265 int is_const;
266 long cval;
267 /* parser-internal */
268 struct list entry;
269 };
270
271 struct _type_t {
272 const char *name;
273 enum type_kind kind;
274 unsigned char type;
275 struct _type_t *ref;
276 attr_list_t *attrs;
277 func_list_t *funcs; /* interfaces and modules */
278 var_list_t *fields_or_args; /* interfaces, structures, enumerations and functions (for args) */
279 ifref_list_t *ifaces; /* coclasses */
280 unsigned long dim; /* array dimension */
281 expr_t *size_is, *length_is;
282 type_t *orig; /* dup'd types */
283 unsigned int typestring_offset;
284 unsigned int ptrdesc; /* used for complex structs */
285 int typelib_idx;
286 unsigned int declarray : 1; /* if declared as an array */
287 unsigned int ignore : 1;
288 unsigned int defined : 1;
289 unsigned int written : 1;
290 unsigned int user_types_registered : 1;
291 unsigned int tfswrite : 1; /* if the type needs to be written to the TFS */
292 unsigned int checked : 1;
293 int sign : 2;
294 };
295
296 struct _var_t {
297 char *name;
298 type_t *type;
299 attr_list_t *attrs;
300 expr_t *eval;
301 enum storage_class stgclass;
302
303 struct _loc_info_t loc_info;
304
305 /* parser-internal */
306 struct list entry;
307 };
308
309 struct _declarator_t {
310 var_t *var;
311 type_t *type;
312 type_t *func_type;
313 array_dims_t *array;
314
315 /* parser-internal */
316 struct list entry;
317 };
318
319 struct _func_t {
320 var_t *def;
321 var_list_t *args;
322 int ignore, idx;
323
324 /* parser-internal */
325 struct list entry;
326 };
327
328 struct _ifref_t {
329 type_t *iface;
330 attr_list_t *attrs;
331
332 /* parser-internal */
333 struct list entry;
334 };
335
336 struct _typelib_entry_t {
337 type_t *type;
338 struct list entry;
339 };
340
341 struct _importinfo_t {
342 int offset;
343 GUID guid;
344 int flags;
345 int id;
346
347 char *name;
348
349 importlib_t *importlib;
350 };
351
352 struct _importlib_t {
353 char *name;
354
355 int version;
356 GUID guid;
357
358 importinfo_t *importinfos;
359 int ntypeinfos;
360
361 int allocated;
362
363 struct list entry;
364 };
365
366 struct _typelib_t {
367 char *name;
368 char *filename;
369 const attr_list_t *attrs;
370 struct list entries;
371 struct list importlibs;
372 statement_list_t *stmts;
373 };
374
375 struct _user_type_t {
376 struct list entry;
377 const char *name;
378 };
379
380 struct _type_list_t {
381 type_t *type;
382 struct _type_list_t *next;
383 };
384
385 struct _statement_t {
386 struct list entry;
387 enum statement_type type;
388 union
389 {
390 ifref_t iface;
391 type_t *type;
392 const char *str;
393 var_t *var;
394 typelib_t *lib;
395 type_list_t *type_list;
396 } u;
397 };
398
399 extern unsigned char pointer_default;
400
401 extern user_type_list_t user_type_list;
402 void check_for_additional_prototype_types(const var_list_t *list);
403
404 void init_types(void);
405 type_t *alloc_type(void);
406 void set_all_tfswrite(int val);
407
408 type_t *duptype(type_t *t, int dupname);
409 type_t *alias(type_t *t, const char *name);
410
411 int is_ptr(const type_t *t);
412 int is_array(const type_t *t);
413 int is_var_ptr(const var_t *v);
414 int cant_be_null(const var_t *v);
415 int is_struct(unsigned char tc);
416 int is_union(unsigned char tc);
417
418 var_t *find_const(const char *name, int f);
419 type_t *find_type(const char *name, int t);
420 type_t *make_type(unsigned char type, type_t *ref);
421
422 static inline type_t *get_func_return_type(const func_t *func)
423 {
424 return func->def->type->ref;
425 }
426
427 #endif