wnaspi32: Make winaspi.dll into a stand-alone 16-bit module.
[wine] / tools / widl / typetree.h
1 /*
2  * IDL Type Tree
3  *
4  * Copyright 2008 Robert Shearman
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 #include "widltypes.h"
22 #include <assert.h>
23
24 #ifndef WIDL_TYPE_TREE_H
25 #define WIDL_TYPE_TREE_H
26
27 type_t *type_new_function(var_list_t *args);
28 type_t *type_new_pointer(unsigned char pointer_default, type_t *ref, attr_list_t *attrs);
29 type_t *type_new_alias(type_t *t, const char *name);
30 type_t *type_new_module(char *name);
31 type_t *type_new_array(const char *name, type_t *element, int declptr,
32                        unsigned int dim, expr_t *size_is, expr_t *length_is,
33                        unsigned char ptr_default_fc);
34 type_t *type_new_basic(enum type_basic_type basic_type);
35 type_t *type_new_int(enum type_basic_type basic_type, int sign);
36 type_t *type_new_void(void);
37 type_t *type_new_coclass(char *name);
38 type_t *type_new_enum(const char *name, int defined, var_list_t *enums);
39 type_t *type_new_struct(char *name, int defined, var_list_t *fields);
40 type_t *type_new_nonencapsulated_union(const char *name, int defined, var_list_t *fields);
41 type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases);
42 void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts);
43 void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods);
44 void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface);
45 void type_module_define(type_t *module, statement_list_t *stmts);
46 type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces);
47 int type_is_equal(const type_t *type1, const type_t *type2);
48
49 /* FIXME: shouldn't need to export this */
50 type_t *duptype(type_t *t, int dupname);
51
52 /* un-alias the type until finding the non-alias type */
53 static inline type_t *type_get_real_type(const type_t *type)
54 {
55     if (type->is_alias)
56         return type_get_real_type(type->orig);
57     else
58         return (type_t *)type;
59 }
60
61 static inline enum type_type type_get_type(const type_t *type)
62 {
63     return type_get_type_detect_alias(type_get_real_type(type));
64 }
65
66 static inline enum type_basic_type type_basic_get_type(const type_t *type)
67 {
68     type = type_get_real_type(type);
69     assert(type_get_type(type) == TYPE_BASIC);
70     return type->details.basic.type;
71 }
72
73 static inline int type_basic_get_sign(const type_t *type)
74 {
75     type = type_get_real_type(type);
76     assert(type_get_type(type) == TYPE_BASIC);
77     return type->details.basic.sign;
78 }
79
80 static inline var_list_t *type_struct_get_fields(const type_t *type)
81 {
82     type = type_get_real_type(type);
83     assert(type_get_type(type) == TYPE_STRUCT);
84     return type->details.structure->fields;
85 }
86
87 static inline var_list_t *type_function_get_args(const type_t *type)
88 {
89     type = type_get_real_type(type);
90     assert(type_get_type(type) == TYPE_FUNCTION);
91     return type->details.function->args;
92 }
93
94 static inline type_t *type_function_get_rettype(const type_t *type)
95 {
96     type = type_get_real_type(type);
97     assert(type_get_type(type) == TYPE_FUNCTION);
98     return type->details.function->rettype;
99 }
100
101 static inline var_list_t *type_enum_get_values(const type_t *type)
102 {
103     type = type_get_real_type(type);
104     assert(type_get_type(type) == TYPE_ENUM);
105     return type->details.enumeration->enums;
106 }
107
108 static inline var_t *type_union_get_switch_value(const type_t *type)
109 {
110     type = type_get_real_type(type);
111     assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
112     return LIST_ENTRY(list_head(type->details.structure->fields), var_t, entry);
113 }
114
115 static inline var_list_t *type_encapsulated_union_get_fields(const type_t *type)
116 {
117     type = type_get_real_type(type);
118     assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
119     return type->details.structure->fields;
120 }
121
122 static inline var_list_t *type_union_get_cases(const type_t *type)
123 {
124     enum type_type type_type;
125
126     type = type_get_real_type(type);
127     type_type = type_get_type(type);
128
129     assert(type_type == TYPE_UNION || type_type == TYPE_ENCAPSULATED_UNION);
130     if (type_type == TYPE_ENCAPSULATED_UNION)
131     {
132         const var_t *uv = LIST_ENTRY(list_tail(type->details.structure->fields), const var_t, entry);
133         return uv->type->details.structure->fields;
134     }
135     else
136         return type->details.structure->fields;
137 }
138
139 static inline statement_list_t *type_iface_get_stmts(const type_t *type)
140 {
141     type = type_get_real_type(type);
142     assert(type_get_type(type) == TYPE_INTERFACE);
143     return type->details.iface->stmts;
144 }
145
146 static inline type_t *type_iface_get_inherit(const type_t *type)
147 {
148     type = type_get_real_type(type);
149     assert(type_get_type(type) == TYPE_INTERFACE);
150     return type->details.iface->inherit;
151 }
152
153 static inline var_list_t *type_dispiface_get_props(const type_t *type)
154 {
155     type = type_get_real_type(type);
156     assert(type_get_type(type) == TYPE_INTERFACE);
157     return type->details.iface->disp_props;
158 }
159
160 static inline var_list_t *type_dispiface_get_methods(const type_t *type)
161 {
162     type = type_get_real_type(type);
163     assert(type_get_type(type) == TYPE_INTERFACE);
164     return type->details.iface->disp_methods;
165 }
166
167 static inline int type_is_defined(const type_t *type)
168 {
169     return type->defined;
170 }
171
172 static inline int type_is_complete(const type_t *type)
173 {
174     switch (type_get_type_detect_alias(type))
175     {
176     case TYPE_FUNCTION:
177         return (type->details.function != NULL);
178     case TYPE_INTERFACE:
179         return (type->details.iface != NULL);
180     case TYPE_ENUM:
181         return (type->details.enumeration != NULL);
182     case TYPE_UNION:
183     case TYPE_ENCAPSULATED_UNION:
184     case TYPE_STRUCT:
185         return (type->details.structure != NULL);
186     case TYPE_VOID:
187     case TYPE_BASIC:
188     case TYPE_ALIAS:
189     case TYPE_MODULE:
190     case TYPE_COCLASS:
191     case TYPE_POINTER:
192     case TYPE_ARRAY:
193         return TRUE;
194     }
195     return FALSE;
196 }
197
198 static inline int type_array_has_conformance(const type_t *type)
199 {
200     type = type_get_real_type(type);
201     assert(type_get_type(type) == TYPE_ARRAY);
202     return (type->details.array.size_is != NULL);
203 }
204
205 static inline int type_array_has_variance(const type_t *type)
206 {
207     type = type_get_real_type(type);
208     assert(type_get_type(type) == TYPE_ARRAY);
209     return (type->details.array.length_is != NULL);
210 }
211
212 static inline unsigned int type_array_get_dim(const type_t *type)
213 {
214     type = type_get_real_type(type);
215     assert(type_get_type(type) == TYPE_ARRAY);
216     return type->details.array.dim;
217 }
218
219 static inline expr_t *type_array_get_conformance(const type_t *type)
220 {
221     type = type_get_real_type(type);
222     assert(type_get_type(type) == TYPE_ARRAY);
223     return type->details.array.size_is;
224 }
225
226 static inline expr_t *type_array_get_variance(const type_t *type)
227 {
228     type = type_get_real_type(type);
229     assert(type_get_type(type) == TYPE_ARRAY);
230     return type->details.array.length_is;
231 }
232
233 static inline type_t *type_array_get_element(const type_t *type)
234 {
235     type = type_get_real_type(type);
236     assert(type_get_type(type) == TYPE_ARRAY);
237     return type->details.array.elem;
238 }
239
240 static inline int type_array_is_decl_as_ptr(const type_t *type)
241 {
242     type = type_get_real_type(type);
243     assert(type_get_type(type) == TYPE_ARRAY);
244     return type->details.array.declptr;
245 }
246
247 static inline unsigned char type_array_get_ptr_default_fc(const type_t *type)
248 {
249     type = type_get_real_type(type);
250     assert(type_get_type(type) == TYPE_ARRAY);
251     return type->details.array.ptr_def_fc;
252 }
253
254 static inline int type_is_alias(const type_t *type)
255 {
256     return type->is_alias;
257 }
258
259 static inline type_t *type_alias_get_aliasee(const type_t *type)
260 {
261     assert(type_is_alias(type));
262     return type->orig;
263 }
264
265 static inline ifref_list_t *type_coclass_get_ifaces(const type_t *type)
266 {
267     type = type_get_real_type(type);
268     assert(type_get_type(type) == TYPE_COCLASS);
269     return type->details.coclass.ifaces;
270 }
271
272 static inline type_t *type_pointer_get_ref(const type_t *type)
273 {
274     type = type_get_real_type(type);
275     assert(type_get_type(type) == TYPE_POINTER);
276     return type->details.pointer.ref;
277 }
278
279 static inline unsigned char type_pointer_get_default_fc(const type_t *type)
280 {
281     type = type_get_real_type(type);
282     assert(type_get_type(type) == TYPE_POINTER);
283     return type->details.pointer.def_fc;
284 }
285
286 #endif /* WIDL_TYPE_TREE_H */