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_location( &t
->where
, NULL
, NULL
);
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_at( &type
->where
, "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
, "GUID")) n
+= strappend(buf
, len
, pos
+ n
, "g16");
202 else if (!strcmp(type
->name
, "HSTRING")) n
+= strappend(buf
, len
, pos
+ n
, "string");
203 else n
+= append_type_signature(buf
, len
, pos
+ n
, type
->details
.alias
.aliasee
.type
);
206 n
+= strappend(buf
, len
, pos
+ n
, "struct(");
207 n
+= append_namespaces(buf
, len
, pos
+ n
, type
->namespace, "", ".", type
->name
, NULL
);
208 n
+= append_var_list_signature(buf
, len
, pos
+ n
, type
->details
.structure
->fields
);
209 n
+= strappend(buf
, len
, pos
+ n
, ")");
212 switch (type_basic_get_type(type
))
214 case TYPE_BASIC_INT16
:
215 n
+= strappend(buf
, len
, pos
+ n
, type_basic_get_sign(type
) <= 0 ? "i2" : "u2");
218 case TYPE_BASIC_INT32
:
219 case TYPE_BASIC_LONG
:
220 n
+= strappend(buf
, len
, pos
+ n
, type_basic_get_sign(type
) <= 0 ? "i4" : "u4");
222 case TYPE_BASIC_INT64
:
223 n
+= strappend(buf
, len
, pos
+ n
, type_basic_get_sign(type
) <= 0 ? "i8" : "u8");
225 case TYPE_BASIC_INT8
:
226 assert(type_basic_get_sign(type
) > 0); /* signature string for signed char isn't specified */
227 n
+= strappend(buf
, len
, pos
+ n
, "u1");
229 case TYPE_BASIC_FLOAT
:
230 n
+= strappend(buf
, len
, pos
+ n
, "f4");
232 case TYPE_BASIC_DOUBLE
:
233 n
+= strappend(buf
, len
, pos
+ n
, "f8");
235 case TYPE_BASIC_BYTE
:
236 n
+= strappend(buf
, len
, pos
+ n
, "u1");
238 case TYPE_BASIC_INT3264
:
239 case TYPE_BASIC_CHAR
:
240 case TYPE_BASIC_HYPER
:
241 case TYPE_BASIC_WCHAR
:
242 case TYPE_BASIC_ERROR_STATUS_T
:
243 case TYPE_BASIC_HANDLE
:
244 error_at( &type
->where
, "unimplemented type signature for basic type %d.\n",
245 type_basic_get_type( type
) );
249 n
+= strappend(buf
, len
, pos
+ n
, "enum(");
250 n
+= append_namespaces(buf
, len
, pos
+ n
, type
->namespace, "", ".", type
->name
, NULL
);
251 if (is_attr(type
->attrs
, ATTR_FLAGS
)) n
+= strappend(buf
, len
, pos
+ n
, ";u4");
252 else n
+= strappend(buf
, len
, pos
+ n
, ";i4");
253 n
+= strappend(buf
, len
, pos
+ n
, ")");
256 case TYPE_ENCAPSULATED_UNION
:
263 case TYPE_APICONTRACT
:
264 error_at( &type
->where
, "unimplemented type signature for type %s of type %d.\n",
265 type
->name
, type
->type_type
);
267 case TYPE_PARAMETERIZED_TYPE
:
269 assert(0); /* should not be there */
276 char *format_namespace(struct namespace *namespace, const char *prefix
, const char *separator
, const char *suffix
, const char *abi_prefix
)
280 append_namespaces(&buf
, &len
, 0, namespace, prefix
, separator
, suffix
, abi_prefix
);
284 char *format_parameterized_type_name(type_t
*type
, typeref_list_t
*params
)
286 size_t len
= 0, pos
= 0;
290 pos
+= strappend(&buf
, &len
, pos
, "%s<", type
->name
);
291 if (params
) LIST_FOR_EACH_ENTRY(ref
, params
, typeref_t
, entry
)
293 type
= type_pointer_get_root_type(ref
->type
);
294 pos
+= strappend(&buf
, &len
, pos
, "%s", type
->qualified_name
);
295 pos
+= append_pointer_stars(&buf
, &len
, pos
, ref
->type
);
296 if (list_next(params
, &ref
->entry
)) pos
+= strappend(&buf
, &len
, pos
, ",");
298 pos
+= strappend(&buf
, &len
, pos
, " >");
303 static char const *parameterized_type_shorthands
[][2] = {
304 {"Windows__CFoundation__CCollections__C", "__F"},
305 {"Windows_CFoundation_CCollections_C", "__F"},
306 {"Windows__CFoundation__C", "__F"},
307 {"Windows_CFoundation_C", "__F"},
310 static char *format_parameterized_type_c_name(type_t
*type
, typeref_list_t
*params
, const char *prefix
, const char *separator
)
312 const char *tmp
, *ns_prefix
= "__x_", *abi_prefix
= NULL
;
313 size_t len
= 0, pos
= 0;
315 int i
, count
= params
? list_count(params
) : 0;
318 if (!strcmp(separator
, "__C")) ns_prefix
= "_C";
319 else if (use_abi_namespace
) abi_prefix
= "ABI";
321 pos
+= append_namespaces(&buf
, &len
, pos
, type
->namespace, ns_prefix
, separator
, "", abi_prefix
);
322 pos
+= strappend(&buf
, &len
, pos
, "%s%s_%d", prefix
, type
->name
, count
);
323 if (params
) LIST_FOR_EACH_ENTRY(ref
, params
, typeref_t
, entry
)
325 type
= type_pointer_get_root_type(ref
->type
);
326 if ((tmp
= type
->param_name
)) pos
+= strappend(&buf
, &len
, pos
, "_%s", tmp
);
327 else pos
+= append_namespaces(&buf
, &len
, pos
, type
->namespace, "_", "__C", type
->name
, NULL
);
330 for (i
= 0; i
< ARRAY_SIZE(parameterized_type_shorthands
); ++i
)
332 if ((tmp
= strstr(buf
, parameterized_type_shorthands
[i
][0])) &&
333 (tmp
- buf
) == strlen(ns_prefix
) + (abi_prefix
? 5 : 0))
335 tmp
+= strlen(parameterized_type_shorthands
[i
][0]);
336 strcpy(buf
, parameterized_type_shorthands
[i
][1]);
337 memmove(buf
+ 3, tmp
, len
- (tmp
- buf
));
344 static char *format_parameterized_type_signature(type_t
*type
, typeref_list_t
*params
)
346 size_t len
= 0, pos
= 0;
349 const struct uuid
*uuid
;
351 if (!(uuid
= get_attrp( type
->attrs
, ATTR_UUID
)))
352 error_at( &type
->where
, "cannot compute type signature, no uuid found for type %s.\n", type
->name
);
354 pos
+= strappend(&buf
, &len
, pos
, "pinterface({%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
355 uuid
->Data1
, uuid
->Data2
, uuid
->Data3
,
356 uuid
->Data4
[0], uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3],
357 uuid
->Data4
[4], uuid
->Data4
[5], uuid
->Data4
[6], uuid
->Data4
[7]);
358 if (params
) LIST_FOR_EACH_ENTRY(ref
, params
, typeref_t
, entry
)
360 pos
+= strappend(&buf
, &len
, pos
, ";");
361 pos
+= append_type_signature(&buf
, &len
, pos
, ref
->type
);
363 pos
+= strappend(&buf
, &len
, pos
, ")");
368 static char *format_parameterized_type_short_name(type_t
*type
, typeref_list_t
*params
, const char *prefix
)
370 size_t len
= 0, pos
= 0;
374 pos
+= strappend(&buf
, &len
, pos
, "%s%s", prefix
, type
->name
);
375 if (params
) LIST_FOR_EACH_ENTRY(ref
, params
, typeref_t
, entry
)
377 type
= type_pointer_get_root_type(ref
->type
);
378 if (type
->short_name
) pos
+= strappend(&buf
, &len
, pos
, "_%s", type
->short_name
);
379 else pos
+= strappend(&buf
, &len
, pos
, "_%s", type
->name
);
385 static char *format_parameterized_type_impl_name(type_t
*type
, typeref_list_t
*params
, const char *prefix
)
387 size_t len
= 0, pos
= 0;
392 pos
+= strappend(&buf
, &len
, pos
, "%s%s_impl<", prefix
, type
->name
);
393 if (params
) LIST_FOR_EACH_ENTRY(ref
, params
, typeref_t
, entry
)
395 type
= type_pointer_get_root_type(ref
->type
);
396 if (type
->type_type
== TYPE_RUNTIMECLASS
)
398 pos
+= strappend(&buf
, &len
, pos
, "ABI::Windows::Foundation::Internal::AggregateType<%s", type
->qualified_name
);
399 pos
+= append_pointer_stars(&buf
, &len
, pos
, ref
->type
);
400 iface
= type_runtimeclass_get_default_iface(type
, TRUE
);
401 pos
+= strappend(&buf
, &len
, pos
, ", %s", iface
->qualified_name
);
402 pos
+= append_pointer_stars(&buf
, &len
, pos
, ref
->type
);
403 pos
+= strappend(&buf
, &len
, pos
, " >");
407 pos
+= strappend(&buf
, &len
, pos
, "%s", type
->qualified_name
);
408 pos
+= append_pointer_stars(&buf
, &len
, pos
, ref
->type
);
410 if (list_next(params
, &ref
->entry
)) pos
+= strappend(&buf
, &len
, pos
, ", ");
412 pos
+= strappend(&buf
, &len
, pos
, " >");
417 type_t
*type_new_function(var_list_t
*args
)
425 arg
= LIST_ENTRY(list_head(args
), var_t
, entry
);
426 if (list_count(args
) == 1 && !arg
->name
&& arg
->declspec
.type
&& type_get_type(arg
->declspec
.type
) == TYPE_VOID
)
428 list_remove(&arg
->entry
);
434 if (args
) LIST_FOR_EACH_ENTRY(arg
, args
, var_t
, entry
)
436 if (arg
->declspec
.type
&& type_get_type(arg
->declspec
.type
) == TYPE_VOID
)
437 error_loc("argument '%s' has void type\n", arg
->name
);
441 error_loc("too many unnamed arguments\n");
448 name
[0] = i
> 26 ? 'a' + i
/ 26 : 'a' + i
;
449 name
[1] = i
> 26 ? 'a' + i
% 26 : 0;
451 unique
= !find_arg(args
, name
);
453 arg
->name
= xstrdup(name
);
460 t
= make_type(TYPE_FUNCTION
);
461 t
->details
.function
= xmalloc(sizeof(*t
->details
.function
));
462 t
->details
.function
->args
= args
;
463 t
->details
.function
->retval
= make_var(xstrdup("_RetVal"));
467 type_t
*type_new_pointer(type_t
*ref
)
469 type_t
*t
= make_type(TYPE_POINTER
);
470 t
->details
.pointer
.ref
.type
= ref
;
474 type_t
*type_new_alias(const decl_spec_t
*t
, const char *name
)
476 type_t
*a
= make_type(TYPE_ALIAS
);
478 a
->name
= xstrdup(name
);
480 a
->details
.alias
.aliasee
= *t
;
481 init_location( &a
->where
, NULL
, NULL
);
486 type_t
*type_new_array(const char *name
, const decl_spec_t
*element
, int declptr
,
487 unsigned int dim
, expr_t
*size_is
, expr_t
*length_is
)
489 type_t
*t
= make_type(TYPE_ARRAY
);
490 if (name
) t
->name
= xstrdup(name
);
491 t
->details
.array
.declptr
= declptr
;
492 t
->details
.array
.length_is
= length_is
;
494 t
->details
.array
.size_is
= size_is
;
496 t
->details
.array
.dim
= dim
;
498 t
->details
.array
.elem
= *element
;
502 type_t
*type_new_basic(enum type_basic_type basic_type
)
504 type_t
*t
= make_type(TYPE_BASIC
);
505 t
->details
.basic
.type
= basic_type
;
506 t
->details
.basic
.sign
= 0;
510 type_t
*type_new_int(enum type_basic_type basic_type
, int sign
)
512 static type_t
*int_types
[TYPE_BASIC_INT_MAX
+1][3];
514 assert(basic_type
<= TYPE_BASIC_INT_MAX
);
516 /* map sign { -1, 0, 1 } -> { 0, 1, 2 } */
517 if (!int_types
[basic_type
][sign
+ 1])
519 int_types
[basic_type
][sign
+ 1] = type_new_basic(basic_type
);
520 int_types
[basic_type
][sign
+ 1]->details
.basic
.sign
= sign
;
522 return int_types
[basic_type
][sign
+ 1];
525 type_t
*type_new_void(void)
527 static type_t
*void_type
= NULL
;
529 void_type
= make_type(TYPE_VOID
);
533 type_t
*type_new_enum(const char *name
, struct namespace *namespace, int defined
, var_list_t
*enums
)
538 t
= find_type(name
, namespace,tsENUM
);
542 t
= make_type(TYPE_ENUM
);
544 t
->namespace = namespace;
546 reg_type(t
, name
, namespace, tsENUM
);
549 if (!t
->defined
&& defined
)
551 t
->details
.enumeration
= xmalloc(sizeof(*t
->details
.enumeration
));
552 t
->details
.enumeration
->enums
= enums
;
556 error_loc("redefinition of enum %s\n", name
);
561 type_t
*type_new_struct(char *name
, struct namespace *namespace, int defined
, var_list_t
*fields
)
566 t
= find_type(name
, namespace, tsSTRUCT
);
570 t
= make_type(TYPE_STRUCT
);
572 t
->namespace = namespace;
574 reg_type(t
, name
, namespace, tsSTRUCT
);
577 if (!t
->defined
&& defined
)
579 t
->details
.structure
= xmalloc(sizeof(*t
->details
.structure
));
580 t
->details
.structure
->fields
= fields
;
584 error_loc("redefinition of struct %s\n", name
);
589 type_t
*type_new_nonencapsulated_union(const char *name
, struct namespace *namespace, int defined
, var_list_t
*fields
)
594 t
= find_type(name
, namespace, tsUNION
);
598 t
= make_type(TYPE_UNION
);
600 t
->namespace = namespace;
602 reg_type(t
, name
, namespace, tsUNION
);
605 if (!t
->defined
&& defined
)
607 t
->details
.structure
= xmalloc(sizeof(*t
->details
.structure
));
608 t
->details
.structure
->fields
= fields
;
612 error_loc("redefinition of union %s\n", name
);
617 type_t
*type_new_encapsulated_union(char *name
, var_t
*switch_field
, var_t
*union_field
, var_list_t
*cases
)
622 t
= find_type(name
, NULL
, tsUNION
);
626 t
= make_type(TYPE_ENCAPSULATED_UNION
);
629 reg_type(t
, name
, NULL
, tsUNION
);
631 t
->type_type
= TYPE_ENCAPSULATED_UNION
;
636 union_field
= make_var(xstrdup("tagged_union"));
637 union_field
->declspec
.type
= type_new_nonencapsulated_union(gen_name(), NULL
, TRUE
, cases
);
639 t
->details
.structure
= xmalloc(sizeof(*t
->details
.structure
));
640 t
->details
.structure
->fields
= append_var(NULL
, switch_field
);
641 t
->details
.structure
->fields
= append_var(t
->details
.structure
->fields
, union_field
);
645 error_loc("redefinition of union %s\n", name
);
650 static int is_valid_bitfield_type(const type_t
*type
)
652 switch (type_get_type(type
))
657 switch (type_basic_get_type(type
))
659 case TYPE_BASIC_INT8
:
660 case TYPE_BASIC_INT16
:
661 case TYPE_BASIC_INT32
:
662 case TYPE_BASIC_INT64
:
664 case TYPE_BASIC_INT3264
:
665 case TYPE_BASIC_LONG
:
666 case TYPE_BASIC_CHAR
:
667 case TYPE_BASIC_HYPER
:
668 case TYPE_BASIC_BYTE
:
669 case TYPE_BASIC_WCHAR
:
670 case TYPE_BASIC_ERROR_STATUS_T
:
672 case TYPE_BASIC_FLOAT
:
673 case TYPE_BASIC_DOUBLE
:
674 case TYPE_BASIC_HANDLE
:
683 type_t
*type_new_bitfield(type_t
*field
, const expr_t
*bits
)
687 if (!is_valid_bitfield_type(field
))
688 error_loc("bit-field has invalid type\n");
691 error_loc("negative width for bit-field\n");
693 /* FIXME: validate bits->cval <= memsize(field) * 8 */
695 t
= make_type(TYPE_BITFIELD
);
696 t
->details
.bitfield
.field
= field
;
697 t
->details
.bitfield
.bits
= bits
;
701 static unsigned int compute_method_indexes(type_t
*iface
)
706 if (!iface
->details
.iface
)
709 if (type_iface_get_inherit(iface
))
710 idx
= compute_method_indexes(type_iface_get_inherit(iface
));
714 STATEMENTS_FOR_EACH_FUNC( stmt
, type_iface_get_stmts(iface
) )
716 var_t
*func
= stmt
->u
.var
;
717 if (!is_callas(func
->attrs
))
718 func
->func_idx
= idx
++;
724 type_t
*type_interface_declare(char *name
, struct namespace *namespace)
726 type_t
*type
= get_type(TYPE_INTERFACE
, name
, namespace, 0);
727 if (type_get_type_detect_alias( type
) != TYPE_INTERFACE
)
728 error_loc( "interface %s previously not declared an interface at %s:%d\n", type
->name
,
729 type
->where
.input_name
, type
->where
.first_line
);
733 type_t
*type_interface_define(type_t
*iface
, attr_list_t
*attrs
, type_t
*inherit
, statement_list_t
*stmts
, typeref_list_t
*requires
)
736 error_loc( "interface %s already defined at %s:%d\n", iface
->name
,
737 iface
->where
.input_name
, iface
->where
.first_line
);
738 if (iface
== inherit
)
739 error_loc("interface %s can't inherit from itself\n",
741 iface
->attrs
= check_interface_attrs(iface
->name
, attrs
);
742 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
743 iface
->details
.iface
->disp_props
= NULL
;
744 iface
->details
.iface
->disp_methods
= NULL
;
745 iface
->details
.iface
->stmts
= stmts
;
746 iface
->details
.iface
->inherit
= inherit
;
747 iface
->details
.iface
->disp_inherit
= NULL
;
748 iface
->details
.iface
->async_iface
= NULL
;
749 iface
->details
.iface
->requires
= requires
;
750 iface
->defined
= TRUE
;
751 compute_method_indexes(iface
);
755 type_t
*type_dispinterface_declare(char *name
)
757 type_t
*type
= get_type(TYPE_INTERFACE
, name
, NULL
, 0);
758 if (type_get_type_detect_alias( type
) != TYPE_INTERFACE
)
759 error_loc( "dispinterface %s previously not declared a dispinterface at %s:%d\n",
760 type
->name
, type
->where
.input_name
, type
->where
.first_line
);
764 type_t
*type_dispinterface_define(type_t
*iface
, attr_list_t
*attrs
, var_list_t
*props
, var_list_t
*methods
)
767 error_loc( "dispinterface %s already defined at %s:%d\n", iface
->name
,
768 iface
->where
.input_name
, iface
->where
.first_line
);
769 iface
->attrs
= check_dispiface_attrs(iface
->name
, attrs
);
770 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
771 iface
->details
.iface
->disp_props
= props
;
772 iface
->details
.iface
->disp_methods
= methods
;
773 iface
->details
.iface
->stmts
= NULL
;
774 iface
->details
.iface
->inherit
= find_type("IDispatch", NULL
, 0);
775 if (!iface
->details
.iface
->inherit
) error_loc("IDispatch is undefined\n");
776 iface
->details
.iface
->disp_inherit
= NULL
;
777 iface
->details
.iface
->async_iface
= NULL
;
778 iface
->details
.iface
->requires
= NULL
;
779 iface
->defined
= TRUE
;
780 compute_method_indexes(iface
);
784 type_t
*type_dispinterface_define_from_iface(type_t
*dispiface
, attr_list_t
*attrs
, type_t
*iface
)
786 if (dispiface
->defined
)
787 error_loc( "dispinterface %s already defined at %s:%d\n", dispiface
->name
,
788 dispiface
->where
.input_name
, dispiface
->where
.first_line
);
789 dispiface
->attrs
= check_dispiface_attrs(dispiface
->name
, attrs
);
790 dispiface
->details
.iface
= xmalloc(sizeof(*dispiface
->details
.iface
));
791 dispiface
->details
.iface
->disp_props
= NULL
;
792 dispiface
->details
.iface
->disp_methods
= NULL
;
793 dispiface
->details
.iface
->stmts
= NULL
;
794 dispiface
->details
.iface
->inherit
= find_type("IDispatch", NULL
, 0);
795 if (!dispiface
->details
.iface
->inherit
) error_loc("IDispatch is undefined\n");
796 dispiface
->details
.iface
->disp_inherit
= iface
;
797 dispiface
->details
.iface
->async_iface
= NULL
;
798 dispiface
->details
.iface
->requires
= NULL
;
799 dispiface
->defined
= TRUE
;
800 compute_method_indexes(dispiface
);
804 type_t
*type_module_declare(char *name
)
806 type_t
*type
= get_type(TYPE_MODULE
, name
, NULL
, 0);
807 if (type_get_type_detect_alias( type
) != TYPE_MODULE
)
808 error_loc( "module %s previously not declared a module at %s:%d\n", type
->name
,
809 type
->where
.input_name
, type
->where
.first_line
);
813 type_t
*type_module_define(type_t
* module
, attr_list_t
*attrs
, statement_list_t
*stmts
)
816 error_loc( "module %s already defined at %s:%d\n", module
->name
,
817 module
->where
.input_name
, module
->where
.first_line
);
818 module
->attrs
= check_module_attrs(module
->name
, attrs
);
819 module
->details
.module
= xmalloc(sizeof(*module
->details
.module
));
820 module
->details
.module
->stmts
= stmts
;
821 module
->defined
= TRUE
;
825 type_t
*type_coclass_declare(char *name
)
827 type_t
*type
= get_type(TYPE_COCLASS
, name
, NULL
, 0);
828 if (type_get_type_detect_alias( type
) != TYPE_COCLASS
)
829 error_loc( "coclass %s previously not declared a coclass at %s:%d\n", type
->name
,
830 type
->where
.input_name
, type
->where
.first_line
);
834 type_t
*type_coclass_define(type_t
*coclass
, attr_list_t
*attrs
, typeref_list_t
*ifaces
)
836 if (coclass
->defined
)
837 error_loc( "coclass %s already defined at %s:%d\n", coclass
->name
,
838 coclass
->where
.input_name
, coclass
->where
.first_line
);
839 coclass
->attrs
= check_coclass_attrs(coclass
->name
, attrs
);
840 coclass
->details
.coclass
.ifaces
= ifaces
;
841 coclass
->defined
= TRUE
;
845 type_t
*type_runtimeclass_declare(char *name
, struct namespace *namespace)
847 type_t
*type
= get_type(TYPE_RUNTIMECLASS
, name
, namespace, 0);
848 if (type_get_type_detect_alias( type
) != TYPE_RUNTIMECLASS
)
849 error_loc( "runtimeclass %s previously not declared a runtimeclass at %s:%d\n", type
->name
,
850 type
->where
.input_name
, type
->where
.first_line
);
854 type_t
*type_runtimeclass_define(type_t
*runtimeclass
, attr_list_t
*attrs
, typeref_list_t
*ifaces
)
856 typeref_t
*ref
, *required
, *tmp
;
857 typeref_list_t
*requires
;
859 if (runtimeclass
->defined
)
860 error_loc( "runtimeclass %s already defined at %s:%d\n", runtimeclass
->name
,
861 runtimeclass
->where
.input_name
, runtimeclass
->where
.first_line
);
862 runtimeclass
->attrs
= check_runtimeclass_attrs(runtimeclass
->name
, attrs
);
863 runtimeclass
->details
.runtimeclass
.ifaces
= ifaces
;
864 runtimeclass
->defined
= TRUE
;
865 if (!type_runtimeclass_get_default_iface(runtimeclass
, FALSE
) &&
866 !get_attrp(runtimeclass
->attrs
, ATTR_STATIC
))
867 error_loc("runtimeclass %s must have a default interface or static factory\n", runtimeclass
->name
);
869 if (ifaces
) LIST_FOR_EACH_ENTRY(ref
, ifaces
, typeref_t
, entry
)
871 /* FIXME: this should probably not be allowed, here or in coclass, */
872 /* but for now there's too many places in Wine IDL where it is to */
873 /* even print a warning. */
874 if (!(ref
->type
->defined
)) continue;
875 if (!(requires
= type_iface_get_requires(ref
->type
))) continue;
876 LIST_FOR_EACH_ENTRY(required
, requires
, typeref_t
, entry
)
880 LIST_FOR_EACH_ENTRY(tmp
, ifaces
, typeref_t
, entry
)
881 if ((found
= type_is_equal(tmp
->type
, required
->type
))) break;
884 error_loc("interface '%s' also requires interface '%s', "
885 "but runtimeclass '%s' does not implement it.\n",
886 ref
->type
->name
, required
->type
->name
, runtimeclass
->name
);
893 type_t
*type_apicontract_declare(char *name
, struct namespace *namespace)
895 type_t
*type
= get_type(TYPE_APICONTRACT
, name
, namespace, 0);
896 if (type_get_type_detect_alias( type
) != TYPE_APICONTRACT
)
897 error_loc( "apicontract %s previously not declared a apicontract at %s:%d\n", type
->name
,
898 type
->where
.input_name
, type
->where
.first_line
);
902 type_t
*type_apicontract_define(type_t
*apicontract
, attr_list_t
*attrs
)
904 if (apicontract
->defined
)
905 error_loc( "apicontract %s already defined at %s:%d\n", apicontract
->name
,
906 apicontract
->where
.input_name
, apicontract
->where
.first_line
);
907 apicontract
->attrs
= check_apicontract_attrs(apicontract
->name
, attrs
);
908 apicontract
->defined
= TRUE
;
912 static void compute_delegate_iface_names(type_t
*delegate
, type_t
*type
, typeref_list_t
*params
)
914 type_t
*iface
= delegate
->details
.delegate
.iface
;
915 iface
->namespace = delegate
->namespace;
916 iface
->name
= strmake("I%s", delegate
->name
);
917 if (type
) iface
->c_name
= format_parameterized_type_c_name(type
, params
, "I", "_C");
918 else iface
->c_name
= format_namespace(delegate
->namespace, "__x_", "_C", iface
->name
, use_abi_namespace
? "ABI" : NULL
);
919 if (type
) iface
->param_name
= format_parameterized_type_c_name(type
, params
, "I", "__C");
920 else iface
->param_name
= format_namespace(delegate
->namespace, "_", "__C", iface
->name
, NULL
);
921 iface
->qualified_name
= format_namespace(delegate
->namespace, "", "::", iface
->name
, use_abi_namespace
? "ABI" : NULL
);
924 type_t
*type_delegate_declare(char *name
, struct namespace *namespace)
926 type_t
*type
= get_type(TYPE_DELEGATE
, name
, namespace, 0);
927 if (type_get_type_detect_alias( type
) != TYPE_DELEGATE
)
928 error_loc( "delegate %s previously not declared a delegate at %s:%d\n", type
->name
,
929 type
->where
.input_name
, type
->where
.first_line
);
933 type_t
*type_delegate_define(type_t
*delegate
, attr_list_t
*attrs
, statement_list_t
*stmts
)
937 if (delegate
->defined
)
938 error_loc( "delegate %s already defined at %s:%d\n", delegate
->name
,
939 delegate
->where
.input_name
, delegate
->where
.first_line
);
941 delegate
->attrs
= check_interface_attrs(delegate
->name
, attrs
);
943 iface
= make_type(TYPE_INTERFACE
);
944 iface
->attrs
= delegate
->attrs
;
945 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
946 iface
->details
.iface
->disp_props
= NULL
;
947 iface
->details
.iface
->disp_methods
= NULL
;
948 iface
->details
.iface
->stmts
= stmts
;
949 iface
->details
.iface
->inherit
= find_type("IUnknown", NULL
, 0);
950 if (!iface
->details
.iface
->inherit
) error_loc("IUnknown is undefined\n");
951 iface
->details
.iface
->disp_inherit
= NULL
;
952 iface
->details
.iface
->async_iface
= NULL
;
953 iface
->details
.iface
->requires
= NULL
;
954 iface
->defined
= TRUE
;
955 compute_method_indexes(iface
);
957 delegate
->details
.delegate
.iface
= iface
;
958 delegate
->defined
= TRUE
;
959 compute_delegate_iface_names(delegate
, NULL
, NULL
);
964 type_t
*type_parameterized_interface_declare(char *name
, struct namespace *namespace, typeref_list_t
*params
)
966 type_t
*type
= get_type(TYPE_PARAMETERIZED_TYPE
, name
, namespace, 0);
967 if (type_get_type_detect_alias( type
) != TYPE_PARAMETERIZED_TYPE
)
968 error_loc( "pinterface %s previously not declared a pinterface at %s:%d\n", type
->name
,
969 type
->where
.input_name
, type
->where
.first_line
);
970 type
->details
.parameterized
.type
= make_type(TYPE_INTERFACE
);
971 type
->details
.parameterized
.params
= params
;
975 type_t
*type_parameterized_interface_define(type_t
*type
, attr_list_t
*attrs
, type_t
*inherit
, statement_list_t
*stmts
, typeref_list_t
*requires
)
979 error_loc( "pinterface %s already defined at %s:%d\n", type
->name
,
980 type
->where
.input_name
, type
->where
.first_line
);
982 /* The parameterized type UUID is actually a PIID that is then used as a seed to generate
983 * a new type GUID with the rules described in:
984 * https://docs.microsoft.com/en-us/uwp/winrt-cref/winrt-type-system#parameterized-types
985 * TODO: store type signatures for generated interfaces, and generate their GUIDs
987 type
->attrs
= check_interface_attrs(type
->name
, attrs
);
989 iface
= type
->details
.parameterized
.type
;
990 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
991 iface
->details
.iface
->disp_props
= NULL
;
992 iface
->details
.iface
->disp_methods
= NULL
;
993 iface
->details
.iface
->stmts
= stmts
;
994 iface
->details
.iface
->inherit
= inherit
;
995 iface
->details
.iface
->disp_inherit
= NULL
;
996 iface
->details
.iface
->async_iface
= NULL
;
997 iface
->details
.iface
->requires
= requires
;
999 iface
->name
= type
->name
;
1001 type
->defined
= TRUE
;
1005 type_t
*type_parameterized_delegate_declare(char *name
, struct namespace *namespace, typeref_list_t
*params
)
1007 type_t
*type
= get_type(TYPE_PARAMETERIZED_TYPE
, name
, namespace, 0);
1008 if (type_get_type_detect_alias( type
) != TYPE_PARAMETERIZED_TYPE
)
1009 error_loc( "pdelegate %s previously not declared a pdelegate at %s:%d\n", type
->name
,
1010 type
->where
.input_name
, type
->where
.first_line
);
1011 type
->details
.parameterized
.type
= make_type(TYPE_DELEGATE
);
1012 type
->details
.parameterized
.params
= params
;
1016 type_t
*type_parameterized_delegate_define(type_t
*type
, attr_list_t
*attrs
, statement_list_t
*stmts
)
1018 type_t
*iface
, *delegate
;
1021 error_loc( "pdelegate %s already defined at %s:%d\n", type
->name
,
1022 type
->where
.input_name
, type
->where
.first_line
);
1024 type
->attrs
= check_interface_attrs(type
->name
, attrs
);
1026 delegate
= type
->details
.parameterized
.type
;
1027 delegate
->attrs
= type
->attrs
;
1028 delegate
->details
.delegate
.iface
= make_type(TYPE_INTERFACE
);
1030 iface
= delegate
->details
.delegate
.iface
;
1031 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
1032 iface
->details
.iface
->disp_props
= NULL
;
1033 iface
->details
.iface
->disp_methods
= NULL
;
1034 iface
->details
.iface
->stmts
= stmts
;
1035 iface
->details
.iface
->inherit
= find_type("IUnknown", NULL
, 0);
1036 if (!iface
->details
.iface
->inherit
) error_loc("IUnknown is undefined\n");
1037 iface
->details
.iface
->disp_inherit
= NULL
;
1038 iface
->details
.iface
->async_iface
= NULL
;
1039 iface
->details
.iface
->requires
= NULL
;
1041 delegate
->name
= type
->name
;
1042 compute_delegate_iface_names(delegate
, type
, type
->details
.parameterized
.params
);
1044 type
->defined
= TRUE
;
1048 type_t
*type_parameterized_type_specialize_partial(type_t
*type
, typeref_list_t
*params
)
1050 type_t
*new_type
= duptype(type
, 0);
1051 new_type
->details
.parameterized
.type
= type
;
1052 new_type
->details
.parameterized
.params
= params
;
1056 static type_t
*replace_type_parameters_in_type(type_t
*type
, typeref_list_t
*orig
, typeref_list_t
*repl
);
1058 static typeref_list_t
*replace_type_parameters_in_type_list(typeref_list_t
*list
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1060 typeref_list_t
*new_list
= NULL
;
1063 if (!list
) return list
;
1065 LIST_FOR_EACH_ENTRY(ref
, list
, typeref_t
, entry
)
1067 type_t
*new_type
= replace_type_parameters_in_type(ref
->type
, orig
, repl
);
1068 new_list
= append_typeref(new_list
, make_typeref(new_type
));
1074 static var_t
*replace_type_parameters_in_var(var_t
*var
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1076 var_t
*new_var
= xmalloc(sizeof(*new_var
));
1078 list_init(&new_var
->entry
);
1079 new_var
->declspec
.type
= replace_type_parameters_in_type(var
->declspec
.type
, orig
, repl
);
1083 static var_list_t
*replace_type_parameters_in_var_list(var_list_t
*var_list
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1085 var_list_t
*new_var_list
;
1086 var_t
*var
, *new_var
;
1088 if (!var_list
) return var_list
;
1090 new_var_list
= xmalloc(sizeof(*new_var_list
));
1091 list_init(new_var_list
);
1093 LIST_FOR_EACH_ENTRY(var
, var_list
, var_t
, entry
)
1095 new_var
= replace_type_parameters_in_var(var
, orig
, repl
);
1096 list_add_tail(new_var_list
, &new_var
->entry
);
1099 return new_var_list
;
1102 static statement_t
*replace_type_parameters_in_statement( statement_t
*stmt
, typeref_list_t
*orig
,
1103 typeref_list_t
*repl
, struct location
*where
)
1105 statement_t
*new_stmt
= xmalloc(sizeof(*new_stmt
));
1107 list_init(&new_stmt
->entry
);
1111 case STMT_DECLARATION
:
1112 new_stmt
->u
.var
= replace_type_parameters_in_var(stmt
->u
.var
, orig
, repl
);
1116 new_stmt
->u
.type
= replace_type_parameters_in_type(stmt
->u
.type
, orig
, repl
);
1119 new_stmt
->u
.type_list
= replace_type_parameters_in_type_list(stmt
->u
.type_list
, orig
, repl
);
1124 case STMT_IMPORTLIB
:
1127 error_at( where
, "unimplemented parameterized type replacement for statement type %d.\n", stmt
->type
);
1134 static statement_list_t
*replace_type_parameters_in_statement_list( statement_list_t
*stmt_list
, typeref_list_t
*orig
,
1135 typeref_list_t
*repl
, struct location
*where
)
1137 statement_list_t
*new_stmt_list
;
1138 statement_t
*stmt
, *new_stmt
;
1140 if (!stmt_list
) return stmt_list
;
1142 new_stmt_list
= xmalloc(sizeof(*new_stmt_list
));
1143 list_init(new_stmt_list
);
1145 LIST_FOR_EACH_ENTRY(stmt
, stmt_list
, statement_t
, entry
)
1147 new_stmt
= replace_type_parameters_in_statement( stmt
, orig
, repl
, where
);
1148 list_add_tail(new_stmt_list
, &new_stmt
->entry
);
1151 return new_stmt_list
;
1154 static type_t
*replace_type_parameters_in_type(type_t
*type
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1159 if (!type
) return type
;
1160 switch (type
->type_type
)
1166 case TYPE_INTERFACE
:
1167 case TYPE_RUNTIMECLASS
:
1170 case TYPE_ENCAPSULATED_UNION
:
1173 case TYPE_PARAMETER
:
1174 if (!orig
|| !repl
) return NULL
;
1175 for (o
= list_head(orig
), r
= list_head(repl
); o
&& r
;
1176 o
= list_next(orig
, o
), r
= list_next(repl
, r
))
1177 if (type
== LIST_ENTRY(o
, typeref_t
, entry
)->type
)
1178 return LIST_ENTRY(r
, typeref_t
, entry
)->type
;
1181 t
= replace_type_parameters_in_type(type
->details
.pointer
.ref
.type
, orig
, repl
);
1182 if (t
== type
->details
.pointer
.ref
.type
) return type
;
1183 type
= duptype(type
, 0);
1184 type
->details
.pointer
.ref
.type
= t
;
1187 t
= replace_type_parameters_in_type(type
->details
.alias
.aliasee
.type
, orig
, repl
);
1188 if (t
== type
->details
.alias
.aliasee
.type
) return type
;
1189 type
= duptype(type
, 0);
1190 type
->details
.alias
.aliasee
.type
= t
;
1193 t
= replace_type_parameters_in_type(type
->details
.array
.elem
.type
, orig
, repl
);
1194 if (t
== t
->details
.array
.elem
.type
) return type
;
1195 type
= duptype(type
, 0);
1196 t
->details
.array
.elem
.type
= t
;
1199 t
= duptype(type
, 0);
1200 t
->details
.function
= xmalloc(sizeof(*t
->details
.function
));
1201 t
->details
.function
->args
= replace_type_parameters_in_var_list(type
->details
.function
->args
, orig
, repl
);
1202 t
->details
.function
->retval
= replace_type_parameters_in_var(type
->details
.function
->retval
, orig
, repl
);
1204 case TYPE_PARAMETERIZED_TYPE
:
1205 t
= type
->details
.parameterized
.type
;
1206 if (t
->type_type
!= TYPE_PARAMETERIZED_TYPE
) return find_parameterized_type(type
, repl
);
1207 repl
= replace_type_parameters_in_type_list(type
->details
.parameterized
.params
, orig
, repl
);
1208 return replace_type_parameters_in_type(t
, t
->details
.parameterized
.params
, repl
);
1211 case TYPE_APICONTRACT
:
1212 error_at( &type
->where
, "unimplemented parameterized type replacement for type %s of type %d.\n",
1213 type
->name
, type
->type_type
);
1220 static void type_parameterized_interface_specialize(type_t
*tmpl
, type_t
*iface
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1222 iface
->details
.iface
= xmalloc(sizeof(*iface
->details
.iface
));
1223 iface
->details
.iface
->disp_methods
= NULL
;
1224 iface
->details
.iface
->disp_props
= NULL
;
1225 iface
->details
.iface
->stmts
= replace_type_parameters_in_statement_list( tmpl
->details
.iface
->stmts
,
1226 orig
, repl
, &tmpl
->where
);
1227 iface
->details
.iface
->inherit
= replace_type_parameters_in_type(tmpl
->details
.iface
->inherit
, orig
, repl
);
1228 iface
->details
.iface
->disp_inherit
= NULL
;
1229 iface
->details
.iface
->async_iface
= NULL
;
1230 iface
->details
.iface
->requires
= NULL
;
1233 static void type_parameterized_delegate_specialize(type_t
*tmpl
, type_t
*delegate
, typeref_list_t
*orig
, typeref_list_t
*repl
)
1235 type_parameterized_interface_specialize(tmpl
->details
.delegate
.iface
, delegate
->details
.delegate
.iface
, orig
, repl
);
1238 type_t
*type_parameterized_type_specialize_declare(type_t
*type
, typeref_list_t
*params
)
1240 type_t
*tmpl
= type
->details
.parameterized
.type
;
1241 type_t
*new_type
= duptype(tmpl
, 0);
1243 new_type
->namespace = type
->namespace;
1244 new_type
->name
= format_parameterized_type_name(type
, params
);
1245 reg_type(new_type
, new_type
->name
, new_type
->namespace, 0);
1246 new_type
->c_name
= format_parameterized_type_c_name(type
, params
, "", "_C");
1247 new_type
->short_name
= format_parameterized_type_short_name(type
, params
, "");
1248 new_type
->param_name
= format_parameterized_type_c_name(type
, params
, "", "__C");
1250 if (new_type
->type_type
== TYPE_DELEGATE
)
1252 new_type
->details
.delegate
.iface
= duptype(tmpl
->details
.delegate
.iface
, 0);
1253 compute_delegate_iface_names(new_type
, type
, params
);
1254 new_type
->details
.delegate
.iface
->short_name
= format_parameterized_type_short_name(type
, params
, "I");
1260 static void compute_interface_signature_uuid(type_t
*iface
)
1262 static const char winrt_pinterface_namespace
[] = {0x11,0xf4,0x7a,0xd5,0x7b,0x73,0x42,0xc0,0xab,0xae,0x87,0x8b,0x1e,0x16,0xad,0xee};
1263 static const int version
= 5;
1264 struct sha1_context ctx
;
1265 unsigned char hash
[20];
1268 if (!(uuid
= get_attrp(iface
->attrs
, ATTR_UUID
)))
1270 uuid
= xmalloc(sizeof(*uuid
));
1271 iface
->attrs
= append_attr( iface
->attrs
, attr_ptr( iface
->where
, ATTR_UUID
, uuid
) );
1275 sha1_update(&ctx
, winrt_pinterface_namespace
, sizeof(winrt_pinterface_namespace
));
1276 sha1_update(&ctx
, iface
->signature
, strlen(iface
->signature
));
1277 sha1_finalize(&ctx
, (unsigned int *)hash
);
1279 /* https://tools.ietf.org/html/rfc4122:
1281 * Set the four most significant bits (bits 12 through 15) of the
1282 time_hi_and_version field to the appropriate 4-bit version number
1285 * Set the two most significant bits (bits 6 and 7) of the
1286 clock_seq_hi_and_reserved to zero and one, respectively.
1289 hash
[6] = ((hash
[6] & 0x0f) | (version
<< 4));
1290 hash
[8] = ((hash
[8] & 0x3f) | 0x80);
1292 uuid
->Data1
= ((unsigned int)hash
[0] << 24) | ((unsigned int)hash
[1] << 16) | ((unsigned int)hash
[2] << 8) | hash
[3];
1293 uuid
->Data2
= ((unsigned short)hash
[4] << 8) | hash
[5];
1294 uuid
->Data3
= ((unsigned short)hash
[6] << 8) | hash
[7];
1295 memcpy(&uuid
->Data4
, hash
+ 8, sizeof(*uuid
) - offsetof(struct uuid
, Data4
));
1298 type_t
*type_parameterized_type_specialize_define(type_t
*type
)
1300 type_t
*tmpl
= type
->details
.parameterized
.type
;
1301 typeref_list_t
*orig
= tmpl
->details
.parameterized
.params
;
1302 typeref_list_t
*repl
= type
->details
.parameterized
.params
;
1303 type_t
*iface
= find_parameterized_type(tmpl
, repl
);
1305 if (type_get_type_detect_alias(type
) != TYPE_PARAMETERIZED_TYPE
||
1306 type_get_type_detect_alias(tmpl
) != TYPE_PARAMETERIZED_TYPE
)
1307 error_loc( "cannot define non-parameterized type %s, declared at %s:%d\n", type
->name
,
1308 type
->where
.input_name
, type
->where
.first_line
);
1310 if (type_get_type_detect_alias(tmpl
->details
.parameterized
.type
) == TYPE_INTERFACE
&&
1311 type_get_type_detect_alias(iface
) == TYPE_INTERFACE
)
1312 type_parameterized_interface_specialize(tmpl
->details
.parameterized
.type
, iface
, orig
, repl
);
1313 else if (type_get_type_detect_alias(tmpl
->details
.parameterized
.type
) == TYPE_DELEGATE
&&
1314 type_get_type_detect_alias(iface
) == TYPE_DELEGATE
)
1315 type_parameterized_delegate_specialize(tmpl
->details
.parameterized
.type
, iface
, orig
, repl
);
1317 error_loc("pinterface/pdelegate %s previously not declared a pinterface/pdelegate at %s:%d\n",
1318 iface
->name
, iface
->where
.input_name
, iface
->where
.first_line
);
1320 iface
->impl_name
= format_parameterized_type_impl_name(type
, repl
, "");
1321 iface
->signature
= format_parameterized_type_signature(type
, repl
);
1322 iface
->defined
= TRUE
;
1323 if (iface
->type_type
== TYPE_DELEGATE
)
1325 iface
= iface
->details
.delegate
.iface
;
1326 iface
->impl_name
= format_parameterized_type_impl_name(type
, repl
, "I");
1327 iface
->signature
= format_parameterized_type_signature(type
, repl
);
1328 iface
->defined
= TRUE
;
1330 compute_interface_signature_uuid(iface
);
1331 compute_method_indexes(iface
);
1335 int type_is_equal(const type_t
*type1
, const type_t
*type2
)
1339 if (type_get_type_detect_alias(type1
) != type_get_type_detect_alias(type2
))
1341 if (type1
->namespace != type2
->namespace)
1344 if (type1
->name
&& type2
->name
)
1345 return !strcmp(type1
->name
, type2
->name
);
1346 else if ((!type1
->name
&& type2
->name
) || (type1
->name
&& !type2
->name
))
1349 /* FIXME: do deep inspection of types to determine if they are equal */