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 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);
39
40 /* FIXME: shouldn't need to export this */
41 type_t *duptype(type_t *t, int dupname);
42
43 /* un-alias the type until finding the non-alias type */
44 static inline type_t *type_get_real_type(const type_t *type)
45 {
46 if (type->is_alias)
47 return type_get_real_type(type->orig);
48 else
49 return (type_t *)type;
50 }
51
52 static inline enum type_type type_get_type(const type_t *type)
53 {
54 return type_get_type_detect_alias(type_get_real_type(type));
55 }
56
57 static inline unsigned char type_basic_get_fc(const type_t *type)
58 {
59 type = type_get_real_type(type);
60 assert(type_get_type(type) == TYPE_BASIC);
61 return type->type;
62 }
63
64 static inline var_list_t *type_struct_get_fields(const type_t *type)
65 {
66 type = type_get_real_type(type);
67 assert(type_get_type(type) == TYPE_STRUCT);
68 return type->details.structure->fields;
69 }
70
71 static inline var_list_t *type_function_get_args(const type_t *type)
72 {
73 type = type_get_real_type(type);
74 assert(type_get_type(type) == TYPE_FUNCTION);
75 return type->details.function->args;
76 }
77
78 static inline type_t *type_function_get_rettype(const type_t *type)
79 {
80 type = type_get_real_type(type);
81 assert(type_get_type(type) == TYPE_FUNCTION);
82 return type->ref;
83 }
84
85 static inline var_list_t *type_enum_get_values(const type_t *type)
86 {
87 type = type_get_real_type(type);
88 assert(type_get_type(type) == TYPE_ENUM);
89 return type->details.enumeration->enums;
90 }
91
92 static inline var_t *type_union_get_switch_value(const type_t *type)
93 {
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);
97 }
98
99 static inline var_list_t *type_encapsulated_union_get_fields(const type_t *type)
100 {
101 type = type_get_real_type(type);
102 assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
103 return type->details.structure->fields;
104 }
105
106 static inline var_list_t *type_union_get_cases(const type_t *type)
107 {
108 enum type_type type_type;
109
110 type = type_get_real_type(type);
111 type_type = type_get_type(type);
112
113 assert(type_type == TYPE_UNION || type_type == TYPE_ENCAPSULATED_UNION);
114 if (type_type == TYPE_ENCAPSULATED_UNION)
115 {
116 const var_t *uv = LIST_ENTRY(list_tail(type->details.structure->fields), const var_t, entry);
117 return uv->type->details.structure->fields;
118 }
119 else
120 return type->details.structure->fields;
121 }
122
123 static inline statement_list_t *type_iface_get_stmts(const type_t *type)
124 {
125 type = type_get_real_type(type);
126 assert(type_get_type(type) == TYPE_INTERFACE);
127 return type->details.iface->stmts;
128 }
129
130 static inline type_t *type_iface_get_inherit(const type_t *type)
131 {
132 type = type_get_real_type(type);
133 assert(type_get_type(type) == TYPE_INTERFACE);
134 return type->ref;
135 }
136
137 static inline var_list_t *type_dispiface_get_props(const type_t *type)
138 {
139 type = type_get_real_type(type);
140 assert(type_get_type(type) == TYPE_INTERFACE);
141 return type->details.iface->disp_props;
142 }
143
144 static inline var_list_t *type_dispiface_get_methods(const type_t *type)
145 {
146 type = type_get_real_type(type);
147 assert(type_get_type(type) == TYPE_INTERFACE);
148 return type->details.iface->disp_methods;
149 }
150
151 static inline int type_is_defined(const type_t *type)
152 {
153 return type->defined;
154 }
155
156 static inline int type_is_complete(const type_t *type)
157 {
158 switch (type_get_type_detect_alias(type))
159 {
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;
178 }
179 return FALSE;
180 }
181
182 static inline int type_array_has_conformance(const type_t *type)
183 {
184 type = type_get_real_type(type);
185 assert(type_get_type(type) == TYPE_ARRAY);
186 return (type->details.array.size_is != NULL);
187 }
188
189 static inline int type_array_has_variance(const type_t *type)
190 {
191 type = type_get_real_type(type);
192 assert(type_get_type(type) == TYPE_ARRAY);
193 return (type->details.array.length_is != NULL);
194 }
195
196 static inline unsigned int type_array_get_dim(const type_t *type)
197 {
198 type = type_get_real_type(type);
199 assert(type_get_type(type) == TYPE_ARRAY);
200 return type->details.array.dim;
201 }
202
203 static inline expr_t *type_array_get_conformance(const type_t *type)
204 {
205 type = type_get_real_type(type);
206 assert(type_get_type(type) == TYPE_ARRAY);
207 return type->details.array.size_is;
208 }
209
210 static inline expr_t *type_array_get_variance(const type_t *type)
211 {
212 type = type_get_real_type(type);
213 assert(type_get_type(type) == TYPE_ARRAY);
214 return type->details.array.length_is;
215 }
216
217 static inline type_t *type_array_get_element(const type_t *type)
218 {
219 type = type_get_real_type(type);
220 assert(type_get_type(type) == TYPE_ARRAY);
221 return type->ref;
222 }
223
224 static inline int type_is_alias(const type_t *type)
225 {
226 return type->is_alias;
227 }
228
229 static inline type_t *type_alias_get_aliasee(const type_t *type)
230 {
231 assert(type_is_alias(type));
232 return type->orig;
233 }
234
235 static inline ifref_list_t *type_coclass_get_ifaces(const type_t *type)
236 {
237 type = type_get_real_type(type);
238 assert(type_get_type(type) == TYPE_COCLASS);
239 return type->details.coclass.ifaces;
240 }
241
242 static inline type_t *type_pointer_get_ref(const type_t *type)
243 {
244 type = type_get_real_type(type);
245 assert(type_get_type(type) == TYPE_POINTER);
246 return type->ref;
247 }
248
249 #endif /* WIDL_TYPE_TREE_H */
250
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.