wined3d: Disable WINED3DFMT_D16_LOCKABLE on backbuffer ORM.
[wine.git] / tools / widl / typetree.c
blob591a58b28493739847fe7c0d8bb6fce79c991afe
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"
32 #include "hash.h"
34 type_t *duptype(type_t *t, int dupname)
36 type_t *d = alloc_type();
38 *d = *t;
39 if (dupname && t->name)
40 d->name = xstrdup(t->name);
42 return d;
45 type_t *make_type(enum type_type type)
47 type_t *t = alloc_type();
48 t->name = NULL;
49 t->namespace = NULL;
50 t->type_type = type;
51 t->attrs = NULL;
52 t->c_name = NULL;
53 t->signature = NULL;
54 t->qualified_name = NULL;
55 t->impl_name = NULL;
56 t->short_name = NULL;
57 memset(&t->details, 0, sizeof(t->details));
58 t->typestring_offset = 0;
59 t->ptrdesc = 0;
60 t->ignore = (parse_only != 0);
61 t->defined = FALSE;
62 t->written = FALSE;
63 t->user_types_registered = FALSE;
64 t->tfswrite = FALSE;
65 t->checked = FALSE;
66 t->typelib_idx = -1;
67 init_loc_info(&t->loc_info);
68 return t;
71 static const var_t *find_arg(const var_list_t *args, const char *name)
73 const var_t *arg;
75 if (args) LIST_FOR_EACH_ENTRY(arg, args, const var_t, entry)
77 if (arg->name && !strcmp(name, arg->name))
78 return arg;
81 return NULL;
84 const char *type_get_name(const type_t *type, enum name_type name_type)
86 switch(name_type) {
87 case NAME_DEFAULT:
88 return type->name;
89 case NAME_C:
90 return type->c_name ? type->c_name : type->name;
93 assert(0);
94 return NULL;
97 const char *type_get_qualified_name(const type_t *type, enum name_type name_type)
99 switch(name_type) {
100 case NAME_DEFAULT:
101 return type->qualified_name;
102 case NAME_C:
103 return type->c_name;
106 assert(0);
107 return NULL;
110 static size_t append_namespace(char **buf, size_t *len, size_t pos, struct namespace *namespace, const char *separator, const char *abi_prefix)
112 int nested = namespace && !is_global_namespace(namespace);
113 const char *name = nested ? namespace->name : abi_prefix;
114 size_t n = 0;
115 if (!name) return 0;
116 if (nested) n += append_namespace(buf, len, pos + n, namespace->parent, separator, abi_prefix);
117 n += strappend(buf, len, pos + n, "%s%s", name, separator);
118 return n;
121 static size_t append_namespaces(char **buf, size_t *len, size_t pos, struct namespace *namespace, const char *prefix,
122 const char *separator, const char *suffix, const char *abi_prefix)
124 int nested = namespace && !is_global_namespace(namespace);
125 size_t n = 0;
126 n += strappend(buf, len, pos + n, "%s", prefix);
127 if (nested) n += append_namespace(buf, len, pos + n, namespace, separator, abi_prefix);
128 if (suffix) n += strappend(buf, len, pos + n, "%s", suffix);
129 else if (nested)
131 n -= strlen(separator);
132 (*buf)[n] = 0;
134 return n;
137 static size_t append_pointer_stars(char **buf, size_t *len, size_t pos, type_t *type)
139 size_t n = 0;
140 for (; type && type->type_type == TYPE_POINTER; type = type_pointer_get_ref_type(type)) n += strappend(buf, len, pos + n, "*");
141 return n;
144 static size_t append_type_signature(char **buf, size_t *len, size_t pos, type_t *type);
146 static size_t append_var_list_signature(char **buf, size_t *len, size_t pos, var_list_t *var_list)
148 var_t *var;
149 size_t n = 0;
151 if (!var_list) n += strappend(buf, len, pos + n, ";");
152 else LIST_FOR_EACH_ENTRY(var, var_list, var_t, entry)
154 n += strappend(buf, len, pos + n, ";");
155 n += append_type_signature(buf, len, pos + n, var->declspec.type);
158 return n;
161 static size_t append_type_signature(char **buf, size_t *len, size_t pos, type_t *type)
163 const GUID *uuid;
164 size_t n = 0;
166 if (!type) return 0;
167 switch (type->type_type)
169 case TYPE_INTERFACE:
170 if (type->signature) n += strappend(buf, len, pos + n, "%s", type->signature);
171 else
173 if (!(uuid = get_attrp(type->attrs, ATTR_UUID)))
174 error_loc_info(&type->loc_info, "cannot compute type signature, no uuid found for type %s.\n", type->name);
176 n += strappend(buf, len, pos + n, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
177 uuid->Data1, uuid->Data2, uuid->Data3,
178 uuid->Data4[0], uuid->Data4[1], uuid->Data4[2], uuid->Data4[3],
179 uuid->Data4[4], uuid->Data4[5], uuid->Data4[6], uuid->Data4[7]);
181 return n;
182 case TYPE_DELEGATE:
183 n += strappend(buf, len, pos + n, "delegate(");
184 n += append_type_signature(buf, len, pos + n, type_delegate_get_iface(type));
185 n += strappend(buf, len, pos + n, ")");
186 return n;
187 case TYPE_RUNTIMECLASS:
188 n += strappend(buf, len, pos + n, "rc(");
189 n += append_namespaces(buf, len, pos + n, type->namespace, "", ".", type->name, NULL);
190 n += strappend(buf, len, pos + n, ";");
191 n += append_type_signature(buf, len, pos + n, type_runtimeclass_get_default_iface(type));
192 n += strappend(buf, len, pos + n, ")");
193 return n;
194 case TYPE_POINTER:
195 n += append_type_signature(buf, len, pos + n, type->details.pointer.ref.type);
196 return n;
197 case TYPE_ALIAS:
198 if (!strcmp(type->name, "boolean")) n += strappend(buf, len, pos + n, "b1");
199 else n += append_type_signature(buf, len, pos + n, type->details.alias.aliasee.type);
200 return n;
201 case TYPE_STRUCT:
202 n += strappend(buf, len, pos + n, "struct(");
203 n += append_namespaces(buf, len, pos + n, type->namespace, "", ".", type->name, NULL);
204 n += append_var_list_signature(buf, len, pos + n, type->details.structure->fields);
205 n += strappend(buf, len, pos + n, ")");
206 return n;
207 case TYPE_BASIC:
208 switch (type_basic_get_type(type))
210 case TYPE_BASIC_INT:
211 case TYPE_BASIC_INT32:
212 n += strappend(buf, len, pos + n, type_basic_get_sign(type) < 0 ? "i4" : "u4");
213 return n;
214 case TYPE_BASIC_INT64:
215 n += strappend(buf, len, pos + n, type_basic_get_sign(type) < 0 ? "i8" : "u8");
216 return n;
217 case TYPE_BASIC_INT8:
218 assert(type_basic_get_sign(type) >= 0); /* signature string for signed char isn't specified */
219 n += strappend(buf, len, pos + n, "u1");
220 return n;
221 case TYPE_BASIC_FLOAT:
222 n += strappend(buf, len, pos + n, "f4");
223 return n;
224 case TYPE_BASIC_DOUBLE:
225 n += strappend(buf, len, pos + n, "f8");
226 return n;
227 case TYPE_BASIC_INT16:
228 case TYPE_BASIC_INT3264:
229 case TYPE_BASIC_LONG:
230 case TYPE_BASIC_CHAR:
231 case TYPE_BASIC_HYPER:
232 case TYPE_BASIC_BYTE:
233 case TYPE_BASIC_WCHAR:
234 case TYPE_BASIC_ERROR_STATUS_T:
235 case TYPE_BASIC_HANDLE:
236 error_loc_info(&type->loc_info, "unimplemented type signature for basic type %d.\n", type_basic_get_type(type));
237 break;
239 case TYPE_ENUM:
240 n += strappend(buf, len, pos + n, "enum(");
241 n += append_namespaces(buf, len, pos + n, type->namespace, "", ".", type->name, NULL);
242 if (is_attr(type->attrs, ATTR_FLAGS)) n += strappend(buf, len, pos + n, ";u4");
243 else n += strappend(buf, len, pos + n, ";i4");
244 n += strappend(buf, len, pos + n, ")");
245 return n;
246 case TYPE_ARRAY:
247 case TYPE_ENCAPSULATED_UNION:
248 case TYPE_UNION:
249 case TYPE_COCLASS:
250 case TYPE_VOID:
251 case TYPE_FUNCTION:
252 case TYPE_BITFIELD:
253 case TYPE_MODULE:
254 case TYPE_APICONTRACT:
255 error_loc_info(&type->loc_info, "unimplemented type signature for type %s of type %d.\n", type->name, type->type_type);
256 break;
257 case TYPE_PARAMETERIZED_TYPE:
258 case TYPE_PARAMETER:
259 assert(0); /* should not be there */
260 break;
263 return n;
266 char *format_namespace(struct namespace *namespace, const char *prefix, const char *separator, const char *suffix, const char *abi_prefix)
268 size_t len = 0;
269 char *buf = NULL;
270 append_namespaces(&buf, &len, 0, namespace, prefix, separator, suffix, abi_prefix);
271 return buf;
274 char *format_parameterized_type_name(type_t *type, typeref_list_t *params)
276 size_t len = 0, pos = 0;
277 char *buf = NULL;
278 typeref_t *ref;
280 pos += strappend(&buf, &len, pos, "%s<", type->name);
281 if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
283 type = type_pointer_get_root_type(ref->type);
284 pos += strappend(&buf, &len, pos, "%s", type->qualified_name);
285 pos += append_pointer_stars(&buf, &len, pos, ref->type);
286 if (list_next(params, &ref->entry)) pos += strappend(&buf, &len, pos, ",");
288 pos += strappend(&buf, &len, pos, " >");
290 return buf;
293 static char const *parameterized_type_shorthands[][2] = {
294 {"Windows_CFoundation_CCollections_C", "__F"},
295 {"Windows_CFoundation_C", "__F"},
298 static char *format_parameterized_type_c_name(type_t *type, typeref_list_t *params, const char *prefix)
300 size_t len = 0, pos = 0;
301 char *buf = NULL, *tmp;
302 int i, count = params ? list_count(params) : 0;
303 typeref_t *ref;
305 pos += append_namespaces(&buf, &len, pos, type->namespace, "__x_", "_C", "", use_abi_namespace ? "ABI" : NULL);
306 pos += strappend(&buf, &len, pos, "%s%s_%d", prefix, type->name, count);
307 if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
309 type = type_pointer_get_root_type(ref->type);
310 pos += append_namespaces(&buf, &len, pos, type->namespace, "_", "__C", type->name, NULL);
313 for (i = 0; i < ARRAY_SIZE(parameterized_type_shorthands); ++i)
315 if ((tmp = strstr(buf, parameterized_type_shorthands[i][0])) &&
316 (tmp - buf) == strlen(use_abi_namespace ? "__x_ABI_C" : "__x_C"))
318 tmp += strlen(parameterized_type_shorthands[i][0]);
319 strcpy(buf, parameterized_type_shorthands[i][1]);
320 memmove(buf + 3, tmp, len - (tmp - buf));
324 return buf;
327 static char *format_parameterized_type_signature(type_t *type, typeref_list_t *params)
329 size_t len = 0, pos = 0;
330 char *buf = NULL;
331 typeref_t *ref;
332 const GUID *uuid;
334 if (!(uuid = get_attrp(type->attrs, ATTR_UUID)))
335 error_loc_info(&type->loc_info, "cannot compute type signature, no uuid found for type %s.\n", type->name);
337 pos += strappend(&buf, &len, pos, "pinterface({%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
338 uuid->Data1, uuid->Data2, uuid->Data3,
339 uuid->Data4[0], uuid->Data4[1], uuid->Data4[2], uuid->Data4[3],
340 uuid->Data4[4], uuid->Data4[5], uuid->Data4[6], uuid->Data4[7]);
341 if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
343 pos += strappend(&buf, &len, pos, ";");
344 pos += append_type_signature(&buf, &len, pos, ref->type);
346 pos += strappend(&buf, &len, pos, ")");
348 return buf;
351 static char *format_parameterized_type_short_name(type_t *type, typeref_list_t *params, const char *prefix)
353 size_t len = 0, pos = 0;
354 char *buf = NULL;
355 typeref_t *ref;
357 pos += strappend(&buf, &len, pos, "%s%s", prefix, type->name);
358 if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
360 type = type_pointer_get_root_type(ref->type);
361 pos += strappend(&buf, &len, pos, "_%s", type->name);
364 return buf;
367 static char *format_parameterized_type_impl_name(type_t *type, typeref_list_t *params, const char *prefix)
369 size_t len = 0, pos = 0;
370 char *buf = NULL;
371 typeref_t *ref;
372 type_t *iface;
374 pos += strappend(&buf, &len, pos, "%s%s_impl<", prefix, type->name);
375 if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
377 type = type_pointer_get_root_type(ref->type);
378 if (type->type_type == TYPE_RUNTIMECLASS)
380 pos += strappend(&buf, &len, pos, "ABI::Windows::Foundation::Internal::AggregateType<%s", type->qualified_name);
381 pos += append_pointer_stars(&buf, &len, pos, ref->type);
382 iface = type_runtimeclass_get_default_iface(type);
383 pos += strappend(&buf, &len, pos, ", %s", iface->qualified_name);
384 pos += append_pointer_stars(&buf, &len, pos, ref->type);
385 pos += strappend(&buf, &len, pos, " >");
387 else
389 pos += strappend(&buf, &len, pos, "%s", type->qualified_name);
390 pos += append_pointer_stars(&buf, &len, pos, ref->type);
392 if (list_next(params, &ref->entry)) pos += strappend(&buf, &len, pos, ", ");
394 pos += strappend(&buf, &len, pos, " >");
396 return buf;
399 type_t *type_new_function(var_list_t *args)
401 var_t *arg;
402 type_t *t;
403 unsigned int i = 0;
405 if (args)
407 arg = LIST_ENTRY(list_head(args), var_t, entry);
408 if (list_count(args) == 1 && !arg->name && arg->declspec.type && type_get_type(arg->declspec.type) == TYPE_VOID)
410 list_remove(&arg->entry);
411 free(arg);
412 free(args);
413 args = NULL;
416 if (args) LIST_FOR_EACH_ENTRY(arg, args, var_t, entry)
418 if (arg->declspec.type && type_get_type(arg->declspec.type) == TYPE_VOID)
419 error_loc("argument '%s' has void type\n", arg->name);
420 if (!arg->name)
422 if (i > 26 * 26)
423 error_loc("too many unnamed arguments\n");
424 else
426 int unique;
429 char name[3];
430 name[0] = i > 26 ? 'a' + i / 26 : 'a' + i;
431 name[1] = i > 26 ? 'a' + i % 26 : 0;
432 name[2] = 0;
433 unique = !find_arg(args, name);
434 if (unique)
435 arg->name = xstrdup(name);
436 i++;
437 } while (!unique);
442 t = make_type(TYPE_FUNCTION);
443 t->details.function = xmalloc(sizeof(*t->details.function));
444 t->details.function->args = args;
445 t->details.function->retval = make_var(xstrdup("_RetVal"));
446 return t;
449 type_t *type_new_pointer(type_t *ref)
451 type_t *t = make_type(TYPE_POINTER);
452 t->details.pointer.ref.type = ref;
453 return t;
456 type_t *type_new_alias(const decl_spec_t *t, const char *name)
458 type_t *a = make_type(TYPE_ALIAS);
460 a->name = xstrdup(name);
461 a->attrs = NULL;
462 a->details.alias.aliasee = *t;
463 init_loc_info(&a->loc_info);
465 return a;
468 type_t *type_new_array(const char *name, const decl_spec_t *element, int declptr,
469 unsigned int dim, expr_t *size_is, expr_t *length_is)
471 type_t *t = make_type(TYPE_ARRAY);
472 if (name) t->name = xstrdup(name);
473 t->details.array.declptr = declptr;
474 t->details.array.length_is = length_is;
475 if (size_is)
476 t->details.array.size_is = size_is;
477 else
478 t->details.array.dim = dim;
479 if (element)
480 t->details.array.elem = *element;
481 return t;
484 type_t *type_new_basic(enum type_basic_type basic_type)
486 type_t *t = make_type(TYPE_BASIC);
487 t->details.basic.type = basic_type;
488 t->details.basic.sign = 0;
489 return t;
492 type_t *type_new_int(enum type_basic_type basic_type, int sign)
494 static type_t *int_types[TYPE_BASIC_INT_MAX+1][3];
496 assert(basic_type <= TYPE_BASIC_INT_MAX);
498 /* map sign { -1, 0, 1 } -> { 0, 1, 2 } */
499 if (!int_types[basic_type][sign + 1])
501 int_types[basic_type][sign + 1] = type_new_basic(basic_type);
502 int_types[basic_type][sign + 1]->details.basic.sign = sign;
504 return int_types[basic_type][sign + 1];
507 type_t *type_new_void(void)
509 static type_t *void_type = NULL;
510 if (!void_type)
511 void_type = make_type(TYPE_VOID);
512 return void_type;
515 type_t *type_new_enum(const char *name, struct namespace *namespace, int defined, var_list_t *enums)
517 type_t *t = NULL;
519 if (name)
520 t = find_type(name, namespace,tsENUM);
522 if (!t)
524 t = make_type(TYPE_ENUM);
525 t->name = name;
526 t->namespace = namespace;
527 if (name)
528 reg_type(t, name, namespace, tsENUM);
531 if (!t->defined && defined)
533 t->details.enumeration = xmalloc(sizeof(*t->details.enumeration));
534 t->details.enumeration->enums = enums;
535 t->defined = TRUE;
537 else if (defined)
538 error_loc("redefinition of enum %s\n", name);
540 return t;
543 type_t *type_new_struct(char *name, struct namespace *namespace, int defined, var_list_t *fields)
545 type_t *t = NULL;
547 if (name)
548 t = find_type(name, namespace, tsSTRUCT);
550 if (!t)
552 t = make_type(TYPE_STRUCT);
553 t->name = name;
554 t->namespace = namespace;
555 if (name)
556 reg_type(t, name, namespace, tsSTRUCT);
559 if (!t->defined && defined)
561 t->details.structure = xmalloc(sizeof(*t->details.structure));
562 t->details.structure->fields = fields;
563 t->defined = TRUE;
565 else if (defined)
566 error_loc("redefinition of struct %s\n", name);
568 return t;
571 type_t *type_new_nonencapsulated_union(const char *name, int defined, var_list_t *fields)
573 type_t *t = NULL;
575 if (name)
576 t = find_type(name, NULL, tsUNION);
578 if (!t)
580 t = make_type(TYPE_UNION);
581 t->name = name;
582 if (name)
583 reg_type(t, name, NULL, tsUNION);
586 if (!t->defined && defined)
588 t->details.structure = xmalloc(sizeof(*t->details.structure));
589 t->details.structure->fields = fields;
590 t->defined = TRUE;
592 else if (defined)
593 error_loc("redefinition of union %s\n", name);
595 return t;
598 type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases)
600 type_t *t = NULL;
602 if (name)
603 t = find_type(name, NULL, tsUNION);
605 if (!t)
607 t = make_type(TYPE_ENCAPSULATED_UNION);
608 t->name = name;
609 if (name)
610 reg_type(t, name, NULL, tsUNION);
612 t->type_type = TYPE_ENCAPSULATED_UNION;
614 if (!t->defined)
616 if (!union_field)
617 union_field = make_var(xstrdup("tagged_union"));
618 union_field->declspec.type = type_new_nonencapsulated_union(gen_name(), TRUE, cases);
620 t->details.structure = xmalloc(sizeof(*t->details.structure));
621 t->details.structure->fields = append_var(NULL, switch_field);
622 t->details.structure->fields = append_var(t->details.structure->fields, union_field);
623 t->defined = TRUE;
625 else
626 error_loc("redefinition of union %s\n", name);
628 return t;
631 static int is_valid_bitfield_type(const type_t *type)
633 switch (type_get_type(type))
635 case TYPE_ENUM:
636 return TRUE;
637 case TYPE_BASIC:
638 switch (type_basic_get_type(type))
640 case TYPE_BASIC_INT8:
641 case TYPE_BASIC_INT16:
642 case TYPE_BASIC_INT32:
643 case TYPE_BASIC_INT64:
644 case TYPE_BASIC_INT:
645 case TYPE_BASIC_INT3264:
646 case TYPE_BASIC_LONG:
647 case TYPE_BASIC_CHAR:
648 case TYPE_BASIC_HYPER:
649 case TYPE_BASIC_BYTE:
650 case TYPE_BASIC_WCHAR:
651 case TYPE_BASIC_ERROR_STATUS_T:
652 return TRUE;
653 case TYPE_BASIC_FLOAT:
654 case TYPE_BASIC_DOUBLE:
655 case TYPE_BASIC_HANDLE:
656 return FALSE;
658 return FALSE;
659 default:
660 return FALSE;
664 type_t *type_new_bitfield(type_t *field, const expr_t *bits)
666 type_t *t;
668 if (!is_valid_bitfield_type(field))
669 error_loc("bit-field has invalid type\n");
671 if (bits->cval < 0)
672 error_loc("negative width for bit-field\n");
674 /* FIXME: validate bits->cval <= memsize(field) * 8 */
676 t = make_type(TYPE_BITFIELD);
677 t->details.bitfield.field = field;
678 t->details.bitfield.bits = bits;
679 return t;
682 static unsigned int compute_method_indexes(type_t *iface)
684 unsigned int idx;
685 statement_t *stmt;
687 if (!iface->details.iface)
688 return 0;
690 if (type_iface_get_inherit(iface))
691 idx = compute_method_indexes(type_iface_get_inherit(iface));
692 else
693 idx = 0;
695 STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
697 var_t *func = stmt->u.var;
698 if (!is_callas(func->attrs))
699 func->func_idx = idx++;
702 return idx;
705 type_t *type_interface_declare(char *name, struct namespace *namespace)
707 type_t *type = get_type(TYPE_INTERFACE, name, namespace, 0);
708 if (type_get_type_detect_alias(type) != TYPE_INTERFACE)
709 error_loc("interface %s previously not declared an interface at %s:%d\n",
710 type->name, type->loc_info.input_name, type->loc_info.line_number);
711 return type;
714 type_t *type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit, statement_list_t *stmts, typeref_list_t *requires)
716 if (iface->defined)
717 error_loc("interface %s already defined at %s:%d\n",
718 iface->name, iface->loc_info.input_name, iface->loc_info.line_number);
719 if (iface == inherit)
720 error_loc("interface %s can't inherit from itself\n",
721 iface->name);
722 iface->attrs = check_interface_attrs(iface->name, attrs);
723 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
724 iface->details.iface->disp_props = NULL;
725 iface->details.iface->disp_methods = NULL;
726 iface->details.iface->stmts = stmts;
727 iface->details.iface->inherit = inherit;
728 iface->details.iface->disp_inherit = NULL;
729 iface->details.iface->async_iface = NULL;
730 iface->details.iface->requires = requires;
731 iface->defined = TRUE;
732 compute_method_indexes(iface);
733 return iface;
736 type_t *type_dispinterface_declare(char *name)
738 type_t *type = get_type(TYPE_INTERFACE, name, NULL, 0);
739 if (type_get_type_detect_alias(type) != TYPE_INTERFACE)
740 error_loc("dispinterface %s previously not declared a dispinterface at %s:%d\n",
741 type->name, type->loc_info.input_name, type->loc_info.line_number);
742 return type;
745 type_t *type_dispinterface_define(type_t *iface, attr_list_t *attrs, var_list_t *props, var_list_t *methods)
747 if (iface->defined)
748 error_loc("dispinterface %s already defined at %s:%d\n",
749 iface->name, iface->loc_info.input_name, iface->loc_info.line_number);
750 iface->attrs = check_dispiface_attrs(iface->name, attrs);
751 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
752 iface->details.iface->disp_props = props;
753 iface->details.iface->disp_methods = methods;
754 iface->details.iface->stmts = NULL;
755 iface->details.iface->inherit = find_type("IDispatch", NULL, 0);
756 if (!iface->details.iface->inherit) error_loc("IDispatch is undefined\n");
757 iface->details.iface->disp_inherit = NULL;
758 iface->details.iface->async_iface = NULL;
759 iface->details.iface->requires = NULL;
760 iface->defined = TRUE;
761 compute_method_indexes(iface);
762 return iface;
765 type_t *type_dispinterface_define_from_iface(type_t *dispiface, attr_list_t *attrs, type_t *iface)
767 if (dispiface->defined)
768 error_loc("dispinterface %s already defined at %s:%d\n",
769 dispiface->name, dispiface->loc_info.input_name, dispiface->loc_info.line_number);
770 dispiface->attrs = check_dispiface_attrs(dispiface->name, attrs);
771 dispiface->details.iface = xmalloc(sizeof(*dispiface->details.iface));
772 dispiface->details.iface->disp_props = NULL;
773 dispiface->details.iface->disp_methods = NULL;
774 dispiface->details.iface->stmts = NULL;
775 dispiface->details.iface->inherit = find_type("IDispatch", NULL, 0);
776 if (!dispiface->details.iface->inherit) error_loc("IDispatch is undefined\n");
777 dispiface->details.iface->disp_inherit = iface;
778 dispiface->details.iface->async_iface = NULL;
779 dispiface->details.iface->requires = NULL;
780 dispiface->defined = TRUE;
781 compute_method_indexes(dispiface);
782 return dispiface;
785 type_t *type_module_declare(char *name)
787 type_t *type = get_type(TYPE_MODULE, name, NULL, 0);
788 if (type_get_type_detect_alias(type) != TYPE_MODULE)
789 error_loc("module %s previously not declared a module at %s:%d\n",
790 type->name, type->loc_info.input_name, type->loc_info.line_number);
791 return type;
794 type_t *type_module_define(type_t* module, attr_list_t *attrs, statement_list_t *stmts)
796 if (module->defined)
797 error_loc("module %s already defined at %s:%d\n",
798 module->name, module->loc_info.input_name, module->loc_info.line_number);
799 module->attrs = check_module_attrs(module->name, attrs);
800 module->details.module = xmalloc(sizeof(*module->details.module));
801 module->details.module->stmts = stmts;
802 module->defined = TRUE;
803 return module;
806 type_t *type_coclass_declare(char *name)
808 type_t *type = get_type(TYPE_COCLASS, name, NULL, 0);
809 if (type_get_type_detect_alias(type) != TYPE_COCLASS)
810 error_loc("coclass %s previously not declared a coclass at %s:%d\n",
811 type->name, type->loc_info.input_name, type->loc_info.line_number);
812 return type;
815 type_t *type_coclass_define(type_t *coclass, attr_list_t *attrs, typeref_list_t *ifaces)
817 if (coclass->defined)
818 error_loc("coclass %s already defined at %s:%d\n",
819 coclass->name, coclass->loc_info.input_name, coclass->loc_info.line_number);
820 coclass->attrs = check_coclass_attrs(coclass->name, attrs);
821 coclass->details.coclass.ifaces = ifaces;
822 coclass->defined = TRUE;
823 return coclass;
826 type_t *type_runtimeclass_declare(char *name, struct namespace *namespace)
828 type_t *type = get_type(TYPE_RUNTIMECLASS, name, namespace, 0);
829 if (type_get_type_detect_alias(type) != TYPE_RUNTIMECLASS)
830 error_loc("runtimeclass %s previously not declared a runtimeclass at %s:%d\n",
831 type->name, type->loc_info.input_name, type->loc_info.line_number);
832 return type;
835 type_t *type_runtimeclass_define(type_t *runtimeclass, attr_list_t *attrs, typeref_list_t *ifaces)
837 typeref_t *ref, *required, *tmp;
838 typeref_list_t *requires;
840 if (runtimeclass->defined)
841 error_loc("runtimeclass %s already defined at %s:%d\n",
842 runtimeclass->name, runtimeclass->loc_info.input_name, runtimeclass->loc_info.line_number);
843 runtimeclass->attrs = check_runtimeclass_attrs(runtimeclass->name, attrs);
844 runtimeclass->details.runtimeclass.ifaces = ifaces;
845 runtimeclass->defined = TRUE;
846 if (!type_runtimeclass_get_default_iface(runtimeclass))
847 error_loc("missing default interface on runtimeclass %s\n", runtimeclass->name);
849 LIST_FOR_EACH_ENTRY(ref, ifaces, typeref_t, entry)
851 /* FIXME: this should probably not be allowed, here or in coclass, */
852 /* but for now there's too many places in Wine IDL where it is to */
853 /* even print a warning. */
854 if (!(ref->type->defined)) continue;
855 if (!(requires = type_iface_get_requires(ref->type))) continue;
856 LIST_FOR_EACH_ENTRY(required, requires, typeref_t, entry)
858 int found = 0;
860 LIST_FOR_EACH_ENTRY(tmp, ifaces, typeref_t, entry)
861 if ((found = type_is_equal(tmp->type, required->type))) break;
863 if (!found)
864 error_loc("interface '%s' also requires interface '%s', "
865 "but runtimeclass '%s' does not implement it.\n",
866 ref->type->name, required->type->name, runtimeclass->name);
870 return runtimeclass;
873 type_t *type_apicontract_declare(char *name, struct namespace *namespace)
875 type_t *type = get_type(TYPE_APICONTRACT, name, namespace, 0);
876 if (type_get_type_detect_alias(type) != TYPE_APICONTRACT)
877 error_loc("apicontract %s previously not declared a apicontract at %s:%d\n",
878 type->name, type->loc_info.input_name, type->loc_info.line_number);
879 return type;
882 type_t *type_apicontract_define(type_t *apicontract, attr_list_t *attrs)
884 if (apicontract->defined)
885 error_loc("apicontract %s already defined at %s:%d\n",
886 apicontract->name, apicontract->loc_info.input_name, apicontract->loc_info.line_number);
887 apicontract->attrs = check_apicontract_attrs(apicontract->name, attrs);
888 apicontract->defined = TRUE;
889 return apicontract;
892 static void compute_delegate_iface_names(type_t *delegate, type_t *type, typeref_list_t *params)
894 type_t *iface = delegate->details.delegate.iface;
895 iface->namespace = delegate->namespace;
896 iface->name = strmake("I%s", delegate->name);
897 if (type) iface->c_name = format_parameterized_type_c_name(type, params, "I");
898 else iface->c_name = format_namespace(delegate->namespace, "__x_", "_C", iface->name, use_abi_namespace ? "ABI" : NULL);
899 iface->qualified_name = format_namespace(delegate->namespace, "", "::", iface->name, use_abi_namespace ? "ABI" : NULL);
902 type_t *type_delegate_declare(char *name, struct namespace *namespace)
904 type_t *type = get_type(TYPE_DELEGATE, name, namespace, 0);
905 if (type_get_type_detect_alias(type) != TYPE_DELEGATE)
906 error_loc("delegate %s previously not declared a delegate at %s:%d\n",
907 type->name, type->loc_info.input_name, type->loc_info.line_number);
908 return type;
911 type_t *type_delegate_define(type_t *delegate, attr_list_t *attrs, statement_list_t *stmts)
913 type_t *iface;
915 if (delegate->defined)
916 error_loc("delegate %s already defined at %s:%d\n",
917 delegate->name, delegate->loc_info.input_name, delegate->loc_info.line_number);
919 delegate->attrs = check_interface_attrs(delegate->name, attrs);
921 iface = make_type(TYPE_INTERFACE);
922 iface->attrs = delegate->attrs;
923 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
924 iface->details.iface->disp_props = NULL;
925 iface->details.iface->disp_methods = NULL;
926 iface->details.iface->stmts = stmts;
927 iface->details.iface->inherit = find_type("IUnknown", NULL, 0);
928 if (!iface->details.iface->inherit) error_loc("IUnknown is undefined\n");
929 iface->details.iface->disp_inherit = NULL;
930 iface->details.iface->async_iface = NULL;
931 iface->details.iface->requires = NULL;
932 iface->defined = TRUE;
933 compute_method_indexes(iface);
935 delegate->details.delegate.iface = iface;
936 delegate->defined = TRUE;
937 compute_delegate_iface_names(delegate, NULL, NULL);
939 return delegate;
942 type_t *type_parameterized_interface_declare(char *name, struct namespace *namespace, typeref_list_t *params)
944 type_t *type = get_type(TYPE_PARAMETERIZED_TYPE, name, namespace, 0);
945 if (type_get_type_detect_alias(type) != TYPE_PARAMETERIZED_TYPE)
946 error_loc("pinterface %s previously not declared a pinterface at %s:%d\n",
947 type->name, type->loc_info.input_name, type->loc_info.line_number);
948 type->details.parameterized.type = make_type(TYPE_INTERFACE);
949 type->details.parameterized.params = params;
950 return type;
953 type_t *type_parameterized_interface_define(type_t *type, attr_list_t *attrs, type_t *inherit, statement_list_t *stmts, typeref_list_t *requires)
955 type_t *iface;
956 if (type->defined)
957 error_loc("pinterface %s already defined at %s:%d\n",
958 type->name, type->loc_info.input_name, type->loc_info.line_number);
960 /* The parameterized type UUID is actually a PIID that is then used as a seed to generate
961 * a new type GUID with the rules described in:
962 * https://docs.microsoft.com/en-us/uwp/winrt-cref/winrt-type-system#parameterized-types
963 * TODO: store type signatures for generated interfaces, and generate their GUIDs
965 type->attrs = check_interface_attrs(type->name, attrs);
967 iface = type->details.parameterized.type;
968 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
969 iface->details.iface->disp_props = NULL;
970 iface->details.iface->disp_methods = NULL;
971 iface->details.iface->stmts = stmts;
972 iface->details.iface->inherit = inherit;
973 iface->details.iface->disp_inherit = NULL;
974 iface->details.iface->async_iface = NULL;
975 iface->details.iface->requires = requires;
977 iface->name = type->name;
979 type->defined = TRUE;
980 return type;
983 type_t *type_parameterized_delegate_declare(char *name, struct namespace *namespace, typeref_list_t *params)
985 type_t *type = get_type(TYPE_PARAMETERIZED_TYPE, name, namespace, 0);
986 if (type_get_type_detect_alias(type) != TYPE_PARAMETERIZED_TYPE)
987 error_loc("pdelegate %s previously not declared a pdelegate at %s:%d\n",
988 type->name, type->loc_info.input_name, type->loc_info.line_number);
989 type->details.parameterized.type = make_type(TYPE_DELEGATE);
990 type->details.parameterized.params = params;
991 return type;
994 type_t *type_parameterized_delegate_define(type_t *type, attr_list_t *attrs, statement_list_t *stmts)
996 type_t *iface, *delegate;
998 if (type->defined)
999 error_loc("pdelegate %s already defined at %s:%d\n",
1000 type->name, type->loc_info.input_name, type->loc_info.line_number);
1002 type->attrs = check_interface_attrs(type->name, attrs);
1004 delegate = type->details.parameterized.type;
1005 delegate->attrs = type->attrs;
1006 delegate->details.delegate.iface = make_type(TYPE_INTERFACE);
1008 iface = delegate->details.delegate.iface;
1009 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
1010 iface->details.iface->disp_props = NULL;
1011 iface->details.iface->disp_methods = NULL;
1012 iface->details.iface->stmts = stmts;
1013 iface->details.iface->inherit = find_type("IUnknown", NULL, 0);
1014 if (!iface->details.iface->inherit) error_loc("IUnknown is undefined\n");
1015 iface->details.iface->disp_inherit = NULL;
1016 iface->details.iface->async_iface = NULL;
1017 iface->details.iface->requires = NULL;
1019 delegate->name = type->name;
1020 compute_delegate_iface_names(delegate, type, type->details.parameterized.params);
1022 type->defined = TRUE;
1023 return type;
1026 type_t *type_parameterized_type_specialize_partial(type_t *type, typeref_list_t *params)
1028 type_t *new_type = duptype(type, 0);
1029 new_type->details.parameterized.type = type;
1030 new_type->details.parameterized.params = params;
1031 return new_type;
1034 static type_t *replace_type_parameters_in_type(type_t *type, typeref_list_t *orig, typeref_list_t *repl);
1036 static typeref_list_t *replace_type_parameters_in_type_list(typeref_list_t *list, typeref_list_t *orig, typeref_list_t *repl)
1038 typeref_list_t *new_list = NULL;
1039 typeref_t *ref;
1041 if (!list) return list;
1043 LIST_FOR_EACH_ENTRY(ref, list, typeref_t, entry)
1045 type_t *new_type = replace_type_parameters_in_type(ref->type, orig, repl);
1046 new_list = append_typeref(new_list, make_typeref(new_type));
1049 return new_list;
1052 static var_t *replace_type_parameters_in_var(var_t *var, typeref_list_t *orig, typeref_list_t *repl)
1054 var_t *new_var = xmalloc(sizeof(*new_var));
1055 *new_var = *var;
1056 list_init(&new_var->entry);
1057 new_var->declspec.type = replace_type_parameters_in_type(var->declspec.type, orig, repl);
1058 return new_var;
1061 static var_list_t *replace_type_parameters_in_var_list(var_list_t *var_list, typeref_list_t *orig, typeref_list_t *repl)
1063 var_list_t *new_var_list;
1064 var_t *var, *new_var;
1066 if (!var_list) return var_list;
1068 new_var_list = xmalloc(sizeof(*new_var_list));
1069 list_init(new_var_list);
1071 LIST_FOR_EACH_ENTRY(var, var_list, var_t, entry)
1073 new_var = replace_type_parameters_in_var(var, orig, repl);
1074 list_add_tail(new_var_list, &new_var->entry);
1077 return new_var_list;
1080 static statement_t *replace_type_parameters_in_statement(statement_t *stmt, typeref_list_t *orig, typeref_list_t *repl, loc_info_t *loc)
1082 statement_t *new_stmt = xmalloc(sizeof(*new_stmt));
1083 *new_stmt = *stmt;
1084 list_init(&new_stmt->entry);
1086 switch (stmt->type)
1088 case STMT_DECLARATION:
1089 new_stmt->u.var = replace_type_parameters_in_var(stmt->u.var, orig, repl);
1090 break;
1091 case STMT_TYPE:
1092 case STMT_TYPEREF:
1093 new_stmt->u.type = replace_type_parameters_in_type(stmt->u.type, orig, repl);
1094 break;
1095 case STMT_TYPEDEF:
1096 new_stmt->u.type_list = replace_type_parameters_in_type_list(stmt->u.type_list, orig, repl);
1097 break;
1098 case STMT_MODULE:
1099 case STMT_LIBRARY:
1100 case STMT_IMPORT:
1101 case STMT_IMPORTLIB:
1102 case STMT_PRAGMA:
1103 case STMT_CPPQUOTE:
1104 error_loc_info(loc, "unimplemented parameterized type replacement for statement type %d.\n", stmt->type);
1105 break;
1108 return new_stmt;
1111 static statement_list_t *replace_type_parameters_in_statement_list(statement_list_t *stmt_list, typeref_list_t *orig, typeref_list_t *repl, loc_info_t *loc)
1113 statement_list_t *new_stmt_list;
1114 statement_t *stmt, *new_stmt;
1116 if (!stmt_list) return stmt_list;
1118 new_stmt_list = xmalloc(sizeof(*new_stmt_list));
1119 list_init(new_stmt_list);
1121 LIST_FOR_EACH_ENTRY(stmt, stmt_list, statement_t, entry)
1123 new_stmt = replace_type_parameters_in_statement(stmt, orig, repl, loc);
1124 list_add_tail(new_stmt_list, &new_stmt->entry);
1127 return new_stmt_list;
1130 static type_t *replace_type_parameters_in_type(type_t *type, typeref_list_t *orig, typeref_list_t *repl)
1132 struct list *o, *r;
1133 type_t *t;
1135 if (!type) return type;
1136 switch (type->type_type)
1138 case TYPE_VOID:
1139 case TYPE_BASIC:
1140 case TYPE_ENUM:
1141 case TYPE_BITFIELD:
1142 case TYPE_INTERFACE:
1143 case TYPE_RUNTIMECLASS:
1144 case TYPE_DELEGATE:
1145 return type;
1146 case TYPE_PARAMETER:
1147 if (!orig || !repl) return NULL;
1148 for (o = list_head(orig), r = list_head(repl); o && r;
1149 o = list_next(orig, o), r = list_next(repl, r))
1150 if (type == LIST_ENTRY(o, typeref_t, entry)->type)
1151 return LIST_ENTRY(r, typeref_t, entry)->type;
1152 return type;
1153 case TYPE_POINTER:
1154 t = replace_type_parameters_in_type(type->details.pointer.ref.type, orig, repl);
1155 if (t == type->details.pointer.ref.type) return type;
1156 type = duptype(type, 0);
1157 type->details.pointer.ref.type = t;
1158 return type;
1159 case TYPE_ALIAS:
1160 t = replace_type_parameters_in_type(type->details.alias.aliasee.type, orig, repl);
1161 if (t == type->details.alias.aliasee.type) return type;
1162 type = duptype(type, 0);
1163 type->details.alias.aliasee.type = t;
1164 return type;
1165 case TYPE_ARRAY:
1166 t = replace_type_parameters_in_type(type->details.array.elem.type, orig, repl);
1167 if (t == t->details.array.elem.type) return type;
1168 type = duptype(type, 0);
1169 t->details.array.elem.type = t;
1170 return type;
1171 case TYPE_FUNCTION:
1172 t = duptype(type, 0);
1173 t->details.function = xmalloc(sizeof(*t->details.function));
1174 t->details.function->args = replace_type_parameters_in_var_list(type->details.function->args, orig, repl);
1175 t->details.function->retval = replace_type_parameters_in_var(type->details.function->retval, orig, repl);
1176 return t;
1177 case TYPE_PARAMETERIZED_TYPE:
1178 t = type->details.parameterized.type;
1179 if (t->type_type != TYPE_PARAMETERIZED_TYPE) return find_parameterized_type(type, repl);
1180 repl = replace_type_parameters_in_type_list(type->details.parameterized.params, orig, repl);
1181 return replace_type_parameters_in_type(t, t->details.parameterized.params, repl);
1182 case TYPE_STRUCT:
1183 case TYPE_ENCAPSULATED_UNION:
1184 case TYPE_UNION:
1185 case TYPE_MODULE:
1186 case TYPE_COCLASS:
1187 case TYPE_APICONTRACT:
1188 error_loc_info(&type->loc_info, "unimplemented parameterized type replacement for type %s of type %d.\n", type->name, type->type_type);
1189 break;
1192 return type;
1195 static void type_parameterized_interface_specialize(type_t *tmpl, type_t *iface, typeref_list_t *orig, typeref_list_t *repl)
1197 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
1198 iface->details.iface->disp_methods = NULL;
1199 iface->details.iface->disp_props = NULL;
1200 iface->details.iface->stmts = replace_type_parameters_in_statement_list(tmpl->details.iface->stmts, orig, repl, &tmpl->loc_info);
1201 iface->details.iface->inherit = replace_type_parameters_in_type(tmpl->details.iface->inherit, orig, repl);
1202 iface->details.iface->disp_inherit = NULL;
1203 iface->details.iface->async_iface = NULL;
1204 iface->details.iface->requires = NULL;
1207 static void type_parameterized_delegate_specialize(type_t *tmpl, type_t *delegate, typeref_list_t *orig, typeref_list_t *repl)
1209 type_parameterized_interface_specialize(tmpl->details.delegate.iface, delegate->details.delegate.iface, orig, repl);
1212 type_t *type_parameterized_type_specialize_declare(type_t *type, typeref_list_t *params)
1214 type_t *tmpl = type->details.parameterized.type;
1215 type_t *new_type = duptype(tmpl, 0);
1217 new_type->namespace = type->namespace;
1218 new_type->name = format_parameterized_type_name(type, params);
1219 reg_type(new_type, new_type->name, new_type->namespace, 0);
1220 new_type->c_name = format_parameterized_type_c_name(type, params, "");
1221 new_type->short_name = format_parameterized_type_short_name(type, params, "");
1223 if (new_type->type_type == TYPE_DELEGATE)
1225 new_type->details.delegate.iface = duptype(tmpl->details.delegate.iface, 0);
1226 compute_delegate_iface_names(new_type, type, params);
1227 new_type->details.delegate.iface->short_name = format_parameterized_type_short_name(type, params, "I");
1230 return new_type;
1233 static void compute_interface_signature_uuid(type_t *iface)
1235 static const char winrt_pinterface_namespace[] = {0x11,0xf4,0x7a,0xd5,0x7b,0x73,0x42,0xc0,0xab,0xae,0x87,0x8b,0x1e,0x16,0xad,0xee};
1236 static const int version = 5;
1237 struct sha1_context ctx;
1238 unsigned char hash[20];
1239 GUID *uuid;
1241 if (!(uuid = get_attrp(iface->attrs, ATTR_UUID)))
1243 uuid = xmalloc(sizeof(GUID));
1244 iface->attrs = append_attr(iface->attrs, make_attrp(ATTR_UUID, uuid));
1247 sha1_init(&ctx);
1248 sha1_update(&ctx, winrt_pinterface_namespace, sizeof(winrt_pinterface_namespace));
1249 sha1_update(&ctx, iface->signature, strlen(iface->signature));
1250 sha1_finalize(&ctx, (ULONG *)hash);
1252 /* https://tools.ietf.org/html/rfc4122:
1254 * Set the four most significant bits (bits 12 through 15) of the
1255 time_hi_and_version field to the appropriate 4-bit version number
1256 from Section 4.1.3.
1258 * Set the two most significant bits (bits 6 and 7) of the
1259 clock_seq_hi_and_reserved to zero and one, respectively.
1262 hash[6] = ((hash[6] & 0x0f) | (version << 4));
1263 hash[8] = ((hash[8] & 0x3f) | 0x80);
1265 uuid->Data1 = ((DWORD)hash[0] << 24)|((DWORD)hash[1] << 16)|((DWORD)hash[2] << 8)|(DWORD)hash[3];
1266 uuid->Data2 = ((WORD)hash[4] << 8)|(WORD)hash[5];
1267 uuid->Data3 = ((WORD)hash[6] << 8)|(WORD)hash[7];
1268 memcpy(&uuid->Data4, hash + 8, sizeof(*uuid) - offsetof(GUID, Data4));
1271 type_t *type_parameterized_type_specialize_define(type_t *type)
1273 type_t *tmpl = type->details.parameterized.type;
1274 typeref_list_t *orig = tmpl->details.parameterized.params;
1275 typeref_list_t *repl = type->details.parameterized.params;
1276 type_t *iface = find_parameterized_type(tmpl, repl);
1278 if (type_get_type_detect_alias(type) != TYPE_PARAMETERIZED_TYPE ||
1279 type_get_type_detect_alias(tmpl) != TYPE_PARAMETERIZED_TYPE)
1280 error_loc("cannot define non-parameterized type %s, declared at %s:%d\n",
1281 type->name, type->loc_info.input_name, type->loc_info.line_number);
1283 if (type_get_type_detect_alias(tmpl->details.parameterized.type) == TYPE_INTERFACE &&
1284 type_get_type_detect_alias(iface) == TYPE_INTERFACE)
1285 type_parameterized_interface_specialize(tmpl->details.parameterized.type, iface, orig, repl);
1286 else if (type_get_type_detect_alias(tmpl->details.parameterized.type) == TYPE_DELEGATE &&
1287 type_get_type_detect_alias(iface) == TYPE_DELEGATE)
1288 type_parameterized_delegate_specialize(tmpl->details.parameterized.type, iface, orig, repl);
1289 else
1290 error_loc("pinterface/pdelegate %s previously not declared a pinterface/pdelegate at %s:%d\n",
1291 iface->name, iface->loc_info.input_name, iface->loc_info.line_number);
1293 iface->impl_name = format_parameterized_type_impl_name(type, repl, "");
1294 iface->signature = format_parameterized_type_signature(type, repl);
1295 iface->defined = TRUE;
1296 if (iface->type_type == TYPE_DELEGATE)
1298 iface = iface->details.delegate.iface;
1299 iface->impl_name = format_parameterized_type_impl_name(type, repl, "I");
1300 iface->signature = format_parameterized_type_signature(type, repl);
1301 iface->defined = TRUE;
1303 compute_interface_signature_uuid(iface);
1304 compute_method_indexes(iface);
1305 return iface;
1308 int type_is_equal(const type_t *type1, const type_t *type2)
1310 if (type1 == type2)
1311 return TRUE;
1312 if (type_get_type_detect_alias(type1) != type_get_type_detect_alias(type2))
1313 return FALSE;
1314 if (type1->namespace != type2->namespace)
1315 return FALSE;
1317 if (type1->name && type2->name)
1318 return !strcmp(type1->name, type2->name);
1319 else if ((!type1->name && type2->name) || (type1->name && !type2->name))
1320 return FALSE;
1322 /* FIXME: do deep inspection of types to determine if they are equal */
1324 return FALSE;