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(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
);
39 /* FIXME: shouldn't need to export this */
40 type_t
*duptype(type_t
*t
, int dupname
);
42 /* un-alias the type until finding the non-alias type */
43 static inline type_t
*type_get_real_type(const type_t
*type
)
46 return type_get_real_type(type
->orig
);
48 return (type_t
*)type
;
51 static inline enum type_type
type_get_type(const type_t
*type
)
53 return type_get_type_detect_alias(type_get_real_type(type
));
56 static inline unsigned char type_basic_get_fc(const type_t
*type
)
58 type
= type_get_real_type(type
);
59 assert(type_get_type(type
) == TYPE_BASIC
);
63 static inline var_list_t
*type_struct_get_fields(const type_t
*type
)
65 type
= type_get_real_type(type
);
66 assert(type_get_type(type
) == TYPE_STRUCT
);
67 return type
->details
.structure
->fields
;
70 static inline var_list_t
*type_function_get_args(const type_t
*type
)
72 type
= type_get_real_type(type
);
73 assert(type_get_type(type
) == TYPE_FUNCTION
);
74 return type
->details
.function
->args
;
77 static inline type_t
*type_function_get_rettype(const type_t
*type
)
79 type
= type_get_real_type(type
);
80 assert(type_get_type(type
) == TYPE_FUNCTION
);
84 static inline var_list_t
*type_enum_get_values(const type_t
*type
)
86 type
= type_get_real_type(type
);
87 assert(type_get_type(type
) == TYPE_ENUM
);
88 return type
->details
.enumeration
->enums
;
91 static inline var_t
*type_union_get_switch_value(const type_t
*type
)
93 type
= type_get_real_type(type
);
94 assert(type_get_type(type
) == TYPE_ENCAPSULATED_UNION
);
95 return LIST_ENTRY(list_head(type
->details
.structure
->fields
), var_t
, entry
);
98 static inline var_list_t
*type_encapsulated_union_get_fields(const type_t
*type
)
100 type
= type_get_real_type(type
);
101 assert(type_get_type(type
) == TYPE_ENCAPSULATED_UNION
);
102 return type
->details
.structure
->fields
;
105 static inline var_list_t
*type_union_get_cases(const type_t
*type
)
107 enum type_type type_type
;
109 type
= type_get_real_type(type
);
110 type_type
= type_get_type(type
);
112 assert(type_type
== TYPE_UNION
|| type_type
== TYPE_ENCAPSULATED_UNION
);
113 if (type_type
== TYPE_ENCAPSULATED_UNION
)
115 const var_t
*uv
= LIST_ENTRY(list_tail(type
->details
.structure
->fields
), const var_t
, entry
);
116 return uv
->type
->details
.structure
->fields
;
119 return type
->details
.structure
->fields
;
122 static inline statement_list_t
*type_iface_get_stmts(const type_t
*type
)
124 type
= type_get_real_type(type
);
125 assert(type_get_type(type
) == TYPE_INTERFACE
);
126 return type
->details
.iface
->stmts
;
129 static inline type_t
*type_iface_get_inherit(const type_t
*type
)
131 type
= type_get_real_type(type
);
132 assert(type_get_type(type
) == TYPE_INTERFACE
);
136 static inline var_list_t
*type_dispiface_get_props(const type_t
*type
)
138 type
= type_get_real_type(type
);
139 assert(type_get_type(type
) == TYPE_INTERFACE
);
140 return type
->details
.iface
->disp_props
;
143 static inline var_list_t
*type_dispiface_get_methods(const type_t
*type
)
145 type
= type_get_real_type(type
);
146 assert(type_get_type(type
) == TYPE_INTERFACE
);
147 return type
->details
.iface
->disp_methods
;
150 static inline int type_is_defined(const type_t
*type
)
152 return type
->defined
;
155 static inline int type_is_complete(const type_t
*type
)
157 switch (type_get_type_detect_alias(type
))
160 return (type
->details
.function
!= NULL
);
162 return (type
->details
.iface
!= NULL
);
164 return (type
->details
.enumeration
!= NULL
);
166 case TYPE_ENCAPSULATED_UNION
:
168 return (type
->details
.structure
!= NULL
);
181 static inline int type_array_has_conformance(const type_t
*type
)
183 type
= type_get_real_type(type
);
184 assert(type_get_type(type
) == TYPE_ARRAY
);
185 return (type
->details
.array
.size_is
!= NULL
);
188 static inline int type_array_has_variance(const type_t
*type
)
190 type
= type_get_real_type(type
);
191 assert(type_get_type(type
) == TYPE_ARRAY
);
192 return (type
->details
.array
.length_is
!= NULL
);
195 static inline unsigned int type_array_get_dim(const type_t
*type
)
197 type
= type_get_real_type(type
);
198 assert(type_get_type(type
) == TYPE_ARRAY
);
199 return type
->details
.array
.dim
;
202 static inline expr_t
*type_array_get_conformance(const type_t
*type
)
204 type
= type_get_real_type(type
);
205 assert(type_get_type(type
) == TYPE_ARRAY
);
206 return type
->details
.array
.size_is
;
209 static inline expr_t
*type_array_get_variance(const type_t
*type
)
211 type
= type_get_real_type(type
);
212 assert(type_get_type(type
) == TYPE_ARRAY
);
213 return type
->details
.array
.length_is
;
216 static inline type_t
*type_array_get_element(const type_t
*type
)
218 type
= type_get_real_type(type
);
219 assert(type_get_type(type
) == TYPE_ARRAY
);
223 static inline int type_is_alias(const type_t
*type
)
225 return type
->is_alias
;
228 static inline type_t
*type_alias_get_aliasee(const type_t
*type
)
230 assert(type_is_alias(type
));
234 static inline ifref_list_t
*type_coclass_get_ifaces(const type_t
*type
)
236 type
= type_get_real_type(type
);
237 assert(type_get_type(type
) == TYPE_COCLASS
);
238 return type
->details
.coclass
.ifaces
;
241 static inline type_t
*type_pointer_get_ref(const type_t
*type
)
243 type
= type_get_real_type(type
);
244 assert(type_get_type(type
) == TYPE_POINTER
);
248 #endif /* WIDL_TYPE_TREE_H */