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 "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2009-02-23 14:48:15 +01:00
|
|
|
#include <string.h>
|
2008-12-29 13:05:27 +01:00
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "typetree.h"
|
|
|
|
#include "header.h"
|
|
|
|
|
2009-01-06 00:33:52 +01:00
|
|
|
type_t *duptype(type_t *t, int dupname)
|
|
|
|
{
|
|
|
|
type_t *d = alloc_type();
|
|
|
|
|
|
|
|
*d = *t;
|
|
|
|
if (dupname && t->name)
|
|
|
|
d->name = xstrdup(t->name);
|
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2009-03-05 09:22:32 +01:00
|
|
|
type_t *make_type(enum type_type type)
|
|
|
|
{
|
|
|
|
type_t *t = alloc_type();
|
|
|
|
t->name = NULL;
|
2015-07-31 13:37:50 +02:00
|
|
|
t->namespace = NULL;
|
2009-03-05 09:22:32 +01:00
|
|
|
t->type_type = type;
|
|
|
|
t->attrs = NULL;
|
2015-07-31 13:37:50 +02:00
|
|
|
t->c_name = NULL;
|
2009-03-05 09:22:32 +01:00
|
|
|
memset(&t->details, 0, sizeof(t->details));
|
|
|
|
t->typestring_offset = 0;
|
|
|
|
t->ptrdesc = 0;
|
|
|
|
t->ignore = (parse_only != 0);
|
|
|
|
t->defined = FALSE;
|
|
|
|
t->written = FALSE;
|
|
|
|
t->user_types_registered = FALSE;
|
|
|
|
t->tfswrite = FALSE;
|
|
|
|
t->checked = FALSE;
|
|
|
|
t->typelib_idx = -1;
|
|
|
|
init_loc_info(&t->loc_info);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2009-11-07 15:54:24 +01:00
|
|
|
static const var_t *find_arg(const var_list_t *args, const char *name)
|
|
|
|
{
|
|
|
|
const var_t *arg;
|
|
|
|
|
|
|
|
if (args) LIST_FOR_EACH_ENTRY(arg, args, const var_t, entry)
|
|
|
|
{
|
|
|
|
if (arg->name && !strcmp(name, arg->name))
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-07 15:41:55 +02:00
|
|
|
const char *type_get_name(const type_t *type, enum name_type name_type)
|
|
|
|
{
|
|
|
|
switch(name_type) {
|
|
|
|
case NAME_DEFAULT:
|
|
|
|
return type->name;
|
|
|
|
case NAME_C:
|
2020-11-04 19:49:29 +01:00
|
|
|
return type->c_name ? type->c_name : type->name;
|
2015-08-07 15:41:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-12-01 15:01:54 +01:00
|
|
|
static char *append_namespace(char *ptr, struct namespace *namespace, const char *separator, const char *abi_prefix)
|
2015-07-31 13:37:50 +02:00
|
|
|
{
|
2015-08-05 12:52:15 +02:00
|
|
|
if(is_global_namespace(namespace)) {
|
2020-12-01 15:01:54 +01:00
|
|
|
if(!abi_prefix) return ptr;
|
|
|
|
strcpy(ptr, abi_prefix);
|
2015-08-05 12:52:15 +02:00
|
|
|
strcat(ptr, separator);
|
|
|
|
return ptr + strlen(ptr);
|
|
|
|
}
|
2015-07-31 13:37:50 +02:00
|
|
|
|
2020-12-01 15:01:54 +01:00
|
|
|
ptr = append_namespace(ptr, namespace->parent, separator, abi_prefix);
|
2015-07-31 13:37:50 +02:00
|
|
|
strcpy(ptr, namespace->name);
|
|
|
|
strcat(ptr, separator);
|
|
|
|
return ptr + strlen(ptr);
|
|
|
|
}
|
|
|
|
|
2020-12-01 15:01:54 +01:00
|
|
|
char *format_namespace(struct namespace *namespace, const char *prefix, const char *separator, const char *suffix,
|
|
|
|
const char *abi_prefix)
|
2015-07-31 13:37:50 +02:00
|
|
|
{
|
|
|
|
unsigned len = strlen(prefix) + strlen(suffix);
|
|
|
|
unsigned sep_len = strlen(separator);
|
|
|
|
struct namespace *iter;
|
|
|
|
char *ret, *ptr;
|
|
|
|
|
2020-12-01 15:01:54 +01:00
|
|
|
if(abi_prefix)
|
|
|
|
len += strlen(abi_prefix) + sep_len;
|
2015-08-05 12:52:15 +02:00
|
|
|
|
2015-07-31 13:37:50 +02:00
|
|
|
for(iter = namespace; !is_global_namespace(iter); iter = iter->parent)
|
|
|
|
len += strlen(iter->name) + sep_len;
|
|
|
|
|
|
|
|
ret = xmalloc(len+1);
|
|
|
|
strcpy(ret, prefix);
|
2020-12-01 15:01:54 +01:00
|
|
|
ptr = append_namespace(ret + strlen(ret), namespace, separator, abi_prefix);
|
2015-07-31 13:37:50 +02:00
|
|
|
strcpy(ptr, suffix);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
type_t *type_new_function(var_list_t *args)
|
|
|
|
{
|
2009-11-07 15:54:24 +01:00
|
|
|
var_t *arg;
|
|
|
|
type_t *t;
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
if (args)
|
|
|
|
{
|
|
|
|
arg = LIST_ENTRY(list_head(args), var_t, entry);
|
2019-07-05 23:49:49 +02:00
|
|
|
if (list_count(args) == 1 && !arg->name && arg->declspec.type && type_get_type(arg->declspec.type) == TYPE_VOID)
|
2009-11-07 15:54:24 +01:00
|
|
|
{
|
|
|
|
list_remove(&arg->entry);
|
|
|
|
free(arg);
|
|
|
|
free(args);
|
|
|
|
args = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args) LIST_FOR_EACH_ENTRY(arg, args, var_t, entry)
|
|
|
|
{
|
2019-07-05 23:49:49 +02:00
|
|
|
if (arg->declspec.type && type_get_type(arg->declspec.type) == TYPE_VOID)
|
2009-11-07 15:54:24 +01:00
|
|
|
error_loc("argument '%s' has void type\n", arg->name);
|
|
|
|
if (!arg->name)
|
|
|
|
{
|
|
|
|
if (i > 26 * 26)
|
|
|
|
error_loc("too many unnamed arguments\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int unique;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
char name[3];
|
|
|
|
name[0] = i > 26 ? 'a' + i / 26 : 'a' + i;
|
|
|
|
name[1] = i > 26 ? 'a' + i % 26 : 0;
|
|
|
|
name[2] = 0;
|
|
|
|
unique = !find_arg(args, name);
|
|
|
|
if (unique)
|
|
|
|
arg->name = xstrdup(name);
|
|
|
|
i++;
|
|
|
|
} while (!unique);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t = make_type(TYPE_FUNCTION);
|
2008-12-29 13:05:35 +01:00
|
|
|
t->details.function = xmalloc(sizeof(*t->details.function));
|
|
|
|
t->details.function->args = args;
|
2019-08-18 03:07:05 +02:00
|
|
|
t->details.function->retval = make_var(xstrdup("_RetVal"));
|
2008-12-29 13:05:27 +01:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2019-08-18 03:07:08 +02:00
|
|
|
type_t *type_new_pointer(type_t *ref)
|
2008-12-29 13:05:27 +01:00
|
|
|
{
|
2009-03-05 09:22:32 +01:00
|
|
|
type_t *t = make_type(TYPE_POINTER);
|
2019-07-05 23:51:32 +02:00
|
|
|
t->details.pointer.ref.type = ref;
|
2008-12-29 13:05:27 +01:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2019-08-16 03:13:21 +02:00
|
|
|
type_t *type_new_alias(const decl_spec_t *t, const char *name)
|
2009-01-06 00:33:52 +01:00
|
|
|
{
|
2019-08-15 04:45:49 +02:00
|
|
|
type_t *a = make_type(TYPE_ALIAS);
|
2009-01-06 00:33:52 +01:00
|
|
|
|
2009-01-06 00:34:23 +01:00
|
|
|
a->name = xstrdup(name);
|
|
|
|
a->attrs = NULL;
|
2019-08-16 03:13:21 +02:00
|
|
|
a->details.alias.aliasee = *t;
|
2009-01-06 00:34:23 +01:00
|
|
|
init_loc_info(&a->loc_info);
|
2009-01-06 00:33:52 +01:00
|
|
|
|
2009-01-06 00:34:23 +01:00
|
|
|
return a;
|
2009-01-06 00:33:52 +01:00
|
|
|
}
|
|
|
|
|
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-01-07 00:20:59 +01:00
|
|
|
{
|
2009-03-05 09:22:32 +01:00
|
|
|
type_t *t = make_type(TYPE_ARRAY);
|
2009-01-07 00:20:59 +01:00
|
|
|
if (name) t->name = xstrdup(name);
|
2009-03-05 09:21:35 +01:00
|
|
|
t->details.array.declptr = declptr;
|
2009-01-07 00:20:59 +01:00
|
|
|
t->details.array.length_is = length_is;
|
|
|
|
if (size_is)
|
|
|
|
t->details.array.size_is = size_is;
|
|
|
|
else
|
|
|
|
t->details.array.dim = dim;
|
2019-08-16 03:13:20 +02:00
|
|
|
if (element)
|
|
|
|
t->details.array.elem = *element;
|
2009-01-07 00:20:59 +01:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2009-03-05 09:21:51 +01:00
|
|
|
type_t *type_new_basic(enum type_basic_type basic_type)
|
|
|
|
{
|
2009-03-05 09:22:32 +01:00
|
|
|
type_t *t = make_type(TYPE_BASIC);
|
2009-03-05 09:21:51 +01:00
|
|
|
t->details.basic.type = basic_type;
|
|
|
|
t->details.basic.sign = 0;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_new_int(enum type_basic_type basic_type, int sign)
|
|
|
|
{
|
|
|
|
static type_t *int_types[TYPE_BASIC_INT_MAX+1][3];
|
|
|
|
|
|
|
|
assert(basic_type <= TYPE_BASIC_INT_MAX);
|
|
|
|
|
|
|
|
/* map sign { -1, 0, 1 } -> { 0, 1, 2 } */
|
|
|
|
if (!int_types[basic_type][sign + 1])
|
|
|
|
{
|
|
|
|
int_types[basic_type][sign + 1] = type_new_basic(basic_type);
|
|
|
|
int_types[basic_type][sign + 1]->details.basic.sign = sign;
|
|
|
|
}
|
|
|
|
return int_types[basic_type][sign + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_new_void(void)
|
|
|
|
{
|
|
|
|
static type_t *void_type = NULL;
|
|
|
|
if (!void_type)
|
2009-03-05 09:22:32 +01:00
|
|
|
void_type = make_type(TYPE_VOID);
|
2009-03-05 09:21:51 +01:00
|
|
|
return void_type;
|
|
|
|
}
|
|
|
|
|
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)
|
2009-03-05 09:23:00 +01:00
|
|
|
{
|
2019-08-20 04:17:39 +02:00
|
|
|
type_t *t = NULL;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
t = find_type(name, namespace,tsENUM);
|
|
|
|
|
|
|
|
if (!t)
|
|
|
|
{
|
|
|
|
t = make_type(TYPE_ENUM);
|
|
|
|
t->name = name;
|
|
|
|
t->namespace = namespace;
|
|
|
|
if (name)
|
|
|
|
reg_type(t, name, namespace, tsENUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!t->defined && defined)
|
2009-03-05 09:23:00 +01:00
|
|
|
{
|
|
|
|
t->details.enumeration = xmalloc(sizeof(*t->details.enumeration));
|
|
|
|
t->details.enumeration->enums = enums;
|
|
|
|
t->defined = TRUE;
|
|
|
|
}
|
2019-08-21 05:28:24 +02:00
|
|
|
else if (defined)
|
|
|
|
error_loc("redefinition of enum %s\n", name);
|
2009-03-05 09:23:00 +01:00
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2019-08-20 04:17:37 +02:00
|
|
|
type_t *t = NULL;
|
2015-11-03 06:32:01 +01:00
|
|
|
|
2019-08-20 04:17:37 +02:00
|
|
|
if (name)
|
|
|
|
t = find_type(name, namespace, tsSTRUCT);
|
2015-11-03 06:32:01 +01:00
|
|
|
|
2019-08-20 04:17:37 +02:00
|
|
|
if (!t)
|
|
|
|
{
|
|
|
|
t = make_type(TYPE_STRUCT);
|
|
|
|
t->name = name;
|
|
|
|
t->namespace = namespace;
|
|
|
|
if (name)
|
|
|
|
reg_type(t, name, namespace, tsSTRUCT);
|
|
|
|
}
|
2015-08-10 13:19:48 +02:00
|
|
|
|
2019-08-20 04:17:37 +02:00
|
|
|
if (!t->defined && defined)
|
2009-03-05 09:23:00 +01:00
|
|
|
{
|
|
|
|
t->details.structure = xmalloc(sizeof(*t->details.structure));
|
|
|
|
t->details.structure->fields = fields;
|
|
|
|
t->defined = TRUE;
|
|
|
|
}
|
2019-08-21 05:28:24 +02:00
|
|
|
else if (defined)
|
|
|
|
error_loc("redefinition of struct %s\n", name);
|
2019-08-20 04:17:37 +02:00
|
|
|
|
2009-03-05 09:23:00 +01:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_new_nonencapsulated_union(const char *name, int defined, var_list_t *fields)
|
|
|
|
{
|
2019-08-20 04:17:38 +02:00
|
|
|
type_t *t = NULL;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
t = find_type(name, NULL, tsUNION);
|
|
|
|
|
|
|
|
if (!t)
|
|
|
|
{
|
|
|
|
t = make_type(TYPE_UNION);
|
|
|
|
t->name = name;
|
|
|
|
if (name)
|
|
|
|
reg_type(t, name, NULL, tsUNION);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!t->defined && defined)
|
2009-03-05 09:23:00 +01:00
|
|
|
{
|
|
|
|
t->details.structure = xmalloc(sizeof(*t->details.structure));
|
|
|
|
t->details.structure->fields = fields;
|
|
|
|
t->defined = TRUE;
|
|
|
|
}
|
2019-08-21 05:28:24 +02:00
|
|
|
else if (defined)
|
|
|
|
error_loc("redefinition of union %s\n", name);
|
2019-08-20 04:17:38 +02:00
|
|
|
|
2009-03-05 09:23:00 +01:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases)
|
|
|
|
{
|
2019-08-20 04:17:38 +02:00
|
|
|
type_t *t = NULL;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
t = find_type(name, NULL, tsUNION);
|
|
|
|
|
|
|
|
if (!t)
|
|
|
|
{
|
|
|
|
t = make_type(TYPE_ENCAPSULATED_UNION);
|
|
|
|
t->name = name;
|
|
|
|
if (name)
|
|
|
|
reg_type(t, name, NULL, tsUNION);
|
|
|
|
}
|
|
|
|
t->type_type = TYPE_ENCAPSULATED_UNION;
|
|
|
|
|
|
|
|
if (!t->defined)
|
|
|
|
{
|
|
|
|
if (!union_field)
|
|
|
|
union_field = make_var(xstrdup("tagged_union"));
|
2019-08-21 18:18:06 +02:00
|
|
|
union_field->declspec.type = type_new_nonencapsulated_union(gen_name(), TRUE, cases);
|
2019-08-20 04:17:38 +02:00
|
|
|
|
|
|
|
t->details.structure = xmalloc(sizeof(*t->details.structure));
|
|
|
|
t->details.structure->fields = append_var(NULL, switch_field);
|
|
|
|
t->details.structure->fields = append_var(t->details.structure->fields, union_field);
|
|
|
|
t->defined = TRUE;
|
|
|
|
}
|
2019-08-21 05:28:24 +02:00
|
|
|
else
|
|
|
|
error_loc("redefinition of union %s\n", name);
|
2019-08-20 04:17:38 +02:00
|
|
|
|
2009-03-05 09:23:00 +01:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2009-11-07 15:55:09 +01:00
|
|
|
static int is_valid_bitfield_type(const type_t *type)
|
|
|
|
{
|
|
|
|
switch (type_get_type(type))
|
|
|
|
{
|
|
|
|
case TYPE_ENUM:
|
|
|
|
return TRUE;
|
|
|
|
case TYPE_BASIC:
|
|
|
|
switch (type_basic_get_type(type))
|
|
|
|
{
|
|
|
|
case TYPE_BASIC_INT8:
|
|
|
|
case TYPE_BASIC_INT16:
|
|
|
|
case TYPE_BASIC_INT32:
|
|
|
|
case TYPE_BASIC_INT64:
|
|
|
|
case TYPE_BASIC_INT:
|
|
|
|
case TYPE_BASIC_INT3264:
|
2018-11-01 15:02:28 +01:00
|
|
|
case TYPE_BASIC_LONG:
|
2009-11-07 15:55:09 +01:00
|
|
|
case TYPE_BASIC_CHAR:
|
|
|
|
case TYPE_BASIC_HYPER:
|
|
|
|
case TYPE_BASIC_BYTE:
|
|
|
|
case TYPE_BASIC_WCHAR:
|
|
|
|
case TYPE_BASIC_ERROR_STATUS_T:
|
|
|
|
return TRUE;
|
|
|
|
case TYPE_BASIC_FLOAT:
|
|
|
|
case TYPE_BASIC_DOUBLE:
|
|
|
|
case TYPE_BASIC_HANDLE:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_new_bitfield(type_t *field, const expr_t *bits)
|
|
|
|
{
|
|
|
|
type_t *t;
|
|
|
|
|
|
|
|
if (!is_valid_bitfield_type(field))
|
|
|
|
error_loc("bit-field has invalid type\n");
|
|
|
|
|
|
|
|
if (bits->cval < 0)
|
|
|
|
error_loc("negative width for bit-field\n");
|
|
|
|
|
|
|
|
/* FIXME: validate bits->cval <= memsize(field) * 8 */
|
|
|
|
|
|
|
|
t = make_type(TYPE_BITFIELD);
|
|
|
|
t->details.bitfield.field = field;
|
|
|
|
t->details.bitfield.bits = bits;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2019-08-14 04:08:07 +02:00
|
|
|
static unsigned int compute_method_indexes(type_t *iface)
|
2008-12-29 13:05:27 +01:00
|
|
|
{
|
2019-08-14 04:08:07 +02:00
|
|
|
unsigned int idx;
|
2009-01-06 00:33:27 +01:00
|
|
|
statement_t *stmt;
|
|
|
|
|
|
|
|
if (!iface->details.iface)
|
|
|
|
return 0;
|
2008-12-29 13:05:27 +01:00
|
|
|
|
2009-01-06 00:35:06 +01:00
|
|
|
if (type_iface_get_inherit(iface))
|
|
|
|
idx = compute_method_indexes(type_iface_get_inherit(iface));
|
2008-12-29 13:05:27 +01:00
|
|
|
else
|
|
|
|
idx = 0;
|
|
|
|
|
2009-01-06 00:35:13 +01:00
|
|
|
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
|
2009-01-06 00:33:27 +01:00
|
|
|
{
|
|
|
|
var_t *func = stmt->u.var;
|
|
|
|
if (!is_callas(func->attrs))
|
2019-08-14 04:08:07 +02:00
|
|
|
func->func_idx = idx++;
|
2009-01-06 00:33:27 +01:00
|
|
|
}
|
2008-12-29 13:05:27 +01:00
|
|
|
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2021-02-05 10:11:00 +01:00
|
|
|
type_t *type_interface_declare(char *name, struct namespace *namespace)
|
2008-12-29 13:05:27 +01:00
|
|
|
{
|
2021-02-05 10:11:00 +01:00
|
|
|
type_t *type = get_type(TYPE_INTERFACE, name, namespace, 0);
|
|
|
|
if (type_get_type_detect_alias(type) != TYPE_INTERFACE)
|
|
|
|
error_loc("interface %s previously not declared an interface at %s:%d\n",
|
|
|
|
type->name, type->loc_info.input_name, type->loc_info.line_number);
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit, statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
if (iface->defined)
|
|
|
|
error_loc("interface %s already defined at %s:%d\n",
|
|
|
|
iface->name, iface->loc_info.input_name, iface->loc_info.line_number);
|
|
|
|
if (iface == inherit)
|
|
|
|
error_loc("interface %s can't inherit from itself\n",
|
|
|
|
iface->name);
|
|
|
|
iface->attrs = check_interface_attrs(iface->name, attrs);
|
2008-12-29 13:05:35 +01:00
|
|
|
iface->details.iface = xmalloc(sizeof(*iface->details.iface));
|
|
|
|
iface->details.iface->disp_props = NULL;
|
|
|
|
iface->details.iface->disp_methods = NULL;
|
2009-01-06 00:33:27 +01:00
|
|
|
iface->details.iface->stmts = stmts;
|
2009-03-05 09:22:32 +01:00
|
|
|
iface->details.iface->inherit = inherit;
|
2018-05-29 09:49:35 +02:00
|
|
|
iface->details.iface->disp_inherit = NULL;
|
2018-11-07 16:13:47 +01:00
|
|
|
iface->details.iface->async_iface = NULL;
|
2008-12-29 13:05:27 +01:00
|
|
|
iface->defined = TRUE;
|
|
|
|
compute_method_indexes(iface);
|
2021-02-05 10:11:00 +01:00
|
|
|
return iface;
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
|
|
|
|
2021-02-05 10:11:01 +01:00
|
|
|
type_t *type_dispinterface_declare(char *name)
|
2008-12-29 13:05:27 +01:00
|
|
|
{
|
2021-02-05 10:11:01 +01:00
|
|
|
type_t *type = get_type(TYPE_INTERFACE, name, NULL, 0);
|
|
|
|
if (type_get_type_detect_alias(type) != TYPE_INTERFACE)
|
|
|
|
error_loc("dispinterface %s previously not declared a dispinterface at %s:%d\n",
|
|
|
|
type->name, type->loc_info.input_name, type->loc_info.line_number);
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_dispinterface_define(type_t *iface, attr_list_t *attrs, var_list_t *props, var_list_t *methods)
|
|
|
|
{
|
|
|
|
if (iface->defined)
|
|
|
|
error_loc("dispinterface %s already defined at %s:%d\n",
|
|
|
|
iface->name, iface->loc_info.input_name, iface->loc_info.line_number);
|
|
|
|
iface->attrs = check_dispiface_attrs(iface->name, attrs);
|
2008-12-29 13:05:35 +01:00
|
|
|
iface->details.iface = xmalloc(sizeof(*iface->details.iface));
|
|
|
|
iface->details.iface->disp_props = props;
|
|
|
|
iface->details.iface->disp_methods = methods;
|
2009-01-06 00:33:27 +01:00
|
|
|
iface->details.iface->stmts = NULL;
|
2015-07-31 13:37:40 +02:00
|
|
|
iface->details.iface->inherit = find_type("IDispatch", NULL, 0);
|
2009-03-05 09:22:32 +01:00
|
|
|
if (!iface->details.iface->inherit) error_loc("IDispatch is undefined\n");
|
2018-05-29 09:49:35 +02:00
|
|
|
iface->details.iface->disp_inherit = NULL;
|
2018-11-07 16:13:47 +01:00
|
|
|
iface->details.iface->async_iface = NULL;
|
2008-12-29 13:05:27 +01:00
|
|
|
iface->defined = TRUE;
|
|
|
|
compute_method_indexes(iface);
|
2021-02-05 10:11:01 +01:00
|
|
|
return iface;
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
|
|
|
|
2021-02-05 10:11:01 +01:00
|
|
|
type_t *type_dispinterface_define_from_iface(type_t *dispiface, attr_list_t *attrs, type_t *iface)
|
2008-12-29 13:05:27 +01:00
|
|
|
{
|
2021-02-05 10:11:01 +01:00
|
|
|
if (dispiface->defined)
|
|
|
|
error_loc("dispinterface %s already defined at %s:%d\n",
|
|
|
|
dispiface->name, dispiface->loc_info.input_name, dispiface->loc_info.line_number);
|
|
|
|
dispiface->attrs = check_dispiface_attrs(dispiface->name, attrs);
|
2018-05-29 09:49:35 +02:00
|
|
|
dispiface->details.iface = xmalloc(sizeof(*dispiface->details.iface));
|
|
|
|
dispiface->details.iface->disp_props = NULL;
|
|
|
|
dispiface->details.iface->disp_methods = NULL;
|
|
|
|
dispiface->details.iface->stmts = NULL;
|
|
|
|
dispiface->details.iface->inherit = find_type("IDispatch", NULL, 0);
|
|
|
|
if (!dispiface->details.iface->inherit) error_loc("IDispatch is undefined\n");
|
|
|
|
dispiface->details.iface->disp_inherit = iface;
|
2018-11-07 16:13:47 +01:00
|
|
|
dispiface->details.iface->async_iface = NULL;
|
2018-05-29 09:49:35 +02:00
|
|
|
dispiface->defined = TRUE;
|
|
|
|
compute_method_indexes(dispiface);
|
2021-02-05 10:11:01 +01:00
|
|
|
return dispiface;
|
2008-12-29 13:05:27 +01:00
|
|
|
}
|
2009-01-06 00:33:27 +01:00
|
|
|
|
2021-02-05 10:11:03 +01:00
|
|
|
type_t *type_module_declare(char *name)
|
|
|
|
{
|
|
|
|
type_t *type = get_type(TYPE_MODULE, name, NULL, 0);
|
|
|
|
if (type_get_type_detect_alias(type) != TYPE_MODULE)
|
|
|
|
error_loc("module %s previously not declared a module at %s:%d\n",
|
|
|
|
type->name, type->loc_info.input_name, type->loc_info.line_number);
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_module_define(type_t* module, attr_list_t *attrs, statement_list_t *stmts)
|
2009-01-06 00:33:27 +01:00
|
|
|
{
|
2021-02-05 10:11:03 +01:00
|
|
|
if (module->defined)
|
|
|
|
error_loc("module %s already defined at %s:%d\n",
|
|
|
|
module->name, module->loc_info.input_name, module->loc_info.line_number);
|
|
|
|
module->attrs = check_module_attrs(module->name, attrs);
|
2009-01-06 00:33:27 +01:00
|
|
|
module->details.module = xmalloc(sizeof(*module->details.module));
|
|
|
|
module->details.module->stmts = stmts;
|
|
|
|
module->defined = TRUE;
|
2021-02-05 10:11:03 +01:00
|
|
|
return module;
|
2009-01-06 00:33:27 +01:00
|
|
|
}
|
2009-01-06 00:34:38 +01:00
|
|
|
|
2021-02-04 17:43:41 +01:00
|
|
|
type_t *type_coclass_declare(char *name)
|
|
|
|
{
|
|
|
|
type_t *type = get_type(TYPE_COCLASS, name, NULL, 0);
|
|
|
|
if (type_get_type_detect_alias(type) != TYPE_COCLASS)
|
|
|
|
error_loc("coclass %s previously not declared a coclass at %s:%d\n",
|
|
|
|
type->name, type->loc_info.input_name, type->loc_info.line_number);
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_coclass_define(type_t *coclass, attr_list_t *attrs, ifref_list_t *ifaces)
|
2009-01-06 00:34:38 +01:00
|
|
|
{
|
2021-02-04 17:43:41 +01:00
|
|
|
if (coclass->defined)
|
|
|
|
error_loc("coclass %s already defined at %s:%d\n",
|
|
|
|
coclass->name, coclass->loc_info.input_name, coclass->loc_info.line_number);
|
|
|
|
coclass->attrs = check_coclass_attrs(coclass->name, attrs);
|
2009-01-06 00:34:44 +01:00
|
|
|
coclass->details.coclass.ifaces = ifaces;
|
2009-01-06 00:34:38 +01:00
|
|
|
coclass->defined = TRUE;
|
|
|
|
return coclass;
|
|
|
|
}
|
2009-02-23 14:48:15 +01:00
|
|
|
|
2021-02-04 17:43:42 +01:00
|
|
|
type_t *type_runtimeclass_declare(char *name, struct namespace *namespace)
|
|
|
|
{
|
|
|
|
type_t *type = get_type(TYPE_RUNTIMECLASS, name, namespace, 0);
|
|
|
|
if (type_get_type_detect_alias(type) != TYPE_RUNTIMECLASS)
|
|
|
|
error_loc("runtimeclass %s previously not declared a runtimeclass at %s:%d\n",
|
|
|
|
type->name, type->loc_info.input_name, type->loc_info.line_number);
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_runtimeclass_define(type_t *runtimeclass, attr_list_t *attrs, ifref_list_t *ifaces)
|
2021-01-27 21:20:45 +01:00
|
|
|
{
|
2021-02-04 17:43:42 +01:00
|
|
|
if (runtimeclass->defined)
|
|
|
|
error_loc("runtimeclass %s already defined at %s:%d\n",
|
|
|
|
runtimeclass->name, runtimeclass->loc_info.input_name, runtimeclass->loc_info.line_number);
|
|
|
|
runtimeclass->attrs = check_runtimeclass_attrs(runtimeclass->name, attrs);
|
2021-01-27 21:20:45 +01:00
|
|
|
runtimeclass->details.runtimeclass.ifaces = ifaces;
|
|
|
|
runtimeclass->defined = TRUE;
|
|
|
|
if (!type_runtimeclass_get_default_iface(runtimeclass))
|
|
|
|
error_loc("missing default interface on runtimeclass %s\n", runtimeclass->name);
|
|
|
|
return runtimeclass;
|
|
|
|
}
|
|
|
|
|
2021-02-05 10:11:02 +01:00
|
|
|
type_t *type_apicontract_declare(char *name, struct namespace *namespace)
|
|
|
|
{
|
|
|
|
type_t *type = get_type(TYPE_APICONTRACT, name, namespace, 0);
|
|
|
|
if (type_get_type_detect_alias(type) != TYPE_APICONTRACT)
|
|
|
|
error_loc("apicontract %s previously not declared a apicontract at %s:%d\n",
|
|
|
|
type->name, type->loc_info.input_name, type->loc_info.line_number);
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_apicontract_define(type_t *apicontract, attr_list_t *attrs)
|
|
|
|
{
|
|
|
|
if (apicontract->defined)
|
|
|
|
error_loc("apicontract %s already defined at %s:%d\n",
|
|
|
|
apicontract->name, apicontract->loc_info.input_name, apicontract->loc_info.line_number);
|
|
|
|
apicontract->attrs = check_apicontract_attrs(apicontract->name, attrs);
|
|
|
|
apicontract->defined = TRUE;
|
|
|
|
return apicontract;
|
|
|
|
}
|
|
|
|
|
2009-02-23 14:48:15 +01:00
|
|
|
int type_is_equal(const type_t *type1, const type_t *type2)
|
|
|
|
{
|
|
|
|
if (type_get_type_detect_alias(type1) != type_get_type_detect_alias(type2))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (type1->name && type2->name)
|
|
|
|
return !strcmp(type1->name, type2->name);
|
|
|
|
else if ((!type1->name && type2->name) || (type1->name && !type2->name))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* FIXME: do deep inspection of types to determine if they are equal */
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|