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
34 type_t
*duptype(type_t
*t
, int dupname
)
36 type_t
*d
= alloc_type();
39 if (dupname
&& t
->name
)
40 d
->name
= xstrdup(t
->name
);
45 type_t
*make_type(enum type_type type
)
47 type_t
*t
= alloc_type();
54 t
->qualified_name
= NULL
;
58 memset(&t
->details
, 0, sizeof(t
->details
));
59 t
->typestring_offset
= 0;
61 t
->ignore
= (parse_only
!= 0);
64 t
->user_types_registered
= FALSE
;
68 init_loc_info(&t
->loc_info
);
72 static const var_t
*find_arg(const var_list_t
*args
, const char *name
)
76 if (args
) LIST_FOR_EACH_ENTRY(arg
, args
, const var_t
, entry
)
78 if (arg
->name
&& !strcmp(name
, arg
->name
))
85 const char *type_get_decl_name(const type_t
*type
, enum name_type name_type
)
91 return type
->c_name
? type
->c_name
: type
->name
;
98 const char *type_get_name(const type_t
*type
, enum name_type name_type
)
102 return type
->qualified_name
? type
->qualified_name
: type
->name
;
104 return type
->c_name
? type
->c_name
: type
->name
;
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
;
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
);
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);
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
);
132 n
-= strlen(separator
);
138 static size_t append_pointer_stars(char **buf
, size_t *len
, size_t pos
, type_t
*type
)
141 for (; type
&& type
->type_type
== TYPE_POINTER
; type
= type_pointer_get_ref_type(type
)) n
+= strappend(buf
, len
, pos
+ 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
)
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
);
162 static size_t append_type_signature(char **buf
, size_t *len
, size_t pos
, type_t
*type
)
164 const struct uuid
*uuid
;
168 switch (type
->type_type
)
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
);
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]);
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
, ")");
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
, ")");
197 n
+= append_type_signature(buf
, len
, pos
+ n
, type
->details
.pointer
.ref
.type
);
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
);
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
, ")");
211 switch (type_basic_get_type(type
))
214 case TYPE_BASIC_INT32
:
215 n
+= strappend(buf
, len
, pos
+ n
, type_basic_get_sign(type
) <= 0 ? "i4" : "u4");
217 case TYPE_BASIC_INT64
:
218 n
+= strappend(buf
, len
, pos
+ n
, type_basic_get_sign(type
) <= 0 ? "i8" : "u8");
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");
224 case TYPE_BASIC_FLOAT
:
225 n
+= strappend(buf
, len
, pos
+ n
, "f4");
227 case TYPE_BASIC_DOUBLE
:
228 n
+= strappend(buf
, len
, pos
+ n
, "f8");
230 case TYPE_BASIC_BYTE
:
231 n
+= strappend(buf
, len
, pos
+ n
, "u1");
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
));
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
, ")");
252 case TYPE_ENCAPSULATED_UNION
:
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
);
262 case TYPE_PARAMETERIZED_TYPE
:
264 assert(0); /* should not be there */
271 char *format_namespace(struct namespace *namespace, const char *prefix
, const char *separator
, const char *suffix
, const char *abi_prefix
)
275 append_namespaces(&buf
, &len
, 0, namespace, prefix
, separator
, suffix
, abi_prefix
);
279 char *format_parameterized_type_name(type_t
*type
, typeref_list_t
*params
)
281 size_t len
= 0, pos
= 0;
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
, " >");
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;
310 int i
, count
= params
? list_count(params
) : 0;
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
));
339 static char *format_parameterized_type_signature(type_t
*type
, typeref_list_t
*params
)
341 size_t len
= 0, pos
= 0;
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
, ")");
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;
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
);
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;
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
, " >");
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
, " >");
412 type_t
*type_new_function(var_list_t
*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
);
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
);
436 error_loc("too many unnamed arguments\n");
443 name
[0] = i
> 26 ? 'a' + i
/ 26 : 'a' + i
;
444 name
[1] = i
> 26 ? 'a' + i
% 26 : 0;
446 unique
= !find_arg(args
, name
);
448 arg
->name
= xstrdup(name
);
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"));
462 type_t
*type_new_pointer(type_t
*ref
)
464 type_t
*t
= make_type(TYPE_POINTER
);
465 t
->details
.pointer
.ref
.type
= ref
;
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
);
475 a
->details
.alias
.aliasee
= *t
;
476 init_loc_info(&a
->loc_info
);
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
;
489 t
->details
.array
.size_is
= size_is
;
491 t
->details
.array
.dim
= dim
;
493 t
->details
.array
.elem
= *element
;
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;
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
;
524 void_type
= make_type(TYPE_VOID
);
528 type_t
*type_new_enum(const char *name
, struct namespace *namespace, int defined
, var_list_t
*enums
)
533 t
= find_type(name
, namespace,tsENUM
);
537 t
= make_type(TYPE_ENUM
);
539 t
->namespace = namespace;
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
;
551 error_loc("redefinition of enum %s\n", name
);
556 type_t
*type_new_struct(char *name
, struct namespace *namespace, int defined
, var_list_t
*fields
)
561 t
= find_type(name
, namespace, tsSTRUCT
);
565 t
= make_type(TYPE_STRUCT
);
567 t
->namespace = namespace;
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
;
579 error_loc("redefinition of struct %s\n", name
);
584 type_t
*type_new_nonencapsulated_union(const char *name
, struct namespace *namespace, int defined
, var_list_t
*fields
)
589 t
= find_type(name
, namespace, tsUNION
);
593 t
= make_type(TYPE_UNION
);
595 t
->namespace = namespace;
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
;
607 error_loc("redefinition of union %s\n", name
);
612 type_t
*type_new_encapsulated_union(char *name
, var_t
*switch_field
, var_t
*union_field
, var_list_t
*cases
)
617 t
= find_type(name
, NULL
, tsUNION
);
621 t
= make_type(TYPE_ENCAPSULATED_UNION
);
624 reg_type(t
, name
, NULL
, tsUNION
);
626 t
->type_type
= TYPE_ENCAPSULATED_UNION
;
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
);
640 error_loc("redefinition of union %s\n", name
);
645 static int is_valid_bitfield_type(const type_t
*type
)
647 switch (type_get_type(type
))
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
:
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
:
667 case TYPE_BASIC_FLOAT
:
668 case TYPE_BASIC_DOUBLE
:
669 case TYPE_BASIC_HANDLE
:
678 type_t
*type_new_bitfield(type_t
*field
, const expr_t
*bits
)
682 if (!is_valid_bitfield_type(field
))
683 error_loc("bit-field has invalid type\n");
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
;
696 static unsigned int compute_method_indexes(type_t
*iface
)
701 if (!iface
->details
.iface
)
704 if (type_iface_get_inherit(iface
))
705 idx
= compute_method_indexes(type_iface_get_inherit(iface
));
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
++;
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
);
728 type_t
*type_interface_define(type_t
*iface
, attr_list_t
*attrs
, type_t
*inherit
, statement_list_t
*stmts
, typeref_list_t
*requires
)
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",
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
);
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
);
759 type_t
*type_dispinterface_define(type_t
*iface
, attr_list_t
*attrs
, var_list_t
*props
, var_list_t
*methods
)
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
);
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
);
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
);
808 type_t
*type_module_define(type_t
* module
, attr_list_t
*attrs
, statement_list_t
*stmts
)
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
;
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
);
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
;
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
);
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
)
875 LIST_FOR_EACH_ENTRY(tmp
, ifaces
, typeref_t
, entry
)
876 if ((found
= type_is_equal(tmp
->type
, required
->type
))) break;
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
);
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
);
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
;
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
);
928 type_t
*type_delegate_define(type_t
*delegate
, attr_list_t
*attrs
, statement_list_t
*stmts
)
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
);
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
;
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
)
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
;
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
;
1011 type_t
*type_parameterized_delegate_define(type_t
*type
, attr_list_t
*attrs
, statement_list_t
*stmts
)
1013 type_t
*iface
, *delegate
;
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
;
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
;
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
;
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
));
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
));
1073 list_init(&new_var
->entry
);
1074 new_var
->declspec
.type
= replace_type_parameters_in_type(var
->declspec
.type
, orig
, repl
);
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
));
1101 list_init(&new_stmt
->entry
);
1105 case STMT_DECLARATION
:
1106 new_stmt
->u
.var
= replace_type_parameters_in_var(stmt
->u
.var
, orig
, repl
);
1110 new_stmt
->u
.type
= replace_type_parameters_in_type(stmt
->u
.type
, orig
, repl
);
1113 new_stmt
->u
.type_list
= replace_type_parameters_in_type_list(stmt
->u
.type_list
, orig
, repl
);
1118 case STMT_IMPORTLIB
:
1121 error_loc_info(loc
, "unimplemented parameterized type replacement for statement type %d.\n", stmt
->type
);
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
)
1152 if (!type
) return type
;
1153 switch (type
->type_type
)
1159 case TYPE_INTERFACE
:
1160 case TYPE_RUNTIMECLASS
:
1163 case TYPE_ENCAPSULATED_UNION
:
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
;
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
;
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
;
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
;
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
);
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
);
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
);
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");
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];
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
));
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
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
);
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
);
1326 int type_is_equal(const type_t
*type1
, const type_t
*type2
)
1330 if (type_get_type_detect_alias(type1
) != type_get_type_detect_alias(type2
))
1332 if (type1
->namespace != type2
->namespace)
1335 if (type1
->name
&& type2
->name
)
1336 return !strcmp(type1
->name
, type2
->name
);
1337 else if ((!type1
->name
&& type2
->name
) || (type1
->name
&& !type2
->name
))
1340 /* FIXME: do deep inspection of types to determine if they are equal */