orbacle 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +119 -0
  8. data/LICENSE +22 -0
  9. data/Makefile +57 -0
  10. data/README.md +53 -0
  11. data/circle.yml +82 -0
  12. data/exe/orbaclerun +6 -0
  13. data/index.html +106 -0
  14. data/lib/orbacle.rb +96 -0
  15. data/lib/orbacle/ast_utils.rb +35 -0
  16. data/lib/orbacle/bottom_type.rb +23 -0
  17. data/lib/orbacle/builder.rb +1414 -0
  18. data/lib/orbacle/builder/context.rb +71 -0
  19. data/lib/orbacle/builder/operator_assignment_processors.rb +80 -0
  20. data/lib/orbacle/class_type.rb +32 -0
  21. data/lib/orbacle/command_line_interface.rb +107 -0
  22. data/lib/orbacle/const_name.rb +33 -0
  23. data/lib/orbacle/const_ref.rb +53 -0
  24. data/lib/orbacle/constants_tree.rb +73 -0
  25. data/lib/orbacle/define_builtins.rb +139 -0
  26. data/lib/orbacle/engine.rb +74 -0
  27. data/lib/orbacle/find_definition_under_position.rb +76 -0
  28. data/lib/orbacle/generic_type.rb +35 -0
  29. data/lib/orbacle/global_tree.rb +280 -0
  30. data/lib/orbacle/graph.rb +126 -0
  31. data/lib/orbacle/indexer.rb +151 -0
  32. data/lib/orbacle/integer_id_generator.rb +13 -0
  33. data/lib/orbacle/lambda_type.rb +37 -0
  34. data/lib/orbacle/lang_server.rb +64 -0
  35. data/lib/orbacle/main_type.rb +23 -0
  36. data/lib/orbacle/nesting.rb +78 -0
  37. data/lib/orbacle/node.rb +23 -0
  38. data/lib/orbacle/nominal_type.rb +32 -0
  39. data/lib/orbacle/ruby_parser.rb +19 -0
  40. data/lib/orbacle/scope.rb +63 -0
  41. data/lib/orbacle/selfie.rb +41 -0
  42. data/lib/orbacle/type_pretty_printer.rb +24 -0
  43. data/lib/orbacle/typing_service.rb +816 -0
  44. data/lib/orbacle/union_type.rb +40 -0
  45. data/lib/orbacle/uuid_id_generator.rb +11 -0
  46. data/lib/orbacle/worklist.rb +51 -0
  47. data/orbacle.gemspec +33 -0
  48. metadata +258 -0
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orbacle
4
+ class UnionType
5
+ def initialize(types)
6
+ @types_set = Set.new(types)
7
+ end
8
+
9
+ attr_reader :types_set
10
+
11
+ def types
12
+ @types_set
13
+ end
14
+
15
+ def ==(other)
16
+ self.class == other.class &&
17
+ self.types_set == other.types_set
18
+ end
19
+
20
+ def hash
21
+ [
22
+ self.class,
23
+ self.types_set,
24
+ ].hash ^ BIG_VALUE
25
+ end
26
+ alias eql? ==
27
+
28
+ def each_possible_type
29
+ types.each do |type|
30
+ type.each_possible_type do |t|
31
+ yield t
32
+ end
33
+ end
34
+ end
35
+
36
+ def bottom?
37
+ false
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ module Orbacle
6
+ class UuidIdGenerator
7
+ def call
8
+ SecureRandom.uuid
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fc'
4
+
5
+ module Orbacle
6
+ class Worklist
7
+ BlockNode = Struct.new(:node)
8
+ BlockLambda = Struct.new(:lambda_id)
9
+ MessageSend = Struct.new(:message_send, :send_obj, :send_args, :send_result, :block, :location)
10
+ SuperSend = Struct.new(:send_args, :send_result, :block, :method_id, :location)
11
+
12
+ def initialize
13
+ @message_sends = Set.new
14
+ @nodes = FastContainers::PriorityQueue.new(:max)
15
+ @handled_message_sends = Set.new
16
+ @nodes_counter = {}
17
+ end
18
+
19
+ attr_reader :message_sends, :nodes, :handled_message_sends
20
+ attr_writer :nodes
21
+
22
+ def add_message_send(message_send)
23
+ @message_sends << message_send
24
+ end
25
+
26
+ def enqueue_node(v)
27
+ @nodes.push(v, 1)
28
+ end
29
+
30
+ def pop_node
31
+ @nodes.pop
32
+ end
33
+
34
+ def count_node(node)
35
+ @nodes_counter[node] = @nodes_counter.fetch(node, 0) + 1
36
+ end
37
+
38
+ def limit_exceeded?(node)
39
+ # @nodes_counter.fetch(node, 0) > 100
40
+ false
41
+ end
42
+
43
+ def message_send_handled?(message_send)
44
+ handled_message_sends.include?(message_send)
45
+ end
46
+
47
+ def mark_message_send_as_handled(message_send)
48
+ handled_message_sends << message_send
49
+ end
50
+ end
51
+ end
data/orbacle.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'orbacle'
7
+ spec.version = '0.1.0'
8
+ spec.licenses = ['MIT']
9
+ spec.authors = ['Rafał Łasocha']
10
+ spec.email = 'orbacle@swistak35.com'
11
+
12
+ spec.summary = "Static analysis for Ruby"
13
+ spec.description = "A simple hello world gem"
14
+ spec.homepage = 'https://github.com/swistak35/orbacle'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|script)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'priority_queue_cxx'
22
+ spec.add_dependency 'lsp-protocol', '>= 0.0.3'
23
+ spec.add_dependency 'parser', '~> 2.4.0.2'
24
+ spec.add_dependency 'rubytree', '~> 0.9.7'
25
+ spec.add_dependency 'rgl', '~> 0.5.3'
26
+ spec.add_development_dependency 'bundler', '~> 1.9'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'byebug'
29
+ spec.add_development_dependency 'hash_diff', '~> 0.6.2'
30
+ spec.add_development_dependency 'nokogiri', '>= 1.8.4'
31
+ spec.add_development_dependency 'mutant-rspec'
32
+ spec.add_development_dependency 'ruby-prof'
33
+ end
metadata ADDED
@@ -0,0 +1,258 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orbacle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rafał Łasocha
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: priority_queue_cxx
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: lsp-protocol
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: parser
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.4.0.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.4.0.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubytree
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.7
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.7
69
+ - !ruby/object:Gem::Dependency
70
+ name: rgl
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.5.3
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.5.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: hash_diff
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.6.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.6.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: nokogiri
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 1.8.4
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 1.8.4
153
+ - !ruby/object:Gem::Dependency
154
+ name: mutant-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: ruby-prof
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: A simple hello world gem
182
+ email: orbacle@swistak35.com
183
+ executables:
184
+ - orbaclerun
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rspec"
190
+ - ".ruby-version"
191
+ - CHANGELOG.md
192
+ - Gemfile
193
+ - Gemfile.lock
194
+ - LICENSE
195
+ - Makefile
196
+ - README.md
197
+ - circle.yml
198
+ - exe/orbaclerun
199
+ - index.html
200
+ - lib/orbacle.rb
201
+ - lib/orbacle/ast_utils.rb
202
+ - lib/orbacle/bottom_type.rb
203
+ - lib/orbacle/builder.rb
204
+ - lib/orbacle/builder/context.rb
205
+ - lib/orbacle/builder/operator_assignment_processors.rb
206
+ - lib/orbacle/class_type.rb
207
+ - lib/orbacle/command_line_interface.rb
208
+ - lib/orbacle/const_name.rb
209
+ - lib/orbacle/const_ref.rb
210
+ - lib/orbacle/constants_tree.rb
211
+ - lib/orbacle/define_builtins.rb
212
+ - lib/orbacle/engine.rb
213
+ - lib/orbacle/find_definition_under_position.rb
214
+ - lib/orbacle/generic_type.rb
215
+ - lib/orbacle/global_tree.rb
216
+ - lib/orbacle/graph.rb
217
+ - lib/orbacle/indexer.rb
218
+ - lib/orbacle/integer_id_generator.rb
219
+ - lib/orbacle/lambda_type.rb
220
+ - lib/orbacle/lang_server.rb
221
+ - lib/orbacle/main_type.rb
222
+ - lib/orbacle/nesting.rb
223
+ - lib/orbacle/node.rb
224
+ - lib/orbacle/nominal_type.rb
225
+ - lib/orbacle/ruby_parser.rb
226
+ - lib/orbacle/scope.rb
227
+ - lib/orbacle/selfie.rb
228
+ - lib/orbacle/type_pretty_printer.rb
229
+ - lib/orbacle/typing_service.rb
230
+ - lib/orbacle/union_type.rb
231
+ - lib/orbacle/uuid_id_generator.rb
232
+ - lib/orbacle/worklist.rb
233
+ - orbacle.gemspec
234
+ homepage: https://github.com/swistak35/orbacle
235
+ licenses:
236
+ - MIT
237
+ metadata: {}
238
+ post_install_message:
239
+ rdoc_options: []
240
+ require_paths:
241
+ - lib
242
+ required_ruby_version: !ruby/object:Gem::Requirement
243
+ requirements:
244
+ - - ">="
245
+ - !ruby/object:Gem::Version
246
+ version: '0'
247
+ required_rubygems_version: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - ">="
250
+ - !ruby/object:Gem::Version
251
+ version: '0'
252
+ requirements: []
253
+ rubyforge_project:
254
+ rubygems_version: 2.7.6
255
+ signing_key:
256
+ specification_version: 4
257
+ summary: Static analysis for Ruby
258
+ test_files: []