widl: Lay framework for unions with simple unions working.
[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 "guiddef.h"
26 #include "wine/rpcfc.h"
27 #include "wine/list.h"
28
29 #ifndef UUID_DEFINED
30 #define UUID_DEFINED
31 typedef GUID UUID;
32 #endif
33
34 #define TRUE 1
35 #define FALSE 0
36
37 typedef struct _attr_t attr_t;
38 typedef struct _expr_t expr_t;
39 typedef struct _type_t type_t;
40 typedef struct _typeref_t typeref_t;
41 typedef struct _var_t var_t;
42 typedef struct _pident_t pident_t;
43 typedef struct _func_t func_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
50 typedef struct list attr_list_t;
51 typedef struct list str_list_t;
52 typedef struct list func_list_t;
53 typedef struct list expr_list_t;
54 typedef struct list var_list_t;
55 typedef struct list pident_list_t;
56 typedef struct list ifref_list_t;
57 typedef struct list array_dims_t;
58
59 enum attr_type
60 {
61     ATTR_AGGREGATABLE,
62     ATTR_APPOBJECT,
63     ATTR_ASYNC,
64     ATTR_AUTO_HANDLE,
65     ATTR_BINDABLE,
66     ATTR_CALLAS,
67     ATTR_CASE,
68     ATTR_CONTEXTHANDLE,
69     ATTR_CONTROL,
70     ATTR_DEFAULT,
71     ATTR_DEFAULTCOLLELEM,
72     ATTR_DEFAULTVALUE_EXPR,
73     ATTR_DEFAULTVALUE_STRING,
74     ATTR_DEFAULTVTABLE,
75     ATTR_DISPINTERFACE,
76     ATTR_DISPLAYBIND,
77     ATTR_DLLNAME,
78     ATTR_DUAL,
79     ATTR_ENDPOINT,
80     ATTR_ENTRY_ORDINAL,
81     ATTR_ENTRY_STRING,
82     ATTR_EXPLICIT_HANDLE,
83     ATTR_HANDLE,
84     ATTR_HELPCONTEXT,
85     ATTR_HELPFILE,
86     ATTR_HELPSTRING,
87     ATTR_HELPSTRINGCONTEXT,
88     ATTR_HELPSTRINGDLL,
89     ATTR_HIDDEN,
90     ATTR_ID,
91     ATTR_IDEMPOTENT,
92     ATTR_IIDIS,
93     ATTR_IMMEDIATEBIND,
94     ATTR_IMPLICIT_HANDLE,
95     ATTR_IN,
96     ATTR_INPUTSYNC,
97     ATTR_LENGTHIS,
98     ATTR_LOCAL,
99     ATTR_NONBROWSABLE,
100     ATTR_NONCREATABLE,
101     ATTR_NONEXTENSIBLE,
102     ATTR_OBJECT,
103     ATTR_ODL,
104     ATTR_OLEAUTOMATION,
105     ATTR_OPTIONAL,
106     ATTR_OUT,
107     ATTR_POINTERDEFAULT,
108     ATTR_POINTERTYPE,
109     ATTR_PROPGET,
110     ATTR_PROPPUT,
111     ATTR_PROPPUTREF,
112     ATTR_PUBLIC,
113     ATTR_RANGE,
114     ATTR_READONLY,
115     ATTR_REQUESTEDIT,
116     ATTR_RESTRICTED,
117     ATTR_RETVAL,
118     ATTR_SIZEIS,
119     ATTR_SOURCE,
120     ATTR_STRING,
121     ATTR_SWITCHIS,
122     ATTR_SWITCHTYPE,
123     ATTR_TRANSMITAS,
124     ATTR_UUID,
125     ATTR_V1ENUM,
126     ATTR_VARARG,
127     ATTR_VERSION,
128     ATTR_WIREMARSHAL
129 };
130
131 enum expr_type
132 {
133     EXPR_VOID,
134     EXPR_NUM,
135     EXPR_HEXNUM,
136     EXPR_IDENTIFIER,
137     EXPR_NEG,
138     EXPR_NOT,
139     EXPR_PPTR,
140     EXPR_CAST,
141     EXPR_SIZEOF,
142     EXPR_SHL,
143     EXPR_SHR,
144     EXPR_MUL,
145     EXPR_DIV,
146     EXPR_ADD,
147     EXPR_SUB,
148     EXPR_AND,
149     EXPR_OR,
150     EXPR_COND,
151     EXPR_TRUEFALSE,
152 };
153
154 enum type_kind
155 {
156     TKIND_PRIMITIVE = -1,
157     TKIND_ENUM,
158     TKIND_RECORD,
159     TKIND_MODULE,
160     TKIND_INTERFACE,
161     TKIND_DISPATCH,
162     TKIND_COCLASS,
163     TKIND_ALIAS,
164     TKIND_UNION,
165     TKIND_MAX
166 };
167
168 struct str_list_entry_t
169 {
170     char *str;
171     struct list entry;
172 };
173
174 struct _attr_t {
175   enum attr_type type;
176   union {
177     unsigned long ival;
178     void *pval;
179   } u;
180   /* parser-internal */
181   struct list entry;
182 };
183
184 struct _expr_t {
185   enum expr_type type;
186   const expr_t *ref;
187   union {
188     long lval;
189     const char *sval;
190     const expr_t *ext;
191     type_t *tref;
192   } u;
193   const expr_t *ext2;
194   int is_const;
195   long cval;
196   /* parser-internal */
197   struct list entry;
198 };
199
200 struct _type_t {
201   const char *name;
202   enum type_kind kind;
203   unsigned char type;
204   struct _type_t *ref;
205   const attr_list_t *attrs;
206   func_list_t *funcs;             /* interfaces and modules */
207   var_list_t *fields;             /* interfaces, structures and enumerations */
208   ifref_list_t *ifaces;           /* coclasses */
209   type_t *orig;                   /* dup'd types */
210   unsigned int typestring_offset;
211   int ignore, is_const, sign;
212   int defined, written, user_types_registered;
213   int typelib_idx;
214 };
215
216 struct _var_t {
217   char *name;
218   array_dims_t *array;
219   type_t *type;
220   var_list_t *args;  /* for function pointers */
221   attr_list_t *attrs;
222   expr_t *eval;
223   size_t corrdesc;  /* offset to correlation descriptor (e.g., for unions) */
224
225   /* parser-internal */
226   struct list entry;
227 };
228
229 struct _pident_t {
230   var_t *var;
231   int ptr_level;
232
233   /* parser-internal */
234   struct list entry;
235 };
236
237 struct _func_t {
238   var_t *def;
239   var_list_t *args;
240   int ignore, idx;
241
242   /* parser-internal */
243   struct list entry;
244 };
245
246 struct _ifref_t {
247   type_t *iface;
248   attr_list_t *attrs;
249
250   /* parser-internal */
251   struct list entry;
252 };
253
254 struct _typelib_entry_t {
255     type_t *type;
256     struct list entry;
257 };
258
259 struct _importinfo_t {
260     int offset;
261     GUID guid;
262     int flags;
263     int id;
264
265     char *name;
266
267     importlib_t *importlib;
268 };
269
270 struct _importlib_t {
271     char *name;
272
273     int version;
274     GUID guid;
275
276     importinfo_t *importinfos;
277     int ntypeinfos;
278
279     int allocated;
280
281     struct list entry;
282 };
283
284 struct _typelib_t {
285     char *name;
286     char *filename;
287     attr_list_t *attrs;
288     struct list entries;
289     struct list importlibs;
290 };
291
292 void init_types(void);
293
294 type_t *duptype(type_t *t, int dupname);
295 type_t *alias(type_t *t, const char *name);
296
297 int is_ptr(const type_t *t);
298 int is_var_ptr(const var_t *v);
299 int cant_be_null(const var_t *v);
300
301 #endif