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