widl: Move declarray property to array_details.
[wine/wine-gecko.git] / tools / widl / typetree.c
blobd11c0a62247fd1cd81df5ef94d1d3f20afd9ad96
1 /*
2 * IDL Type Tree
4 * Copyright 2008 Robert Shearman
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.
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.
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
21 #include "config.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "widl.h"
28 #include "utils.h"
29 #include "parser.h"
30 #include "typetree.h"
31 #include "header.h"
33 type_t *duptype(type_t *t, int dupname)
35 type_t *d = alloc_type();
37 *d = *t;
38 if (dupname && t->name)
39 d->name = xstrdup(t->name);
41 return d;
44 type_t *type_new_function(var_list_t *args)
46 type_t *t = make_type(RPC_FC_FUNCTION, NULL);
47 t->details.function = xmalloc(sizeof(*t->details.function));
48 t->details.function->args = args;
49 t->details.function->idx = -1;
50 return t;
53 type_t *type_new_pointer(type_t *ref, attr_list_t *attrs)
55 type_t *t = make_type(pointer_default, ref);
56 t->attrs = attrs;
57 return t;
60 type_t *type_new_alias(type_t *t, const char *name)
62 type_t *a = duptype(t, 0);
64 a->name = xstrdup(name);
65 a->attrs = NULL;
66 a->orig = t;
67 a->is_alias = TRUE;
68 init_loc_info(&a->loc_info);
70 return a;
73 type_t *type_new_module(char *name)
75 type_t *type = make_type(RPC_FC_MODULE, NULL);
76 type->name = name;
77 /* FIXME: register type to detect multiple definitions */
78 return type;
81 type_t *type_new_array(const char *name, type_t *element, int declptr,
82 unsigned int dim, expr_t *size_is, expr_t *length_is)
84 type_t *t = make_type(RPC_FC_LGFARRAY, element);
85 if (name) t->name = xstrdup(name);
86 t->details.array.declptr = declptr;
87 t->details.array.length_is = length_is;
88 if (size_is)
89 t->details.array.size_is = size_is;
90 else
91 t->details.array.dim = dim;
92 return t;
95 static int compute_method_indexes(type_t *iface)
97 int idx;
98 statement_t *stmt;
100 if (!iface->details.iface)
101 return 0;
103 if (type_iface_get_inherit(iface))
104 idx = compute_method_indexes(type_iface_get_inherit(iface));
105 else
106 idx = 0;
108 STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
110 var_t *func = stmt->u.var;
111 if (!is_callas(func->attrs))
112 func->type->details.function->idx = idx++;
115 return idx;
118 void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts)
120 iface->ref = inherit;
121 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
122 iface->details.iface->disp_props = NULL;
123 iface->details.iface->disp_methods = NULL;
124 iface->details.iface->stmts = stmts;
125 iface->defined = TRUE;
126 compute_method_indexes(iface);
129 void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods)
131 iface->ref = find_type("IDispatch", 0);
132 if (!iface->ref) error_loc("IDispatch is undefined\n");
133 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
134 iface->details.iface->disp_props = props;
135 iface->details.iface->disp_methods = methods;
136 iface->details.iface->stmts = NULL;
137 iface->defined = TRUE;
138 compute_method_indexes(iface);
141 void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface)
143 type_dispinterface_define(dispiface, iface->details.iface->disp_props,
144 iface->details.iface->disp_methods);
147 void type_module_define(type_t *module, statement_list_t *stmts)
149 if (module->details.module) error_loc("multiple definition error\n");
150 module->details.module = xmalloc(sizeof(*module->details.module));
151 module->details.module->stmts = stmts;
152 module->defined = TRUE;
155 type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces)
157 coclass->details.coclass.ifaces = ifaces;
158 coclass->defined = TRUE;
159 return coclass;
162 int type_is_equal(const type_t *type1, const type_t *type2)
164 if (type_get_type_detect_alias(type1) != type_get_type_detect_alias(type2))
165 return FALSE;
167 if (type1->name && type2->name)
168 return !strcmp(type1->name, type2->name);
169 else if ((!type1->name && type2->name) || (type1->name && !type2->name))
170 return FALSE;
172 /* FIXME: do deep inspection of types to determine if they are equal */
174 return FALSE;