OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [runtime/] [go-type.h] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
/* 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
#define GO_NO_POINTERS (1 << 7)
57
 
58
#define GO_CODE_MASK 0x7f
59
 
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.  */
63
 
64
struct __go_type_descriptor
65
{
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;
71
 
72
  /* The alignment in bytes of a variable with this type.  */
73
  unsigned char __align;
74
 
75
  /* The alignment in bytes of a struct field with this type.  */
76
  unsigned char __field_align;
77
 
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;
81
 
82
  /* The type's hash code.  */
83
  uint32_t __hash;
84
 
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);
90
 
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);
94
 
95
  /* A string describing this type.  This is only used for
96
     debugging.  */
97
  const struct __go_string *__reflection;
98
 
99
  /* A pointer to fields which are only used for some types.  */
100
  const struct __go_uncommon_type *__uncommon;
101
 
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;
105
};
106
 
107
/* The information we store for each method of a type.  */
108
 
109
struct __go_method
110
{
111
  /* The name of the method.  */
112
  const struct __go_string *__name;
113
 
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;
117
 
118
  /* The type of the method, without the receiver.  This will be a
119
     function type.  */
120
  const struct __go_type_descriptor *__mtype;
121
 
122
  /* The type of the method, with the receiver.  This will be a
123
     function type.  */
124
  const struct __go_type_descriptor *__type;
125
 
126
  /* A pointer to the code which implements the method.  This is
127
     really a function pointer.  */
128
  const void *__function;
129
};
130
 
131
/* Additional information that we keep for named types and for types
132
   with methods.  */
133
 
134
struct __go_uncommon_type
135
{
136
  /* The name of the type.  */
137
  const struct __go_string *__name;
138
 
139
  /* The type's package.  This is NULL for builtin types.  */
140
  const struct __go_string *__pkg_path;
141
 
142
  /* The type's methods.  This is an array of struct __go_method.  */
143
  struct __go_open_array __methods;
144
};
145
 
146
/* The type descriptor for a fixed array type.  */
147
 
148
struct __go_array_type
149
{
150
  /* Starts like all type descriptors.  */
151
  struct __go_type_descriptor __common;
152
 
153
  /* The element type.  */
154
  struct __go_type_descriptor *__element_type;
155
 
156
  /* The type of a slice of the same element type.  */
157
  struct __go_type_descriptor *__slice_type;
158
 
159
  /* The length of the array.  */
160
  uintptr_t __len;
161
};
162
 
163
/* The type descriptor for a slice.  */
164
 
165
struct __go_slice_type
166
{
167
  /* Starts like all other type descriptors.  */
168
  struct __go_type_descriptor __common;
169
 
170
  /* The element type.  */
171
  struct __go_type_descriptor *__element_type;
172
};
173
 
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)
178
 
179
/* The type descriptor for a channel.  */
180
 
181
struct __go_channel_type
182
{
183
  /* Starts like all other type descriptors.  */
184
  struct __go_type_descriptor __common;
185
 
186
  /* The element type.  */
187
  const struct __go_type_descriptor *__element_type;
188
 
189
  /* The direction.  */
190
  uintptr_t __dir;
191
};
192
 
193
/* The type descriptor for a function.  */
194
 
195
struct __go_func_type
196
{
197
  /* Starts like all other type descriptors.  */
198
  struct __go_type_descriptor __common;
199
 
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;
204
 
205
  /* The input parameter types.  This is an array of pointers to
206
     struct __go_type_descriptor.  */
207
  struct __go_open_array __in;
208
 
209
  /* The output parameter types.  This is an array of pointers to
210
     struct __go_type_descriptor.  */
211
  struct __go_open_array __out;
212
};
213
 
214
/* A method on an interface type.  */
215
 
216
struct __go_interface_method
217
{
218
  /* The name of the method.  */
219
  const struct __go_string *__name;
220
 
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;
224
 
225
  /* The real type of the method.  */
226
  struct __go_type_descriptor *__type;
227
};
228
 
229
/* An interface type.  */
230
 
231
struct __go_interface_type
232
{
233
  /* Starts like all other type descriptors.  */
234
  struct __go_type_descriptor __common;
235
 
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;
240
};
241
 
242
/* A map type.  */
243
 
244
struct __go_map_type
245
{
246
  /* Starts like all other type descriptors.  */
247
  struct __go_type_descriptor __common;
248
 
249
  /* The map key type.  */
250
  const struct __go_type_descriptor *__key_type;
251
 
252
  /* The map value type.  */
253
  const struct __go_type_descriptor *__val_type;
254
};
255
 
256
/* A pointer type.  */
257
 
258
struct __go_ptr_type
259
{
260
  /* Starts like all other type descriptors.  */
261
  struct __go_type_descriptor __common;
262
 
263
  /* The type to which this points.  */
264
  const struct __go_type_descriptor *__element_type;
265
};
266
 
267
/* A field in a structure.  */
268
 
269
struct __go_struct_field
270
{
271
  /* The name of the field--NULL for an anonymous field.  */
272
  const struct __go_string *__name;
273
 
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;
277
 
278
  /* The type of the field.  */
279
  const struct __go_type_descriptor *__type;
280
 
281
  /* The field tag, or NULL.  */
282
  const struct __go_string *__tag;
283
 
284
  /* The offset of the field in the struct.  */
285
  uintptr_t __offset;
286
};
287
 
288
/* A struct type.  */
289
 
290
struct __go_struct_type
291
{
292
  /* Starts like all other type descriptors.  */
293
  struct __go_type_descriptor __common;
294
 
295
  /* An array of struct __go_struct_field.  */
296
  struct __go_open_array __fields;
297
};
298
 
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.  */
302
 
303
enum
304
{
305
  reflectFlags = 3,
306
};
307
 
308
/* Whether a type descriptor is a pointer.  */
309
 
310
static inline _Bool
311
__go_is_pointer_type (const struct __go_type_descriptor *td)
312
{
313
  return td->__code == GO_PTR || td->__code == GO_UNSAFE_POINTER;
314
}
315
 
316
extern _Bool
317
__go_type_descriptors_equal(const struct __go_type_descriptor*,
318
                            const struct __go_type_descriptor*);
319
 
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);
332
 
333
#endif /* !defined(LIBGO_GO_TYPE_H) */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.