github.com/gidoBOSSftw5731/go/src@v0.0.0-20210226122457-d24b0edbf019/reflect/export_test.go (about) 1 // Copyright 2012 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 package reflect 6 7 import "unsafe" 8 9 // MakeRO returns a copy of v with the read-only flag set. 10 func MakeRO(v Value) Value { 11 v.flag |= flagStickyRO 12 return v 13 } 14 15 // IsRO reports whether v's read-only flag is set. 16 func IsRO(v Value) bool { 17 return v.flag&flagStickyRO != 0 18 } 19 20 var CallGC = &callGC 21 22 const PtrSize = ptrSize 23 24 func FuncLayout(t Type, rcvr Type) (frametype Type, argSize, retOffset uintptr, stack []byte, gc []byte, ptrs bool) { 25 var ft *rtype 26 var abi abiDesc 27 if rcvr != nil { 28 ft, _, abi = funcLayout((*funcType)(unsafe.Pointer(t.(*rtype))), rcvr.(*rtype)) 29 } else { 30 ft, _, abi = funcLayout((*funcType)(unsafe.Pointer(t.(*rtype))), nil) 31 } 32 argSize = abi.stackCallArgsSize 33 retOffset = abi.retOffset 34 frametype = ft 35 for i := uint32(0); i < abi.stackPtrs.n; i++ { 36 stack = append(stack, abi.stackPtrs.data[i/8]>>(i%8)&1) 37 } 38 if ft.kind&kindGCProg != 0 { 39 panic("can't handle gc programs") 40 } 41 ptrs = ft.ptrdata != 0 42 if ptrs { 43 nptrs := ft.ptrdata / ptrSize 44 gcdata := ft.gcSlice(0, (nptrs+7)/8) 45 for i := uintptr(0); i < nptrs; i++ { 46 gc = append(gc, gcdata[i/8]>>(i%8)&1) 47 } 48 } 49 return 50 } 51 52 func TypeLinks() []string { 53 var r []string 54 sections, offset := typelinks() 55 for i, offs := range offset { 56 rodata := sections[i] 57 for _, off := range offs { 58 typ := (*rtype)(resolveTypeOff(unsafe.Pointer(rodata), off)) 59 r = append(r, typ.String()) 60 } 61 } 62 return r 63 } 64 65 var GCBits = gcbits 66 67 func gcbits(interface{}) []byte // provided by runtime 68 69 func MapBucketOf(x, y Type) Type { 70 return bucketOf(x.(*rtype), y.(*rtype)) 71 } 72 73 func CachedBucketOf(m Type) Type { 74 t := m.(*rtype) 75 if Kind(t.kind&kindMask) != Map { 76 panic("not map") 77 } 78 tt := (*mapType)(unsafe.Pointer(t)) 79 return tt.bucket 80 } 81 82 type EmbedWithUnexpMeth struct{} 83 84 func (EmbedWithUnexpMeth) f() {} 85 86 type pinUnexpMeth interface { 87 f() 88 } 89 90 var pinUnexpMethI = pinUnexpMeth(EmbedWithUnexpMeth{}) 91 92 func FirstMethodNameBytes(t Type) *byte { 93 _ = pinUnexpMethI 94 95 ut := t.uncommon() 96 if ut == nil { 97 panic("type has no methods") 98 } 99 m := ut.methods()[0] 100 mname := t.(*rtype).nameOff(m.name) 101 if *mname.data(0, "name flag field")&(1<<2) == 0 { 102 panic("method name does not have pkgPath *string") 103 } 104 return mname.bytes 105 } 106 107 type OtherPkgFields struct { 108 OtherExported int 109 otherUnexported int 110 } 111 112 func IsExported(t Type) bool { 113 typ := t.(*rtype) 114 n := typ.nameOff(typ.str) 115 return n.isExported() 116 } 117 118 func ResolveReflectName(s string) { 119 resolveReflectName(newName(s, "", false)) 120 } 121 122 type Buffer struct { 123 buf []byte 124 }