annotate libgo/runtime/go-type.h @ 143:76e1cf5455ef

add cbc_gc test
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 19:24:05 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* go-type.h -- basic information for a Go type.
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 Copyright 2009 The Go Authors. All rights reserved.
kono
parents:
diff changeset
4 Use of this source code is governed by a BSD-style
kono
parents:
diff changeset
5 license that can be found in the LICENSE file. */
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 #ifndef LIBGO_GO_TYPE_H
kono
parents:
diff changeset
8 #define LIBGO_GO_TYPE_H
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 #include <stddef.h>
kono
parents:
diff changeset
11 #include <stdint.h>
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 #include "array.h"
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 struct String;
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 /* Many of the types in this file must match the data structures
kono
parents:
diff changeset
18 generated by the compiler, and must also match the Go types which
kono
parents:
diff changeset
19 appear in go/runtime/type.go and go/reflect/type.go. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 /* Type kinds. These are used to get the type descriptor to use for
kono
parents:
diff changeset
22 the type itself, when using unsafe.Typeof or unsafe.Reflect. The
kono
parents:
diff changeset
23 values here must match the values generated by the compiler (the
kono
parents:
diff changeset
24 RUNTIME_TYPE_KIND_xxx values in gcc/go/types.h). These are macros
kono
parents:
diff changeset
25 rather than an enum to make it easy to change values in the future
kono
parents:
diff changeset
26 and hard to get confused about it.
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 These correspond to the kind values used by the gc compiler. */
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 #define GO_BOOL 1
kono
parents:
diff changeset
31 #define GO_INT 2
kono
parents:
diff changeset
32 #define GO_INT8 3
kono
parents:
diff changeset
33 #define GO_INT16 4
kono
parents:
diff changeset
34 #define GO_INT32 5
kono
parents:
diff changeset
35 #define GO_INT64 6
kono
parents:
diff changeset
36 #define GO_UINT 7
kono
parents:
diff changeset
37 #define GO_UINT8 8
kono
parents:
diff changeset
38 #define GO_UINT16 9
kono
parents:
diff changeset
39 #define GO_UINT32 10
kono
parents:
diff changeset
40 #define GO_UINT64 11
kono
parents:
diff changeset
41 #define GO_UINTPTR 12
kono
parents:
diff changeset
42 #define GO_FLOAT32 13
kono
parents:
diff changeset
43 #define GO_FLOAT64 14
kono
parents:
diff changeset
44 #define GO_COMPLEX64 15
kono
parents:
diff changeset
45 #define GO_COMPLEX128 16
kono
parents:
diff changeset
46 #define GO_ARRAY 17
kono
parents:
diff changeset
47 #define GO_CHAN 18
kono
parents:
diff changeset
48 #define GO_FUNC 19
kono
parents:
diff changeset
49 #define GO_INTERFACE 20
kono
parents:
diff changeset
50 #define GO_MAP 21
kono
parents:
diff changeset
51 #define GO_PTR 22
kono
parents:
diff changeset
52 #define GO_SLICE 23
kono
parents:
diff changeset
53 #define GO_STRING 24
kono
parents:
diff changeset
54 #define GO_STRUCT 25
kono
parents:
diff changeset
55 #define GO_UNSAFE_POINTER 26
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 #define GO_DIRECT_IFACE (1 << 5)
kono
parents:
diff changeset
58 #define GO_GC_PROG (1 << 6)
kono
parents:
diff changeset
59 #define GO_NO_POINTERS (1 << 7)
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 #define GO_CODE_MASK 0x1f
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 /* For each Go type the compiler constructs one of these structures.
kono
parents:
diff changeset
64 This is used for type reflection, interfaces, maps, and reference
kono
parents:
diff changeset
65 counting. */
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 struct __go_type_descriptor
kono
parents:
diff changeset
68 {
kono
parents:
diff changeset
69 /* The size in bytes of a value of this type. Note that all types
kono
parents:
diff changeset
70 in Go have a fixed size. */
kono
parents:
diff changeset
71 uintptr_t __size;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 /* The size of the memory prefix of a value of this type that holds
kono
parents:
diff changeset
74 all pointers. */
kono
parents:
diff changeset
75 uintptr_t __ptrdata;
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 /* The type's hash code. */
kono
parents:
diff changeset
78 uint32_t __hash;
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 /* The type code for this type, one of the type kind values above.
kono
parents:
diff changeset
81 This is used by unsafe.Reflect and unsafe.Typeof to determine the
kono
parents:
diff changeset
82 type descriptor to return for this type itself. It is also used
kono
parents:
diff changeset
83 by reflect.toType when mapping to a reflect Type structure. */
kono
parents:
diff changeset
84 unsigned char __code;
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 /* The alignment in bytes of a variable with this type. */
kono
parents:
diff changeset
87 unsigned char __align;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 /* The alignment in bytes of a struct field with this type. */
kono
parents:
diff changeset
90 unsigned char __field_align;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 /* This function takes a pointer to a value of this type, and the
kono
parents:
diff changeset
93 size of this type, and returns a hash code. We pass the size
kono
parents:
diff changeset
94 explicitly becaues it means that we can share a single instance
kono
parents:
diff changeset
95 of this function for various different types. */
kono
parents:
diff changeset
96 const FuncVal *__hashfn;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 /* This function takes two pointers to values of this type, and the
kono
parents:
diff changeset
99 size of this type, and returns whether the values are equal. */
kono
parents:
diff changeset
100 const FuncVal *__equalfn;
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 /* The garbage collection data. */
kono
parents:
diff changeset
103 const byte *__gcdata;
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 /* A string describing this type. This is only used for
kono
parents:
diff changeset
106 debugging. */
kono
parents:
diff changeset
107 const struct String *__reflection;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 /* A pointer to fields which are only used for some types. */
kono
parents:
diff changeset
110 const struct __go_uncommon_type *__uncommon;
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 /* The descriptor for the type which is a pointer to this type.
kono
parents:
diff changeset
113 This may be NULL. */
kono
parents:
diff changeset
114 const struct __go_type_descriptor *__pointer_to_this;
kono
parents:
diff changeset
115 };
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 /* The information we store for each method of a type. */
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 struct __go_method
kono
parents:
diff changeset
120 {
kono
parents:
diff changeset
121 /* The name of the method. */
kono
parents:
diff changeset
122 const struct String *__name;
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 /* This is NULL for an exported method, or the name of the package
kono
parents:
diff changeset
125 where it lives. */
kono
parents:
diff changeset
126 const struct String *__pkg_path;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 /* The type of the method, without the receiver. This will be a
kono
parents:
diff changeset
129 function type. */
kono
parents:
diff changeset
130 const struct __go_type_descriptor *__mtype;
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 /* The type of the method, with the receiver. This will be a
kono
parents:
diff changeset
133 function type. */
kono
parents:
diff changeset
134 const struct __go_type_descriptor *__type;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 /* A pointer to the code which implements the method. This is
kono
parents:
diff changeset
137 really a function pointer. */
kono
parents:
diff changeset
138 const void *__function;
kono
parents:
diff changeset
139 };
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 /* Additional information that we keep for named types and for types
kono
parents:
diff changeset
142 with methods. */
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 struct __go_uncommon_type
kono
parents:
diff changeset
145 {
kono
parents:
diff changeset
146 /* The name of the type. */
kono
parents:
diff changeset
147 const struct String *__name;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 /* The type's package. This is NULL for builtin types. */
kono
parents:
diff changeset
150 const struct String *__pkg_path;
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 /* The type's methods. This is an array of struct __go_method. */
kono
parents:
diff changeset
153 struct __go_open_array __methods;
kono
parents:
diff changeset
154 };
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 /* The type descriptor for a fixed array type. */
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 struct __go_array_type
kono
parents:
diff changeset
159 {
kono
parents:
diff changeset
160 /* Starts like all type descriptors. */
kono
parents:
diff changeset
161 struct __go_type_descriptor __common;
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 /* The element type. */
kono
parents:
diff changeset
164 struct __go_type_descriptor *__element_type;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 /* The type of a slice of the same element type. */
kono
parents:
diff changeset
167 struct __go_type_descriptor *__slice_type;
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 /* The length of the array. */
kono
parents:
diff changeset
170 uintptr_t __len;
kono
parents:
diff changeset
171 };
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 /* The type descriptor for a slice. */
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 struct __go_slice_type
kono
parents:
diff changeset
176 {
kono
parents:
diff changeset
177 /* Starts like all other type descriptors. */
kono
parents:
diff changeset
178 struct __go_type_descriptor __common;
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 /* The element type. */
kono
parents:
diff changeset
181 struct __go_type_descriptor *__element_type;
kono
parents:
diff changeset
182 };
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 /* The direction of a channel. */
kono
parents:
diff changeset
185 #define CHANNEL_RECV_DIR 1
kono
parents:
diff changeset
186 #define CHANNEL_SEND_DIR 2
kono
parents:
diff changeset
187 #define CHANNEL_BOTH_DIR (CHANNEL_RECV_DIR | CHANNEL_SEND_DIR)
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 /* The type descriptor for a channel. */
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 struct __go_channel_type
kono
parents:
diff changeset
192 {
kono
parents:
diff changeset
193 /* Starts like all other type descriptors. */
kono
parents:
diff changeset
194 struct __go_type_descriptor __common;
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 /* The element type. */
kono
parents:
diff changeset
197 const struct __go_type_descriptor *__element_type;
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 /* The direction. */
kono
parents:
diff changeset
200 uintptr_t __dir;
kono
parents:
diff changeset
201 };
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 /* The type descriptor for a function. */
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 struct __go_func_type
kono
parents:
diff changeset
206 {
kono
parents:
diff changeset
207 /* Starts like all other type descriptors. */
kono
parents:
diff changeset
208 struct __go_type_descriptor __common;
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 /* Whether this is a varargs function. If this is true, there will
kono
parents:
diff changeset
211 be at least one parameter. For "..." the last parameter type is
kono
parents:
diff changeset
212 "interface{}". For "... T" the last parameter type is "[]T". */
kono
parents:
diff changeset
213 _Bool __dotdotdot;
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 /* The input parameter types. This is an array of pointers to
kono
parents:
diff changeset
216 struct __go_type_descriptor. */
kono
parents:
diff changeset
217 struct __go_open_array __in;
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 /* The output parameter types. This is an array of pointers to
kono
parents:
diff changeset
220 struct __go_type_descriptor. */
kono
parents:
diff changeset
221 struct __go_open_array __out;
kono
parents:
diff changeset
222 };
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 /* A method on an interface type. */
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 struct __go_interface_method
kono
parents:
diff changeset
227 {
kono
parents:
diff changeset
228 /* The name of the method. */
kono
parents:
diff changeset
229 const struct String *__name;
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 /* This is NULL for an exported method, or the name of the package
kono
parents:
diff changeset
232 where it lives. */
kono
parents:
diff changeset
233 const struct String *__pkg_path;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 /* The real type of the method. */
kono
parents:
diff changeset
236 struct __go_type_descriptor *__type;
kono
parents:
diff changeset
237 };
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 /* An interface type. */
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 struct __go_interface_type
kono
parents:
diff changeset
242 {
kono
parents:
diff changeset
243 /* Starts like all other type descriptors. */
kono
parents:
diff changeset
244 struct __go_type_descriptor __common;
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 /* Array of __go_interface_method . The methods are sorted in the
kono
parents:
diff changeset
247 same order that they appear in the definition of the
kono
parents:
diff changeset
248 interface. */
kono
parents:
diff changeset
249 struct __go_open_array __methods;
kono
parents:
diff changeset
250 };
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 /* A map type. */
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 struct __go_map_type
kono
parents:
diff changeset
255 {
kono
parents:
diff changeset
256 /* Starts like all other type descriptors. */
kono
parents:
diff changeset
257 struct __go_type_descriptor __common;
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 /* The map key type. */
kono
parents:
diff changeset
260 const struct __go_type_descriptor *__key_type;
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 /* The map value type. */
kono
parents:
diff changeset
263 const struct __go_type_descriptor *__val_type;
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 /* The map bucket type. */
kono
parents:
diff changeset
266 const struct __go_type_descriptor *__bucket_type;
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 /* The map header type. */
kono
parents:
diff changeset
269 const struct __go_type_descriptor *__hmap_type;
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 /* The size of the key slot. */
kono
parents:
diff changeset
272 uint8_t __key_size;
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 /* Whether to store a pointer to key rather than the key itself. */
kono
parents:
diff changeset
275 uint8_t __indirect_key;
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 /* The size of the value slot. */
kono
parents:
diff changeset
278 uint8_t __value_size;
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 /* Whether to store a pointer to value rather than the value itself. */
kono
parents:
diff changeset
281 uint8_t __indirect_value;
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 /* The size of a bucket. */
kono
parents:
diff changeset
284 uint16_t __bucket_size;
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 /* Whether the key type is reflexive--whether k==k for all keys. */
kono
parents:
diff changeset
287 _Bool __reflexive_key;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 /* Whether we should update the key when overwriting an entry. */
kono
parents:
diff changeset
290 _Bool __need_key_update;
kono
parents:
diff changeset
291 };
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 /* A pointer type. */
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 struct __go_ptr_type
kono
parents:
diff changeset
296 {
kono
parents:
diff changeset
297 /* Starts like all other type descriptors. */
kono
parents:
diff changeset
298 struct __go_type_descriptor __common;
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 /* The type to which this points. */
kono
parents:
diff changeset
301 const struct __go_type_descriptor *__element_type;
kono
parents:
diff changeset
302 };
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 /* A field in a structure. */
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 struct __go_struct_field
kono
parents:
diff changeset
307 {
kono
parents:
diff changeset
308 /* The name of the field--NULL for an anonymous field. */
kono
parents:
diff changeset
309 const struct String *__name;
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 /* This is NULL for an exported method, or the name of the package
kono
parents:
diff changeset
312 where it lives. */
kono
parents:
diff changeset
313 const struct String *__pkg_path;
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 /* The type of the field. */
kono
parents:
diff changeset
316 const struct __go_type_descriptor *__type;
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 /* The field tag, or NULL. */
kono
parents:
diff changeset
319 const struct String *__tag;
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 /* The offset of the field in the struct. */
kono
parents:
diff changeset
322 uintptr_t __offset;
kono
parents:
diff changeset
323 };
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 /* A struct type. */
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 struct __go_struct_type
kono
parents:
diff changeset
328 {
kono
parents:
diff changeset
329 /* Starts like all other type descriptors. */
kono
parents:
diff changeset
330 struct __go_type_descriptor __common;
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 /* An array of struct __go_struct_field. */
kono
parents:
diff changeset
333 struct __go_open_array __fields;
kono
parents:
diff changeset
334 };
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 /* Whether a type descriptor is a pointer. */
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 static inline _Bool
kono
parents:
diff changeset
339 __go_is_pointer_type (const struct __go_type_descriptor *td)
kono
parents:
diff changeset
340 {
kono
parents:
diff changeset
341 return ((td->__code & GO_CODE_MASK) == GO_PTR
kono
parents:
diff changeset
342 || (td->__code & GO_CODE_MASK) == GO_UNSAFE_POINTER);
kono
parents:
diff changeset
343 }
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 /* Call a type hash function, given the __hashfn value. */
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 static inline uintptr_t
kono
parents:
diff changeset
348 __go_call_hashfn (const FuncVal *hashfn, const void *p, uintptr_t seed,
kono
parents:
diff changeset
349 uintptr_t size)
kono
parents:
diff changeset
350 {
kono
parents:
diff changeset
351 uintptr_t (*h) (const void *, uintptr_t, uintptr_t) = (void *) hashfn->fn;
kono
parents:
diff changeset
352 return __builtin_call_with_static_chain (h (p, seed, size), hashfn);
kono
parents:
diff changeset
353 }
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 /* Call a type equality function, given the __equalfn value. */
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 static inline _Bool
kono
parents:
diff changeset
358 __go_call_equalfn (const FuncVal *equalfn, const void *p1, const void *p2,
kono
parents:
diff changeset
359 uintptr_t size)
kono
parents:
diff changeset
360 {
kono
parents:
diff changeset
361 _Bool (*e) (const void *, const void *, uintptr_t) = (void *) equalfn->fn;
kono
parents:
diff changeset
362 return __builtin_call_with_static_chain (e (p1, p2, size), equalfn);
kono
parents:
diff changeset
363 }
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 extern _Bool
kono
parents:
diff changeset
366 __go_type_descriptors_equal(const struct __go_type_descriptor*,
kono
parents:
diff changeset
367 const struct __go_type_descriptor*);
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 #endif /* !defined(LIBGO_GO_TYPE_H) */