typetree.h 9.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * IDL Type Tree
 *
 * Copyright 2008 Robert Shearman
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "widltypes.h"
#include <assert.h>

#ifndef WIDL_TYPE_TREE_H
#define WIDL_TYPE_TREE_H

type_t *type_new_function(var_list_t *args);
28
type_t *type_new_pointer(unsigned char pointer_default, 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 declptr,
32 33
                       unsigned int dim, expr_t *size_is, expr_t *length_is,
                       unsigned char ptr_default_fc);
34 35 36
type_t *type_new_basic(enum type_basic_type basic_type);
type_t *type_new_int(enum type_basic_type basic_type, int sign);
type_t *type_new_void(void);
37
type_t *type_new_coclass(char *name);
38 39 40 41
type_t *type_new_enum(const char *name, int defined, var_list_t *enums);
type_t *type_new_struct(char *name, int defined, var_list_t *fields);
type_t *type_new_nonencapsulated_union(const char *name, int defined, var_list_t *fields);
type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases);
42
type_t *type_new_bitfield(type_t *field_type, const expr_t *bits);
43
void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts);
44 45
void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods);
void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface);
46
void type_module_define(type_t *module, statement_list_t *stmts);
47
type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces);
48
int type_is_equal(const type_t *type1, const type_t *type2);
49

50 51 52
/* FIXME: shouldn't need to export this */
type_t *duptype(type_t *t, int dupname);

53 54 55 56 57 58 59 60 61 62 63 64 65 66
/* un-alias the type until finding the non-alias type */
static inline type_t *type_get_real_type(const type_t *type)
{
    if (type->is_alias)
        return type_get_real_type(type->orig);
    else
        return (type_t *)type;
}

static inline enum type_type type_get_type(const type_t *type)
{
    return type_get_type_detect_alias(type_get_real_type(type));
}

67 68 69 70 71 72 73 74 75 76 77 78
static inline enum type_basic_type type_basic_get_type(const type_t *type)
{
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_BASIC);
    return type->details.basic.type;
}

static inline int type_basic_get_sign(const type_t *type)
{
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_BASIC);
    return type->details.basic.sign;
79 80
}

81 82
static inline var_list_t *type_struct_get_fields(const type_t *type)
{
83 84
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_STRUCT);
85
    return type->details.structure->fields;
86 87 88 89
}

static inline var_list_t *type_function_get_args(const type_t *type)
{
90 91
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_FUNCTION);
92
    return type->details.function->args;
93 94
}

95 96
static inline type_t *type_function_get_rettype(const type_t *type)
{
97 98
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_FUNCTION);
99
    return type->details.function->rettype;
100 101
}

102 103
static inline var_list_t *type_enum_get_values(const type_t *type)
{
104 105
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_ENUM);
106
    return type->details.enumeration->enums;
107 108 109 110
}

static inline var_t *type_union_get_switch_value(const type_t *type)
{
111 112
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
113
    return LIST_ENTRY(list_head(type->details.structure->fields), var_t, entry);
114 115 116 117
}

static inline var_list_t *type_encapsulated_union_get_fields(const type_t *type)
{
118 119
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
120
    return type->details.structure->fields;
121 122 123 124
}

static inline var_list_t *type_union_get_cases(const type_t *type)
{
125 126 127 128 129 130 131
    enum type_type type_type;

    type = type_get_real_type(type);
    type_type = type_get_type(type);

    assert(type_type == TYPE_UNION || type_type == TYPE_ENCAPSULATED_UNION);
    if (type_type == TYPE_ENCAPSULATED_UNION)
132
    {
133 134
        const var_t *uv = LIST_ENTRY(list_tail(type->details.structure->fields), const var_t, entry);
        return uv->type->details.structure->fields;
135 136
    }
    else
137
        return type->details.structure->fields;
138 139
}

140 141
static inline statement_list_t *type_iface_get_stmts(const type_t *type)
{
142 143
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_INTERFACE);
144 145 146
    return type->details.iface->stmts;
}

147 148
static inline type_t *type_iface_get_inherit(const type_t *type)
{
149 150
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_INTERFACE);
151
    return type->details.iface->inherit;
