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