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
13 #include "go-string.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. */
43 #define GO_COMPLEX64 15
44 #define GO_COMPLEX128 16
48 #define GO_INTERFACE 20
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
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. */
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. */
78 /* The type's hash code. */
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
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. */
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
108 const struct __go_string
*__pkg_path
;
110 /* The type of the method, without the receiver. This will be a
112 const struct __go_type_descriptor
*__mtype
;
114 /* The type of the method, with the receiver. This will be a
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
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. */
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
;
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". */
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
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
228 struct __go_open_array __methods
;
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. */
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
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. */
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. */
291 __go_is_pointer_type (const struct __go_type_descriptor
*td
)
293 return td
->__code
== GO_PTR
|| td
->__code
== GO_UNSAFE_POINTER
;
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) */