OSDN Git Service

Remove the types float and complex.
[pf3gnuchains/gcc-fork.git] / libgo / runtime / go-type.h
1 /* go-type.h -- basic information for a Go type.
2
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.  */
6
7 #ifndef LIBGO_GO_TYPE_H
8 #define LIBGO_GO_TYPE_H
9
10 #include <stddef.h>
11 #include <stdint.h>
12
13 #include "go-string.h"
14 #include "array.h"
15
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.  */
19
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.
26
27    These correspond to the kind values used by the gc compiler.  */
28
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
55
56 /* For each Go type the compiler constructs one of these structures.
57    This is used for type reflectin, interfaces, maps, and reference
58    counting.  */
59
60 struct __go_type_descriptor
61 {
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.  */
66   unsigned char __code;
67
68   /* The alignment in bytes of a variable with this type.  */
69   unsigned char __align;
70
71   /* The alignment in bytes of a struct field with this type.  */
72   unsigned char __field_align;
73
74   /* The size in bytes of a value of this type.  Note that all types
75      in Go have a fixed size.  */
76   uintptr_t __size;
77
78   /* The type's hash code.  */
79   uint32_t __hash;
80
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);
86
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);
90
91   /* A string describing this type.  This is only used for
92      debugging.  */
93   const struct __go_string *__reflection;
94
95   /* A pointer to fields which are only used for some types.  */
96   const struct __go_uncommon_type *__uncommon;
97 };
98
99 /* The information we store for each method of a type.  */
100
101 struct __go_method
102 {
103   /* The name of the method.  */
104   const struct __go_string *__name;
105
106   /* This is NULL for an exported method, or the name of the package
107      where it lives.  */
108   const struct __go_string *__pkg_path;
109
110   /* The type of the method, without the receiver.  This will be a
111      function type.  */
112   const struct __go_type_descriptor *__mtype;
113
114   /* The type of the method, with the receiver.  This will be a
115      function type.  */
116   const struct __go_type_descriptor *__type;
117
118   /* A pointer to the code which implements the method.  This is
119      really a function pointer.  */
120   const void *__function;
121 };
122
123 /* Additional information that we keep for named types and for types
124    with methods.  */
125
126 struct __go_uncommon_type
127 {
128   /* The name of the type.  */
129   const struct __go_string *__name;
130
131   /* The type's package.  This is NULL for builtin types.  */
132   const struct __go_string *__pkg_path;
133
134   /* The type's methods.  This is an array of struct __go_method.  */
135   struct __go_open_array __methods;
136 };
137
138 /* The type descriptor for a fixed array type.  */
139
140 struct __go_array_type
141 {
142   /* Starts like all type descriptors.  */
143   struct __go_type_descriptor __common;
144
145   /* The element type.  */
146   struct __go_type_descriptor *__element_type;
147
148   /* The length of the array.  */
149   uintptr_t __len;
150 };
151
152 /* The type descriptor for a slice.  */
153
154 struct __go_slice_type
155 {
156   /* Starts like all other type descriptors.  */
157   struct __go_type_descriptor __common;
158
159   /* The element type.  */
160   struct __go_type_descriptor *__element_type;
161 };
162
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)
167
168 /* The type descriptor for a channel.  */
169
170 struct __go_channel_type
171 {
172   /* Starts like all other type descriptors.  */
173   struct __go_type_descriptor __common;
174
175   /* The element type.  */
176   const struct __go_type_descriptor *__element_type;
177
178   /* The direction.  */
179   uintptr_t __dir;
180 };
181
182 /* The type descriptor for a function.  */
183
184 struct __go_func_type
185 {
186   /* Starts like all other type descriptors.  */
187   struct __go_type_descriptor __common;
188
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".  */
192   _Bool __dotdotdot;
193
194   /* The input parameter types.  This is an array of pointers to
195      struct __go_type_descriptor.  */
196   struct __go_open_array __in;
197
198   /* The output parameter types.  This is an array of pointers to
199      struct __go_type_descriptor.  */
200   struct __go_open_array __out;
201 };
202
203 /* A method on an interface type.  */
204
205 struct __go_interface_method
206 {
207   /* The name of the method.  */
208   const struct __go_string *__name;
209
210   /* This is NULL for an exported method, or the name of the package
211      where it lives.  */
212   const struct __go_string *__pkg_path;
213
214   /* The real type of the method.  */
215   struct __go_type_descriptor *__type;
216 };
217
218 /* An interface type.  */
219
220 struct __go_interface_type
221 {
222   /* Starts like all other type descriptors.  */
223   struct __go_type_descriptor __common;
224
225   /* Array of __go_interface_method .  The methods are sorted in the
226      same order that they appear in the definition of the
227      interface.  */
228   struct __go_open_array __methods;
229 };
230
231 /* A map type.  */
232
233 struct __go_map_type
234 {
235   /* Starts like all other type descriptors.  */
236   struct __go_type_descriptor __common;
237
238   /* The map key type.  */
239   const struct __go_type_descriptor *__key_type;
240
241   /* The map value type.  */
242   const struct __go_type_descriptor *__val_type;
243 };
244
245 /* A pointer type.  */
246
247 struct __go_ptr_type
248 {
249   /* Starts like all other type descriptors.  */
250   struct __go_type_descriptor __common;
251
252   /* The type to which this points.  */
253   const struct __go_type_descriptor *__element_type;
254 };
255
256 /* A field in a structure.  */
257
258 struct __go_struct_field
259 {
260   /* The name of the field--NULL for an anonymous field.  */
261   const struct __go_string *__name;
262
263   /* This is NULL for an exported method, or the name of the package
264      where it lives.  */
265   const struct __go_string *__pkg_path;
266
267   /* The type of the field.  */
268   const struct __go_type_descriptor *__type;
269
270   /* The field tag, or NULL.  */
271   const struct __go_string *__tag;
272
273   /* The offset of the field in the struct.  */
274   uintptr_t __offset;
275 };
276
277 /* A struct type.  */
278
279 struct __go_struct_type
280 {
281   /* Starts like all other type descriptors.  */
282   struct __go_type_descriptor __common;
283
284   /* An array of struct __go_struct_field.  */
285   struct __go_open_array __fields;
286 };
287
288 /* Whether a type descriptor is a pointer.  */
289
290 static inline _Bool
291 __go_is_pointer_type (const struct __go_type_descriptor *td)
292 {
293   return td->__code == GO_PTR || td->__code == GO_UNSAFE_POINTER;
294 }
295
296 extern _Bool
297 __go_type_descriptors_equal(const struct __go_type_descriptor*,
298                             const struct __go_type_descriptor*);
299
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);
308
309 #endif /* !defined(LIBGO_GO_TYPE_H) */