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
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. */
44 #define GO_COMPLEX64 15
45 #define GO_COMPLEX128 16
49 #define GO_INTERFACE 20
55 #define GO_UNSAFE_POINTER 26
57 #define GO_DIRECT_IFACE (1 << 5)
58 #define GO_GC_PROG (1 << 6)
59 #define GO_NO_POINTERS (1 << 7)
61 #define GO_CODE_MASK 0x1f
63 /* For each Go type the compiler constructs one of these structures.
64 This is used for type reflection, interfaces, maps, and reference
67 struct __go_type_descriptor
69 /* The type code for this type, one of the type kind values above.
70 This is used by unsafe.Reflect and unsafe.Typeof to determine the
71 type descriptor to return for this type itself. It is also used
72 by reflect.toType when mapping to a reflect Type structure. */
75 /* The alignment in bytes of a variable with this type. */
76 unsigned char __align
;
78 /* The alignment in bytes of a struct field with this type. */
79 unsigned char __field_align
;
81 /* The size in bytes of a value of this type. Note that all types
82 in Go have a fixed size. */
85 /* The type's hash code. */
88 /* This function takes a pointer to a value of this type, and the
89 size of this type, and returns a hash code. We pass the size
90 explicitly becaues it means that we can share a single instance
91 of this function for various different types. */
92 uintptr_t (*__hashfn
) (const void *, uintptr_t);
94 /* This function takes two pointers to values of this type, and the
95 size of this type, and returns whether the values are equal. */
96 _Bool (*__equalfn
) (const void *, const void *, uintptr_t);
98 /* The garbage collection data. */
101 /* A string describing this type. This is only used for
103 const struct String
*__reflection
;
105 /* A pointer to fields which are only used for some types. */
106 const struct __go_uncommon_type
*__uncommon
;
108 /* The descriptor for the type which is a pointer to this type.
110 const struct __go_type_descriptor
*__pointer_to_this
;
112 /* A pointer to a zero value for this type. All types will point to
113 the same zero value, go$zerovalue, which is a common variable so
114 that it will be large enough. */
118 /* The information we store for each method of a type. */
122 /* The name of the method. */
123 const struct String
*__name
;
125 /* This is NULL for an exported method, or the name of the package
127 const struct String
*__pkg_path
;
129 /* The type of the method, without the receiver. This will be a
131 const struct __go_type_descriptor
*__mtype
;
133 /* The type of the method, with the receiver. This will be a
135 const struct __go_type_descriptor
*__type
;
137 /* A pointer to the code which implements the method. This is
138 really a function pointer. */
139 const void *__function
;
142 /* Additional information that we keep for named types and for types
145 struct __go_uncommon_type
147 /* The name of the type. */
148 const struct String
*__name
;
150 /* The type's package. This is NULL for builtin types. */
151 const struct String
*__pkg_path
;
153 /* The type's methods. This is an array of struct __go_method. */
154 struct __go_open_array __methods
;
157 /* The type descriptor for a fixed array type. */
159 struct __go_array_type
161 /* Starts like all type descriptors. */
162 struct __go_type_descriptor __common
;
164 /* The element type. */
165 struct __go_type_descriptor
*__element_type
;
167 /* The type of a slice of the same element type. */
168 struct __go_type_descriptor
*__slice_type
;
170 /* The length of the array. */
174 /* The type descriptor for a slice. */
176 struct __go_slice_type
178 /* Starts like all other type descriptors. */
179 struct __go_type_descriptor __common
;
181 /* The element type. */
182 struct __go_type_descriptor
*__element_type
;
185 /* The direction of a channel. */
186 #define CHANNEL_RECV_DIR 1
187 #define CHANNEL_SEND_DIR 2
188 #define CHANNEL_BOTH_DIR (CHANNEL_RECV_DIR | CHANNEL_SEND_DIR)
190 /* The type descriptor for a channel. */
192 struct __go_channel_type
194 /* Starts like all other type descriptors. */
195 struct __go_type_descriptor __common
;
197 /* The element type. */
198 const struct __go_type_descriptor
*__element_type
;
204 /* The type descriptor for a function. */
206 struct __go_func_type
208 /* Starts like all other type descriptors. */
209 struct __go_type_descriptor __common
;
211 /* Whether this is a varargs function. If this is true, there will
212 be at least one parameter. For "..." the last parameter type is
213 "interface{}". For "... T" the last parameter type is "[]T". */
216 /* The input parameter types. This is an array of pointers to
217 struct __go_type_descriptor. */
218 struct __go_open_array __in
;
220 /* The output parameter types. This is an array of pointers to
221 struct __go_type_descriptor. */
222 struct __go_open_array __out
;
225 /* A method on an interface type. */
227 struct __go_interface_method
229 /* The name of the method. */
230 const struct String
*__name
;
232 /* This is NULL for an exported method, or the name of the package
234 const struct String
*__pkg_path
;
236 /* The real type of the method. */
237 struct __go_type_descriptor
*__type
;
240 /* An interface type. */
242 struct __go_interface_type
244 /* Starts like all other type descriptors. */
245 struct __go_type_descriptor __common
;
247 /* Array of __go_interface_method . The methods are sorted in the
248 same order that they appear in the definition of the
250 struct __go_open_array __methods
;
257 /* Starts like all other type descriptors. */
258 struct __go_type_descriptor __common
;
260 /* The map key type. */
261 const struct __go_type_descriptor
*__key_type
;
263 /* The map value type. */
264 const struct __go_type_descriptor
*__val_type
;
267 /* A pointer type. */
271 /* Starts like all other type descriptors. */
272 struct __go_type_descriptor __common
;
274 /* The type to which this points. */
275 const struct __go_type_descriptor
*__element_type
;
278 /* A field in a structure. */
280 struct __go_struct_field
282 /* The name of the field--NULL for an anonymous field. */
283 const struct String
*__name
;
285 /* This is NULL for an exported method, or the name of the package
287 const struct String
*__pkg_path
;
289 /* The type of the field. */
290 const struct __go_type_descriptor
*__type
;
292 /* The field tag, or NULL. */
293 const struct String
*__tag
;
295 /* The offset of the field in the struct. */
301 struct __go_struct_type
303 /* Starts like all other type descriptors. */
304 struct __go_type_descriptor __common
;
306 /* An array of struct __go_struct_field. */
307 struct __go_open_array __fields
;
310 /* Whether a type descriptor is a pointer. */
313 __go_is_pointer_type (const struct __go_type_descriptor
*td
)
315 return ((td
->__code
& GO_CODE_MASK
) == GO_PTR
316 || (td
->__code
& GO_CODE_MASK
) == GO_UNSAFE_POINTER
);
320 __go_type_descriptors_equal(const struct __go_type_descriptor
*,
321 const struct __go_type_descriptor
*);
323 extern uintptr_t __go_type_hash_identity (const void *, uintptr_t);
324 extern _Bool
__go_type_equal_identity (const void *, const void *, uintptr_t);
325 extern uintptr_t __go_type_hash_string (const void *, uintptr_t);
326 extern _Bool
__go_type_equal_string (const void *, const void *, uintptr_t);
327 extern uintptr_t __go_type_hash_float (const void *, uintptr_t);
328 extern _Bool
__go_type_equal_float (const void *, const void *, uintptr_t);
329 extern uintptr_t __go_type_hash_complex (const void *, uintptr_t);
330 extern _Bool
__go_type_equal_complex (const void *, const void *, uintptr_t);
331 extern uintptr_t __go_type_hash_interface (const void *, uintptr_t);
332 extern _Bool
__go_type_equal_interface (const void *, const void *, uintptr_t);
333 extern uintptr_t __go_type_hash_error (const void *, uintptr_t);
334 extern _Bool
__go_type_equal_error (const void *, const void *, uintptr_t);
336 #endif /* !defined(LIBGO_GO_TYPE_H) */