4751a594a59aa5aa58693da583a2e8688fab909c
[platform/upstream/gcc.git] / libgo / go / runtime / type.go
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Runtime type representation.
6
7 package runtime
8
9 import "unsafe"
10
11 type _type struct {
12         kind       uint8
13         align      int8
14         fieldAlign uint8
15         _          uint8
16         size       uintptr
17         hash       uint32
18
19         hashfn  func(unsafe.Pointer, uintptr, uintptr) uintptr
20         equalfn func(unsafe.Pointer, unsafe.Pointer, uintptr) bool
21
22         gc     unsafe.Pointer
23         string *string
24         *uncommontype
25         ptrToThis *_type
26 }
27
28 // Return whether two type descriptors are equal.
29 // This is gccgo-specific, as gccgo, unlike gc, permits multiple
30 // independent descriptors for a single type.
31 func eqtype(t1, t2 *_type) bool {
32         switch {
33         case t1 == t2:
34                 return true
35         case t1 == nil || t2 == nil:
36                 return false
37         case t1.kind != t2.kind || t1.hash != t2.hash:
38                 return false
39         default:
40                 return *t1.string == *t2.string
41         }
42 }
43
44 type method struct {
45         name    *string
46         pkgPath *string
47         mtyp    *_type
48         typ     *_type
49         tfn     unsafe.Pointer
50 }
51
52 type uncommontype struct {
53         name    *string
54         pkgPath *string
55         methods []method
56 }
57
58 type imethod struct {
59         name    *string
60         pkgPath *string
61         typ     *_type
62 }
63
64 type interfacetype struct {
65         typ     _type
66         methods []imethod
67 }
68
69 type maptype struct {
70         typ           _type
71         key           *_type
72         elem          *_type
73         bucket        *_type // internal type representing a hash bucket
74         hmap          *_type // internal type representing a hmap
75         keysize       uint8  // size of key slot
76         indirectkey   bool   // store ptr to key instead of key itself
77         valuesize     uint8  // size of value slot
78         indirectvalue bool   // store ptr to value instead of value itself
79         bucketsize    uint16 // size of bucket
80         reflexivekey  bool   // true if k==k for all keys
81         needkeyupdate bool   // true if we need to update key on an overwrite
82 }
83
84 type arraytype struct {
85         typ   _type
86         elem  *_type
87         slice *_type
88         len   uintptr
89 }
90
91 type chantype struct {
92         typ  _type
93         elem *_type
94         dir  uintptr
95 }
96
97 type slicetype struct {
98         typ  _type
99         elem *_type
100 }
101
102 type functype struct {
103         typ       _type
104         dotdotdot bool
105         in        []*_type
106         out       []*_type
107 }
108
109 type ptrtype struct {
110         typ  _type
111         elem *_type
112 }
113
114 type structfield struct {
115         name    *string // nil for embedded fields
116         pkgPath *string // nil for exported Names; otherwise import path
117         typ     *_type  // type of field
118         tag     *string // nil if no tag
119         offset  uintptr // byte offset of field within struct
120 }
121
122 type structtype struct {
123         typ    _type
124         fields []structfield
125 }