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 (type
->signature
) n
+= strappend(buf
, len
, pos
+ n
, "%s", type
->signature
);
174 if (!(uuid
= get_attrp(type
->attrs
, ATTR_UUID
)))
175 error_loc_info(&type
->loc_info
, "cannot compute type signature, no uuid found for type %s.\n", type
->name
);
177 n
+= strappend(buf
, len
, pos
+ n
, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
178 uuid
->Data1
, uuid
->Data2
, uuid
->Data3
,
179 uuid
->Data4
[0], uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3],
180 uuid
->Data4
[4], uuid
->Data4
[5], uuid
->Data4
[6], uuid
->Data4
[7]);
184 n
+= strappend(buf
, len
, pos
+ n
, "delegate(");
185 n
+= append_type_signature(buf
, len
, pos
+ n
, type_delegate_get_iface(type
));
186 n
+= strappend(buf
, len
, pos
+ n
, ")");
188 case TYPE_RUNTIMECLASS
:
189 n
+= strappend(buf
, len
, pos
+ n
, "rc(");
190 n
+= append_namespaces(buf
, len
, pos
+ n
, type
->namespace, "", ".", type
->name
, NULL
);
191 n
+= strappend(buf
, len
, pos
+ n
, ";");
192 n
+= append_type_signature(buf
, len
, pos
+ n
, type_runtimeclass_get_default_iface(type
, TRUE
));
193 n
+= strappend(buf
, len
, pos
+ n
, ")");
196 n
+= append_type_signature(buf
, len
, pos
+ n
, type
->details
.pointer
.ref
.type
);
199 if (!strcmp(type
->name
, "boolean")) n
+= strappend(buf
, len
, pos
+ n
, "b1");
200 else if (!strcmp(type
->name
, "HSTRING")) n
+= strappend(buf
, len
, pos
+ n
, "string");
201 else n
+= append_type_signature(buf
, len
, pos
+ n
, type
->details
.alias
.aliasee
.type
);
204 n
+= strappend(buf
, len
, pos
+ n
, "struct(");
205 n
+= append_namespaces(buf
, len
, pos
+ n
, type
->namespace, "", ".", type
->name
, NULL
);
206 n
+= append_var_list_signature(buf
, len
, pos
+ n
, type
->details
.structure
->fields
);
207 n
+= strappend(buf
, len
, pos
+ n
, ")");
210 switch (type_basic_get_type(type
))
213 case TYPE_BASIC_INT32
:
214 n
+= strappend(buf
, len
, pos
+ n
, type_basic_get_sign(type
) <= 0 ? "i4" : "u4");
216 case TYPE_BASIC_INT64
:
217 n
+= strappend(buf
, len
, pos
+ n
, type_basic_get_sign(type
) <= 0 ? "i8" : "u8");
219 case TYPE_BASIC_INT8
:
220 assert(type_basic_get_sign(type
) > 0); /* signature string for signed char isn't specified */
221 n
+= strappend(buf
, len
, pos
+ n
, "u1");
223 case TYPE_BASIC_FLOAT
:
224 n
+= strappend(buf
, len
, pos
+ n
, "f4");
226 case TYPE_BASIC_DOUBLE
:
227 n
+= strappend(buf
, len
, pos
+ n
, "f8");
229 case TYPE_BASIC_INT16
:
230 case TYPE_BASIC_INT3264
:
231 case TYPE_BASIC_LONG
:
232 case TYPE_BASIC_CHAR
:
233 case TYPE_BASIC_HYPER
:
234 case TYPE_BASIC_BYTE
:
235 case TYPE_BASIC_WCHAR
:
236 case TYPE_BASIC_ERROR_STATUS_T
:
237 case TYPE_BASIC_HANDLE
:
238 error_loc_info(&type
->loc_info
, "unimplemented type signature for basic type %d.\n", type_basic_get_type(type
));
242 n
+= strappend(buf
, len
, pos
+ n
, "enum(");
243 n
+= append_namespaces(buf
, len
, pos
+ n
, type
->namespace, "", ".", type
->name
, NULL
);
244 if (is_attr(type
->attrs
, ATTR_FLAGS
)) n
+= strappend(buf
, len
, pos
+ n
, ";u4");
245 else n
+= strappend(buf
, len
, pos
+ n
, ";i4");
246 n
+= strappend(buf
, len
, pos
+ n
, ")");
249 case TYPE_ENCAPSULATED_UNION
:
256 case TYPE_APICONTRACT
:
257 error_loc_info(&type
->loc_info
, "unimplemented type signature for type %s of type %d.\n", type
->name
, type
->type_type
);
259 case TYPE_PARAMETERIZED_TYPE
:
261 assert(0); /* should not be there */
268 char *format_namespace(struct namespace *namespace, const char *prefix
, const char *separator
, const char *suffix
, const char *abi_prefix
)
272 append_namespaces(&buf
, &len
, 0, namespace, prefix
, separator
, suffix
, abi_prefix
);
276 char *format_parameterized_type_name(type_t
*type
, typeref_list_t
*params
)
278 size_t len
= 0, pos
= 0;
282 pos
+= strappend(&buf
, &len
, pos
, "%s<", type
->name
);
283 if (params
) LIST_FOR_EACH_ENTRY(ref
, params
, typeref_t
, entry
)
285 type
= type_pointer_get_root_type(ref
->type
);
286 pos
+= strappend(&buf
, &len
, pos
, "%s", type
->qualified_name
);
287 pos
+= append_pointer_stars(&buf
, &len
, pos
, ref
->type
);
288 if (list_next(params
, &ref
->entry
)) pos
+= strappend(&buf
, &len
, pos
, ",");
290 pos
+= strappend(&buf
, &len
, pos
, " >");
295 static char const *parameterized_type_shorthands
[][2] = {
296 {"Windows__CFoundation__CCollections__C", "__F"},
297 {"Windows_CFoundation_CCollections_C", "__F"},
298 {"Windows__CFoundation__C", "__F"},
299 {"Windows_CFoundation_C", "__F"},
302 static char *format_parameterized_type_c_name(type_t
*type
, typeref_list_t
*params
, const char *prefix
, const char *separator
)
304 const char *tmp
, *ns_prefix
= "__x_", *abi_prefix
= NULL
;
305 size_t len
= 0, pos
= 0;
307 int i
, count
= params
? list_count(params
) : 0;
310 if (!strcmp(separator
, "__C")) ns_prefix
= "_C";
311 else if (use_abi_namespace
) abi_prefix
= "ABI";
313 pos
+= append_namespaces(&buf
, &len
, pos
, type
->namespace, ns_prefix
, separator
, "", abi_prefix
);
314 pos
+= strappend(&buf
, &len
, pos
, "%s%s_%d", prefix
, type
->name
, count
);
315 if (params
) LIST_FOR_EACH_ENTRY(ref
, params
, typeref_t
, entry
)
317 type
= type_pointer_get_root_type(ref
->type
);
318 if ((tmp
= type
->param_name
)) pos
+= strappend(&buf
, &len
, pos
, "_%s", tmp
);
319 else pos
+= append_namespaces(&buf
, &len
, pos
, type
->namespace, "_", "__C", type
->name
, NULL
);
322 for (i
= 0; i
< ARRAY_SIZE(parameterized_type_shorthands
); ++i
)
324 if ((tmp
= strstr(buf
, parameterized_type_shorthands
[i
][0])) &&
325 (tmp
- buf
) == strlen(ns_prefix
) + (abi_prefix
? 5 : 0))
327 tmp
+= strlen(parameterized_type_shorthands
[i
][0]);
328 strcpy(buf
, parameterized_type_shorthands
[i
][1]);
329 memmove(buf
+ 3, tmp
, len
- (tmp
- buf
));
336 static char *format_parameterized_type_signature(type_t
*type
, typeref_list_t
*params
)
338 size_t len
= 0, pos
= 0;
341 const struct uuid
*uuid
;
343 if (!(uuid
= get_attrp(type
->attrs
, ATTR_UUID
)))
344 error_loc_info(&type
->loc_info
, "cannot compute type signature, no uuid found for type %s.\n", type
->name
);
346 pos
+= strappend(&buf
, &len
, pos
, "pinterface({%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
347 uuid
->Data1
, uuid
->Data2
, uuid
->Data3
,
348 uuid
->Data4
[0], uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3],
349 uuid
->Data4
[4], uuid
->Data4
[5], uuid
->Data4
[6], uuid
->Data4
[7]);
350 if (params
) LIST_FOR_EACH_ENTRY(ref
, params
, typeref_t
, entry
)
352 pos
+= strappend(&buf
, &len
, pos
, ";");
353 pos
+= append_type_signature(&buf
, &len
, pos
, ref
->type
);
355 pos
+= strappend(&buf
, &len
, pos
, ")");
360 static char *format_parameterized_type_short_name(type_t
*type
, typeref_list_t
*params
, const char *prefix
)
362 size_t len
= 0, pos
= 0;
366 pos
+= strappend(&buf
, &len
, pos
, "%s%s", prefix
, type
->name
);
367 if (params
) LIST_FOR_EACH_ENTRY(ref
, params
, typeref_t
, entry
)
369 type
= type_pointer_get_root_type(ref
->type
);
370 if (type
->short_name
) pos
+= strappend(&buf
, &len
, pos
, "_%s", type
->short_name
);
371 else pos
+= strappend(&buf
, &len
, pos
, "_%s", type
->name
);
377 static char *format_parameterized_type_impl_name(type_t
*type
, typeref_list_t
*params
, const char *prefix
)
379 size_t len
= 0, pos
= 0;
384 pos
+= strappend(&buf
, &len
, pos
, "%s%s_impl<", prefix
, type
->name
);
385 if (params
) LIST_FOR_EACH_ENTRY(ref
, params
, typeref_t
, entry
)
387 type
= type_pointer_get_root_type(ref
->type
);
388 if (type
->type_type
== TYPE_RUNTIMECLASS
)
390 pos
+= strappend(&buf
, &len
, pos
, "ABI::Windows::Foundation::Internal::AggregateType<%s", type
->qualified_name
);
391 pos
+= append_pointer_stars(&buf
, &len
, pos
, ref
->type
);
392 iface
= type_runtimeclass_get_default_iface(type
, TRUE
);
393 pos
+= strappend(&buf
, &len
, pos
, ", %s", iface
->qualified_name
);
394 pos
+= append_pointer_stars(&buf
, &len
, pos
, ref
->type
);
395 pos
+= strappend(&buf
, &len
, pos
, " >");
399 pos
+= strappend(&buf
, &len
, pos
, "%s", type
->qualified_name
);
400 pos
+= append_pointer_stars(&buf
, &len
, pos
, ref
->type
);
402 if (list_next(params
, &ref
->entry
)) pos
+= strappend(&buf
, &len
, pos
, ", ");
404 pos
+= strappend(&buf
, &len
, pos
, " >");
409 type_t
*type_new_function(var_list_t
*args
)
417 arg
= LIST_ENTRY(list_head(args
), var_t
, entry
);
418 if (list_count(args
) == 1 && !arg
->name
&& arg
->declspec
.type
&& type_get_type(arg
->declspec
.type
) == TYPE_VOID
)
420 list_remove(&arg
->entry
);
426 if (args
) LIST_FOR_EACH_ENTRY(arg
, args
, var_t
, entry
)
428 if (arg
->declspec
.type
&& type_get_type(arg
->declspec
.type
) == TYPE_VOID
)
429 error_loc("argument '%s' has void type\n", arg
->name
);
433 error_loc("too many unnamed arguments\n");
440 name
[0] = i
> 26 ? 'a' + i
/ 26 : 'a' + i
;
441 name
[1] = i
> 26 ? 'a' + i
% 26 : 0;
443 unique
= !find_arg(args
, name
);
445 arg
->name
= xstrdup(name
);
452 t
= make_type(TYPE_FUNCTION
);
453 t
->details
.function
= xmalloc(sizeof(*t
->details
.function
));
454 t
->details
.function
->args
= args
;
455 t
->details
.function
->retval
= make_var(xstrdup("_RetVal"));
459 type_t
*type_new_pointer(type_t
*ref
)
461 type_t
*t
= make_type(TYPE_POINTER
);
462 t
->details
.pointer
.ref
.type
= ref
;
466 type_t
*type_new_alias(const decl_spec_t
*t
, const char *name
)
468 type_t
*a
= make_type(TYPE_ALIAS
);
470 a
->name
= xstrdup(name
);
472 a
->details
.alias
.aliasee
= *t
;
473 init_loc_info(&a
->loc_info
);
478 type_t
*type_new_array(const char *name
, const decl_spec_t
*element
, int declptr
,
479 unsigned int dim
, expr_t
*size_is
, expr_t
*length_is
)
481 type_t
*t
= make_type(TYPE_ARRAY
);
482 if (name
) t
->name
= xstrdup(name
);
483 t
->details
.array
.declptr
= declptr
;
484 t
->details
.array
.length_is
= length_is
;
486 t
->details
.array
.size_is
= size_is
;
488 t
->details
.array
.dim
= dim
;
490 t
->details
.array
.elem
= *element
;
494 type_t
*type_new_basic(enum type_basic_type basic_type
)
496 type_t
*t
= make_type(TYPE_BASIC
);
497 t
->details
.basic
.type
= basic_type
;
498 t
->details
.basic
.sign
= 0;
502 type_t
*type_new_int(enum type_basic_type basic_type
, int sign
)
504 static type_t
*int_types
[TYPE_BASIC_INT_MAX
+1][3];
506 assert(basic_type
<= TYPE_BASIC_INT_MAX
);
508 /* map sign { -1, 0, 1 } -> { 0, 1, 2 } */
509 if (!int_types
[basic_type
][sign
+ 1])
511 int_types
[basic_type
][sign
+ 1] = type_new_basic(basic_type
);
512 int_types
[basic_type
][sign
+ 1]->details
.basic
.sign
= sign
;
514 return int_types
[basic_type
][sign
+ 1];
517 type_t
*type_new_void(void)
519 static type_t
*void_type
= NULL
;
521 void_type
= make_type(TYPE_VOID
);
525 type_t
*type_new_enum(const char *name
, struct namespace *namespace, int defined
, var_list_t
*enums
)
530 t
= find_type(name
, namespace,tsENUM
);
534 t
= make_type(TYPE_ENUM
);
536 t
->namespace = namespace;
538 reg_type(t
, name
, namespace, tsENUM
);
541 if (!t
->defined
&& defined
)
543 t
->details
.enumeration
= xmalloc(sizeof(*t
->details
.enumeration
));
544 t
->details
.enumeration
->enums
= enums
;
548 error_loc("redefinition of enum %s\n", name
);
553 type_t
*type_new_struct(char *name
, struct namespace *namespace, int defined
, var_list_t
*fields
)
558 t
= find_type(name
, namespace, tsSTRUCT
);
562 t
= make_type(TYPE_STRUCT
);
564 t
->namespace = namespace;
566 reg_type(t
, name
, namespace, tsSTRUCT
);
569 if (!t
->defined
&& defined
)
571 t
->details
.structure
= xmalloc(sizeof(*t
->details
.structure
));
572 t
->details
.structure
->fields
= fields
;
576 error_loc("redefinition of struct %s\n", name
);
581 type_t
*type_new_nonencapsulated_union(const char *name
, int defined
, var_list_t
*fields
)
586 t
= find_type(name
, NULL
, tsUNION
);
590 t
= make_type(TYPE_UNION
);
593 reg_type(t
, name
, NULL
, tsUNION
);
596 if (!t
->defined
&& defined
)
598 t
->details
.structure
= xmalloc(sizeof(*t
->details
.structure
));
599 t
->details
.structure
->fields
= fields
;
603 error_loc("redefinition of union %s\n", name
);
608 type_t
*type_new_encapsulated_union(char *name
, var_t
*switch_field
, var_t
*union_field
, var_list_t
*cases
)
613 t
= find_type(name
, NULL
, tsUNION
);
617 t
= make_type(TYPE_ENCAPSULATED_UNION
);
620 reg_type(t
, name
, NULL
, tsUNION
);
622 t
->type_type
= TYPE_ENCAPSULATED_UNION
;
627 union_field
= make_var(xstrdup("tagged_union"));
628 union_field
->declspec
.type
= type_new_nonencapsulated_union(gen_name(), TRUE
, cases
);
630 t
->details
.structure
= xmalloc(sizeof(*t
->details
.structure
));
631 t
->details
.structure
->fields
= append_var(NULL
, switch_field
);
632 t
->details
.structure
->fields
= append_var(t
->details
.structure
->fields
, union_field
);
636 error_loc("redefinition of union %s\n", name
);
641 static int is_valid_bitfield_type(const type_t
*type
)
643 switch (type_get_type(type
))
648 switch (type_basic_get_type(type
))
650 case TYPE_BASIC_INT8
:
651 case TYPE_BASIC_INT16
:
652 case TYPE_BASIC_INT32
:
653 case TYPE_BASIC_INT64
:
655 case TYPE_BASIC_INT3264
:
656 case TYPE_BASIC_LONG
:
657 case TYPE_BASIC_CHAR
:
658 case TYPE_BASIC_HYPER
:
659 case TYPE_BASIC_BYTE
:
660 case TYPE_BASIC_WCHAR
:
661 case TYPE_BASIC_ERROR_STATUS_T
:
663 case TYPE_BASIC_FLOAT
:
664 case TYPE_BASIC_DOUBLE
:
665 case TYPE_BASIC_HANDLE
:
674 type_t
*type_new_bitfield(type_t
*field
, const expr_t
*bits
)
678 if (!is_valid_bitfield_type(field
))
679 error_loc("bit-field has invalid type\n");
682 error_loc("negative width for bit-field\n");
684 /* FIXME: validate bits->cval <= memsize(field) * 8 */
686 t
= make_type(TYPE_BITFIELD
);
687 t
->details
.bitfield
.field
= field
;
688 t
->details
.bitfield
.bits
= bits
;
692 static unsigned int compute_method_indexes(type_t
*iface
)
697 if (!iface
->details
.iface
)
700 if (type_iface_get_inherit(iface
))
701 idx
= compute_method_indexes(type_iface_get_inherit(iface
));
705 STATEMENTS_FOR_EACH_FUNC( stmt
, type_iface_get_stmts(iface
) )
707 var_t
*func
= stmt
->u
.var
;
708 if (!is_callas(func
->attrs
))
709 func
->func_idx
= idx
++;
715 type_t
*type_interface_declare(char *name
, struct namespace *namespace)
717 type_t
*type
= get_type(TYPE_INTERFACE
, name
, namespace, 0);
718 if (type_get_type_detect_alias(type
) != TYPE_INTERFACE
)
719 error_loc("interface %s previously not declared an interface at %s:%d\n",
720 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
724 type_t
*type_interface_define(type_t
*iface
, attr_list_t
*attrs
, type_t
*inherit
, statement_list_t
*stmts
, typeref_list_t
*requires
)
727 error_loc("interface %s already defined at %s:%d\n",
728 iface
->name
, iface
->loc_info
.input_name
, iface
->loc_info
.line_number
);
729 if (iface
== inherit
)
730 error_loc("interface %s can't inherit from itself\n",
732 iface
->attrs
= check_interface_attrs(iface
->name
, attrs
);
733 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
734 iface
->details
.iface
->disp_props
= NULL
;
735 iface
->details
.iface
->disp_methods
= NULL
;
736 iface
->details
.iface
->stmts
= stmts
;
737 iface
->details
.iface
->inherit
= inherit
;
738 iface
->details
.iface
->disp_inherit
= NULL
;
739 iface
->details
.iface
->async_iface
= NULL
;
740 iface
->details
.iface
->requires
= requires
;
741 iface
->defined
= TRUE
;
742 compute_method_indexes(iface
);
746 type_t
*type_dispinterface_declare(char *name
)
748 type_t
*type
= get_type(TYPE_INTERFACE
, name
, NULL
, 0);
749 if (type_get_type_detect_alias(type
) != TYPE_INTERFACE
)
750 error_loc("dispinterface %s previously not declared a dispinterface at %s:%d\n",
751 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
755 type_t
*type_dispinterface_define(type_t
*iface
, attr_list_t
*attrs
, var_list_t
*props
, var_list_t
*methods
)
758 error_loc("dispinterface %s already defined at %s:%d\n",
759 iface
->name
, iface
->loc_info
.input_name
, iface
->loc_info
.line_number
);
760 iface
->attrs
= check_dispiface_attrs(iface
->name
, attrs
);
761 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
762 iface
->details
.iface
->disp_props
= props
;
763 iface
->details
.iface
->disp_methods
= methods
;
764 iface
->details
.iface
->stmts
= NULL
;
765 iface
->details
.iface
->inherit
= find_type("IDispatch", NULL
, 0);
766 if (!iface
->details
.iface
->inherit
) error_loc("IDispatch is undefined\n");
767 iface
->details
.iface
->disp_inherit
= NULL
;
768 iface
->details
.iface
->async_iface
= NULL
;
769 iface
->details
.iface
->requires
= NULL
;
770 iface
->defined
= TRUE
;
771 compute_method_indexes(iface
);
775 type_t
*type_dispinterface_define_from_iface(type_t
*dispiface
, attr_list_t
*attrs
, type_t
*iface
)
777 if (dispiface
->defined
)
778 error_loc("dispinterface %s already defined at %s:%d\n",
779 dispiface
->name
, dispiface
->loc_info
.input_name
, dispiface
->loc_info
.line_number
);
780 dispiface
->attrs
= check_dispiface_attrs(dispiface
->name
, attrs
);
781 dispiface
->details
.iface
= xmalloc(sizeof(*dispiface
->details
.iface
));
782 dispiface
->details
.iface
->disp_props
= NULL
;
783 dispiface
->details
.iface
->disp_methods
= NULL
;
784 dispiface
->details
.iface
->stmts
= NULL
;
785 dispiface
->details
.iface
->inherit
= find_type("IDispatch", NULL
, 0);
786 if (!dispiface
->details
.iface
->inherit
) error_loc("IDispatch is undefined\n");
787 dispiface
->details
.iface
->disp_inherit
= iface
;
788 dispiface
->details
.iface
->async_iface
= NULL
;
789 dispiface
->details
.iface
->requires
= NULL
;
790 dispiface
->defined
= TRUE
;
791 compute_method_indexes(dispiface
);
795 type_t
*type_module_declare(char *name
)
797 type_t
*type
= get_type(TYPE_MODULE
, name
, NULL
, 0);
798 if (type_get_type_detect_alias(type
) != TYPE_MODULE
)
799 error_loc("module %s previously not declared a module at %s:%d\n",
800 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
804 type_t
*type_module_define(type_t
* module
, attr_list_t
*attrs
, statement_list_t
*stmts
)
807 error_loc("module %s already defined at %s:%d\n",
808 module
->name
, module
->loc_info
.input_name
, module
->loc_info
.line_number
);
809 module
->attrs
= check_module_attrs(module
->name
, attrs
);
810 module
->details
.module
= xmalloc(sizeof(*module
->details
.module
));
811 module
->details
.module
->stmts
= stmts
;
812 module
->defined
= TRUE
;
816 type_t
*type_coclass_declare(char *name
)
818 type_t
*type
= get_type(TYPE_COCLASS
, name
, NULL
, 0);
819 if (type_get_type_detect_alias(type
) != TYPE_COCLASS
)
820 error_loc("coclass %s previously not declared a coclass at %s:%d\n",
821 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
825 type_t
*type_coclass_define(type_t
*coclass
, attr_list_t
*attrs
, typeref_list_t
*ifaces
)
827 if (coclass
->defined
)
828 error_loc("coclass %s already defined at %s:%d\n",
829 coclass
->name
, coclass
->loc_info
.input_name
, coclass
->loc_info
.line_number
);
830 coclass
->attrs
= check_coclass_attrs(coclass
->name
, attrs
);
831 coclass
->details
.coclass
.ifaces
= ifaces
;
832 coclass
->defined
= TRUE
;
836 type_t
*type_runtimeclass_declare(char *name
, struct namespace *namespace)
838 type_t
*type
= get_type(TYPE_RUNTIMECLASS
, name
, namespace, 0);
839 if (type_get_type_detect_alias(type
) != TYPE_RUNTIMECLASS
)
840 error_loc("runtimeclass %s previously not declared a runtimeclass at %s:%d\n",
841 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
845 type_t
*type_runtimeclass_define(type_t
*runtimeclass
, attr_list_t
*attrs
, typeref_list_t
*ifaces
)
847 typeref_t
*ref
, *required
, *tmp
;
848 typeref_list_t
*requires
;
850 if (runtimeclass
->defined
)
851 error_loc("runtimeclass %s already defined at %s:%d\n",
852 runtimeclass
->name
, runtimeclass
->loc_info
.input_name
, runtimeclass
->loc_info
.line_number
);
853 runtimeclass
->attrs
= check_runtimeclass_attrs(runtimeclass
->name
, attrs
);
854 runtimeclass
->details
.runtimeclass
.ifaces
= ifaces
;
855 runtimeclass
->defined
= TRUE
;
856 if (!type_runtimeclass_get_default_iface(runtimeclass
, FALSE
) &&
857 !get_attrp(runtimeclass
->attrs
, ATTR_STATIC
))
858 error_loc("runtimeclass %s must have a default interface or static factory\n", runtimeclass
->name
);
860 if (ifaces
) LIST_FOR_EACH_ENTRY(ref
, ifaces
, typeref_t
, entry
)
862 /* FIXME: this should probably not be allowed, here or in coclass, */
863 /* but for now there's too many places in Wine IDL where it is to */
864 /* even print a warning. */
865 if (!(ref
->type
->defined
)) continue;
866 if (!(requires
= type_iface_get_requires(ref
->type
))) continue;
867 LIST_FOR_EACH_ENTRY(required
, requires
, typeref_t
, entry
)
871 LIST_FOR_EACH_ENTRY(tmp
, ifaces
, typeref_t
, entry
)
872 if ((found
= type_is_equal(tmp
->type
, required
->type
))) break;
875 error_loc("interface '%s' also requires interface '%s', "
876 "but runtimeclass '%s' does not implement it.\n",
877 ref
->type
->name
, required
->type
->name
, runtimeclass
->name
);
884 type_t
*type_apicontract_declare(char *name
, struct namespace *namespace)
886 type_t
*type
= get_type(TYPE_APICONTRACT
, name
, namespace, 0);
887 if (type_get_type_detect_alias(type
) != TYPE_APICONTRACT
)
888 error_loc("apicontract %s previously not declared a apicontract at %s:%d\n",
889 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
893 type_t
*type_apicontract_define(type_t
*apicontract
, attr_list_t
*attrs
)
895 if (apicontract
->defined
)
896 error_loc("apicontract %s already defined at %s:%d\n",
897 apicontract
->name
, apicontract
->loc_info
.input_name
, apicontract
->loc_info
.line_number
);
898 apicontract
->attrs
= check_apicontract_attrs(apicontract
->name
, attrs
);
899 apicontract
->defined
= TRUE
;
903 static void compute_delegate_iface_names(type_t
*delegate
, type_t
*type
, typeref_list_t
*params
)
905 type_t
*iface
= delegate
->details
.delegate
.iface
;
906 iface
->namespace = delegate
->namespace;
907 iface
->name
= strmake("I%s", delegate
->name
);
908 if (type
) iface
->c_name
= format_parameterized_type_c_name(type
, params
, "I", "_C");
909 else iface
->c_name
= format_namespace(delegate
->namespace, "__x_", "_C", iface
->name
, use_abi_namespace
? "ABI" : NULL
);
910 if (type
) iface
->param_name
= format_parameterized_type_c_name(type
, params
, "I", "__C");
911 else iface
->param_name
= format_namespace(delegate
->namespace, "_", "__C", iface
->name
, NULL
);
912 iface
->qualified_name
= format_namespace(delegate
->namespace, "", "::", iface
->name
, use_abi_namespace
? "ABI" : NULL
);
915 type_t
*type_delegate_declare(char *name
, struct namespace *namespace)
917 type_t
*type
= get_type(TYPE_DELEGATE
, name
, namespace, 0);
918 if (type_get_type_detect_alias(type
) != TYPE_DELEGATE
)
919 error_loc("delegate %s previously not declared a delegate at %s:%d\n",
920 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
924 type_t
*type_delegate_define(type_t
*delegate
, attr_list_t
*attrs
, statement_list_t
*stmts
)
928 if (delegate
->defined
)
929 error_loc("delegate %s already defined at %s:%d\n",
930 delegate
->name
, delegate
->loc_info
.input_name
, delegate
->loc_info
.line_number
);
932 delegate
->attrs
= check_interface_attrs(delegate
->name
, attrs
);
934 iface
= make_type(TYPE_INTERFACE
);
935 iface
->attrs
= delegate
->attrs
;
936 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
937 iface
->details
.iface
->disp_props
= NULL
;
938 iface
->details
.iface
->disp_methods
= NULL
;
939 iface
->details
.iface
->stmts
= stmts
;
940 iface
->details
.iface
->inherit
= find_type("IUnknown", NULL
, 0);
941 if (!iface
->details
.iface
->inherit
) error_loc("IUnknown is undefined\n");
942 iface
->details
.iface
->disp_inherit
= NULL
;
943 iface
->details
.iface
->async_iface
= NULL
;
944 iface
->details
.iface
->requires
= NULL
;
945 iface
->defined
= TRUE
;
946 compute_method_indexes(iface
);
948 delegate
->details
.delegate
.iface
= iface
;
949 delegate
->defined
= TRUE
;
950 compute_delegate_iface_names(delegate
, NULL
, NULL
);
955 type_t
*type_parameterized_interface_declare(char *name
, struct namespace *namespace, typeref_list_t
*params
)
957 type_t
*type
= get_type(TYPE_PARAMETERIZED_TYPE
, name
, namespace, 0);
958 if (type_get_type_detect_alias(type
) != TYPE_PARAMETERIZED_TYPE
)
959 error_loc("pinterface %s previously not declared a pinterface at %s:%d\n",
960 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
961 type
->details
.parameterized
.type
= make_type(TYPE_INTERFACE
);
962 type
->details
.parameterized
.params
= params
;
966 type_t
*type_parameterized_interface_define(type_t
*type
, attr_list_t
*attrs
, type_t
*inherit
, statement_list_t
*stmts
, typeref_list_t
*requires
)
970 error_loc("pinterface %s already defined at %s:%d\n",
971 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
973 /* The parameterized type UUID is actually a PIID that is then used as a seed to generate
974 * a new type GUID with the rules described in:
975 * https://docs.microsoft.com/en-us/uwp/winrt-cref/winrt-type-system#parameterized-types
976 * TODO: store type signatures for generated interfaces, and generate their GUIDs
978 type
->attrs
= check_interface_attrs(type
->name
, attrs
);
980 iface
= type
->details
.parameterized
.type
;
981 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
982 iface
->details
.iface
->disp_props
= NULL
;
983 iface
->details
.iface
->disp_methods
= NULL
;
984 iface
->details
.iface
->stmts
= stmts
;
985 iface
->details
.iface
->inherit
= inherit
;
986 iface
->details
.iface
->disp_inherit
= NULL
;
987 iface
->details
.iface
->async_iface
= NULL
;
988 iface
->details
.iface
->requires
= requires
;
990 iface
->name
= type
->name
;
992 type
->defined
= TRUE
;
996 type_t
*type_parameterized_delegate_declare(char *name
, struct namespace *namespace, typeref_list_t
*params
)
998 type_t
*type
= get_type(TYPE_PARAMETERIZED_TYPE
, name
, namespace, 0);
999 if (type_get_type_detect_alias(type
) != TYPE_PARAMETERIZED_TYPE
)
1000 error_loc("pdelegate %s previously not declared a pdelegate at %s:%d\n",
1001 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
1002 type
->details
.parameterized
.type
= make_type(TYPE_DELEGATE
);
1003 type
->details
.parameterized
.params
= params
;
1007 type_t
*type_parameterized_delegate_define(type_t
*type
, attr_list_t
*attrs
, statement_list_t
*stmts
)
1009 type_t
*iface
, *delegate
;
1012 error_loc("pdelegate %s already defined at %s:%d\n",
1013 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
1015 type
->attrs
= check_interface_attrs(type
->name
, attrs
);
1017 delegate
= type
->details
.parameterized
.type
;
1018 delegate
->attrs
= type
->attrs
;
1019 delegate
->details
.delegate
.iface
= make_type(TYPE_INTERFACE
);
1021 iface
= delegate
->details
.delegate
.iface
;
1022 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
1023 iface
->details
.iface
->disp_props
= NULL
;
1024 iface
->details
.iface
->disp_methods
= NULL
;
1025 iface
->details
.iface
->stmts
= stmts
;
1026 iface
->details
.iface
->inherit
= find_type("IUnknown", NULL
, 0);
1027 if (!iface
->details
.iface
->inherit
) error_loc("IUnknown is undefined\n");
1028 iface
->details
.iface
->disp_inherit
= NULL
;
1029 iface
->details
.iface
->async_iface
= NULL
;
1030 iface
->details
.iface
->requires
= NULL
;
1032 delegate
->name
= type
->name
;
1033 compute_delegate_iface_names(delegate
, type
, type
->details
.parameterized
.params
);
1035 type
->defined
= TRUE
;
1039 type_t
*type_parameterized_type_specialize_partial(type_t
*type
, typeref_list_t
*params
)
1041 type_t
*new_type
= duptype(type
, 0);
1042 new_type
->details
.parameterized
.type
= type
;
1043 new_type
->details
.parameterized
.params
= params
;
1047 static type_t
*replace_type_parameters_in_type(type_t
*type
, typeref_list_t
*orig
, typeref_list_t
*repl
);
1049 static typeref_list_t
*replace_type_parameters_in_type_list(typeref_list_t
*list
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1051 typeref_list_t
*new_list
= NULL
;
1054 if (!list
) return list
;
1056 LIST_FOR_EACH_ENTRY(ref
, list
, typeref_t
, entry
)
1058 type_t
*new_type
= replace_type_parameters_in_type(ref
->type
, orig
, repl
);
1059 new_list
= append_typeref(new_list
, make_typeref(new_type
));
1065 static var_t
*replace_type_parameters_in_var(var_t
*var
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1067 var_t
*new_var
= xmalloc(sizeof(*new_var
));
1069 list_init(&new_var
->entry
);
1070 new_var
->declspec
.type
= replace_type_parameters_in_type(var
->declspec
.type
, orig
, repl
);
1074 static var_list_t
*replace_type_parameters_in_var_list(var_list_t
*var_list
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1076 var_list_t
*new_var_list
;
1077 var_t
*var
, *new_var
;
1079 if (!var_list
) return var_list
;
1081 new_var_list
= xmalloc(sizeof(*new_var_list
));
1082 list_init(new_var_list
);
1084 LIST_FOR_EACH_ENTRY(var
, var_list
, var_t
, entry
)
1086 new_var
= replace_type_parameters_in_var(var
, orig
, repl
);
1087 list_add_tail(new_var_list
, &new_var
->entry
);
1090 return new_var_list
;
1093 static statement_t
*replace_type_parameters_in_statement(statement_t
*stmt
, typeref_list_t
*orig
, typeref_list_t
*repl
, loc_info_t
*loc
)
1095 statement_t
*new_stmt
= xmalloc(sizeof(*new_stmt
));
1097 list_init(&new_stmt
->entry
);
1101 case STMT_DECLARATION
:
1102 new_stmt
->u
.var
= replace_type_parameters_in_var(stmt
->u
.var
, orig
, repl
);
1106 new_stmt
->u
.type
= replace_type_parameters_in_type(stmt
->u
.type
, orig
, repl
);
1109 new_stmt
->u
.type_list
= replace_type_parameters_in_type_list(stmt
->u
.type_list
, orig
, repl
);
1114 case STMT_IMPORTLIB
:
1117 error_loc_info(loc
, "unimplemented parameterized type replacement for statement type %d.\n", stmt
->type
);
1124 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
)
1126 statement_list_t
*new_stmt_list
;
1127 statement_t
*stmt
, *new_stmt
;
1129 if (!stmt_list
) return stmt_list
;
1131 new_stmt_list
= xmalloc(sizeof(*new_stmt_list
));
1132 list_init(new_stmt_list
);
1134 LIST_FOR_EACH_ENTRY(stmt
, stmt_list
, statement_t
, entry
)
1136 new_stmt
= replace_type_parameters_in_statement(stmt
, orig
, repl
, loc
);
1137 list_add_tail(new_stmt_list
, &new_stmt
->entry
);
1140 return new_stmt_list
;
1143 static type_t
*replace_type_parameters_in_type(type_t
*type
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1148 if (!type
) return type
;
1149 switch (type
->type_type
)
1155 case TYPE_INTERFACE
:
1156 case TYPE_RUNTIMECLASS
:
1159 case TYPE_PARAMETER
:
1160 if (!orig
|| !repl
) return NULL
;
1161 for (o
= list_head(orig
), r
= list_head(repl
); o
&& r
;
1162 o
= list_next(orig
, o
), r
= list_next(repl
, r
))
1163 if (type
== LIST_ENTRY(o
, typeref_t
, entry
)->type
)
1164 return LIST_ENTRY(r
, typeref_t
, entry
)->type
;
1167 t
= replace_type_parameters_in_type(type
->details
.pointer
.ref
.type
, orig
, repl
);
1168 if (t
== type
->details
.pointer
.ref
.type
) return type
;
1169 type
= duptype(type
, 0);
1170 type
->details
.pointer
.ref
.type
= t
;
1173 t
= replace_type_parameters_in_type(type
->details
.alias
.aliasee
.type
, orig
, repl
);
1174 if (t
== type
->details
.alias
.aliasee
.type
) return type
;
1175 type
= duptype(type
, 0);
1176 type
->details
.alias
.aliasee
.type
= t
;
1179 t
= replace_type_parameters_in_type(type
->details
.array
.elem
.type
, orig
, repl
);
1180 if (t
== t
->details
.array
.elem
.type
) return type
;
1181 type
= duptype(type
, 0);
1182 t
->details
.array
.elem
.type
= t
;
1185 t
= duptype(type
, 0);
1186 t
->details
.function
= xmalloc(sizeof(*t
->details
.function
));
1187 t
->details
.function
->args
= replace_type_parameters_in_var_list(type
->details
.function
->args
, orig
, repl
);
1188 t
->details
.function
->retval
= replace_type_parameters_in_var(type
->details
.function
->retval
, orig
, repl
);
1190 case TYPE_PARAMETERIZED_TYPE
:
1191 t
= type
->details
.parameterized
.type
;
1192 if (t
->type_type
!= TYPE_PARAMETERIZED_TYPE
) return find_parameterized_type(type
, repl
);
1193 repl
= replace_type_parameters_in_type_list(type
->details
.parameterized
.params
, orig
, repl
);
1194 return replace_type_parameters_in_type(t
, t
->details
.parameterized
.params
, repl
);
1196 case TYPE_ENCAPSULATED_UNION
:
1200 case TYPE_APICONTRACT
:
1201 error_loc_info(&type
->loc_info
, "unimplemented parameterized type replacement for type %s of type %d.\n", type
->name
, type
->type_type
);
1208 static void type_parameterized_interface_specialize(type_t
*tmpl
, type_t
*iface
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1210 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
1211 iface
->details
.iface
->disp_methods
= NULL
;
1212 iface
->details
.iface
->disp_props
= NULL
;
1213 iface
->details
.iface
->stmts
= replace_type_parameters_in_statement_list(tmpl
->details
.iface
->stmts
, orig
, repl
, &tmpl
->loc_info
);
1214 iface
->details
.iface
->inherit
= replace_type_parameters_in_type(tmpl
->details
.iface
->inherit
, orig
, repl
);
1215 iface
->details
.iface
->disp_inherit
= NULL
;
1216 iface
->details
.iface
->async_iface
= NULL
;
1217 iface
->details
.iface
->requires
= NULL
;
1220 static void type_parameterized_delegate_specialize(type_t
*tmpl
, type_t
*delegate
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1222 type_parameterized_interface_specialize(tmpl
->details
.delegate
.iface
, delegate
->details
.delegate
.iface
, orig
, repl
);
1225 type_t
*type_parameterized_type_specialize_declare(type_t
*type
, typeref_list_t
*params
)
1227 type_t
*tmpl
= type
->details
.parameterized
.type
;
1228 type_t
*new_type
= duptype(tmpl
, 0);
1230 new_type
->namespace = type
->namespace;
1231 new_type
->name
= format_parameterized_type_name(type
, params
);
1232 reg_type(new_type
, new_type
->name
, new_type
->namespace, 0);
1233 new_type
->c_name
= format_parameterized_type_c_name(type
, params
, "", "_C");
1234 new_type
->short_name
= format_parameterized_type_short_name(type
, params
, "");
1235 new_type
->param_name
= format_parameterized_type_c_name(type
, params
, "", "__C");
1237 if (new_type
->type_type
== TYPE_DELEGATE
)
1239 new_type
->details
.delegate
.iface
= duptype(tmpl
->details
.delegate
.iface
, 0);
1240 compute_delegate_iface_names(new_type
, type
, params
);
1241 new_type
->details
.delegate
.iface
->short_name
= format_parameterized_type_short_name(type
, params
, "I");
1247 static void compute_interface_signature_uuid(type_t
*iface
)
1249 static const char winrt_pinterface_namespace
[] = {0x11,0xf4,0x7a,0xd5,0x7b,0x73,0x42,0xc0,0xab,0xae,0x87,0x8b,0x1e,0x16,0xad,0xee};
1250 static const int version
= 5;
1251 struct sha1_context ctx
;
1252 unsigned char hash
[20];
1255 if (!(uuid
= get_attrp(iface
->attrs
, ATTR_UUID
)))
1257 uuid
= xmalloc(sizeof(*uuid
));
1258 iface
->attrs
= append_attr(iface
->attrs
, make_attrp(ATTR_UUID
, uuid
));
1262 sha1_update(&ctx
, winrt_pinterface_namespace
, sizeof(winrt_pinterface_namespace
));
1263 sha1_update(&ctx
, iface
->signature
, strlen(iface
->signature
));
1264 sha1_finalize(&ctx
, (unsigned int *)hash
);
1266 /* https://tools.ietf.org/html/rfc4122:
1268 * Set the four most significant bits (bits 12 through 15) of the
1269 time_hi_and_version field to the appropriate 4-bit version number
1272 * Set the two most significant bits (bits 6 and 7) of the
1273 clock_seq_hi_and_reserved to zero and one, respectively.
1276 hash
[6] = ((hash
[6] & 0x0f) | (version
<< 4));
1277 hash
[8] = ((hash
[8] & 0x3f) | 0x80);
1279 uuid
->Data1
= ((unsigned int)hash
[0] << 24) | ((unsigned int)hash
[1] << 16) | ((unsigned int)hash
[2] << 8) | hash
[3];
1280 uuid
->Data2
= ((unsigned short)hash
[4] << 8) | hash
[5];
1281 uuid
->Data3
= ((unsigned short)hash
[6] << 8) | hash
[7];
1282 memcpy(&uuid
->Data4
, hash
+ 8, sizeof(*uuid
) - offsetof(struct uuid
, Data4
));
1285 type_t
*type_parameterized_type_specialize_define(type_t
*type
)
1287 type_t
*tmpl
= type
->details
.parameterized
.type
;
1288 typeref_list_t
*orig
= tmpl
->details
.parameterized
.params
;
1289 typeref_list_t
*repl
= type
->details
.parameterized
.params
;
1290 type_t
*iface
= find_parameterized_type(tmpl
, repl
);
1292 if (type_get_type_detect_alias(type
) != TYPE_PARAMETERIZED_TYPE
||
1293 type_get_type_detect_alias(tmpl
) != TYPE_PARAMETERIZED_TYPE
)
1294 error_loc("cannot define non-parameterized type %s, declared at %s:%d\n",
1295 type
->name
, type
->loc_info
.input_name
, type
->loc_info
.line_number
);
1297 if (type_get_type_detect_alias(tmpl
->details
.parameterized
.type
) == TYPE_INTERFACE
&&
1298 type_get_type_detect_alias(iface
) == TYPE_INTERFACE
)
1299 type_parameterized_interface_specialize(tmpl
->details
.parameterized
.type
, iface
, orig
, repl
);
1300 else if (type_get_type_detect_alias(tmpl
->details
.parameterized
.type
) == TYPE_DELEGATE
&&
1301 type_get_type_detect_alias(iface
) == TYPE_DELEGATE
)
1302 type_parameterized_delegate_specialize(tmpl
->details
.parameterized
.type
, iface
, orig
, repl
);
1304 error_loc("pinterface/pdelegate %s previously not declared a pinterface/pdelegate at %s:%d\n",
1305 iface
->name
, iface
->loc_info
.input_name
, iface
->loc_info
.line_number
);
1307 iface
->impl_name
= format_parameterized_type_impl_name(type
, repl
, "");
1308 iface
->signature
= format_parameterized_type_signature(type
, repl
);
1309 iface
->defined
= TRUE
;
1310 if (iface
->type_type
== TYPE_DELEGATE
)
1312 iface
= iface
->details
.delegate
.iface
;
1313 iface
->impl_name
= format_parameterized_type_impl_name(type
, repl
, "I");
1314 iface
->signature
= format_parameterized_type_signature(type
, repl
);
1315 iface
->defined
= TRUE
;
1317 compute_interface_signature_uuid(iface
);
1318 compute_method_indexes(iface
);
1322 int type_is_equal(const type_t
*type1
, const type_t
*type2
)
1326 if (type_get_type_detect_alias(type1
) != type_get_type_detect_alias(type2
))
1328 if (type1
->namespace != type2
->namespace)
1331 if (type1
->name
&& type2
->name
)
1332 return !strcmp(type1
->name
, type2
->name
);
1333 else if ((!type1
->name
&& type2
->name
) || (type1
->name
&& !type2
->name
))
1336 /* FIXME: do deep inspection of types to determine if they are equal */