push 52d6b63ba2f2d4f9b02b6b922d27bff05a60596f
[wine/hacks.git] / tools / widl / widltypes.h
blobe80c7ed821b0193c98d815ebeea344370f4bd752
1 /*
2 * IDL Compiler
4 * Copyright 2002 Ove Kaaven
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.
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.
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
21 #ifndef __WIDL_WIDLTYPES_H
22 #define __WIDL_WIDLTYPES_H
24 #include <stdarg.h>
25 #include <assert.h>
26 #include "guiddef.h"
27 #include "wine/rpcfc.h"
28 #include "wine/list.h"
30 #ifndef UUID_DEFINED
31 #define UUID_DEFINED
32 typedef GUID UUID;
33 #endif
35 #define TRUE 1
36 #define FALSE 0
38 #define RPC_FC_MODULE 0xfc
39 #define RPC_FC_COCLASS 0xfd
40 #define RPC_FC_FUNCTION 0xfe
42 typedef struct _loc_info_t loc_info_t;
43 typedef struct _attr_t attr_t;
44 typedef struct _expr_t expr_t;
45 typedef struct _type_t type_t;
46 typedef struct _typeref_t typeref_t;
47 typedef struct _var_t var_t;
48 typedef struct _declarator_t declarator_t;
49 typedef struct _func_t func_t;
50 typedef struct _ifref_t ifref_t;
51 typedef struct _typelib_entry_t typelib_entry_t;
52 typedef struct _importlib_t importlib_t;
53 typedef struct _importinfo_t importinfo_t;
54 typedef struct _typelib_t typelib_t;
55 typedef struct _user_type_t user_type_t;
56 typedef struct _user_type_t context_handle_t;
57 typedef struct _type_list_t type_list_t;
58 typedef struct _statement_t statement_t;
60 typedef struct list attr_list_t;
61 typedef struct list str_list_t;
62 typedef struct list func_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;
72 enum attr_type
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
150 enum expr_type
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,
191 enum type_kind
193 TKIND_PRIMITIVE = -1,
194 TKIND_ENUM,
195 TKIND_RECORD,
196 TKIND_MODULE,
197 TKIND_INTERFACE,
198 TKIND_DISPATCH,
199 TKIND_COCLASS,
200 TKIND_ALIAS,
201 TKIND_UNION,
202 TKIND_MAX
205 enum storage_class
207 STG_NONE,
208 STG_STATIC,
209 STG_EXTERN,
210 STG_REGISTER,
213 enum statement_type
215 STMT_LIBRARY,
216 STMT_DECLARATION,
217 STMT_TYPE,
218 STMT_TYPEREF,
219 STMT_MODULE,
220 STMT_TYPEDEF,
221 STMT_IMPORT,
222 STMT_IMPORTLIB,
223 STMT_CPPQUOTE
226 enum type_basic_type
228 TYPE_BASIC_INT8 = 1,
229 TYPE_BASIC_INT16,
230 TYPE_BASIC_INT32,
231 TYPE_BASIC_INT64,
232 TYPE_BASIC_INT,
233 TYPE_BASIC_CHAR,
234 TYPE_BASIC_HYPER,
235 TYPE_BASIC_BYTE,
236 TYPE_BASIC_WCHAR,
237 TYPE_BASIC_FLOAT,
238 TYPE_BASIC_DOUBLE,
239 TYPE_BASIC_ERROR_STATUS_T,
240 TYPE_BASIC_HANDLE,
243 #define TYPE_BASIC_MAX TYPE_BASIC_HANDLE
244 #define TYPE_BASIC_INT_MIN TYPE_BASIC_INT8
245 #define TYPE_BASIC_INT_MAX TYPE_BASIC_HYPER
247 struct _loc_info_t
249 const char *input_name;
250 int line_number;
251 const char *near_text;
254 struct str_list_entry_t
256 char *str;
257 struct list entry;
260 struct _attr_t {
261 enum attr_type type;
262 union {
263 unsigned long ival;
264 void *pval;
265 } u;
266 /* parser-internal */
267 struct list entry;
270 struct _expr_t {
271 enum expr_type type;
272 const expr_t *ref;
273 union {
274 long lval;
275 double dval;
276 const char *sval;
277 const expr_t *ext;
278 type_t *tref;
279 } u;
280 const expr_t *ext2;
281 int is_const;
282 long cval;
283 /* parser-internal */
284 struct list entry;
287 struct struct_details
289 var_list_t *fields;
292 struct enumeration_details
294 var_list_t *enums;
297 struct func_details
299 var_list_t *args;
300 struct _type_t *rettype;
301 int idx;
304 struct iface_details
306 statement_list_t *stmts;
307 func_list_t *disp_methods;
308 var_list_t *disp_props;
309 struct _type_t *inherit;
312 struct module_details
314 statement_list_t *stmts;
315 func_list_t *funcs;
318 struct array_details
320 expr_t *size_is;
321 expr_t *length_is;
322 struct _type_t *elem;
323 unsigned int dim;
324 unsigned char ptr_def_fc;
325 unsigned char declptr; /* if declared as a pointer */
328 struct coclass_details
330 ifref_list_t *ifaces;
333 struct basic_details
335 enum type_basic_type type;
336 int sign;
339 struct pointer_details
341 struct _type_t *ref;
342 unsigned char def_fc;
345 enum type_type
347 TYPE_VOID,
348 TYPE_BASIC, /* ints, floats and handles */
349 TYPE_ENUM,
350 TYPE_STRUCT,
351 TYPE_ENCAPSULATED_UNION,
352 TYPE_UNION,
353 TYPE_ALIAS,
354 TYPE_MODULE,
355 TYPE_COCLASS,
356 TYPE_FUNCTION,
357 TYPE_INTERFACE,
358 TYPE_POINTER,
359 TYPE_ARRAY,
362 struct _type_t {
363 const char *name;
364 enum type_type type_type;
365 attr_list_t *attrs;
366 union
368 struct struct_details *structure;
369 struct enumeration_details *enumeration;
370 struct func_details *function;
371 struct iface_details *iface;
372 struct module_details *module;
373 struct array_details array;
374 struct coclass_details coclass;
375 struct basic_details basic;
376 struct pointer_details pointer;
377 } details;
378 type_t *orig; /* dup'd types */
379 unsigned int typestring_offset;
380 unsigned int ptrdesc; /* used for complex structs */
381 int typelib_idx;
382 loc_info_t loc_info;
383 unsigned int ignore : 1;
384 unsigned int defined : 1;
385 unsigned int written : 1;
386 unsigned int user_types_registered : 1;
387 unsigned int tfswrite : 1; /* if the type needs to be written to the TFS */
388 unsigned int checked : 1;
389 unsigned int is_alias : 1; /* is the type an alias? */
392 struct _var_t {
393 char *name;
394 type_t *type;
395 attr_list_t *attrs;
396 expr_t *eval;
397 enum storage_class stgclass;
399 struct _loc_info_t loc_info;
401 /* parser-internal */
402 struct list entry;
405 struct _declarator_t {
406 var_t *var;
407 type_t *type;
408 type_t *func_type;
409 array_dims_t *array;
411 /* parser-internal */
412 struct list entry;
415 struct _func_t {
416 var_t *def;
418 /* parser-internal */
419 struct list entry;
422 struct _ifref_t {
423 type_t *iface;
424 attr_list_t *attrs;
426 /* parser-internal */
427 struct list entry;
430 struct _typelib_entry_t {
431 type_t *type;
432 struct list entry;
435 struct _importinfo_t {
436 int offset;
437 GUID guid;
438 int flags;
439 int id;
441 char *name;
443 importlib_t *importlib;
446 struct _importlib_t {
447 char *name;
449 int version;
450 GUID guid;
452 importinfo_t *importinfos;
453 int ntypeinfos;
455 int allocated;
457 struct list entry;
460 struct _typelib_t {
461 char *name;
462 char *filename;
463 const attr_list_t *attrs;
464 struct list importlibs;
465 statement_list_t *stmts;
468 struct _user_type_t {
469 struct list entry;
470 const char *name;
473 struct _type_list_t {
474 type_t *type;
475 struct _type_list_t *next;
478 struct _statement_t {
479 struct list entry;
480 enum statement_type type;
481 union
483 ifref_t iface;
484 type_t *type;
485 const char *str;
486 var_t *var;
487 typelib_t *lib;
488 type_list_t *type_list;
489 } u;
492 typedef enum {
493 SYS_WIN16,
494 SYS_WIN32,
495 SYS_MAC,
496 SYS_WIN64
497 } syskind_t;
499 extern syskind_t typelib_kind;
500 extern user_type_list_t user_type_list;
501 void check_for_additional_prototype_types(const var_list_t *list);
503 void init_types(void);
504 type_t *alloc_type(void);
505 void set_all_tfswrite(int val);
506 void clear_all_offsets(void);
508 int is_ptr(const type_t *t);
509 int is_array(const type_t *t);
510 int is_var_ptr(const var_t *v);
511 int cant_be_null(const var_t *v);
512 int is_struct(unsigned char tc);
513 int is_union(unsigned char tc);
515 #define tsENUM 1
516 #define tsSTRUCT 2
517 #define tsUNION 3
519 var_t *find_const(const char *name, int f);
520 type_t *find_type(const char *name, int t);
521 type_t *make_type(enum type_type type);
522 type_t *get_type(enum type_type type, char *name, int t);
523 type_t *reg_type(type_t *type, const char *name, int t);
524 void add_incomplete(type_t *t);
526 var_t *make_var(char *name);
527 var_list_t *append_var(var_list_t *list, var_t *var);
529 void init_loc_info(loc_info_t *);
531 static inline var_list_t *type_get_function_args(const type_t *func_type)
533 return func_type->details.function->args;
536 static inline enum type_type type_get_type_detect_alias(const type_t *type)
538 if (type->is_alias)
539 return TYPE_ALIAS;
540 return type->type_type;
543 #define STATEMENTS_FOR_EACH_FUNC(stmt, stmts) \
544 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, statement_t, entry ) \
545 if (stmt->type == STMT_DECLARATION && stmt->u.var->stgclass == STG_NONE && \
546 type_get_type_detect_alias(stmt->u.var->type) == TYPE_FUNCTION)
548 static inline int statements_has_func(const statement_list_t *stmts)
550 const statement_t *stmt;
551 int has_func = 0;
552 STATEMENTS_FOR_EACH_FUNC(stmt, stmts)
554 has_func = 1;
555 break;
557 return has_func;
560 #endif