N3778: Sized Deallocation
[official-gcc.git] / libgo / runtime / go-type.h
blob74e8340059844f0df699b7d6aeef35e7493a679d
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 "array.h"
15 struct String;
17 /* Many of the types in this file must match the data structures
18 generated by the compiler, and must also match the Go types which
19 appear in go/runtime/type.go and go/reflect/type.go. */
21 /* Type kinds. These are used to get the type descriptor to use for
22 the type itself, when using unsafe.Typeof or unsafe.Reflect. The
23 values here must match the values generated by the compiler (the
24 RUNTIME_TYPE_KIND_xxx values in gcc/go/types.h). These are macros
25 rather than an enum to make it easy to change values in the future
26 and hard to get confused about it.
28 These correspond to the kind values used by the gc compiler. */
30 #define GO_BOOL 1
31 #define GO_INT 2
32 #define GO_INT8 3
33 #define GO_INT16 4
34 #define GO_INT32 5
35 #define GO_INT64 6
36 #define GO_UINT 7
37 #define GO_UINT8 8
38 #define GO_UINT16 9
39 #define GO_UINT32 10
40 #define GO_UINT64 11
41 #define GO_UINTPTR 12
42 #define GO_FLOAT32 13
43 #define GO_FLOAT64 14
44 #define GO_COMPLEX64 15
45 #define GO_COMPLEX128 16
46 #define GO_ARRAY 17
47 #define GO_CHAN 18
48 #define GO_FUNC 19
49 #define GO_INTERFACE 20
50 #define GO_MAP 21
51 #define GO_PTR 22
52 #define GO_SLICE 23
53 #define GO_STRING 24
54 #define GO_STRUCT 25
55 #define GO_UNSAFE_POINTER 26
57 #define GO_NO_POINTERS (1 << 7)
59 #define GO_CODE_MASK 0x7f
61 /* For each Go type the compiler constructs one of these structures.
62 This is used for type reflection, interfaces, maps, and reference
63 counting. */
65 struct __go_type_descriptor
67 /* The type code for this type, one of the type kind values above.
68 This is used by unsafe.Reflect and unsafe.Typeof to determine the
69 type descriptor to return for this type itself. It is also used
70 by reflect.toType when mapping to a reflect Type structure. */
71 unsigned char __code;
73 /* The alignment in bytes of a variable with this type. */
74 unsigned char __align;
76 /* The alignment in bytes of a struct field with this type. */
77 unsigned char __field_align;
79 /* The size in bytes of a value of this type. Note that all types
80 in Go have a fixed size. */
81 uintptr_t __size;
83 /* The type's hash code. */
84 uint32_t __hash;
86 /* This function takes a pointer to a value of this type, and the
87 size of this type, and returns a hash code. We pass the size
88 explicitly becaues it means that we can share a single instance
89 of this function for various different types. */
90 uintptr_t (*__hashfn) (const void *, uintptr_t);
92 /* This function takes two pointers to values of this type, and the
93 size of this type, and returns whether the values are equal. */
94 _Bool (*__equalfn) (const void *, const void *, uintptr_t);
96 /* The garbage collection data. */
97 const uintptr *__gc;
99 /* A string describing this type. This is only used for
100 debugging. */
101 const struct String *__reflection;
103 /* A pointer to fields which are only used for some types. */
104 const struct __go_uncommon_type *__uncommon;
106 /* The descriptor for the type which is a pointer to this type.
107 This may be NULL. */
108 const struct __go_type_descriptor *__pointer_to_this;
110 /* A pointer to a zero value for this type. All types will point to
111 the same zero value, go$zerovalue, which is a common variable so
112 that it will be large enough. */
113 void *__zero;
116 /* The information we store for each method of a type. */
118 struct __go_method
120 /* The name of the method. */
121 const struct String *__name;
123 /* This is NULL for an exported method, or the name of the package
124 where it lives. */
125 const struct String *__pkg_path;
127 /* The type of the method, without the receiver. This will be a
128 function type. */
129 const struct __go_type_descriptor *__mtype;
131 /* The type of the method, with the receiver. This will be a
132 function type. */
133 const struct __go_type_descriptor *__type;
135 /* A pointer to the code which implements the method. This is
136 really a function pointer. */
137 const void *__function;
140 /* Additional information that we keep for named types and for types
141 with methods. */
143 struct __go_uncommon_type
145 /* The name of the type. */
146 const struct String *__name;
148 /* The type's package. This is NULL for builtin types. */
149 const struct String *__pkg_path;
151 /* The type's methods. This is an array of struct __go_method. */
152 struct __go_open_array __methods;
155 /* The type descriptor for a fixed array type. */
157 struct __go_array_type
159 /* Starts like all type descriptors. */
160 struct __go_type_descriptor __common;
162 /* The element type. */
163 struct __go_type_descriptor *__element_type;
165 /* The type of a slice of the same element type. */
166 struct __go_type_descriptor *__slice_type;
168 /* The length of the array. */
169 uintptr_t __len;
172 /* The type descriptor for a slice. */
174 struct __go_slice_type
176 /* Starts like all other type descriptors. */
177 struct __go_type_descriptor __common;
179 /* The element type. */
180 struct __go_type_descriptor *__element_type;
183 /* The direction of a channel. */
184 #define CHANNEL_RECV_DIR 1
185 #define CHANNEL_SEND_DIR 2
186 #define CHANNEL_BOTH_DIR (CHANNEL_RECV_DIR | CHANNEL_SEND_DIR)
188 /* The type descriptor for a channel. */
190 struct __go_channel_type
192 /* Starts like all other type descriptors. */
193 struct __go_type_descriptor __common;
195 /* The element type. */
196 const struct __go_type_descriptor *__element_type;
198 /* The direction. */
199 uintptr_t __dir;
202 /* The type descriptor for a function. */
204 struct __go_func_type
206 /* Starts like all other type descriptors. */
207 struct __go_type_descriptor __common;
209 /* Whether this is a varargs function. If this is true, there will
210 be at least one parameter. For "..." the last parameter type is
211 "interface{}". For "... T" the last parameter type is "[]T". */
212 _Bool __dotdotdot;
214 /* The input parameter types. This is an array of pointers to
215 struct __go_type_descriptor. */
216 struct __go_open_array __in;
218 /* The output parameter types. This is an array of pointers to
219 struct __go_type_descriptor. */
220 struct __go_open_array __out;
223 /* A method on an interface type. */
225 struct __go_interface_method
227 /* The name of the method. */
228 const struct String *__name;
230 /* This is NULL for an exported method, or the name of the package
231 where it lives. */
232 const struct String *__pkg_path;
234 /* The real type of the method. */
235 struct __go_type_descriptor *__type;
238 /* An interface type. */
240 struct __go_interface_type
242 /* Starts like all other type descriptors. */
243 struct __go_type_descriptor __common;
245 /* Array of __go_interface_method . The methods are sorted in the
246 same order that they appear in the definition of the
247 interface. */
248 struct __go_open_array __methods;
251 /* A map type. */
253 struct __go_map_type
255 /* Starts like all other type descriptors. */
256 struct __go_type_descriptor __common;
258 /* The map key type. */
259 const struct __go_type_descriptor *__key_type;
261 /* The map value type. */
262 const struct __go_type_descriptor *__val_type;
265 /* A pointer type. */
267 struct __go_ptr_type
269 /* Starts like all other type descriptors. */
270 struct __go_type_descriptor __common;
272 /* The type to which this points. */
273 const struct __go_type_descriptor *__element_type;
276 /* A field in a structure. */
278 struct __go_struct_field
280 /* The name of the field--NULL for an anonymous field. */
281 const struct String *__name;
283 /* This is NULL for an exported method, or the name of the package
284 where it lives. */
285 const struct String *__pkg_path;
287 /* The type of the field. */
288 const struct __go_type_descriptor *__type;
290 /* The field tag, or NULL. */
291 const struct String *__tag;
293 /* The offset of the field in the struct. */
294 uintptr_t __offset;
297 /* A struct type. */
299 struct __go_struct_type
301 /* Starts like all other type descriptors. */
302 struct __go_type_descriptor __common;
304 /* An array of struct __go_struct_field. */
305 struct __go_open_array __fields;
308 /* Whether a type descriptor is a pointer. */
310 static inline _Bool
311 __go_is_pointer_type (const struct __go_type_descriptor *td)
313 return td->__code == GO_PTR || td->__code == GO_UNSAFE_POINTER;
316 extern _Bool
317 __go_type_descriptors_equal(const struct __go_type_descriptor*,
318 const struct __go_type_descriptor*);
320 extern uintptr_t __go_type_hash_identity (const void *, uintptr_t);
321 extern _Bool __go_type_equal_identity (const void *, const void *, uintptr_t);
322 extern uintptr_t __go_type_hash_string (const void *, uintptr_t);
323 extern _Bool __go_type_equal_string (const void *, const void *, uintptr_t);
324 extern uintptr_t __go_type_hash_float (const void *, uintptr_t);
325 extern _Bool __go_type_equal_float (const void *, const void *, uintptr_t);
326 extern uintptr_t __go_type_hash_complex (const void *, uintptr_t);
327 extern _Bool __go_type_equal_complex (const void *, const void *, uintptr_t);
328 extern uintptr_t __go_type_hash_interface (const void *, uintptr_t);
329 extern _Bool __go_type_equal_interface (const void *, const void *, uintptr_t);
330 extern uintptr_t __go_type_hash_error (const void *, uintptr_t);
331 extern _Bool __go_type_equal_error (const void *, const void *, uintptr_t);
333 #endif /* !defined(LIBGO_GO_TYPE_H) */