push 8724397e7ede0f147b6e05994a72142d44d4fecc
[wine/hacks.git] / tools / widl / typetree.h
bloba6bc982e288caafe5297eb0cf369e20ce427aeb8
1 /*
2 * IDL Type Tree
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"
22 #include <assert.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(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 declarray,
32 unsigned int dim, expr_t *size_is, expr_t *length_is);
33 void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts);
34 void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods);
35 void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface);
36 void type_module_define(type_t *module, statement_list_t *stmts);
37 type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces);
38 int type_is_equal(const type_t *type1, const type_t *type2);
40 /* FIXME: shouldn't need to export this */
41 type_t *duptype(type_t *t, int dupname);
43 /* un-alias the type until finding the non-alias type */
44 static inline type_t *type_get_real_type(const type_t *type)
46 if (type->is_alias)
47 return type_get_real_type(type->orig);
48 else
49 return (type_t *)type;
52 static inline enum type_type type_get_type(const type_t *type)
54 return type_get_type_detect_alias(type_get_real_type(type));
57 static inline unsigned char type_basic_get_fc(const type_t *type)
59 type = type_get_real_type(type);
60 assert(type_get_type(type) == TYPE_BASIC);
61 return type->type;
64 static inline var_list_t *type_struct_get_fields(const type_t *type)
66 type = type_get_real_type(type);
67 assert(type_get_type(type) == TYPE_STRUCT);
68 return type->details.structure->fields;
71 static inline var_list_t *type_function_get_args(const type_t *type)
73 type = type_get_real_type(type);
74 assert(type_get_type(type) == TYPE_FUNCTION);
75 return type->details.function->args;
78 static inline type_t *type_function_get_rettype(const type_t *type)
80 type = type_get_real_type(type);
81 assert(type_get_type(type) == TYPE_FUNCTION);
82 return type->ref;
85 static inline var_list_t *type_enum_get_values(const type_t *type)
87 type = type_get_real_type(type);
88 assert(type_get_type(type) == TYPE_ENUM);
89 return type->details.enumeration->enums;
92 static inline var_t *type_union_get_switch_value(const type_t *type)
94 type = type_get_real_type(type);
95 assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
96 return LIST_ENTRY(list_head(type->details.structure->fields), var_t, entry);
99 static inline var_list_t *type_encapsulated_union_get_fields(const type_t *type)
101 type = type_get_real_type(type);
102 assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
103 return type->details.structure->fields;
106 static inline var_list_t *type_union_get_cases(const type_t *type)
108 enum type_type type_type;
110 type = type_get_real_type(type);
111 type_type = type_get_type(type);
113 assert(type_type == TYPE_UNION || type_type == TYPE_ENCAPSULATED_UNION);
114 if (type_type == TYPE_ENCAPSULATED_UNION)
116 const var_t *uv = LIST_ENTRY(list_tail(type->details.structure->fields), const var_t, entry);
117 return uv->type->details.structure->fields;
119 else
120 return type->details.structure->fields;
123 static inline statement_list_t *type_iface_get_stmts(const type_t *type)
125 type = type_get_real_type(type);
126 assert(type_get_type(type) == TYPE_INTERFACE);
127 return type->details.iface->stmts;
130 static inline type_t *type_iface_get_inherit(const type_t *type)
132 type = type_get_real_type(type);
133 assert(type_get_type(type) == TYPE_INTERFACE);
134 return type->ref;
137 static inline var_list_t *type_dispiface_get_props(const type_t *type)
139 type = type_get_real_type(type);
140 assert(type_get_type(type) == TYPE_INTERFACE);
141 return type->details.iface->disp_props;
144 static inline var_list_t *type_dispiface_get_methods(const type_t *type)
146 type = type_get_real_type(type);
147 assert(type_get_type(type) == TYPE_INTERFACE);
148 return type->details.iface->disp_methods;
151 static inline int type_is_defined(const type_t *type)
153 return type->defined;
156 static inline int type_is_complete(const type_t *type)
158 switch (type_get_type_detect_alias(type))
160 case TYPE_FUNCTION:
161 return (type->details.function != NULL);
162 case TYPE_INTERFACE:
163 return (type->details.iface != NULL);
164 case TYPE_ENUM:
165 return (type->details.enumeration != NULL);
166 case TYPE_UNION:
167 case TYPE_ENCAPSULATED_UNION:
168 case TYPE_STRUCT:
169 return (type->details.structure != NULL);
170 case TYPE_VOID:
171 case TYPE_BASIC:
172 case TYPE_ALIAS:
173 case TYPE_MODULE:
174 case TYPE_COCLASS:
175 case TYPE_POINTER:
176 case TYPE_ARRAY:
177 return TRUE;
179 return FALSE;
182 static inline int type_array_has_conformance(const type_t *type)
184 type = type_get_real_type(type);
185 assert(type_get_type(type) == TYPE_ARRAY);
186 return (type->details.array.size_is != NULL);
189 static inline int type_array_has_variance(const type_t *type)
191 type = type_get_real_type(type);
192 assert(type_get_type(type) == TYPE_ARRAY);
193 return (type->details.array.length_is != NULL);
196 static inline unsigned int type_array_get_dim(const type_t *type)
198 type = type_get_real_type(type);
199 assert(type_get_type(type) == TYPE_ARRAY);
200 return type->details.array.dim;
203 static inline expr_t *type_array_get_conformance(const type_t *type)
205 type = type_get_real_type(type);
206 assert(type_get_type(type) == TYPE_ARRAY);
207 return type->details.array.size_is;
210 static inline expr_t *type_array_get_variance(const type_t *type)
212 type = type_get_real_type(type);
213 assert(type_get_type(type) == TYPE_ARRAY);
214 return type->details.array.length_is;
217 static inline type_t *type_array_get_element(const type_t *type)
219 type = type_get_real_type(type);
220 assert(type_get_type(type) == TYPE_ARRAY);
221 return type->ref;
224 static inline int type_is_alias(const type_t *type)
226 return type->is_alias;
229 static inline type_t *type_alias_get_aliasee(const type_t *type)
231 assert(type_is_alias(type));
232 return type->orig;
235 static inline ifref_list_t *type_coclass_get_ifaces(const type_t *type)
237 type = type_get_real_type(type);
238 assert(type_get_type(type) == TYPE_COCLASS);
239 return type->details.coclass.ifaces;
242 static inline type_t *type_pointer_get_ref(const type_t *type)
244 type = type_get_real_type(type);
245 assert(type_get_type(type) == TYPE_POINTER);
246 return type->ref;
249 #endif /* WIDL_TYPE_TREE_H */