reflectx

package module
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 14 Imported by: 4

README

reflectx

Golang reflect package hack tools

Go1.14 Go1.15 Go1.16 Go1.17 Go1.18 Go1.19 Go1.20 Go1.21

ABI

support ABI0 and ABIInternal

  • ABI0 stack-based ABI

  • ABIInternal register-based Go calling convention proposal

    • Go1.17: amd64
    • Go1.18: amd64 arm64 ppc64/ppc64le
    • Go1.19: amd64 arm64 ppc64/ppc64le riscv64
    • Go1.20: amd64 arm64 ppc64/ppc64le riscv64
    • Go1.21: amd64 arm64 ppc64/ppc64le riscv64
Field
  • reflectx.CanSet
  • reflectx.Field
  • reflectx.FieldByIndex
  • reflectx.FieldByName
  • reflectx.FieldByNameFunc
Named
  • reflectx.StructOf(fs)

  • reflectx.NamedTypeOf

  • SetUnderlying

  • SetTypeName

Method
  • reflectx.Method

  • reflectx.MakeMethod

  • reflectx.NewMethodSet

  • reflectx.SetMethodSet

  • reflectx.StructToMethodSet

Interface
  • reflectx.InterfaceOf
  • reflectx.NamedInterfaceOf
  • reflectx.NewInterfaceType
  • reflectx.SetInterfaceType
Context
  • reflectx.NewContext()
Method allocs
  • allocs
import _ "github.com/goplus/reflectx/icall/icall[N]"
  • install icall_gen
go get github.com/goplus/reflectx/cmd/icall_gen
icall_gen -o icall1024.go -pkg main -size 1024

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// disable unable allocate warning
	DisableAllocateWarning bool
)

Functions

func CanSet

func CanSet(v reflect.Value) reflect.Value

func DumpType added in v0.5.24

func DumpType(w io.Writer, typ reflect.Type)

func Field

func Field(s reflect.Value, i int) reflect.Value

func FieldByIndex

func FieldByIndex(s reflect.Value, index []int) reflect.Value

func FieldByIndexX added in v0.6.3

func FieldByIndexX(v reflect.Value, index []int) reflect.Value

func FieldByName

func FieldByName(s reflect.Value, name string) reflect.Value

func FieldByNameFunc

func FieldByNameFunc(s reflect.Value, match func(name string) bool) reflect.Value

func FieldByNameFuncX added in v0.6.3

func FieldByNameFuncX(v reflect.Value, match func(string) bool) reflect.Value

FieldByNameFunc returns the struct field with a name that satisfies the match function. It panics if v's Kind is not struct. It returns the zero Value if no field was found.

func FieldByNameX added in v0.6.3

func FieldByNameX(v reflect.Value, name string) reflect.Value

func FieldX added in v0.6.3

func FieldX(v reflect.Value, i int) reflect.Value

Field returns the i'th field of the struct v. It panics if v's Kind is not Struct or i is out of range.

func IcallStat added in v1.1.0

func IcallStat() (capacity int, allocate int, aviable int)

icall stat

func InterfaceOf added in v0.4.0

func InterfaceOf(embedded []reflect.Type, methods []reflect.Method) reflect.Type

func MakeEmptyInterface added in v0.4.0

func MakeEmptyInterface(pkgpath string, name string) reflect.Type

func MethodByIndex added in v0.4.0

func MethodByIndex(typ reflect.Type, index int) reflect.Method

func MethodByName added in v0.4.0

func MethodByName(typ reflect.Type, name string) (m reflect.Method, ok bool)

func MethodX added in v0.6.3

func MethodX(typ reflect.Type, i int) reflect.Method

func NamedInterfaceOf added in v0.4.0

func NamedInterfaceOf(pkgpath string, name string, embedded []reflect.Type, methods []reflect.Method) reflect.Type

func NamedStructOf added in v0.3.2

func NamedStructOf(pkgpath string, name string, fields []reflect.StructField) reflect.Type

func NamedTypeOf added in v0.3.5

func NamedTypeOf(pkgpath string, name string, from reflect.Type) reflect.Type

func NewInterfaceType added in v0.5.3

func NewInterfaceType(pkgpath string, name string) reflect.Type

func NewMethodSet added in v0.5.3

func NewMethodSet(styp reflect.Type, maxmfunc, maxpfunc int) reflect.Type

NewMethodSet is pre define method set of styp maxmfunc - set methodset of T max member func maxpfunc - set methodset of *T + T max member func

