widl: Add a function to get the return type of a parsed function.
[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 typedef struct _user_type_t user_type_t;
50 typedef struct _user_type_t context_handle_t;
51
52 typedef struct list attr_list_t;
53 typedef struct list str_list_t;
54 typedef struct list func_list_t;
55 typedef struct list expr_list_t;
56 typedef struct list var_list_t;
57 typedef struct list pident_list_t;
58 typedef struct list ifref_list_t;
59 typedef struct list array_dims_t;
60 typedef struct list user_type_list_t;
61 typedef struct list context_handle_list_t;
62
63 enum attr_type
64 {
65     ATTR_AGGREGATABLE,
66     ATTR_APPOBJECT,
67     ATTR_ASYNC,
68     ATTR_AUTO_HANDLE,
69     ATTR_BINDABLE,
70     ATTR_CALLAS,
71     ATTR_CASE,
72     ATTR_CONTEXTHANDLE,
73     ATTR_CONTROL,
74     ATTR_DEFAULT,
75     ATTR_DEFAULTCOLLELEM,
76     ATTR_DEFAULTVALUE_EXPR,
77     ATTR_DEFAULTVALUE_STRING,
78     ATTR_DEFAULTVTABLE,
79     ATTR_DISPINTERFACE,
80     ATTR_DISPLAYBIND,
81     ATTR_DLLNAME,
82     ATTR_DUAL,
83     ATTR_ENDPOINT,
84     ATTR_ENTRY_ORDINAL,
85     ATTR_ENTRY_STRING,
86     ATTR_EXPLICIT_HANDLE,
87     ATTR_HANDLE,
88     ATTR_HELPCONTEXT,
89     ATTR_HELPFILE,
90     ATTR_HELPSTRING,
91     ATTR_HELPSTRINGCONTEXT,
92     ATTR_HELPSTRINGDLL,
93     ATTR_HIDDEN,
94     ATTR_ID,
95     ATTR_IDEMPOTENT,
96     ATTR_IIDIS,
97     ATTR_IMMEDIATEBIND,
98     ATTR_IMPLICIT_HANDLE,
99     ATTR_IN,
100     ATTR_INPUTSYNC,
101     ATTR_LENGTHIS,
102     ATTR_LOCAL,
103     ATTR_NONBROWSABLE,
104     ATTR_NONCREATABLE,
105     ATTR_NONEXTENSIBLE,
106     ATTR_OBJECT,
107     ATTR_ODL,
108     ATTR_OLEAUTOMATION,
109     ATTR_OPTIONAL,
110     ATTR_OUT,
111     ATTR_POINTERDEFAULT,
112     ATTR_POINTERTYPE,
113     ATTR_PROPGET,
114     ATTR_PROPPUT,
115     ATTR_PROPPUTREF,
116     ATTR_PUBLIC,
117     ATTR_RANGE,
118     ATTR_READONLY,
119     ATTR_REQUESTEDIT,
120     ATTR_RESTRICTED,
121     ATTR_RETVAL,
122     ATTR_SIZEIS,
123     ATTR_SOURCE,
124     ATTR_STRICTCONTEXTHANDLE,
125     ATTR_STRING,
126     ATTR_SWITCHIS,
127     ATTR_SWITCHTYPE,
128     ATTR_TRANSMITAS,
129     ATTR_UUID,
130     ATTR_V1ENUM,
131     ATTR_VARARG,
132     ATTR_VERSION,
133     ATTR_WIREMARSHAL
134 };
135
136 enum expr_type
137 {
138     EXPR_VOID,
139     EXPR_NUM,
140     EXPR_HEXNUM,
141     EXPR_DOUBLE,
142     EXPR_IDENTIFIER,
143     EXPR_NEG,
144     EXPR_NOT,
145     EXPR_PPTR,
146     EXPR_CAST,
147     EXPR_SIZEOF,
148     EXPR_SHL,
149     EXPR_SHR,
150     EXPR_MUL,
151     EXPR_DIV,
152     EXPR_ADD,
153     EXPR_SUB,
154     EXPR_AND,
155     EXPR_OR,
156     EXPR_COND,
157     EXPR_TRUEFALSE,
158     EXPR_ADDRESSOF,
159 };
160
161 enum type_kind
162 {
163     TKIND_PRIMITIVE = -1,
164     TKIND_ENUM,
165     TKIND_RECORD,
166     TKIND_MODULE,
167     TKIND_INTERFACE,
168     TKIND_DISPATCH,
169     TKIND_COCLASS,
170     TKIND_ALIAS,
171     TKIND_UNION,
172     TKIND_MAX
173 };
174
175 struct str_list_entry_t
176 {
177     char *str;
178     struct list entry;
179 };
180
181 struct _attr_t {
182   enum attr_type type;
183   union {
184     unsigned long ival;
185     void *pval;
186   } u;
187   /* parser-internal */
188   struct list entry;
189 };
190
191 struct _expr_t {
192   enum expr_type type;
193   const expr_t *ref;
194   union {
195     long lval;
196     double dval;
197     const char *sval;
198     const expr_t *ext;
199     type_t *tref;
200   } u;
201   const expr_t *ext2;
202   int is_const;
203   long cval;
204   /* parser-internal */
205   struct list entry;
206 };
207
208 struct _type_t {
209   const char *name;
210   enum type_kind kind;
211   unsigned char type;
212   struct _type_t *ref;
213   const attr_list_t *attrs;
214   func_list_t *funcs;             /* interfaces and modules */
215   var_list_t *fields;             /* interfaces, structures and enumerations */
216   ifref_list_t *ifaces;           /* coclasses */
217   unsigned long dim;              /* array dimension */
218   expr_t *size_is, *length_is;
219   type_t *orig;                   /* dup'd types */
220   unsigned int typestring_offset;
221   unsigned int ptrdesc;           /* used for complex structs */
222   int typelib_idx;
223   unsigned int declarray : 1;     /* if declared as an array */
224   unsigned int ignore : 1;
225   unsigned int is_const : 1;
226   unsigned int defined : 1;
227   unsigned int written : 1;
228   unsigned int user_types_registered : 1;
229   unsigned int tfswrite : 1;   /* if the type needs to be written to the TFS */
230   int sign : 2;
231 };
232
233 struct _var_t {
234   char *name;
235   type_t *type;
236   var_list_t *args;  /* for function pointers */
237   attr_list_t *attrs;
238   expr_t *eval;
239
240   /* parser-internal */
241   struct list entry;
242 };
243
244 struct _pident_t {
245   var_t *var;
246   int ptr_level;
247   /* levels of indirection for function pointers */
248   int func_ptr_level;
249
250   /* parser-internal */
251   struct list entry;
252 };
253
254 struct _func_t {
255   var_t *def;
256   var_list_t *args;
257   int ignore, idx;
258
259   /* parser-internal */
260   struct list entry;
261 };
262
263 struct _ifref_t {
264   type_t *iface;
265   attr_list_t *attrs;
266
267   /* parser-internal */
268   struct list entry;
269 };
270
271 struct _typelib_entry_t {
272     type_t *type;
273     struct list entry;
274 };
275
276 struct _importinfo_t {
277     int offset;
278     GUID guid;
279     int flags;
280     int id;
281
282     char *name;
283
284     importlib_t *importlib;
285 };
286
287 struct _importlib_t {
288     char *name;
289
290     int version;
291     GUID guid;
292
293     importinfo_t *importinfos;
294     int ntypeinfos;
295
296     int allocated;
297
298     struct list entry;
299 };
300
301 struct _typelib_t {
302     char *name;
303     char *filename;
304     attr_list_t *attrs;
305     struct list entries;
306     struct list importlibs;
307 };
308
309 struct _user_type_t {
310     struct list entry;
311     const char *name;
312 };
313
314 extern unsigned char pointer_default;
315
316 extern user_type_list_t user_type_list;
317 void check_for_additional_prototype_types(const var_list_t *list);
318
319 void init_types(void);
320 type_t *alloc_type(void);
321 void set_all_tfswrite(int val);
322
323 type_t *duptype(type_t *t, int dupname);
324 type_t *alias(type_t *t, const char *name);
325
326 int is_ptr(const type_t *t);
327 int is_array(const type_t *t);
328 int is_var_ptr(const var_t *v);
329 int cant_be_null(const var_t *v);
330 int is_struct(unsigned char tc);
331 int is_union(unsigned char tc);
332
333 static inline type_t *get_func_return_type(const func_t *func)
334 {
335   return func->def->type;
336 }
337
338 #endif