typeprof 0.21.11 → 0.30.1
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 +178 -0
- data/lib/typeprof/cli.rb +3 -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 +259 -0
- data/lib/typeprof/core/ast/const.rb +126 -0
- data/lib/typeprof/core/ast/control.rb +433 -0
- data/lib/typeprof/core/ast/meta.rb +150 -0
- data/lib/typeprof/core/ast/method.rb +339 -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 +366 -0
- data/lib/typeprof/core/graph/box.rb +998 -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 +225 -0
- data/lib/typeprof/core/service.rb +514 -0
- data/lib/typeprof/core/type.rb +352 -0
- data/lib/typeprof/core/util.rb +81 -0
- data/lib/typeprof/core.rb +31 -0
- data/lib/typeprof/diagnostic.rb +35 -0
- data/lib/typeprof/lsp/messages.rb +415 -0
- data/lib/typeprof/lsp/server.rb +203 -0
- data/lib/typeprof/lsp/text.rb +69 -0
- data/lib/typeprof/lsp/util.rb +51 -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 +47 -33
- 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,123 @@
|
|
1
|
+
module TypeProf::Core
|
2
|
+
class AST
|
3
|
+
class ModuleBaseNode < Node
|
4
|
+
def initialize(raw_node, lenv, raw_cpath, meta, raw_scope, use_result)
|
5
|
+
super(raw_node, lenv)
|
6
|
+
|
7
|
+
@cpath = AST.create_node(raw_cpath, lenv)
|
8
|
+
@static_cpath = AST.parse_cpath(raw_cpath, lenv.cref)
|
9
|
+
@tbl = raw_node.locals
|
10
|
+
|
11
|
+
# TODO: class Foo < Struct.new(:foo, :bar)
|
12
|
+
|
13
|
+
if @static_cpath
|
14
|
+
ncref = CRef.new(@static_cpath, meta ? :metaclass : :class, nil, lenv.cref)
|
15
|
+
nlenv = LocalEnv.new(@lenv.path, ncref, {}, [])
|
16
|
+
@body = raw_scope ? AST.create_node(raw_scope, nlenv, use_result) : DummyNilNode.new(code_range, lenv)
|
17
|
+
else
|
18
|
+
@body = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
@cname_code_range = meta ? nil : TypeProf::CodeRange.from_node(raw_node.constant_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :tbl, :cpath, :static_cpath, :cname_code_range, :body
|
25
|
+
|
26
|
+
def subnodes = { cpath:, body: }
|
27
|
+
def attrs = { static_cpath:, tbl: }
|
28
|
+
|
29
|
+
def define0(genv)
|
30
|
+
@cpath.define(genv)
|
31
|
+
if @static_cpath
|
32
|
+
@body.define(genv)
|
33
|
+
@mod = genv.resolve_cpath(@static_cpath)
|
34
|
+
@mod_cdef = @mod.add_module_def(genv, self)
|
35
|
+
else
|
36
|
+
kind = self.is_a?(ModuleNode) ? "module" : "class"
|
37
|
+
@changes.add_diagnostic(:code_range, "TypeProf cannot analyze a non-static #{ kind }") # warning
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def define_copy(genv)
|
43
|
+
if @static_cpath
|
44
|
+
@mod_cdef.add_def(self)
|
45
|
+
@mod_cdef.remove_def(@prev_node)
|
46
|
+
end
|
47
|
+
super(genv)
|
48
|
+
end
|
49
|
+
|
50
|
+
def undefine0(genv)
|
51
|
+
if @static_cpath
|
52
|
+
@mod.remove_module_def(genv, self)
|
53
|
+
@body.undefine(genv)
|
54
|
+
end
|
55
|
+
@cpath.undefine(genv)
|
56
|
+
end
|
57
|
+
|
58
|
+
def install0(genv)
|
59
|
+
@cpath.install(genv)
|
60
|
+
if @static_cpath
|
61
|
+
@tbl.each {|var| @body.lenv.locals[var] = Source.new(genv.nil_type) }
|
62
|
+
@body.lenv.locals[:"*self"] = @body.lenv.cref.get_self(genv)
|
63
|
+
|
64
|
+
@mod_val = Source.new(Type::Singleton.new(genv, genv.resolve_cpath(@static_cpath)))
|
65
|
+
@changes.add_edge(genv, @mod_val, @mod_cdef.vtx)
|
66
|
+
ret = Vertex.new(self)
|
67
|
+
@changes.add_edge(genv, @body.install(genv), ret)
|
68
|
+
ret
|
69
|
+
else
|
70
|
+
Source.new
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def modified_vars(tbl, vars)
|
75
|
+
# skip
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class ModuleNode < ModuleBaseNode
|
80
|
+
def initialize(raw_node, lenv, use_result)
|
81
|
+
super(raw_node, lenv, raw_node.constant_path, false, raw_node.body, use_result)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class ClassNode < ModuleBaseNode
|
86
|
+
def initialize(raw_node, lenv, use_result)
|
87
|
+
super(raw_node, lenv, raw_node.constant_path, false, raw_node.body, use_result)
|
88
|
+
raw_superclass = raw_node.superclass
|
89
|
+
@superclass_cpath = raw_superclass ? AST.create_node(raw_superclass, lenv) : nil
|
90
|
+
end
|
91
|
+
|
92
|
+
attr_reader :superclass_cpath
|
93
|
+
|
94
|
+
def subnodes
|
95
|
+
super.merge!({ superclass_cpath: })
|
96
|
+
end
|
97
|
+
|
98
|
+
def define0(genv)
|
99
|
+
if @static_cpath && @superclass_cpath
|
100
|
+
const = @superclass_cpath.define(genv)
|
101
|
+
const.followers << genv.resolve_cpath(@static_cpath) if const
|
102
|
+
end
|
103
|
+
super(genv)
|
104
|
+
end
|
105
|
+
|
106
|
+
def undefine0(genv)
|
107
|
+
super(genv)
|
108
|
+
@superclass_cpath.undefine(genv) if @superclass_cpath
|
109
|
+
end
|
110
|
+
|
111
|
+
def install0(genv)
|
112
|
+
@superclass_cpath.install(genv) if @superclass_cpath
|
113
|
+
super(genv)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class SingletonClassNode < ModuleBaseNode
|
118
|
+
def initialize(raw_node, lenv, use_result)
|
119
|
+
super(raw_node, lenv, raw_node.expression, true, raw_node.body, use_result)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -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
|