Sync to wine-0.9.60:
[reactos.git] / reactos / 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 #define S_OK 0
25 #define S_FALSE 1
26 #define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
27 #define TYPE_E_IOERROR ((HRESULT)0x80028CA2L)
28
29 #define max(a, b) ((a) > (b) ? a : b)
30
31 #include <stdarg.h>
32 #include "guiddef.h"
33 #include "wine/rpcfc.h"
34 #include "wine/list.h"
35
36 #ifndef UUID_DEFINED
37 #define UUID_DEFINED
38 typedef GUID UUID;
39 #endif
40
41 #ifndef TRUE
42 #define TRUE 1
43 #endif
44 #define FALSE 0
45
46 #define RPC_FC_FUNCTION 0xfe
47
48 typedef struct _loc_info_t loc_info_t;
49 typedef struct _attr_t attr_t;
50 typedef struct _expr_t expr_t;
51 typedef struct _type_t type_t;
52 typedef struct _typeref_t typeref_t;
53 typedef struct _var_t var_t;
54 typedef struct _pident_t pident_t;
55 typedef struct _func_t func_t;
56 typedef struct _ifref_t ifref_t;
57 typedef struct _typelib_entry_t typelib_entry_t;
58 typedef struct _importlib_t importlib_t;
59 typedef struct _importinfo_t importinfo_t;
60 typedef struct _typelib_t typelib_t;
61 typedef struct _user_type_t user_type_t;
62 typedef struct _user_type_t context_handle_t;
63
64 typedef struct list attr_list_t;
65 typedef struct list str_list_t;
66 typedef struct list func_list_t;
67 typedef struct list expr_list_t;
68 typedef struct list var_list_t;
69 typedef struct list pident_list_t;
70 typedef struct list ifref_list_t;
71 typedef struct list array_dims_t;
72 typedef struct list user_type_list_t;
73 typedef struct list context_handle_list_t;
74
75 enum attr_type
76 {
77 ATTR_AGGREGATABLE,
78 ATTR_APPOBJECT,
79 ATTR_ASYNC,
80 ATTR_AUTO_HANDLE,
81 ATTR_BINDABLE,
82 ATTR_BROADCAST,
83 ATTR_CALLAS,
84 ATTR_CALLCONV, /* calling convention pseudo-attribute */
85 ATTR_CASE,
86 ATTR_CONTEXTHANDLE,
87 ATTR_CONTROL,
88 ATTR_DEFAULT,
89 ATTR_DEFAULTCOLLELEM,
90 ATTR_DEFAULTVALUE_EXPR,
91 ATTR_DEFAULTVALUE_STRING,
92 ATTR_DEFAULTVTABLE,
93 ATTR_DISPINTERFACE,
94 ATTR_DISPLAYBIND,
95 ATTR_DLLNAME,
96 ATTR_DUAL,
97 ATTR_ENDPOINT,
98 ATTR_ENTRY_ORDINAL,
99 ATTR_ENTRY_STRING,
100 ATTR_EXPLICIT_HANDLE,
101 ATTR_HANDLE,
102 ATTR_HELPCONTEXT,
103 ATTR_HELPFILE,
104 ATTR_HELPSTRING,
105 ATTR_HELPSTRINGCONTEXT,
106 ATTR_HELPSTRINGDLL,
107 ATTR_HIDDEN,
108 ATTR_ID,
109 ATTR_IDEMPOTENT,
110 ATTR_IIDIS,
111 ATTR_IMMEDIATEBIND,
112 ATTR_IMPLICIT_HANDLE,
113 ATTR_IN,
114 ATTR_INPUTSYNC,
115 ATTR_LENGTHIS,
116 ATTR_LOCAL,
117 ATTR_NONBROWSABLE,
118 ATTR_NONCREATABLE,
119 ATTR_NONEXTENSIBLE,
120 ATTR_OBJECT,
121 ATTR_ODL,
122 ATTR_OLEAUTOMATION,
123 ATTR_OPTIONAL,
124 ATTR_OUT,
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 };
174
175 enum type_kind
176 {
177 TKIND_PRIMITIVE = -1,
178 TKIND_ENUM,
179 TKIND_RECORD,
180 TKIND_MODULE,
181 TKIND_INTERFACE,
182 TKIND_DISPATCH,
183 TKIND_COCLASS,
184 TKIND_ALIAS,
185 TKIND_UNION,
186 TKIND_MAX
187 };
188
189 struct _loc_info_t
190 {
191 const char *input_name;
192 int line_number;
193 const char *near_text;
194 };
195
196 struct str_list_entry_t
197 {
198 char *str;
199 struct list entry;
200 };
201
202 struct _attr_t {
203 enum attr_type type;
204 union {
205 unsigned long ival;
206 void *pval;
207 } u;
208 /* parser-internal */
209 struct list entry;
210 };
211
212 struct _expr_t {
213 enum expr_type type;
214 const expr_t *ref;
215 union {
216 long lval;
217 double dval;
218 const char *sval;
219 const expr_t *ext;
220 type_t *tref;
221 } u;
222 const expr_t *ext2;
223 int is_const;
224 long cval;
225 /* parser-internal */
226 struct list entry;
227 };
228
229 struct _type_t {
230 const char *name;
231 enum type_kind kind;
232 unsigned char type;
233 struct _type_t *ref;
234 const attr_list_t *attrs;
235 func_list_t *funcs; /* interfaces and modules */
236 var_list_t *fields_or_args; /* interfaces, structures, enumerations and functions (for args) */
237 ifref_list_t *ifaces; /* coclasses */
238 unsigned long dim; /* array dimension */
239 expr_t *size_is, *length_is;
240 type_t *orig; /* dup'd types */
241 unsigned int typestring_offset;
242 unsigned int ptrdesc; /* used for complex structs */
243 int typelib_idx;
244 unsigned int declarray : 1; /* if declared as an array */
245 unsigned int ignore : 1;
246 unsigned int is_const : 1;
247 unsigned int defined : 1;
248 unsigned int written : 1;
249 unsigned int user_types_registered : 1;
250 unsigned int tfswrite : 1; /* if the type needs to be written to the TFS */
251 int sign : 2;
252 };
253
254 struct _var_t {
255 char *name;
256 type_t *type;
257 attr_list_t *attrs;
258 expr_t *eval;
259
260 struct _loc_info_t loc_info;
261
262 /* parser-internal */
263 struct list entry;
264 };
265
266 struct _pident_t {
267 var_t *var;
268 int ptr_level;
269
270 int is_func;
271 /* levels of indirection for function pointers */
272 int func_ptr_level;
273 var_list_t *args;
274 char *callconv;
275
276 /* parser-internal */
277 struct list entry;
278 };
279
280 struct _func_t {
281 var_t *def;
282 var_list_t *args;
283 int ignore, idx;
284
285 /* parser-internal */
286 struct list entry;
287 };
288
289 struct _ifref_t {
290 type_t *iface;
291 attr_list_t *attrs;
292
293 /* parser-internal */
294 struct list entry;
295 };
296
297 struct _typelib_entry_t {
298 type_t *type;
299 struct list entry;
300 };
301
302 struct _importinfo_t {
303 int offset;
304 GUID guid;
305 int flags;
306 int id;
307
308 char *name;
309
310 importlib_t *importlib;
311 };
312
313 struct _importlib_t {
314 char *name;
315
316 int version;
317 GUID guid;
318
319 importinfo_t *importinfos;
320 int ntypeinfos;
321
322 int allocated;
323
324 struct list entry;
325 };
326
327 struct _typelib_t {
328 char *name;
329 char *filename;
330 const attr_list_t *attrs;
331 struct list entries;
332 struct list importlibs;
333 };
334
335 struct _user_type_t {
336 struct list entry;
337 const char *name;
338 };
339
340 extern unsigned char pointer_default;
341
342 extern user_type_list_t user_type_list;
343 void check_for_additional_prototype_types(const var_list_t *list);
344
345 void init_types(void);
346 type_t *alloc_type(void);
347 void set_all_tfswrite(int val);
348
349 type_t *duptype(type_t *t, int dupname);
350 type_t *alias(type_t *t, const char *name);
351
352 int is_ptr(const type_t *t);
353 int is_array(const type_t *t);
354 int is_var_ptr(const var_t *v);
355 int cant_be_null(const var_t *v);
356 int is_struct(unsigned char tc);
357 int is_union(unsigned char tc);
358
359 static inline type_t *get_func_return_type(const func_t *func)
360 {
361 return func->def->type->ref;
362 }
363
364 #endif