mirror of https://github.com/golang/go.git
reflect: clean up unnecessary comments for rtype
For consistency, this CL cleans up unnecessary comments,
and moves these Overflow methods to exported area.
For #60427
Change-Id: I14d4ffbc3552d31c211ea1e0b7a0f7090a4a8b89
GitHub-Last-Rev: acdc6ad51b
GitHub-Pull-Request: golang/go#66019
Reviewed-on: https://go-review.googlesource.com/c/go/+/567917
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
ff35c382eb
commit
ac76417a62
|
|
@ -313,58 +313,6 @@ type rtype struct {
|
||||||
t abi.Type
|
t abi.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
// OverflowComplex reports whether the complex128 x cannot be represented by type t.
|
|
||||||
// It panics if t's Kind is not Complex64 or Complex128.
|
|
||||||
func (t *rtype) OverflowComplex(x complex128) bool {
|
|
||||||
k := t.Kind()
|
|
||||||
switch k {
|
|
||||||
case Complex64:
|
|
||||||
return overflowFloat32(real(x)) || overflowFloat32(imag(x))
|
|
||||||
case Complex128:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
panic("reflect: OverflowComplex of non-complex type " + t.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// OverflowFloat reports whether the float64 x cannot be represented by type t.
|
|
||||||
// It panics if t's Kind is not Float32 or Float64.
|
|
||||||
func (t *rtype) OverflowFloat(x float64) bool {
|
|
||||||
k := t.Kind()
|
|
||||||
switch k {
|
|
||||||
case Float32:
|
|
||||||
return overflowFloat32(x)
|
|
||||||
case Float64:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
panic("reflect: OverflowFloat of non-float type " + t.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// OverflowInt reports whether the int64 x cannot be represented by type t.
|
|
||||||
// It panics if t's Kind is not Int, Int8, Int16, Int32, or Int64.
|
|
||||||
func (t *rtype) OverflowInt(x int64) bool {
|
|
||||||
k := t.Kind()
|
|
||||||
switch k {
|
|
||||||
case Int, Int8, Int16, Int32, Int64:
|
|
||||||
bitSize := t.Size() * 8
|
|
||||||
trunc := (x << (64 - bitSize)) >> (64 - bitSize)
|
|
||||||
return x != trunc
|
|
||||||
}
|
|
||||||
panic("reflect: OverflowInt of non-int type " + t.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// OverflowUint reports whether the uint64 x cannot be represented by type t.
|
|
||||||
// It panics if t's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
|
|
||||||
func (t *rtype) OverflowUint(x uint64) bool {
|
|
||||||
k := t.Kind()
|
|
||||||
switch k {
|
|
||||||
case Uint, Uintptr, Uint8, Uint16, Uint32, Uint64:
|
|
||||||
bitSize := t.Size() * 8
|
|
||||||
trunc := (x << (64 - bitSize)) >> (64 - bitSize)
|
|
||||||
return x != trunc
|
|
||||||
}
|
|
||||||
panic("reflect: OverflowUint of non-uint type " + t.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *rtype) common() *abi.Type {
|
func (t *rtype) common() *abi.Type {
|
||||||
return &t.t
|
return &t.t
|
||||||
}
|
}
|
||||||
|
|
@ -880,6 +828,50 @@ func (t *rtype) IsVariadic() bool {
|
||||||
return tt.IsVariadic()
|
return tt.IsVariadic()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *rtype) OverflowComplex(x complex128) bool {
|
||||||
|
k := t.Kind()
|
||||||
|
switch k {
|
||||||
|
case Complex64:
|
||||||
|
return overflowFloat32(real(x)) || overflowFloat32(imag(x))
|
||||||
|
case Complex128:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
panic("reflect: OverflowComplex of non-complex type " + t.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *rtype) OverflowFloat(x float64) bool {
|
||||||
|
k := t.Kind()
|
||||||
|
switch k {
|
||||||
|
case Float32:
|
||||||
|
return overflowFloat32(x)
|
||||||
|
case Float64:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
panic("reflect: OverflowFloat of non-float type " + t.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *rtype) OverflowInt(x int64) bool {
|
||||||
|
k := t.Kind()
|
||||||
|
switch k {
|
||||||
|
case Int, Int8, Int16, Int32, Int64:
|
||||||
|
bitSize := t.Size() * 8
|
||||||
|
trunc := (x << (64 - bitSize)) >> (64 - bitSize)
|
||||||
|
return x != trunc
|
||||||
|
}
|
||||||
|
panic("reflect: OverflowInt of non-int type " + t.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *rtype) OverflowUint(x uint64) bool {
|
||||||
|
k := t.Kind()
|
||||||
|
switch k {
|
||||||
|
case Uint, Uintptr, Uint8, Uint16, Uint32, Uint64:
|
||||||
|
bitSize := t.Size() * 8
|
||||||
|
trunc := (x << (64 - bitSize)) >> (64 - bitSize)
|
||||||
|
return x != trunc
|
||||||
|
}
|
||||||
|
panic("reflect: OverflowUint of non-uint type " + t.String())
|
||||||
|
}
|
||||||
|
|
||||||
// add returns p+x.
|
// add returns p+x.
|
||||||
//
|
//
|
||||||
// The whySafe string is ignored, so that the function still inlines
|
// The whySafe string is ignored, so that the function still inlines
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue