OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package fmt | 5 package fmt |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "io" | 9 "io" |
10 "os" | 10 "os" |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 case 'X': | 513 case 'X': |
514 p.fmt.fmt_sX(s) | 514 p.fmt.fmt_sX(s) |
515 case 'q': | 515 case 'q': |
516 p.fmt.fmt_q(s) | 516 p.fmt.fmt_q(s) |
517 default: | 517 default: |
518 p.badVerb(verb, value) | 518 p.badVerb(verb, value) |
519 } | 519 } |
520 } | 520 } |
521 | 521 |
522 func (p *pp) fmtPointer(field interface{}, value reflect.Value, verb int, goSynt
ax bool) { | 522 func (p *pp) fmtPointer(field interface{}, value reflect.Value, verb int, goSynt
ax bool) { |
523 » v, ok := value.(uintptrGetter) | 523 » var u uintptr |
524 » if !ok { // reflect.PtrValue is a uintptrGetter, so failure means it's n
ot a pointer at all. | 524 » switch value.(type) { |
| 525 » case *reflect.ChanValue, *reflect.FuncValue, *reflect.MapValue, *reflect
.PtrValue, *reflect.SliceValue, *reflect.UnsafePointerValue: |
| 526 » » u = value.(uintptrGetter).Get() |
| 527 » default: |
525 p.badVerb(verb, field) | 528 p.badVerb(verb, field) |
526 return | 529 return |
527 } | 530 } |
528 u := v.Get() | |
529 if goSyntax { | 531 if goSyntax { |
530 p.add('(') | 532 p.add('(') |
531 p.buf.WriteString(reflect.Typeof(field).String()) | 533 p.buf.WriteString(reflect.Typeof(field).String()) |
532 p.add(')') | 534 p.add(')') |
533 p.add('(') | 535 p.add('(') |
534 if u == 0 { | 536 if u == 0 { |
535 p.buf.Write(nilBytes) | 537 p.buf.Write(nilBytes) |
536 } else { | 538 } else { |
537 » » » p.fmt0x64(uint64(v.Get()), true) | 539 » » » p.fmt0x64(uint64(u), true) |
538 } | 540 } |
539 p.add(')') | 541 p.add(')') |
540 } else { | 542 } else { |
541 p.fmt0x64(uint64(u), !p.fmt.sharp) | 543 p.fmt0x64(uint64(u), !p.fmt.sharp) |
542 } | 544 } |
543 } | 545 } |
544 | 546 |
545 var ( | 547 var ( |
546 intBits = reflect.Typeof(0).Bits() | 548 intBits = reflect.Typeof(0).Bits() |
547 floatBits = reflect.Typeof(0.0).Bits() | 549 floatBits = reflect.Typeof(0.0).Bits() |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 p.fmt0x64(uint64(v), true) | 806 p.fmt0x64(uint64(v), true) |
805 } | 807 } |
806 p.buf.WriteByte(')') | 808 p.buf.WriteByte(')') |
807 break | 809 break |
808 } | 810 } |
809 if v == 0 { | 811 if v == 0 { |
810 p.buf.Write(nilAngleBytes) | 812 p.buf.Write(nilAngleBytes) |
811 break | 813 break |
812 } | 814 } |
813 p.fmt0x64(uint64(v), true) | 815 p.fmt0x64(uint64(v), true) |
814 » case uintptrGetter: | 816 » case *reflect.ChanValue, *reflect.FuncValue, *reflect.UnsafePointerValue
: |
815 p.fmtPointer(field, value, verb, goSyntax) | 817 p.fmtPointer(field, value, verb, goSyntax) |
816 default: | 818 default: |
817 p.unknownType(f) | 819 p.unknownType(f) |
818 } | 820 } |
819 return false | 821 return false |
820 } | 822 } |
821 | 823 |
822 // intFromArg gets the fieldnumth element of a. On return, isInt reports whether
the argument has type int. | 824 // intFromArg gets the fieldnumth element of a. On return, isInt reports whether
the argument has type int. |
823 func intFromArg(a []interface{}, end, i, fieldnum int) (num int, isInt bool, new
i, newfieldnum int) { | 825 func intFromArg(a []interface{}, end, i, fieldnum int) (num int, isInt bool, new
i, newfieldnum int) { |
824 newi, newfieldnum = end, fieldnum | 826 newi, newfieldnum = end, fieldnum |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 if addspace || !isString && !prevString { | 941 if addspace || !isString && !prevString { |
940 p.buf.WriteByte(' ') | 942 p.buf.WriteByte(' ') |
941 } | 943 } |
942 } | 944 } |
943 prevString = p.printField(field, 'v', false, false, 0) | 945 prevString = p.printField(field, 'v', false, false, 0) |
944 } | 946 } |
945 if addnewline { | 947 if addnewline { |
946 p.buf.WriteByte('\n') | 948 p.buf.WriteByte('\n') |
947 } | 949 } |
948 } | 950 } |
OLD | NEW |