Fix PR47707
[official-gcc.git] / libgo / runtime / go-type.h
blobb1f32850a0087a68490ed44dbf61fc228a93c2de
1 /* go-type.h -- basic information for a Go type.
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. */
7 #ifndef LIBGO_GO_TYPE_H
8 #define LIBGO_GO_TYPE_H
10 #include <stddef.h>
11 #include <stdint.h>
13 #include "go-string.h"
14 #include "array.h"
16 /* Many of the types in this file must match the data structures
17 generated by the compiler, and must also match the Go types which
18 appear in go/runtime/type.go and go/reflect/type.go. */
20 /* Type kinds. These are used to get the type descriptor to use for
21 the type itself, when using unsafe.Typeof or unsafe.Reflect. The
22 values here must match the values generated by the compiler (the
23 RUNTIME_TYPE_KIND_xxx values in gcc/go/types.h). These are macros
24 rather than an enum to make it easy to change values in the future
25 and hard to get confused about it.
27 These correspond to the kind values used by the gc compiler. */
29 #define GO_BOOL 1
30 #define GO_INT 2
31 #define GO_INT8 3
32 #define GO_INT16 4
33 #define GO_INT32 5
34 #define GO_INT64 6
35 #define GO_UINT 7
36 #define GO_UINT8 8
37 #define GO_UINT16 9
38 #define GO_UINT32 10
39 #define GO_UINT64 11
40 #define GO_UINTPTR 12
41 #define GO_FLOAT32 13
42 #define GO_FLOAT64 14
43 #define GO_COMPLEX64 15
44 #define GO_COMPLEX128 16
45 #define GO_ARRAY 17
46 #define GO_CHAN 18
47 #define GO_FUNC 19
48 #define GO_INTERFACE 20
49 #define GO_MAP 21
50 #define GO_PTR 22
51 #define GO_SLICE 23
52 #define GO_STRING 24
53 #define GO_STRUCT 25
54 #define GO_UNSAFE_POINTER 26
56 /* For each Go type the compiler constructs one of these structures.
57 This is used for type reflectin, interfaces, maps, and reference
58 counting. */
60 struct __go_type_descriptor
62 /* The type code for this type, a value in enum __go_type_codes.
63 This is used by unsafe.Reflect and unsafe.Typeof to determine the
64 type descriptor to return for this type itself. It is also used
65 by reflect.toType when mapping to a reflect Type structure. */
66 unsigned char __code;
68 /* The alignment in bytes of a variable with this type. */
69 unsigned char __align;
71 /* The alignment in bytes of a struct field with this type. */
72 unsigned char __field_align;
74 /* The size in bytes of a value of this type. Note that all types
75 in Go have a fixed size. */
76 uintptr_t __size;
78 /* The type's hash code. */
79 uint32_t __hash;
81 /* This function takes a pointer to a value of this type, and the
82 size of this type, and returns a hash code. We pass the size
83 explicitly becaues it means that we can share a single instance
84 of this function for various different types. */
85 size_t (*__hashfn) (const void *, size_t);
87 /* This function takes two pointers to values of this type, and the
88 size of this type, and returns whether the values are equal. */
89 _Bool (*__equalfn) (const void *, const void *, size_t);
91 /* A string describing this type. This is only used for
92 debugging. */
93 const struct __go_string *__reflection;
95 /* A pointer to fields which are only used for some types. */
96 const struct __go_uncommon_type *__uncommon;
99 /* The information we store for each method of a type. */
101 struct __go_method
103 /* The name of the method. */
104 const struct __go_string *__name;
106 /* This is NULL for an exported method, or the name of the package
107 where it lives. */
108 const struct __go_string *__pkg_path;
110 /* The type of the method, without the receiver. This will be a
111 function type. */
112 const struct __go_type_descriptor *__mtype;
114 /* The type of the method, with the receiver. This will be a
115 function type. */
116 const struct __go_type_descriptor *__type;
118 /* A pointer to the code which implements the method. This is
119 really a function pointer. */
120 const void *__function;
123 /* Additional information that we keep for named types and for types
124 with methods. */
126 struct __go_uncommon_type
128 /* The name of the type. */
129 const struct __go_string *__name;
131 /* The type's package. This is NULL for builtin types. */
132 const struct __go_string *__pkg_path;
134 /* The type's methods. This is an array of struct __go_method. */
135 struct __go_open_array __methods;
138 /* The type descriptor for a fixed array type. */
140 struct __go_array_type
142 /* Starts like all type descriptors. */
143 struct __go_type_descriptor __common;
145 /* The element type. */
146 struct __go_type_descriptor *__element_type;
148 /* The length of the array. */
149 uintptr_t __len;
152 /* The type descriptor for a slice. */
154 struct __go_slice_type
156 /* Starts like all other type descriptors. */
157 struct __go_type_descriptor __common;
159 /* The element type. */
160 struct __go_type_descriptor *__element_type;
163 /* The direction of a channel. */
164 #define CHANNEL_RECV_DIR 1
165 #define CHANNEL_SEND_DIR 2
166 #define CHANNEL_BOTH_DIR (CHANNEL_RECV_DIR | CHANNEL_SEND_DIR)
168 /* The type descriptor for a channel. */
170 struct __go_channel_type
172 /* Starts like all other type descriptors. */
173 struct __go_type_descriptor __common;
175 /* The element type. */
176 const struct __go_type_descriptor *__element_type;
178 /* The direction. */
179 uintptr_t __dir;
182 /* The type descriptor for a function. */
184 struct __go_func_type
186 /* Starts like all other type descriptors. */
187 struct __go_type_descriptor __common;
189 /* Whether this is a varargs function. If this is true, there will
190 be at least one parameter. For "..." the last parameter type is
191 "interface{}". For "... T" the last parameter type is "[]T". */
192 _Bool __dotdotdot;
194 /* The input parameter types. This is an array of pointers to
195 struct __go_type_descriptor. */
196 struct __go_open_array __in;
198 /* The output parameter types. This is an array of pointers to
199 struct __go_type_descriptor. */
200 struct __go_open_array __out;
203 /* A method on an interface type. */
205 struct __go_interface_method
207 /* The name of the method. */
208 const struct __go_string *__name;
210 /* This is NULL for an exported method, or the name of the package
211 where it lives. */
212 const struct __go_string *__pkg_path;
214 /* The real type of the method. */
215 struct __go_type_descriptor *__type;
218 /* An interface type. */
220 struct __go_interface_type
222 /* Starts like all other type descriptors. */
223 struct __go_type_descriptor __common;
225 /* Array of __go_interface_method . The methods are sorted in the
226 same order that they appear in the definition of the
227 interface. */
228 struct __go_open_array __methods;
231 /* A map type. */
233 struct __go_map_type
235 /* Starts like all other type descriptors. */
236 struct __go_type_descriptor __common;
238 /* The map key type. */
239 const struct __go_type_descriptor *__key_type;
241 /* The map value type. */
242 const struct __go_type_descriptor *__val_type;
245 /* A pointer type. */
247 struct __go_ptr_type
249 /* Starts like all other type descriptors. */
250 struct __go_type_descriptor __common;
252 /* The type to which this points. */
253 const struct __go_type_descriptor *__element_type;
256 /* A field in a structure. */
258 struct __go_struct_field
260 /* The name of the field--NULL for an anonymous field. */
261 const struct __go_string *__name;
263 /* This is NULL for an exported method, or the name of the package
264 where it lives. */
265 const struct __go_string *__pkg_path;
267 /* The type of the field. */
268 const struct __go_type_descriptor *__type;
270 /* The field tag, or NULL. */
271 const struct __go_string *__tag;
273 /* The offset of the field in the struct. */
274 uintptr_t __offset;
277 /* A struct type. */
279 struct __go_struct_type
281 /* Starts like all other type descriptors. */
282 struct __go_type_descriptor __common;
284 /* An array of struct __go_struct_field. */
285 struct __go_open_array __fields;
288 /* Whether a type descriptor is a pointer. */
290 static inline _Bool
291 __go_is_pointer_type (const struct __go_type_descriptor *td)
293 return td->__code == GO_PTR || td->__code == GO_UNSAFE_POINTER;
296 extern _Bool
297 __go_type_descriptors_equal(const struct __go_type_descriptor*,
298 const struct __go_type_descriptor*);
300 extern size_t __go_type_hash_identity (const void *, size_t);
301 extern _Bool __go_type_equal_identity (const void *, const void *, size_t);
302 extern size_t __go_type_hash_string (const void *, size_t);
303 extern _Bool __go_type_equal_string (const void *, const void *, size_t);
304 extern size_t __go_type_hash_interface (const void *, size_t);
305 extern _Bool __go_type_equal_interface (const void *, const void *, size_t);
306 extern size_t __go_type_hash_error (const void *, size_t);
307 extern _Bool __go_type_equal_error (const void *, const void *, size_t);
309 #endif /* !defined(LIBGO_GO_TYPE_H) */