rs6000.c: Delete unnecessary forward declarations.
[official-gcc.git] / libgo / runtime / go-type.h
blob25f096c485174e2e870ee920e1f6c882720009b3
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 #define GO_NO_POINTERS (1 << 7)
58 #define GO_CODE_MASK 0x7f
60 /* For each Go type the compiler constructs one of these structures.
61 This is used for type reflectin, interfaces, maps, and reference
62 counting. */
64 struct __go_type_descriptor
66 /* The type code for this type, one of the type kind values above.
67 This is used by unsafe.Reflect and unsafe.Typeof to determine the
68 type descriptor to return for this type itself. It is also used
69 by reflect.toType when mapping to a reflect Type structure. */
70 unsigned char __code;
72 /* The alignment in bytes of a variable with this type. */
73 unsigned char __align;
75 /* The alignment in bytes of a struct field with this type. */
76 unsigned char __field_align;
78 /* The size in bytes of a value of this type. Note that all types
79 in Go have a fixed size. */
80 uintptr_t __size;
82 /* The type's hash code. */
83 uint32_t __hash;
85 /* This function takes a pointer to a value of this type, and the
86 size of this type, and returns a hash code. We pass the size
87 explicitly becaues it means that we can share a single instance
88 of this function for various different types. */
89 uintptr_t (*__hashfn) (const void *, uintptr_t);
91 /* This function takes two pointers to values of this type, and the
92 size of this type, and returns whether the values are equal. */
93 _Bool (*__equalfn) (const void *, const void *, uintptr_t);
95 /* A string describing this type. This is only used for
96 debugging. */
97 const struct __go_string *__reflection;
99 /* A pointer to fields which are only used for some types. */
100 const struct __go_uncommon_type *__uncommon;
102 /* The descriptor for the type which is a pointer to this type.
103 This may be NULL. */
104 const struct __go_type_descriptor *__pointer_to_this;
107 /* The information we store for each method of a type. */
109 struct __go_method
111 /* The name of the method. */
112 const struct __go_string *__name;
114 /* This is NULL for an exported method, or the name of the package
115 where it lives. */
116 const struct __go_string *__pkg_path;
118 /* The type of the method, without the receiver. This will be a
119 function type. */
120 const struct __go_type_descriptor *__mtype;
122 /* The type of the method, with the receiver. This will be a
123 function type. */
124 const struct __go_type_descriptor *__type;
126 /* A pointer to the code which implements the method. This is
127 really a function pointer. */
128 const void *__function;
131 /* Additional information that we keep for named types and for types
132 with methods. */
134 struct __go_uncommon_type
136 /* The name of the type. */
137 const struct __go_string *__name;
139 /* The type's package. This is NULL for builtin types. */
140 const struct __go_string *__pkg_path;
142 /* The type's methods. This is an array of struct __go_method. */
143 struct __go_open_array __methods;
146 /* The type descriptor for a fixed array type. */
148 struct __go_array_type
150 /* Starts like all type descriptors. */
151 struct __go_type_descriptor __common;
153 /* The element type. */
154 struct __go_type_descriptor *__element_type;
156 /* The type of a slice of the same element type. */
157 struct __go_type_descriptor *__slice_type;
159 /* The length of the array. */
160 uintptr_t __len;
163 /* The type descriptor for a slice. */
165 struct __go_slice_type
167 /* Starts like all other type descriptors. */
168 struct __go_type_descriptor __common;
170 /* The element type. */
171 struct __go_type_descriptor *__element_type;
174 /* The direction of a channel. */
175 #define CHANNEL_RECV_DIR 1
176 #define CHANNEL_SEND_DIR 2
177 #define CHANNEL_BOTH_DIR (CHANNEL_RECV_DIR | CHANNEL_SEND_DIR)
179 /* The type descriptor for a channel. */
181 struct __go_channel_type
183 /* Starts like all other type descriptors. */
184 struct __go_type_descriptor __common;
186 /* The element type. */
187 const struct __go_type_descriptor *__element_type;
189 /* The direction. */
190 uintptr_t __dir;
193 /* The type descriptor for a function. */
195 struct __go_func_type
197 /* Starts like all other type descriptors. */
198 struct __go_type_descriptor __common;
200 /* Whether this is a varargs function. If this is true, there will
201 be at least one parameter. For "..." the last parameter type is
202 "interface{}". For "... T" the last parameter type is "[]T". */
203 _Bool __dotdotdot;
205 /* The input parameter types. This is an array of pointers to
206 struct __go_type_descriptor. */
207 struct __go_open_array __in;
209 /* The output parameter types. This is an array of pointers to
210 struct __go_type_descriptor. */
211 struct __go_open_array __out;
214 /* A method on an interface type. */
216 struct __go_interface_method
218 /* The name of the method. */
219 const struct __go_string *__name;
221 /* This is NULL for an exported method, or the name of the package
222 where it lives. */
223 const struct __go_string *__pkg_path;
225 /* The real type of the method. */
226 struct __go_type_descriptor *__type;
229 /* An interface type. */
231 struct __go_interface_type
233 /* Starts like all other type descriptors. */
234 struct __go_type_descriptor __common;
236 /* Array of __go_interface_method . The methods are sorted in the
237 same order that they appear in the definition of the
238 interface. */
239 struct __go_open_array __methods;
242 /* A map type. */
244 struct __go_map_type
246 /* Starts like all other type descriptors. */
247 struct __go_type_descriptor __common;
249 /* The map key type. */
250 const struct __go_type_descriptor *__key_type;
252 /* The map value type. */
253 const struct __go_type_descriptor *__val_type;
256 /* A pointer type. */
258 struct __go_ptr_type
260 /* Starts like all other type descriptors. */
261 struct __go_type_descriptor __common;
263 /* The type to which this points. */
264 const struct __go_type_descriptor *__element_type;
267 /* A field in a structure. */
269 struct __go_struct_field
271 /* The name of the field--NULL for an anonymous field. */
272 const struct __go_string *__name;
274 /* This is NULL for an exported method, or the name of the package
275 where it lives. */
276 const struct __go_string *__pkg_path;
278 /* The type of the field. */
279 const struct __go_type_descriptor *__type;
281 /* The field tag, or NULL. */
282 const struct __go_string *__tag;
284 /* The offset of the field in the struct. */
285 uintptr_t __offset;
288 /* A struct type. */
290 struct __go_struct_type
292 /* Starts like all other type descriptors. */
293 struct __go_type_descriptor __common;
295 /* An array of struct __go_struct_field. */
296 struct __go_open_array __fields;
299 /* If an empty interface has these bits set in its type pointer, it
300 was copied from a reflect.Value and is not a valid empty
301 interface. */
303 enum
305 reflectFlags = 3,
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) */