Skip to content

Commit ac76417

Browse files
callthingsoffgopherbot
authored andcommitted
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: acdc6ad GitHub-Pull-Request: #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>
1 parent ff35c38 commit ac76417

File tree

1 file changed

+44
-52
lines changed

1 file changed

+44
-52
lines changed

src/reflect/type.go

+44-52
Original file line numberDiff line numberDiff line change
@@ -313,58 +313,6 @@ type rtype struct {
313313
t abi.Type
314314
}
315315

316-
// OverflowComplex reports whether the complex128 x cannot be represented by type t.
317-
// It panics if t's Kind is not Complex64 or Complex128.
318-
func (t *rtype) OverflowComplex(x complex128) bool {
319-
k := t.Kind()
320-
switch k {
321-
case Complex64:
322-
return overflowFloat32(real(x)) || overflowFloat32(imag(x))
323-
case Complex128:
324-
return false
325-
}
326-
panic("reflect: OverflowComplex of non-complex type " + t.String())
327-
}
328-
329-
// OverflowFloat reports whether the float64 x cannot be represented by type t.
330-
// It panics if t's Kind is not Float32 or Float64.
331-
func (t *rtype) OverflowFloat(x float64) bool {
332-
k := t.Kind()
333-
switch k {
334-
case Float32:
335-
return overflowFloat32(x)
336-
case Float64:
337-
return false
338-
}
339-
panic("reflect: OverflowFloat of non-float type " + t.String())
340-
}
341-
342-
// OverflowInt reports whether the int64 x cannot be represented by type t.
343-
// It panics if t's Kind is not Int, Int8, Int16, Int32, or Int64.
344-
func (t *rtype) OverflowInt(x int64) bool {
345-
k := t.Kind()
346-
switch k {
347-
case Int, Int8, Int16, Int32, Int64:
348-
bitSize := t.Size() * 8
349-
trunc := (x << (64 - bitSize)) >> (64 - bitSize)
350-
return x != trunc
351-
}
352-
panic("reflect: OverflowInt of non-int type " + t.String())
353-
}
354-
355-
// OverflowUint reports whether the uint64 x cannot be represented by type t.
356-
// It panics if t's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
357-
func (t *rtype) OverflowUint(x uint64) bool {
358-
k := t.Kind()
359-
switch k {
360-
case Uint, Uintptr, Uint8, Uint16, Uint32, Uint64:
361-
bitSize := t.Size() * 8
362-
trunc := (x << (64 - bitSize)) >> (64 - bitSize)
363-
return x != trunc
364-
}
365-
panic("reflect: OverflowUint of non-uint type " + t.String())
366-
}
367-
368316
func (t *rtype) common() *abi.Type {
369317
return &t.t
370318
}
@@ -880,6 +828,50 @@ func (t *rtype) IsVariadic() bool {
880828
return tt.IsVariadic()
881829
}
882830

831+
func (t *rtype) OverflowComplex(x complex128) bool {
832+
k := t.Kind()
833+
switch k {
834+
case Complex64:
835+
return overflowFloat32(real(x)) || overflowFloat32(imag(x))
836+
case Complex128:
837+
return false
838+
}
839+
panic("reflect: OverflowComplex of non-complex type " + t.String())
840+
}
841+
842+
func (t *rtype) OverflowFloat(x float64) bool {
843+
k := t.Kind()
844+
switch k {
845+
case Float32:
846+
return overflowFloat32(x)
847+
case Float64:
848+
return false
849+
}
850+
panic("reflect: OverflowFloat of non-float type " + t.String())
851+
}
852+
853+
func (t *rtype) OverflowInt(x int64) bool {
854+
k := t.Kind()
855+
switch k {
856+
case Int, Int8, Int16, Int32, Int64:
857+
bitSize := t.Size() * 8
858+
trunc := (x << (64 - bitSize)) >> (64 - bitSize)
859+
return x != trunc
860+
}
861+
panic("reflect: OverflowInt of non-int type " + t.String())
862+
}
863+
864+
func (t *rtype) OverflowUint(x uint64) bool {
865+
k := t.Kind()
866+
switch k {
867+
case Uint, Uintptr, Uint8, Uint16, Uint32, Uint64:
868+
bitSize := t.Size() * 8
869+
trunc := (x << (64 - bitSize)) >> (64 - bitSize)
870+
return x != trunc
871+
}
872+
panic("reflect: OverflowUint of non-uint type " + t.String())
873+
}
874+
883875
// add returns p+x.
884876
//
885877
// The whySafe string is ignored, so that the function still inlines

0 commit comments

Comments
 (0)