]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgo/runtime/reflect.goc
Add Go frontend, libgo library, and Go testsuite.
[thirdparty/gcc.git] / libgo / runtime / reflect.goc
1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package reflect
6 #include "go-type.h"
7 #include "interface.h"
8 #define nil NULL
9 typedef unsigned char byte;
10
11 typedef struct __go_interface Iface;
12 typedef struct __go_empty_interface Eface;
13
14 func setiface(typ *byte, x *byte, ret *byte) {
15 struct __go_interface_type *t;
16 const struct __go_type_descriptor* xt;
17
18 /* FIXME: We should check __type_descriptor to verify that
19 this is really a type descriptor. */
20 t = (struct __go_interface_type *)typ;
21 if(t->__methods.__count == 0) {
22 // already an empty interface
23 *(Eface*)ret = *(Eface*)x;
24 return;
25 }
26 xt = ((Eface*)x)->__type_descriptor;
27 if(xt == nil) {
28 // can assign nil to any interface
29 ((Iface*)ret)->__methods = nil;
30 ((Iface*)ret)->__object = nil;
31 return;
32 }
33 ((Iface*)ret)->__methods = __go_convert_interface(&t->__common, xt);
34 ((Iface*)ret)->__object = ((Eface*)x)->__object;
35 }