Source file
src/go/types/typelists.go
1
2
3
4
5
6
7
8 package types
9
10 import "bytes"
11
12
13 type TypeParamList struct{ tparams []*TypeParam }
14
15
16
17 func (l *TypeParamList) Len() int { return len(l.list()) }
18
19
20 func (l *TypeParamList) At(i int) *TypeParam { return l.tparams[i] }
21
22
23
24
25 func (l *TypeParamList) list() []*TypeParam {
26 if l == nil {
27 return nil
28 }
29 return l.tparams
30 }
31
32 func (l *TypeParamList) String() string {
33 var buf bytes.Buffer
34 buf.WriteByte('[')
35 for i, tparam := range l.tparams {
36 if i > 0 {
37 buf.WriteString(", ")
38 }
39 WriteType(&buf, tparam, nil)
40 }
41 buf.WriteByte(']')
42 return buf.String()
43 }
44
45
46 type TypeList struct{ types []Type }
47
48
49 func newTypeList(list []Type) *TypeList {
50 if len(list) == 0 {
51 return nil
52 }
53 return &TypeList{list}
54 }
55
56
57
58 func (l *TypeList) Len() int { return len(l.list()) }
59
60
61 func (l *TypeList) At(i int) Type { return l.types[i] }
62
63
64
65
66 func (l *TypeList) list() []Type {
67 if l == nil {
68 return nil
69 }
70 return l.types
71 }
72
73 func (l *TypeList) String() string {
74 var buf bytes.Buffer
75 buf.WriteByte('[')
76 for i, t := range l.types {
77 if i > 0 {
78 buf.WriteString(", ")
79 }
80 WriteType(&buf, t, nil)
81 }
82 buf.WriteByte(']')
83 return buf.String()
84 }
85
86
87
88
89 func bindTParams(list []*TypeParam) *TypeParamList {
90 if len(list) == 0 {
91 return nil
92 }
93 for i, typ := range list {
94 if typ.index >= 0 {
95 panic("type parameter bound more than once")
96 }
97 typ.index = i
98 }
99 return &TypeParamList{tparams: list}
100 }
101
View as plain text