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 long 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 static inline var_list_t
*type_struct_get_fields(const type_t
*type
)
44 assert(is_struct(type
->type
));
45 return type
->details
.structure
->fields
;
48 static inline var_list_t
*type_function_get_args(const type_t
*type
)
50 assert(type
->type
== RPC_FC_FUNCTION
);
51 return type
->details
.function
->args
;
54 static inline type_t
*type_function_get_rettype(const type_t
*type
)
56 assert(type
->type
== RPC_FC_FUNCTION
);
60 static inline var_list_t
*type_enum_get_values(const type_t
*type
)
62 assert(type
->type
== RPC_FC_ENUM16
|| type
->type
== RPC_FC_ENUM32
);
63 return type
->details
.enumeration
->enums
;
66 static inline var_t
*type_union_get_switch_value(const type_t
*type
)
68 assert(type
->type
== RPC_FC_ENCAPSULATED_UNION
);
69 return LIST_ENTRY(list_head(type
->details
.structure
->fields
), var_t
, entry
);
72 static inline var_list_t
*type_encapsulated_union_get_fields(const type_t
*type
)
74 assert(type
->type
== RPC_FC_ENCAPSULATED_UNION
);
75 return type
->details
.structure
->fields
;
78 static inline var_list_t
*type_union_get_cases(const type_t
*type
)
80 assert(type
->type
== RPC_FC_ENCAPSULATED_UNION
||
81 type
->type
== RPC_FC_NON_ENCAPSULATED_UNION
);
82 if (type
->type
== RPC_FC_ENCAPSULATED_UNION
)
84 const var_t
*uv
= LIST_ENTRY(list_tail(type
->details
.structure
->fields
), const var_t
, entry
);
85 return uv
->type
->details
.structure
->fields
;
88 return type
->details
.structure
->fields
;
91 static inline statement_list_t
*type_iface_get_stmts(const type_t
*type
)
93 assert(type
->type
== RPC_FC_IP
);
94 return type
->details
.iface
->stmts
;
97 static inline type_t
*type_iface_get_inherit(const type_t
*type
)
99 assert(type
->type
== RPC_FC_IP
);
103 static inline var_list_t
*type_dispiface_get_props(const type_t
*type
)
105 assert(type
->type
== RPC_FC_IP
);
106 return type
->details
.iface
->disp_props
;
109 static inline var_list_t
*type_dispiface_get_methods(const type_t
*type
)
111 assert(type
->type
== RPC_FC_IP
);
112 return type
->details
.iface
->disp_methods
;
115 static inline int type_is_defined(const type_t
*type
)
117 return type
->defined
;
120 static inline int type_is_complete(const type_t
*type
)
122 if (type
->type
== RPC_FC_FUNCTION
)
123 return (type
->details
.function
!= NULL
);
124 else if (type
->type
== RPC_FC_IP
)
125 return (type
->details
.iface
!= NULL
);
126 else if (type
->type
== RPC_FC_ENUM16
|| type
->type
== RPC_FC_ENUM32
)
127 return (type
->details
.enumeration
!= NULL
);
128 else if (is_struct(type
->type
) || is_union(type
->type
))
129 return (type
->details
.structure
!= NULL
);
134 static inline int type_array_has_conformance(const type_t
*type
)
136 assert(is_array(type
));
137 return (type
->details
.array
.size_is
!= NULL
);
140 static inline int type_array_has_variance(const type_t
*type
)
142 assert(is_array(type
));
143 return (type
->details
.array
.length_is
!= NULL
);
146 static inline unsigned long type_array_get_dim(const type_t
*type
)
148 assert(is_array(type
));
149 return type
->details
.array
.dim
;
152 static inline expr_t
*type_array_get_conformance(const type_t
*type
)
154 assert(is_array(type
));
155 return type
->details
.array
.size_is
;
158 static inline expr_t
*type_array_get_variance(const type_t
*type
)
160 assert(is_array(type
));
161 return type
->details
.array
.length_is
;
164 static inline type_t
*type_array_get_element(const type_t
*type
)
166 assert(is_array(type
));
170 static inline type_t
*type_get_real_type(const type_t
*type
)
173 return type_get_real_type(type
->orig
);
175 return (type_t
*)type
;
178 static inline int type_is_alias(const type_t
*type
)
180 return type
->is_alias
;
183 static inline ifref_list_t
*type_coclass_get_ifaces(const type_t
*type
)
185 assert(type
->type
== RPC_FC_COCLASS
);
186 return type
->details
.coclass
.ifaces
;
189 static inline type_t
*type_pointer_get_ref(const type_t
*type
)
191 assert(is_ptr(type
));
195 #endif /* WIDL_TYPE_TREE_H */