1 /* go-can-convert-interface.c -- can we convert to an interface?
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
11 #include "interface.h"
13 /* Return whether we can convert from the type in FROM_DESCRIPTOR to
14 the interface in TO_DESCRIPTOR. This is used for type
18 __go_can_convert_to_interface (
19 const struct __go_type_descriptor
*to_descriptor
,
20 const struct __go_type_descriptor
*from_descriptor
)
22 const struct __go_interface_type
*to_interface
;
24 const struct __go_interface_method
*to_method
;
25 const struct __go_uncommon_type
*from_uncommon
;
26 int from_method_count
;
27 const struct __go_method
*from_method
;
30 /* In a type switch FROM_DESCRIPTOR can be NULL. */
31 if (from_descriptor
== NULL
)
34 __go_assert ((to_descriptor
->__code
& GO_CODE_MASK
) == GO_INTERFACE
);
35 to_interface
= (const struct __go_interface_type
*) to_descriptor
;
36 to_method_count
= to_interface
->__methods
.__count
;
37 to_method
= ((const struct __go_interface_method
*)
38 to_interface
->__methods
.__values
);
40 from_uncommon
= from_descriptor
->__uncommon
;
41 if (from_uncommon
== NULL
)
43 from_method_count
= 0;
48 from_method_count
= from_uncommon
->__methods
.__count
;
49 from_method
= ((const struct __go_method
*)
50 from_uncommon
->__methods
.__values
);
53 for (i
= 0; i
< to_method_count
; ++i
)
55 while (from_method_count
> 0
56 && (!__go_ptr_strings_equal (from_method
->__name
,
58 || !__go_ptr_strings_equal (from_method
->__pkg_path
,
59 to_method
->__pkg_path
)))
65 if (from_method_count
== 0)
68 if (!__go_type_descriptors_equal (from_method
->__mtype
,