4 * Copyright 2008 Robert Shearman
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.
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.
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
21 #include "widltypes.h"
24 #ifndef WIDL_TYPE_TREE_H
25 #define WIDL_TYPE_TREE_H
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 type_t *type_new_bitfield(type_t *field_type, const expr_t *bits);
43 void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts);
44 void type_dispinterface_define(type_t *iface, var_list_t *props, var_list_t *methods);
45 void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface);
46 void type_module_define(type_t *module, statement_list_t *stmts);
47 type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces);
48 int type_is_equal(const type_t *type1, const type_t *type2);
50 /* FIXME: shouldn't need to export this */
51 type_t *duptype(type_t *t, int dupname);
53 /* un-alias the type until finding the non-alias type */
54 static inline type_t *type_get_real_type(const type_t *type)
57 return type_get_real_type(type->orig);
59 return (type_t *)type;
62 static inline enum type_type type_get_type(const type_t *type)
64 return type_get_type_detect_alias(type_get_real_type(type));
67 static inline enum type_basic_type type_basic_get_type(const type_t *type)
69 type = type_get_real_type(type);
70 assert(type_get_type(type) == TYPE_BASIC);
71 return type->details.basic.type;
74 static inline int type_basic_get_sign(const type_t *type)
76 type = type_get_real_type(type);
77 assert(type_get_type(type) == TYPE_BASIC);
78 return type->details.basic.sign;
81 static inline var_list_t *type_struct_get_fields(const type_t *type)
83 type = type_get_real_type(type);
84 assert(type_get_type(type) == TYPE_STRUCT);
85 return type->details.structure->fields;
88 static inline var_list_t *type_function_get_args(const type_t *type)
90 type = type_get_real_type(type);
91 assert(type_get_type(type) == TYPE_FUNCTION);
92 return type->details.function->args;
95 static inline type_t *type_function_get_rettype(const type_t *type)
97 type = type_get_real_type(type);
98 assert(type_get_type(type) == TYPE_FUNCTION);
99 return type->details.function->rettype;
102 static inline var_list_t *type_enum_get_values(const type_t *type)
104 type = type_get_real_type(type);
105 assert(type_get_type(type) == TYPE_ENUM);
106 return type->details.enumeration->enums;
109 static inline var_t *type_union_get_switch_value(const type_t *type)
111 type = type_get_real_type(type);
112 assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
113 return LIST_ENTRY(list_head(type->details.structure->fields), var_t, entry);
116 static inline var_list_t *type_encapsulated_union_get_fields(const type_t *type)
118 type = type_get_real_type(type);
119 assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
120 return type->details.structure->fields;
123 static inline var_list_t *type_union_get_cases(const type_t *type)
125 enum type_type type_type;
127 type = type_get_real_type(type);
128 type_type = type_get_type(type);
130 assert(type_type == TYPE_UNION || type_type == TYPE_ENCAPSULATED_UNION);
131 if (type_type == TYPE_ENCAPSULATED_UNION)
133 const var_t *uv = LIST_ENTRY(list_tail(type->details.structure->fields), const var_t, entry);
134 return uv->type->details.structure->fields;
137 return type->details.structure->fields;
140 static inline statement_list_t *type_iface_get_stmts(const type_t *type)
142 type = type_get_real_type(type);
143 assert(type_get_type(type) == TYPE_INTERFACE);
144 return type->details.iface->stmts;
147 static inline type_t *type_iface_get_inherit(const type_t *type)
149 type = type_get_real_type(type);
150 assert(type_get_type(type) == TYPE_INTERFACE);
151 return type->details.iface->inherit;
154 static inline var_list_t *type_dispiface_get_props(const type_t *type)
156 type = type_get_real_type(type);
157 assert(type_get_type(type) == TYPE_INTERFACE);
158 return type->details.iface->disp_props;
161 static inline var_list_t *type_dispiface_get_methods(const type_t *type)
163 type = type_get_real_type(type);
164 assert(type_get_type(type) == TYPE_INTERFACE);
165 return type->details.iface->disp_methods;
168 static inline int type_is_defined(const type_t *type)
170 return type->defined;
173 static inline int type_is_complete(const type_t *type)
175 switch (type_get_type_detect_alias(type))
178 return (type->details.function != NULL);
180 return (type->details.iface != NULL);
182 return (type->details.enumeration != NULL);
184 case TYPE_ENCAPSULATED_UNION:
186 return (type->details.structure != NULL);
200 static inline int type_array_has_conformance(const type_t *type)
202 type = type_get_real_type(type);
203 assert(type_get_type(type) == TYPE_ARRAY);
204 return (type->details.array.size_is != NULL);
207 static inline int type_array_has_variance(const type_t *type)
209 type = type_get_real_type(type);
210 assert(type_get_type(type) == TYPE_ARRAY);
211 return (type->details.array.length_is != NULL);
214 static inline unsigned int type_array_get_dim(const type_t *type)
216 type = type_get_real_type(type);
217 assert(type_get_type(type) == TYPE_ARRAY);
218 return type->details.array.dim;
221 static inline expr_t *type_array_get_conformance(const type_t *type)
223 type = type_get_real_type(type);
224 assert(type_get_type(type) == TYPE_ARRAY);
225 return type->details.array.size_is;
228 static inline expr_t *type_array_get_variance(const type_t *type)
230 type = type_get_real_type(type);
231 assert(type_get_type(type) == TYPE_ARRAY);
232 return type->details.array.length_is;
235 static inline type_t *type_array_get_element(const type_t *type)
237 type = type_get_real_type(type);
238 assert(type_get_type(type) == TYPE_ARRAY);
239 return type->details.array.elem;
242 static inline int type_array_is_decl_as_ptr(const type_t *type)
244 type = type_get_real_type(type);
245 assert(type_get_type(type) == TYPE_ARRAY);
246 return type->details.array.declptr;
249 static inline unsigned char type_array_get_ptr_default_fc(const type_t *type)
251 type = type_get_real_type(type);
252 assert(type_get_type(type) == TYPE_ARRAY);
253 return type->details.array.ptr_def_fc;
256 static inline int type_is_alias(const type_t *type)
258 return type->is_alias;
261 static inline type_t *type_alias_get_aliasee(const type_t *type)
263 assert(type_is_alias(type));
267 static inline ifref_list_t *type_coclass_get_ifaces(const type_t *type)
269 type = type_get_real_type(type);
270 assert(type_get_type(type) == TYPE_COCLASS);
271 return type->details.coclass.ifaces;
274 static inline type_t *type_pointer_get_ref(const type_t *type)
276 type = type_get_real_type(type);
277 assert(type_get_type(type) == TYPE_POINTER);
278 return type->details.pointer.ref;
281 static inline unsigned char type_pointer_get_default_fc(const type_t *type)
283 type = type_get_real_type(type);
284 assert(type_get_type(type) == TYPE_POINTER);
285 return type->details.pointer.def_fc;
288 static inline type_t *type_bitfield_get_field(const type_t *type)
290 type = type_get_real_type(type);
291 assert(type_get_type(type) == TYPE_BITFIELD);
292 return type->details.bitfield.field;
295 static inline const expr_t *type_bitfield_get_bits(const type_t *type)
297 type = type_get_real_type(type);
298 assert(type_get_type(type) == TYPE_BITFIELD);
299 return type->details.bitfield.bits;
302 #endif /* WIDL_TYPE_TREE_H */