github.com/goccy/go-reflect@v1.2.1-0.20220925055700-4646ad15ec8a/reflect.go (about)

     1  package reflect
     2  
     3  import (
     4  	"reflect"
     5  	"unsafe"
     6  )
     7  
     8  // Type is the representation of a Go type.
     9  //
    10  // Not all methods apply to all kinds of types. Restrictions,
    11  // if any, are noted in the documentation for each method.
    12  // Use the Kind method to find out the kind of type before
    13  // calling kind-specific methods. Calling a method
    14  // inappropriate to the kind of type causes a run-time panic.
    15  //
    16  // Type values are comparable, such as with the == operator,
    17  // so they can be used as map keys.
    18  // Two Type values are equal if they represent identical types.
    19  type Type = *rtype
    20  
    21  type rtype struct{}
    22  
    23  type flag uintptr
    24  
    25  const (
    26  	flagKindWidth        = 5 // there are 27 kinds
    27  	flagKindMask    flag = 1<<flagKindWidth - 1
    28  	flagStickyRO    flag = 1 << 5
    29  	flagEmbedRO     flag = 1 << 6
    30  	flagIndir       flag = 1 << 7
    31  	flagAddr        flag = 1 << 8
    32  	flagMethod      flag = 1 << 9
    33  	flagMethodShift      = 10
    34  	flagRO          flag = flagStickyRO | flagEmbedRO
    35  )
    36  
    37  // A Kind represents the specific kind of type that a Type represents.
    38  // The zero Kind is not a valid kind.
    39  type Kind = reflect.Kind
    40  
    41  const (
    42  	Invalid Kind = iota
    43  	Bool
    44  	Int
    45  	Int8
    46  	Int16
    47  	Int32
    48  	Int64
    49  	Uint
    50  	Uint8
    51  	Uint16
    52  	Uint32
    53  	Uint64
    54  	Uintptr
    55  	Float32
    56  	Float64
    57  	Complex64
    58  	Complex128
    59  	Array
    60  	Chan
    61  	Func
    62  	Interface
    63  	Map
    64  	Ptr
    65  	Slice
    66  	String
    67  	Struct
    68  	UnsafePointer
    69  )
    70  
    71  const (
    72  	_             SelectDir = iota
    73  	SelectSend              // case Chan <- Send
    74  	SelectRecv              // case <-Chan:
    75  	SelectDefault           // default
    76  )
    77  
    78  // A StructTag is the tag string in a struct field.
    79  //
    80  // By convention, tag strings are a concatenation of
    81  // optionally space-separated key:"value" pairs.
    82  // Each key is a non-empty string consisting of non-control
    83  // characters other than space (U+0020 ' '), quote (U+0022 '"'),
    84  // and colon (U+003A ':').  Each value is quoted using U+0022 '"'
    85  // characters and Go string literal syntax.
    86  type StructTag = reflect.StructTag
    87  
    88  // ChanDir represents a channel type's direction.
    89  type ChanDir = reflect.ChanDir
    90  
    91  const (
    92  	RecvDir ChanDir             = 1 << iota // <-chan
    93  	SendDir                                 // chan<-
    94  	BothDir = RecvDir | SendDir             // chan
    95  )
    96  
    97  // A MapIter is an iterator for ranging over a map.
    98  // See Value.MapRange.
    99  type MapIter = reflect.MapIter
   100  
   101  // A ValueError occurs when a Value method is invoked on
   102  // a Value that does not support it. Such cases are documented
   103  // in the description of each method.
   104  type ValueError = reflect.ValueError
   105  
   106  // SliceHeader is the runtime representation of a slice.
   107  // It cannot be used safely or portably and its representation may
   108  // change in a later release.
   109  // Moreover, the Data field is not sufficient to guarantee the data
   110  // it references will not be garbage collected, so programs must keep
   111  // a separate, correctly typed pointer to the underlying data.
   112  type SliceHeader = reflect.SliceHeader
   113  
   114  // StringHeader is the runtime representation of a string.
   115  // It cannot be used safely or portably and its representation may
   116  // change in a later release.
   117  // Moreover, the Data field is not sufficient to guarantee the data
   118  // it references will not be garbage collected, so programs must keep
   119  // a separate, correctly typed pointer to the underlying data.
   120  type StringHeader = reflect.StringHeader
   121  
   122  // A SelectCase describes a single case in a select operation.
   123  // The kind of case depends on Dir, the communication direction.
   124  //
   125  // If Dir is SelectDefault, the case represents a default case.
   126  // Chan and Send must be zero Values.
   127  //
   128  // If Dir is SelectSend, the case represents a send operation.
   129  // Normally Chan's underlying value must be a channel, and Send's underlying value must be
   130  // assignable to the channel's element type. As a special case, if Chan is a zero Value,
   131  // then the case is ignored, and the field Send will also be ignored and may be either zero
   132  // or non-zero.
   133  //
   134  // If Dir is SelectRecv, the case represents a receive operation.
   135  // Normally Chan's underlying value must be a channel and Send must be a zero Value.
   136  // If Chan is a zero Value, then the case is ignored, but Send must still be a zero Value.
   137  // When a receive operation is selected, the received Value is returned by Select.
   138  type SelectCase struct {
   139  	Dir  SelectDir // direction of case
   140  	Chan Value     // channel to use (for send or receive)
   141  	Send Value     // value to send (for send)
   142  }
   143  
   144  type SelectDir = reflect.SelectDir
   145  
   146  // Value is the reflection interface to a Go value.
   147  // Not all methods apply to all kinds of values.
   148  // Restrictions, if any, are noted in the documentation for each method.
   149  // Use the Kind method to find out the kind of value before calling kind-specific methods.
   150  // Calling a method inappropriate to the kind of type causes a run time panic.
   151  // The zero Value represents no value.
   152  // Its IsValid method returns false, its Kind method returns Invalid,
   153  // its String method returns "<invalid Value>", and all other methods panic.
   154  // Most functions and methods never return an invalid value.
   155  // If one does, its documentation states the conditions explicitly.
   156  // A Value can be used concurrently by multiple goroutines provided that
   157  // the underlying Go value can be used concurrently for the equivalent direct operations.
   158  // To compare two Values, compare the results of the Interface method.
   159  // Using == on two Values does not compare the underlying values they represent.
   160  type Value struct {
   161  	typ Type
   162  	ptr unsafe.Pointer
   163  	flag
   164  }
   165  
   166  // Method represents a single method.
   167  type Method struct {
   168  	// Name is the method name.
   169  	// PkgPath is the package path that qualifies a lower case (unexported)
   170  	// method name. It is empty for upper case (exported) method names.
   171  	// The combination of PkgPath and Name uniquely identifies a method
   172  	// in a method set.
   173  	// See https://golang.org/ref/spec#Uniqueness_of_identifiers
   174  	Name    string
   175  	PkgPath string
   176  
   177  	Type  Type  // method type
   178  	Func  Value // func with receiver as first argument
   179  	Index int   // index for Type.Method
   180  }
   181  
   182  // A StructField describes a single field in a struct.
   183  type StructField struct {
   184  	// Name is the field name.
   185  	Name string
   186  	// PkgPath is the package path that qualifies a lower case (unexported)
   187  	// field name. It is empty for upper case (exported) field names.
   188  	// See https://golang.org/ref/spec#Uniqueness_of_identifiers
   189  	PkgPath string
   190  
   191  	Type      Type      // field type
   192  	Tag       StructTag // field tag string
   193  	Offset    uintptr   // offset within struct, in bytes
   194  	Index     []int     // index sequence for Type.FieldByIndex
   195  	Anonymous bool      // is an embedded field
   196  }
   197  
   198  // IsExported reports whether the field is exported.
   199  func (f StructField) IsExported() bool {
   200  	return f.PkgPath == ""
   201  }
   202  
   203  // ArrayOf returns the array type with the given count and element type.
   204  // For example, if t represents int, ArrayOf(5, t) represents [5]int.
   205  //
   206  // If the resulting type would be larger than the available address space,
   207  // ArrayOf panics.
   208  func ArrayOf(count int, elem Type) Type {
   209  	return arrayOf(count, elem)
   210  }
   211  
   212  // ChanOf returns the channel type with the given direction and element type.
   213  // For example, if t represents int, ChanOf(RecvDir, t) represents <-chan int.
   214  //
   215  // The gc runtime imposes a limit of 64 kB on channel element types.
   216  // If t's size is equal to or exceeds this limit, ChanOf panics.
   217  func ChanOf(dir ChanDir, t Type) Type {
   218  	return chanOf(dir, t)
   219  }
   220  
   221  // FuncOf returns the function type with the given argument and result types.
   222  // For example if k represents int and e represents string,
   223  // FuncOf([]Type{k}, []Type{e}, false) represents func(int) string.
   224  //
   225  // The variadic argument controls whether the function is variadic. FuncOf
   226  // panics if the in[len(in)-1] does not represent a slice and variadic is
   227  // true.
   228  func FuncOf(in, out []Type, variadic bool) Type {
   229  	return funcOf(in, out, variadic)
   230  }
   231  
   232  // MapOf returns the map type with the given key and element types.
   233  // For example, if k represents int and e represents string,
   234  // MapOf(k, e) represents map[int]string.
   235  //
   236  // If the key type is not a valid map key type (that is, if it does
   237  // not implement Go's == operator), MapOf panics.
   238  func MapOf(key, elem Type) Type {
   239  	return mapOf(key, elem)
   240  }
   241  
   242  // PtrTo returns the pointer type with element t.
   243  // For example, if t represents type Foo, PtrTo(t) represents *Foo.
   244  func PtrTo(t Type) Type {
   245  	return ptrTo(t)
   246  }
   247  
   248  // SliceOf returns the slice type with element type t.
   249  // For example, if t represents int, SliceOf(t) represents []int.
   250  func SliceOf(t Type) Type {
   251  	return sliceOf(t)
   252  }
   253  
   254  // StructOf returns the struct type containing fields.
   255  // The Offset and Index fields are ignored and computed as they would be
   256  // by the compiler.
   257  //
   258  // StructOf currently does not generate wrapper methods for embedded
   259  // fields and panics if passed unexported StructFields.
   260  // These limitations may be lifted in a future version.
   261  func StructOf(fields []StructField) Type {
   262  	return structOf(fields)
   263  }
   264  
   265  // TypeOf returns the reflection Type that represents the dynamic type of i.
   266  // If i is a nil interface value, TypeOf returns nil.
   267  func TypeOf(v interface{}) Type {
   268  	value := (*Value)(unsafe.Pointer(&v))
   269  	return value.typ
   270  }
   271  
   272  // TypeID returns unique type identifier of v.
   273  func TypeID(v interface{}) uintptr {
   274  	return uintptr(unsafe.Pointer(TypeOf(v)))
   275  }
   276  
   277  func valueOf(v interface{}) Value {
   278  	if v == nil {
   279  		return Value{}
   280  	}
   281  	valueLayout := (*Value)(unsafe.Pointer(&v))
   282  	value := Value{}
   283  	value.typ = valueLayout.typ
   284  	value.ptr = valueLayout.ptr
   285  	f := flag(value.typ.Kind())
   286  	if ifaceIndir(value.typ) {
   287  		f |= flagIndir
   288  	}
   289  	value.flag = f
   290  	return value
   291  }
   292  
   293  // TypeAndPtrOf returns raw Type and ptr value in favor of performance.
   294  func TypeAndPtrOf(v interface{}) (Type, unsafe.Pointer) {
   295  	value := (*Value)(unsafe.Pointer(&v))
   296  	return value.typ, value.ptr
   297  }
   298  
   299  // ValueOf returns a new Value initialized to the concrete value
   300  // stored in the interface i. ValueOf(nil) returns the zero Value.
   301  func ValueOf(v interface{}) Value {
   302  	escape(v)
   303  	return valueOf(v)
   304  }
   305  
   306  // ValueNoEscapeOf no escape of ValueOf.
   307  func ValueNoEscapeOf(v interface{}) Value {
   308  	return valueOf(v)
   309  }
   310  
   311  // ToReflectType convert Type to reflect.Type
   312  func ToReflectType(t Type) reflect.Type {
   313  	return toRT(t)
   314  }
   315  
   316  // ToReflectValue convert Value to reflect.Value
   317  func ToReflectValue(v Value) reflect.Value {
   318  	return toRV(v)
   319  }
   320  
   321  // ToType convert reflect.Type to Type
   322  func ToType(t reflect.Type) Type {
   323  	return toT(t)
   324  }
   325  
   326  // ToValue convert reflect.Value to Value
   327  func ToValue(v reflect.Value) Value {
   328  	return toV(v)
   329  }
   330  
   331  // Copy copies the contents of src into dst until either
   332  // dst has been filled or src has been exhausted.
   333  // It returns the number of elements copied.
   334  // Dst and src each must have kind Slice or Array, and
   335  // dst and src must have the same element type.
   336  //
   337  // As a special case, src can have kind String if the element type of dst is kind Uint8.
   338  func Copy(dst, src Value) int {
   339  	return value_Copy(dst, src)
   340  }
   341  
   342  // DeepEqual reports whether x and y are “deeply equal,” defined as follows.
   343  // Two values of identical type are deeply equal if one of the following cases applies.
   344  // Values of distinct types are never deeply equal.
   345  //
   346  // Array values are deeply equal when their corresponding elements are deeply equal.
   347  //
   348  // Struct values are deeply equal if their corresponding fields,
   349  // both exported and unexported, are deeply equal.
   350  //
   351  // Func values are deeply equal if both are nil; otherwise they are not deeply equal.
   352  //
   353  // Interface values are deeply equal if they hold deeply equal concrete values.
   354  //
   355  // Map values are deeply equal when all of the following are true:
   356  // they are both nil or both non-nil, they have the same length,
   357  // and either they are the same map object or their corresponding keys
   358  // (matched using Go equality) map to deeply equal values.
   359  //
   360  // Pointer values are deeply equal if they are equal using Go's == operator
   361  // or if they point to deeply equal values.
   362  //
   363  // Slice values are deeply equal when all of the following are true:
   364  // they are both nil or both non-nil, they have the same length,
   365  // and either they point to the same initial entry of the same underlying array
   366  // (that is, &x[0] == &y[0]) or their corresponding elements (up to length) are deeply equal.
   367  // Note that a non-nil empty slice and a nil slice (for example, []byte{} and []byte(nil))
   368  // are not deeply equal.
   369  //
   370  // Other values - numbers, bools, strings, and channels - are deeply equal
   371  // if they are equal using Go's == operator.
   372  //
   373  // In general DeepEqual is a recursive relaxation of Go's == operator.
   374  // However, this idea is impossible to implement without some inconsistency.
   375  // Specifically, it is possible for a value to be unequal to itself,
   376  // either because it is of func type (uncomparable in general)
   377  // or because it is a floating-point NaN value (not equal to itself in floating-point comparison),
   378  // or because it is an array, struct, or interface containing
   379  // such a value.
   380  // On the other hand, pointer values are always equal to themselves,
   381  // even if they point at or contain such problematic values,
   382  // because they compare equal using Go's == operator, and that
   383  // is a sufficient condition to be deeply equal, regardless of content.
   384  // DeepEqual has been defined so that the same short-cut applies
   385  // to slices and maps: if x and y are the same slice or the same map,
   386  // they are deeply equal regardless of content.
   387  //
   388  // As DeepEqual traverses the data values it may find a cycle. The
   389  // second and subsequent times that DeepEqual compares two pointer
   390  // values that have been compared before, it treats the values as
   391  // equal rather than examining the values to which they point.
   392  // This ensures that DeepEqual terminates.
   393  func DeepEqual(x, y interface{}) bool {
   394  	return reflect.DeepEqual(x, y)
   395  }
   396  
   397  func Swapper(slice interface{}) func(i, j int) {
   398  	return reflect.Swapper(slice)
   399  }
   400  
   401  // Append appends the values x to a slice s and returns the resulting slice.
   402  // As in Go, each x's value must be assignable to the slice's element type.
   403  func Append(s Value, x ...Value) Value {
   404  	return value_Append(s, x...)
   405  }
   406  
   407  // AppendSlice appends a slice t to a slice s and returns the resulting slice.
   408  // The slices s and t must have the same element type.
   409  func AppendSlice(s, t Value) Value {
   410  	return value_AppendSlice(s, t)
   411  }
   412  
   413  // Indirect returns the value that v points to.
   414  // If v is a nil pointer, Indirect returns a zero Value.
   415  // If v is not a pointer, Indirect returns v.
   416  func Indirect(v Value) Value {
   417  	return value_Indirect(v)
   418  }
   419  
   420  // MakeChan creates a new channel with the specified type and buffer size.
   421  func MakeChan(typ Type, buffer int) Value {
   422  	return value_MakeChan(typ, buffer)
   423  }
   424  
   425  // MakeFunc returns a new function of the given Type
   426  // that wraps the function fn. When called, that new function
   427  // does the following:
   428  //
   429  //   - converts its arguments to a slice of Values.
   430  //   - runs results := fn(args).
   431  //   - returns the results as a slice of Values, one per formal result.
   432  //
   433  // The implementation fn can assume that the argument Value slice
   434  // has the number and type of arguments given by typ.
   435  // If typ describes a variadic function, the final Value is itself
   436  // a slice representing the variadic arguments, as in the
   437  // body of a variadic function. The result Value slice returned by fn
   438  // must have the number and type of results given by typ.
   439  //
   440  // The Value.Call method allows the caller to invoke a typed function
   441  // in terms of Values; in contrast, MakeFunc allows the caller to implement
   442  // a typed function in terms of Values.
   443  //
   444  // The Examples section of the documentation includes an illustration
   445  // of how to use MakeFunc to build a swap function for different types.
   446  func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value {
   447  	return value_MakeFunc(typ, fn)
   448  }
   449  
   450  // MakeMap creates a new map with the specified type.
   451  func MakeMap(typ Type) Value {
   452  	return value_MakeMap(typ)
   453  }
   454  
   455  // MakeMapWithSize creates a new map with the specified type
   456  // and initial space for approximately n elements.
   457  func MakeMapWithSize(typ Type, n int) Value {
   458  	return value_MakeMapWithSize(typ, n)
   459  }
   460  
   461  // MakeSlice creates a new zero-initialized slice value
   462  // for the specified slice type, length, and capacity.
   463  func MakeSlice(typ Type, len, cap int) Value {
   464  	return value_MakeSlice(typ, len, cap)
   465  }
   466  
   467  // New returns a Value representing a pointer to a new zero value
   468  // for the specified type. That is, the returned Value's Type is PtrTo(typ).
   469  func New(typ Type) Value {
   470  	return value_New(typ)
   471  }
   472  
   473  // NewAt returns a Value representing a pointer to a value of the
   474  // specified type, using p as that pointer.
   475  func NewAt(typ Type, p unsafe.Pointer) Value {
   476  	return value_NewAt(typ, p)
   477  }
   478  
   479  // Select executes a select operation described by the list of cases.
   480  // Like the Go select statement, it blocks until at least one of the cases
   481  // can proceed, makes a uniform pseudo-random choice,
   482  // and then executes that case. It returns the index of the chosen case
   483  // and, if that case was a receive operation, the value received and a
   484  // boolean indicating whether the value corresponds to a send on the channel
   485  // (as opposed to a zero value received because the channel is closed).
   486  func Select(cases []SelectCase) (int, Value, bool) {
   487  	return value_Select(cases)
   488  }
   489  
   490  // Zero returns a Value representing the zero value for the specified type.
   491  // The result is different from the zero value of the Value struct,
   492  // which represents no value at all.
   493  // For example, Zero(TypeOf(42)) returns a Value with Kind Int and value 0.
   494  // The returned value is neither addressable nor settable.
   495  func Zero(typ Type) Value {
   496  	return value_Zero(typ)
   497  }
   498  
   499  // Align returns the alignment in bytes of a value of
   500  // this type when allocated in memory.
   501  func (t *rtype) Align() int {
   502  	return type_Align(t)
   503  }
   504  
   505  // FieldAlign returns the alignment in bytes of a value of
   506  // this type when used as a field in a struct.
   507  func (t *rtype) FieldAlign() int {
   508  	return type_FieldAlign(t)
   509  }
   510  
   511  // Method returns the i'th method in the type's method set.
   512  // It panics if i is not in the range [0, NumMethod()).
   513  //
   514  // For a non-interface type T or *T, the returned Method's Type and Func
   515  // fields describe a function whose first argument is the receiver.
   516  //
   517  // For an interface type, the returned Method's Type field gives the
   518  // method signature, without a receiver, and the Func field is nil.
   519  //
   520  // Only exported methods are accessible and they are sorted in
   521  // lexicographic order.
   522  func (t *rtype) Method(a0 int) Method {
   523  	return toM(type_Method(t, a0))
   524  }
   525  
   526  // MethodByName returns the method with that name in the type's
   527  // method set and a boolean indicating if the method was found.
   528  //
   529  // For a non-interface type T or *T, the returned Method's Type and Func
   530  // fields describe a function whose first argument is the receiver.
   531  //
   532  // For an interface type, the returned Method's Type field gives the
   533  // method signature, without a receiver, and the Func field is nil.
   534  func (t *rtype) MethodByName(a0 string) (Method, bool) {
   535  	mtd, ok := type_MethodByName(t, a0)
   536  	return toM(mtd), ok
   537  }
   538  
   539  // NumMethod returns the number of exported methods in the type's method set.
   540  func (t *rtype) NumMethod() int {
   541  	return type_NumMethod(t)
   542  }
   543  
   544  // Name returns the type's name within its package for a defined type.
   545  // For other (non-defined) types it returns the empty string.
   546  func (t *rtype) Name() string {
   547  	return type_Name(t)
   548  }
   549  
   550  // PkgPath returns a defined type's package path, that is, the import path
   551  // that uniquely identifies the package, such as "encoding/base64".
   552  // If the type was predeclared (string, error) or not defined (*T, struct{},
   553  // []int, or A where A is an alias for a non-defined type), the package path
   554  // will be the empty string.
   555  func (t *rtype) PkgPath() string {
   556  	return type_PkgPath(t)
   557  }
   558  
   559  // Size returns the number of bytes needed to store
   560  // a value of the given type; it is analogous to unsafe.Sizeof.
   561  func (t *rtype) Size() uintptr {
   562  	return type_Size(t)
   563  }
   564  
   565  // String returns a string representation of the type.
   566  // The string representation may use shortened package names
   567  // (e.g., base64 instead of "encoding/base64") and is not
   568  // guaranteed to be unique among types. To test for type identity,
   569  // compare the Types directly.
   570  func (t *rtype) String() string {
   571  	return type_String(t)
   572  }
   573  
   574  // Kind returns the specific kind of this type.
   575  func (t *rtype) Kind() Kind {
   576  	return type_Kind(t)
   577  }
   578  
   579  // Implements reports whether the type implements the interface type u.
   580  func (t *rtype) Implements(u Type) bool {
   581  	return type_Implements(t, toRT(u))
   582  }
   583  
   584  // AssignableTo reports whether a value of the type is assignable to type u.
   585  func (t *rtype) AssignableTo(u Type) bool {
   586  	return type_AssignableTo(t, toRT(u))
   587  }
   588  
   589  // ConvertibleTo reports whether a value of the type is convertible to type u.
   590  func (t *rtype) ConvertibleTo(u Type) bool {
   591  	return type_ConvertibleTo(t, toRT(u))
   592  }
   593  
   594  // Comparable reports whether values of this type are comparable.
   595  func (t *rtype) Comparable() bool {
   596  	return type_Comparable(t)
   597  }
   598  
   599  // Methods applicable only to some types, depending on Kind.
   600  // The methods allowed for each kind are:
   601  //
   602  //	Int*, Uint*, Float*, Complex*: Bits
   603  //	Array: Elem, Len
   604  //	Chan: ChanDir, Elem
   605  //	Func: In, NumIn, Out, NumOut, IsVariadic.
   606  //	Map: Key, Elem
   607  //	Ptr: Elem
   608  //	Slice: Elem
   609  //	Struct: Field, FieldByIndex, FieldByName, FieldByNameFunc, NumField
   610  
   611  // Bits returns the size of the type in bits.
   612  // It panics if the type's Kind is not one of the
   613  // sized or unsized Int, Uint, Float, or Complex kinds.
   614  func (t *rtype) Bits() int {
   615  	return type_Bits(t)
   616  }
   617  
   618  // ChanDir returns a channel type's direction.
   619  // It panics if the type's Kind is not Chan.
   620  func (t *rtype) ChanDir() ChanDir {
   621  	return type_ChanDir(t)
   622  }
   623  
   624  // IsVariadic reports whether a function type's final input parameter
   625  // is a "..." parameter. If so, t.In(t.NumIn() - 1) returns the parameter's
   626  // implicit actual type []T.
   627  //
   628  // For concreteness, if t represents func(x int, y ... float64), then
   629  //
   630  //	t.NumIn() == 2
   631  //	t.In(0) is the reflect.Type for "int"
   632  //	t.In(1) is the reflect.Type for "[]float64"
   633  //	t.IsVariadic() == true
   634  //
   635  // IsVariadic panics if the type's Kind is not Func.
   636  func (t *rtype) IsVariadic() bool {
   637  	return type_IsVariadic(t)
   638  }
   639  
   640  // Elem returns a type's element type.
   641  // It panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice.
   642  func (t *rtype) Elem() Type {
   643  	return ToType(type_Elem(t))
   644  }
   645  
   646  // Field returns a struct type's i'th field.
   647  // It panics if the type's Kind is not Struct.
   648  // It panics if i is not in the range [0, NumField()).
   649  func (t *rtype) Field(i int) StructField {
   650  	return toSF(type_Field(t, i))
   651  }
   652  
   653  // FieldByIndex returns the nested field corresponding
   654  // to the index sequence. It is equivalent to calling Field
   655  // successively for each index i.
   656  // It panics if the type's Kind is not Struct.
   657  func (t *rtype) FieldByIndex(index []int) StructField {
   658  	return toSF(type_FieldByIndex(t, index))
   659  }
   660  
   661  // FieldByName returns the struct field with the given name
   662  // and a boolean indicating if the field was found.
   663  func (t *rtype) FieldByName(name string) (StructField, bool) {
   664  	field, ok := type_FieldByName(t, name)
   665  	return toSF(field), ok
   666  }
   667  
   668  // FieldByNameFunc returns the struct field with a name
   669  // that satisfies the match function and a boolean indicating if
   670  // the field was found.
   671  //
   672  // FieldByNameFunc considers the fields in the struct itself
   673  // and then the fields in any embedded structs, in breadth first order,
   674  // stopping at the shallowest nesting depth containing one or more
   675  // fields satisfying the match function. If multiple fields at that depth
   676  // satisfy the match function, they cancel each other
   677  // and FieldByNameFunc returns no match.
   678  // This behavior mirrors Go's handling of name lookup in
   679  // structs containing embedded fields.
   680  func (t *rtype) FieldByNameFunc(match func(string) bool) (StructField, bool) {
   681  	field, ok := type_FieldByNameFunc(t, match)
   682  	return toSF(field), ok
   683  }
   684  
   685  // In returns the type of a function type's i'th input parameter.
   686  // It panics if the type's Kind is not Func.
   687  // It panics if i is not in the range [0, NumIn()).
   688  func (t *rtype) In(i int) Type {
   689  	return ToType(type_In(t, i))
   690  }
   691  
   692  // Key returns a map type's key type.
   693  // It panics if the type's Kind is not Map.
   694  func (t *rtype) Key() Type {
   695  	return ToType(type_Key(t))
   696  }
   697  
   698  // Len returns an array type's length.
   699  // It panics if the type's Kind is not Array.
   700  func (t *rtype) Len() int {
   701  	return type_Len(t)
   702  }
   703  
   704  // NumField returns a struct type's field count.
   705  // It panics if the type's Kind is not Struct.
   706  func (t *rtype) NumField() int {
   707  	return type_NumField(t)
   708  }
   709  
   710  // NumIn returns a function type's input parameter count.
   711  // It panics if the type's Kind is not Func.
   712  func (t *rtype) NumIn() int {
   713  	return type_NumIn(t)
   714  }
   715  
   716  // NumOut returns a function type's output parameter count.
   717  // It panics if the type's Kind is not Func.
   718  func (t *rtype) NumOut() int {
   719  	return type_NumOut(t)
   720  }
   721  
   722  // Out returns the type of a function type's i'th output parameter.
   723  // It panics if the type's Kind is not Func.
   724  // It panics if i is not in the range [0, NumOut()).
   725  func (t *rtype) Out(i int) Type {
   726  	return toT(type_Out(t, i))
   727  }
   728  
   729  // Addr returns a pointer value representing the address of v.
   730  // It panics if CanAddr() returns false.
   731  // Addr is typically used to obtain a pointer to a struct field
   732  // or slice element in order to call a method that requires a
   733  // pointer receiver.
   734  func (v Value) Addr() Value {
   735  	return value_Addr(v)
   736  }
   737  
   738  // Bool returns v's underlying value.
   739  // It panics if v's kind is not Bool.
   740  func (v Value) Bool() bool {
   741  	return value_Bool(v)
   742  }
   743  
   744  // Bytes returns v's underlying value.
   745  // It panics if v's underlying value is not a slice of bytes.
   746  func (v Value) Bytes() []byte {
   747  	return value_Bytes(v)
   748  }
   749  
   750  // Call calls the function v with the input arguments in.
   751  // For example, if len(in) == 3, v.Call(in) represents the Go call v(in[0], in[1], in[2]).
   752  // Call panics if v's Kind is not Func.
   753  // It returns the output results as Values.
   754  // As in Go, each input argument must be assignable to the
   755  // type of the function's corresponding input parameter.
   756  // If v is a variadic function, Call creates the variadic slice parameter
   757  // itself, copying in the corresponding values.
   758  func (v Value) Call(in []Value) []Value {
   759  	return value_Call(v, in)
   760  }
   761  
   762  // CallSlice calls the variadic function v with the input arguments in,
   763  // assigning the slice in[len(in)-1] to v's final variadic argument.
   764  // For example, if len(in) == 3, v.CallSlice(in) represents the Go call v(in[0], in[1], in[2]...).
   765  // CallSlice panics if v's Kind is not Func or if v is not variadic.
   766  // It returns the output results as Values.
   767  // As in Go, each input argument must be assignable to the
   768  // type of the function's corresponding input parameter.
   769  func (v Value) CallSlice(in []Value) []Value {
   770  	return value_CallSlice(v, in)
   771  }
   772  
   773  // CanAddr reports whether the value's address can be obtained with Addr.
   774  // Such values are called addressable. A value is addressable if it is
   775  // an element of a slice, an element of an addressable array,
   776  // a field of an addressable struct, or the result of dereferencing a pointer.
   777  // If CanAddr returns false, calling Addr will panic.
   778  func (v Value) CanAddr() bool {
   779  	return value_CanAddr(v)
   780  }
   781  
   782  // CanInterface reports whether Interface can be used without panicking.
   783  func (v Value) CanInterface() bool {
   784  	return value_CanInterface(v)
   785  }
   786  
   787  // CanSet reports whether the value of v can be changed.
   788  // A Value can be changed only if it is addressable and was not
   789  // obtained by the use of unexported struct fields.
   790  // If CanSet returns false, calling Set or any type-specific
   791  // setter (e.g., SetBool, SetInt) will panic.
   792  func (v Value) CanSet() bool {
   793  	return value_CanSet(v)
   794  }
   795  
   796  // Cap returns v's capacity.
   797  // It panics if v's Kind is not Array, Chan, or Slice.
   798  func (v Value) Cap() int {
   799  	return value_Cap(v)
   800  }
   801  
   802  // Close closes the channel v.
   803  // It panics if v's Kind is not Chan.
   804  func (v Value) Close() {
   805  	value_Close(v)
   806  }
   807  
   808  // Complex returns v's underlying value, as a complex128.
   809  // It panics if v's Kind is not Complex64 or Complex128.
   810  func (v Value) Complex() complex128 {
   811  	return value_Complex(v)
   812  }
   813  
   814  // Convert returns the value v converted to type t.
   815  // If the usual Go conversion rules do not allow conversion
   816  // of the value v to type t, Convert panics.
   817  func (v Value) Convert(t Type) Value {
   818  	return value_Convert(v, t)
   819  }
   820  
   821  // Elem returns the value that the interface v contains
   822  // or that the pointer v points to.
   823  // It panics if v's Kind is not Interface or Ptr.
   824  // It returns the zero Value if v is nil.
   825  func (v Value) Elem() Value {
   826  	return value_Elem(v)
   827  }
   828  
   829  // Field returns the i'th field of the struct v.
   830  // It panics if v's Kind is not Struct or i is out of range.
   831  func (v Value) Field(i int) Value {
   832  	return value_Field(v, i)
   833  }
   834  
   835  // FieldByIndex returns the nested field corresponding to index.
   836  // It panics if v's Kind is not struct.
   837  func (v Value) FieldByIndex(index []int) Value {
   838  	return value_FieldByIndex(v, index)
   839  }
   840  
   841  // FieldByName returns the struct field with the given name.
   842  // It returns the zero Value if no field was found.
   843  // It panics if v's Kind is not struct.
   844  func (v Value) FieldByName(name string) Value {
   845  	return value_FieldByName(v, name)
   846  }
   847  
   848  // FieldByNameFunc returns the struct field with a name
   849  // that satisfies the match function.
   850  // It panics if v's Kind is not struct.
   851  // It returns the zero Value if no field was found.
   852  func (v Value) FieldByNameFunc(match func(string) bool) Value {
   853  	return value_FieldByNameFunc(v, match)
   854  }
   855  
   856  // Float returns v's underlying value, as a float64.
   857  // It panics if v's Kind is not Float32 or Float64.
   858  func (v Value) Float() float64 {
   859  	return value_Float(v)
   860  }
   861  
   862  // Index returns v's i'th element.
   863  // It panics if v's Kind is not Array, Slice, or String or i is out of range.
   864  func (v Value) Index(i int) Value {
   865  	return value_Index(v, i)
   866  }
   867  
   868  // Int returns v's underlying value, as an int64.
   869  // It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64.
   870  func (v Value) Int() int64 {
   871  	return value_Int(v)
   872  }
   873  
   874  // Interface returns v's current value as an interface{}.
   875  // It is equivalent to:
   876  //
   877  //	var i interface{} = (v's underlying value)
   878  //
   879  // It panics if the Value was obtained by accessing
   880  // unexported struct fields.
   881  func (v Value) Interface() interface{} {
   882  	return value_Interface(v)
   883  }
   884  
   885  // InterfaceData returns the interface v's value as a uintptr pair.
   886  // It panics if v's Kind is not Interface.
   887  func (v Value) InterfaceData() [2]uintptr {
   888  	return value_InterfaceData(v)
   889  }
   890  
   891  // IsNil reports whether its argument v is nil. The argument must be
   892  // a chan, func, interface, map, pointer, or slice value; if it is
   893  // not, IsNil panics. Note that IsNil is not always equivalent to a
   894  // regular comparison with nil in Go. For example, if v was created
   895  // by calling ValueOf with an uninitialized interface variable i,
   896  // i==nil will be true but v.IsNil will panic as v will be the zero
   897  // Value.
   898  func (v Value) IsNil() bool {
   899  	return value_IsNil(v)
   900  }
   901  
   902  // IsValid reports whether v represents a value.
   903  // It returns false if v is the zero Value.
   904  // If IsValid returns false, all other methods except String panic.
   905  // Most functions and methods never return an invalid Value.
   906  // If one does, its documentation states the conditions explicitly.
   907  func (v Value) IsValid() bool {
   908  	return value_IsValid(v)
   909  }
   910  
   911  // Kind returns v's Kind.
   912  // If v is the zero Value (IsValid returns false), Kind returns Invalid.
   913  func (v Value) Kind() Kind {
   914  	return value_Kind(v)
   915  }
   916  
   917  // Len returns v's length.
   918  // It panics if v's Kind is not Array, Chan, Map, Slice, or String.
   919  func (v Value) Len() int {
   920  	return value_Len(v)
   921  }
   922  
   923  // MapIndex returns the value associated with key in the map v.
   924  // It panics if v's Kind is not Map.
   925  // It returns the zero Value if key is not found in the map or if v represents a nil map.
   926  // As in Go, the key's value must be assignable to the map's key type.
   927  func (v Value) MapIndex(key Value) Value {
   928  	return value_MapIndex(v, key)
   929  }
   930  
   931  // MapKeys returns a slice containing all the keys present in the map,
   932  // in unspecified order.
   933  // It panics if v's Kind is not Map.
   934  // It returns an empty slice if v represents a nil map.
   935  func (v Value) MapKeys() []Value {
   936  	return value_MapKeys(v)
   937  }
   938  
   939  // MapRange returns a range iterator for a map.
   940  // It panics if v's Kind is not Map.
   941  //
   942  // Call Next to advance the iterator, and Key/Value to access each entry.
   943  // Next returns false when the iterator is exhausted.
   944  // MapRange follows the same iteration semantics as a range statement.
   945  //
   946  // Example:
   947  //
   948  //	iter := reflect.ValueOf(m).MapRange()
   949  //	for iter.Next() {
   950  //		k := iter.Key()
   951  //		v := iter.Value()
   952  //		...
   953  //	}
   954  func (v Value) MapRange() *MapIter {
   955  	return value_MapRange(v)
   956  }
   957  
   958  // Method returns a function value corresponding to v's i'th method.
   959  // The arguments to a Call on the returned function should not include
   960  // a receiver; the returned function will always use v as the receiver.
   961  // Method panics if i is out of range or if v is a nil interface value.
   962  func (v Value) Method(i int) Value {
   963  	return value_Method(v, i)
   964  }
   965  
   966  // MethodByName returns a function value corresponding to the method
   967  // of v with the given name.
   968  // The arguments to a Call on the returned function should not include
   969  // a receiver; the returned function will always use v as the receiver.
   970  // It returns the zero Value if no method was found.
   971  func (v Value) MethodByName(name string) Value {
   972  	return value_MethodByName(v, name)
   973  }
   974  
   975  // NumField returns the number of fields in the struct v.
   976  // It panics if v's Kind is not Struct.
   977  func (v Value) NumField() int {
   978  	return value_NumField(v)
   979  }
   980  
   981  // NumMethod returns the number of exported methods in the value's method set.
   982  func (v Value) NumMethod() int {
   983  	return value_NumMethod(v)
   984  }
   985  
   986  // OverflowComplex reports whether the complex128 x cannot be represented by v's type.
   987  // It panics if v's Kind is not Complex64 or Complex128.
   988  func (v Value) OverflowComplex(x complex128) bool {
   989  	return value_OverflowComplex(v, x)
   990  }
   991  
   992  // OverflowFloat reports whether the float64 x cannot be represented by v's type.
   993  // It panics if v's Kind is not Float32 or Float64.
   994  func (v Value) OverflowFloat(x float64) bool {
   995  	return value_OverflowFloat(v, x)
   996  }
   997  
   998  // OverflowInt reports whether the int64 x cannot be represented by v's type.
   999  // It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64.
  1000  func (v Value) OverflowInt(x int64) bool {
  1001  	return value_OverflowInt(v, x)
  1002  }
  1003  
  1004  // OverflowUint reports whether the uint64 x cannot be represented by v's type.
  1005  // It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
  1006  func (v Value) OverflowUint(x uint64) bool {
  1007  	return value_OverflowUint(v, x)
  1008  }
  1009  
  1010  //go:nocheckptr
  1011  // This prevents inlining Value.Pointer when -d=checkptr is enabled,
  1012  // which ensures cmd/compile can recognize unsafe.Pointer(v.Pointer())
  1013  // and make an exception.
  1014  
  1015  // Pointer returns v's value as a uintptr.
  1016  // It returns uintptr instead of unsafe.Pointer so that
  1017  // code using reflect cannot obtain unsafe.Pointers
  1018  // without importing the unsafe package explicitly.
  1019  // It panics if v's Kind is not Chan, Func, Map, Ptr, Slice, or UnsafePointer.
  1020  //
  1021  // If v's Kind is Func, the returned pointer is an underlying
  1022  // code pointer, but not necessarily enough to identify a
  1023  // single function uniquely. The only guarantee is that the
  1024  // result is zero if and only if v is a nil func Value.
  1025  //
  1026  // If v's Kind is Slice, the returned pointer is to the first
  1027  // element of the slice. If the slice is nil the returned value
  1028  // is 0.  If the slice is empty but non-nil the return value is non-zero.
  1029  func (v Value) Pointer() uintptr {
  1030  	return value_Pointer(v)
  1031  }
  1032  
  1033  // Recv receives and returns a value from the channel v.
  1034  // It panics if v's Kind is not Chan.
  1035  // The receive blocks until a value is ready.
  1036  // The boolean value ok is true if the value x corresponds to a send
  1037  // on the channel, false if it is a zero value received because the channel is closed.
  1038  func (v Value) Recv() (Value, bool) {
  1039  	return value_Recv(v)
  1040  }
  1041  
  1042  // Send sends x on the channel v.
  1043  // It panics if v's kind is not Chan or if x's type is not the same type as v's element type.
  1044  // As in Go, x's value must be assignable to the channel's element type.
  1045  func (v Value) Send(x Value) {
  1046  	value_Send(v, x)
  1047  }
  1048  
  1049  // Set assigns x to the value v.
  1050  // It panics if CanSet returns false.
  1051  // As in Go, x's value must be assignable to v's type.
  1052  func (v Value) Set(x Value) {
  1053  	value_Set(v, x)
  1054  }
  1055  
  1056  // SetBool sets v's underlying value.
  1057  // It panics if v's Kind is not Bool or if CanSet() is false.
  1058  func (v Value) SetBool(x bool) {
  1059  	value_SetBool(v, x)
  1060  }
  1061  
  1062  // SetBytes sets v's underlying value.
  1063  // It panics if v's underlying value is not a slice of bytes.
  1064  func (v Value) SetBytes(x []byte) {
  1065  	value_SetBytes(v, x)
  1066  }
  1067  
  1068  // SetCap sets v's capacity to n.
  1069  // It panics if v's Kind is not Slice or if n is smaller than the length or
  1070  // greater than the capacity of the slice.
  1071  func (v Value) SetCap(n int) {
  1072  	value_SetCap(v, n)
  1073  }
  1074  
  1075  // SetComplex sets v's underlying value to x.
  1076  // It panics if v's Kind is not Complex64 or Complex128, or if CanSet() is false.
  1077  func (v Value) SetComplex(x complex128) {
  1078  	value_SetComplex(v, x)
  1079  }
  1080  
  1081  // SetFloat sets v's underlying value to x.
  1082  // It panics if v's Kind is not Float32 or Float64, or if CanSet() is false.
  1083  func (v Value) SetFloat(x float64) {
  1084  	value_SetFloat(v, x)
  1085  }
  1086  
  1087  // SetInt sets v's underlying value to x.
  1088  // It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64, or if CanSet() is false.
  1089  func (v Value) SetInt(x int64) {
  1090  	value_SetInt(v, x)
  1091  }
  1092  
  1093  // SetLen sets v's length to n.
  1094  // It panics if v's Kind is not Slice or if n is negative or
  1095  // greater than the capacity of the slice.
  1096  func (v Value) SetLen(n int) {
  1097  	value_SetLen(v, n)
  1098  }
  1099  
  1100  // SetMapIndex sets the element associated with key in the map v to elem.
  1101  // It panics if v's Kind is not Map.
  1102  // If elem is the zero Value, SetMapIndex deletes the key from the map.
  1103  // Otherwise if v holds a nil map, SetMapIndex will panic.
  1104  // As in Go, key's elem must be assignable to the map's key type,
  1105  // and elem's value must be assignable to the map's elem type.
  1106  func (v Value) SetMapIndex(key, elem Value) {
  1107  	value_SetMapIndex(v, key, elem)
  1108  }
  1109  
  1110  // SetPointer sets the unsafe.Pointer value v to x.
  1111  // It panics if v's Kind is not UnsafePointer.
  1112  func (v Value) SetPointer(x unsafe.Pointer) {
  1113  	value_SetPointer(v, x)
  1114  }
  1115  
  1116  // SetString sets v's underlying value to x.
  1117  // It panics if v's Kind is not String or if CanSet() is false.
  1118  func (v Value) SetString(x string) {
  1119  	value_SetString(v, x)
  1120  }
  1121  
  1122  // SetUint sets v's underlying value to x.
  1123  // It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64, or if CanSet() is false.
  1124  func (v Value) SetUint(x uint64) {
  1125  	value_SetUint(v, x)
  1126  }
  1127  
  1128  // Slice returns v[i:j].
  1129  // It panics if v's Kind is not Array, Slice or String, or if v is an unaddressable array,
  1130  // or if the indexes are out of bounds.
  1131  func (v Value) Slice(i, j int) Value {
  1132  	return value_Slice(v, i, j)
  1133  }
  1134  
  1135  // Slice3 is the 3-index form of the slice operation: it returns v[i:j:k].
  1136  // It panics if v's Kind is not Array or Slice, or if v is an unaddressable array,
  1137  // or if the indexes are out of bounds.
  1138  func (v Value) Slice3(i, j, k int) Value {
  1139  	return value_Slice3(v, i, j, k)
  1140  }
  1141  
  1142  // String returns the string v's underlying value, as a string.
  1143  // String is a special case because of Go's String method convention.
  1144  // Unlike the other getters, it does not panic if v's Kind is not String.
  1145  // Instead, it returns a string of the form "<T value>" where T is v's type.
  1146  // The fmt package treats Values specially. It does not call their String
  1147  // method implicitly but instead prints the concrete values they hold.
  1148  func (v Value) String() string {
  1149  	return value_String(v)
  1150  }
  1151  
  1152  // TryRecv attempts to receive a value from the channel v but will not block.
  1153  // It panics if v's Kind is not Chan.
  1154  // If the receive delivers a value, x is the transferred value and ok is true.
  1155  // If the receive cannot finish without blocking, x is the zero Value and ok is false.
  1156  // If the channel is closed, x is the zero value for the channel's element type and ok is false.
  1157  func (v Value) TryRecv() (Value, bool) {
  1158  	return value_TryRecv(v)
  1159  }
  1160  
  1161  // TrySend attempts to send x on the channel v but will not block.
  1162  // It panics if v's Kind is not Chan.
  1163  // It reports whether the value was sent.
  1164  // As in Go, x's value must be assignable to the channel's element type.
  1165  func (v Value) TrySend(x Value) bool {
  1166  	return value_TrySend(v, x)
  1167  }
  1168  
  1169  // Type returns v's type.
  1170  func (v Value) Type() Type {
  1171  	return value_Type(v)
  1172  }
  1173  
  1174  // Uint returns v's underlying value, as a uint64.
  1175  // It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
  1176  func (v Value) Uint() uint64 {
  1177  	return value_Uint(v)
  1178  }
  1179  
  1180  //go:nocheckptr
  1181  // This prevents inlining Value.UnsafeAddr when -d=checkptr is enabled,
  1182  // which ensures cmd/compile can recognize unsafe.Pointer(v.UnsafeAddr())
  1183  // and make an exception.
  1184  
  1185  // UnsafeAddr returns a pointer to v's data.
  1186  // It is for advanced clients that also import the "unsafe" package.
  1187  // It panics if v is not addressable.
  1188  func (v Value) UnsafeAddr() uintptr {
  1189  	return value_UnsafeAddr(v)
  1190  }