File tree Expand file tree Collapse file tree 5 files changed +505
-1
lines changed Expand file tree Collapse file tree 5 files changed +505
-1
lines changed Original file line number Diff line number Diff line change @@ -5,4 +5,7 @@ import "reflect"
5
5
func main () {
6
6
tyIntSlice := reflect .SliceOf (reflect .TypeOf (0 ))
7
7
println (tyIntSlice .String ())
8
+
9
+ v := reflect .Zero (tyIntSlice )
10
+ println (v .Len ())
8
11
}
Original file line number Diff line number Diff line change @@ -329,6 +329,22 @@ func (p *Imethod) PkgPath() string {
329
329
330
330
func (t * Type ) Kind () Kind { return Kind (t .Kind_ & KindMask ) }
331
331
332
+ func (t * Type ) HasName () bool {
333
+ return t .TFlag & TFlagNamed != 0
334
+ }
335
+
336
+ func (t * Type ) Pointers () bool { return t .PtrBytes != 0 }
337
+
338
+ // IfaceIndir reports whether t is stored indirectly in an interface value.
339
+ func (t * Type ) IfaceIndir () bool {
340
+ return t .Kind_ & KindDirectIface == 0
341
+ }
342
+
343
+ // isDirectIface reports whether t is stored directly in an interface value.
344
+ func (t * Type ) IsDirectIface () bool {
345
+ return t .Kind_ & KindDirectIface != 0
346
+ }
347
+
332
348
// Size returns the size of data with type t.
333
349
func (t * Type ) Size () uintptr { return t .Size_ }
334
350
@@ -340,7 +356,7 @@ func (t *Type) FieldAlign() int { return int(t.FieldAlign_) }
340
356
// String returns string form of type t.
341
357
func (t * Type ) String () string {
342
358
if t .TFlag & TFlagExtraStar != 0 {
343
- return "*" + t .Str_
359
+ return "*" + t .Str_ // TODO(xsw): misunderstand
344
360
}
345
361
return t .Str_
346
362
}
Original file line number Diff line number Diff line change
1
+ // Copyright 2020 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.
4
+
5
+ // Package unsafeheader contains header declarations for the Go runtime's slice
6
+ // and string implementations.
7
+ //
8
+ // This package allows packages that cannot import "reflect" to use types that
9
+ // are tested to be equivalent to reflect.SliceHeader and reflect.StringHeader.
10
+ package reflect
11
+
12
+ import (
13
+ "unsafe"
14
+ )
15
+
16
+ // unsafeheaderSlice is the runtime representation of a slice.
17
+ // It cannot be used safely or portably and its representation may
18
+ // change in a later release.
19
+ //
20
+ // Unlike reflect.SliceHeader, its Data field is sufficient to guarantee the
21
+ // data it references will not be garbage collected.
22
+ type unsafeheaderSlice struct {
23
+ Data unsafe.Pointer
24
+ Len int
25
+ Cap int
26
+ }
27
+
28
+ // unsafeheaderString is the runtime representation of a string.
29
+ // It cannot be used safely or portably and its representation may
30
+ // change in a later release.
31
+ //
32
+ // Unlike reflect.StringHeader, its Data field is sufficient to guarantee the
33
+ // data it references will not be garbage collected.
34
+ type unsafeheaderString struct {
35
+ Data unsafe.Pointer
36
+ Len int
37
+ }
You can’t perform that action at this time.
0 commit comments