rubydex 0.1.0.beta1-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 +285 -0
- data/ext/rubydex/declaration.h +22 -0
- data/ext/rubydex/definition.c +193 -0
- data/ext/rubydex/definition.h +28 -0
- data/ext/rubydex/diagnostic.c +6 -0
- data/ext/rubydex/diagnostic.h +11 -0
- data/ext/rubydex/document.c +98 -0
- data/ext/rubydex/document.h +10 -0
- data/ext/rubydex/extconf.rb +37 -16
- data/ext/rubydex/graph.c +412 -0
- data/ext/rubydex/graph.h +10 -0
- data/ext/rubydex/handle.h +44 -0
- data/ext/rubydex/location.c +22 -0
- data/ext/rubydex/location.h +15 -0
- data/ext/rubydex/reference.c +104 -0
- data/ext/rubydex/reference.h +16 -0
- data/ext/rubydex/rubydex.c +22 -0
- data/ext/rubydex/utils.c +52 -0
- data/ext/rubydex/utils.h +19 -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 +1297 -0
- data/rust/Cargo.toml +23 -0
- data/rust/about.hbs +78 -0
- data/rust/about.toml +10 -0
- data/rust/rubydex/Cargo.toml +42 -0
- data/rust/rubydex/src/compile_assertions.rs +13 -0
- data/rust/rubydex/src/diagnostic.rs +108 -0
- data/rust/rubydex/src/errors.rs +28 -0
- data/rust/rubydex/src/indexing/local_graph.rs +189 -0
- data/rust/rubydex/src/indexing/ruby_indexer.rs +6040 -0
- data/rust/rubydex/src/indexing.rs +128 -0
- data/rust/rubydex/src/job_queue.rs +186 -0
- data/rust/rubydex/src/lib.rs +16 -0
- data/rust/rubydex/src/listing.rs +249 -0
- data/rust/rubydex/src/main.rs +116 -0
- data/rust/rubydex/src/model/comment.rs +24 -0
- data/rust/rubydex/src/model/declaration.rs +562 -0
- data/rust/rubydex/src/model/definitions.rs +1454 -0
- data/rust/rubydex/src/model/document.rs +252 -0
- data/rust/rubydex/src/model/encoding.rs +22 -0
- data/rust/rubydex/src/model/graph.rs +1505 -0
- data/rust/rubydex/src/model/id.rs +84 -0
- data/rust/rubydex/src/model/identity_maps.rs +58 -0
- data/rust/rubydex/src/model/ids.rs +38 -0
- data/rust/rubydex/src/model/name.rs +293 -0
- data/rust/rubydex/src/model/references.rs +111 -0
- data/rust/rubydex/src/model/string_ref.rs +50 -0
- data/rust/rubydex/src/model/visibility.rs +41 -0
- data/rust/rubydex/src/model.rs +13 -0
- data/rust/rubydex/src/offset.rs +70 -0
- data/rust/rubydex/src/position.rs +6 -0
- data/rust/rubydex/src/query.rs +278 -0
- data/rust/rubydex/src/resolution.rs +4232 -0
- data/rust/rubydex/src/stats/memory.rs +71 -0
- data/rust/rubydex/src/stats/timer.rs +126 -0
- data/rust/rubydex/src/stats.rs +9 -0
- data/rust/rubydex/src/test_utils/context.rs +226 -0
- data/rust/rubydex/src/test_utils/graph_test.rs +522 -0
- data/rust/rubydex/src/test_utils/local_graph_test.rs +166 -0
- data/rust/rubydex/src/test_utils.rs +52 -0
- data/rust/rubydex/src/visualization/dot.rs +176 -0
- data/rust/rubydex/src/visualization.rs +6 -0
- data/rust/rubydex/tests/cli.rs +167 -0
- data/rust/rubydex-sys/Cargo.toml +20 -0
- data/rust/rubydex-sys/build.rs +14 -0
- data/rust/rubydex-sys/cbindgen.toml +12 -0
- data/rust/rubydex-sys/src/declaration_api.rs +341 -0
- data/rust/rubydex-sys/src/definition_api.rs +350 -0
- data/rust/rubydex-sys/src/diagnostic_api.rs +99 -0
- data/rust/rubydex-sys/src/document_api.rs +54 -0
- data/rust/rubydex-sys/src/graph_api.rs +519 -0
- data/rust/rubydex-sys/src/lib.rs +9 -0
- data/rust/rubydex-sys/src/location_api.rs +79 -0
- data/rust/rubydex-sys/src/name_api.rs +135 -0
- data/rust/rubydex-sys/src/reference_api.rs +191 -0
- data/rust/rubydex-sys/src/utils.rs +50 -0
- data/rust/rustfmt.toml +2 -0
- metadata +78 -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
|
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
#include "declaration.h"
|
|
2
|
+
#include "definition.h"
|
|
3
|
+
#include "graph.h"
|
|
4
|
+
#include "handle.h"
|
|
5
|
+
#include "rustbindings.h"
|
|
6
|
+
#include "utils.h"
|
|
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
|
+
}
|
|
45
|
+
|
|
46
|
+
// Declaration#name -> String
|
|
47
|
+
static VALUE rdxr_declaration_name(VALUE self) {
|
|
48
|
+
HandleData *data;
|
|
49
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
50
|
+
|
|
51
|
+
void *graph;
|
|
52
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
53
|
+
const char *name = rdx_declaration_name(graph, data->id);
|
|
54
|
+
|
|
55
|
+
if (name == NULL) {
|
|
56
|
+
return Qnil;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
VALUE str = rb_utf8_str_new_cstr(name);
|
|
60
|
+
free_c_string(name);
|
|
61
|
+
|
|
62
|
+
return str;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Declaration#unqualified_name -> String
|
|
66
|
+
static VALUE rdxr_declaration_unqualified_name(VALUE self) {
|
|
67
|
+
HandleData *data;
|
|
68
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
69
|
+
|
|
70
|
+
void *graph;
|
|
71
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
72
|
+
const char *name = rdx_declaration_unqualified_name(graph, data->id);
|
|
73
|
+
|
|
74
|
+
if (name == NULL) {
|
|
75
|
+
return Qnil;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
VALUE str = rb_utf8_str_new_cstr(name);
|
|
79
|
+
free_c_string(name);
|
|
80
|
+
|
|
81
|
+
return str;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Body function for rb_ensure in Declaration#definitions
|
|
85
|
+
static VALUE declaration_definitions_yield(VALUE args) {
|
|
86
|
+
VALUE self = rb_ary_entry(args, 0);
|
|
87
|
+
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
88
|
+
|
|
89
|
+
HandleData *data;
|
|
90
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
91
|
+
|
|
92
|
+
uint64_t id = 0;
|
|
93
|
+
DefinitionKind kind;
|
|
94
|
+
while (rdx_definitions_iter_next(iter, &id, &kind)) {
|
|
95
|
+
VALUE argv[] = {data->graph_obj, ULL2NUM(id)};
|
|
96
|
+
VALUE defn_class = rdxi_definition_class_for_kind(kind);
|
|
97
|
+
VALUE handle = rb_class_new_instance(2, argv, defn_class);
|
|
98
|
+
rb_yield(handle);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return Qnil;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Ensure function for rb_ensure in Declaration#definitions to always free the
|
|
105
|
+
// iterator
|
|
106
|
+
static VALUE declaration_definitions_ensure(VALUE args) {
|
|
107
|
+
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
108
|
+
rdx_definitions_iter_free(iter);
|
|
109
|
+
|
|
110
|
+
return Qnil;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Size function for the Declaration#definitions enumerator
|
|
114
|
+
static VALUE declaration_definitions_size(VALUE self, VALUE _args, VALUE _eobj) {
|
|
115
|
+
HandleData *data;
|
|
116
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
117
|
+
|
|
118
|
+
void *graph;
|
|
119
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
120
|
+
struct DefinitionsIter *iter = rdx_declaration_definitions_iter_new(graph, data->id);
|
|
121
|
+
size_t len = rdx_definitions_iter_len(iter);
|
|
122
|
+
rdx_definitions_iter_free(iter);
|
|
123
|
+
|
|
124
|
+
return SIZET2NUM(len);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Declaration#definitions: () -> Enumerator[Definition]
|
|
128
|
+
// Returns an enumerator that yields all definitions for this declaration lazily
|
|
129
|
+
static VALUE rdxr_declaration_definitions(VALUE self) {
|
|
130
|
+
if (!rb_block_given_p()) {
|
|
131
|
+
return rb_enumeratorize_with_size(self, rb_str_new2("definitions"), 0, NULL, declaration_definitions_size);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
HandleData *data;
|
|
135
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
136
|
+
|
|
137
|
+
void *graph;
|
|
138
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
139
|
+
|
|
140
|
+
void *iter = rdx_declaration_definitions_iter_new(graph, data->id);
|
|
141
|
+
VALUE args = rb_ary_new_from_args(2, self, ULL2NUM((uintptr_t)iter));
|
|
142
|
+
rb_ensure(declaration_definitions_yield, args, declaration_definitions_ensure, args);
|
|
143
|
+
|
|
144
|
+
return self;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Declaration#member: (String member) -> Declaration
|
|
148
|
+
// Returns a declaration handle for the given member
|
|
149
|
+
static VALUE rdxr_declaration_member(VALUE self, VALUE name) {
|
|
150
|
+
HandleData *data;
|
|
151
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
152
|
+
|
|
153
|
+
void *graph;
|
|
154
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
155
|
+
|
|
156
|
+
if (TYPE(name) != T_STRING) {
|
|
157
|
+
rb_raise(rb_eTypeError, "expected String");
|
|
158
|
+
}
|
|
159
|
+
|
|
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) {
|
|
182
|
+
return Qnil;
|
|
183
|
+
}
|
|
184
|
+
|
|
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);
|
|
254
|
+
|
|
255
|
+
return self;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
void rdxi_initialize_declaration(VALUE mRubydex) {
|
|
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);
|
|
270
|
+
|
|
271
|
+
rb_define_alloc_func(cDeclaration, rdxr_handle_alloc);
|
|
272
|
+
rb_define_method(cDeclaration, "initialize", rdxr_handle_initialize, 2);
|
|
273
|
+
rb_define_method(cDeclaration, "name", rdxr_declaration_name, 0);
|
|
274
|
+
rb_define_method(cDeclaration, "unqualified_name", rdxr_declaration_unqualified_name, 0);
|
|
275
|
+
rb_define_method(cDeclaration, "definitions", rdxr_declaration_definitions, 0);
|
|
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);
|
|
283
|
+
|
|
284
|
+
rb_funcall(rb_singleton_class(cDeclaration), rb_intern("private"), 1, ID2SYM(rb_intern("new")));
|
|
285
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#ifndef RUBYDEX_DECLARATION_H
|
|
2
|
+
#define RUBYDEX_DECLARATION_H
|
|
3
|
+
|
|
4
|
+
#include "ruby.h"
|
|
5
|
+
#include "rustbindings.h"
|
|
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;
|
|
18
|
+
|
|
19
|
+
VALUE rdxi_declaration_class_for_kind(CDeclarationKind kind);
|
|
20
|
+
void rdxi_initialize_declaration(VALUE mRubydex);
|
|
21
|
+
|
|
22
|
+
#endif // RUBYDEX_DECLARATION_H
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#include "definition.h"
|
|
2
|
+
#include "graph.h"
|
|
3
|
+
#include "handle.h"
|
|
4
|
+
#include "location.h"
|
|
5
|
+
#include "ruby/internal/scan_args.h"
|
|
6
|
+
#include "rustbindings.h"
|
|
7
|
+
|
|
8
|
+
static VALUE mRubydex;
|
|
9
|
+
VALUE cComment;
|
|
10
|
+
VALUE cDefinition;
|
|
11
|
+
VALUE cClassDefinition;
|
|
12
|
+
VALUE cSingletonClassDefinition;
|
|
13
|
+
VALUE cModuleDefinition;
|
|
14
|
+
VALUE cConstantDefinition;
|
|
15
|
+
VALUE cConstantAliasDefinition;
|
|
16
|
+
VALUE cMethodDefinition;
|
|
17
|
+
VALUE cAttrAccessorDefinition;
|
|
18
|
+
VALUE cAttrReaderDefinition;
|
|
19
|
+
VALUE cAttrWriterDefinition;
|
|
20
|
+
VALUE cGlobalVariableDefinition;
|
|
21
|
+
VALUE cInstanceVariableDefinition;
|
|
22
|
+
VALUE cClassVariableDefinition;
|
|
23
|
+
VALUE cMethodAliasDefinition;
|
|
24
|
+
VALUE cGlobalVariableAliasDefinition;
|
|
25
|
+
|
|
26
|
+
// Keep this in sync with definition.rs
|
|
27
|
+
VALUE rdxi_definition_class_for_kind(DefinitionKind kind) {
|
|
28
|
+
switch (kind) {
|
|
29
|
+
case DefinitionKind_Class:
|
|
30
|
+
return cClassDefinition;
|
|
31
|
+
case DefinitionKind_SingletonClass:
|
|
32
|
+
return cSingletonClassDefinition;
|
|
33
|
+
case DefinitionKind_Module:
|
|
34
|
+
return cModuleDefinition;
|
|
35
|
+
case DefinitionKind_Constant:
|
|
36
|
+
return cConstantDefinition;
|
|
37
|
+
case DefinitionKind_ConstantAlias:
|
|
38
|
+
return cConstantAliasDefinition;
|
|
39
|
+
case DefinitionKind_Method:
|
|
40
|
+
return cMethodDefinition;
|
|
41
|
+
case DefinitionKind_AttrAccessor:
|
|
42
|
+
return cAttrAccessorDefinition;
|
|
43
|
+
case DefinitionKind_AttrReader:
|
|
44
|
+
return cAttrReaderDefinition;
|
|
45
|
+
case DefinitionKind_AttrWriter:
|
|
46
|
+
return cAttrWriterDefinition;
|
|
47
|
+
case DefinitionKind_GlobalVariable:
|
|
48
|
+
return cGlobalVariableDefinition;
|
|
49
|
+
case DefinitionKind_InstanceVariable:
|
|
50
|
+
return cInstanceVariableDefinition;
|
|
51
|
+
case DefinitionKind_ClassVariable:
|
|
52
|
+
return cClassVariableDefinition;
|
|
53
|
+
case DefinitionKind_MethodAlias:
|
|
54
|
+
return cMethodAliasDefinition;
|
|
55
|
+
case DefinitionKind_GlobalVariableAlias:
|
|
56
|
+
return cGlobalVariableAliasDefinition;
|
|
57
|
+
default:
|
|
58
|
+
rb_raise(rb_eRuntimeError, "Unknown DefinitionKind: %d", kind);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Definition#location -> Rubydex::Location
|
|
63
|
+
static VALUE rdxr_definition_location(VALUE self) {
|
|
64
|
+
HandleData *data;
|
|
65
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
66
|
+
|
|
67
|
+
void *graph;
|
|
68
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
69
|
+
|
|
70
|
+
Location *loc = rdx_definition_location(graph, data->id);
|
|
71
|
+
VALUE location = rdxi_build_location_value(loc);
|
|
72
|
+
rdx_location_free(loc);
|
|
73
|
+
|
|
74
|
+
return location;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Definition#comments -> [Rubydex::Comment]
|
|
78
|
+
static VALUE rdxr_definition_comments(VALUE self) {
|
|
79
|
+
HandleData *data;
|
|
80
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
81
|
+
|
|
82
|
+
void *graph;
|
|
83
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
84
|
+
|
|
85
|
+
CommentArray *arr = rdx_definition_comments(graph, data->id);
|
|
86
|
+
if (arr == NULL || arr->len == 0) {
|
|
87
|
+
if (arr != NULL) {
|
|
88
|
+
rdx_definition_comments_free(arr);
|
|
89
|
+
}
|
|
90
|
+
return rb_ary_new();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
VALUE ary = rb_ary_new_capa((long)arr->len);
|
|
94
|
+
for (size_t i = 0; i < arr->len; i++) {
|
|
95
|
+
CommentEntry entry = arr->items[i];
|
|
96
|
+
|
|
97
|
+
VALUE string = rb_utf8_str_new_cstr(entry.string);
|
|
98
|
+
|
|
99
|
+
Location *loc = entry.location;
|
|
100
|
+
VALUE location = rdxi_build_location_value(loc);
|
|
101
|
+
|
|
102
|
+
VALUE comment_kwargs = rb_hash_new();
|
|
103
|
+
rb_hash_aset(comment_kwargs, ID2SYM(rb_intern("string")), string);
|
|
104
|
+
rb_hash_aset(comment_kwargs, ID2SYM(rb_intern("location")), location);
|
|
105
|
+
VALUE comment = rb_class_new_instance_kw(1, &comment_kwargs, cComment, RB_PASS_KEYWORDS);
|
|
106
|
+
|
|
107
|
+
rb_ary_push(ary, comment);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Free the array and all inner allocations on the Rust side
|
|
111
|
+
rdx_definition_comments_free(arr);
|
|
112
|
+
return ary;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Definition#name -> String
|
|
116
|
+
static VALUE rdxr_definition_name(VALUE self) {
|
|
117
|
+
HandleData *data;
|
|
118
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
119
|
+
|
|
120
|
+
void *graph;
|
|
121
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
122
|
+
|
|
123
|
+
const char *name = rdx_definition_name(graph, data->id);
|
|
124
|
+
if (name == NULL) {
|
|
125
|
+
return Qnil;
|
|
126
|
+
}
|
|
127
|
+
VALUE str = rb_utf8_str_new_cstr(name);
|
|
128
|
+
free_c_string(name);
|
|
129
|
+
return str;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Definition#deprecated? -> bool
|
|
133
|
+
static VALUE rdxr_definition_deprecated(VALUE self) {
|
|
134
|
+
HandleData *data;
|
|
135
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
136
|
+
|
|
137
|
+
void *graph;
|
|
138
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
139
|
+
|
|
140
|
+
bool deprecated = rdx_definition_is_deprecated(graph, data->id);
|
|
141
|
+
return deprecated ? Qtrue : Qfalse;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Definition#name_location -> Rubydex::Location or nil
|
|
145
|
+
// For class, module, and singleton class definitions, returns the location of just the name
|
|
146
|
+
// (e.g., "Bar" in "class Foo::Bar"). For other definition types, returns nil.
|
|
147
|
+
static VALUE rdxr_definition_name_location(VALUE self) {
|
|
148
|
+
HandleData *data;
|
|
149
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
150
|
+
|
|
151
|
+
void *graph;
|
|
152
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
153
|
+
|
|
154
|
+
Location *loc = rdx_definition_name_location(graph, data->id);
|
|
155
|
+
if (loc == NULL) {
|
|
156
|
+
return Qnil;
|
|
157
|
+
}
|
|
158
|
+
VALUE location = rdxi_build_location_value(loc);
|
|
159
|
+
rdx_location_free(loc);
|
|
160
|
+
|
|
161
|
+
return location;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
void rdxi_initialize_definition(VALUE mod) {
|
|
165
|
+
mRubydex = mod;
|
|
166
|
+
|
|
167
|
+
cComment = rb_define_class_under(mRubydex, "Comment", rb_cObject);
|
|
168
|
+
|
|
169
|
+
cDefinition = rb_define_class_under(mRubydex, "Definition", rb_cObject);
|
|
170
|
+
rb_define_alloc_func(cDefinition, rdxr_handle_alloc);
|
|
171
|
+
rb_define_method(cDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
172
|
+
rb_funcall(rb_singleton_class(cDefinition), rb_intern("private"), 1, ID2SYM(rb_intern("new")));
|
|
173
|
+
rb_define_method(cDefinition, "location", rdxr_definition_location, 0);
|
|
174
|
+
rb_define_method(cDefinition, "comments", rdxr_definition_comments, 0);
|
|
175
|
+
rb_define_method(cDefinition, "name", rdxr_definition_name, 0);
|
|
176
|
+
rb_define_method(cDefinition, "deprecated?", rdxr_definition_deprecated, 0);
|
|
177
|
+
rb_define_method(cDefinition, "name_location", rdxr_definition_name_location, 0);
|
|
178
|
+
|
|
179
|
+
cClassDefinition = rb_define_class_under(mRubydex, "ClassDefinition", cDefinition);
|
|
180
|
+
cSingletonClassDefinition = rb_define_class_under(mRubydex, "SingletonClassDefinition", cDefinition);
|
|
181
|
+
cModuleDefinition = rb_define_class_under(mRubydex, "ModuleDefinition", cDefinition);
|
|
182
|
+
cConstantDefinition = rb_define_class_under(mRubydex, "ConstantDefinition", cDefinition);
|
|
183
|
+
cConstantAliasDefinition = rb_define_class_under(mRubydex, "ConstantAliasDefinition", cDefinition);
|
|
184
|
+
cMethodDefinition = rb_define_class_under(mRubydex, "MethodDefinition", cDefinition);
|
|
185
|
+
cAttrAccessorDefinition = rb_define_class_under(mRubydex, "AttrAccessorDefinition", cDefinition);
|
|
186
|
+
cAttrReaderDefinition = rb_define_class_under(mRubydex, "AttrReaderDefinition", cDefinition);
|
|
187
|
+
cAttrWriterDefinition = rb_define_class_under(mRubydex, "AttrWriterDefinition", cDefinition);
|
|
188
|
+
cGlobalVariableDefinition = rb_define_class_under(mRubydex, "GlobalVariableDefinition", cDefinition);
|
|
189
|
+
cInstanceVariableDefinition = rb_define_class_under(mRubydex, "InstanceVariableDefinition", cDefinition);
|
|
190
|
+
cClassVariableDefinition = rb_define_class_under(mRubydex, "ClassVariableDefinition", cDefinition);
|
|
191
|
+
cMethodAliasDefinition = rb_define_class_under(mRubydex, "MethodAliasDefinition", cDefinition);
|
|
192
|
+
cGlobalVariableAliasDefinition = rb_define_class_under(mRubydex, "GlobalVariableAliasDefinition", cDefinition);
|
|
193
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#ifndef RUBYDEX_DEFINITION_H
|
|
2
|
+
#define RUBYDEX_DEFINITION_H
|
|
3
|
+
|
|
4
|
+
#include "ruby.h"
|
|
5
|
+
#include "rustbindings.h"
|
|
6
|
+
|
|
7
|
+
extern VALUE cDefinition;
|
|
8
|
+
extern VALUE cClassDefinition;
|
|
9
|
+
extern VALUE cSingletonClassDefinition;
|
|
10
|
+
extern VALUE cModuleDefinition;
|
|
11
|
+
extern VALUE cConstantDefinition;
|
|
12
|
+
extern VALUE cConstantAliasDefinition;
|
|
13
|
+
extern VALUE cMethodDefinition;
|
|
14
|
+
extern VALUE cAttrAccessorDefinition;
|
|
15
|
+
extern VALUE cAttrReaderDefinition;
|
|
16
|
+
extern VALUE cAttrWriterDefinition;
|
|
17
|
+
extern VALUE cGlobalVariableDefinition;
|
|
18
|
+
extern VALUE cInstanceVariableDefinition;
|
|
19
|
+
extern VALUE cClassVariableDefinition;
|
|
20
|
+
extern VALUE cMethodAliasDefinition;
|
|
21
|
+
extern VALUE cGlobalVariableAliasDefinition;
|
|
22
|
+
|
|
23
|
+
void rdxi_initialize_definition(VALUE mRubydex);
|
|
24
|
+
|
|
25
|
+
// Returns the Ruby class for a given DefinitionKind without calling back into Rust
|
|
26
|
+
VALUE rdxi_definition_class_for_kind(DefinitionKind kind);
|
|
27
|
+
|
|
28
|
+
#endif // RUBYDEX_DEFINITION_H
|