mirror of
https://github.com/golang/go
synced 2024-11-26 04:07:59 -07:00
refect: rename Ptr Kind to Pointer (but keep Ptr)
reflect.Ptr didn't match reflect.UnsafePointer or unsafe.Pointer so rename it to reflect.Pointer. Keep reflect.Ptr for compatibility. Likewise with PtrTo. Change to use it in std will come in a subsequent CL. Fixes #47651 Change-Id: I5d4abe2b2fe10948bd68bb12c557165bedffbcba Reviewed-on: https://go-review.googlesource.com/c/go/+/341333 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Joe Tsai <joetsai@digital-static.net> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
9f69a44308
commit
17910ed4ff
@ -100,13 +100,15 @@ const (
|
||||
Func
|
||||
Interface
|
||||
Map
|
||||
Ptr
|
||||
Pointer
|
||||
Slice
|
||||
String
|
||||
Struct
|
||||
UnsafePointer
|
||||
)
|
||||
|
||||
const Ptr = Pointer
|
||||
|
||||
// tflag is used by an rtype to signal what extra type information is
|
||||
// available in the memory directly following the rtype value.
|
||||
//
|
||||
|
@ -87,7 +87,7 @@ func (f flag) ro() flag {
|
||||
}
|
||||
|
||||
// pointer returns the underlying pointer represented by v.
|
||||
// v.Kind() must be Ptr, Map, Chan, Func, or UnsafePointer
|
||||
// v.Kind() must be Pointer, Map, Chan, Func, or UnsafePointer
|
||||
func (v Value) pointer() unsafe.Pointer {
|
||||
if v.typ.size != goarch.PtrSize || !v.typ.pointers() {
|
||||
panic("can't call pointer on a non-pointer Value")
|
||||
@ -220,7 +220,7 @@ func (v Value) CanSet() bool {
|
||||
|
||||
// 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 Ptr.
|
||||
// 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 {
|
||||
k := v.kind()
|
||||
@ -239,7 +239,7 @@ func (v Value) Elem() Value {
|
||||
x.flag |= v.flag.ro()
|
||||
}
|
||||
return x
|
||||
case Ptr:
|
||||
case Pointer:
|
||||
ptr := v.ptr
|
||||
if v.flag&flagIndir != 0 {
|
||||
ptr = *(*unsafe.Pointer)(ptr)
|
||||
@ -288,7 +288,7 @@ func valueInterface(v Value) interface{} {
|
||||
func (v Value) IsNil() bool {
|
||||
k := v.kind()
|
||||
switch k {
|
||||
case Chan, Func, Map, Ptr, UnsafePointer:
|
||||
case Chan, Func, Map, Pointer, UnsafePointer:
|
||||
// if v.flag&flagMethod != 0 {
|
||||
// return false
|
||||
// }
|
||||
|
@ -126,7 +126,7 @@ type Type interface {
|
||||
// Chan: ChanDir, Elem
|
||||
// Func: In, NumIn, Out, NumOut, IsVariadic.
|
||||
// Map: Key, Elem
|
||||
// Ptr: Elem
|
||||
// Pointer: Elem
|
||||
// Slice: Elem
|
||||
// Struct: Field, FieldByIndex, FieldByName, FieldByNameFunc, NumField
|
||||
|
||||
@ -154,7 +154,7 @@ type Type interface {
|
||||
IsVariadic() bool
|
||||
|
||||
// Elem returns a type's element type.
|
||||
// It panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice.
|
||||
// It panics if the type's Kind is not Array, Chan, Map, Pointer, or Slice.
|
||||
Elem() Type
|
||||
|
||||
// Field returns a struct type's i'th field.
|
||||
@ -261,13 +261,18 @@ const (
|
||||
Func
|
||||
Interface
|
||||
Map
|
||||
Ptr
|
||||
Pointer
|
||||
Slice
|
||||
String
|
||||
Struct
|
||||
UnsafePointer
|
||||
)
|
||||
|
||||
// Ptr is the old name for the Pointer kind.
|
||||
//
|
||||
// Deprecated: use the new spelling, Pointer.
|
||||
const Ptr = Pointer
|
||||
|
||||
// tflag is used by an rtype to signal what extra type information is
|
||||
// available in the memory directly following the rtype value.
|
||||
//
|
||||
@ -658,7 +663,7 @@ var kindNames = []string{
|
||||
Func: "func",
|
||||
Interface: "interface",
|
||||
Map: "map",
|
||||
Ptr: "ptr",
|
||||
Pointer: "ptr",
|
||||
Slice: "slice",
|
||||
String: "string",
|
||||
Struct: "struct",
|
||||
@ -741,7 +746,7 @@ func (t *rtype) uncommon() *uncommonType {
|
||||
switch t.Kind() {
|
||||
case Struct:
|
||||
return &(*structTypeUncommon)(unsafe.Pointer(t)).u
|
||||
case Ptr:
|
||||
case Pointer:
|
||||
type u struct {
|
||||
ptrType
|
||||
u uncommonType
|
||||
@ -945,7 +950,7 @@ func (t *rtype) Elem() Type {
|
||||
case Map:
|
||||
tt := (*mapType)(unsafe.Pointer(t))
|
||||
return toType(tt.elem)
|
||||
case Ptr:
|
||||
case Pointer:
|
||||
tt := (*ptrType)(unsafe.Pointer(t))
|
||||
return toType(tt.elem)
|
||||
case Slice:
|
||||
@ -1265,7 +1270,7 @@ func (t *structType) FieldByIndex(index []int) (f StructField) {
|
||||
for i, x := range index {
|
||||
if i > 0 {
|
||||
ft := f.Type
|
||||
if ft.Kind() == Ptr && ft.Elem().Kind() == Struct {
|
||||
if ft.Kind() == Pointer && ft.Elem().Kind() == Struct {
|
||||
ft = ft.Elem()
|
||||
}
|
||||
f.Type = ft
|
||||
@ -1336,7 +1341,7 @@ func (t *structType) FieldByNameFunc(match func(string) bool) (result StructFiel
|
||||
if f.embedded() {
|
||||
// Embedded field of type T or *T.
|
||||
ntyp = f.typ
|
||||
if ntyp.Kind() == Ptr {
|
||||
if ntyp.Kind() == Pointer {
|
||||
ntyp = ntyp.Elem().common()
|
||||
}
|
||||
}
|
||||
@ -1416,12 +1421,19 @@ func TypeOf(i interface{}) Type {
|
||||
return toType(eface.typ)
|
||||
}
|
||||
|
||||
// ptrMap is the cache for PtrTo.
|
||||
// ptrMap is the cache for PointerTo.
|
||||
var ptrMap sync.Map // map[*rtype]*ptrType
|
||||
|
||||
// PtrTo returns the pointer type with element t.
|
||||
// For example, if t represents type Foo, PtrTo(t) represents *Foo.
|
||||
func PtrTo(t Type) Type {
|
||||
//
|
||||
// Deprecated: use PointerTo. PtrTo is the old spelling.
|
||||
// The two functions behaves identically.
|
||||
func PtrTo(t Type) Type { return PointerTo(t) }
|
||||
|
||||
// PointerTo returns the pointer type with element t.
|
||||
// For example, if t represents type Foo, PointerTo(t) represents *Foo.
|
||||
func PointerTo(t Type) Type {
|
||||
return t.(*rtype).ptrTo()
|
||||
}
|
||||
|
||||
@ -1695,7 +1707,7 @@ func haveIdenticalUnderlyingType(T, V *rtype, cmpTags bool) bool {
|
||||
case Map:
|
||||
return haveIdenticalType(T.Key(), V.Key(), cmpTags) && haveIdenticalType(T.Elem(), V.Elem(), cmpTags)
|
||||
|
||||
case Ptr, Slice:
|
||||
case Pointer, Slice:
|
||||
return haveIdenticalType(T.Elem(), V.Elem(), cmpTags)
|
||||
|
||||
case Struct:
|
||||
@ -2136,7 +2148,7 @@ func funcStr(ft *funcType) string {
|
||||
// That is, x == x for all values x of type t.
|
||||
func isReflexive(t *rtype) bool {
|
||||
switch t.Kind() {
|
||||
case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Ptr, String, UnsafePointer:
|
||||
case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Pointer, String, UnsafePointer:
|
||||
return true
|
||||
case Float32, Float64, Complex64, Complex128, Interface:
|
||||
return false
|
||||
@ -2160,7 +2172,7 @@ func isReflexive(t *rtype) bool {
|
||||
// needKeyUpdate reports whether map overwrites require the key to be copied.
|
||||
func needKeyUpdate(t *rtype) bool {
|
||||
switch t.Kind() {
|
||||
case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Ptr, UnsafePointer:
|
||||
case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Chan, Pointer, UnsafePointer:
|
||||
return false
|
||||
case Float32, Float64, Complex64, Complex128, Interface, String:
|
||||
// Float keys can be updated from +0 to -0.
|
||||
@ -2217,10 +2229,10 @@ const (
|
||||
|
||||
func bucketOf(ktyp, etyp *rtype) *rtype {
|
||||
if ktyp.size > maxKeySize {
|
||||
ktyp = PtrTo(ktyp).(*rtype)
|
||||
ktyp = PointerTo(ktyp).(*rtype)
|
||||
}
|
||||
if etyp.size > maxValSize {
|
||||
etyp = PtrTo(etyp).(*rtype)
|
||||
etyp = PointerTo(etyp).(*rtype)
|
||||
}
|
||||
|
||||
// Prepare GC data if any.
|
||||
@ -2458,10 +2470,10 @@ func StructOf(fields []StructField) Type {
|
||||
repr = append(repr, (" " + name)...)
|
||||
if f.embedded() {
|
||||
// Embedded field
|
||||
if f.typ.Kind() == Ptr {
|
||||
if f.typ.Kind() == Pointer {
|
||||
// Embedded ** and *interface{} are illegal
|
||||
elem := ft.Elem()
|
||||
if k := elem.Kind(); k == Ptr || k == Interface {
|
||||
if k := elem.Kind(); k == Pointer || k == Interface {
|
||||
panic("reflect.StructOf: illegal embedded field type " + ft.String())
|
||||
}
|
||||
}
|
||||
@ -2526,7 +2538,7 @@ func StructOf(fields []StructField) Type {
|
||||
tfn: resolveReflectText(unsafe.Pointer(&tfn)),
|
||||
})
|
||||
}
|
||||
case Ptr:
|
||||
case Pointer:
|
||||
ptr := (*ptrType)(unsafe.Pointer(ft))
|
||||
if unt := ptr.uncommon(); unt != nil {
|
||||
if i > 0 && unt.mcount > 0 {
|
||||
@ -3123,7 +3135,7 @@ func addTypeBits(bv *bitVector, offset uintptr, t *rtype) {
|
||||
}
|
||||
|
||||
switch Kind(t.kind & kindMask) {
|
||||
case Chan, Func, Map, Ptr, Slice, String, UnsafePointer:
|
||||
case Chan, Func, Map, Pointer, Slice, String, UnsafePointer:
|
||||
// 1 pointer at start of representation
|
||||
for bv.n < uint32(offset/uintptr(goarch.PtrSize)) {
|
||||
bv.append(0)
|
||||
|
Loading…
Reference in New Issue
Block a user