2008-12-29 13:05:27 +01:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2015-08-07 15:41:55 +02:00
|
|
|
enum name_type {
|
|
|
|
NAME_DEFAULT,
|
|
|
|
NAME_C
|
|
|
|
};
|
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
type_t *type_new_function(var_list_t *args);
|
2019-08-18 03:07:08 +02:00
|
|
|
type_t *type_new_pointer(type_t *ref);
|
2019-08-16 03:13:21 +02:00
|
|
|
type_t *type_new_alias(const decl_spec_t *t, const char *name);
|
2009-03-05 09:23:07 +01:00
|
|
|
type_t *type_new_module(char *name);
|
2019-08-16 03:13:20 +02:00
|
|
|
type_t *type_new_array(const char *name, const decl_spec_t *element, int declptr,
|
2019-08-18 03:07:08 +02:00
|
|
|
unsigned int dim, expr_t *size_is, expr_t *length_is);
|
2009-03-05 09:21:51 +01:00
|
|
|
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);
|
2009-03-05 09:23:07 +01:00
|
|
|
type_t *type_new_coclass(char *name);
|
2015-08-07 15:41:55 +02:00
|
|
|
type_t *type_new_enum(const char *name, struct namespace *namespace, int defined, var_list_t *enums);
|
2015-08-10 13:19:48 +02:00
|
|
|
type_t *type_new_struct(char *name, struct namespace *namespace, int defined, var_list_t *fields);
|
2009-03-05 09:23:00 +01:00
|
|
|
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);
|
2009-11-07 15:55:09 +01:00
|
|
|
type_t *type_new_bitfield(type_t *field_type, const expr_t *bits);
|
2008-12-29 13:06:35 +01:00
|
|
|
void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts);
|
2010-03-23 14:33:36 +01:00
|
|
|
void type_dispinterface_define(type_t *iface, var_list_t *props, var_list_t *methods);
|
2008-12-29 13:05:27 +01:00
|
|
|
void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface);
|
2009-01-06 00:33:27 +01:00
|
|
|
void type_module_define(type_t *module, statement_list_t *stmts);
|
2009-01-06 00:34:38 +01:00
|
|
|
type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces);
|
2009-02-23 14:48:15 +01:00
|
|
|
int type_is_equal(const type_t *type1, const type_t *type2);
|
2015-08-07 15:41:55 +02:00
|
|
|
const char *type_get_name(const type_t *type, enum name_type name_type);
|
2019-08-21 18:18:06 +02:00
|
|
|
char *gen_name(void);
|
2008-12-29 13:05:27 +01:00
|
|
|
|
2009-01-06 00:33:52 +01:00
|
|
|
/* FIXME: shouldn't need to export this */
|
|
|
|
type_t *duptype(type_t *t, int dupname);
|
|
|
|
|
2009-01-19 01:02:35 +01:00
|
|
|
/* un-alias the type until finding the non-alias type */
|
|
|
|
static inline type_t *type_get_real_type(const type_t *type)
|
|
|
|
{
|
2019-08-15 04:45:49 +02:00
|
|
|
if (type->type_type == TYPE_ALIAS)
|
2019-08-15 04:45:50 +02:00
|
|
|
return type_get_real_type(type->details.alias.aliasee.type);
|
2009-01-19 01:02:35 +01:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2009-03-05 09:21:51 +01:00
|
|
|
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;
|
2009-01-19 01:02:35 +01:00
|
|
|
}
|
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
static inline var_list_t *type_struct_get_fields(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_STRUCT);
|
2008-12-29 13:05:35 +01:00
|
|
|
return type->details.structure->fields;
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline var_list_t *type_function_get_args(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_FUNCTION);
|
2008-12-29 13:05:35 +01:00
|
|
|
return type->details.function->args;
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
|
|
|
|
2011-09-17 13:38:15 +02:00
|
|
|
static inline var_t *type_function_get_retval(const type_t *type)
|
2009-01-06 00:35:24 +01:00
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_FUNCTION);
|
2011-09-17 13:38:15 +02:00
|
|
|
return type->details.function->retval;
|
|
|
|
}
|
|
|
|
|
2019-08-16 03:13:18 +02:00
|
|
|
static inline const decl_spec_t *type_function_get_ret(const type_t *type)
|
|
|
|
{
|
|
|
|
return &type_function_get_retval(type)->declspec;
|
|
|
|
}
|
|
|
|
|
2011-09-17 13:38:15 +02:00
|
|
|
static inline type_t *type_function_get_rettype(const type_t *type)
|
|
|
|
{
|
2019-07-05 23:49:49 +02:00
|
|
|
return type_function_get_retval(type)->declspec.type;
|
2009-01-06 00:35:24 +01:00
|
|
|
}
|
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
static inline var_list_t *type_enum_get_values(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_ENUM);
|
2008-12-29 13:05:35 +01:00
|
|
|
return type->details.enumeration->enums;
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline var_t *type_union_get_switch_value(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
|
2008-12-29 13:05:35 +01:00
|
|
|
return LIST_ENTRY(list_head(type->details.structure->fields), var_t, entry);
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline var_list_t *type_encapsulated_union_get_fields(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION);
|
2008-12-29 13:05:35 +01:00
|
|
|
return type->details.structure->fields;
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline var_list_t *type_union_get_cases(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
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)
|
2008-12-29 13:05:27 +01:00
|
|
|
{
|
2008-12-29 13:05:35 +01:00
|
|
|
const var_t *uv = LIST_ENTRY(list_tail(type->details.structure->fields), const var_t, entry);
|
2019-07-05 23:49:49 +02:00
|
|
|
return uv->declspec.type->details.structure->fields;
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
|
|
|
else
|
2008-12-29 13:05:35 +01:00
|
|
|
return type->details.structure->fields;
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
|
|
|
|
2009-01-06 00:35:13 +01:00
|
|
|
static inline statement_list_t *type_iface_get_stmts(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_INTERFACE);
|
2009-01-06 00:35:13 +01:00
|
|
|
return type->details.iface->stmts;
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:35:06 +01:00
|
|
|
static inline type_t *type_iface_get_inherit(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_INTERFACE);
|
2009-03-05 09:22:32 +01:00
|
|
|
return type->details.iface->inherit;
|
2009-01-06 00:35:06 +01:00
|
|
|
}
|
|
|
|
|
2019-08-15 04:45:46 +02:00
|
|
|
static inline type_t *type_iface_get_async_iface(const type_t *type)
|
|
|
|
{
|
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_INTERFACE);
|
|
|
|
return type->details.iface->async_iface;
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
static inline var_list_t *type_dispiface_get_props(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_INTERFACE);
|
2008-12-29 13:05:35 +01:00
|
|
|
return type->details.iface->disp_props;
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline var_list_t *type_dispiface_get_methods(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_INTERFACE);
|
2008-12-29 13:05:35 +01:00
|
|
|
return type->details.iface->disp_methods;
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
|
|
|
|
2018-05-29 09:49:35 +02:00
|
|
|
static inline type_t *type_dispiface_get_inherit(const type_t *type)
|
|
|
|
{
|
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_INTERFACE);
|
|
|
|
return type->details.iface->disp_inherit;
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
static inline int type_is_defined(const type_t *type)
|
|
|
|
{
|
|
|
|
return type->defined;
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:05:35 +01:00
|
|
|
static inline int type_is_complete(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
switch (type_get_type_detect_alias(type))
|
|
|
|
{
|
|
|
|
case TYPE_FUNCTION:
|
2008-12-29 13:05:35 +01:00
|
|
|
return (type->details.function != NULL);
|
2009-01-19 01:02:35 +01:00
|
|
|
case TYPE_INTERFACE:
|
2008-12-29 13:05:35 +01:00
|
|
|
return (type->details.iface != NULL);
|
2009-01-19 01:02:35 +01:00
|
|
|
case TYPE_ENUM:
|
2008-12-29 13:05:35 +01:00
|
|
|
return (type->details.enumeration != NULL);
|
2009-01-19 01:02:35 +01:00
|
|
|
case TYPE_UNION:
|
|
|
|
case TYPE_ENCAPSULATED_UNION:
|
|
|
|
case TYPE_STRUCT:
|
2008-12-29 13:05:35 +01:00
|
|
|
return (type->details.structure != NULL);
|
2009-01-19 01:02:35 +01:00
|
|
|
case TYPE_VOID:
|
|
|
|
case TYPE_BASIC:
|
|
|
|
case TYPE_ALIAS:
|
|
|
|
case TYPE_MODULE:
|
|
|
|
case TYPE_COCLASS:
|
|
|
|
case TYPE_POINTER:
|
|
|
|
case TYPE_ARRAY:
|
2009-11-07 15:55:09 +01:00
|
|
|
case TYPE_BITFIELD:
|
2008-12-29 13:05:35 +01:00
|
|
|
return TRUE;
|
2009-01-19 01:02:35 +01:00
|
|
|
}
|
|
|
|
return FALSE;
|
2008-12-29 13:05:35 +01:00
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:36 +01:00
|
|
|
static inline int type_array_has_conformance(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_ARRAY);
|
2009-01-06 00:33:36 +01:00
|
|
|
return (type->details.array.size_is != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int type_array_has_variance(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_ARRAY);
|
2009-01-06 00:33:36 +01:00
|
|
|
return (type->details.array.length_is != NULL);
|
|
|
|
}
|
|
|
|
|
2009-02-06 14:30:38 +01:00
|
|
|
static inline unsigned int type_array_get_dim(const type_t *type)
|
2009-01-06 00:33:36 +01:00
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_ARRAY);
|
2009-01-06 00:33:36 +01:00
|
|
|
return type->details.array.dim;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline expr_t *type_array_get_conformance(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_ARRAY);
|
2009-01-06 00:33:36 +01:00
|
|
|
return type->details.array.size_is;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline expr_t *type_array_get_variance(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_ARRAY);
|
2009-01-06 00:33:36 +01:00
|
|
|
return type->details.array.length_is;
|
|
|
|
}
|
|
|
|
|
2019-08-15 04:45:48 +02:00
|
|
|
static inline unsigned short type_array_get_ptr_tfsoff(const type_t *type)
|
|
|
|
{
|
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_ARRAY);
|
|
|
|
return type->details.array.ptr_tfsoff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void type_array_set_ptr_tfsoff(type_t *type, unsigned short ptr_tfsoff)
|
|
|
|
{
|
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_ARRAY);
|
|
|
|
type->details.array.ptr_tfsoff = ptr_tfsoff;
|
|
|
|
}
|
|
|
|
|
2019-07-05 23:51:31 +02:00
|
|
|
static inline const decl_spec_t *type_array_get_element(const type_t *type)
|
2009-01-06 00:34:52 +01:00
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_ARRAY);
|
2019-07-05 23:51:31 +02:00
|
|
|
return &type->details.array.elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline type_t *type_array_get_element_type(const type_t *type)
|
|
|
|
{
|
|
|
|
return type_array_get_element(type)->type;
|
2009-01-06 00:34:52 +01:00
|
|
|
}
|
|
|
|
|
2009-03-05 09:21:35 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:43 +01:00
|
|
|
static inline int type_is_alias(const type_t *type)
|
|
|
|
{
|
2019-08-15 04:45:49 +02:00
|
|
|
return type->type_type == TYPE_ALIAS;
|
2009-01-06 00:33:43 +01:00
|
|
|
}
|
|
|
|
|
2019-08-16 03:13:18 +02:00
|
|
|
static inline const decl_spec_t *type_alias_get_aliasee(const type_t *type)
|
|
|
|
{
|
|
|
|
assert(type_is_alias(type));
|
|
|
|
return &type->details.alias.aliasee;
|
|
|
|
}
|
|
|
|
|
2019-08-15 04:45:50 +02:00
|
|
|
static inline type_t *type_alias_get_aliasee_type(const type_t *type)
|
2009-01-19 01:02:28 +01:00
|
|
|
{
|
|
|
|
assert(type_is_alias(type));
|
2019-08-15 04:45:50 +02:00
|
|
|
return type->details.alias.aliasee.type;
|
2009-01-19 01:02:28 +01:00
|
|
|
}
|
|
|
|
|
2009-01-06 00:34:38 +01:00
|
|
|
static inline ifref_list_t *type_coclass_get_ifaces(const type_t *type)
|
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_COCLASS);
|
2009-01-06 00:34:44 +01:00
|
|
|
return type->details.coclass.ifaces;
|
2009-01-06 00:34:38 +01:00
|
|
|
}
|
|
|
|
|
2019-07-05 23:51:32 +02:00
|
|
|
static inline const decl_spec_t *type_pointer_get_ref(const type_t *type)
|
2009-01-06 00:34:58 +01:00
|
|
|
{
|
2009-01-19 01:02:35 +01:00
|
|
|
type = type_get_real_type(type);
|
|
|
|
assert(type_get_type(type) == TYPE_POINTER);
|
2019-07-05 23:51:32 +02:00
|
|
|
return &type->details.pointer.ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline type_t *type_pointer_get_ref_type(const type_t *type)
|
|
|
|
{
|
|
|
|
return type_pointer_get_ref(type)->type;
|
2009-01-06 00:34:58 +01:00
|
|
|
}
|
|
|
|
|
2009-11-07 15:55:09 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
#endif /* WIDL_TYPE_TREE_H */
|