...
1
2
3
4
5
6
7
8 package typeparams
9
10 import (
11 "go/ast"
12 "go/types"
13 )
14
15
16 type IndexListExpr = ast.IndexListExpr
17
18
19 func ForTypeSpec(n *ast.TypeSpec) *ast.FieldList {
20 if n == nil {
21 return nil
22 }
23 return n.TypeParams
24 }
25
26
27 func ForFuncType(n *ast.FuncType) *ast.FieldList {
28 if n == nil {
29 return nil
30 }
31 return n.TypeParams
32 }
33
34
35 type TypeParam = types.TypeParam
36
37
38 type TypeParamList = types.TypeParamList
39
40
41 type TypeList = types.TypeList
42
43
44 func NewTypeParam(name *types.TypeName, constraint types.Type) *TypeParam {
45 return types.NewTypeParam(name, constraint)
46 }
47
48
49 func SetTypeParamConstraint(tparam *TypeParam, constraint types.Type) {
50 tparam.SetConstraint(constraint)
51 }
52
53
54 func NewSignatureType(recv *types.Var, recvTypeParams, typeParams []*TypeParam, params, results *types.Tuple, variadic bool) *types.Signature {
55 return types.NewSignatureType(recv, recvTypeParams, typeParams, params, results, variadic)
56 }
57
58
59 func ForSignature(sig *types.Signature) *TypeParamList {
60 return sig.TypeParams()
61 }
62
63
64 func RecvTypeParams(sig *types.Signature) *TypeParamList {
65 return sig.RecvTypeParams()
66 }
67
68
69 func IsComparable(iface *types.Interface) bool {
70 return iface.IsComparable()
71 }
72
73
74 func IsMethodSet(iface *types.Interface) bool {
75 return iface.IsMethodSet()
76 }
77
78
79 func IsImplicit(iface *types.Interface) bool {
80 return iface.IsImplicit()
81 }
82
83
84 func MarkImplicit(iface *types.Interface) {
85 iface.MarkImplicit()
86 }
87
88
89
90 func ForNamed(named *types.Named) *TypeParamList {
91 return named.TypeParams()
92 }
93
94
95
96 func SetForNamed(n *types.Named, tparams []*TypeParam) {
97 n.SetTypeParams(tparams)
98 }
99
100
101 func NamedTypeArgs(named *types.Named) *TypeList {
102 return named.TypeArgs()
103 }
104
105
106 func NamedTypeOrigin(named *types.Named) types.Type {
107 return named.Origin()
108 }
109
110
111 type Term = types.Term
112
113
114 func NewTerm(tilde bool, typ types.Type) *Term {
115 return types.NewTerm(tilde, typ)
116 }
117
118
119 type Union = types.Union
120
121
122 func NewUnion(terms []*Term) *Union {
123 return types.NewUnion(terms)
124 }
125
126
127
128 func InitInstanceInfo(info *types.Info) {
129 info.Instances = make(map[*ast.Ident]types.Instance)
130 }
131
132
133 type Instance = types.Instance
134
135
136 func GetInstances(info *types.Info) map[*ast.Ident]Instance {
137 return info.Instances
138 }
139
140
141 type Context = types.Context
142
143
144 func NewContext() *Context {
145 return types.NewContext()
146 }
147
148
149 func Instantiate(ctxt *Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error) {
150 return types.Instantiate(ctxt, typ, targs, validate)
151 }
152
View as plain text