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