rubydex 0.1.0.beta11 → 0.1.0.beta13
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/LICENSE.txt +23 -23
- data/README.md +125 -125
- data/THIRD_PARTY_LICENSES.html +2018 -945
- data/exe/rdx +47 -47
- data/ext/rubydex/declaration.c +453 -388
- data/ext/rubydex/declaration.h +23 -23
- data/ext/rubydex/definition.c +284 -197
- data/ext/rubydex/definition.h +28 -28
- data/ext/rubydex/diagnostic.c +6 -6
- data/ext/rubydex/diagnostic.h +11 -11
- data/ext/rubydex/document.c +97 -98
- data/ext/rubydex/document.h +10 -10
- data/ext/rubydex/extconf.rb +146 -127
- data/ext/rubydex/graph.c +701 -512
- data/ext/rubydex/graph.h +10 -10
- data/ext/rubydex/handle.h +44 -44
- data/ext/rubydex/location.c +22 -22
- data/ext/rubydex/location.h +15 -15
- data/ext/rubydex/reference.c +123 -104
- data/ext/rubydex/reference.h +15 -16
- data/ext/rubydex/rubydex.c +22 -22
- data/ext/rubydex/utils.c +108 -86
- data/ext/rubydex/utils.h +34 -28
- data/lib/rubydex/comment.rb +17 -17
- data/lib/rubydex/declaration.rb +11 -0
- data/lib/rubydex/diagnostic.rb +21 -21
- data/lib/rubydex/failures.rb +15 -15
- data/lib/rubydex/graph.rb +98 -92
- data/lib/rubydex/keyword.rb +17 -0
- data/lib/rubydex/keyword_parameter.rb +13 -0
- data/lib/rubydex/location.rb +90 -90
- data/lib/rubydex/mixin.rb +22 -0
- data/lib/rubydex/version.rb +5 -5
- data/lib/rubydex.rb +24 -20
- data/rbi/rubydex.rbi +425 -310
- data/rust/Cargo.lock +1851 -1851
- data/rust/Cargo.toml +29 -29
- data/rust/about.toml +10 -10
- data/rust/{about.hbs → about_templates/about.hbs} +81 -78
- data/rust/about_templates/mingw_licenses.hbs +1071 -0
- data/rust/rubydex/Cargo.toml +42 -42
- data/rust/rubydex/src/compile_assertions.rs +13 -13
- data/rust/rubydex/src/diagnostic.rs +110 -109
- data/rust/rubydex/src/errors.rs +28 -28
- data/rust/rubydex/src/indexing/local_graph.rs +224 -224
- data/rust/rubydex/src/indexing/rbs_indexer.rs +1551 -1554
- data/rust/rubydex/src/indexing/ruby_indexer.rs +2329 -6753
- data/rust/rubydex/src/indexing/ruby_indexer_tests.rs +4962 -0
- data/rust/rubydex/src/indexing.rs +210 -210
- data/rust/rubydex/src/integrity.rs +279 -278
- data/rust/rubydex/src/job_queue.rs +199 -205
- data/rust/rubydex/src/lib.rs +17 -17
- data/rust/rubydex/src/listing.rs +371 -272
- data/rust/rubydex/src/main.rs +160 -160
- data/rust/rubydex/src/model/built_in.rs +83 -0
- data/rust/rubydex/src/model/comment.rs +24 -24
- data/rust/rubydex/src/model/declaration.rs +679 -588
- data/rust/rubydex/src/model/definitions.rs +1682 -1602
- data/rust/rubydex/src/model/document.rs +222 -252
- data/rust/rubydex/src/model/encoding.rs +22 -22
- data/rust/rubydex/src/model/graph.rs +3782 -3556
- data/rust/rubydex/src/model/id.rs +110 -110
- data/rust/rubydex/src/model/identity_maps.rs +58 -58
- data/rust/rubydex/src/model/ids.rs +60 -38
- data/rust/rubydex/src/model/keywords.rs +256 -256
- data/rust/rubydex/src/model/name.rs +298 -298
- data/rust/rubydex/src/model/references.rs +111 -111
- data/rust/rubydex/src/model/string_ref.rs +50 -50
- data/rust/rubydex/src/model/visibility.rs +41 -41
- data/rust/rubydex/src/model.rs +15 -14
- data/rust/rubydex/src/offset.rs +147 -147
- data/rust/rubydex/src/position.rs +6 -6
- data/rust/rubydex/src/query.rs +1841 -1700
- data/rust/rubydex/src/resolution.rs +1852 -5895
- data/rust/rubydex/src/resolution_tests.rs +4701 -0
- data/rust/rubydex/src/stats/memory.rs +71 -71
- data/rust/rubydex/src/stats/orphan_report.rs +264 -263
- data/rust/rubydex/src/stats/timer.rs +127 -127
- data/rust/rubydex/src/stats.rs +11 -11
- data/rust/rubydex/src/test_utils/context.rs +226 -226
- data/rust/rubydex/src/test_utils/graph_test.rs +730 -679
- data/rust/rubydex/src/test_utils/local_graph_test.rs +602 -602
- data/rust/rubydex/src/test_utils.rs +52 -52
- data/rust/rubydex/src/visualization/dot.rs +192 -176
- data/rust/rubydex/src/visualization.rs +6 -6
- data/rust/rubydex/tests/cli.rs +185 -167
- data/rust/rubydex-mcp/Cargo.toml +28 -28
- data/rust/rubydex-mcp/src/main.rs +48 -48
- data/rust/rubydex-mcp/src/server.rs +1145 -1145
- data/rust/rubydex-mcp/src/tools.rs +49 -49
- data/rust/rubydex-mcp/tests/mcp.rs +302 -302
- data/rust/rubydex-sys/Cargo.toml +20 -20
- data/rust/rubydex-sys/build.rs +14 -14
- data/rust/rubydex-sys/cbindgen.toml +12 -12
- data/rust/rubydex-sys/src/declaration_api.rs +485 -469
- data/rust/rubydex-sys/src/definition_api.rs +443 -352
- data/rust/rubydex-sys/src/diagnostic_api.rs +99 -99
- data/rust/rubydex-sys/src/document_api.rs +85 -54
- data/rust/rubydex-sys/src/graph_api.rs +1017 -700
- data/rust/rubydex-sys/src/lib.rs +79 -9
- data/rust/rubydex-sys/src/location_api.rs +79 -79
- data/rust/rubydex-sys/src/name_api.rs +187 -135
- data/rust/rubydex-sys/src/reference_api.rs +267 -195
- data/rust/rubydex-sys/src/utils.rs +70 -70
- data/rust/rustfmt.toml +2 -2
- metadata +16 -9
- data/lib/rubydex/librubydex_sys.so +0 -0
|
@@ -1,195 +1,267 @@
|
|
|
1
|
-
//! C API for exposing references through ID handles (like definitions)
|
|
2
|
-
|
|
3
|
-
use std::ffi::CString;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
use crate::
|
|
7
|
-
use
|
|
8
|
-
use
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#[
|
|
50
|
-
pub
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
///
|
|
58
|
-
///
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
///
|
|
98
|
-
///
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
/// #
|
|
105
|
-
///
|
|
106
|
-
///
|
|
107
|
-
#[unsafe(no_mangle)]
|
|
108
|
-
pub unsafe extern "C" fn
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/// Returns the UTF-8 name string for a
|
|
124
|
-
/// Caller must free with `free_c_string`.
|
|
125
|
-
///
|
|
126
|
-
/// # Safety
|
|
127
|
-
///
|
|
128
|
-
/// Assumes pointer is valid.
|
|
129
|
-
///
|
|
130
|
-
/// # Panics
|
|
131
|
-
///
|
|
132
|
-
/// This function will panic if the reference cannot be found.
|
|
133
|
-
#[unsafe(no_mangle)]
|
|
134
|
-
pub unsafe extern "C" fn
|
|
135
|
-
with_graph(pointer, |graph| {
|
|
136
|
-
let ref_id =
|
|
137
|
-
let reference = graph.
|
|
138
|
-
let name = graph
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.
|
|
142
|
-
.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
///
|
|
150
|
-
///
|
|
151
|
-
///
|
|
152
|
-
///
|
|
153
|
-
///
|
|
154
|
-
///
|
|
155
|
-
///
|
|
156
|
-
///
|
|
157
|
-
///
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
let
|
|
163
|
-
let
|
|
164
|
-
|
|
165
|
-
.
|
|
166
|
-
.
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
///
|
|
174
|
-
///
|
|
175
|
-
///
|
|
176
|
-
///
|
|
177
|
-
///
|
|
178
|
-
/// - `
|
|
179
|
-
///
|
|
180
|
-
///
|
|
181
|
-
///
|
|
182
|
-
///
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
let
|
|
188
|
-
let
|
|
189
|
-
|
|
190
|
-
.
|
|
191
|
-
.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
1
|
+
//! C API for exposing references through ID handles (like definitions)
|
|
2
|
+
|
|
3
|
+
use std::ffi::CString;
|
|
4
|
+
use std::ptr;
|
|
5
|
+
|
|
6
|
+
use crate::declaration_api::CDeclaration;
|
|
7
|
+
use crate::graph_api::{GraphPointer, with_graph};
|
|
8
|
+
use crate::location_api::{Location, create_location_for_uri_and_offset};
|
|
9
|
+
use libc::c_char;
|
|
10
|
+
use rubydex::model::graph::Graph;
|
|
11
|
+
use rubydex::model::ids::{ConstantReferenceId, MethodReferenceId};
|
|
12
|
+
use rubydex::model::name::NameRef;
|
|
13
|
+
|
|
14
|
+
#[repr(C)]
|
|
15
|
+
#[derive(Debug, Clone, Copy)]
|
|
16
|
+
pub struct CConstantReference {
|
|
17
|
+
pub id: u64,
|
|
18
|
+
pub declaration_id: u64,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
impl CConstantReference {
|
|
22
|
+
/// Build a `CConstantReference` from a graph and reference ID. Sets `declaration_id` to 0 when the reference is
|
|
23
|
+
/// unresolved.
|
|
24
|
+
///
|
|
25
|
+
/// # Panics
|
|
26
|
+
///
|
|
27
|
+
/// This function will panic if there's inconsistent data in the graph
|
|
28
|
+
#[must_use]
|
|
29
|
+
pub fn from_id(graph: &Graph, ref_id: ConstantReferenceId) -> Self {
|
|
30
|
+
let reference = graph
|
|
31
|
+
.constant_references()
|
|
32
|
+
.get(&ref_id)
|
|
33
|
+
.expect("Constant reference not found");
|
|
34
|
+
|
|
35
|
+
let name_ref = graph.names().get(reference.name_id()).expect("Name ID should exist");
|
|
36
|
+
|
|
37
|
+
let declaration_id = match name_ref {
|
|
38
|
+
NameRef::Resolved(resolved) => **resolved.declaration_id(),
|
|
39
|
+
NameRef::Unresolved(_) => 0,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
Self {
|
|
43
|
+
id: *ref_id,
|
|
44
|
+
declaration_id,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#[derive(Debug)]
|
|
50
|
+
pub struct ConstantReferencesIter {
|
|
51
|
+
entries: Box<[CConstantReference]>,
|
|
52
|
+
index: usize,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
iterator!(ConstantReferencesIter, entries: CConstantReference);
|
|
56
|
+
|
|
57
|
+
/// # Safety
|
|
58
|
+
/// `iter` must be a valid pointer previously returned by `ConstantReferencesIter::new`.
|
|
59
|
+
#[unsafe(no_mangle)]
|
|
60
|
+
pub unsafe extern "C" fn rdx_constant_references_iter_len(iter: *const ConstantReferencesIter) -> usize {
|
|
61
|
+
unsafe { ConstantReferencesIter::len(iter) }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// # Safety
|
|
65
|
+
/// - `iter` must be a valid pointer previously returned by `ConstantReferencesIter::new`.
|
|
66
|
+
/// - `out` must be a valid, writable pointer.
|
|
67
|
+
#[unsafe(no_mangle)]
|
|
68
|
+
pub unsafe extern "C" fn rdx_constant_references_iter_next(
|
|
69
|
+
iter: *mut ConstantReferencesIter,
|
|
70
|
+
out: *mut CConstantReference,
|
|
71
|
+
) -> bool {
|
|
72
|
+
unsafe { ConstantReferencesIter::next(iter, out) }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// # Safety
|
|
76
|
+
/// - `iter` must be a pointer previously returned by `ConstantReferencesIter::new`.
|
|
77
|
+
/// - `iter` must not be used after being freed.
|
|
78
|
+
#[unsafe(no_mangle)]
|
|
79
|
+
pub unsafe extern "C" fn rdx_constant_references_iter_free(iter: *mut ConstantReferencesIter) {
|
|
80
|
+
unsafe { ConstantReferencesIter::free(iter) }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#[repr(C)]
|
|
84
|
+
#[derive(Debug, Clone, Copy)]
|
|
85
|
+
pub struct CMethodReference {
|
|
86
|
+
pub id: u64,
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#[derive(Debug)]
|
|
90
|
+
pub struct MethodReferencesIter {
|
|
91
|
+
entries: Box<[CMethodReference]>,
|
|
92
|
+
index: usize,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
iterator!(MethodReferencesIter, entries: CMethodReference);
|
|
96
|
+
|
|
97
|
+
/// # Safety
|
|
98
|
+
/// `iter` must be a valid pointer previously returned by `MethodReferencesIter::new`.
|
|
99
|
+
#[unsafe(no_mangle)]
|
|
100
|
+
pub unsafe extern "C" fn rdx_method_references_iter_len(iter: *const MethodReferencesIter) -> usize {
|
|
101
|
+
unsafe { MethodReferencesIter::len(iter) }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/// # Safety
|
|
105
|
+
/// - `iter` must be a valid pointer previously returned by `MethodReferencesIter::new`.
|
|
106
|
+
/// - `out` must be a valid, writable pointer.
|
|
107
|
+
#[unsafe(no_mangle)]
|
|
108
|
+
pub unsafe extern "C" fn rdx_method_references_iter_next(
|
|
109
|
+
iter: *mut MethodReferencesIter,
|
|
110
|
+
out: *mut CMethodReference,
|
|
111
|
+
) -> bool {
|
|
112
|
+
unsafe { MethodReferencesIter::next(iter, out) }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/// # Safety
|
|
116
|
+
/// - `iter` must be a pointer previously returned by `MethodReferencesIter::new`.
|
|
117
|
+
/// - `iter` must not be used after being freed.
|
|
118
|
+
#[unsafe(no_mangle)]
|
|
119
|
+
pub unsafe extern "C" fn rdx_method_references_iter_free(iter: *mut MethodReferencesIter) {
|
|
120
|
+
unsafe { MethodReferencesIter::free(iter) }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/// Returns the UTF-8 name string for a constant reference id.
|
|
124
|
+
/// Caller must free with `free_c_string`.
|
|
125
|
+
///
|
|
126
|
+
/// # Safety
|
|
127
|
+
///
|
|
128
|
+
/// Assumes pointer is valid.
|
|
129
|
+
///
|
|
130
|
+
/// # Panics
|
|
131
|
+
///
|
|
132
|
+
/// This function will panic if the reference cannot be found.
|
|
133
|
+
#[unsafe(no_mangle)]
|
|
134
|
+
pub unsafe extern "C" fn rdx_constant_reference_name(pointer: GraphPointer, reference_id: u64) -> *const c_char {
|
|
135
|
+
with_graph(pointer, |graph| {
|
|
136
|
+
let ref_id = ConstantReferenceId::new(reference_id);
|
|
137
|
+
let reference = graph.constant_references().get(&ref_id).expect("Reference not found");
|
|
138
|
+
let name = graph.names().get(reference.name_id()).expect("Name ID should exist");
|
|
139
|
+
|
|
140
|
+
let name_string = graph
|
|
141
|
+
.strings()
|
|
142
|
+
.get(name.str())
|
|
143
|
+
.expect("String ID should exist")
|
|
144
|
+
.to_string();
|
|
145
|
+
CString::new(name_string).unwrap().into_raw().cast_const()
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/// Returns the UTF-8 name string for a method reference id.
|
|
150
|
+
/// Caller must free with `free_c_string`.
|
|
151
|
+
///
|
|
152
|
+
/// # Safety
|
|
153
|
+
///
|
|
154
|
+
/// Assumes pointer is valid.
|
|
155
|
+
///
|
|
156
|
+
/// # Panics
|
|
157
|
+
///
|
|
158
|
+
/// This function will panic if the reference cannot be found.
|
|
159
|
+
#[unsafe(no_mangle)]
|
|
160
|
+
pub unsafe extern "C" fn rdx_method_reference_name(pointer: GraphPointer, reference_id: u64) -> *const c_char {
|
|
161
|
+
with_graph(pointer, |graph| {
|
|
162
|
+
let ref_id = MethodReferenceId::new(reference_id);
|
|
163
|
+
let reference = graph.method_references().get(&ref_id).expect("Reference not found");
|
|
164
|
+
let name = graph
|
|
165
|
+
.strings()
|
|
166
|
+
.get(reference.str())
|
|
167
|
+
.expect("Name ID should exist")
|
|
168
|
+
.to_string();
|
|
169
|
+
CString::new(name).unwrap().into_raw().cast_const()
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/// Returns a newly allocated `Location` for the given constant reference id.
|
|
174
|
+
/// Caller must free the returned pointer with `rdx_location_free`.
|
|
175
|
+
///
|
|
176
|
+
/// # Safety
|
|
177
|
+
///
|
|
178
|
+
/// - `pointer` must be a valid pointer previously returned by `rdx_graph_new`.
|
|
179
|
+
/// - `reference_id` must be a valid reference id.
|
|
180
|
+
///
|
|
181
|
+
/// # Panics
|
|
182
|
+
///
|
|
183
|
+
/// This function will panic if a reference or document cannot be found.
|
|
184
|
+
#[unsafe(no_mangle)]
|
|
185
|
+
pub unsafe extern "C" fn rdx_constant_reference_location(pointer: GraphPointer, reference_id: u64) -> *mut Location {
|
|
186
|
+
with_graph(pointer, |graph| {
|
|
187
|
+
let ref_id = ConstantReferenceId::new(reference_id);
|
|
188
|
+
let reference = graph.constant_references().get(&ref_id).expect("Reference not found");
|
|
189
|
+
let document = graph
|
|
190
|
+
.documents()
|
|
191
|
+
.get(&reference.uri_id())
|
|
192
|
+
.expect("Document should exist");
|
|
193
|
+
|
|
194
|
+
create_location_for_uri_and_offset(graph, document, reference.offset())
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/// Returns the declaration that the given resolved constant reference points to. Returns NULL if the reference is
|
|
199
|
+
/// unresolved. Caller must free with `free_c_declaration`.
|
|
200
|
+
///
|
|
201
|
+
/// # Safety
|
|
202
|
+
///
|
|
203
|
+
/// Assumes pointer is valid.
|
|
204
|
+
///
|
|
205
|
+
/// # Panics
|
|
206
|
+
///
|
|
207
|
+
/// This function will panic if the reference cannot be found.
|
|
208
|
+
#[unsafe(no_mangle)]
|
|
209
|
+
pub unsafe extern "C" fn rdx_resolved_constant_reference_declaration(
|
|
210
|
+
pointer: GraphPointer,
|
|
211
|
+
reference_id: u64,
|
|
212
|
+
) -> *const CDeclaration {
|
|
213
|
+
with_graph(pointer, |graph| {
|
|
214
|
+
let ref_id = ConstantReferenceId::new(reference_id);
|
|
215
|
+
let reference = graph.constant_references().get(&ref_id).expect("Reference not found");
|
|
216
|
+
let name_ref = graph.names().get(reference.name_id()).expect("Name ID should exist");
|
|
217
|
+
|
|
218
|
+
match name_ref {
|
|
219
|
+
NameRef::Resolved(resolved) => {
|
|
220
|
+
let decl_id = *resolved.declaration_id();
|
|
221
|
+
let decl = graph.declarations().get(&decl_id).expect("Declaration not found");
|
|
222
|
+
Box::into_raw(Box::new(CDeclaration::from_declaration(decl_id, decl))).cast_const()
|
|
223
|
+
}
|
|
224
|
+
NameRef::Unresolved(_) => ptr::null(),
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/// Returns a newly allocated `Location` for the given method reference id.
|
|
230
|
+
/// Caller must free the returned pointer with `rdx_location_free`.
|
|
231
|
+
///
|
|
232
|
+
/// # Safety
|
|
233
|
+
///
|
|
234
|
+
/// - `pointer` must be a valid pointer previously returned by `rdx_graph_new`.
|
|
235
|
+
/// - `reference_id` must be a valid reference id.
|
|
236
|
+
///
|
|
237
|
+
/// # Panics
|
|
238
|
+
///
|
|
239
|
+
/// This function will panic if a reference or document cannot be found.
|
|
240
|
+
#[unsafe(no_mangle)]
|
|
241
|
+
pub unsafe extern "C" fn rdx_method_reference_location(pointer: GraphPointer, reference_id: u64) -> *mut Location {
|
|
242
|
+
with_graph(pointer, |graph| {
|
|
243
|
+
let ref_id = MethodReferenceId::new(reference_id);
|
|
244
|
+
let reference = graph.method_references().get(&ref_id).expect("Reference not found");
|
|
245
|
+
let document = graph
|
|
246
|
+
.documents()
|
|
247
|
+
.get(&reference.uri_id())
|
|
248
|
+
.expect("Document should exist");
|
|
249
|
+
|
|
250
|
+
create_location_for_uri_and_offset(graph, document, reference.offset())
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/// Frees a `CConstantReference` previously returned by an FFI function.
|
|
255
|
+
///
|
|
256
|
+
/// # Safety
|
|
257
|
+
/// - `ptr` must be a valid pointer previously returned by an FFI function that allocates a `CConstantReference`, or
|
|
258
|
+
/// NULL.
|
|
259
|
+
/// - `ptr` must not be used after being freed.
|
|
260
|
+
#[unsafe(no_mangle)]
|
|
261
|
+
pub unsafe extern "C" fn free_c_constant_reference(ptr: *const CConstantReference) {
|
|
262
|
+
if !ptr.is_null() {
|
|
263
|
+
unsafe {
|
|
264
|
+
let _ = Box::from_raw(ptr.cast_mut());
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
use libc::{c_char, size_t};
|
|
2
|
-
use std::ffi::{CStr, CString};
|
|
3
|
-
use std::slice;
|
|
4
|
-
use std::str::Utf8Error;
|
|
5
|
-
|
|
6
|
-
/// Converts a C array of strings into a Vec<String>
|
|
7
|
-
///
|
|
8
|
-
/// # Safety
|
|
9
|
-
///
|
|
10
|
-
/// This function is unsafe because it attempts to instantiate a Vec<String> from a raw char** pointer
|
|
11
|
-
///
|
|
12
|
-
/// # Errors
|
|
13
|
-
///
|
|
14
|
-
/// This function errors if any of the strings inside the array contain invalid UTF-8 data
|
|
15
|
-
pub unsafe fn convert_double_pointer_to_vec(data: *const *const c_char, len: size_t) -> Result<Vec<String>, Utf8Error> {
|
|
16
|
-
unsafe {
|
|
17
|
-
slice::from_raw_parts(data, len)
|
|
18
|
-
.iter()
|
|
19
|
-
.map(|arg| CStr::from_ptr(*arg).to_str().map(ToString::to_string))
|
|
20
|
-
.collect()
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/// # Safety
|
|
25
|
-
///
|
|
26
|
-
/// This function is unsafe because it dereferences the char pointer, which needs to be valid for the duration of the
|
|
27
|
-
/// function
|
|
28
|
-
///
|
|
29
|
-
/// # Errors
|
|
30
|
-
///
|
|
31
|
-
/// This function errors if any of the strings inside the array contain invalid UTF-8 data
|
|
32
|
-
pub unsafe fn convert_char_ptr_to_string(data: *const c_char) -> Result<String, Utf8Error> {
|
|
33
|
-
unsafe { CStr::from_ptr(data).to_str().map(ToString::to_string) }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/// Frees a `CString` allocated on the Rust side
|
|
37
|
-
#[unsafe(no_mangle)]
|
|
38
|
-
pub extern "C" fn free_c_string(ptr: *const c_char) {
|
|
39
|
-
unsafe {
|
|
40
|
-
let _ = CString::from_raw(ptr.cast_mut());
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/// Frees a boxed u64 allocated on the Rust side
|
|
45
|
-
#[unsafe(no_mangle)]
|
|
46
|
-
pub extern "C" fn free_u64(ptr: *const u64) {
|
|
47
|
-
unsafe {
|
|
48
|
-
let _ = Box::from_raw(ptr.cast_mut());
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/// Frees an array of C strings allocated by Rust.
|
|
53
|
-
///
|
|
54
|
-
/// # Safety
|
|
55
|
-
/// - `ptr` must be a pointer to a boxed slice of C strings previously allocated by this crate.
|
|
56
|
-
/// - `count` must be the length of the array.
|
|
57
|
-
/// - `ptr` must not be used after being freed.
|
|
58
|
-
#[unsafe(no_mangle)]
|
|
59
|
-
pub unsafe extern "C" fn free_c_string_array(ptr: *const *const c_char, count: usize) {
|
|
60
|
-
if ptr.is_null() {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let slice = unsafe { Box::from_raw(std::ptr::slice_from_raw_parts_mut(ptr.cast_mut(), count)) };
|
|
65
|
-
let _: Vec<_> = slice
|
|
66
|
-
.iter()
|
|
67
|
-
.filter(|p| !p.is_null())
|
|
68
|
-
.map(|arg| unsafe { CString::from_raw((*arg).cast_mut()) })
|
|
69
|
-
.collect();
|
|
70
|
-
}
|
|
1
|
+
use libc::{c_char, size_t};
|
|
2
|
+
use std::ffi::{CStr, CString};
|
|
3
|
+
use std::slice;
|
|
4
|
+
use std::str::Utf8Error;
|
|
5
|
+
|
|
6
|
+
/// Converts a C array of strings into a Vec<String>
|
|
7
|
+
///
|
|
8
|
+
/// # Safety
|
|
9
|
+
///
|
|
10
|
+
/// This function is unsafe because it attempts to instantiate a Vec<String> from a raw char** pointer
|
|
11
|
+
///
|
|
12
|
+
/// # Errors
|
|
13
|
+
///
|
|
14
|
+
/// This function errors if any of the strings inside the array contain invalid UTF-8 data
|
|
15
|
+
pub unsafe fn convert_double_pointer_to_vec(data: *const *const c_char, len: size_t) -> Result<Vec<String>, Utf8Error> {
|
|
16
|
+
unsafe {
|
|
17
|
+
slice::from_raw_parts(data, len)
|
|
18
|
+
.iter()
|
|
19
|
+
.map(|arg| CStr::from_ptr(*arg).to_str().map(ToString::to_string))
|
|
20
|
+
.collect()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// # Safety
|
|
25
|
+
///
|
|
26
|
+
/// This function is unsafe because it dereferences the char pointer, which needs to be valid for the duration of the
|
|
27
|
+
/// function
|
|
28
|
+
///
|
|
29
|
+
/// # Errors
|
|
30
|
+
///
|
|
31
|
+
/// This function errors if any of the strings inside the array contain invalid UTF-8 data
|
|
32
|
+
pub unsafe fn convert_char_ptr_to_string(data: *const c_char) -> Result<String, Utf8Error> {
|
|
33
|
+
unsafe { CStr::from_ptr(data).to_str().map(ToString::to_string) }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// Frees a `CString` allocated on the Rust side
|
|
37
|
+
#[unsafe(no_mangle)]
|
|
38
|
+
pub extern "C" fn free_c_string(ptr: *const c_char) {
|
|
39
|
+
unsafe {
|
|
40
|
+
let _ = CString::from_raw(ptr.cast_mut());
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// Frees a boxed u64 allocated on the Rust side
|
|
45
|
+
#[unsafe(no_mangle)]
|
|
46
|
+
pub extern "C" fn free_u64(ptr: *const u64) {
|
|
47
|
+
unsafe {
|
|
48
|
+
let _ = Box::from_raw(ptr.cast_mut());
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// Frees an array of C strings allocated by Rust.
|
|
53
|
+
///
|
|
54
|
+
/// # Safety
|
|
55
|
+
/// - `ptr` must be a pointer to a boxed slice of C strings previously allocated by this crate.
|
|
56
|
+
/// - `count` must be the length of the array.
|
|
57
|
+
/// - `ptr` must not be used after being freed.
|
|
58
|
+
#[unsafe(no_mangle)]
|
|
59
|
+
pub unsafe extern "C" fn free_c_string_array(ptr: *const *const c_char, count: usize) {
|
|
60
|
+
if ptr.is_null() {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let slice = unsafe { Box::from_raw(std::ptr::slice_from_raw_parts_mut(ptr.cast_mut(), count)) };
|
|
65
|
+
let _: Vec<_> = slice
|
|
66
|
+
.iter()
|
|
67
|
+
.filter(|p| !p.is_null())
|
|
68
|
+
.map(|arg| unsafe { CString::from_raw((*arg).cast_mut()) })
|
|
69
|
+
.collect();
|
|
70
|
+
}
|
data/rust/rustfmt.toml
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
max_width = 120
|
|
2
|
-
edition = "2024"
|
|
1
|
+
max_width = 120
|
|
2
|
+
edition = "2024"
|