2008-12-29 12:05:27 +00: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 13:48:15 +00:00
|
|
|
#include <string.h>
|
2008-12-29 12:05:27 +00:00
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "typetree.h"
|
|
|
|
#include "header.h"
|
|
|
|
|
2009-01-05 23:33:52 +00: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;
|
|
|
|
}
|
|
|
|
|
2008-12-29 12:05:27 +00:00
|
|
|
type_t *type_new_function(var_list_t *args)
|
|
|
|
{
|
|
|
|
type_t *t = make_type(RPC_FC_FUNCTION, NULL);
|
2008-12-29 12:05:35 +00:00
|
|
|
t->details.function = xmalloc(sizeof(*t->details.function));
|
|
|
|
t->details.function->args = args;
|
2009-01-05 23:33:27 +00:00
|
|
|
t->details.function->idx = -1;
|
2008-12-29 12:05:27 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_t *type_new_pointer(type_t *ref, attr_list_t *attrs)
|
|
|
|
{
|
|
|
|
type_t *t = make_type(pointer_default, ref);
|
|
|
|
t->attrs = attrs;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2009-01-05 23:33:52 +00:00
|
|
|
type_t *type_new_alias(type_t *t, const char *name)
|
|
|
|
{
|
2009-01-05 23:34:23 +00:00
|
|
|
type_t *a = duptype(t, 0);
|
2009-01-05 23:33:52 +00:00
|
|
|
|
2009-01-05 23:34:23 +00:00
|
|
|
a->name = xstrdup(name);
|
|
|
|
a->attrs = NULL;
|
|
|
|
a->orig = t;
|
|
|
|
a->is_alias = TRUE;
|
|
|
|
init_loc_info(&a->loc_info);
|
2009-01-05 23:33:52 +00:00
|
|
|
|
2009-01-05 23:34:23 +00:00
|
|
|
return a;
|
2009-01-05 23:33:52 +00:00
|
|
|
}
|
|
|
|
|
2009-01-05 23:34:08 +00:00
|
|
|
type_t *type_new_module(char *name)
|
|
|
|
{
|
|
|
|
type_t *type = make_type(RPC_FC_MODULE, NULL);
|
|
|
|
type->name = name;
|
|
|
|
/* FIXME: register type to detect multiple definitions */
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2009-03-05 08:21:35 +00:00
|
|
|
type_t *type_new_array(const char *name, type_t *element, int declptr,
|
2009-02-06 13:30:38 +00:00
|
|
|
unsigned int dim, expr_t *size_is, expr_t *length_is)
|
2009-01-06 23:20:59 +00:00
|
|
|
{
|
|
|
|
type_t *t = make_type(RPC_FC_LGFARRAY, element);
|
|
|
|
if (name) t->name = xstrdup(name);
|
2009-03-05 08:21:35 +00:00
|
|
|
t->details.array.declptr = declptr;
|
2009-01-06 23:20:59 +00:00
|
|
|
t->details.array.length_is = length_is;
|
|
|
|
if (size_is)
|
|
|
|
t->details.array.size_is = size_is;
|
|
|
|
else
|
|
|
|
t->details.array.dim = dim;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2009-03-05 08:21:51 +00:00
|
|
|
type_t *type_new_basic(enum type_basic_type basic_type)
|
|
|
|
{
|
|
|
|
type_t *t = make_type(TYPE_BASIC, NULL);
|
|
|
|
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)
|
|
|
|
void_type = make_type(0, NULL);
|
|
|
|
return void_type;
|
|
|
|
}
|
|
|
|
|
2008-12-29 12:05:27 +00:00
|
|
|
static int compute_method_indexes(type_t *iface)
|
|
|
|
{
|
|
|
|
int idx;
|
2009-01-05 23:33:27 +00:00
|
|
|
statement_t *stmt;
|
|
|
|
|
|
|
|
if (!iface->details.iface)
|
|
|
|
return 0;
|
2008-12-29 12:05:27 +00:00
|
|
|
|
2009-01-05 23:35:06 +00:00
|
|
|
if (type_iface_get_inherit(iface))
|
|
|
|
idx = compute_method_indexes(type_iface_get_inherit(iface));
|
2008-12-29 12:05:27 +00:00
|
|
|
else
|
|
|
|
idx = 0;
|
|
|
|
|
2009-01-05 23:35:13 +00:00
|
|
|
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
|
2009-01-05 23:33:27 +00:00
|
|
|
{
|
|
|
|
var_t *func = stmt->u.var;
|
|
|
|
if (!is_callas(func->attrs))
|
|
|
|
func->type->details.function->idx = idx++;
|
|
|
|
}
|
2008-12-29 12:05:27 +00:00
|
|
|
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2008-12-29 12:06:35 +00:00
|
|
|
void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts)
|
2008-12-29 12:05:27 +00:00
|
|
|
{
|
|
|
|
iface->ref = inherit;
|
2008-12-29 12:05:35 +00:00
|
|
|
iface->details.iface = xmalloc(sizeof(*iface->details.iface));
|
|
|
|
iface->details.iface->disp_props = NULL;
|
|
|
|
iface->details.iface->disp_methods = NULL;
|
2009-01-05 23:33:27 +00:00
|
|
|
iface->details.iface->stmts = stmts;
|
2008-12-29 12:05:27 +00:00
|
|
|
iface->defined = TRUE;
|
|
|
|
compute_method_indexes(iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods)
|
|
|
|
{
|
|
|
|
iface->ref = find_type("IDispatch", 0);
|
|
|
|
if (!iface->ref) error_loc("IDispatch is undefined\n");
|
2008-12-29 12:05:35 +00:00
|
|
|
iface->details.iface = xmalloc(sizeof(*iface->details.iface));
|
|
|
|
iface->details.iface->disp_props = props;
|
|
|
|
iface->details.iface->disp_methods = methods;
|
2009-01-05 23:33:27 +00:00
|
|
|
iface->details.iface->stmts = NULL;
|
2008-12-29 12:05:27 +00:00
|
|
|
iface->defined = TRUE;
|
|
|
|
compute_method_indexes(iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface)
|
|
|
|
{
|
2008-12-29 12:05:35 +00:00
|
|
|
type_dispinterface_define(dispiface, iface->details.iface->disp_props,
|
|
|
|
iface->details.iface->disp_methods);
|
2008-12-29 12:05:27 +00:00
|
|
|
}
|
2009-01-05 23:33:27 +00:00
|
|
|
|
|
|
|
void type_module_define(type_t *module, statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
if (module->details.module) error_loc("multiple definition error\n");
|
|
|
|
module->details.module = xmalloc(sizeof(*module->details.module));
|
|
|
|
module->details.module->stmts = stmts;
|
|
|
|
module->defined = TRUE;
|
|
|
|
}
|
2009-01-05 23:34:38 +00:00
|
|
|
|
|
|
|
type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces)
|
|
|
|
{
|
2009-01-05 23:34:44 +00:00
|
|
|
coclass->details.coclass.ifaces = ifaces;
|
2009-01-05 23:34:38 +00:00
|
|
|
coclass->defined = TRUE;
|
|
|
|
return coclass;
|
|
|
|
}
|
2009-02-23 13:48:15 +00: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;
|
|
|
|
}
|