widl: Replace uses of get_func_return_type with type_function_get_rettype.
[wine] / tools / widl / typetree.h
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 void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts);
32 void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods);
33 void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface);
34 void type_module_define(type_t *module, statement_list_t *stmts);
35 type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces);
36
37 /* FIXME: shouldn't need to export this */
38 type_t *duptype(type_t *t, int dupname);
39
40 static inline var_list_t *type_struct_get_fields(const type_t *type)
41 {
42     assert(is_struct(type->type));
43     return type->details.structure->fields;
44 }
45
46 static inline var_list_t *type_function_get_args(const type_t *type)
47 {
48     assert(type->type == RPC_FC_FUNCTION);
49     return type->details.function->args;
50 }
51
52 static inline type_t *type_function_get_rettype(const type_t *type)
53 {
54     assert(type->type == RPC_FC_FUNCTION);
55     return type->ref;
56 }
57
58 static inline var_list_t *type_enum_get_values(const type_t *type)
59 {
60     assert(type->type == RPC_FC_ENUM16 || type->type == RPC_FC_ENUM32);
61     return type->details.enumeration->enums;
62 }
63
64 static inline var_t *type_union_get_switch_value(const type_t *type)
65 {
66     assert(type->type == RPC_FC_ENCAPSULATED_UNION);
67     return LIST_ENTRY(list_head(type->details.structure->fields), var_t, entry);
68 }
69
70 static inline var_list_t *type_encapsulated_union_get_fields(const type_t *type)
71 {
72     assert(type->type == RPC_FC_ENCAPSULATED_UNION);
73     return type->details.structure->fields;
74 }
75
76 static inline var_list_t *type_union_get_cases(const type_t *type)
77 {
78     assert(type->type == RPC_FC_ENCAPSULATED_UNION ||
79            type->type == RPC_FC_NON_ENCAPSULATED_UNION);
80     if (type->type == RPC_FC_ENCAPSULATED_UNION)
81     {
82         const var_t *uv = LIST_ENTRY(list_tail(type->details.structure->fields), const var_t, entry);
83         return uv->type->details.structure->fields;
84     }
85     else
86         return type->details.structure->fields;
87 }
88
89 static inline statement_list_t *type_iface_get_stmts(const type_t *type)
90 {
91     assert(type->type == RPC_FC_IP);
92     return type->details.iface->stmts;
93 }
94
95 static inline type_t *type_iface_get_inherit(const type_t *type)
96 {
97     assert(type->type == RPC_FC_IP);
98     return type->ref;
99 }
100
101 static inline var_list_t *type_dispiface_get_props(const type_t *type)
102 {
103     assert(type->type == RPC_FC_IP);
104     return type->details.iface->disp_props;
105 }
106
107 static inline var_list_t *type_dispiface_get_methods(const type_t *type)
108 {
109     assert(type->type == RPC_FC_IP);
110     return type->details.iface->disp_methods;
111 }
112
113 static inline int type_is_defined(const type_t *type)
114 {
115     return type->defined;
116 }
117
118 static inline int type_is_complete(const type_t *type)
119 {
120     if (type->type == RPC_FC_FUNCTION)
121         return (type->details.function != NULL);
122     else if (type->type == RPC_FC_IP)
123         return (type->details.iface != NULL);
124     else if (type->type == RPC_FC_ENUM16 || type->type == RPC_FC_ENUM32)
125         return (type->details.enumeration != NULL);
126     else if (is_struct(type->type) || is_union(type->type))
127         return (type->details.structure != NULL);
128     else
129         return TRUE;
130 }
131
132 static inline int type_array_has_conformance(const type_t *type)
133 {
134     assert(is_array(type));
135     return (type->details.array.size_is != NULL);
136 }
137
138 static inline int type_array_has_variance(const type_t *type)
139 {
140     assert(is_array(type));
141     return (type->details.array.length_is != NULL);
142 }
143
144 static inline unsigned long type_array_get_dim(const type_t *type)
145 {
146     assert(is_array(type));
147     return type->details.array.dim;
148 }
149
150 static inline expr_t *type_array_get_conformance(const type_t *type)
151 {
152     assert(is_array(type));
153     return type->details.array.size_is;
154 }
155
156 static inline expr_t *type_array_get_variance(const type_t *type)
157 {
158     assert(is_array(type));
159     return type->details.array.length_is;
160 }
161
162 static inline type_t *type_array_get_element(const type_t *type)
163 {
164     assert(is_array(type));
165     return type->ref;
166 }
167
168 static inline type_t *type_get_real_type(const type_t *type)
169 {
170     if (type->is_alias)
171         return type_get_real_type(type->orig);
172     else
173         return (type_t *)type;
174 }
175
176 static inline int type_is_alias(const type_t *type)
177 {
178     return type->is_alias;
179 }
180
181 static inline ifref_list_t *type_coclass_get_ifaces(const type_t *type)
182 {
183     assert(type->type == RPC_FC_COCLASS);
184     return type->details.coclass.ifaces;
185 }
186
187 static inline type_t *type_pointer_get_ref(const type_t *type)
188 {
189     assert(is_ptr(type));
190     return type->ref;
191 }
192
193 #endif /* WIDL_TYPE_TREE_H */