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