f0afce4e6a59f0465c0ffdbc556e6c43a7c32636
[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 <assert.h>
33 #include "guiddef.h"
34 #include "wine/rpcfc.h"
35 #include "wine/list.h"
36
37 #ifndef UUID_DEFINED
38 #define UUID_DEFINED
39 typedef GUID UUID;
40 #endif
41
42 #ifndef TRUE
43 #define TRUE 1
44 #endif
45 #define FALSE 0
46
47 #define RPC_FC_MODULE 0xfc
48 #define RPC_FC_COCLASS 0xfd
49 #define RPC_FC_FUNCTION 0xfe
50
51 typedef struct _loc_info_t loc_info_t;
52 typedef struct _attr_t attr_t;
53 typedef struct _expr_t expr_t;
54 typedef struct _type_t type_t;
55 typedef struct _typeref_t typeref_t;
56 typedef struct _var_t var_t;
57 typedef struct _declarator_t declarator_t;
58 typedef struct _func_t func_t;
59 typedef struct _ifref_t ifref_t;
60 typedef struct _typelib_entry_t typelib_entry_t;
61 typedef struct _importlib_t importlib_t;
62 typedef struct _importinfo_t importinfo_t;
63 typedef struct _typelib_t typelib_t;
64 typedef struct _user_type_t user_type_t;
65 typedef struct _user_type_t context_handle_t;
66 typedef struct _type_list_t type_list_t;
67 typedef struct _statement_t statement_t;
68
69 typedef struct list attr_list_t;
70 typedef struct list str_list_t;
71 typedef struct list func_list_t;
72 typedef struct list expr_list_t;
73 typedef struct list var_list_t;
74 typedef struct list declarator_list_t;
75 typedef struct list ifref_list_t;
76 typedef struct list array_dims_t;
77 typedef struct list user_type_list_t;
78 typedef struct list context_handle_list_t;
79 typedef struct list statement_list_t;
80
81 enum attr_type
82 {
83 ATTR_AGGREGATABLE,
84 ATTR_ANNOTATION,
85 ATTR_APPOBJECT,
86 ATTR_ASYNC,
87 ATTR_AUTO_HANDLE,
88 ATTR_BINDABLE,
89 ATTR_BROADCAST,
90 ATTR_CALLAS,
91 ATTR_CALLCONV, /* calling convention pseudo-attribute */
92 ATTR_CASE,
93 ATTR_CONST, /* const pseudo-attribute */
94 ATTR_CONTEXTHANDLE,
95 ATTR_CONTROL,
96 ATTR_DEFAULT,
97 ATTR_DEFAULTCOLLELEM,
98 ATTR_DEFAULTVALUE,
99 ATTR_DEFAULTVTABLE,
100 ATTR_DISPINTERFACE,
101 ATTR_DISPLAYBIND,
102 ATTR_DLLNAME,
103 ATTR_DUAL,
104 ATTR_ENDPOINT,
105 ATTR_ENTRY,
106 ATTR_EXPLICIT_HANDLE,
107 ATTR_HANDLE,
108 ATTR_HELPCONTEXT,
109 ATTR_HELPFILE,
110 ATTR_HELPSTRING,
111 ATTR_HELPSTRINGCONTEXT,
112 ATTR_HELPSTRINGDLL,
113 ATTR_HIDDEN,
114 ATTR_ID,
115 ATTR_IDEMPOTENT,
116 ATTR_IIDIS,
117 ATTR_IMMEDIATEBIND,
118 ATTR_IMPLICIT_HANDLE,
119 ATTR_IN,
120 ATTR_INLINE,
121 ATTR_INPUTSYNC,
122 ATTR_LENGTHIS,
123 ATTR_LIBLCID,
124 ATTR_LOCAL,
125 ATTR_NONBROWSABLE,
126 ATTR_NONCREATABLE,
127 ATTR_NONEXTENSIBLE,
128 ATTR_OBJECT,
129 ATTR_ODL,
130 ATTR_OLEAUTOMATION,
131 ATTR_OPTIONAL,
132 ATTR_OUT,
133 ATTR_PARAMLCID,
134 ATTR_POINTERDEFAULT,
135 ATTR_POINTERTYPE,
136 ATTR_PROPGET,
137 ATTR_PROPPUT,
138 ATTR_PROPPUTREF,
139 ATTR_PUBLIC,
140 ATTR_RANGE,
141 ATTR_READONLY,
142 ATTR_REQUESTEDIT,
143 ATTR_RESTRICTED,
144 ATTR_RETVAL,
145 ATTR_SIZEIS,
146 ATTR_SOURCE,
147 ATTR_STRICTCONTEXTHANDLE,
148 ATTR_STRING,
149 ATTR_SWITCHIS,
150 ATTR_SWITCHTYPE,
151 ATTR_TRANSMITAS,
152 ATTR_UUID,
153 ATTR_V1ENUM,
154 ATTR_VARARG,
155 ATTR_VERSION,
156 ATTR_WIREMARSHAL
157 };
158
159 enum expr_type
160 {
161 EXPR_VOID,
162 EXPR_NUM,
163 EXPR_HEXNUM,
164 EXPR_DOUBLE,
165 EXPR_IDENTIFIER,
166 EXPR_NEG,
167 EXPR_NOT,
168 EXPR_PPTR,
169 EXPR_CAST,
170 EXPR_SIZEOF,
171 EXPR_SHL,
172 EXPR_SHR,
173 EXPR_MUL,
174 EXPR_DIV,
175 EXPR_ADD,
176 EXPR_SUB,
177 EXPR_AND,
178 EXPR_OR,
179 EXPR_COND,
180 EXPR_TRUEFALSE,
181 EXPR_ADDRESSOF,
182 EXPR_MEMBER,
183 EXPR_ARRAY,
184 EXPR_MOD,
185 EXPR_LOGOR,
186 EXPR_LOGAND,
187 EXPR_XOR,
188 EXPR_EQUALITY,
189 EXPR_INEQUALITY,
190 EXPR_GTR,
191 EXPR_LESS,
192 EXPR_GTREQL,
193 EXPR_LESSEQL,
194 EXPR_LOGNOT,
195 EXPR_POS,
196 EXPR_STRLIT,
197 EXPR_WSTRLIT,
198 };
199
200 enum type_kind
201 {
202 TKIND_PRIMITIVE = -1,
203 TKIND_ENUM,
204 TKIND_RECORD,
205 TKIND_MODULE,
206 TKIND_INTERFACE,
207 TKIND_DISPATCH,
208 TKIND_COCLASS,
209 TKIND_ALIAS,
210 TKIND_UNION,
211 TKIND_MAX
212 };
213
214 enum storage_class
215 {
216 STG_NONE,
217 STG_STATIC,
218 STG_EXTERN,
219 STG_REGISTER,
220 };
221
222 enum statement_type
223 {
224 STMT_LIBRARY,
225 STMT_DECLARATION,
226 STMT_TYPE,
227 STMT_TYPEREF,
228 STMT_MODULE,
229 STMT_TYPEDEF,
230 STMT_IMPORT,
231 STMT_IMPORTLIB,
232 STMT_CPPQUOTE
233 };
234
235 enum type_basic_type
236 {
237 TYPE_BASIC_INT8 = 1,
238 TYPE_BASIC_INT16,
239 TYPE_BASIC_INT32,
240 TYPE_BASIC_INT64,
241 TYPE_BASIC_INT,
242 TYPE_BASIC_INT3264,
243 TYPE_BASIC_CHAR,
244 TYPE_BASIC_HYPER,
245 TYPE_BASIC_BYTE,
246 TYPE_BASIC_WCHAR,
247 TYPE_BASIC_FLOAT,
248 TYPE_BASIC_DOUBLE,
249 TYPE_BASIC_ERROR_STATUS_T,
250 TYPE_BASIC_HANDLE,
251 };
252
253 #define TYPE_BASIC_MAX TYPE_BASIC_HANDLE
254 #define TYPE_BASIC_INT_MIN TYPE_BASIC_INT8
255 #define TYPE_BASIC_INT_MAX TYPE_BASIC_HYPER
256
257 struct _loc_info_t
258 {
259 const char *input_name;
260 int line_number;
261 const char *near_text;
262 };
263
264 struct str_list_entry_t
265 {
266 char *str;
267 struct list entry;
268 };
269
270 struct _attr_t {
271 enum attr_type type;
272 union {
273 unsigned long ival;
274 void *pval;
275 } u;
276 /* parser-internal */
277 struct list entry;
278 };
279
280 struct _expr_t {
281 enum expr_type type;
282 const expr_t *ref;
283 union {
284 long lval;
285 double dval;
286 const char *sval;
287 const expr_t *ext;
288 type_t *tref;
289 } u;
290 const expr_t *ext2;
291 int is_const;
292 long cval;
293 /* parser-internal */
294 struct list entry;
295 };
296
297 struct struct_details
298 {
299 var_list_t *fields;
300 };
301
302 struct enumeration_details
303 {
304 var_list_t *enums;
305 };
306
307 struct func_details
308 {
309 var_list_t *args;
310 struct _type_t *rettype;
311 int idx;
312 };
313
314 struct iface_details
315 {
316 statement_list_t *stmts;
317 func_list_t *disp_methods;
318 var_list_t *disp_props;
319 struct _type_t *inherit;
320 };
321
322 struct module_details
323 {
324 statement_list_t *stmts;
325 func_list_t *funcs;
326 };
327
328 struct array_details
329 {
330 expr_t *size_is;
331 expr_t *length_is;
332 struct _type_t *elem;
333 unsigned int dim;
334 unsigned char ptr_def_fc;
335 unsigned char declptr; /* if declared as a pointer */
336 };
337
338 struct coclass_details
339 {
340 ifref_list_t *ifaces;
341 };
342
343 struct basic_details
344 {
345 enum type_basic_type type;
346 int sign;
347 };
348
349 struct pointer_details
350 {
351 struct _type_t *ref;
352 unsigned char def_fc;
353 };
354
355 struct bitfield_details
356 {
357 struct _type_t *field;
358 const expr_t *bits;
359 };
360
361 enum type_type
362 {
363 TYPE_VOID,
364 TYPE_BASIC, /* ints, floats and handles */
365 TYPE_ENUM,
366 TYPE_STRUCT,
367 TYPE_ENCAPSULATED_UNION,
368 TYPE_UNION,
369 TYPE_ALIAS,
370 TYPE_MODULE,
371 TYPE_COCLASS,
372 TYPE_FUNCTION,
373 TYPE_INTERFACE,
374 TYPE_POINTER,
375 TYPE_ARRAY,
376 TYPE_BITFIELD,
377 };
378
379 struct _type_t {
380 const char *name;
381 enum type_type type_type;
382 attr_list_t *attrs;
383 union
384 {
385 struct struct_details *structure;
386 struct enumeration_details *enumeration;
387 struct func_details *function;
388 struct iface_details *iface;
389 struct module_details *module;
390 struct array_details array;
391 struct coclass_details coclass;
392 struct basic_details basic;
393 struct pointer_details pointer;
394 struct bitfield_details bitfield;
395 } details;
396 type_t *orig; /* dup'd types */
397 unsigned int typestring_offset;
398 unsigned int ptrdesc; /* used for complex structs */
399 int typelib_idx;
400 loc_info_t loc_info;
401 unsigned int ignore : 1;
402 unsigned int defined : 1;
403 unsigned int written : 1;
404 unsigned int user_types_registered : 1;
405 unsigned int tfswrite : 1; /* if the type needs to be written to the TFS */
406 unsigned int checked : 1;
407 unsigned int is_alias : 1; /* is the type an alias? */
408 };
409
410 struct _var_t {
411 char *name;
412 type_t *type;
413 attr_list_t *attrs;
414 expr_t *eval;
415 enum storage_class stgclass;
416
417 struct _loc_info_t loc_info;
418
419 /* parser-internal */
420 struct list entry;
421 };
422
423 struct _declarator_t {
424 var_t *var;
425 type_t *type;
426 type_t *func_type;
427 array_dims_t *array;
428 expr_t *bits;
429
430 /* parser-internal */
431 struct list entry;
432 };
433
434 struct _func_t {
435 var_t *def;
436
437 /* parser-internal */
438 struct list entry;
439 };
440
441 struct _ifref_t {
442 type_t *iface;
443 attr_list_t *attrs;
444
445 /* parser-internal */
446 struct list entry;
447 };
448
449 struct _typelib_entry_t {
450 type_t *type;
451 struct list entry;
452 };
453
454 struct _importinfo_t {
455 int offset;
456 GUID guid;
457 int flags;
458 int id;
459
460 char *name;
461
462 importlib_t *importlib;
463 };
464
465 struct _importlib_t {
466 char *name;
467
468 int version;
469 GUID guid;
470
471 importinfo_t *importinfos;
472 int ntypeinfos;
473
474 int allocated;
475
476 struct list entry;
477 };
478
479 struct _typelib_t {
480 char *name;
481 char *filename;
482 const attr_list_t *attrs;
483 struct list importlibs;
484 statement_list_t *stmts;
485 };
486
487 struct _user_type_t {
488 struct list entry;
489 const char *name;
490 };
491
492 struct _type_list_t {
493 type_t *type;
494 struct _type_list_t *next;
495 };
496
497 struct _statement_t {
498 struct list entry;
499 enum statement_type type;
500 union
501 {
502 ifref_t iface;
503 type_t *type;
504 const char *str;
505 var_t *var;
506 typelib_t *lib;
507 type_list_t *type_list;
508 } u;
509 };
510
511 typedef enum {
512 SYS_WIN16,
513 SYS_WIN32,
514 SYS_MAC,
515 SYS_WIN64
516 } syskind_t;
517
518 extern syskind_t typelib_kind;
519 extern user_type_list_t user_type_list;
520 void check_for_additional_prototype_types(const var_list_t *list);
521
522 void init_types(void);
523 type_t *alloc_type(void);
524 void set_all_tfswrite(int val);
525 void clear_all_offsets(void);
526
527 int is_ptr(const type_t *t);
528 int is_array(const type_t *t);
529 int is_var_ptr(const var_t *v);
530 int cant_be_null(const var_t *v);
531 int is_struct(unsigned char tc);
532 int is_union(unsigned char tc);
533
534 #define tsENUM 1
535 #define tsSTRUCT 2
536 #define tsUNION 3
537
538 var_t *find_const(const char *name, int f);
539 type_t *find_type(const char *name, int t);
540 type_t *make_type(enum type_type type);
541 type_t *get_type(enum type_type type, char *name, int t);
542 type_t *reg_type(type_t *type, const char *name, int t);
543 void add_incomplete(type_t *t);
544
545 var_t *make_var(char *name);
546 var_list_t *append_var(var_list_t *list, var_t *var);
547
548 void init_loc_info(loc_info_t *);
549
550 static inline var_list_t *type_get_function_args(const type_t *func_type)
551 {
552 return func_type->details.function->args;
553 }
554
555 static inline enum type_type type_get_type_detect_alias(const type_t *type)
556 {
557 if (type->is_alias)
558 return TYPE_ALIAS;
559 return type->type_type;
560 }
561
562 #define STATEMENTS_FOR_EACH_FUNC(stmt, stmts) \
563 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, statement_t, entry ) \
564 if (stmt->type == STMT_DECLARATION && stmt->u.var->stgclass == STG_NONE && \
565 type_get_type_detect_alias(stmt->u.var->type) == TYPE_FUNCTION)
566
567 static inline int statements_has_func(const statement_list_t *stmts)
568 {
569 const statement_t *stmt;
570 int has_func = 0;
571 STATEMENTS_FOR_EACH_FUNC(stmt, stmts)
572 {
573 has_func = 1;
574 break;
575 }
576 return has_func;
577 }
578
579 #endif