rubydex 0.1.0.beta2-x86_64-linux → 0.1.0.beta3-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/THIRD_PARTY_LICENSES.html +25 -2
- data/ext/rubydex/declaration.c +148 -9
- data/ext/rubydex/declaration.h +12 -0
- data/ext/rubydex/definition.c +0 -41
- data/ext/rubydex/document.c +2 -2
- data/ext/rubydex/extconf.rb +1 -1
- data/ext/rubydex/graph.c +48 -41
- data/ext/rubydex/handle.h +2 -2
- data/ext/rubydex/utils.c +25 -0
- data/ext/rubydex/utils.h +6 -0
- data/lib/rubydex/3.2/rubydex.so +0 -0
- data/lib/rubydex/3.3/rubydex.so +0 -0
- data/lib/rubydex/3.4/rubydex.so +0 -0
- data/lib/rubydex/4.0/rubydex.so +0 -0
- data/lib/rubydex/librubydex_sys.so +0 -0
- data/lib/rubydex/version.rb +1 -1
- data/rust/Cargo.lock +27 -5
- data/rust/about.toml +1 -0
- data/rust/rubydex/Cargo.toml +2 -1
- data/rust/rubydex/src/compile_assertions.rs +13 -0
- data/rust/rubydex/src/indexing/local_graph.rs +21 -4
- data/rust/rubydex/src/indexing/ruby_indexer.rs +1241 -598
- data/rust/rubydex/src/lib.rs +1 -0
- data/rust/rubydex/src/listing.rs +3 -3
- data/rust/rubydex/src/model/declaration.rs +25 -4
- data/rust/rubydex/src/model/definitions.rs +19 -40
- data/rust/rubydex/src/model/document.rs +141 -0
- data/rust/rubydex/src/model/graph.rs +241 -123
- data/rust/rubydex/src/model/id.rs +10 -16
- data/rust/rubydex/src/model/identity_maps.rs +4 -0
- data/rust/rubydex/src/model/ids.rs +7 -1
- data/rust/rubydex/src/model/name.rs +131 -26
- data/rust/rubydex/src/model/references.rs +18 -36
- data/rust/rubydex/src/model/string_ref.rs +10 -4
- data/rust/rubydex/src/query.rs +177 -2
- data/rust/rubydex/src/resolution.rs +499 -688
- data/rust/rubydex/src/test_utils/graph_test.rs +404 -111
- data/rust/rubydex/src/visualization/dot.rs +1 -1
- data/rust/rubydex-sys/src/declaration_api.rs +240 -13
- data/rust/rubydex-sys/src/definition_api.rs +10 -10
- data/rust/rubydex-sys/src/document_api.rs +4 -4
- data/rust/rubydex-sys/src/graph_api.rs +92 -66
- data/rust/rubydex-sys/src/name_api.rs +64 -10
- data/rust/rubydex-sys/src/reference_api.rs +7 -7
- data/rust/rubydex-sys/src/utils.rs +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2de40c7335743a85b7d61d9a513d40b29fcecf62e19cfff8ef2637cd4297b6a8
|
|
4
|
+
data.tar.gz: 99bed4d413ab7e1bd97f76965906037d1da29f12af8dba7f19f48d5665c73bc5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 29ef5b84c94af6eb1608d42acbc7a0c5c115fef6317645b369fca27c1c1714c64a21dba7a1b10f490939fbf547583fbed20db30d26e9ad4f42b9c8079c8b7e6c
|
|
7
|
+
data.tar.gz: e4d9dce9acf24ef5c704dab14d89a82143c39e259e8923fc71830abe600b54240094a8e287aa647b62e419fac42db6e1c3f4b59d20b29498d1b5872865083dd5
|
data/THIRD_PARTY_LICENSES.html
CHANGED
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
<li><a href="#Apache-2.0">Apache License 2.0</a> (106)</li>
|
|
54
54
|
<li><a href="#Unicode-3.0">Unicode License v3</a> (19)</li>
|
|
55
55
|
<li><a href="#MIT">MIT License</a> (15)</li>
|
|
56
|
+
<li><a href="#BSD-2-Clause">BSD 2-Clause "Simplified" License</a> (2)</li>
|
|
56
57
|
<li><a href="#BSD-3-Clause">BSD 3-Clause "New" or "Revised" License</a> (1)</li>
|
|
57
58
|
<li><a href="#BSL-1.0">Boost Software License 1.0</a> (1)</li>
|
|
58
59
|
<li><a href="#ISC">ISC License</a> (1)</li>
|
|
@@ -2332,6 +2333,28 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
2332
2333
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2333
2334
|
See the License for the specific language governing permissions and
|
|
2334
2335
|
limitations under the License.
|
|
2336
|
+
</pre>
|
|
2337
|
+
</li>
|
|
2338
|
+
<li class="license">
|
|
2339
|
+
<h3 id="BSD-2-Clause">BSD 2-Clause "Simplified" License</h3>
|
|
2340
|
+
<h4>Used by:</h4>
|
|
2341
|
+
<ul class="license-used-by">
|
|
2342
|
+
<li><a
|
|
2343
|
+
href=" https://github.com/ruby/rbs.git ">ruby-rbs-sys
|
|
2344
|
+
0.1.1</a></li>
|
|
2345
|
+
<li><a
|
|
2346
|
+
href=" https://github.com/ruby/rbs.git ">ruby-rbs
|
|
2347
|
+
0.1.1</a></li>
|
|
2348
|
+
</ul>
|
|
2349
|
+
<pre class="license-text">Copyright (c) <year> <owner>
|
|
2350
|
+
|
|
2351
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
2352
|
+
|
|
2353
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
2354
|
+
|
|
2355
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
2356
|
+
|
|
2357
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2335
2358
|
</pre>
|
|
2336
2359
|
</li>
|
|
2337
2360
|
<li class="license">
|
|
@@ -2539,10 +2562,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRES
|
|
|
2539
2562
|
<ul class="license-used-by">
|
|
2540
2563
|
<li><a
|
|
2541
2564
|
href=" https://github.com/ruby/prism ">ruby-prism-sys
|
|
2542
|
-
1.
|
|
2565
|
+
1.9.0</a></li>
|
|
2543
2566
|
<li><a
|
|
2544
2567
|
href=" https://github.com/ruby/prism ">ruby-prism
|
|
2545
|
-
1.
|
|
2568
|
+
1.9.0</a></li>
|
|
2546
2569
|
</ul>
|
|
2547
2570
|
<pre class="license-text">Copyright 2022-present, Shopify Inc.
|
|
2548
2571
|
|
data/ext/rubydex/declaration.c
CHANGED
|
@@ -3,8 +3,45 @@
|
|
|
3
3
|
#include "graph.h"
|
|
4
4
|
#include "handle.h"
|
|
5
5
|
#include "rustbindings.h"
|
|
6
|
+
#include "utils.h"
|
|
6
7
|
|
|
7
8
|
VALUE cDeclaration;
|
|
9
|
+
VALUE cNamespace;
|
|
10
|
+
VALUE cClass;
|
|
11
|
+
VALUE cModule;
|
|
12
|
+
VALUE cSingletonClass;
|
|
13
|
+
VALUE cConstant;
|
|
14
|
+
VALUE cConstantAlias;
|
|
15
|
+
VALUE cMethod;
|
|
16
|
+
VALUE cGlobalVariable;
|
|
17
|
+
VALUE cInstanceVariable;
|
|
18
|
+
VALUE cClassVariable;
|
|
19
|
+
|
|
20
|
+
// Keep this in sync with declaration_api.rs
|
|
21
|
+
VALUE rdxi_declaration_class_for_kind(CDeclarationKind kind) {
|
|
22
|
+
switch (kind) {
|
|
23
|
+
case CDeclarationKind_Class:
|
|
24
|
+
return cClass;
|
|
25
|
+
case CDeclarationKind_Module:
|
|
26
|
+
return cModule;
|
|
27
|
+
case CDeclarationKind_SingletonClass:
|
|
28
|
+
return cSingletonClass;
|
|
29
|
+
case CDeclarationKind_Constant:
|
|
30
|
+
return cConstant;
|
|
31
|
+
case CDeclarationKind_ConstantAlias:
|
|
32
|
+
return cConstantAlias;
|
|
33
|
+
case CDeclarationKind_Method:
|
|
34
|
+
return cMethod;
|
|
35
|
+
case CDeclarationKind_GlobalVariable:
|
|
36
|
+
return cGlobalVariable;
|
|
37
|
+
case CDeclarationKind_InstanceVariable:
|
|
38
|
+
return cInstanceVariable;
|
|
39
|
+
case CDeclarationKind_ClassVariable:
|
|
40
|
+
return cClassVariable;
|
|
41
|
+
default:
|
|
42
|
+
rb_raise(rb_eRuntimeError, "Unknown CDeclarationKind: %d", kind);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
8
45
|
|
|
9
46
|
// Declaration#name -> String
|
|
10
47
|
static VALUE rdxr_declaration_name(VALUE self) {
|
|
@@ -52,10 +89,10 @@ static VALUE declaration_definitions_yield(VALUE args) {
|
|
|
52
89
|
HandleData *data;
|
|
53
90
|
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
54
91
|
|
|
55
|
-
|
|
92
|
+
uint64_t id = 0;
|
|
56
93
|
DefinitionKind kind;
|
|
57
94
|
while (rdx_definitions_iter_next(iter, &id, &kind)) {
|
|
58
|
-
VALUE argv[] = {data->graph_obj,
|
|
95
|
+
VALUE argv[] = {data->graph_obj, ULL2NUM(id)};
|
|
59
96
|
VALUE defn_class = rdxi_definition_class_for_kind(kind);
|
|
60
97
|
VALUE handle = rb_class_new_instance(2, argv, defn_class);
|
|
61
98
|
rb_yield(handle);
|
|
@@ -120,27 +157,129 @@ static VALUE rdxr_declaration_member(VALUE self, VALUE name) {
|
|
|
120
157
|
rb_raise(rb_eTypeError, "expected String");
|
|
121
158
|
}
|
|
122
159
|
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
160
|
+
const CDeclaration *decl = rdx_declaration_member(graph, data->id, StringValueCStr(name));
|
|
161
|
+
if (decl == NULL) {
|
|
162
|
+
return Qnil;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
VALUE decl_class = rdxi_declaration_class_for_kind(decl->kind);
|
|
166
|
+
VALUE argv[] = {data->graph_obj, ULL2NUM(decl->id)};
|
|
167
|
+
free_c_declaration(decl);
|
|
168
|
+
|
|
169
|
+
return rb_class_new_instance(2, argv, decl_class);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Declaration#singleton_class -> SingletonClass
|
|
173
|
+
static VALUE rdxr_declaration_singleton_class(VALUE self) {
|
|
174
|
+
HandleData *data;
|
|
175
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
176
|
+
|
|
177
|
+
void *graph;
|
|
178
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
179
|
+
const CDeclaration *decl = rdx_declaration_singleton_class(graph, data->id);
|
|
180
|
+
|
|
181
|
+
if (decl == NULL) {
|
|
125
182
|
return Qnil;
|
|
126
183
|
}
|
|
127
184
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
185
|
+
VALUE decl_class = rdxi_declaration_class_for_kind(decl->kind);
|
|
186
|
+
VALUE argv[] = {data->graph_obj, ULL2NUM(decl->id)};
|
|
187
|
+
free_c_declaration(decl);
|
|
188
|
+
|
|
189
|
+
return rb_class_new_instance(2, argv, decl_class);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Declaration#owner -> Declaration
|
|
193
|
+
static VALUE rdxr_declaration_owner(VALUE self) {
|
|
194
|
+
HandleData *data;
|
|
195
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
196
|
+
|
|
197
|
+
void *graph;
|
|
198
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
199
|
+
const CDeclaration *decl = rdx_declaration_owner(graph, data->id);
|
|
200
|
+
|
|
201
|
+
if (decl == NULL) {
|
|
202
|
+
rb_raise(rb_eRuntimeError, "owner can never be nil for any declarations");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
VALUE decl_class = rdxi_declaration_class_for_kind(decl->kind);
|
|
206
|
+
VALUE argv[] = {data->graph_obj, ULL2NUM(decl->id)};
|
|
207
|
+
free_c_declaration(decl);
|
|
208
|
+
|
|
209
|
+
return rb_class_new_instance(2, argv, decl_class);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Declaration#ancestors: () -> Enumerator[Declaration]
|
|
213
|
+
static VALUE rdxr_declaration_ancestors(VALUE self) {
|
|
214
|
+
if (!rb_block_given_p()) {
|
|
215
|
+
return rb_enumeratorize(self, rb_str_new2("ancestors"), 0, NULL);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
HandleData *data;
|
|
219
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
220
|
+
|
|
221
|
+
void *graph;
|
|
222
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
223
|
+
|
|
224
|
+
void *iter = rdx_declaration_ancestors(graph, data->id);
|
|
225
|
+
if (iter == NULL) {
|
|
226
|
+
rb_raise(rb_eRuntimeError, "failed to create iterator");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
|
|
230
|
+
rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
|
|
231
|
+
|
|
232
|
+
return self;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Declaration#descendants: () -> Enumerator[Declaration]
|
|
236
|
+
static VALUE rdxr_declaration_descendants(VALUE self) {
|
|
237
|
+
if (!rb_block_given_p()) {
|
|
238
|
+
return rb_enumeratorize(self, rb_str_new2("descendants"), 0, NULL);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
HandleData *data;
|
|
242
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
243
|
+
|
|
244
|
+
void *graph;
|
|
245
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
246
|
+
|
|
247
|
+
void *iter = rdx_declaration_descendants(graph, data->id);
|
|
248
|
+
if (iter == NULL) {
|
|
249
|
+
rb_raise(rb_eRuntimeError, "failed to create iterator");
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
|
|
253
|
+
rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
|
|
131
254
|
|
|
132
|
-
return
|
|
255
|
+
return self;
|
|
133
256
|
}
|
|
134
257
|
|
|
135
258
|
void rdxi_initialize_declaration(VALUE mRubydex) {
|
|
136
259
|
cDeclaration = rb_define_class_under(mRubydex, "Declaration", rb_cObject);
|
|
260
|
+
cNamespace = rb_define_class_under(mRubydex, "Namespace", cDeclaration);
|
|
261
|
+
cClass = rb_define_class_under(mRubydex, "Class", cNamespace);
|
|
262
|
+
cModule = rb_define_class_under(mRubydex, "Module", cNamespace);
|
|
263
|
+
cSingletonClass = rb_define_class_under(mRubydex, "SingletonClass", cNamespace);
|
|
264
|
+
cConstant = rb_define_class_under(mRubydex, "Constant", cDeclaration);
|
|
265
|
+
cConstantAlias = rb_define_class_under(mRubydex, "ConstantAlias", cDeclaration);
|
|
266
|
+
cMethod = rb_define_class_under(mRubydex, "Method", cDeclaration);
|
|
267
|
+
cGlobalVariable = rb_define_class_under(mRubydex, "GlobalVariable", cDeclaration);
|
|
268
|
+
cInstanceVariable = rb_define_class_under(mRubydex, "InstanceVariable", cDeclaration);
|
|
269
|
+
cClassVariable = rb_define_class_under(mRubydex, "ClassVariable", cDeclaration);
|
|
137
270
|
|
|
138
271
|
rb_define_alloc_func(cDeclaration, rdxr_handle_alloc);
|
|
139
272
|
rb_define_method(cDeclaration, "initialize", rdxr_handle_initialize, 2);
|
|
140
273
|
rb_define_method(cDeclaration, "name", rdxr_declaration_name, 0);
|
|
141
274
|
rb_define_method(cDeclaration, "unqualified_name", rdxr_declaration_unqualified_name, 0);
|
|
142
275
|
rb_define_method(cDeclaration, "definitions", rdxr_declaration_definitions, 0);
|
|
143
|
-
rb_define_method(cDeclaration, "
|
|
276
|
+
rb_define_method(cDeclaration, "owner", rdxr_declaration_owner, 0);
|
|
277
|
+
|
|
278
|
+
// Namespace only methods
|
|
279
|
+
rb_define_method(cNamespace, "member", rdxr_declaration_member, 1);
|
|
280
|
+
rb_define_method(cNamespace, "singleton_class", rdxr_declaration_singleton_class, 0);
|
|
281
|
+
rb_define_method(cNamespace, "ancestors", rdxr_declaration_ancestors, 0);
|
|
282
|
+
rb_define_method(cNamespace, "descendants", rdxr_declaration_descendants, 0);
|
|
144
283
|
|
|
145
284
|
rb_funcall(rb_singleton_class(cDeclaration), rb_intern("private"), 1, ID2SYM(rb_intern("new")));
|
|
146
285
|
}
|
data/ext/rubydex/declaration.h
CHANGED
|
@@ -2,9 +2,21 @@
|
|
|
2
2
|
#define RUBYDEX_DECLARATION_H
|
|
3
3
|
|
|
4
4
|
#include "ruby.h"
|
|
5
|
+
#include "rustbindings.h"
|
|
5
6
|
|
|
6
7
|
extern VALUE cDeclaration;
|
|
8
|
+
extern VALUE cNamespace;
|
|
9
|
+
extern VALUE cClass;
|
|
10
|
+
extern VALUE cModule;
|
|
11
|
+
extern VALUE cSingletonClass;
|
|
12
|
+
extern VALUE cConstant;
|
|
13
|
+
extern VALUE cConstantAlias;
|
|
14
|
+
extern VALUE cMethod;
|
|
15
|
+
extern VALUE cGlobalVariable;
|
|
16
|
+
extern VALUE cInstanceVariable;
|
|
17
|
+
extern VALUE cClassVariable;
|
|
7
18
|
|
|
19
|
+
VALUE rdxi_declaration_class_for_kind(CDeclarationKind kind);
|
|
8
20
|
void rdxi_initialize_declaration(VALUE mRubydex);
|
|
9
21
|
|
|
10
22
|
#endif // RUBYDEX_DECLARATION_H
|
data/ext/rubydex/definition.c
CHANGED
|
@@ -177,58 +177,17 @@ void rdxi_initialize_definition(VALUE mod) {
|
|
|
177
177
|
rb_define_method(cDefinition, "name_location", rdxr_definition_name_location, 0);
|
|
178
178
|
|
|
179
179
|
cClassDefinition = rb_define_class_under(mRubydex, "ClassDefinition", cDefinition);
|
|
180
|
-
rb_define_alloc_func(cClassDefinition, rdxr_handle_alloc);
|
|
181
|
-
rb_define_method(cClassDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
182
|
-
|
|
183
180
|
cSingletonClassDefinition = rb_define_class_under(mRubydex, "SingletonClassDefinition", cDefinition);
|
|
184
|
-
rb_define_alloc_func(cSingletonClassDefinition, rdxr_handle_alloc);
|
|
185
|
-
rb_define_method(cSingletonClassDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
186
|
-
|
|
187
181
|
cModuleDefinition = rb_define_class_under(mRubydex, "ModuleDefinition", cDefinition);
|
|
188
|
-
rb_define_alloc_func(cModuleDefinition, rdxr_handle_alloc);
|
|
189
|
-
rb_define_method(cModuleDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
190
|
-
|
|
191
182
|
cConstantDefinition = rb_define_class_under(mRubydex, "ConstantDefinition", cDefinition);
|
|
192
|
-
rb_define_alloc_func(cConstantDefinition, rdxr_handle_alloc);
|
|
193
|
-
rb_define_method(cConstantDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
194
|
-
|
|
195
183
|
cConstantAliasDefinition = rb_define_class_under(mRubydex, "ConstantAliasDefinition", cDefinition);
|
|
196
|
-
rb_define_alloc_func(cConstantAliasDefinition, rdxr_handle_alloc);
|
|
197
|
-
rb_define_method(cConstantAliasDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
198
|
-
|
|
199
184
|
cMethodDefinition = rb_define_class_under(mRubydex, "MethodDefinition", cDefinition);
|
|
200
|
-
rb_define_alloc_func(cMethodDefinition, rdxr_handle_alloc);
|
|
201
|
-
rb_define_method(cMethodDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
202
|
-
|
|
203
185
|
cAttrAccessorDefinition = rb_define_class_under(mRubydex, "AttrAccessorDefinition", cDefinition);
|
|
204
|
-
rb_define_alloc_func(cAttrAccessorDefinition, rdxr_handle_alloc);
|
|
205
|
-
rb_define_method(cAttrAccessorDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
206
|
-
|
|
207
186
|
cAttrReaderDefinition = rb_define_class_under(mRubydex, "AttrReaderDefinition", cDefinition);
|
|
208
|
-
rb_define_alloc_func(cAttrReaderDefinition, rdxr_handle_alloc);
|
|
209
|
-
rb_define_method(cAttrReaderDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
210
|
-
|
|
211
187
|
cAttrWriterDefinition = rb_define_class_under(mRubydex, "AttrWriterDefinition", cDefinition);
|
|
212
|
-
rb_define_alloc_func(cAttrWriterDefinition, rdxr_handle_alloc);
|
|
213
|
-
rb_define_method(cAttrWriterDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
214
|
-
|
|
215
188
|
cGlobalVariableDefinition = rb_define_class_under(mRubydex, "GlobalVariableDefinition", cDefinition);
|
|
216
|
-
rb_define_alloc_func(cGlobalVariableDefinition, rdxr_handle_alloc);
|
|
217
|
-
rb_define_method(cGlobalVariableDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
218
|
-
|
|
219
189
|
cInstanceVariableDefinition = rb_define_class_under(mRubydex, "InstanceVariableDefinition", cDefinition);
|
|
220
|
-
rb_define_alloc_func(cInstanceVariableDefinition, rdxr_handle_alloc);
|
|
221
|
-
rb_define_method(cInstanceVariableDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
222
|
-
|
|
223
190
|
cClassVariableDefinition = rb_define_class_under(mRubydex, "ClassVariableDefinition", cDefinition);
|
|
224
|
-
rb_define_alloc_func(cClassVariableDefinition, rdxr_handle_alloc);
|
|
225
|
-
rb_define_method(cClassVariableDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
226
|
-
|
|
227
191
|
cMethodAliasDefinition = rb_define_class_under(mRubydex, "MethodAliasDefinition", cDefinition);
|
|
228
|
-
rb_define_alloc_func(cMethodAliasDefinition, rdxr_handle_alloc);
|
|
229
|
-
rb_define_method(cMethodAliasDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
230
|
-
|
|
231
192
|
cGlobalVariableAliasDefinition = rb_define_class_under(mRubydex, "GlobalVariableAliasDefinition", cDefinition);
|
|
232
|
-
rb_define_alloc_func(cGlobalVariableAliasDefinition, rdxr_handle_alloc);
|
|
233
|
-
rb_define_method(cGlobalVariableAliasDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
234
193
|
}
|
data/ext/rubydex/document.c
CHANGED
|
@@ -33,10 +33,10 @@ static VALUE document_definitions_yield(VALUE args) {
|
|
|
33
33
|
HandleData *data;
|
|
34
34
|
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
uint64_t id = 0;
|
|
37
37
|
DefinitionKind kind;
|
|
38
38
|
while (rdx_definitions_iter_next(iter, &id, &kind)) {
|
|
39
|
-
VALUE argv[] = {data->graph_obj,
|
|
39
|
+
VALUE argv[] = {data->graph_obj, ULL2NUM(id)};
|
|
40
40
|
VALUE defn_class = rdxi_definition_class_for_kind(kind);
|
|
41
41
|
VALUE handle = rb_class_new_instance(2, argv, defn_class);
|
|
42
42
|
rb_yield(handle);
|
data/ext/rubydex/extconf.rb
CHANGED
|
@@ -56,7 +56,7 @@ end
|
|
|
56
56
|
create_makefile("rubydex/rubydex")
|
|
57
57
|
|
|
58
58
|
cargo_command = if ENV["SANITIZER"]
|
|
59
|
-
ENV["RUSTFLAGS"] = "-Zsanitizer=#{ENV["SANITIZER"]}"
|
|
59
|
+
ENV["RUSTFLAGS"] = "-Zsanitizer=#{ENV["SANITIZER"]} -C target-cpu=x86-64-v3"
|
|
60
60
|
"cargo +nightly build -Zbuild-std #{cargo_args.join(" ")}".strip
|
|
61
61
|
else
|
|
62
62
|
"cargo build #{cargo_args.join(" ")}".strip
|
data/ext/rubydex/graph.c
CHANGED
|
@@ -58,29 +58,6 @@ static VALUE rdxr_graph_index_all(VALUE self, VALUE file_paths) {
|
|
|
58
58
|
return Qnil;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
// Body function for rb_ensure in Graph#declarations
|
|
62
|
-
static VALUE graph_declarations_yield(VALUE args) {
|
|
63
|
-
VALUE self = rb_ary_entry(args, 0);
|
|
64
|
-
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
65
|
-
|
|
66
|
-
int64_t id = 0;
|
|
67
|
-
while (rdx_graph_declarations_iter_next(iter, &id)) {
|
|
68
|
-
VALUE argv[] = {self, LL2NUM(id)};
|
|
69
|
-
VALUE handle = rb_class_new_instance(2, argv, cDeclaration);
|
|
70
|
-
rb_yield(handle);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return Qnil;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Ensure function for rb_ensure in Graph#declarations to always free the iterator
|
|
77
|
-
static VALUE graph_declarations_ensure(VALUE args) {
|
|
78
|
-
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
79
|
-
rdx_graph_declarations_iter_free(iter);
|
|
80
|
-
|
|
81
|
-
return Qnil;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
61
|
// Size function for the declarations enumerator
|
|
85
62
|
static VALUE graph_declarations_size(VALUE self, VALUE _args, VALUE _eobj) {
|
|
86
63
|
void *graph;
|
|
@@ -105,7 +82,7 @@ static VALUE rdxr_graph_declarations(VALUE self) {
|
|
|
105
82
|
|
|
106
83
|
void *iter = rdx_graph_declarations_iter_new(graph);
|
|
107
84
|
VALUE args = rb_ary_new_from_args(2, self, ULL2NUM((uintptr_t)iter));
|
|
108
|
-
rb_ensure(
|
|
85
|
+
rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
|
|
109
86
|
|
|
110
87
|
return self;
|
|
111
88
|
}
|
|
@@ -131,7 +108,7 @@ static VALUE rdxr_graph_search(VALUE self, VALUE query) {
|
|
|
131
108
|
}
|
|
132
109
|
|
|
133
110
|
VALUE args = rb_ary_new_from_args(2, self, ULL2NUM((uintptr_t)iter));
|
|
134
|
-
rb_ensure(
|
|
111
|
+
rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
|
|
135
112
|
|
|
136
113
|
return self;
|
|
137
114
|
}
|
|
@@ -141,9 +118,9 @@ static VALUE graph_documents_yield(VALUE args) {
|
|
|
141
118
|
VALUE self = rb_ary_entry(args, 0);
|
|
142
119
|
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
143
120
|
|
|
144
|
-
|
|
121
|
+
uint64_t id = 0;
|
|
145
122
|
while (rdx_graph_documents_iter_next(iter, &id)) {
|
|
146
|
-
VALUE argv[] = {self,
|
|
123
|
+
VALUE argv[] = {self, ULL2NUM(id)};
|
|
147
124
|
VALUE handle = rb_class_new_instance(2, argv, cDocument);
|
|
148
125
|
rb_yield(handle);
|
|
149
126
|
}
|
|
@@ -198,16 +175,16 @@ static VALUE rdxr_graph_aref(VALUE self, VALUE key) {
|
|
|
198
175
|
rb_raise(rb_eTypeError, "expected String");
|
|
199
176
|
}
|
|
200
177
|
|
|
201
|
-
const
|
|
202
|
-
if (
|
|
178
|
+
const CDeclaration *decl = rdx_graph_get_declaration(graph, StringValueCStr(key));
|
|
179
|
+
if (decl == NULL) {
|
|
203
180
|
return Qnil;
|
|
204
181
|
}
|
|
205
182
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
183
|
+
VALUE decl_class = rdxi_declaration_class_for_kind(decl->kind);
|
|
184
|
+
VALUE argv[] = {self, ULL2NUM(decl->id)};
|
|
185
|
+
free_c_declaration(decl);
|
|
209
186
|
|
|
210
|
-
return rb_class_new_instance(2, argv,
|
|
187
|
+
return rb_class_new_instance(2, argv, decl_class);
|
|
211
188
|
}
|
|
212
189
|
|
|
213
190
|
// Body function for rb_ensure for the reference enumerators
|
|
@@ -215,11 +192,11 @@ static VALUE graph_references_yield(VALUE args) {
|
|
|
215
192
|
VALUE self = rb_ary_entry(args, 0);
|
|
216
193
|
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
217
194
|
|
|
218
|
-
|
|
195
|
+
uint64_t id = 0;
|
|
219
196
|
ReferenceKind kind;
|
|
220
197
|
while (rdx_references_iter_next(iter, &id, &kind)) {
|
|
221
198
|
VALUE ref_class = rdxi_reference_class_for_kind(kind);
|
|
222
|
-
VALUE argv[] = {self,
|
|
199
|
+
VALUE argv[] = {self, ULL2NUM(id)};
|
|
223
200
|
VALUE obj = rb_class_new_instance(2, argv, ref_class);
|
|
224
201
|
rb_yield(obj);
|
|
225
202
|
}
|
|
@@ -333,7 +310,7 @@ static VALUE rdxr_graph_resolve_constant(VALUE self, VALUE const_name, VALUE nes
|
|
|
333
310
|
void *graph;
|
|
334
311
|
TypedData_Get_Struct(self, void *, &graph_type, graph);
|
|
335
312
|
|
|
336
|
-
const
|
|
313
|
+
const CDeclaration *decl =
|
|
337
314
|
rdx_graph_resolve_constant(graph, StringValueCStr(const_name), (const char **)converted_file_paths, length);
|
|
338
315
|
|
|
339
316
|
for (size_t i = 0; i < length; i++) {
|
|
@@ -341,15 +318,44 @@ static VALUE rdxr_graph_resolve_constant(VALUE self, VALUE const_name, VALUE nes
|
|
|
341
318
|
}
|
|
342
319
|
free(converted_file_paths);
|
|
343
320
|
|
|
344
|
-
if (
|
|
321
|
+
if (decl == NULL) {
|
|
345
322
|
return Qnil;
|
|
346
323
|
}
|
|
347
324
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
325
|
+
VALUE decl_class = rdxi_declaration_class_for_kind(decl->kind);
|
|
326
|
+
VALUE argv[] = {self, ULL2NUM(decl->id)};
|
|
327
|
+
free_c_declaration(decl);
|
|
328
|
+
|
|
329
|
+
return rb_class_new_instance(2, argv, decl_class);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Graph#resolve_require_path: (String require_path, Array[String] load_paths) -> Document?
|
|
333
|
+
// Resolves a require path to its Document.
|
|
334
|
+
static VALUE rdxr_graph_resolve_require_path(VALUE self, VALUE require_path, VALUE load_paths) {
|
|
335
|
+
Check_Type(require_path, T_STRING);
|
|
336
|
+
rdxi_check_array_of_strings(load_paths);
|
|
337
|
+
|
|
338
|
+
void *graph;
|
|
339
|
+
TypedData_Get_Struct(self, void *, &graph_type, graph);
|
|
340
|
+
const char *path_str = StringValueCStr(require_path);
|
|
341
|
+
|
|
342
|
+
size_t paths_len = RARRAY_LEN(load_paths);
|
|
343
|
+
char **converted_paths = rdxi_str_array_to_char(load_paths, paths_len);
|
|
344
|
+
|
|
345
|
+
const uint64_t *uri_id = rdx_resolve_require_path(graph, path_str, (const char **)converted_paths, paths_len);
|
|
346
|
+
|
|
347
|
+
for (size_t i = 0; i < paths_len; i++) {
|
|
348
|
+
free(converted_paths[i]);
|
|
349
|
+
}
|
|
350
|
+
free(converted_paths);
|
|
351
|
+
|
|
352
|
+
if (uri_id == NULL) {
|
|
353
|
+
return Qnil;
|
|
354
|
+
}
|
|
351
355
|
|
|
352
|
-
|
|
356
|
+
VALUE argv[] = {self, ULL2NUM(*uri_id)};
|
|
357
|
+
free_u64(uri_id);
|
|
358
|
+
return rb_class_new_instance(2, argv, cDocument);
|
|
353
359
|
}
|
|
354
360
|
|
|
355
361
|
// Graph#diagnostics -> Array[Rubydex::Diagnostic]
|
|
@@ -402,4 +408,5 @@ void rdxi_initialize_graph(VALUE mRubydex) {
|
|
|
402
408
|
rb_define_method(cGraph, "[]", rdxr_graph_aref, 1);
|
|
403
409
|
rb_define_method(cGraph, "search", rdxr_graph_search, 1);
|
|
404
410
|
rb_define_method(cGraph, "set_encoding", rdxr_graph_set_encoding, 1);
|
|
411
|
+
rb_define_method(cGraph, "resolve_require_path", rdxr_graph_resolve_require_path, 2);
|
|
405
412
|
}
|
data/ext/rubydex/handle.h
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
typedef struct {
|
|
7
7
|
VALUE graph_obj; // Ruby Graph object to keep it alive
|
|
8
|
-
|
|
8
|
+
uint64_t id; // Canonical ID mapping to a DeclarationId, DefinitionId, UriId, etc. See `ids.rs`.
|
|
9
9
|
} HandleData;
|
|
10
10
|
|
|
11
11
|
static void handle_mark(void *ptr) {
|
|
@@ -36,7 +36,7 @@ static VALUE rdxr_handle_initialize(VALUE self, VALUE graph_obj, VALUE id_val) {
|
|
|
36
36
|
HandleData *data;
|
|
37
37
|
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
38
38
|
data->graph_obj = graph_obj;
|
|
39
|
-
data->id =
|
|
39
|
+
data->id = NUM2ULL(id_val);
|
|
40
40
|
|
|
41
41
|
return self;
|
|
42
42
|
}
|
data/ext/rubydex/utils.c
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#include "utils.h"
|
|
2
|
+
#include "declaration.h"
|
|
3
|
+
#include "rustbindings.h"
|
|
2
4
|
|
|
3
5
|
// Convert a Ruby array of strings into a double char pointer so that we can pass that to Rust.
|
|
4
6
|
// This copies the data so it must be freed
|
|
@@ -25,3 +27,26 @@ void rdxi_check_array_of_strings(VALUE array) {
|
|
|
25
27
|
Check_Type(item, T_STRING);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
30
|
+
|
|
31
|
+
// Yield body for iterating over declarations
|
|
32
|
+
VALUE rdxi_declarations_yield(VALUE args) {
|
|
33
|
+
VALUE self = rb_ary_entry(args, 0);
|
|
34
|
+
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
35
|
+
|
|
36
|
+
CDeclaration decl;
|
|
37
|
+
while (rdx_graph_declarations_iter_next(iter, &decl)) {
|
|
38
|
+
VALUE decl_class = rdxi_declaration_class_for_kind(decl.kind);
|
|
39
|
+
VALUE argv[] = {self, ULL2NUM(decl.id)};
|
|
40
|
+
VALUE handle = rb_class_new_instance(2, argv, decl_class);
|
|
41
|
+
rb_yield(handle);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return Qnil;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Ensure function for iterating over declarations to always free the iterator
|
|
48
|
+
VALUE rdxi_declarations_ensure(VALUE args) {
|
|
49
|
+
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
50
|
+
rdx_graph_declarations_iter_free(iter);
|
|
51
|
+
return Qnil;
|
|
52
|
+
}
|
data/ext/rubydex/utils.h
CHANGED
|
@@ -10,4 +10,10 @@ char **rdxi_str_array_to_char(VALUE array, size_t length);
|
|
|
10
10
|
// Verify that the Ruby object is an array of strings or raise `TypeError`
|
|
11
11
|
void rdxi_check_array_of_strings(VALUE array);
|
|
12
12
|
|
|
13
|
+
// Yield body for iterating over declarations
|
|
14
|
+
VALUE rdxi_declarations_yield(VALUE args);
|
|
15
|
+
|
|
16
|
+
// Ensure function for iterating over declarations to always free the iterator
|
|
17
|
+
VALUE rdxi_declarations_ensure(VALUE args);
|
|
18
|
+
|
|
13
19
|
#endif // RUBYDEX_UTILS_H
|
data/lib/rubydex/3.2/rubydex.so
CHANGED
|
Binary file
|
data/lib/rubydex/3.3/rubydex.so
CHANGED
|
Binary file
|
data/lib/rubydex/3.4/rubydex.so
CHANGED
|
Binary file
|
data/lib/rubydex/4.0/rubydex.so
CHANGED
|
Binary file
|
|
Binary file
|
data/lib/rubydex/version.rb
CHANGED
data/rust/Cargo.lock
CHANGED
|
@@ -706,20 +706,41 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
|
|
706
706
|
|
|
707
707
|
[[package]]
|
|
708
708
|
name = "ruby-prism"
|
|
709
|
-
version = "1.
|
|
709
|
+
version = "1.9.0"
|
|
710
710
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
711
|
-
checksum = "
|
|
711
|
+
checksum = "3b302f00359d0b5423a600314935ca5f994484e15da2db5345631d28c6e029d6"
|
|
712
712
|
dependencies = [
|
|
713
713
|
"ruby-prism-sys",
|
|
714
714
|
"serde",
|
|
715
|
-
"
|
|
715
|
+
"serde_json",
|
|
716
716
|
]
|
|
717
717
|
|
|
718
718
|
[[package]]
|
|
719
719
|
name = "ruby-prism-sys"
|
|
720
|
-
version = "1.
|
|
720
|
+
version = "1.9.0"
|
|
721
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
722
|
+
checksum = "9f85fd9571455bdca2b3bf0b2f543cd13ac39d5de0026a8eb2deb94ffd264f00"
|
|
723
|
+
dependencies = [
|
|
724
|
+
"bindgen",
|
|
725
|
+
"cc",
|
|
726
|
+
]
|
|
727
|
+
|
|
728
|
+
[[package]]
|
|
729
|
+
name = "ruby-rbs"
|
|
730
|
+
version = "0.1.1"
|
|
731
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
732
|
+
checksum = "a0a52a3610111ac0cb06281f0850de2415c1a120d52ec5a6f7da8c52365a56e8"
|
|
733
|
+
dependencies = [
|
|
734
|
+
"ruby-rbs-sys",
|
|
735
|
+
"serde",
|
|
736
|
+
"serde_yaml",
|
|
737
|
+
]
|
|
738
|
+
|
|
739
|
+
[[package]]
|
|
740
|
+
name = "ruby-rbs-sys"
|
|
741
|
+
version = "0.1.1"
|
|
721
742
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
722
|
-
checksum = "
|
|
743
|
+
checksum = "6d657fad68a7679f97d9572ffcf2bc56f35238979950c7ff14915ea7a05b16ea"
|
|
723
744
|
dependencies = [
|
|
724
745
|
"bindgen",
|
|
725
746
|
"cc",
|
|
@@ -742,6 +763,7 @@ dependencies = [
|
|
|
742
763
|
"predicates",
|
|
743
764
|
"regex",
|
|
744
765
|
"ruby-prism",
|
|
766
|
+
"ruby-rbs",
|
|
745
767
|
"rubydex",
|
|
746
768
|
"tempfile",
|
|
747
769
|
"url",
|