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