1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Formatting of reflection types and values for debugging.
6 // Not defined as methods so they do not need to be linked into most binaries;
7 // the functions are not used by the library itself, only in tests.
16 // valueToString returns a textual representation of the reflection value val.
17 // For debugging only.
18 func valueToString(val Value
) string {
25 case Int
, Int8
, Int16
, Int32
, Int64
:
26 return strconv
.FormatInt(val
.Int(), 10)
27 case Uint
, Uint8
, Uint16
, Uint32
, Uint64
, Uintptr
:
28 return strconv
.FormatUint(val
.Uint(), 10)
29 case Float32
, Float64
:
30 return strconv
.FormatFloat(val
.Float(), 'g', -1, 64)
31 case Complex64
, Complex128
:
33 return strconv
.FormatFloat(real(c
), 'g', -1, 64) + "+" + strconv
.FormatFloat(imag(c
), 'g', -1, 64) + "i"
44 str
= typ
.String() + "("
48 str
+= "&" + valueToString(v
.Elem())
56 for i
:= 0; i
< v
.Len(); i
++ {
60 str
+= valueToString(v
.Index(i
))
68 str
+= "<can't iterate on maps>"
79 for i
, n
:= 0, v
.NumField(); i
< n
; i
++ {
83 str
+= valueToString(v
.Field(i
))
88 return typ
.String() + "(" + valueToString(val
.Elem()) + ")"
91 return typ
.String() + "(" + strconv
.FormatUint(uint64(v
.Pointer()), 10) + ")"
93 panic("valueToString: can't print type " + typ
.String())