2
* Copyright 2021 ByteDance Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
25
reflectRtypeItab = findReflectRtypeItab()
28
// GoType.KindFlags const
31
F_kind_mask = (1 << 5) - 1
36
tflagUncommon uint8 = 1 << 0
37
tflagExtraStar uint8 = 1 << 1
38
tflagNamed uint8 = 1 << 2
39
tflagRegularMemory uint8 = 1 << 3
56
func (self *GoType) IsNamed() bool {
57
return (self.Flags & tflagNamed) != 0
60
func (self *GoType) Kind() reflect.Kind {
61
return reflect.Kind(self.KindFlags & F_kind_mask)
64
func (self *GoType) Pack() (t reflect.Type) {
65
(*GoIface)(unsafe.Pointer(&t)).Itab = reflectRtypeItab
66
(*GoIface)(unsafe.Pointer(&t)).Value = unsafe.Pointer(self)
70
func (self *GoType) String() string {
71
return self.Pack().String()
74
func (self *GoType) Indirect() bool {
75
return self.KindFlags & F_direct == 0
84
Buckets unsafe.Pointer
85
OldBuckets unsafe.Pointer
90
type GoMapIterator struct {
95
Buckets unsafe.Pointer
97
Overflow *[]unsafe.Pointer
98
OldOverflow *[]unsafe.Pointer
126
func (self GoEface) Pack() (v interface{}) {
127
*(*GoEface)(unsafe.Pointer(&v)) = self
131
type GoPtrType struct {
136
type GoMapType struct {
141
Hasher func(unsafe.Pointer, uintptr) uintptr
148
func (self *GoMapType) IndirectElem() bool {
149
return self.Flags & 2 != 0
152
type GoStructType struct {
155
Fields []GoStructField
158
type GoStructField struct {
164
type GoInterfaceType struct {
167
Methods []GoInterfaceMethod
170
type GoInterfaceMethod struct {
181
type GoString struct {
186
func PtrElem(t *GoType) *GoType {
187
return (*GoPtrType)(unsafe.Pointer(t)).Elem
190
func MapType(t *GoType) *GoMapType {
191
return (*GoMapType)(unsafe.Pointer(t))
194
func IfaceType(t *GoType) *GoInterfaceType {
195
return (*GoInterfaceType)(unsafe.Pointer(t))
198
func UnpackType(t reflect.Type) *GoType {
199
return (*GoType)((*GoIface)(unsafe.Pointer(&t)).Value)
202
func UnpackEface(v interface{}) GoEface {
203
return *(*GoEface)(unsafe.Pointer(&v))
206
func UnpackIface(v interface{}) GoIface {
207
return *(*GoIface)(unsafe.Pointer(&v))
210
func findReflectRtypeItab() *GoItab {
211
v := reflect.TypeOf(struct{}{})
212
return (*GoIface)(unsafe.Pointer(&v)).Itab