typeprof 0.21.11 → 0.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -31
- data/bin/typeprof +5 -0
- data/doc/doc.ja.md +134 -0
- data/doc/doc.md +136 -0
- data/lib/typeprof/cli/cli.rb +180 -0
- data/lib/typeprof/cli.rb +2 -133
- data/lib/typeprof/code_range.rb +112 -0
- data/lib/typeprof/core/ast/base.rb +263 -0
- data/lib/typeprof/core/ast/call.rb +251 -0
- data/lib/typeprof/core/ast/const.rb +126 -0
- data/lib/typeprof/core/ast/control.rb +432 -0
- data/lib/typeprof/core/ast/meta.rb +150 -0
- data/lib/typeprof/core/ast/method.rb +335 -0
- data/lib/typeprof/core/ast/misc.rb +263 -0
- data/lib/typeprof/core/ast/module.rb +123 -0
- data/lib/typeprof/core/ast/pattern.rb +140 -0
- data/lib/typeprof/core/ast/sig_decl.rb +471 -0
- data/lib/typeprof/core/ast/sig_type.rb +663 -0
- data/lib/typeprof/core/ast/value.rb +319 -0
- data/lib/typeprof/core/ast/variable.rb +315 -0
- data/lib/typeprof/core/ast.rb +472 -0
- data/lib/typeprof/core/builtin.rb +146 -0
- data/lib/typeprof/core/env/method.rb +137 -0
- data/lib/typeprof/core/env/method_entity.rb +55 -0
- data/lib/typeprof/core/env/module_entity.rb +408 -0
- data/lib/typeprof/core/env/static_read.rb +155 -0
- data/lib/typeprof/core/env/type_alias_entity.rb +27 -0
- data/lib/typeprof/core/env/value_entity.rb +32 -0
- data/lib/typeprof/core/env.rb +360 -0
- data/lib/typeprof/core/graph/box.rb +991 -0
- data/lib/typeprof/core/graph/change_set.rb +224 -0
- data/lib/typeprof/core/graph/filter.rb +155 -0
- data/lib/typeprof/core/graph/vertex.rb +222 -0
- data/lib/typeprof/core/graph.rb +3 -0
- data/lib/typeprof/core/service.rb +522 -0
- data/lib/typeprof/core/type.rb +348 -0
- data/lib/typeprof/core/util.rb +81 -0
- data/lib/typeprof/core.rb +32 -0
- data/lib/typeprof/diagnostic.rb +35 -0
- data/lib/typeprof/lsp/messages.rb +430 -0
- data/lib/typeprof/lsp/server.rb +177 -0
- data/lib/typeprof/lsp/text.rb +69 -0
- data/lib/typeprof/lsp/util.rb +61 -0
- data/lib/typeprof/lsp.rb +4 -907
- data/lib/typeprof/version.rb +1 -1
- data/lib/typeprof.rb +4 -18
- data/typeprof.gemspec +5 -7
- metadata +48 -35
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/main.yml +0 -39
- data/.gitignore +0 -9
- data/Gemfile +0 -17
- data/Gemfile.lock +0 -41
- data/Rakefile +0 -10
- data/exe/typeprof +0 -10
- data/lib/typeprof/analyzer.rb +0 -2598
- data/lib/typeprof/arguments.rb +0 -414
- data/lib/typeprof/block.rb +0 -176
- data/lib/typeprof/builtin.rb +0 -893
- data/lib/typeprof/code-range.rb +0 -177
- data/lib/typeprof/config.rb +0 -158
- data/lib/typeprof/container-type.rb +0 -912
- data/lib/typeprof/export.rb +0 -589
- data/lib/typeprof/import.rb +0 -852
- data/lib/typeprof/insns-def.rb +0 -65
- data/lib/typeprof/iseq.rb +0 -864
- data/lib/typeprof/method.rb +0 -355
- data/lib/typeprof/type.rb +0 -1140
- data/lib/typeprof/utils.rb +0 -212
- data/tools/coverage.rb +0 -14
- data/tools/setup-insns-def.rb +0 -30
- data/typeprof-lsp +0 -3
@@ -0,0 +1,140 @@
|
|
1
|
+
module TypeProf::Core
|
2
|
+
class AST
|
3
|
+
class ArrayPatternNode < Node
|
4
|
+
def initialize(raw_node, lenv)
|
5
|
+
super(raw_node, lenv)
|
6
|
+
@requireds = raw_node.requireds.map {|raw_pat| AST.create_pattern_node(raw_pat, lenv) }
|
7
|
+
@rest = !!raw_node.rest
|
8
|
+
@rest_pattern = raw_node.rest && raw_node.rest.expression ? AST.create_pattern_node(raw_node.rest.expression, lenv) : nil
|
9
|
+
@posts = raw_node.posts.map {|raw_pat| AST.create_pattern_node(raw_pat, lenv) }
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :requireds, :rest, :rest_pattern, :posts
|
13
|
+
|
14
|
+
def attrs = { rest: }
|
15
|
+
def subnodes = { requireds:, rest_pattern:, posts: }
|
16
|
+
|
17
|
+
def install0(genv)
|
18
|
+
@requireds.each do |pat|
|
19
|
+
pat.install(genv)
|
20
|
+
end
|
21
|
+
@rest_pattern.install(genv) if @rest_pattern
|
22
|
+
@posts.each do |pat|
|
23
|
+
pat.install(genv)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class HashPatternNode < Node
|
29
|
+
def initialize(raw_node, lenv)
|
30
|
+
super(raw_node, lenv)
|
31
|
+
@keys = raw_node.elements.map {|raw_assoc| raw_assoc.key.value.to_sym }
|
32
|
+
@values = raw_node.elements.map {|raw_assoc| AST.create_pattern_node(raw_assoc.value, lenv) }
|
33
|
+
@rest = !!raw_node.rest
|
34
|
+
@rest_pattern = raw_node.rest && raw_node.rest.value ? AST.create_pattern_node(raw_node.rest.value, lenv) : nil
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :keys, :values, :rest, :rest_pattern
|
38
|
+
|
39
|
+
def attrs = { keys:, rest: }
|
40
|
+
def subnodes = { values:, rest_pattern: }
|
41
|
+
|
42
|
+
def install0(genv)
|
43
|
+
@values.each do |pat|
|
44
|
+
pat.install(genv)
|
45
|
+
end
|
46
|
+
@rest_pattern.install(genv) if @rest_pattern
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class FindPatternNode < Node
|
51
|
+
def initialize(raw_node, lenv)
|
52
|
+
super(raw_node, lenv)
|
53
|
+
@left = raw_node.left ? AST.create_pattern_node(raw_node.left.expression, lenv) : nil
|
54
|
+
@requireds = raw_node.requireds.map {|raw_elem| AST.create_pattern_node(raw_elem, lenv) }
|
55
|
+
@right = raw_node.right ? AST.create_pattern_node(raw_node.right.expression, lenv) : nil
|
56
|
+
end
|
57
|
+
|
58
|
+
attr_reader :left, :requireds, :right
|
59
|
+
|
60
|
+
def subnodes = { left:, requireds:, right: }
|
61
|
+
|
62
|
+
def install0(genv)
|
63
|
+
@left.install(genv) if @left
|
64
|
+
@requireds.each do |pat|
|
65
|
+
pat.install(genv)
|
66
|
+
end
|
67
|
+
@right.install(genv) if @right
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class AltPatternNode < Node
|
72
|
+
def initialize(raw_node, lenv)
|
73
|
+
super(raw_node, lenv)
|
74
|
+
@left = AST.create_pattern_node(raw_node.left, lenv)
|
75
|
+
@right = AST.create_pattern_node(raw_node.right, lenv)
|
76
|
+
end
|
77
|
+
|
78
|
+
attr_reader :left, :right
|
79
|
+
|
80
|
+
def subnodes = { left:, right: }
|
81
|
+
|
82
|
+
def install0(genv)
|
83
|
+
@left.install(genv)
|
84
|
+
@right.install(genv)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class CapturePatternNode < Node
|
89
|
+
def initialize(raw_node, lenv)
|
90
|
+
super(raw_node, lenv)
|
91
|
+
@value = AST.create_pattern_node(raw_node.value, lenv)
|
92
|
+
@target = AST.create_pattern_node(raw_node.target, lenv)
|
93
|
+
end
|
94
|
+
|
95
|
+
attr_reader :value, :target
|
96
|
+
|
97
|
+
def subnodes = { value:, target: }
|
98
|
+
|
99
|
+
def install0(genv)
|
100
|
+
@value.install(genv)
|
101
|
+
@target.install(genv)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class IfPatternNode < Node
|
106
|
+
def initialize(raw_node, lenv)
|
107
|
+
super(raw_node, lenv)
|
108
|
+
@cond = AST.create_node(raw_node.predicate, lenv)
|
109
|
+
raise if raw_node.statements.type != :statements_node
|
110
|
+
raise if raw_node.statements.body.size != 1
|
111
|
+
@body = AST.create_pattern_node(raw_node.statements.body[0], lenv)
|
112
|
+
raise if raw_node.subsequent
|
113
|
+
end
|
114
|
+
|
115
|
+
attr_reader :cond, :body
|
116
|
+
|
117
|
+
def subnodes = { cond:, body: }
|
118
|
+
|
119
|
+
def install0(genv)
|
120
|
+
@cond.install(genv)
|
121
|
+
@body.install(genv)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class PinnedPatternNode < Node
|
126
|
+
def initialize(raw_node, lenv)
|
127
|
+
super(raw_node, lenv)
|
128
|
+
@expr = AST.create_node(raw_node.type == :pinned_variable_node ? raw_node.variable : raw_node.expression, lenv)
|
129
|
+
end
|
130
|
+
|
131
|
+
attr_reader :expr
|
132
|
+
|
133
|
+
def subnodes = { expr: }
|
134
|
+
|
135
|
+
def install0(genv)
|
136
|
+
@expr.install(genv)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,471 @@
|
|
1
|
+
module TypeProf::Core
|
2
|
+
class AST
|
3
|
+
def self.resolve_rbs_name(name, lenv)
|
4
|
+
if name.namespace.absolute?
|
5
|
+
name.namespace.path + [name.name]
|
6
|
+
else
|
7
|
+
lenv.cref.cpath + name.namespace.path + [name.name]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class SigModuleBaseNode < Node
|
12
|
+
def initialize(raw_decl, lenv)
|
13
|
+
super(raw_decl, lenv)
|
14
|
+
@cpath = AST.resolve_rbs_name(raw_decl.name, lenv)
|
15
|
+
# TODO: decl.type_params
|
16
|
+
# TODO: decl.super_class.args
|
17
|
+
ncref = CRef.new(@cpath, :class, nil, lenv.cref)
|
18
|
+
nlenv = LocalEnv.new(@lenv.path, ncref, {}, [])
|
19
|
+
@members = raw_decl.members.map do |member|
|
20
|
+
AST.create_rbs_member(member, nlenv)
|
21
|
+
end.compact
|
22
|
+
# TODO?: param.variance, param.unchecked, param.upper_bound
|
23
|
+
@params = raw_decl.type_params.map {|param| param.name }
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :cpath, :members, :params
|
27
|
+
|
28
|
+
def subnodes = { members: }
|
29
|
+
def attrs = { cpath:, params: }
|
30
|
+
|
31
|
+
def define0(genv)
|
32
|
+
@members.each do |member|
|
33
|
+
member.define(genv)
|
34
|
+
end
|
35
|
+
mod = genv.resolve_cpath(@cpath)
|
36
|
+
{ module: mod.add_module_decl(genv, self) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def define_copy(genv)
|
40
|
+
mod = genv.resolve_cpath(@cpath)
|
41
|
+
mod.add_module_decl(genv, self)
|
42
|
+
mod.remove_module_decl(genv, @prev_node)
|
43
|
+
super(genv)
|
44
|
+
end
|
45
|
+
|
46
|
+
def undefine0(genv)
|
47
|
+
mod = genv.resolve_cpath(@cpath)
|
48
|
+
mod.remove_module_decl(genv, self)
|
49
|
+
@members.each do |member|
|
50
|
+
member.undefine(genv)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def install0(genv)
|
55
|
+
@mod_val = Source.new(Type::Singleton.new(genv, genv.resolve_cpath(@cpath)))
|
56
|
+
@changes.add_edge(genv, @mod_val, @static_ret[:module].vtx)
|
57
|
+
@members.each do |member|
|
58
|
+
member.install(genv)
|
59
|
+
end
|
60
|
+
Source.new
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class SigModuleNode < SigModuleBaseNode
|
65
|
+
def initialize(raw_decl, lenv)
|
66
|
+
super(raw_decl, lenv)
|
67
|
+
@self_types = []
|
68
|
+
@self_type_args = []
|
69
|
+
raw_decl.self_types.each do |self_type|
|
70
|
+
name = self_type.name
|
71
|
+
cpath = name.namespace.path + [self_type.name.name]
|
72
|
+
toplevel = name.namespace.absolute?
|
73
|
+
@self_types << [cpath, toplevel]
|
74
|
+
@self_type_args << self_type.args.map {|arg| AST.create_rbs_type(arg, lenv) }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
attr_reader :self_types, :self_type_args
|
79
|
+
|
80
|
+
def subnodes
|
81
|
+
super.merge!({ self_type_args: })
|
82
|
+
end
|
83
|
+
def attrs
|
84
|
+
super.merge!({ self_types: })
|
85
|
+
end
|
86
|
+
|
87
|
+
def define0(genv)
|
88
|
+
static_ret = super(genv)
|
89
|
+
static_ret[:self_types] = self_types = []
|
90
|
+
@self_types.zip(@self_type_args) do |(cpath, toplevel), args|
|
91
|
+
args.each {|arg| arg.define(genv) }
|
92
|
+
const_read = BaseConstRead.new(genv, cpath.first, toplevel ? CRef::Toplevel : @lenv.cref)
|
93
|
+
const_reads = [const_read]
|
94
|
+
cpath[1..].each do |cname|
|
95
|
+
const_read = ScopedConstRead.new(cname, const_read)
|
96
|
+
const_reads << const_read
|
97
|
+
end
|
98
|
+
mod = genv.resolve_cpath(@cpath)
|
99
|
+
const_read.followers << mod
|
100
|
+
self_types << const_reads
|
101
|
+
end
|
102
|
+
static_ret
|
103
|
+
end
|
104
|
+
|
105
|
+
def undefine0(genv)
|
106
|
+
super(genv)
|
107
|
+
if @static_ret
|
108
|
+
@static_ret[:self_types].each do |const_reads|
|
109
|
+
const_reads.each do |const_read|
|
110
|
+
const_read.destroy(genv)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
@self_type_args.each do |args|
|
115
|
+
args.each {|arg| arg.undefine(genv) }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class SigInterfaceNode < SigModuleBaseNode
|
121
|
+
end
|
122
|
+
|
123
|
+
class SigClassNode < SigModuleBaseNode
|
124
|
+
def initialize(raw_decl, lenv)
|
125
|
+
super(raw_decl, lenv)
|
126
|
+
superclass = raw_decl.super_class
|
127
|
+
if superclass
|
128
|
+
name = superclass.name
|
129
|
+
@superclass_cpath = name.namespace.path + [name.name]
|
130
|
+
@superclass_toplevel = name.namespace.absolute?
|
131
|
+
@superclass_args = superclass.args.map {|arg| AST.create_rbs_type(arg, lenv) }
|
132
|
+
else
|
133
|
+
@superclass_cpath = nil
|
134
|
+
@superclass_toplevel = nil
|
135
|
+
@superclass_args = nil
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
attr_reader :superclass_cpath, :superclass_toplevel, :superclass_args
|
140
|
+
|
141
|
+
def subnodes
|
142
|
+
super.merge!({ superclass_args: })
|
143
|
+
end
|
144
|
+
def attrs
|
145
|
+
super.merge!({ superclass_cpath:, superclass_toplevel: })
|
146
|
+
end
|
147
|
+
|
148
|
+
def define0(genv)
|
149
|
+
static_ret = super(genv)
|
150
|
+
const_reads = []
|
151
|
+
if @superclass_cpath
|
152
|
+
@superclass_args.each {|arg| arg.define(genv) }
|
153
|
+
const_read = BaseConstRead.new(genv, @superclass_cpath.first, @superclass_toplevel ? CRef::Toplevel : @lenv.cref)
|
154
|
+
const_reads << const_read
|
155
|
+
@superclass_cpath[1..].each do |cname|
|
156
|
+
const_read = ScopedConstRead.new(cname, const_read)
|
157
|
+
const_reads << const_read
|
158
|
+
end
|
159
|
+
mod = genv.resolve_cpath(@cpath)
|
160
|
+
const_read.followers << mod
|
161
|
+
end
|
162
|
+
static_ret[:superclass_cpath] = const_reads
|
163
|
+
static_ret
|
164
|
+
end
|
165
|
+
|
166
|
+
def undefine0(genv)
|
167
|
+
super(genv)
|
168
|
+
if @static_ret
|
169
|
+
@static_ret[:superclass_cpath].each do |const_read|
|
170
|
+
const_read.destroy(genv)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
if @superclass_args
|
174
|
+
@superclass_args.each {|arg| arg.undefine(genv) }
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
class SigDefNode < Node
|
180
|
+
def initialize(raw_decl, lenv)
|
181
|
+
super(raw_decl, lenv)
|
182
|
+
@mid = raw_decl.name
|
183
|
+
@singleton = raw_decl.singleton?
|
184
|
+
@instance = raw_decl.instance?
|
185
|
+
@method_types = raw_decl.overloads.map do |overload|
|
186
|
+
method_type = overload.method_type
|
187
|
+
AST.create_rbs_func_type(method_type, method_type.type_params, method_type.block, lenv)
|
188
|
+
end
|
189
|
+
@overloading = raw_decl.overloading
|
190
|
+
end
|
191
|
+
|
192
|
+
attr_reader :mid, :singleton, :instance, :method_types, :overloading
|
193
|
+
|
194
|
+
def subnodes = { method_types: }
|
195
|
+
def attrs = { mid:, singleton:, instance:, overloading: }
|
196
|
+
|
197
|
+
def install0(genv)
|
198
|
+
[[@singleton, true], [@instance, false]].each do |enabled, singleton|
|
199
|
+
next unless enabled
|
200
|
+
@changes.add_method_decl_box(genv, @lenv.cref.cpath, singleton, @mid, @method_types, @overloading)
|
201
|
+
end
|
202
|
+
Source.new
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
class SigIncludeNode < Node
|
207
|
+
def initialize(raw_decl, lenv)
|
208
|
+
super(raw_decl, lenv)
|
209
|
+
name = raw_decl.name
|
210
|
+
@cpath = name.namespace.path + [name.name]
|
211
|
+
@toplevel = name.namespace.absolute?
|
212
|
+
@args = raw_decl.args.map {|arg| AST.create_rbs_type(arg, lenv) }
|
213
|
+
end
|
214
|
+
|
215
|
+
attr_reader :cpath, :toplevel, :args
|
216
|
+
def subnodes = { args: }
|
217
|
+
def attrs = { cpath:, toplevel: }
|
218
|
+
|
219
|
+
def define0(genv)
|
220
|
+
@args.each {|arg| arg.define(genv) }
|
221
|
+
const_reads = []
|
222
|
+
const_read = BaseConstRead.new(genv, @cpath.first, @toplevel ? CRef::Toplevel : @lenv.cref)
|
223
|
+
const_reads << const_read
|
224
|
+
@cpath[1..].each do |cname|
|
225
|
+
const_read = ScopedConstRead.new(cname, const_read)
|
226
|
+
const_reads << const_read
|
227
|
+
end
|
228
|
+
mod = genv.resolve_cpath(@lenv.cref.cpath)
|
229
|
+
const_read.followers << mod
|
230
|
+
mod.add_include_decl(genv, self)
|
231
|
+
const_reads
|
232
|
+
end
|
233
|
+
|
234
|
+
def define_copy(genv)
|
235
|
+
mod = genv.resolve_cpath(@lenv.cref.cpath)
|
236
|
+
mod.add_include_decl(genv, self)
|
237
|
+
mod.remove_include_decl(genv, @prev_node)
|
238
|
+
super(genv)
|
239
|
+
end
|
240
|
+
|
241
|
+
def undefine0(genv)
|
242
|
+
mod = genv.resolve_cpath(@lenv.cref.cpath)
|
243
|
+
mod.remove_include_decl(genv, self)
|
244
|
+
@static_ret.each do |const_read|
|
245
|
+
const_read.destroy(genv)
|
246
|
+
end
|
247
|
+
@args.each {|arg| arg.undefine(genv) }
|
248
|
+
end
|
249
|
+
|
250
|
+
def install0(genv)
|
251
|
+
Source.new
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
class SigAliasNode < Node
|
256
|
+
def initialize(raw_decl, lenv)
|
257
|
+
super(raw_decl, lenv)
|
258
|
+
@new_mid = raw_decl.new_name
|
259
|
+
@old_mid = raw_decl.old_name
|
260
|
+
@singleton = raw_decl.singleton?
|
261
|
+
@instance = raw_decl.instance?
|
262
|
+
end
|
263
|
+
|
264
|
+
attr_reader :new_mid, :old_mid, :singleton, :instance
|
265
|
+
def attrs = { new_mid:, old_mid:, singleton:, instance: }
|
266
|
+
|
267
|
+
def install0(genv)
|
268
|
+
[[@singleton, true], [@instance, false]].each do |enabled, singleton|
|
269
|
+
next unless enabled
|
270
|
+
@changes.add_method_alias_box(genv, @lenv.cref.cpath, singleton, @new_mid, @old_mid)
|
271
|
+
end
|
272
|
+
Source.new
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
class SigAttrReaderNode < Node
|
277
|
+
def initialize(raw_decl, lenv)
|
278
|
+
super(raw_decl, lenv)
|
279
|
+
@mid = raw_decl.name
|
280
|
+
# `eval` is used to prevent TypeProf from failing to parse keyword arguments during dogfooding.
|
281
|
+
# TODO: Remove `eval` once TypeProf supports keyword arguments.
|
282
|
+
eval <<~RUBY
|
283
|
+
rbs_method_type = RBS::MethodType.new(
|
284
|
+
type: RBS::Types::Function.empty(raw_decl.type),
|
285
|
+
type_params: [],
|
286
|
+
block: nil,
|
287
|
+
location: raw_decl.type.location,
|
288
|
+
)
|
289
|
+
@method_type = AST.create_rbs_func_type(rbs_method_type, [], nil, lenv)
|
290
|
+
RUBY
|
291
|
+
end
|
292
|
+
|
293
|
+
attr_reader :mid, :method_type
|
294
|
+
|
295
|
+
def subnodes = { method_type: }
|
296
|
+
def attrs = { mid: }
|
297
|
+
|
298
|
+
def install0(genv)
|
299
|
+
@changes.add_method_decl_box(genv, @lenv.cref.cpath, false, @mid, [@method_type], false)
|
300
|
+
Source.new
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
class SigAttrWriterNode < Node
|
305
|
+
def initialize(raw_decl, lenv)
|
306
|
+
super(raw_decl, lenv)
|
307
|
+
@mid = :"#{raw_decl.name}="
|
308
|
+
|
309
|
+
# `eval` is used to prevent TypeProf from failing to parse keyword arguments during dogfooding.
|
310
|
+
# TODO: Remove `eval` once TypeProf supports keyword arguments.
|
311
|
+
eval <<~RUBY
|
312
|
+
# (raw_decl.type) -> raw_decl.type
|
313
|
+
rbs_method_type = RBS::MethodType.new(
|
314
|
+
type: RBS::Types::Function.new(
|
315
|
+
required_positionals: [RBS::Types::Function::Param.new(name: nil, type: raw_decl.type, location: raw_decl.type.location)],
|
316
|
+
optional_positionals: [],
|
317
|
+
rest_positionals: nil,
|
318
|
+
trailing_positionals: [],
|
319
|
+
required_keywords: {},
|
320
|
+
optional_keywords: {},
|
321
|
+
rest_keywords: nil,
|
322
|
+
return_type: raw_decl.type,
|
323
|
+
),
|
324
|
+
type_params: [],
|
325
|
+
block: nil,
|
326
|
+
location: raw_decl.type.location,
|
327
|
+
)
|
328
|
+
@method_type = AST.create_rbs_func_type(rbs_method_type, [], nil, lenv)
|
329
|
+
RUBY
|
330
|
+
end
|
331
|
+
|
332
|
+
attr_reader :mid, :method_type
|
333
|
+
|
334
|
+
def subnodes = { method_type: }
|
335
|
+
def attrs = { mid: }
|
336
|
+
|
337
|
+
def install0(genv)
|
338
|
+
@changes.add_method_decl_box(genv, @lenv.cref.cpath, false, @mid, [@method_type], false)
|
339
|
+
Source.new
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
class SigAttrAccessorNode < Node
|
344
|
+
def initialize(raw_decl, lenv)
|
345
|
+
super(raw_decl, lenv)
|
346
|
+
@reader = SigAttrReaderNode.new(raw_decl, lenv)
|
347
|
+
@writer = SigAttrWriterNode.new(raw_decl, lenv)
|
348
|
+
end
|
349
|
+
|
350
|
+
attr_reader :reader, :writer
|
351
|
+
|
352
|
+
def subnodes = { reader:, writer: }
|
353
|
+
|
354
|
+
def install0(genv)
|
355
|
+
@reader.install0(genv)
|
356
|
+
@writer.install0(genv)
|
357
|
+
Source.new
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
class SigConstNode < Node
|
362
|
+
def initialize(raw_decl, lenv)
|
363
|
+
super(raw_decl, lenv)
|
364
|
+
@cpath = AST.resolve_rbs_name(raw_decl.name, lenv)
|
365
|
+
@type = AST.create_rbs_type(raw_decl.type, lenv)
|
366
|
+
end
|
367
|
+
|
368
|
+
attr_reader :cpath, :type
|
369
|
+
def subnodes = { type: }
|
370
|
+
def attrs = { cpath: }
|
371
|
+
|
372
|
+
def define0(genv)
|
373
|
+
@type.define(genv)
|
374
|
+
mod = genv.resolve_const(@cpath)
|
375
|
+
mod.add_decl(self)
|
376
|
+
mod
|
377
|
+
end
|
378
|
+
|
379
|
+
def define_copy(genv)
|
380
|
+
mod = genv.resolve_const(@cpath)
|
381
|
+
mod.add_decl(self)
|
382
|
+
mod.remove_decl(@prev_node)
|
383
|
+
super(genv)
|
384
|
+
end
|
385
|
+
|
386
|
+
def undefine0(genv)
|
387
|
+
genv.resolve_const(@cpath).remove_decl(self)
|
388
|
+
@type.undefine(genv)
|
389
|
+
end
|
390
|
+
|
391
|
+
def install0(genv)
|
392
|
+
box = @changes.add_type_read_box(genv, @type)
|
393
|
+
@changes.add_edge(genv, box.ret, @static_ret.vtx)
|
394
|
+
box.ret
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
class SigTypeAliasNode < Node
|
399
|
+
def initialize(raw_decl, lenv)
|
400
|
+
super(raw_decl, lenv)
|
401
|
+
@cpath = AST.resolve_rbs_name(raw_decl.name, lenv)
|
402
|
+
@name = @cpath.pop
|
403
|
+
@type = AST.create_rbs_type(raw_decl.type, lenv)
|
404
|
+
@params = raw_decl.type_params.map {|param| param.name }
|
405
|
+
end
|
406
|
+
|
407
|
+
attr_reader :cpath, :name, :type, :params
|
408
|
+
|
409
|
+
def define0(genv)
|
410
|
+
@type.define(genv)
|
411
|
+
tae = genv.resolve_type_alias(@cpath, @name)
|
412
|
+
tae.add_decl(self)
|
413
|
+
tae
|
414
|
+
end
|
415
|
+
|
416
|
+
def define_copy(genv)
|
417
|
+
tae = genv.resolve_type_alias(@cpath, @name)
|
418
|
+
tae.add_decl(self)
|
419
|
+
tae.remove_decl(@prev_node)
|
420
|
+
super(genv)
|
421
|
+
end
|
422
|
+
|
423
|
+
def undefine0(genv)
|
424
|
+
tae = genv.resolve_type_alias(@cpath, @name)
|
425
|
+
tae.remove_decl(self)
|
426
|
+
@type.undefine(genv)
|
427
|
+
end
|
428
|
+
|
429
|
+
def install0(genv)
|
430
|
+
Source.new
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
class SigGlobalVariableNode < Node
|
435
|
+
def initialize(raw_decl, lenv)
|
436
|
+
super(raw_decl, lenv)
|
437
|
+
@var = raw_decl.name
|
438
|
+
@type = AST.create_rbs_type(raw_decl.type, lenv)
|
439
|
+
end
|
440
|
+
|
441
|
+
attr_reader :cpath, :type
|
442
|
+
def subnodes = { type: }
|
443
|
+
def attrs = { cpath: }
|
444
|
+
|
445
|
+
def define0(genv)
|
446
|
+
@type.define(genv)
|
447
|
+
mod = genv.resolve_gvar(@var)
|
448
|
+
mod.add_decl(self)
|
449
|
+
mod
|
450
|
+
end
|
451
|
+
|
452
|
+
def define_copy(genv)
|
453
|
+
mod = genv.resolve_gvar(@var)
|
454
|
+
mod.add_decl(self)
|
455
|
+
mod.remove_decl(@prev_node)
|
456
|
+
super(genv)
|
457
|
+
end
|
458
|
+
|
459
|
+
def undefine0(genv)
|
460
|
+
genv.resolve_gvar(@var).remove_decl(self)
|
461
|
+
@type.undefine(genv)
|
462
|
+
end
|
463
|
+
|
464
|
+
def install0(genv)
|
465
|
+
box = @changes.add_type_read_box(genv, @type)
|
466
|
+
@changes.add_edge(genv, box.ret, @static_ret.vtx)
|
467
|
+
box.ret
|
468
|
+
end
|
469
|
+
end
|
470
|
+
end
|
471
|
+
end
|