OSDN Git Service

mn10300: Add attribute enabled.
[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_FLOAT 13
42 #define GO_FLOAT32 14
43 #define GO_FLOAT64 15
44 #define GO_COMPLEX 16
45 #define GO_COMPLEX64 17
46 #define GO_COMPLEX128 18
47 #define GO_ARRAY 19
48 #define GO_CHAN 20
49 #define GO_FUNC 21
50 #define GO_INTERFACE 22
51 #define GO_MAP 23
52 #define GO_PTR 24
53 #define GO_SLICE 25
54 #define GO_STRING 26
55 #define GO_STRUCT 27
56 #define GO_UNSAFE_POINTER 28
57
58 /* For each Go type the compiler constructs one of these structures.
59    This is used for type reflectin, interfaces, maps, and reference
60    counting.  */
61
62 struct __go_type_descriptor
63 {
64   /* The type code for this type, a value in enum __go_type_codes.
65      This is used by unsafe.Reflect and unsafe.Typeof to determine the
66      type descriptor to return for this type itself.  It is also used
67      by reflect.toType when mapping to a reflect Type structure.  */
68   unsigned char __code;
69
70   /* The alignment in bytes of a variable with this type.  */
71   unsigned char __align;
72
73   /* The alignment in bytes of a struct field with this type.  */
74   unsigned char __field_align;
75
76   /* The size in bytes of a value of this type.  Note that all types
77      in Go have a fixed size.  */
78   uintptr_t __size;
79
80   /* The type's hash code.  */
81   uint32_t __hash;
82
83   /* This function takes a pointer to a value of this type, and the
84      size of this type, and returns a hash code.  We pass the size
85      explicitly becaues it means that we can share a single instance
86      of this function for various different types.  */
87   size_t (*__hashfn) (const void *, size_t);
88
89   /* This function takes two pointers to values of this type, and the
90      size of this type, and returns whether the values are equal.  */
91   _Bool (*__equalfn) (const void *, const void *, size_t);
92
93   /* A string describing this type.  This is only used for
94      debugging.  */
95   const struct __go_string *__reflection;
96
97   /* A pointer to fields which are only used for some types.  */
98   const struct __go_uncommon_type *__uncommon;
99 };
100
101 /* The information we store for each method of a type.  */
102
103 struct __go_method
104 {
105   /* The name of the method.  */
106   const struct __go_string *__name;
107
108   /* This is NULL for an exported method, or the name of the package
109      where it lives.  */
110   const struct __go_string *__pkg_path;
111
112   /* The type of the method, without the receiver.  This will be a
113      function type.  */
114   const struct __go_type_descriptor *__mtype;
115
116   /* The type of the method, with the receiver.  This will be a
117      function type.  */
118   const struct __go_type_descriptor *__type;
119
120   /* A pointer to the code which implements the method.  This is
121      really a function pointer.  */
122   const void *__function;
123 };
124
125 /* Additional information that we keep for named types and for types
126    with methods.  */
127
128 struct __go_uncommon_type
129 {
130   /* The name of the type.  */
131   const struct __go_string *__name;
132
133   /* The type's package.  This is NULL for builtin types.  */
134   const struct __go_string *__pkg_path;
135
136   /* The type's methods.  This is an array of struct __go_method.  */
137   struct __go_open_array __methods;
138 };
139
140 /* The type descriptor for a fixed array type.  */
141
142 struct __go_array_type
143 {
144   /* Starts like all type descriptors.  */
145   struct __go_type_descriptor __common;
146
147   /* The element type.  */
148   struct __go_type_descriptor *__element_type;
149
150   /* The length of the array.  */
151   uintptr_t __len;
152 };
153
154 /* The type descriptor for a slice.  */
155
156 struct __go_slice_type
157 {
158   /* Starts like all other type descriptors.  */
159   struct __go_type_descriptor __common;
160
161   /* The element type.  */
162   struct __go_type_descriptor *__element_type;
163 };
164
165 /* The direction of a channel.  */
166 #define CHANNEL_RECV_DIR 1
167 #define CHANNEL_SEND_DIR 2
168 #define CHANNEL_BOTH_DIR (CHANNEL_RECV_DIR | CHANNEL_SEND_DIR)
169
170 /* The type descriptor for a channel.  */
171
172 struct __go_channel_type
173 {
174   /* Starts like all other type descriptors.  */
175   struct __go_type_descriptor __common;
176
177   /* The element type.  */
178   const struct __go_type_descriptor *__element_type;
179
180   /* The direction.  */
181   uintptr_t __dir;
182 };
183
184 /* The type descriptor for a function.  */
185
186 struct __go_func_type
187 {
188   /* Starts like all other type descriptors.  */
189   struct __go_type_descriptor __common;
190
191   /* Whether this is a varargs function.  If this is true, there will
192      be at least one parameter.  For "..." the last parameter type is
193      "interface{}".  For "... T" the last parameter type is "[]T".  */
194   _Bool __dotdotdot;
195
196   /* The input parameter types.  This is an array of pointers to
197      struct __go_type_descriptor.  */
198   struct __go_open_array __in;
199
200   /* The output parameter types.  This is an array of pointers to
201      struct __go_type_descriptor.  */
202   struct __go_open_array __out;
203 };
204
205 /* A method on an interface type.  */
206
207 struct __go_interface_method
208 {
209   /* The name of the method.  */
210   const struct __go_string *__name;
211
212   /* This is NULL for an exported method, or the name of the package
213      where it lives.  */
214   const struct __go_string *__pkg_path;
215
216   /* The real type of the method.  */
217   struct __go_type_descriptor *__type;
218 };
219
220 /* An interface type.  */
221
222 struct __go_interface_type
223 {
224   /* Starts like all other type descriptors.  */
225   struct __go_type_descriptor __common;
226
227   /* Array of __go_interface_method .  The methods are sorted in the
228      same order that they appear in the definition of the
229      interface.  */
230   struct __go_open_array __methods;
231 };
232
233 /* A map type.  */
234
235 struct __go_map_type
236 {
237   /* Starts like all other type descriptors.  */
238   struct __go_type_descriptor __common;
239
240   /* The map key type.  */
241   const struct __go_type_descriptor *__key_type;
242
243   /* The map value type.  */
244   const struct __go_type_descriptor *__val_type;
245 };
246
247 /* A pointer type.  */
248
249 struct __go_ptr_type
250 {
251   /* Starts like all other type descriptors.  */
252   struct __go_type_descriptor __common;
253
254   /* The type to which this points.  */
255   const struct __go_type_descriptor *__element_type;
256 };
257
258 /* A field in a structure.  */
259
260 struct __go_struct_field
261 {
262   /* The name of the field--NULL for an anonymous field.  */
263   const struct __go_string *__name;
264
265   /* This is NULL for an exported method, or the name of the package
266      where it lives.  */
267   const struct __go_string *__pkg_path;
268
269   /* The type of the field.  */
270   const struct __go_type_descriptor *__type;
271
272   /* The field tag, or NULL.  */
273   const struct __go_string *__tag;
274
275   /* The offset of the field in the struct.  */
276   uintptr_t __offset;
277 };
278
279 /* A struct type.  */
280
281 struct __go_struct_type
282 {
283   /* Starts like all other type descriptors.  */
284   struct __go_type_descriptor __common;
285
286   /* An array of struct __go_struct_field.  */
287   struct __go_open_array __fields;
288 };
289
290 /* Whether a type descriptor is a pointer.  */
291
292 static inline _Bool
293 __go_is_pointer_type (const struct __go_type_descriptor *td)
294 {
295   return td->__code == GO_PTR || td->__code == GO_UNSAFE_POINTER;
296 }
297
298 extern _Bool
299 __go_type_descriptors_equal(const struct __go_type_descriptor*,
300                             const struct __go_type_descriptor*);
301
302 extern size_t __go_type_hash_identity (const void *, size_t);
303 extern _Bool __go_type_equal_identity (const void *, const void *, size_t);
304 extern size_t __go_type_hash_string (const void *, size_t);
305 extern _Bool __go_type_equal_string (const void *, const void *, size_t);
306 extern size_t __go_type_hash_interface (const void *, size_t);
307 extern _Bool __go_type_equal_interface (const void *, const void *, size_t);
308 extern size_t __go_type_hash_error (const void *, size_t);
309 extern _Bool __go_type_equal_error (const void *, const void *, size_t);
310
311 #endif /* !defined(LIBGO_GO_TYPE_H) */