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 reflect | 5 package reflect |
6 | 6 |
7 import ( | 7 import ( |
8 "runtime" | 8 "runtime" |
9 "unsafe" | 9 "unsafe" |
10 ) | 10 ) |
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 if t == nil || i < 0 || i >= len(t.methods) { | 945 if t == nil || i < 0 || i >= len(t.methods) { |
946 return nil | 946 return nil |
947 } | 947 } |
948 p := &t.methods[i] | 948 p := &t.methods[i] |
949 | 949 |
950 // Interface is two words: itable, data. | 950 // Interface is two words: itable, data. |
951 tab := *(**runtime.Itable)(v.addr) | 951 tab := *(**runtime.Itable)(v.addr) |
952 data := &value{Typeof((*byte)(nil)), addr(uintptr(v.addr) + ptrSize), tr
ue} | 952 data := &value{Typeof((*byte)(nil)), addr(uintptr(v.addr) + ptrSize), tr
ue} |
953 | 953 |
954 // Function pointer is at p.perm in the table. | 954 // Function pointer is at p.perm in the table. |
955 » fn := tab.Fn[p.perm] | 955 » fn := tab.Fn[i] |
956 fv := &FuncValue{value: value{toType(*p.typ), addr(&fn), true}, first: d
ata, isInterface: true} | 956 fv := &FuncValue{value: value{toType(*p.typ), addr(&fn), true}, first: d
ata, isInterface: true} |
957 return fv | 957 return fv |
958 } | 958 } |
959 | 959 |
960 /* | 960 /* |
961 * map | 961 * map |
962 */ | 962 */ |
963 | 963 |
964 // A MapValue represents a map value. | 964 // A MapValue represents a map value. |
965 type MapValue struct { | 965 type MapValue struct { |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 panicln("newValue", typ.String()) | 1280 panicln("newValue", typ.String()) |
1281 } | 1281 } |
1282 | 1282 |
1283 // MakeZero returns a zero Value for the specified Type. | 1283 // MakeZero returns a zero Value for the specified Type. |
1284 func MakeZero(typ Type) Value { | 1284 func MakeZero(typ Type) Value { |
1285 if typ == nil { | 1285 if typ == nil { |
1286 return nil | 1286 return nil |
1287 } | 1287 } |
1288 return newValue(typ, addr(unsafe.New(typ)), true) | 1288 return newValue(typ, addr(unsafe.New(typ)), true) |
1289 } | 1289 } |
OLD | NEW |