2016-07-13 Thomas Preud'homme <thomas.preudhomme@arm.com>
[official-gcc.git] / libgo / runtime / go-check-interface.c
blob722a4219ab2c4fd9ee9680ef3de42d8e78e0251a
1 /* go-check-interface.c -- check an interface type for a conversion
3 Copyright 2010 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. */
7 #include "runtime.h"
8 #include "go-panic.h"
9 #include "go-type.h"
10 #include "interface.h"
12 /* Check that an interface type matches for a conversion to a
13 non-interface type. This panics if the types are bad. The actual
14 extraction of the object is inlined. */
16 void
17 __go_check_interface_type (
18 const struct __go_type_descriptor *lhs_descriptor,
19 const struct __go_type_descriptor *rhs_descriptor,
20 const struct __go_type_descriptor *rhs_inter_descriptor)
22 if (rhs_descriptor == NULL)
24 struct __go_empty_interface panic_arg;
26 runtime_newTypeAssertionError(NULL, NULL, lhs_descriptor->__reflection,
27 NULL, &panic_arg);
28 __go_panic(panic_arg);
31 if (lhs_descriptor != rhs_descriptor
32 && !__go_type_descriptors_equal (lhs_descriptor, rhs_descriptor)
33 && ((lhs_descriptor->__code & GO_CODE_MASK) != GO_UNSAFE_POINTER
34 || !__go_is_pointer_type (rhs_descriptor))
35 && ((rhs_descriptor->__code & GO_CODE_MASK) != GO_UNSAFE_POINTER
36 || !__go_is_pointer_type (lhs_descriptor)))
38 struct __go_empty_interface panic_arg;
40 runtime_newTypeAssertionError(rhs_inter_descriptor->__reflection,
41 rhs_descriptor->__reflection,
42 lhs_descriptor->__reflection,
43 NULL, &panic_arg);
44 __go_panic(panic_arg);