Rename reflect.Ptr to reflect.Pointer
This was done in plain Go for 1.18:
17910ed4ff
Этот коммит содержится в:
родитель
cf8f4d65f2
коммит
836ab95192
1 изменённых файлов: 17 добавлений и 12 удалений
|
@ -18,7 +18,7 @@ import (
|
||||||
// if set) and xxx contains the type kind number:
|
// if set) and xxx contains the type kind number:
|
||||||
// 0 (0001): Chan
|
// 0 (0001): Chan
|
||||||
// 1 (0011): Interface
|
// 1 (0011): Interface
|
||||||
// 2 (0101): Ptr
|
// 2 (0101): Pointer
|
||||||
// 3 (0111): Slice
|
// 3 (0111): Slice
|
||||||
// 4 (1001): Array
|
// 4 (1001): Array
|
||||||
// 5 (1011): Func
|
// 5 (1011): Func
|
||||||
|
@ -54,7 +54,7 @@ const (
|
||||||
UnsafePointer
|
UnsafePointer
|
||||||
Chan
|
Chan
|
||||||
Interface
|
Interface
|
||||||
Ptr
|
Pointer
|
||||||
Slice
|
Slice
|
||||||
Array
|
Array
|
||||||
Func
|
Func
|
||||||
|
@ -62,6 +62,9 @@ const (
|
||||||
Struct
|
Struct
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Ptr is the old name for the Pointer kind.
|
||||||
|
const Ptr = Pointer
|
||||||
|
|
||||||
func (k Kind) String() string {
|
func (k Kind) String() string {
|
||||||
switch k {
|
switch k {
|
||||||
case Bool:
|
case Bool:
|
||||||
|
@ -104,7 +107,7 @@ func (k Kind) String() string {
|
||||||
return "chan"
|
return "chan"
|
||||||
case Interface:
|
case Interface:
|
||||||
return "interface"
|
return "interface"
|
||||||
case Ptr:
|
case Pointer:
|
||||||
return "ptr"
|
return "ptr"
|
||||||
case Slice:
|
case Slice:
|
||||||
return "slice"
|
return "slice"
|
||||||
|
@ -252,7 +255,7 @@ type Type interface {
|
||||||
// Chan: ChanDir, Elem
|
// Chan: ChanDir, Elem
|
||||||
// Func: In, NumIn, Out, NumOut, IsVariadic.
|
// Func: In, NumIn, Out, NumOut, IsVariadic.
|
||||||
// Map: Key, Elem
|
// Map: Key, Elem
|
||||||
// Ptr: Elem
|
// Pointer: Elem
|
||||||
// Slice: Elem
|
// Slice: Elem
|
||||||
// Struct: Field, FieldByIndex, FieldByName, FieldByNameFunc, NumField
|
// Struct: Field, FieldByIndex, FieldByName, FieldByNameFunc, NumField
|
||||||
|
|
||||||
|
@ -280,7 +283,7 @@ type Type interface {
|
||||||
IsVariadic() bool
|
IsVariadic() bool
|
||||||
|
|
||||||
// Elem returns a type's element type.
|
// 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
|
Elem() Type
|
||||||
|
|
||||||
// Field returns a struct type's i'th field.
|
// Field returns a struct type's i'th field.
|
||||||
|
@ -350,13 +353,15 @@ func TypeOf(i interface{}) Type {
|
||||||
return ValueOf(i).typecode
|
return ValueOf(i).typecode
|
||||||
}
|
}
|
||||||
|
|
||||||
func PtrTo(t Type) Type {
|
func PtrTo(t Type) Type { return PointerTo(t) }
|
||||||
if t.Kind() == Ptr {
|
|
||||||
|
func PointerTo(t Type) Type {
|
||||||
|
if t.Kind() == Pointer {
|
||||||
panic("reflect: cannot make **T type")
|
panic("reflect: cannot make **T type")
|
||||||
}
|
}
|
||||||
ptrType := t.(rawType)<<5 | 5 // 0b0101 == 5
|
ptrType := t.(rawType)<<5 | 5 // 0b0101 == 5
|
||||||
if ptrType>>5 != t {
|
if ptrType>>5 != t {
|
||||||
panic("reflect: PtrTo type does not fit")
|
panic("reflect: PointerTo type does not fit")
|
||||||
}
|
}
|
||||||
return ptrType
|
return ptrType
|
||||||
}
|
}
|
||||||
|
@ -382,7 +387,7 @@ func (t rawType) Elem() Type {
|
||||||
|
|
||||||
func (t rawType) elem() rawType {
|
func (t rawType) elem() rawType {
|
||||||
switch t.Kind() {
|
switch t.Kind() {
|
||||||
case Chan, Ptr, Slice:
|
case Chan, Pointer, Slice:
|
||||||
return t.stripPrefix()
|
return t.stripPrefix()
|
||||||
case Array:
|
case Array:
|
||||||
index := t.stripPrefix()
|
index := t.stripPrefix()
|
||||||
|
@ -566,7 +571,7 @@ func (t rawType) Size() uintptr {
|
||||||
return 16
|
return 16
|
||||||
case String:
|
case String:
|
||||||
return unsafe.Sizeof("")
|
return unsafe.Sizeof("")
|
||||||
case UnsafePointer, Chan, Map, Ptr:
|
case UnsafePointer, Chan, Map, Pointer:
|
||||||
return unsafe.Sizeof(uintptr(0))
|
return unsafe.Sizeof(uintptr(0))
|
||||||
case Slice:
|
case Slice:
|
||||||
return unsafe.Sizeof([]int{})
|
return unsafe.Sizeof([]int{})
|
||||||
|
@ -615,7 +620,7 @@ func (t rawType) Align() int {
|
||||||
return int(unsafe.Alignof(complex128(0)))
|
return int(unsafe.Alignof(complex128(0)))
|
||||||
case String:
|
case String:
|
||||||
return int(unsafe.Alignof(""))
|
return int(unsafe.Alignof(""))
|
||||||
case UnsafePointer, Chan, Map, Ptr:
|
case UnsafePointer, Chan, Map, Pointer:
|
||||||
return int(unsafe.Alignof(uintptr(0)))
|
return int(unsafe.Alignof(uintptr(0)))
|
||||||
case Slice:
|
case Slice:
|
||||||
return int(unsafe.Alignof([]int(nil)))
|
return int(unsafe.Alignof([]int(nil)))
|
||||||
|
@ -681,7 +686,7 @@ func (t rawType) Comparable() bool {
|
||||||
return true
|
return true
|
||||||
case Interface:
|
case Interface:
|
||||||
return true
|
return true
|
||||||
case Ptr:
|
case Pointer:
|
||||||
return true
|
return true
|
||||||
case Slice:
|
case Slice:
|
||||||
return false
|
return false
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче