rubydex 0.1.0.beta1-x86_64-linux → 0.1.0.beta2-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/ext/rubydex/declaration.c +146 -0
- data/ext/rubydex/declaration.h +10 -0
- data/ext/rubydex/definition.c +234 -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 +36 -15
- data/ext/rubydex/graph.c +405 -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 +27 -0
- data/ext/rubydex/utils.h +13 -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 +1275 -0
- data/rust/Cargo.toml +23 -0
- data/rust/about.hbs +78 -0
- data/rust/about.toml +9 -0
- data/rust/rubydex/Cargo.toml +41 -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 +172 -0
- data/rust/rubydex/src/indexing/ruby_indexer.rs +5397 -0
- data/rust/rubydex/src/indexing.rs +128 -0
- data/rust/rubydex/src/job_queue.rs +186 -0
- data/rust/rubydex/src/lib.rs +15 -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 +541 -0
- data/rust/rubydex/src/model/definitions.rs +1475 -0
- data/rust/rubydex/src/model/document.rs +111 -0
- data/rust/rubydex/src/model/encoding.rs +22 -0
- data/rust/rubydex/src/model/graph.rs +1387 -0
- data/rust/rubydex/src/model/id.rs +90 -0
- data/rust/rubydex/src/model/identity_maps.rs +54 -0
- data/rust/rubydex/src/model/ids.rs +32 -0
- data/rust/rubydex/src/model/name.rs +188 -0
- data/rust/rubydex/src/model/references.rs +129 -0
- data/rust/rubydex/src/model/string_ref.rs +44 -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 +103 -0
- data/rust/rubydex/src/resolution.rs +4421 -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 +229 -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 +114 -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 +493 -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 +81 -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 +77 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4cd7117d9875054427596fc86ec03777c49f83def03b61e88854054ed3ba29e
|
|
4
|
+
data.tar.gz: 784d1100f887338f37156b1154abe838809620fee042a9ee1e6ddb7bce1343e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '084c9c76384daa40ba132d79fd4e4ef8971e4e7f0d1dd33af187ae004507c8b5135b2d241e222acbd47adfc92c043b94924b45e1f7e6f2cda51d783f310c63a4'
|
|
7
|
+
data.tar.gz: dd14d62e46de868f0622c72d379816ef913f0696454507458bb7d7598a6d3f334502a0b4470b5d6775861e208e46b069fcc78efcc6ef1b06b553696dffc7f18b
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#include "declaration.h"
|
|
2
|
+
#include "definition.h"
|
|
3
|
+
#include "graph.h"
|
|
4
|
+
#include "handle.h"
|
|
5
|
+
#include "rustbindings.h"
|
|
6
|
+
|
|
7
|
+
VALUE cDeclaration;
|
|
8
|
+
|
|
9
|
+
// Declaration#name -> String
|
|
10
|
+
static VALUE rdxr_declaration_name(VALUE self) {
|
|
11
|
+
HandleData *data;
|
|
12
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
13
|
+
|
|
14
|
+
void *graph;
|
|
15
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
16
|
+
const char *name = rdx_declaration_name(graph, data->id);
|
|
17
|
+
|
|
18
|
+
if (name == NULL) {
|
|
19
|
+
return Qnil;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
VALUE str = rb_utf8_str_new_cstr(name);
|
|
23
|
+
free_c_string(name);
|
|
24
|
+
|
|
25
|
+
return str;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Declaration#unqualified_name -> String
|
|
29
|
+
static VALUE rdxr_declaration_unqualified_name(VALUE self) {
|
|
30
|
+
HandleData *data;
|
|
31
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
32
|
+
|
|
33
|
+
void *graph;
|
|
34
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
35
|
+
const char *name = rdx_declaration_unqualified_name(graph, data->id);
|
|
36
|
+
|
|
37
|
+
if (name == NULL) {
|
|
38
|
+
return Qnil;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
VALUE str = rb_utf8_str_new_cstr(name);
|
|
42
|
+
free_c_string(name);
|
|
43
|
+
|
|
44
|
+
return str;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Body function for rb_ensure in Declaration#definitions
|
|
48
|
+
static VALUE declaration_definitions_yield(VALUE args) {
|
|
49
|
+
VALUE self = rb_ary_entry(args, 0);
|
|
50
|
+
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
51
|
+
|
|
52
|
+
HandleData *data;
|
|
53
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
54
|
+
|
|
55
|
+
int64_t id = 0;
|
|
56
|
+
DefinitionKind kind;
|
|
57
|
+
while (rdx_definitions_iter_next(iter, &id, &kind)) {
|
|
58
|
+
VALUE argv[] = {data->graph_obj, LL2NUM(id)};
|
|
59
|
+
VALUE defn_class = rdxi_definition_class_for_kind(kind);
|
|
60
|
+
VALUE handle = rb_class_new_instance(2, argv, defn_class);
|
|
61
|
+
rb_yield(handle);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return Qnil;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Ensure function for rb_ensure in Declaration#definitions to always free the
|
|
68
|
+
// iterator
|
|
69
|
+
static VALUE declaration_definitions_ensure(VALUE args) {
|
|
70
|
+
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
71
|
+
rdx_definitions_iter_free(iter);
|
|
72
|
+
|
|
73
|
+
return Qnil;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Size function for the Declaration#definitions enumerator
|
|
77
|
+
static VALUE declaration_definitions_size(VALUE self, VALUE _args, VALUE _eobj) {
|
|
78
|
+
HandleData *data;
|
|
79
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
80
|
+
|
|
81
|
+
void *graph;
|
|
82
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
83
|
+
struct DefinitionsIter *iter = rdx_declaration_definitions_iter_new(graph, data->id);
|
|
84
|
+
size_t len = rdx_definitions_iter_len(iter);
|
|
85
|
+
rdx_definitions_iter_free(iter);
|
|
86
|
+
|
|
87
|
+
return SIZET2NUM(len);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Declaration#definitions: () -> Enumerator[Definition]
|
|
91
|
+
// Returns an enumerator that yields all definitions for this declaration lazily
|
|
92
|
+
static VALUE rdxr_declaration_definitions(VALUE self) {
|
|
93
|
+
if (!rb_block_given_p()) {
|
|
94
|
+
return rb_enumeratorize_with_size(self, rb_str_new2("definitions"), 0, NULL, declaration_definitions_size);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
HandleData *data;
|
|
98
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
99
|
+
|
|
100
|
+
void *graph;
|
|
101
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
102
|
+
|
|
103
|
+
void *iter = rdx_declaration_definitions_iter_new(graph, data->id);
|
|
104
|
+
VALUE args = rb_ary_new_from_args(2, self, ULL2NUM((uintptr_t)iter));
|
|
105
|
+
rb_ensure(declaration_definitions_yield, args, declaration_definitions_ensure, args);
|
|
106
|
+
|
|
107
|
+
return self;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Declaration#member: (String member) -> Declaration
|
|
111
|
+
// Returns a declaration handle for the given member
|
|
112
|
+
static VALUE rdxr_declaration_member(VALUE self, VALUE name) {
|
|
113
|
+
HandleData *data;
|
|
114
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
115
|
+
|
|
116
|
+
void *graph;
|
|
117
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
118
|
+
|
|
119
|
+
if (TYPE(name) != T_STRING) {
|
|
120
|
+
rb_raise(rb_eTypeError, "expected String");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const int64_t *id_ptr = rdx_declaration_member(graph, data->id, StringValueCStr(name));
|
|
124
|
+
if (id_ptr == NULL) {
|
|
125
|
+
return Qnil;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
int64_t id = *id_ptr;
|
|
129
|
+
free_i64(id_ptr);
|
|
130
|
+
VALUE argv[] = {data->graph_obj, LL2NUM(id)};
|
|
131
|
+
|
|
132
|
+
return rb_class_new_instance(2, argv, cDeclaration);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
void rdxi_initialize_declaration(VALUE mRubydex) {
|
|
136
|
+
cDeclaration = rb_define_class_under(mRubydex, "Declaration", rb_cObject);
|
|
137
|
+
|
|
138
|
+
rb_define_alloc_func(cDeclaration, rdxr_handle_alloc);
|
|
139
|
+
rb_define_method(cDeclaration, "initialize", rdxr_handle_initialize, 2);
|
|
140
|
+
rb_define_method(cDeclaration, "name", rdxr_declaration_name, 0);
|
|
141
|
+
rb_define_method(cDeclaration, "unqualified_name", rdxr_declaration_unqualified_name, 0);
|
|
142
|
+
rb_define_method(cDeclaration, "definitions", rdxr_declaration_definitions, 0);
|
|
143
|
+
rb_define_method(cDeclaration, "member", rdxr_declaration_member, 1);
|
|
144
|
+
|
|
145
|
+
rb_funcall(rb_singleton_class(cDeclaration), rb_intern("private"), 1, ID2SYM(rb_intern("new")));
|
|
146
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
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
|
+
rb_define_alloc_func(cClassDefinition, rdxr_handle_alloc);
|
|
181
|
+
rb_define_method(cClassDefinition, "initialize", rdxr_handle_initialize, 2);
|
|
182
|
+
|
|
183
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
}
|
|
@@ -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
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#include "document.h"
|
|
2
|
+
#include "definition.h"
|
|
3
|
+
#include "graph.h"
|
|
4
|
+
#include "handle.h"
|
|
5
|
+
#include "rustbindings.h"
|
|
6
|
+
|
|
7
|
+
VALUE cDocument;
|
|
8
|
+
|
|
9
|
+
// Document#uri -> String
|
|
10
|
+
static VALUE rdxr_document_uri(VALUE self) {
|
|
11
|
+
HandleData *data;
|
|
12
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
13
|
+
|
|
14
|
+
void *graph;
|
|
15
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
16
|
+
const char *uri = rdx_document_uri(graph, data->id);
|
|
17
|
+
|
|
18
|
+
if (uri == NULL) {
|
|
19
|
+
return Qnil;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
VALUE str = rb_utf8_str_new_cstr(uri);
|
|
23
|
+
free_c_string(uri);
|
|
24
|
+
|
|
25
|
+
return str;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Body function for rb_ensure in Document#definitions
|
|
29
|
+
static VALUE document_definitions_yield(VALUE args) {
|
|
30
|
+
VALUE self = rb_ary_entry(args, 0);
|
|
31
|
+
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
32
|
+
|
|
33
|
+
HandleData *data;
|
|
34
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
35
|
+
|
|
36
|
+
int64_t id = 0;
|
|
37
|
+
DefinitionKind kind;
|
|
38
|
+
while (rdx_definitions_iter_next(iter, &id, &kind)) {
|
|
39
|
+
VALUE argv[] = {data->graph_obj, LL2NUM(id)};
|
|
40
|
+
VALUE defn_class = rdxi_definition_class_for_kind(kind);
|
|
41
|
+
VALUE handle = rb_class_new_instance(2, argv, defn_class);
|
|
42
|
+
rb_yield(handle);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return Qnil;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Ensure function for rb_ensure in Document#definitions to always free the iterator
|
|
49
|
+
static VALUE document_definitions_ensure(VALUE args) {
|
|
50
|
+
void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
|
|
51
|
+
rdx_definitions_iter_free(iter);
|
|
52
|
+
|
|
53
|
+
return Qnil;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Size function for the Document#definitions enumerator
|
|
57
|
+
static VALUE document_definitions_size(VALUE self, VALUE _args, VALUE _eobj) {
|
|
58
|
+
HandleData *data;
|
|
59
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
60
|
+
|
|
61
|
+
void *graph;
|
|
62
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
63
|
+
struct DefinitionsIter *iter = rdx_document_definitions_iter_new(graph, data->id);
|
|
64
|
+
size_t len = rdx_definitions_iter_len(iter);
|
|
65
|
+
rdx_definitions_iter_free(iter);
|
|
66
|
+
|
|
67
|
+
return SIZET2NUM(len);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Document#definitions: () -> Enumerator[Definition]
|
|
71
|
+
// Returns an enumerator that yields all definitions for this document lazily
|
|
72
|
+
static VALUE rdxr_document_definitions(VALUE self) {
|
|
73
|
+
if (!rb_block_given_p()) {
|
|
74
|
+
return rb_enumeratorize_with_size(self, rb_str_new2("definitions"), 0, NULL, document_definitions_size);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
HandleData *data;
|
|
78
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
79
|
+
|
|
80
|
+
void *graph;
|
|
81
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
82
|
+
void *iter = rdx_document_definitions_iter_new(graph, data->id);
|
|
83
|
+
VALUE args = rb_ary_new_from_args(2, self, ULL2NUM((uintptr_t)iter));
|
|
84
|
+
rb_ensure(document_definitions_yield, args, document_definitions_ensure, args);
|
|
85
|
+
|
|
86
|
+
return self;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
void rdxi_initialize_document(VALUE mRubydex) {
|
|
90
|
+
cDocument = rb_define_class_under(mRubydex, "Document", rb_cObject);
|
|
91
|
+
|
|
92
|
+
rb_define_alloc_func(cDocument, rdxr_handle_alloc);
|
|
93
|
+
rb_define_method(cDocument, "initialize", rdxr_handle_initialize, 2);
|
|
94
|
+
rb_define_method(cDocument, "uri", rdxr_document_uri, 0);
|
|
95
|
+
rb_define_method(cDocument, "definitions", rdxr_document_definitions, 0);
|
|
96
|
+
|
|
97
|
+
rb_funcall(rb_singleton_class(cDocument), rb_intern("private"), 1, ID2SYM(rb_intern("new")));
|
|
98
|
+
}
|
data/ext/rubydex/extconf.rb
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
require "mkmf"
|
|
4
4
|
require "pathname"
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
unless system("cargo", "--version", out: File::NULL, err: File::NULL)
|
|
7
|
+
abort "Installing Rubydex requires Cargo, the Rust package manager for platforms that we do not precompile binaries."
|
|
8
|
+
end
|
|
9
|
+
|
|
7
10
|
gem_dir = Pathname.new("../..").expand_path(__dir__)
|
|
11
|
+
release = ENV["RELEASE"] || !gem_dir.join(".git").exist?
|
|
8
12
|
root_dir = gem_dir.join("rust")
|
|
9
13
|
target_dir = root_dir.join("target")
|
|
10
14
|
target_dir = target_dir.join("x86_64-pc-windows-gnu") if Gem.win_platform?
|
|
@@ -34,7 +38,16 @@ if Gem.win_platform?
|
|
|
34
38
|
$LDFLAGS << " -l#{lib}"
|
|
35
39
|
end
|
|
36
40
|
else
|
|
37
|
-
|
|
41
|
+
if RUBY_PLATFORM.include?("darwin")
|
|
42
|
+
# On the precompiled version of the gem, the `dylib` is one folder above the `.bundle/.so` file. For on machine
|
|
43
|
+
# compilation, they are at the same level
|
|
44
|
+
append_ldflags("-Wl,-rpath,@loader_path")
|
|
45
|
+
append_ldflags("-Wl,-rpath,@loader_path/..")
|
|
46
|
+
else
|
|
47
|
+
$LDFLAGS << " -Wl,-rpath,\\$$ORIGIN"
|
|
48
|
+
$LDFLAGS << " -Wl,-rpath,\\$$ORIGIN/.."
|
|
49
|
+
end
|
|
50
|
+
|
|
38
51
|
# We cannot use append_ldflags here because the Rust code is only compiled later. If it's not compiled yet, this will
|
|
39
52
|
# fail and the flag will not be added
|
|
40
53
|
$LDFLAGS << " -L#{target_dir} -lrubydex_sys"
|
|
@@ -49,9 +62,22 @@ else
|
|
|
49
62
|
"cargo build #{cargo_args.join(" ")}".strip
|
|
50
63
|
end
|
|
51
64
|
|
|
52
|
-
|
|
65
|
+
lib_dir = gem_dir.join("lib").join("rubydex")
|
|
66
|
+
|
|
67
|
+
copy_dylib_commands = if Gem.win_platform?
|
|
68
|
+
""
|
|
69
|
+
elsif RUBY_PLATFORM.include?("darwin")
|
|
70
|
+
src_dylib = target_dir.join("librubydex_sys.dylib")
|
|
71
|
+
"\t$(COPY) #{src_dylib} #{lib_dir}"
|
|
72
|
+
else
|
|
73
|
+
# Linux
|
|
74
|
+
src_dylib = target_dir.join("librubydex_sys.so")
|
|
75
|
+
"\t$(COPY) #{src_dylib} #{lib_dir}"
|
|
76
|
+
end
|
|
53
77
|
|
|
78
|
+
rust_srcs = Dir.glob("#{root_dir}/**/*.rs").reject { |path| path.include?("rust/target") }
|
|
54
79
|
makefile = File.read("Makefile")
|
|
80
|
+
|
|
55
81
|
new_makefile = makefile.gsub("$(OBJS): $(HDRS) $(ruby_headers)", <<~MAKEFILE.chomp)
|
|
56
82
|
.PHONY: compile_rust
|
|
57
83
|
RUST_SRCS = #{File.expand_path("Cargo.toml", root_dir)} #{File.expand_path("Cargo.lock", root_dir)} #{rust_srcs.join(" ")}
|
|
@@ -66,21 +92,16 @@ new_makefile = makefile.gsub("$(OBJS): $(HDRS) $(ruby_headers)", <<~MAKEFILE.cho
|
|
|
66
92
|
$(OBJS): $(HDRS) $(ruby_headers) .rust_built
|
|
67
93
|
MAKEFILE
|
|
68
94
|
|
|
69
|
-
new_makefile.gsub!(
|
|
70
|
-
|
|
95
|
+
new_makefile.gsub!(/(\$\(Q\) \$\(LDSHARED\) .*)/, <<~MAKEFILE.chomp)
|
|
96
|
+
\\1
|
|
97
|
+
#{copy_dylib_commands}
|
|
71
98
|
\t$(Q)$(RM) .rust_built
|
|
72
99
|
MAKEFILE
|
|
73
100
|
|
|
74
|
-
# Bundle all dependency licenses when building a release version of the gem
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
ERROR: cargo-about is not installed and required to build the release version of the gem.
|
|
79
|
-
Please install it by running:
|
|
80
|
-
cargo install cargo-about
|
|
81
|
-
MESSAGE
|
|
82
|
-
end
|
|
83
|
-
|
|
101
|
+
# Bundle all dependency licenses when building a release version of the gem. This only has to happen on CI where we
|
|
102
|
+
# precompile binaries. Oherwise, we're not redistributing the Rust dependencies as they are getting downloaded, compiled
|
|
103
|
+
# and linked on the user's machine
|
|
104
|
+
if release && system("cargo", "about", "--version", out: File::NULL, err: File::NULL)
|
|
84
105
|
licenses_file = root_dir.join("THIRD_PARTY_LICENSES.html")
|
|
85
106
|
about_config = root_dir.join("about.toml")
|
|
86
107
|
about_template = root_dir.join("about.hbs")
|