| |
| |
| |
|
|
| package reflectlite |
|
|
| import ( |
| "unsafe" |
| ) |
|
|
| |
| |
| func Field(v Value, i int) Value { |
| if v.kind() != Struct { |
| panic(&ValueError{"reflect.Value.Field", v.kind()}) |
| } |
| tt := (*structType)(unsafe.Pointer(v.typ())) |
| if uint(i) >= uint(len(tt.Fields)) { |
| panic("reflect: Field index out of range") |
| } |
| field := &tt.Fields[i] |
| typ := field.Typ |
|
|
| |
| fl := v.flag&(flagStickyRO|flagIndir|flagAddr) | flag(typ.Kind()) |
| |
| if !field.Name.IsExported() { |
| if field.Embedded() { |
| fl |= flagEmbedRO |
| } else { |
| fl |= flagStickyRO |
| } |
| } |
| |
| |
| |
| |
| |
| ptr := add(v.ptr, field.Offset, "same as non-reflect &v.field") |
| return Value{typ, ptr, fl} |
| } |
|
|
| func TField(typ Type, i int) Type { |
| t := typ.(rtype) |
| if t.Kind() != Struct { |
| panic("reflect: Field of non-struct type") |
| } |
| tt := (*structType)(unsafe.Pointer(t.Type)) |
|
|
| return StructFieldType(tt, i) |
| } |
|
|
| |
| func StructFieldType(t *structType, i int) Type { |
| if i < 0 || i >= len(t.Fields) { |
| panic("reflect: Field index out of bounds") |
| } |
| p := &t.Fields[i] |
| return toType(p.Typ) |
| } |
|
|
| |
| |
| |
| |
| |
| func Zero(typ Type) Value { |
| if typ == nil { |
| panic("reflect: Zero(nil)") |
| } |
| t := typ.common() |
| fl := flag(t.Kind()) |
| if !t.IsDirectIface() { |
| return Value{t, unsafe_New(t), fl | flagIndir} |
| } |
| return Value{t, nil, fl} |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| func ToInterface(v Value) (i any) { |
| return valueInterface(v) |
| } |
|
|
| type EmbedWithUnexpMeth struct{} |
|
|
| func (EmbedWithUnexpMeth) f() {} |
|
|
| type pinUnexpMeth interface { |
| f() |
| } |
|
|
| var pinUnexpMethI = pinUnexpMeth(EmbedWithUnexpMeth{}) |
|
|
| func FirstMethodNameBytes(t Type) *byte { |
| _ = pinUnexpMethI |
|
|
| ut := t.uncommon() |
| if ut == nil { |
| panic("type has no methods") |
| } |
| m := ut.Methods()[0] |
| mname := t.(rtype).nameOff(m.Name) |
| if *mname.DataChecked(0, "name flag field")&(1<<2) == 0 { |
| panic("method name does not have pkgPath *string") |
| } |
| return mname.Bytes |
| } |
|
|
| type Buffer struct { |
| buf []byte |
| } |
|
|