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