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