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 /* Return whether we can convert from the type in FROM_DESCRIPTOR to
12 the interface in TO_DESCRIPTOR. This is used for type
16 __go_can_convert_to_interface (
17 const struct __go_type_descriptor *to_descriptor,
18 const struct __go_type_descriptor *from_descriptor)
20 const struct __go_interface_type *to_interface;
22 const struct __go_interface_method *to_method;
23 const struct __go_uncommon_type *from_uncommon;
24 int from_method_count;
25 const struct __go_method *from_method;
28 /* In a type switch FROM_DESCRIPTOR can be NULL. */
29 if (from_descriptor == NULL)
32 __go_assert (to_descriptor->__code == GO_INTERFACE);
33 to_interface = (const struct __go_interface_type *) to_descriptor;
34 to_method_count = to_interface->__methods.__count;
35 to_method = ((const struct __go_interface_method *)
36 to_interface->__methods.__values);
38 from_uncommon = from_descriptor->__uncommon;
39 if (from_uncommon == NULL)
41 from_method_count = 0;
46 from_method_count = from_uncommon->__methods.__count;
47 from_method = ((const struct __go_method *)
48 from_uncommon->__methods.__values);
51 for (i = 0; i < to_method_count; ++i)
53 while (from_method_count > 0
54 && (!__go_ptr_strings_equal (from_method->__name,
56 || !__go_ptr_strings_equal (from_method->__pkg_path,
57 to_method->__pkg_path)))
63 if (from_method_count == 0)
66 if (!__go_type_descriptors_equal (from_method->__mtype,