From ac76417a6210dc2cfd062eb8d9be8108bcc89570 Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Thu, 29 Feb 2024 04:40:02 +0000 Subject: [PATCH] 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: acdc6ad51bd9ad60a34fdfa8f00a7652cbe34510 GitHub-Pull-Request: golang/go#66019 Reviewed-on: https://go-review.googlesource.com/c/go/+/567917 LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Michael Knyszek --- src/reflect/type.go | 96 +++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 52 deletions(-) diff --git a/src/reflect/type.go b/src/reflect/type.go index 89f33e6cf8..1609084699 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -313,58 +313,6 @@ type rtype struct { 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 { return &t.t } @@ -880,6 +828,50 @@ func (t *rtype) IsVariadic() bool { 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. // // The whySafe string is ignored, so that the function still inlines -- 2.48.1