reflectlite

Imports

Imports #

"internal/goarch"
"internal/unsafeheader"
"unsafe"
"internal/abi"
"unsafe"
"internal/abi"
"internal/goarch"
"internal/unsafeheader"
"runtime"
"unsafe"

Constants & Variables

Interface const #

Import-and-export these constants as necessary

const Interface = abi.Interface

Ptr const #

const Ptr = abi.Pointer

Slice const #

const Slice = abi.Slice

String const #

const String = abi.String

Struct const #

const Struct = abi.Struct

dummy var #

var dummy struct{...}

flagAddr const #

const flagAddr flag = *ast.BinaryExpr

flagEmbedRO const #

const flagEmbedRO flag = *ast.BinaryExpr

flagIndir const #

const flagIndir flag = *ast.BinaryExpr

flagKindMask const #

const flagKindMask flag = *ast.BinaryExpr

flagKindWidth const #

const flagKindWidth = 5

flagMethod const #

const flagMethod flag = *ast.BinaryExpr

flagMethodShift const #

const flagMethodShift = 10

flagRO const #

const flagRO flag = *ast.BinaryExpr

flagStickyRO const #

const flagStickyRO flag = *ast.BinaryExpr

Type Aliases

Kind type #

A Kind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.

type Kind abi.Kind

arrayType type #

arrayType represents a fixed array type.

type arrayType abi.ArrayType

chanType type #

chanType represents a channel type.

type chanType abi.ChanType

flag type #

type flag uintptr

funcType type #

type funcType abi.FuncType

interfaceType type #

type interfaceType abi.InterfaceType

nameOff type #

type nameOff abi.NameOff

ptrType type #

ptrType represents a pointer type.

type ptrType abi.PtrType

sliceType type #

sliceType represents a slice type.

type sliceType abi.SliceType

structType type #

structType represents a struct type.

type structType abi.StructType

textOff type #

type textOff abi.TextOff

typeOff type #

type typeOff abi.TypeOff

uncommonType type #

uncommonType is present only for defined types or types with methods (if T is a defined type, the uncommonTypes for T and *T have methods). Using a pointer to this struct reduces the overall size required to describe a non-defined type with no methods.

type uncommonType abi.UncommonType

Interfaces

Type interface #

Type is the representation of a Go type. Not all methods apply to all kinds of types. Restrictions, if any, are noted in the documentation for each method. Use the Kind method to find out the kind of type before calling kind-specific methods. Calling a method inappropriate to the kind of type causes a run-time panic. Type values are comparable, such as with the == operator, so they can be used as map keys. Two Type values are equal if they represent identical types.

type Type interface {
Name() string
PkgPath() string
Size() uintptr
Kind() Kind
Implements(u Type) bool
AssignableTo(u Type) bool
Comparable() bool
String() string
Elem() Type
common() *abi.Type
uncommon() *uncommonType
}

Structs

Value struct #

Value is the reflection interface to a Go value. Not all methods apply to all kinds of values. Restrictions, if any, are noted in the documentation for each method. Use the Kind method to find out the kind of value before calling kind-specific methods. Calling a method inappropriate to the kind of type causes a run time panic. The zero Value represents no value. Its IsValid method returns false, its Kind method returns Invalid, its String method returns "", and all other methods panic. Most functions and methods never return an invalid value. If one does, its documentation states the conditions explicitly. A Value can be used concurrently by multiple goroutines provided that the underlying Go value can be used concurrently for the equivalent direct operations. To compare two Values, compare the results of the Interface method. Using == on two Values does not compare the underlying values they represent.

type Value struct {
typ_ *abi.Type
ptr unsafe.Pointer
flag
}

ValueError struct #

A ValueError occurs when a Value method is invoked on a Value that does not support it. Such cases are documented in the description of each method.

type ValueError struct {
Method string
Kind Kind
}

name struct #

name is an encoded type name with optional extra data. The first byte is a bit field containing: 1<<0 the name is exported 1<<1 tag data follows the name 1<<2 pkgPath nameOff follows the name and tag The next two bytes are the data length: l := uint16(data[1])<<8 | uint16(data[2]) Bytes [3:3+l] are the string data. If tag data follows then bytes 3+l and 3+l+1 are the tag length, with the data following. If the import path follows, then 4 bytes at the end of the data form a nameOff. The import path is only set for concrete methods that are defined in a different package than their type. If a name starts with "*", then the exported bit represents whether the pointed to type is exported.

type name struct {
bytes *byte
}

rtype struct #

type rtype struct {
*abi.Type
}

Functions

AssignableTo method #

func (t rtype) AssignableTo(u Type) bool

CanSet method #

CanSet reports whether the value of v can be changed. A Value can be changed only if it is addressable and was not obtained by the use of unexported struct fields. If CanSet returns false, calling Set or any type-specific setter (e.g., SetBool, SetInt) will panic.

func (v Value) CanSet() bool

Comparable method #

func (t rtype) Comparable() bool

Elem method #

Elem returns the value that the interface v contains or that the pointer v points to. It panics if v's Kind is not Interface or Pointer. It returns the zero Value if v is nil.

func (v Value) Elem() Value

Elem method #

func (t rtype) Elem() Type

Error method #

func (e *ValueError) Error() string

Implements method #

func (t rtype) Implements(u Type) bool

In method #

func (t rtype) In(i int) Type

IsNil method #

IsNil reports whether its argument v is nil. The argument must be a chan, func, interface, map, pointer, or slice value; if it is not, IsNil panics. Note that IsNil is not always equivalent to a regular comparison with nil in Go. For example, if v was created by calling ValueOf with an uninitialized interface variable i, i==nil will be true but v.IsNil will panic as v will be the zero Value.

func (v Value) IsNil() bool

IsValid method #

IsValid reports whether v represents a value. It returns false if v is the zero Value. If IsValid returns false, all other methods except String panic. Most functions and methods never return an invalid Value. If one does, its documentation states the conditions explicitly.

func (v Value) IsValid() bool

Key method #

func (t rtype) Key() Type

Kind method #

Kind returns v's Kind. If v is the zero Value (IsValid returns false), Kind returns Invalid.

func (v Value) Kind() Kind

Len method #

Len returns v's length. It panics if v's Kind is not Array, Chan, Map, Slice, or String.

func (v Value) Len() int

Len method #

func (t rtype) Len() int

Name method #

func (t rtype) Name() string

NumField method #

func (t rtype) NumField() int

NumIn method #

func (t rtype) NumIn() int

NumMethod method #

func (t rtype) NumMethod() int

NumOut method #

func (t rtype) NumOut() int

Out method #

func (t rtype) Out(i int) Type

PkgPath method #

func (t rtype) PkgPath() string

Set method #

Set assigns x to the value v. It panics if CanSet returns false. As in Go, x's value must be assignable to v's type.

func (v Value) Set(x Value)

String method #

func (t rtype) String() string

Swapper function #

Swapper returns a function that swaps the elements in the provided slice. Swapper panics if the provided interface is not a slice.

func Swapper(slice any) (func(i int, j int))

Type method #

Type returns v's type.

func (v Value) Type() Type

TypeOf function #

TypeOf returns the reflection Type that represents the dynamic type of i. If i is a nil interface value, TypeOf returns nil.

func TypeOf(i any) Type

ValueOf function #

ValueOf returns a new Value initialized to the concrete value stored in the interface i. ValueOf(nil) returns the zero Value.

func ValueOf(i any) Value

add function #

add returns p+x. The whySafe string is ignored, so that the function still inlines as efficiently as p+x, but all call sites should use the string to record why the addition is safe, which is to say why the addition does not cause x to advance to the very end of p's allocation and therefore point incorrectly at the next block in memory.

func add(p unsafe.Pointer, x uintptr, whySafe string) unsafe.Pointer

arrayAt function #

arrayAt returns the i-th element of p, an array whose elements are eltSize bytes wide. The array pointed at by p must have at least i+1 elements: it is invalid (but impossible to check here) to pass i >= len, because then the result will point outside the array. whySafe must explain why i < len. (Passing "i < len" is fine; the benefit is to surface this assumption at the call site.)

func arrayAt(p unsafe.Pointer, i int, eltSize uintptr, whySafe string) unsafe.Pointer

assignTo method #

assignTo returns a value v that can be assigned directly to typ. It panics if v is not assignable to typ. For a conversion to an interface type, target is a suggested scratch space to use.

func (v Value) assignTo(context string, dst *abi.Type, target unsafe.Pointer) Value