func NumMethodX added in v0.6.3

func NumMethodX(typ reflect.Type) int

func ReplaceType added in v0.5.5

func ReplaceType(pkg string, typ reflect.Type, m map[string]reflect.Type) (rtyp reflect.Type, changed bool)

func Reset added in v0.5.2

func Reset()

func ResetAll added in v1.1.1

func ResetAll()

func SetElem added in v0.5.4

func SetElem(typ reflect.Type, elem reflect.Type)

func SetInterfaceType added in v0.5.3

func SetInterfaceType(typ reflect.Type, embedded []reflect.Type, methods []reflect.Method) error

func SetMethodSet added in v0.5.3

func SetMethodSet(styp reflect.Type, methods []Method, extractStructEmbed bool) error

func SetTypeName added in v0.4.0

func SetTypeName(typ reflect.Type, pkgpath string, name string)

func SetUnderlying added in v0.6.2

func SetUnderlying(typ reflect.Type, styp reflect.Type)

func SetValue added in v0.3.5

func SetValue(v reflect.Value, x reflect.Value)

func StructOf

func StructOf(fields []reflect.StructField) reflect.Type

func StructToMethodSet added in v0.5.2

func StructToMethodSet(styp reflect.Type) reflect.Type
func TypeLinks() []reflect.Type

func TypesByString added in v0.5.14

func TypesByString(s string) []reflect.Type

func UpdateField added in v0.5.2

func UpdateField(typ reflect.Type, rmap map[reflect.Type]reflect.Type) bool

Types

type AllocError added in v1.1.1

type AllocError struct {
	Typ reflect.Type
	Cap int
	Req int
}

func (*AllocError) Error added in v1.1.1

func (p *AllocError) Error() string

type ChanDir added in v0.3.5

type ChanDir int

ChanDir represents a channel type's direction.

const (
	RecvDir ChanDir             = 1 << iota // <-chan
	SendDir                                 // chan<-
	BothDir = RecvDir | SendDir             // chan
)

type Context added in v1.1.0

type Context struct {
	// contains filtered or unexported fields
}
var Default *Context = NewContext()

func NewContext added in v1.1.0

func NewContext() *Context

func (*Context) IcallAlloc added in v1.1.0

func (ctx *Context) IcallAlloc() int

func (*Context) InterfaceOf added in v1.1.0

func (ctx *Context) InterfaceOf(embedded []reflect.Type, methods []reflect.Method) reflect.Type

func (*Context) NamedStructOf added in v1.1.0

func (ctx *Context) NamedStructOf(pkgpath string, name string, fields []reflect.StructField) reflect.Type

func (*Context) NewMethodSet added in v1.1.0

func (ctx *Context) NewMethodSet(styp reflect.Type, maxmfunc, maxpfunc int) reflect.Type

func (*Context) Reset added in v1.1.1

func (ctx *Context) Reset()

func (*Context) SetMethodSet added in v1.1.0

func (ctx *Context) SetMethodSet(styp reflect.Type, methods []Method, extractStructEmbed bool) error

func (*Context) StructOf added in v1.1.0

func (ctx *Context) StructOf(fields []reflect.StructField) reflect.Type

func (*Context) StructToMethodSet added in v1.1.0

func (ctx *Context) StructToMethodSet(styp reflect.Type) reflect.Type

StructToMethodSet extract method form struct embed fields

type Method added in v0.5.0

type Method struct {
	Name    string
	PkgPath string
	Pointer bool
	Type    reflect.Type
	Func    func([]reflect.Value) []reflect.Value
}

Method struct for MethodOf - name: method name - pointer: flag receiver struct or pointer - typ: method func type without receiver - fn: func with receiver as first argument

func MakeMethod added in v0.4.0

func MakeMethod(name string, pkgpath string, pointer bool, typ reflect.Type, fn func(args []reflect.Value) (result []reflect.Value)) Method

MakeMethod make reflect.Method for MethodOf - name: method name - pointer: flag receiver struct or pointer - typ: method func type without receiver - fn: func with receiver as first argument

type MethodInfo added in v0.7.0

type MethodInfo struct {
	Name     string
	Func     reflect.Value
	Type     reflect.Type
	InTyp    reflect.Type
	OutTyp   reflect.Type
	InSize   uintptr
	OutSize  uintptr
	Pointer  bool
	Indirect bool
	Variadic bool
	OnePtr   bool
}

type Value

type Value struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL