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