chanlen function #

go:noescape

func chanlen(unsafe.Pointer) int

common method #

func (t rtype) common() *abi.Type

data method #

func (n name) data(off int, whySafe string) *byte

directlyAssignable function #

directlyAssignable reports whether a value x of type V can be directly assigned (using memmove) to a value of type T. https://golang.org/doc/go_spec.html#Assignability Ignoring the interface rules (implemented elsewhere) and the ideal constant rules (no ideal constants at run time).

func directlyAssignable(T *abi.Type, V *abi.Type) bool

elem function #

func elem(t *abi.Type) *abi.Type

embedded method #

func (n name) embedded() bool

escapes function #

Dummy annotation marking that the value x escapes, for use in cases where the reflect code is so clever that the compiler cannot follow.

func escapes(x any)

exportedMethods method #

func (t rtype) exportedMethods() []abi.Method

hasTag method #

func (n name) hasTag() bool

haveIdenticalType function #

func haveIdenticalType(T *abi.Type, V *abi.Type, cmpTags bool) bool

haveIdenticalUnderlyingType function #

func haveIdenticalUnderlyingType(T *abi.Type, V *abi.Type, cmpTags bool) bool

ifaceE2I function #

func ifaceE2I(t *abi.Type, src any, dst unsafe.Pointer)

implements function #

implements reports whether the type V implements the interface type T.

func implements(T *abi.Type, V *abi.Type) bool

isExported method #

func (n name) isExported() bool

kind method #

func (f flag) kind() Kind

maplen function #

go:noescape

func maplen(unsafe.Pointer) int

methodName function #

methodName returns the name of the calling method, assumed to be two stack frames above.

func methodName() string

mustBeAssignable method #

mustBeAssignable panics if f records that the value is not assignable, which is to say that either it was obtained using an unexported field or it is not addressable.

func (f flag) mustBeAssignable()

mustBeExported method #

mustBeExported panics if f records that the value was obtained using an unexported field.

func (f flag) mustBeExported()

name method #

func (n name) name() string

nameOff method #

func (t rtype) nameOff(off nameOff) abi.Name

numMethod method #

NumMethod returns the number of exported methods in the value's method set.

func (v Value) numMethod() int

packEface function #

packEface converts v to the empty interface.

func packEface(v Value) any

pkgPath function #

func pkgPath(n abi.Name) string

pointer method #

pointer returns the underlying pointer represented by v. v.Kind() must be Pointer, Map, Chan, Func, or UnsafePointer

func (v Value) pointer() unsafe.Pointer

readVarint method #

readVarint parses a varint as encoded by encoding/binary. It returns the number of encoded bytes and the encoded value.

func (n name) readVarint(off int) (int, int)

resolveNameOff function #

resolveNameOff resolves a name offset from a base pointer. The (*rtype).nameOff method is a convenience wrapper for this function. Implemented in the runtime package. go:noescape

func resolveNameOff(ptrInModule unsafe.Pointer, off int32) unsafe.Pointer

resolveTypeOff function #

resolveTypeOff resolves an *rtype offset from a base type. The (*rtype).typeOff method is a convenience wrapper for this function. Implemented in the runtime package. go:noescape

func resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer

ro method #

func (f flag) ro() flag

tag method #

func (n name) tag() string

toRType function #

func toRType(t *abi.Type) rtype

toType function #

toType converts from a *rtype to a Type that can be returned to the client of package reflect. In gc, the only concern is that a nil *rtype must be replaced by a nil Type, but in gccgo this function takes care of ensuring that multiple *rtype for the same type are coalesced into a single Type.

func toType(t *abi.Type) Type

typ method #

func (v Value) typ() *abi.Type

typeOff method #

func (t rtype) typeOff(off typeOff) *abi.Type

typedmemmove function #

typedmemmove copies a value of type t to dst from src. go:noescape

func typedmemmove(t *abi.Type, dst unsafe.Pointer, src unsafe.Pointer)

uncommon method #

func (t rtype) uncommon() *uncommonType

unpackEface function #

unpackEface converts the empty interface i to a Value.

func unpackEface(i any) Value

unsafe_New function #

go:noescape

func unsafe_New(*abi.Type) unsafe.Pointer

valueInterface function #

func valueInterface(v Value) any

Generated with Arrow