152 153
}

154 155
static inline var_list_t *type_dispiface_get_props(const type_t *type)
{
156 157
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_INTERFACE);
158
    return type->details.iface->disp_props;
159 160 161 162
}

static inline var_list_t *type_dispiface_get_methods(const type_t *type)
{
163 164
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_INTERFACE);
165
    return type->details.iface->disp_methods;
166 167 168 169 170 171 172
}

static inline int type_is_defined(const type_t *type)
{
    return type->defined;
}

173 174
static inline int type_is_complete(const type_t *type)
{
175 176 177
    switch (type_get_type_detect_alias(type))
    {
    case TYPE_FUNCTION:
178
        return (type->details.function != NULL);
179
    case TYPE_INTERFACE:
180
        return (type->details.iface != NULL);
181
    case TYPE_ENUM:
182
        return (type->details.enumeration != NULL);
183 184 185
    case TYPE_UNION:
    case TYPE_ENCAPSULATED_UNION:
    case TYPE_STRUCT:
186
        return (type->details.structure != NULL);
187 188 189 190 191 192 193
    case TYPE_VOID:
    case TYPE_BASIC:
    case TYPE_ALIAS:
    case TYPE_MODULE:
    case TYPE_COCLASS:
    case TYPE_POINTER:
    case TYPE_ARRAY:
194
    case TYPE_BITFIELD:
195
        return TRUE;
196 197
    }
    return FALSE;
198 199
}

200 201
static inline int type_array_has_conformance(const type_t *type)
{
202 203
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_ARRAY);
204 205 206 207 208
    return (type->details.array.size_is != NULL);
}

static inline int type_array_has_variance(const type_t *type)
{
209 210
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_ARRAY);
211 212 213
    return (type->details.array.length_is != NULL);
}

214
static inline unsigned int type_array_get_dim(const type_t *type)
215
{
216 217
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_ARRAY);
218 219 220 221 222
    return type->details.array.dim;
}

static inline expr_t *type_array_get_conformance(const type_t *type)
{
223 224
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_ARRAY);
225 226 227 228 229
    return type->details.array.size_is;
}

static inline expr_t *type_array_get_variance(const type_t *type)
{
230 231
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_ARRAY);
232 233 234
    return type->details.array.length_is;
}

235 236
static inline type_t *type_array_get_element(const type_t *type)
{
237 238
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_ARRAY);
239
    return type->details.array.elem;
240 241
}

242 243 244 245 246 247 248
static inline int type_array_is_decl_as_ptr(const type_t *type)
{
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_ARRAY);
    return type->details.array.declptr;
}

249 250 251 252 253 254 255
static inline unsigned char type_array_get_ptr_default_fc(const type_t *type)
{
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_ARRAY);
    return type->details.array.ptr_def_fc;
}

256 257
static inline int type_is_alias(const type_t *type)
{
258
    return type->is_alias;
259 260
}

261 262 263 264 265 266
static inline type_t *type_alias_get_aliasee(const type_t *type)
{
    assert(type_is_alias(type));
    return type->orig;
}

267 268
static inline ifref_list_t *type_coclass_get_ifaces(const type_t *type)
{
269 270
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_COCLASS);
271
    return type->details.coclass.ifaces;
272 273
}

274 275
static inline type_t *type_pointer_get_ref(const type_t *type)
{
276 277
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_POINTER);
278
    return type->details.pointer.ref;
279 280
}

281 282 283 284 285 286 287
static inline unsigned char type_pointer_get_default_fc(const type_t *type)
{
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_POINTER);
    return type->details.pointer.def_fc;
}

288 289 290 291 292 293 294 295 296 297 298 299 300 301
static inline type_t *type_bitfield_get_field(const type_t *type)
{
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_BITFIELD);
    return type->details.bitfield.field;
}

static inline const expr_t *type_bitfield_get_bits(const type_t *type)
{
    type = type_get_real_type(type);
    assert(type_get_type(type) == TYPE_BITFIELD);
    return type->details.bitfield.bits;
}

302
#endif /* WIDL_TYPE_TREE_H */