widl: Move the pointer referent, array element, function return type and interface...
[wine/multimedia.git] / tools / widl / typetree.h
blob5e1c481cb7e71b3c545e5c8a040775d43346af0f
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(const 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 type_t *type_new_basic(enum type_basic_type basic_type);
34 type_t *type_new_int(enum type_basic_type basic_type, int sign);
35 type_t *type_new_void(void);
36 type_t *type_new_coclass(const char *name);
37 void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts);
38 void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods);
39 void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface);
40 void type_module_define(type_t *module, statement_list_t *stmts);
41 type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces);
42 int type_is_equal(const type_t *type1, const type_t *type2);
44 /* FIXME: shouldn't need to export this */
45 type_t *duptype(type_t *t, int dupname);
47 /* un-alias the type until finding the non-alias type */
48 static inline type_t *type_get_real_type(const type_t *type)
50 if (type->is_alias)
51 return type_get_real_type(type->orig);
52 else
53 return (type_t *)type;
56 static inline enum type_type type_get_type(const type_t *type)
58 return type_get_type_detect_alias(type_get_real_type(type));
61 static inline unsigned char type_basic_get_fc(const type_t *type)
63 int sign;
64 type = type_get_real_type(type);
65 assert(type_get_type(type) == TYPE_BASIC);
66 sign = type->details.basic.sign;
67 switch (type->details.basic.type)
69 case TYPE_BASIC_INT8: return (sign <= 0 ? RPC_FC_SMALL : RPC_FC_USMALL);
70 case TYPE_BASIC_INT16: return (sign <= 0 ? RPC_FC_SHORT : RPC_FC_USHORT);
71 case TYPE_BASIC_INT32: return (sign <= 0 ? RPC_FC_LONG : RPC_FC_ULONG);
72 case TYPE_BASIC_INT64: return RPC_FC_HYPER;
73 case TYPE_BASIC_INT: return (sign <= 0 ? RPC_FC_LONG : RPC_FC_ULONG);
74 case TYPE_BASIC_BYTE: return RPC_FC_BYTE;
75 case TYPE_BASIC_CHAR: return RPC_FC_CHAR;
76 case TYPE_BASIC_WCHAR: return RPC_FC_WCHAR;
77 case TYPE_BASIC_HYPER: return RPC_FC_HYPER;
78 case TYPE_BASIC_FLOAT: return RPC_FC_FLOAT;
79 case TYPE_BASIC_DOUBLE: return RPC_FC_DOUBLE;
80 case TYPE_BASIC_ERROR_STATUS_T: return RPC_FC_ERROR_STATUS_T;
81 case TYPE_BASIC_HANDLE: return RPC_FC_BIND_PRIMITIVE;
82 default: return 0;
86 static inline enum type_basic_type type_basic_get_type(const type_t *type)
88 type = type_get_real_type(type);
89 assert(type_get_type(type) == TYPE_BASIC);
90 return type->details.basic.type;
93 static inline int type_basic_get_sign(const type_t *type)
95 type = type_get_real_type(type);
96 assert(type_get_type(type) == TYPE_BASIC);
97 return type->details.basic.sign;
100 static inline var_list_t *type_struct_get_fields(const type_t *type)
102 type = type_get_real_type(type);
103 assert(type_get_type(type) == TYPE_STRUCT);
104 return type->details.structure->fields;
107 static inline var_list_t *type_function_get_args(const type_t *type)
109 type = type_get_real_type(type);
110 assert(type_get_type(type) == TYPE_FUNCTION);
111 return type->details.function->args;
114 static inline type_t *type_function_get_rettype(const type_t *type)
116 type = type_get_real_type(type);
117 assert(type_get_type(type) == TYPE_FUNCTION);
118 return type->details.function->rettype;
121 static inline var_list_t *type_enum_get_values(const type_t *type)
123 type = type_get_real_type(type);
124 assert(type_get_type(type) == TYPE_ENUM);
125 return type->details.enumeration->enums;
128 static inline var_t *type_union_get_switch_value(const type_t *type)
130 type = type_get_real_type(type);
131 assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
132 return LIST_ENTRY(list_head(type->details.structure->fields), var_t, entry);
135 static inline var_list_t *type_encapsulated_union_get_fields(const type_t *type)
137 type = type_get_real_type(type);
138 assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
139 return type->details.structure->fields;
142 static inline var_list_t *type_union_get_cases(const type_t *type)
144 enum type_type type_type;
146 type = type_get_real_type(type);
147 type_type = type_get_type(type);
149 assert(type_type == TYPE_UNION || type_type == TYPE_ENCAPSULATED_UNION);
150 if (type_type == TYPE_ENCAPSULATED_UNION)
152 const var_t *uv = LIST_ENTRY(list_tail(type->details.structure->fields), const var_t, entry);
153 return uv->type->details.structure->fields;
155 else
156 return type->details.structure->fields;
159 static inline statement_list_t *type_iface_get_stmts(const type_t *type)
161 type = type_get_real_type(type);
162 assert(type_get_type(type) == TYPE_INTERFACE);
163 return type->details.iface->stmts;
166 static inline type_t *type_iface_get_inherit(const type_t *type)
168 type = type_get_real_type(type);
169 assert(type_get_type(type) == TYPE_INTERFACE);
170 return type->details.iface->inherit;
173 static inline var_list_t *type_dispiface_get_props(const type_t *type)
175 type = type_get_real_type(type);
176 assert(type_get_type(type) == TYPE_INTERFACE);
177 return type->details.iface->disp_props;
180 static inline var_list_t *type_dispiface_get_methods(const type_t *type)
182 type = type_get_real_type(type);
183 assert(type_get_type(type) == TYPE_INTERFACE);
184 return type->details.iface->disp_methods;
187 static inline int type_is_defined(const type_t *type)
189 return type->defined;
192 static inline int type_is_complete(const type_t *type)
194 switch (type_get_type_detect_alias(type))
196 case TYPE_FUNCTION:
197 return (type->details.function != NULL);
198 case TYPE_INTERFACE:
199 return (type->details.iface != NULL);
200 case TYPE_ENUM:
201 return (type->details.enumeration != NULL);
202 case TYPE_UNION:
203 case TYPE_ENCAPSULATED_UNION:
204 case TYPE_STRUCT:
205 return (type->details.structure != NULL);
206 case TYPE_VOID:
207 case TYPE_BASIC:
208 case TYPE_ALIAS:
209 case TYPE_MODULE:
210 case TYPE_COCLASS:
211 case TYPE_POINTER:
212 case TYPE_ARRAY:
213 return TRUE;
215 return FALSE;
218 static inline int type_array_has_conformance(const type_t *type)
220 type = type_get_real_type(type);
221 assert(type_get_type(type) == TYPE_ARRAY);
222 return (type->details.array.size_is != NULL);
225 static inline int type_array_has_variance(const type_t *type)
227 type = type_get_real_type(type);
228 assert(type_get_type(type) == TYPE_ARRAY);
229 return (type->details.array.length_is != NULL);
232 static inline unsigned int type_array_get_dim(const type_t *type)
234 type = type_get_real_type(type);
235 assert(type_get_type(type) == TYPE_ARRAY);
236 return type->details.array.dim;
239 static inline expr_t *type_array_get_conformance(const type_t *type)
241 type = type_get_real_type(type);
242 assert(type_get_type(type) == TYPE_ARRAY);
243 return type->details.array.size_is;
246 static inline expr_t *type_array_get_variance(const type_t *type)
248 type = type_get_real_type(type);
249 assert(type_get_type(type) == TYPE_ARRAY);
250 return type->details.array.length_is;
253 static inline type_t *type_array_get_element(const type_t *type)
255 type = type_get_real_type(type);
256 assert(type_get_type(type) == TYPE_ARRAY);
257 return type->details.array.elem;
260 static inline int type_array_is_decl_as_ptr(const type_t *type)
262 type = type_get_real_type(type);
263 assert(type_get_type(type) == TYPE_ARRAY);
264 return type->details.array.declptr;
267 static inline int type_is_alias(const type_t *type)
269 return type->is_alias;
272 static inline type_t *type_alias_get_aliasee(const type_t *type)
274 assert(type_is_alias(type));
275 return type->orig;
278 static inline ifref_list_t *type_coclass_get_ifaces(const type_t *type)
280 type = type_get_real_type(type);
281 assert(type_get_type(type) == TYPE_COCLASS);
282 return type->details.coclass.ifaces;
285 static inline type_t *type_pointer_get_ref(const type_t *type)
287 type = type_get_real_type(type);
288 assert(type_get_type(type) == TYPE_POINTER);
289 return type->details.pointer.ref;
292 #endif /* WIDL_TYPE_TREE_H */