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
32 attr_list_t
*check_apicontract_attrs(const char *name
, attr_list_t
*attrs
);
33 attr_list_t
*check_coclass_attrs(const char *name
, attr_list_t
*attrs
);
34 attr_list_t
*check_dispiface_attrs(const char *name
, attr_list_t
*attrs
);
35 attr_list_t
*check_interface_attrs(const char *name
, attr_list_t
*attrs
);
36 attr_list_t
*check_module_attrs(const char *name
, attr_list_t
*attrs
);
37 attr_list_t
*check_runtimeclass_attrs(const char *name
, attr_list_t
*attrs
);
39 type_t
*find_parameterized_type(type_t
*type
, typeref_list_t
*params
);
41 type_t
*type_new_function(var_list_t
*args
);
42 type_t
*type_new_pointer(type_t
*ref
);
43 type_t
*type_new_alias(const decl_spec_t
*t
, const char *name
);
44 type_t
*type_module_declare(char *name
);
45 type_t
*type_new_array(const char *name
, const decl_spec_t
*element
, int declptr
,
46 unsigned int dim
, expr_t
*size_is
, expr_t
*length_is
);
47 type_t
*type_new_basic(enum type_basic_type basic_type
);
48 type_t
*type_new_int(enum type_basic_type basic_type
, int sign
);
49 type_t
*type_new_void(void);
50 type_t
*type_coclass_declare(char *name
);
51 type_t
*type_new_enum(const char *name
, struct namespace *namespace, int defined
, var_list_t
*enums
);
52 type_t
*type_new_struct(char *name
, struct namespace *namespace, int defined
, var_list_t
*fields
);
53 type_t
*type_new_nonencapsulated_union(const char *name
, int defined
, var_list_t
*fields
);
54 type_t
*type_new_encapsulated_union(char *name
, var_t
*switch_field
, var_t
*union_field
, var_list_t
*cases
);
55 type_t
*type_new_bitfield(type_t
*field_type
, const expr_t
*bits
);
56 type_t
*type_runtimeclass_declare(char *name
, struct namespace *namespace);
57 type_t
*type_interface_declare(char *name
, struct namespace *namespace);
58 type_t
*type_interface_define(type_t
*iface
, attr_list_t
*attrs
, type_t
*inherit
, statement_list_t
*stmts
, typeref_list_t
*requires
);
59 type_t
*type_dispinterface_declare(char *name
);
60 type_t
*type_dispinterface_define(type_t
*iface
, attr_list_t
*attrs
, var_list_t
*props
, var_list_t
*methods
);
61 type_t
*type_dispinterface_define_from_iface(type_t
*dispiface
, attr_list_t
*attrs
, type_t
*iface
);
62 type_t
*type_module_define(type_t
* module
, attr_list_t
*attrs
, statement_list_t
*stmts
);
63 type_t
*type_coclass_define(type_t
*coclass
, attr_list_t
*attrs
, typeref_list_t
*ifaces
);
64 type_t
*type_runtimeclass_define(type_t
*runtimeclass
, attr_list_t
*attrs
, typeref_list_t
*ifaces
);
65 type_t
*type_apicontract_declare(char *name
, struct namespace *namespace);
66 type_t
*type_apicontract_define(type_t
*apicontract
, attr_list_t
*attrs
);
67 type_t
*type_delegate_declare(char *name
, struct namespace *namespace);
68 type_t
*type_delegate_define(type_t
*delegate
, attr_list_t
*attrs
, statement_list_t
*stmts
);
69 type_t
*type_parameterized_interface_declare(char *name
, struct namespace *namespace, typeref_list_t
*params
);
70 type_t
*type_parameterized_interface_define(type_t
*type
, attr_list_t
*attrs
, type_t
*inherit
, statement_list_t
*stmts
, typeref_list_t
*requires
);
71 type_t
*type_parameterized_type_specialize_partial(type_t
*type
, typeref_list_t
*params
);
72 type_t
*type_parameterized_type_specialize_declare(type_t
*type
, typeref_list_t
*params
);
73 type_t
*type_parameterized_type_specialize_define(type_t
*type
);
74 int type_is_equal(const type_t
*type1
, const type_t
*type2
);
75 const char *type_get_name(const type_t
*type
, enum name_type name_type
);
77 extern int is_attr(const attr_list_t
*list
, enum attr_type t
);
79 typeref_t
*make_typeref(type_t
*type
);
80 typeref_list_t
*append_typeref(typeref_list_t
*list
, typeref_t
*ref
);
82 /* FIXME: shouldn't need to export this */
83 type_t
*duptype(type_t
*t
, int dupname
);
85 /* un-alias the type until finding the non-alias type */
86 static inline type_t
*type_get_real_type(const type_t
*type
)
88 if (type
->type_type
== TYPE_ALIAS
)
89 return type_get_real_type(type
->details
.alias
.aliasee
.type
);
91 return (type_t
*)type
;
94 static inline enum type_type
type_get_type(const type_t
*type
)
96 return type_get_type_detect_alias(type_get_real_type(type
));
99 static inline enum type_basic_type
type_basic_get_type(const type_t
*type
)
101 type
= type_get_real_type(type
);
102 assert(type_get_type(type
) == TYPE_BASIC
);
103 return type
->details
.basic
.type
;
106 static inline int type_basic_get_sign(const type_t
*type
)
108 type
= type_get_real_type(type
);
109 assert(type_get_type(type
) == TYPE_BASIC
);
110 return type
->details
.basic
.sign
;
113 static inline var_list_t
*type_struct_get_fields(const type_t
*type
)
115 type
= type_get_real_type(type
);
116 assert(type_get_type(type
) == TYPE_STRUCT
);
117 return type
->details
.structure
->fields
;
120 static inline var_list_t
*type_function_get_args(const type_t
*type
)
122 type
= type_get_real_type(type
);
123 assert(type_get_type(type
) == TYPE_FUNCTION
);
124 return type
->details
.function
->args
;
127 static inline var_t
*type_function_get_retval(const type_t
*type
)
129 type
= type_get_real_type(type
);
130 assert(type_get_type(type
) == TYPE_FUNCTION
);
131 return type
->details
.function
->retval
;
134 static inline const decl_spec_t
*type_function_get_ret(const type_t
*type
)
136 return &type_function_get_retval(type
)->declspec
;
139 static inline type_t
*type_function_get_rettype(const type_t
*type
)
141 return type_function_get_retval(type
)->declspec
.type
;
144 static inline var_list_t
*type_enum_get_values(const type_t
*type
)
146 type
= type_get_real_type(type
);
147 assert(type_get_type(type
) == TYPE_ENUM
);
148 return type
->details
.enumeration
->enums
;
151 static inline var_t
*type_union_get_switch_value(const type_t
*type
)
153 type
= type_get_real_type(type
);
154 assert(type_get_type(type
) == TYPE_ENCAPSULATED_UNION
);
155 return LIST_ENTRY(list_head(type
->details
.structure
->fields
), var_t
, entry
);
158 static inline var_list_t
*type_encapsulated_union_get_fields(const type_t
*type
)
160 type
= type_get_real_type(type
);
161 assert(type_get_type(type
) == TYPE_ENCAPSULATED_UNION
);
162 return type
->details
.structure
->fields
;
165 static inline var_list_t
*type_union_get_cases(const type_t
*type
)
167 enum type_type type_type
;
169 type
= type_get_real_type(type
);
170 type_type
= type_get_type(type
);
172 assert(type_type
== TYPE_UNION
|| type_type
== TYPE_ENCAPSULATED_UNION
);
173 if (type_type
== TYPE_ENCAPSULATED_UNION
)
175 const var_t
*uv
= LIST_ENTRY(list_tail(type
->details
.structure
->fields
), const var_t
, entry
);
176 return uv
->declspec
.type
->details
.structure
->fields
;
179 return type
->details
.structure
->fields
;
182 static inline statement_list_t
*type_iface_get_stmts(const type_t
*type
)
184 type
= type_get_real_type(type
);
185 assert(type_get_type(type
) == TYPE_INTERFACE
);
186 return type
->details
.iface
->stmts
;
189 static inline type_t
*type_iface_get_inherit(const type_t
*type
)
191 type
= type_get_real_type(type
);
192 assert(type_get_type(type
) == TYPE_INTERFACE
);
193 return type
->details
.iface
->inherit
;
196 static inline typeref_list_t
*type_iface_get_requires(const type_t
*type
)
198 type
= type_get_real_type(type
);
199 assert(type_get_type(type
) == TYPE_INTERFACE
);
200 return type
->details
.iface
->requires
;
203 static inline type_t
*type_iface_get_async_iface(const type_t
*type
)
205 type
= type_get_real_type(type
);
206 assert(type_get_type(type
) == TYPE_INTERFACE
);
207 return type
->details
.iface
->async_iface
;
210 static inline var_list_t
*type_dispiface_get_props(const type_t
*type
)
212 type
= type_get_real_type(type
);
213 assert(type_get_type(type
) == TYPE_INTERFACE
);
214 return type
->details
.iface
->disp_props
;
217 static inline var_list_t
*type_dispiface_get_methods(const type_t
*type
)
219 type
= type_get_real_type(type
);
220 assert(type_get_type(type
) == TYPE_INTERFACE
);
221 return type
->details
.iface
->disp_methods
;
224 static inline type_t
*type_dispiface_get_inherit(const type_t
*type
)
226 type
= type_get_real_type(type
);
227 assert(type_get_type(type
) == TYPE_INTERFACE
);
228 return type
->details
.iface
->disp_inherit
;
231 static inline int type_is_defined(const type_t
*type
)
233 return type
->defined
;
236 static inline int type_is_complete(const type_t
*type
)
238 switch (type_get_type_detect_alias(type
))
241 return (type
->details
.function
!= NULL
);
243 return (type
->details
.iface
!= NULL
);
245 return (type
->details
.enumeration
!= NULL
);
247 case TYPE_ENCAPSULATED_UNION
:
249 return (type
->details
.structure
!= NULL
);
258 case TYPE_RUNTIMECLASS
:
261 case TYPE_APICONTRACT
:
262 case TYPE_PARAMETERIZED_TYPE
:
270 static inline int type_array_has_conformance(const type_t
*type
)
272 type
= type_get_real_type(type
);
273 assert(type_get_type(type
) == TYPE_ARRAY
);
274 return (type
->details
.array
.size_is
!= NULL
);
277 static inline int type_array_has_variance(const type_t
*type
)
279 type
= type_get_real_type(type
);
280 assert(type_get_type(type
) == TYPE_ARRAY
);
281 return (type
->details
.array
.length_is
!= NULL
);
284 static inline unsigned int type_array_get_dim(const type_t
*type
)
286 type
= type_get_real_type(type
);
287 assert(type_get_type(type
) == TYPE_ARRAY
);
288 return type
->details
.array
.dim
;
291 static inline expr_t
*type_array_get_conformance(const type_t
*type
)
293 type
= type_get_real_type(type
);
294 assert(type_get_type(type
) == TYPE_ARRAY
);
295 return type
->details
.array
.size_is
;
298 static inline expr_t
*type_array_get_variance(const type_t
*type
)
300 type
= type_get_real_type(type
);
301 assert(type_get_type(type
) == TYPE_ARRAY
);
302 return type
->details
.array
.length_is
;
305 static inline unsigned short type_array_get_ptr_tfsoff(const type_t
*type
)
307 type
= type_get_real_type(type
);
308 assert(type_get_type(type
) == TYPE_ARRAY
);
309 return type
->details
.array
.ptr_tfsoff
;
312 static inline void type_array_set_ptr_tfsoff(type_t
*type
, unsigned short ptr_tfsoff
)
314 type
= type_get_real_type(type
);
315 assert(type_get_type(type
) == TYPE_ARRAY
);
316 type
->details
.array
.ptr_tfsoff
= ptr_tfsoff
;
319 static inline const decl_spec_t
*type_array_get_element(const type_t
*type
)
321 type
= type_get_real_type(type
);
322 assert(type_get_type(type
) == TYPE_ARRAY
);
323 return &type
->details
.array
.elem
;
326 static inline type_t
*type_array_get_element_type(const type_t
*type
)
328 return type_array_get_element(type
)->type
;
331 static inline int type_array_is_decl_as_ptr(const type_t
*type
)
333 type
= type_get_real_type(type
);
334 assert(type_get_type(type
) == TYPE_ARRAY
);
335 return type
->details
.array
.declptr
;
338 static inline int type_is_alias(const type_t
*type
)
340 return type
->type_type
== TYPE_ALIAS
;
343 static inline const decl_spec_t
*type_alias_get_aliasee(const type_t
*type
)
345 assert(type_is_alias(type
));
346 return &type
->details
.alias
.aliasee
;
349 static inline type_t
*type_alias_get_aliasee_type(const type_t
*type
)
351 assert(type_is_alias(type
));
352 return type
->details
.alias
.aliasee
.type
;
355 static inline typeref_list_t
*type_coclass_get_ifaces(const type_t
*type
)
357 type
= type_get_real_type(type
);
358 assert(type_get_type(type
) == TYPE_COCLASS
);
359 return type
->details
.coclass
.ifaces
;
362 static inline typeref_list_t
*type_runtimeclass_get_ifaces(const type_t
*type
)
364 type
= type_get_real_type(type
);
365 assert(type_get_type(type
) == TYPE_RUNTIMECLASS
);
366 return type
->details
.runtimeclass
.ifaces
;
369 static inline type_t
*type_runtimeclass_get_default_iface(const type_t
*type
)
371 typeref_list_t
*ifaces
= type_runtimeclass_get_ifaces(type
);
374 if (!ifaces
) return NULL
;
375 LIST_FOR_EACH_ENTRY(ref
, ifaces
, typeref_t
, entry
)
376 if (is_attr(ref
->attrs
, ATTR_DEFAULT
))
382 static inline type_t
*type_delegate_get_iface(const type_t
*type
)
384 type
= type_get_real_type(type
);
385 assert(type_get_type(type
) == TYPE_DELEGATE
);
386 return type
->details
.delegate
.iface
;
389 static inline const decl_spec_t
*type_pointer_get_ref(const type_t
*type
)
391 type
= type_get_real_type(type
);
392 assert(type_get_type(type
) == TYPE_POINTER
);
393 return &type
->details
.pointer
.ref
;
396 static inline type_t
*type_pointer_get_ref_type(const type_t
*type
)
398 return type_pointer_get_ref(type
)->type
;
401 static inline type_t
*type_bitfield_get_field(const type_t
*type
)
403 type
= type_get_real_type(type
);
404 assert(type_get_type(type
) == TYPE_BITFIELD
);
405 return type
->details
.bitfield
.field
;
408 static inline const expr_t
*type_bitfield_get_bits(const type_t
*type
)
410 type
= type_get_real_type(type
);
411 assert(type_get_type(type
) == TYPE_BITFIELD
);
412 return type
->details
.bitfield
.bits
;
415 #endif /* WIDL_TYPE_TREE_H */