crypt32: Correctly match subdomains with dns name constraints.
[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_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 };
190
191 enum type_kind
192 {
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
203 };
204
205 enum storage_class
206 {
207     STG_NONE,
208     STG_STATIC,
209     STG_EXTERN,
210     STG_REGISTER,
211 };
212
213 enum statement_type
214 {
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
224 };
225
226 enum type_basic_type
227 {
228     TYPE_BASIC_INT8 = 1,
229     TYPE_BASIC_INT16,
230     TYPE_BASIC_INT32,
231     TYPE_BASIC_INT64,
232     TYPE_BASIC_INT,
233     TYPE_BASIC_INT3264,
234     TYPE_BASIC_CHAR,
235     TYPE_BASIC_HYPER,
236     TYPE_BASIC_BYTE,
237     TYPE_BASIC_WCHAR,
238     TYPE_BASIC_FLOAT,
239     TYPE_BASIC_DOUBLE,
240     TYPE_BASIC_ERROR_STATUS_T,
241     TYPE_BASIC_HANDLE,
242 };
243
244 #define TYPE_BASIC_MAX TYPE_BASIC_HANDLE
245 #define TYPE_BASIC_INT_MIN TYPE_BASIC_INT8
246 #define TYPE_BASIC_INT_MAX TYPE_BASIC_HYPER
247
248 struct _loc_info_t
249 {
250     const char *input_name;
251     int line_number;
252     const char *near_text;
253 };
254
255 struct str_list_entry_t
256 {
257     char *str;
258     struct list entry;
259 };
260
261 struct _attr_t {
262   enum attr_type type;
263   union {
264     unsigned long ival;
265     void *pval;
266   } u;
267   /* parser-internal */
268   struct list entry;
269 };
270
271 struct _expr_t {
272   enum expr_type type;
273   const expr_t *ref;
274   union {
275     long lval;
276     double dval;
277     const char *sval;
278     const expr_t *ext;
279     type_t *tref;
280   } u;
281   const expr_t *ext2;
282   int is_const;
283   long cval;
284   /* parser-internal */
285   struct list entry;
286 };
287
288 struct struct_details
289 {
290   var_list_t *fields;
291 };
292
293 struct enumeration_details
294 {
295   var_list_t *enums;
296 };
297
298 struct func_details
299 {
300   var_list_t *args;
301   struct _type_t *rettype;
302   int idx;
303 };
304
305 struct iface_details
306 {
307   statement_list_t *stmts;
308   func_list_t *disp_methods;
309   var_list_t *disp_props;
310   struct _type_t *inherit;
311 };
312
313 struct module_details
314 {
315   statement_list_t *stmts;
316   func_list_t *funcs;
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 _func_t {
426   var_t *def;
427
428   /* parser-internal */
429   struct list entry;
430 };
431
432 struct _ifref_t {
433   type_t *iface;
434   attr_list_t *attrs;
435
436   /* parser-internal */
437   struct list entry;
438 };
439
440 struct _typelib_entry_t {
441     type_t *type;
442     struct list entry;
443 };
444
445 struct _importinfo_t {
446     int offset;
447     GUID guid;
448     int flags;
449     int id;
450
451     char *name;
452
453     importlib_t *importlib;
454 };
455
456 struct _importlib_t {
457     char *name;
458
459     int version;
460     GUID guid;
461
462     importinfo_t *importinfos;
463     int ntypeinfos;
464
465     int allocated;
466
467     struct list entry;
468 };
469
470 struct _typelib_t {
471     char *name;
472     char *filename;
473     const attr_list_t *attrs;
474     struct list importlibs;
475     statement_list_t *stmts;
476 };
477
478 struct _user_type_t {
479     struct list entry;
480     const char *name;
481 };
482
483 struct _type_list_t {
484     type_t *type;
485     struct _type_list_t *next;
486 };
487
488 struct _statement_t {
489     struct list entry;
490     enum statement_type type;
491     union
492     {
493         ifref_t iface;
494         type_t *type;
495         const char *str;
496         var_t *var;
497         typelib_t *lib;
498         type_list_t *type_list;
499     } u;
500 };
501
502 typedef enum {
503     SYS_WIN16,
504     SYS_WIN32,
505     SYS_MAC,
506     SYS_WIN64
507 } syskind_t;
508
509 extern syskind_t typelib_kind;
510 extern user_type_list_t user_type_list;
511 void check_for_additional_prototype_types(const var_list_t *list);
512
513 void init_types(void);
514 type_t *alloc_type(void);
515 void set_all_tfswrite(int val);
516 void clear_all_offsets(void);
517
518 int is_ptr(const type_t *t);
519 int is_array(const type_t *t);
520 int is_var_ptr(const var_t *v);
521 int cant_be_null(const var_t *v);
522 int is_struct(unsigned char tc);
523 int is_union(unsigned char tc);
524
525 #define tsENUM   1
526 #define tsSTRUCT 2
527 #define tsUNION  3
528
529 var_t *find_const(const char *name, int f);
530 type_t *find_type(const char *name, int t);
531 type_t *make_type(enum type_type type);
532 type_t *get_type(enum type_type type, char *name, int t);
533 type_t *reg_type(type_t *type, const char *name, int t);
534 void add_incomplete(type_t *t);
535
536 var_t *make_var(char *name);
537 var_list_t *append_var(var_list_t *list, var_t *var);
538
539 void init_loc_info(loc_info_t *);
540
541 static inline var_list_t *type_get_function_args(const type_t *func_type)
542 {
543   return func_type->details.function->args;
544 }
545
546 static inline enum type_type type_get_type_detect_alias(const type_t *type)
547 {
548     if (type->is_alias)
549         return TYPE_ALIAS;
550     return type->type_type;
551 }
552
553 #define STATEMENTS_FOR_EACH_FUNC(stmt, stmts) \
554   if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, statement_t, entry ) \
555     if (stmt->type == STMT_DECLARATION && stmt->u.var->stgclass == STG_NONE && \
556         type_get_type_detect_alias(stmt->u.var->type) == TYPE_FUNCTION)
557
558 static inline int statements_has_func(const statement_list_t *stmts)
559 {
560   const statement_t *stmt;
561   int has_func = 0;
562   STATEMENTS_FOR_EACH_FUNC(stmt, stmts)
563   {
564     has_func = 1;
565     break;
566   }
567   return has_func;
568 }
569
570 #endif