makedep: Don't add dependencies for tests of disabled dlls.
[wine.git] / tools / widl / typetree.c
blobee71a7a289940e517f9d255bfb7aa7f5219d5a19
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->param_name = NULL;
57 t->short_name = NULL;
58 memset(&t->details, 0, sizeof(t->details));
59 t->typestring_offset = 0;
60 t->ptrdesc = 0;
61 t->ignore = (parse_only != 0);
62 t->defined = FALSE;
63 t->written = FALSE;
64 t->user_types_registered = FALSE;
65 t->tfswrite = FALSE;
66 t->checked = FALSE;
67 t->typelib_idx = -1;
68 init_loc_info(&t->loc_info);
69 return t;
72 static const var_t *find_arg(const var_list_t *args, const char *name)
74 const var_t *arg;
76 if (args) LIST_FOR_EACH_ENTRY(arg, args, const var_t, entry)
78 if (arg->name && !strcmp(name, arg->name))
79 return arg;
82 return NULL;
85 const char *type_get_decl_name(const type_t *type, enum name_type name_type)
87 switch(name_type) {
88 case NAME_DEFAULT:
89 return type->name;
90 case NAME_C:
91 return type->c_name ? type->c_name : type->name;
94 assert(0);
95 return NULL;
98 const char *type_get_name(const type_t *type, enum name_type name_type)
100 switch(name_type) {
101 case NAME_DEFAULT:
102 return type->qualified_name ? type->qualified_name : type->name;
103 case NAME_C:
104 return type->c_name ? type->c_name : type->name;
107 assert(0);
108 return NULL;
111 static size_t append_namespace(char **buf, size_t *len, size_t pos, struct namespace *namespace, const char *separator, const char *abi_prefix)
113 int nested = namespace && !is_global_namespace(namespace);
114 const char *name = nested ? namespace->name : abi_prefix;
115 size_t n = 0;
116 if (!name) return 0;
117 if (nested) n += append_namespace(buf, len, pos + n, namespace->parent, separator, abi_prefix);
118 n += strappend(buf, len, pos + n, "%s%s", name, separator);
119 return n;
122 static size_t append_namespaces(char **buf, size_t *len, size_t pos, struct namespace *namespace, const char *prefix,
123 const char *separator, const char *suffix, const char *abi_prefix)
125 int nested = namespace && !is_global_namespace(namespace);
126 size_t n = 0;
127 n += strappend(buf, len, pos + n, "%s", prefix);
128 if (nested) n += append_namespace(buf, len, pos + n, namespace, separator, abi_prefix);
129 if (suffix) n += strappend(buf, len, pos + n, "%s", suffix);
130 else if (nested)
132 n -= strlen(separator);
133 (*buf)[n] = 0;
135 return n;
138 static size_t append_pointer_stars(char **buf, size_t *len, size_t pos, type_t *type)
140 size_t n = 0;
141 for (; type && type->type_type == TYPE_POINTER; type = type_pointer_get_ref_type(type)) n += strappend(buf, len, pos + n, "*");
142 return n;
145 static size_t append_type_signature(char **buf, size_t *len, size_t pos, type_t *type);
147 static size_t append_var_list_signature(char **buf, size_t *len, size_t pos, var_list_t *var_list)
149 var_t *var;
150 size_t n = 0;
152 if (!var_list) n += strappend(buf, len, pos + n, ";");
153 else LIST_FOR_EACH_ENTRY(var, var_list, var_t, entry)
155 n += strappend(buf, len, pos + n, ";");
156 n += append_type_signature(buf, len, pos + n, var->declspec.type);
159 return n;
162 static size_t append_type_signature(char **buf, size_t *len, size_t pos, type_t *type)
164 const struct uuid *uuid;
165 size_t n = 0;
167 if (!type) return 0;
168 switch (type->type_type)
170 case TYPE_INTERFACE:
171 if (!strcmp(type->name, "IInspectable")) n += strappend(buf, len, pos + n, "cinterface(IInspectable)");
172 else if (type->signature) n += strappend(buf, len, pos + n, "%s", type->signature);
173 else
175 if (!(uuid = get_attrp(type->attrs, ATTR_UUID)))
176 error_loc_info(&type->loc_info, "cannot compute type signature, no uuid found for type %s.\n", type->name);
178 n += strappend(buf, len, pos + n, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
179 uuid->Data1, uuid->Data2, uuid->Data3,
180 uuid->Data4[0], uuid->Data4[1], uuid->Data4[2], uuid->Data4[3],
181 uuid->Data4[4], uuid->Data4[5], uuid->Data4[6], uuid->Data4[7]);
183 return n;
184 case TYPE_DELEGATE:
185 n += strappend(buf, len, pos + n, "delegate(");
186 n += append_type_signature(buf, len, pos + n, type_delegate_get_iface(type));
187 n += strappend(buf, len, pos + n, ")");
188 return n;
189 case TYPE_RUNTIMECLASS:
190 n += strappend(buf, len, pos + n, "rc(");
191 n += append_namespaces(buf, len, pos + n, type->namespace, "", ".", type->name, NULL);
192 n += strappend(buf, len, pos + n, ";");
193 n += append_type_signature(buf, len, pos + n, type_runtimeclass_get_default_iface(type, TRUE));
194 n += strappend(buf, len, pos + n, ")");
195 return n;
196 case TYPE_POINTER:
197 n += append_type_signature(buf, len, pos + n, type->details.pointer.ref.type);
198 return n;
199 case TYPE_ALIAS:
200 if (!strcmp(type->name, "boolean")) n += strappend(buf, len, pos + n, "b1");
201 else if (!strcmp(type->name, "HSTRING")) n += strappend(buf, len, pos + n, "string");
202 else n += append_type_signature(buf, len, pos + n, type->details.alias.aliasee.type);
203 return n;
204 case TYPE_STRUCT:
205 n += strappend(buf, len, pos + n, "struct(");
206 n += append_namespaces(buf, len, pos + n, type->namespace, "", ".", type->name, NULL);
207 n += append_var_list_signature(buf, len, pos + n, type->details.structure->fields);
208 n += strappend(buf, len, pos + n, ")");
209 return n;
210 case TYPE_BASIC:
211 switch (type_basic_get_type(type))
213 case TYPE_BASIC_INT:
214 case TYPE_BASIC_INT32:
215 n += strappend(buf, len, pos + n, type_basic_get_sign(type) <= 0 ? "i4" : "u4");
216 return n;
217 case TYPE_BASIC_INT64:
218 n += strappend(buf, len, pos + n, type_basic_get_sign(type) <= 0 ? "i8" : "u8");
219 return n;
220 case TYPE_BASIC_INT8:
221 assert(type_basic_get_sign(type) > 0); /* signature string for signed char isn't specified */
222 n += strappend(buf, len, pos + n, "u1");
223 return n;
224 case TYPE_BASIC_FLOAT:
225 n += strappend(buf, len, pos + n, "f4");
226 return n;
227 case TYPE_BASIC_DOUBLE:
228 n += strappend(buf, len, pos + n, "f8");
229 return n;
230 case TYPE_BASIC_BYTE:
231 n += strappend(buf, len, pos + n, "u1");
232 return n;
233 case TYPE_BASIC_INT16:
234 case TYPE_BASIC_INT3264:
235 case TYPE_BASIC_LONG:
236 case TYPE_BASIC_CHAR:
237 case TYPE_BASIC_HYPER:
238 case TYPE_BASIC_WCHAR:
239 case TYPE_BASIC_ERROR_STATUS_T:
240 case TYPE_BASIC_HANDLE:
241 error_loc_info(&type->loc_info, "unimplemented type signature for basic type %d.\n", type_basic_get_type(type));
242 break;
244 case TYPE_ENUM:
245 n += strappend(buf, len, pos + n, "enum(");
246 n += append_namespaces(buf, len, pos + n, type->namespace, "", ".", type->name, NULL);
247 if (is_attr(type->attrs, ATTR_FLAGS)) n += strappend(buf, len, pos + n, ";u4");
248 else n += strappend(buf, len, pos + n, ";i4");
249 n += strappend(buf, len, pos + n, ")");
250 return n;
251 case TYPE_ARRAY:
252 case TYPE_ENCAPSULATED_UNION:
253 case TYPE_UNION:
254 case TYPE_COCLASS:
255 case TYPE_VOID:
256 case TYPE_FUNCTION:
257 case TYPE_BITFIELD:
258 case TYPE_MODULE:
259 case TYPE_APICONTRACT:
260 error_loc_info(&type->loc_info, "unimplemented type signature for type %s of type %d.\n", type->name, type->type_type);
261 break;
262 case TYPE_PARAMETERIZED_TYPE:
263 case TYPE_PARAMETER:
264 assert(0); /* should not be there */
265 break;
268 return n;
271 char *format_namespace(struct namespace *namespace, const char *prefix, const char *separator, const char *suffix, const char *abi_prefix)
273 size_t len = 0;
274 char *buf = NULL;
275 append_namespaces(&buf, &len, 0, namespace, prefix, separator, suffix, abi_prefix);
276 return buf;
279 char *format_parameterized_type_name(type_t *type, typeref_list_t *params)
281 size_t len = 0, pos = 0;
282 char *buf = NULL;
283 typeref_t *ref;
285 pos += strappend(&buf, &len, pos, "%s<", type->name);
286 if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
288 type = type_pointer_get_root_type(ref->type);
289 pos += strappend(&buf, &len, pos, "%s", type->qualified_name);
290 pos += append_pointer_stars(&buf, &len, pos, ref->type);
291 if (list_next(params, &ref->entry)) pos += strappend(&buf, &len, pos, ",");
293 pos += strappend(&buf, &len, pos, " >");
295 return buf;
298 static char const *parameterized_type_shorthands[][2] = {
299 {"Windows__CFoundation__CCollections__C", "__F"},
300 {"Windows_CFoundation_CCollections_C", "__F"},
301 {"Windows__CFoundation__C", "__F"},
302 {"Windows_CFoundation_C", "__F"},
305 static char *format_parameterized_type_c_name(type_t *type, typeref_list_t *params, const char *prefix, const char *separator)
307 const char *tmp, *ns_prefix = "__x_", *abi_prefix = NULL;
308 size_t len = 0, pos = 0;
309 char *buf = NULL;
310 int i, count = params ? list_count(params) : 0;
311 typeref_t *ref;
313 if (!strcmp(separator, "__C")) ns_prefix = "_C";
314 else if (use_abi_namespace) abi_prefix = "ABI";
316 pos += append_namespaces(&buf, &len, pos, type->namespace, ns_prefix, separator, "", abi_prefix);
317 pos += strappend(&buf, &len, pos, "%s%s_%d", prefix, type->name, count);
318 if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
320 type = type_pointer_get_root_type(ref->type);
321 if ((tmp = type->param_name)) pos += strappend(&buf, &len, pos, "_%s", tmp);
322 else pos += append_namespaces(&buf, &len, pos, type->namespace, "_", "__C", type->name, NULL);
325 for (i = 0; i < ARRAY_SIZE(parameterized_type_shorthands); ++i)
327 if ((tmp = strstr(buf, parameterized_type_shorthands[i][0])) &&
328 (tmp - buf) == strlen(ns_prefix) + (abi_prefix ? 5 : 0))
330 tmp += strlen(parameterized_type_shorthands[i][0]);
331 strcpy(buf, parameterized_type_shorthands[i][1]);
332 memmove(buf + 3, tmp, len - (tmp - buf));
336 return buf;
339 static char *format_parameterized_type_signature(type_t *type, typeref_list_t *params)
341 size_t len = 0, pos = 0;
342 char *buf = NULL;
343 typeref_t *ref;
344 const struct uuid *uuid;
346 if (!(uuid = get_attrp(type->attrs, ATTR_UUID)))
347 error_loc_info(&type->loc_info, "cannot compute type signature, no uuid found for type %s.\n", type->name);
349 pos += strappend(&buf, &len, pos, "pinterface({%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
350 uuid->Data1, uuid->Data2, uuid->Data3,
351 uuid->Data4[0], uuid->Data4[1], uuid->Data4[2], uuid->Data4[3],
352 uuid->Data4[4], uuid->Data4[5], uuid->Data4[6], uuid->Data4[7]);
353 if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
355 pos += strappend(&buf, &len, pos, ";");
356 pos += append_type_signature(&buf, &len, pos, ref->type);
358 pos += strappend(&buf, &len, pos, ")");
360 return buf;
363 static char *format_parameterized_type_short_name(type_t *type, typeref_list_t *params, const char *prefix)
365 size_t len = 0, pos = 0;
366 char *buf = NULL;
367 typeref_t *ref;
369 pos += strappend(&buf, &len, pos, "%s%s", prefix, type->name);
370 if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
372 type = type_pointer_get_root_type(ref->type);
373 if (type->short_name) pos += strappend(&buf, &len, pos, "_%s", type->short_name);
374 else pos += strappend(&buf, &len, pos, "_%s", type->name);
377 return buf;
380 static char *format_parameterized_type_impl_name(type_t *type, typeref_list_t *params, const char *prefix)
382 size_t len = 0, pos = 0;
383 char *buf = NULL;
384 typeref_t *ref;
385 type_t *iface;
387 pos += strappend(&buf, &len, pos, "%s%s_impl<", prefix, type->name);
388 if (params) LIST_FOR_EACH_ENTRY(ref, params, typeref_t, entry)
390 type = type_pointer_get_root_type(ref->type);
391 if (type->type_type == TYPE_RUNTIMECLASS)
393 pos += strappend(&buf, &len, pos, "ABI::Windows::Foundation::Internal::AggregateType<%s", type->qualified_name);
394 pos += append_pointer_stars(&buf, &len, pos, ref->type);
395 iface = type_runtimeclass_get_default_iface(type, TRUE);
396 pos += strappend(&buf, &len, pos, ", %s", iface->qualified_name);
397 pos += append_pointer_stars(&buf, &len, pos, ref->type);
398 pos += strappend(&buf, &len, pos, " >");
400 else
402 pos += strappend(&buf, &len, pos, "%s", type->qualified_name);
403 pos += append_pointer_stars(&buf, &len, pos, ref->type);
405 if (list_next(params, &ref->entry)) pos += strappend(&buf, &len, pos, ", ");
407 pos += strappend(&buf, &len, pos, " >");
409 return buf;
412 type_t *type_new_function(var_list_t *args)
414 var_t *arg;
415 type_t *t;
416 unsigned int i = 0;
418 if (args)
420 arg = LIST_ENTRY(list_head(args), var_t, entry);
421 if (list_count(args) == 1 && !arg->name && arg->declspec.type && type_get_type(arg->declspec.type) == TYPE_VOID)
423 list_remove(&arg->entry);
424 free(arg);
425 free(args);
426 args = NULL;
429 if (args) LIST_FOR_EACH_ENTRY(arg, args, var_t, entry)
431 if (arg->declspec.type && type_get_type(arg->declspec.type) == TYPE_VOID)
432 error_loc("argument '%s' has void type\n", arg->name);
433 if (!arg->name)
435 if (i > 26 * 26)
436 error_loc("too many unnamed arguments\n");
437 else
439 int unique;
442 char name[3];
443 name[0] = i > 26 ? 'a' + i / 26 : 'a' + i;
444 name[1] = i > 26 ? 'a' + i % 26 : 0;
445 name[2] = 0;
446 unique = !find_arg(args, name);
447 if (unique)
448 arg->name = xstrdup(name);
449 i++;
450 } while (!unique);
455 t = make_type(TYPE_FUNCTION);
456 t->details.function = xmalloc(sizeof(*t->details.function));
457 t->details.function->args = args;
458 t->details.function->retval = make_var(xstrdup("_RetVal"));
459 return t;
462 type_t *type_new_pointer(type_t *ref)
464 type_t *t = make_type(TYPE_POINTER);
465 t->details.pointer.ref.type = ref;
466 return t;
469 type_t *type_new_alias(const decl_spec_t *t, const char *name)
471 type_t *a = make_type(TYPE_ALIAS);
473 a->name = xstrdup(name);
474 a->attrs = NULL;
475 a->details.alias.aliasee = *t;
476 init_loc_info(&a->loc_info);
478 return a;
481 type_t *type_new_array(const char *name, const decl_spec_t *element, int declptr,
482 unsigned int dim, expr_t *size_is, expr_t *length_is)
484 type_t *t = make_type(TYPE_ARRAY);
485 if (name) t->name = xstrdup(name);
486 t->details.array.declptr = declptr;
487 t->details.array.length_is = length_is;
488 if (size_is)
489 t->details.array.size_is = size_is;
490 else
491 t->details.array.dim = dim;
492 if (element)
493 t->details.array.elem = *element;
494 return t;
497 type_t *type_new_basic(enum type_basic_type basic_type)
499 type_t *t = make_type(TYPE_BASIC);
500 t->details.basic.type = basic_type;
501 t->details.basic.sign = 0;
502 return t;
505 type_t *type_new_int(enum type_basic_type basic_type, int sign)
507 static type_t *int_types[TYPE_BASIC_INT_MAX+1][3];
509 assert(basic_type <= TYPE_BASIC_INT_MAX);
511 /* map sign { -1, 0, 1 } -> { 0, 1, 2 } */
512 if (!int_types[basic_type][sign + 1])
514 int_types[basic_type][sign + 1] = type_new_basic(basic_type);
515 int_types[basic_type][sign + 1]->details.basic.sign = sign;
517 return int_types[basic_type][sign + 1];
520 type_t *type_new_void(void)
522 static type_t *void_type = NULL;
523 if (!void_type)
524 void_type = make_type(TYPE_VOID);
525 return void_type;
528 type_t *type_new_enum(const char *name, struct namespace *namespace, int defined, var_list_t *enums)
530 type_t *t = NULL;
532 if (name)
533 t = find_type(name, namespace,tsENUM);
535 if (!t)
537 t = make_type(TYPE_ENUM);
538 t->name = name;
539 t->namespace = namespace;
540 if (name)
541 reg_type(t, name, namespace, tsENUM);
544 if (!t->defined && defined)
546 t->details.enumeration = xmalloc(sizeof(*t->details.enumeration));
547 t->details.enumeration->enums = enums;
548 t->defined = TRUE;
550 else if (defined)
551 error_loc("redefinition of enum %s\n", name);
553 return t;
556 type_t *type_new_struct(char *name, struct namespace *namespace, int defined, var_list_t *fields)
558 type_t *t = NULL;
560 if (name)
561 t = find_type(name, namespace, tsSTRUCT);
563 if (!t)
565 t = make_type(TYPE_STRUCT);
566 t->name = name;
567 t->namespace = namespace;
568 if (name)
569 reg_type(t, name, namespace, tsSTRUCT);
572 if (!t->defined && defined)
574 t->details.structure = xmalloc(sizeof(*t->details.structure));
575 t->details.structure->fields = fields;
576 t->defined = TRUE;
578 else if (defined)
579 error_loc("redefinition of struct %s\n", name);
581 return t;
584 type_t *type_new_nonencapsulated_union(const char *name, struct namespace *namespace, int defined, var_list_t *fields)
586 type_t *t = NULL;
588 if (name)
589 t = find_type(name, namespace, tsUNION);
591 if (!t)
593 t = make_type(TYPE_UNION);
594 t->name = name;
595 t->namespace = namespace;
596 if (name)
597 reg_type(t, name, namespace, tsUNION);
600 if (!t->defined && defined)
602 t->details.structure = xmalloc(sizeof(*t->details.structure));
603 t->details.structure->fields = fields;
604 t->defined = TRUE;
606 else if (defined)
607 error_loc("redefinition of union %s\n", name);
609 return t;
612 type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases)
614 type_t *t = NULL;
616 if (name)
617 t = find_type(name, NULL, tsUNION);
619 if (!t)
621 t = make_type(TYPE_ENCAPSULATED_UNION);
622 t->name = name;
623 if (name)
624 reg_type(t, name, NULL, tsUNION);
626 t->type_type = TYPE_ENCAPSULATED_UNION;
628 if (!t->defined)
630 if (!union_field)
631 union_field = make_var(xstrdup("tagged_union"));
632 union_field->declspec.type = type_new_nonencapsulated_union(gen_name(), NULL, TRUE, cases);
634 t->details.structure = xmalloc(sizeof(*t->details.structure));
635 t->details.structure->fields = append_var(NULL, switch_field);
636 t->details.structure->fields = append_var(t->details.structure->fields, union_field);
637 t->defined = TRUE;
639 else
640 error_loc("redefinition of union %s\n", name);
642 return t;
645 static int is_valid_bitfield_type(const type_t *type)
647 switch (type_get_type(type))
649 case TYPE_ENUM:
650 return TRUE;
651 case TYPE_BASIC:
652 switch (type_basic_get_type(type))
654 case TYPE_BASIC_INT8:
655 case TYPE_BASIC_INT16:
656 case TYPE_BASIC_INT32:
657 case TYPE_BASIC_INT64:
658 case TYPE_BASIC_INT:
659 case TYPE_BASIC_INT3264:
660 case TYPE_BASIC_LONG:
661 case TYPE_BASIC_CHAR:
662 case TYPE_BASIC_HYPER:
663 case TYPE_BASIC_BYTE:
664 case TYPE_BASIC_WCHAR:
665 case TYPE_BASIC_ERROR_STATUS_T:
666 return TRUE;
667 case TYPE_BASIC_FLOAT:
668 case TYPE_BASIC_DOUBLE:
669 case TYPE_BASIC_HANDLE:
670 return FALSE;
672 return FALSE;
673 default:
674 return FALSE;
678 type_t *type_new_bitfield(type_t *field, const expr_t *bits)
680 type_t *t;
682 if (!is_valid_bitfield_type(field))
683 error_loc("bit-field has invalid type\n");
685 if (bits->cval < 0)
686 error_loc("negative width for bit-field\n");
688 /* FIXME: validate bits->cval <= memsize(field) * 8 */
690 t = make_type(TYPE_BITFIELD);
691 t->details.bitfield.field = field;
692 t->details.bitfield.bits = bits;
693 return t;
696 static unsigned int compute_method_indexes(type_t *iface)
698 unsigned int idx;
699 statement_t *stmt;
701 if (!iface->details.iface)
702 return 0;
704 if (type_iface_get_inherit(iface))
705 idx = compute_method_indexes(type_iface_get_inherit(iface));
706 else
707 idx = 0;
709 STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
711 var_t *func = stmt->u.var;
712 if (!is_callas(func->attrs))
713 func->func_idx = idx++;
716 return idx;
719 type_t *type_interface_declare(char *name, struct namespace *namespace)
721 type_t *type = get_type(TYPE_INTERFACE, name, namespace, 0);
722 if (type_get_type_detect_alias(type) != TYPE_INTERFACE)
723 error_loc("interface %s previously not declared an interface at %s:%d\n",
724 type->name, type->loc_info.input_name, type->loc_info.line_number);
725 return type;
728 type_t *type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit, statement_list_t *stmts, typeref_list_t *requires)
730 if (iface->defined)
731 error_loc("interface %s already defined at %s:%d\n",
732 iface->name, iface->loc_info.input_name, iface->loc_info.line_number);
733 if (iface == inherit)
734 error_loc("interface %s can't inherit from itself\n",
735 iface->name);
736 iface->attrs = check_interface_attrs(iface->name, attrs);
737 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
738 iface->details.iface->disp_props = NULL;
739 iface->details.iface->disp_methods = NULL;
740 iface->details.iface->stmts = stmts;
741 iface->details.iface->inherit = inherit;
742 iface->details.iface->disp_inherit = NULL;
743 iface->details.iface->async_iface = NULL;
744 iface->details.iface->requires = requires;
745 iface->defined = TRUE;
746 compute_method_indexes(iface);
747 return iface;
750 type_t *type_dispinterface_declare(char *name)
752 type_t *type = get_type(TYPE_INTERFACE, name, NULL, 0);
753 if (type_get_type_detect_alias(type) != TYPE_INTERFACE)
754 error_loc("dispinterface %s previously not declared a dispinterface at %s:%d\n",
755 type->name, type->loc_info.input_name, type->loc_info.line_number);
756 return type;
759 type_t *type_dispinterface_define(type_t *iface, attr_list_t *attrs, var_list_t *props, var_list_t *methods)
761 if (iface->defined)
762 error_loc("dispinterface %s already defined at %s:%d\n",
763 iface->name, iface->loc_info.input_name, iface->loc_info.line_number);
764 iface->attrs = check_dispiface_attrs(iface->name, attrs);
765 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
766 iface->details.iface->disp_props = props;
767 iface->details.iface->disp_methods = methods;
768 iface->details.iface->stmts = NULL;
769 iface->details.iface->inherit = find_type("IDispatch", NULL, 0);
770 if (!iface->details.iface->inherit) error_loc("IDispatch is undefined\n");
771 iface->details.iface->disp_inherit = NULL;
772 iface->details.iface->async_iface = NULL;
773 iface->details.iface->requires = NULL;
774 iface->defined = TRUE;
775 compute_method_indexes(iface);
776 return iface;
779 type_t *type_dispinterface_define_from_iface(type_t *dispiface, attr_list_t *attrs, type_t *iface)
781 if (dispiface->defined)
782 error_loc("dispinterface %s already defined at %s:%d\n",
783 dispiface->name, dispiface->loc_info.input_name, dispiface->loc_info.line_number);
784 dispiface->attrs = check_dispiface_attrs(dispiface->name, attrs);
785 dispiface->details.iface = xmalloc(sizeof(*dispiface->details.iface));
786 dispiface->details.iface->disp_props = NULL;
787 dispiface->details.iface->disp_methods = NULL;
788 dispiface->details.iface->stmts = NULL;
789 dispiface->details.iface->inherit = find_type("IDispatch", NULL, 0);
790 if (!dispiface->details.iface->inherit) error_loc("IDispatch is undefined\n");
791 dispiface->details.iface->disp_inherit = iface;
792 dispiface->details.iface->async_iface = NULL;
793 dispiface->details.iface->requires = NULL;
794 dispiface->defined = TRUE;
795 compute_method_indexes(dispiface);
796 return dispiface;
799 type_t *type_module_declare(char *name)
801 type_t *type = get_type(TYPE_MODULE, name, NULL, 0);
802 if (type_get_type_detect_alias(type) != TYPE_MODULE)
803 error_loc("module %s previously not declared a module at %s:%d\n",
804 type->name, type->loc_info.input_name, type->loc_info.line_number);
805 return type;
808 type_t *type_module_define(type_t* module, attr_list_t *attrs, statement_list_t *stmts)
810 if (module->defined)
811 error_loc("module %s already defined at %s:%d\n",
812 module->name, module->loc_info.input_name, module->loc_info.line_number);
813 module->attrs = check_module_attrs(module->name, attrs);
814 module->details.module = xmalloc(sizeof(*module->details.module));
815 module->details.module->stmts = stmts;
816 module->defined = TRUE;
817 return module;
820 type_t *type_coclass_declare(char *name)
822 type_t *type = get_type(TYPE_COCLASS, name, NULL, 0);
823 if (type_get_type_detect_alias(type) != TYPE_COCLASS)
824 error_loc("coclass %s previously not declared a coclass at %s:%d\n",
825 type->name, type->loc_info.input_name, type->loc_info.line_number);
826 return type;
829 type_t *type_coclass_define(type_t *coclass, attr_list_t *attrs, typeref_list_t *ifaces)
831 if (coclass->defined)
832 error_loc("coclass %s already defined at %s:%d\n",
833 coclass->name, coclass->loc_info.input_name, coclass->loc_info.line_number);
834 coclass->attrs = check_coclass_attrs(coclass->name, attrs);
835 coclass->details.coclass.ifaces = ifaces;
836 coclass->defined = TRUE;
837 return coclass;
840 type_t *type_runtimeclass_declare(char *name, struct namespace *namespace)
842 type_t *type = get_type(TYPE_RUNTIMECLASS, name, namespace, 0);
843 if (type_get_type_detect_alias(type) != TYPE_RUNTIMECLASS)
844 error_loc("runtimeclass %s previously not declared a runtimeclass at %s:%d\n",
845 type->name, type->loc_info.input_name, type->loc_info.line_number);
846 return type;
849 type_t *type_runtimeclass_define(type_t *runtimeclass, attr_list_t *attrs, typeref_list_t *ifaces)
851 typeref_t *ref, *required, *tmp;
852 typeref_list_t *requires;
854 if (runtimeclass->defined)
855 error_loc("runtimeclass %s already defined at %s:%d\n",
856 runtimeclass->name, runtimeclass->loc_info.input_name, runtimeclass->loc_info.line_number);
857 runtimeclass->attrs = check_runtimeclass_attrs(runtimeclass->name, attrs);
858 runtimeclass->details.runtimeclass.ifaces = ifaces;
859 runtimeclass->defined = TRUE;
860 if (!type_runtimeclass_get_default_iface(runtimeclass, FALSE) &&
861 !get_attrp(runtimeclass->attrs, ATTR_STATIC))
862 error_loc("runtimeclass %s must have a default interface or static factory\n", runtimeclass->name);
864 if (ifaces) LIST_FOR_EACH_ENTRY(ref, ifaces, typeref_t, entry)
866 /* FIXME: this should probably not be allowed, here or in coclass, */
867 /* but for now there's too many places in Wine IDL where it is to */
868 /* even print a warning. */
869 if (!(ref->type->defined)) continue;
870 if (!(requires = type_iface_get_requires(ref->type))) continue;
871 LIST_FOR_EACH_ENTRY(required, requires, typeref_t, entry)
873 int found = 0;
875 LIST_FOR_EACH_ENTRY(tmp, ifaces, typeref_t, entry)
876 if ((found = type_is_equal(tmp->type, required->type))) break;
878 if (!found)
879 error_loc("interface '%s' also requires interface '%s', "
880 "but runtimeclass '%s' does not implement it.\n",
881 ref->type->name, required->type->name, runtimeclass->name);
885 return runtimeclass;
888 type_t *type_apicontract_declare(char *name, struct namespace *namespace)
890 type_t *type = get_type(TYPE_APICONTRACT, name, namespace, 0);
891 if (type_get_type_detect_alias(type) != TYPE_APICONTRACT)
892 error_loc("apicontract %s previously not declared a apicontract at %s:%d\n",
893 type->name, type->loc_info.input_name, type->loc_info.line_number);
894 return type;
897 type_t *type_apicontract_define(type_t *apicontract, attr_list_t *attrs)
899 if (apicontract->defined)
900 error_loc("apicontract %s already defined at %s:%d\n",
901 apicontract->name, apicontract->loc_info.input_name, apicontract->loc_info.line_number);
902 apicontract->attrs = check_apicontract_attrs(apicontract->name, attrs);
903 apicontract->defined = TRUE;
904 return apicontract;
907 static void compute_delegate_iface_names(type_t *delegate, type_t *type, typeref_list_t *params)
909 type_t *iface = delegate->details.delegate.iface;
910 iface->namespace = delegate->namespace;
911 iface->name = strmake("I%s", delegate->name);
912 if (type) iface->c_name = format_parameterized_type_c_name(type, params, "I", "_C");
913 else iface->c_name = format_namespace(delegate->namespace, "__x_", "_C", iface->name, use_abi_namespace ? "ABI" : NULL);
914 if (type) iface->param_name = format_parameterized_type_c_name(type, params, "I", "__C");
915 else iface->param_name = format_namespace(delegate->namespace, "_", "__C", iface->name, NULL);
916 iface->qualified_name = format_namespace(delegate->namespace, "", "::", iface->name, use_abi_namespace ? "ABI" : NULL);
919 type_t *type_delegate_declare(char *name, struct namespace *namespace)
921 type_t *type = get_type(TYPE_DELEGATE, name, namespace, 0);
922 if (type_get_type_detect_alias(type) != TYPE_DELEGATE)
923 error_loc("delegate %s previously not declared a delegate at %s:%d\n",
924 type->name, type->loc_info.input_name, type->loc_info.line_number);
925 return type;
928 type_t *type_delegate_define(type_t *delegate, attr_list_t *attrs, statement_list_t *stmts)
930 type_t *iface;
932 if (delegate->defined)
933 error_loc("delegate %s already defined at %s:%d\n",
934 delegate->name, delegate->loc_info.input_name, delegate->loc_info.line_number);
936 delegate->attrs = check_interface_attrs(delegate->name, attrs);
938 iface = make_type(TYPE_INTERFACE);
939 iface->attrs = delegate->attrs;
940 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
941 iface->details.iface->disp_props = NULL;
942 iface->details.iface->disp_methods = NULL;
943 iface->details.iface->stmts = stmts;
944 iface->details.iface->inherit = find_type("IUnknown", NULL, 0);
945 if (!iface->details.iface->inherit) error_loc("IUnknown is undefined\n");
946 iface->details.iface->disp_inherit = NULL;
947 iface->details.iface->async_iface = NULL;
948 iface->details.iface->requires = NULL;
949 iface->defined = TRUE;
950 compute_method_indexes(iface);
952 delegate->details.delegate.iface = iface;
953 delegate->defined = TRUE;
954 compute_delegate_iface_names(delegate, NULL, NULL);
956 return delegate;
959 type_t *type_parameterized_interface_declare(char *name, struct namespace *namespace, typeref_list_t *params)
961 type_t *type = get_type(TYPE_PARAMETERIZED_TYPE, name, namespace, 0);
962 if (type_get_type_detect_alias(type) != TYPE_PARAMETERIZED_TYPE)
963 error_loc("pinterface %s previously not declared a pinterface at %s:%d\n",
964 type->name, type->loc_info.input_name, type->loc_info.line_number);
965 type->details.parameterized.type = make_type(TYPE_INTERFACE);
966 type->details.parameterized.params = params;
967 return type;
970 type_t *type_parameterized_interface_define(type_t *type, attr_list_t *attrs, type_t *inherit, statement_list_t *stmts, typeref_list_t *requires)
972 type_t *iface;
973 if (type->defined)
974 error_loc("pinterface %s already defined at %s:%d\n",
975 type->name, type->loc_info.input_name, type->loc_info.line_number);
977 /* The parameterized type UUID is actually a PIID that is then used as a seed to generate
978 * a new type GUID with the rules described in:
979 * https://docs.microsoft.com/en-us/uwp/winrt-cref/winrt-type-system#parameterized-types
980 * TODO: store type signatures for generated interfaces, and generate their GUIDs
982 type->attrs = check_interface_attrs(type->name, attrs);
984 iface = type->details.parameterized.type;
985 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
986 iface->details.iface->disp_props = NULL;
987 iface->details.iface->disp_methods = NULL;
988 iface->details.iface->stmts = stmts;
989 iface->details.iface->inherit = inherit;
990 iface->details.iface->disp_inherit = NULL;
991 iface->details.iface->async_iface = NULL;
992 iface->details.iface->requires = requires;
994 iface->name = type->name;
996 type->defined = TRUE;
997 return type;
1000 type_t *type_parameterized_delegate_declare(char *name, struct namespace *namespace, typeref_list_t *params)
1002 type_t *type = get_type(TYPE_PARAMETERIZED_TYPE, name, namespace, 0);
1003 if (type_get_type_detect_alias(type) != TYPE_PARAMETERIZED_TYPE)
1004 error_loc("pdelegate %s previously not declared a pdelegate at %s:%d\n",
1005 type->name, type->loc_info.input_name, type->loc_info.line_number);
1006 type->details.parameterized.type = make_type(TYPE_DELEGATE);
1007 type->details.parameterized.params = params;
1008 return type;
1011 type_t *type_parameterized_delegate_define(type_t *type, attr_list_t *attrs, statement_list_t *stmts)
1013 type_t *iface, *delegate;
1015 if (type->defined)
1016 error_loc("pdelegate %s already defined at %s:%d\n",
1017 type->name, type->loc_info.input_name, type->loc_info.line_number);
1019 type->attrs = check_interface_attrs(type->name, attrs);
1021 delegate = type->details.parameterized.type;
1022 delegate->attrs = type->attrs;
1023 delegate->details.delegate.iface = make_type(TYPE_INTERFACE);
1025 iface = delegate->details.delegate.iface;
1026 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
1027 iface->details.iface->disp_props = NULL;
1028 iface->details.iface->disp_methods = NULL;
1029 iface->details.iface->stmts = stmts;
1030 iface->details.iface->inherit = find_type("IUnknown", NULL, 0);
1031 if (!iface->details.iface->inherit) error_loc("IUnknown is undefined\n");
1032 iface->details.iface->disp_inherit = NULL;
1033 iface->details.iface->async_iface = NULL;
1034 iface->details.iface->requires = NULL;
1036 delegate->name = type->name;
1037 compute_delegate_iface_names(delegate, type, type->details.parameterized.params);
1039 type->defined = TRUE;
1040 return type;
1043 type_t *type_parameterized_type_specialize_partial(type_t *type, typeref_list_t *params)
1045 type_t *new_type = duptype(type, 0);
1046 new_type->details.parameterized.type = type;
1047 new_type->details.parameterized.params = params;
1048 return new_type;
1051 static type_t *replace_type_parameters_in_type(type_t *type, typeref_list_t *orig, typeref_list_t *repl);
1053 static typeref_list_t *replace_type_parameters_in_type_list(typeref_list_t *list, typeref_list_t *orig, typeref_list_t *repl)
1055 typeref_list_t *new_list = NULL;
1056 typeref_t *ref;
1058 if (!list) return list;
1060 LIST_FOR_EACH_ENTRY(ref, list, typeref_t, entry)
1062 type_t *new_type = replace_type_parameters_in_type(ref->type, orig, repl);
1063 new_list = append_typeref(new_list, make_typeref(new_type));
1066 return new_list;
1069 static var_t *replace_type_parameters_in_var(var_t *var, typeref_list_t *orig, typeref_list_t *repl)
1071 var_t *new_var = xmalloc(sizeof(*new_var));
1072 *new_var = *var;
1073 list_init(&new_var->entry);
1074 new_var->declspec.type = replace_type_parameters_in_type(var->declspec.type, orig, repl);
1075 return new_var;
1078 static var_list_t *replace_type_parameters_in_var_list(var_list_t *var_list, typeref_list_t *orig, typeref_list_t *repl)
1080 var_list_t *new_var_list;
1081 var_t *var, *new_var;
1083 if (!var_list) return var_list;
1085 new_var_list = xmalloc(sizeof(*new_var_list));
1086 list_init(new_var_list);
1088 LIST_FOR_EACH_ENTRY(var, var_list, var_t, entry)
1090 new_var = replace_type_parameters_in_var(var, orig, repl);
1091 list_add_tail(new_var_list, &new_var->entry);
1094 return new_var_list;
1097 static statement_t *replace_type_parameters_in_statement(statement_t *stmt, typeref_list_t *orig, typeref_list_t *repl, loc_info_t *loc)
1099 statement_t *new_stmt = xmalloc(sizeof(*new_stmt));
1100 *new_stmt = *stmt;
1101 list_init(&new_stmt->entry);
1103 switch (stmt->type)
1105 case STMT_DECLARATION:
1106 new_stmt->u.var = replace_type_parameters_in_var(stmt->u.var, orig, repl);
1107 break;
1108 case STMT_TYPE:
1109 case STMT_TYPEREF:
1110 new_stmt->u.type = replace_type_parameters_in_type(stmt->u.type, orig, repl);
1111 break;
1112 case STMT_TYPEDEF:
1113 new_stmt->u.type_list = replace_type_parameters_in_type_list(stmt->u.type_list, orig, repl);
1114 break;
1115 case STMT_MODULE:
1116 case STMT_LIBRARY:
1117 case STMT_IMPORT:
1118 case STMT_IMPORTLIB:
1119 case STMT_PRAGMA:
1120 case STMT_CPPQUOTE:
1121 error_loc_info(loc, "unimplemented parameterized type replacement for statement type %d.\n", stmt->type);
1122 break;
1125 return new_stmt;
1128 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)
1130 statement_list_t *new_stmt_list;
1131 statement_t *stmt, *new_stmt;
1133 if (!stmt_list) return stmt_list;
1135 new_stmt_list = xmalloc(sizeof(*new_stmt_list));
1136 list_init(new_stmt_list);
1138 LIST_FOR_EACH_ENTRY(stmt, stmt_list, statement_t, entry)
1140 new_stmt = replace_type_parameters_in_statement(stmt, orig, repl, loc);
1141 list_add_tail(new_stmt_list, &new_stmt->entry);
1144 return new_stmt_list;
1147 static type_t *replace_type_parameters_in_type(type_t *type, typeref_list_t *orig, typeref_list_t *repl)
1149 struct list *o, *r;
1150 type_t *t;
1152 if (!type) return type;
1153 switch (type->type_type)
1155 case TYPE_VOID:
1156 case TYPE_BASIC:
1157 case TYPE_ENUM:
1158 case TYPE_BITFIELD:
1159 case TYPE_INTERFACE:
1160 case TYPE_RUNTIMECLASS:
1161 case TYPE_DELEGATE:
1162 case TYPE_STRUCT:
1163 case TYPE_ENCAPSULATED_UNION:
1164 case TYPE_UNION:
1165 return type;
1166 case TYPE_PARAMETER:
1167 if (!orig || !repl) return NULL;
1168 for (o = list_head(orig), r = list_head(repl); o && r;
1169 o = list_next(orig, o), r = list_next(repl, r))
1170 if (type == LIST_ENTRY(o, typeref_t, entry)->type)
1171 return LIST_ENTRY(r, typeref_t, entry)->type;
1172 return type;
1173 case TYPE_POINTER:
1174 t = replace_type_parameters_in_type(type->details.pointer.ref.type, orig, repl);
1175 if (t == type->details.pointer.ref.type) return type;
1176 type = duptype(type, 0);
1177 type->details.pointer.ref.type = t;
1178 return type;
1179 case TYPE_ALIAS:
1180 t = replace_type_parameters_in_type(type->details.alias.aliasee.type, orig, repl);
1181 if (t == type->details.alias.aliasee.type) return type;
1182 type = duptype(type, 0);
1183 type->details.alias.aliasee.type = t;
1184 return type;
1185 case TYPE_ARRAY:
1186 t = replace_type_parameters_in_type(type->details.array.elem.type, orig, repl);
1187 if (t == t->details.array.elem.type) return type;
1188 type = duptype(type, 0);
1189 t->details.array.elem.type = t;
1190 return type;
1191 case TYPE_FUNCTION:
1192 t = duptype(type, 0);
1193 t->details.function = xmalloc(sizeof(*t->details.function));
1194 t->details.function->args = replace_type_parameters_in_var_list(type->details.function->args, orig, repl);
1195 t->details.function->retval = replace_type_parameters_in_var(type->details.function->retval, orig, repl);
1196 return t;
1197 case TYPE_PARAMETERIZED_TYPE:
1198 t = type->details.parameterized.type;
1199 if (t->type_type != TYPE_PARAMETERIZED_TYPE) return find_parameterized_type(type, repl);
1200 repl = replace_type_parameters_in_type_list(type->details.parameterized.params, orig, repl);
1201 return replace_type_parameters_in_type(t, t->details.parameterized.params, repl);
1202 case TYPE_MODULE:
1203 case TYPE_COCLASS:
1204 case TYPE_APICONTRACT:
1205 error_loc_info(&type->loc_info, "unimplemented parameterized type replacement for type %s of type %d.\n", type->name, type->type_type);
1206 break;
1209 return type;
1212 static void type_parameterized_interface_specialize(type_t *tmpl, type_t *iface, typeref_list_t *orig, typeref_list_t *repl)
1214 iface->details.iface = xmalloc(sizeof(*iface->details.iface));
1215 iface->details.iface->disp_methods = NULL;
1216 iface->details.iface->disp_props = NULL;
1217 iface->details.iface->stmts = replace_type_parameters_in_statement_list(tmpl->details.iface->stmts, orig, repl, &tmpl->loc_info);
1218 iface->details.iface->inherit = replace_type_parameters_in_type(tmpl->details.iface->inherit, orig, repl);
1219 iface->details.iface->disp_inherit = NULL;
1220 iface->details.iface->async_iface = NULL;
1221 iface->details.iface->requires = NULL;
1224 static void type_parameterized_delegate_specialize(type_t *tmpl, type_t *delegate, typeref_list_t *orig, typeref_list_t *repl)
1226 type_parameterized_interface_specialize(tmpl->details.delegate.iface, delegate->details.delegate.iface, orig, repl);
1229 type_t *type_parameterized_type_specialize_declare(type_t *type, typeref_list_t *params)
1231 type_t *tmpl = type->details.parameterized.type;
1232 type_t *new_type = duptype(tmpl, 0);
1234 new_type->namespace = type->namespace;
1235 new_type->name = format_parameterized_type_name(type, params);
1236 reg_type(new_type, new_type->name, new_type->namespace, 0);
1237 new_type->c_name = format_parameterized_type_c_name(type, params, "", "_C");
1238 new_type->short_name = format_parameterized_type_short_name(type, params, "");
1239 new_type->param_name = format_parameterized_type_c_name(type, params, "", "__C");
1241 if (new_type->type_type == TYPE_DELEGATE)
1243 new_type->details.delegate.iface = duptype(tmpl->details.delegate.iface, 0);
1244 compute_delegate_iface_names(new_type, type, params);
1245 new_type->details.delegate.iface->short_name = format_parameterized_type_short_name(type, params, "I");
1248 return new_type;
1251 static void compute_interface_signature_uuid(type_t *iface)
1253 static const char winrt_pinterface_namespace[] = {0x11,0xf4,0x7a,0xd5,0x7b,0x73,0x42,0xc0,0xab,0xae,0x87,0x8b,0x1e,0x16,0xad,0xee};
1254 static const int version = 5;
1255 struct sha1_context ctx;
1256 unsigned char hash[20];
1257 struct uuid *uuid;
1259 if (!(uuid = get_attrp(iface->attrs, ATTR_UUID)))
1261 uuid = xmalloc(sizeof(*uuid));
1262 iface->attrs = append_attr(iface->attrs, make_attrp(ATTR_UUID, uuid));
1265 sha1_init(&ctx);
1266 sha1_update(&ctx, winrt_pinterface_namespace, sizeof(winrt_pinterface_namespace));
1267 sha1_update(&ctx, iface->signature, strlen(iface->signature));
1268 sha1_finalize(&ctx, (unsigned int *)hash);
1270 /* https://tools.ietf.org/html/rfc4122:
1272 * Set the four most significant bits (bits 12 through 15) of the
1273 time_hi_and_version field to the appropriate 4-bit version number
1274 from Section 4.1.3.
1276 * Set the two most significant bits (bits 6 and 7) of the
1277 clock_seq_hi_and_reserved to zero and one, respectively.
1280 hash[6] = ((hash[6] & 0x0f) | (version << 4));
1281 hash[8] = ((hash[8] & 0x3f) | 0x80);
1283 uuid->Data1 = ((unsigned int)hash[0] << 24) | ((unsigned int)hash[1] << 16) | ((unsigned int)hash[2] << 8) | hash[3];
1284 uuid->Data2 = ((unsigned short)hash[4] << 8) | hash[5];
1285 uuid->Data3 = ((unsigned short)hash[6] << 8) | hash[7];
1286 memcpy(&uuid->Data4, hash + 8, sizeof(*uuid) - offsetof(struct uuid, Data4));
1289 type_t *type_parameterized_type_specialize_define(type_t *type)
1291 type_t *tmpl = type->details.parameterized.type;
1292 typeref_list_t *orig = tmpl->details.parameterized.params;
1293 typeref_list_t *repl = type->details.parameterized.params;
1294 type_t *iface = find_parameterized_type(tmpl, repl);
1296 if (type_get_type_detect_alias(type) != TYPE_PARAMETERIZED_TYPE ||
1297 type_get_type_detect_alias(tmpl) != TYPE_PARAMETERIZED_TYPE)
1298 error_loc("cannot define non-parameterized type %s, declared at %s:%d\n",
1299 type->name, type->loc_info.input_name, type->loc_info.line_number);
1301 if (type_get_type_detect_alias(tmpl->details.parameterized.type) == TYPE_INTERFACE &&
1302 type_get_type_detect_alias(iface) == TYPE_INTERFACE)
1303 type_parameterized_interface_specialize(tmpl->details.parameterized.type, iface, orig, repl);
1304 else if (type_get_type_detect_alias(tmpl->details.parameterized.type) == TYPE_DELEGATE &&
1305 type_get_type_detect_alias(iface) == TYPE_DELEGATE)
1306 type_parameterized_delegate_specialize(tmpl->details.parameterized.type, iface, orig, repl);
1307 else
1308 error_loc("pinterface/pdelegate %s previously not declared a pinterface/pdelegate at %s:%d\n",
1309 iface->name, iface->loc_info.input_name, iface->loc_info.line_number);
1311 iface->impl_name = format_parameterized_type_impl_name(type, repl, "");
1312 iface->signature = format_parameterized_type_signature(type, repl);
1313 iface->defined = TRUE;
1314 if (iface->type_type == TYPE_DELEGATE)
1316 iface = iface->details.delegate.iface;
1317 iface->impl_name = format_parameterized_type_impl_name(type, repl, "I");
1318 iface->signature = format_parameterized_type_signature(type, repl);
1319 iface->defined = TRUE;
1321 compute_interface_signature_uuid(iface);
1322 compute_method_indexes(iface);
1323 return iface;
1326 int type_is_equal(const type_t *type1, const type_t *type2)
1328 if (type1 == type2)
1329 return TRUE;
1330 if (type_get_type_detect_alias(type1) != type_get_type_detect_alias(type2))
1331 return FALSE;
1332 if (type1->namespace != type2->namespace)
1333 return FALSE;
1335 if (type1->name && type2->name)
1336 return !strcmp(type1->name, type2->name);
1337 else if ((!type1->name && type2->name) || (type1->name && !type2->name))
1338 return FALSE;
1340 /* FIXME: do deep inspection of types to determine if they are equal */
1342 return FALSE;