internal/lib/reflect: type.method

This commit is contained in:
visualfc
2024-09-04 21:04:54 +08:00
parent 7b74cf1ab9
commit 9cc71b320b
2 changed files with 256 additions and 125 deletions

View File

@@ -226,6 +226,13 @@ func (mt *MapType) HashMightPanic() bool { // true if hash function might panic
return mt.Flags&16 != 0
}
func (t *Type) Key() *Type {
if t.Kind() == Map {
return (*MapType)(unsafe.Pointer(t)).Key
}
return nil
}
type PtrType struct {
Type
Elem *Type // pointer element (pointed at) type
@@ -408,6 +415,15 @@ type structTypeUncommon struct {
u UncommonType
}
// ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).
func (t *Type) ChanDir() ChanDir {
if t.Kind() == Chan {
ch := (*ChanType)(unsafe.Pointer(t))
return ch.Dir
}
return InvalidDir
}
// Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil
func (t *Type) Uncommon() *UncommonType {
if t.TFlag&TFlagUncommon == 0 {