rubydex 0.1.0.beta7-x86_64-linux → 0.1.0.beta9-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af219fca3433166a3612377811acbbfdb9168fe9d3d26c2360b5135790be7086
4
- data.tar.gz: 732a60f49ef00bda8a6568ce7aca09c9a82661312b26a0791735a33697ab4e5d
3
+ metadata.gz: edf2302fdc66d1c0e0560a3f59af9fb2acae9269b3db80dea4a70a70b7b6e0b4
4
+ data.tar.gz: 541747276861c81cb5d4339a9961a8d1b6ab1f58dc6f85f9f1ef0fb00b429449
5
5
  SHA512:
6
- metadata.gz: c2606966fe84e9a746b4ae84e5c070f442c2aa3bc02920b2d2ccd1301af76e8076eda7f49d6cff90f5d2297432a6d87aeea3a2f44afdc2495b5a1bb95987d25a
7
- data.tar.gz: dead00ebb43015352492f217c18cfa747ed7c817a719da0dc3b7b04460a390ffb5df03ff83521800784096ccd182679858e5f08cf6991f50d426531f061d3e59
6
+ metadata.gz: aa0cad72232ba1e55b22aac62c28cd294f06cff2a51ed6583ba8f25974f957adbfd20929266cd112d08b00aa637270d53527584d93fb785fb3be90733c5c62c4
7
+ data.tar.gz: 5521008248d353fc0779882e914d4b50fe882dcc614731298e99ecaff0b88a48aff3e3e0a19e6c7dc661cfac30cbf78e512bd34c3879de713b9cad67bd1305b5
@@ -2,6 +2,7 @@
2
2
  #include "definition.h"
3
3
  #include "graph.h"
4
4
  #include "handle.h"
5
+ #include "reference.h"
5
6
  #include "rustbindings.h"
6
7
  #include "utils.h"
7
8
 
@@ -10,6 +11,7 @@ VALUE cNamespace;
10
11
  VALUE cClass;
11
12
  VALUE cModule;
12
13
  VALUE cSingletonClass;
14
+ VALUE cTodo;
13
15
  VALUE cConstant;
14
16
  VALUE cConstantAlias;
15
17
  VALUE cMethod;
@@ -26,6 +28,8 @@ VALUE rdxi_declaration_class_for_kind(CDeclarationKind kind) {
26
28
  return cModule;
27
29
  case CDeclarationKind_SingletonClass:
28
30
  return cSingletonClass;
31
+ case CDeclarationKind_Todo:
32
+ return cTodo;
29
33
  case CDeclarationKind_Constant:
30
34
  return cConstant;
31
35
  case CDeclarationKind_ConstantAlias:
@@ -291,12 +295,49 @@ static VALUE rdxr_declaration_descendants(VALUE self) {
291
295
  return self;
292
296
  }
293
297
 
298
+ // Size function for the Declaration#references enumerator
299
+ static VALUE declaration_references_size(VALUE self, VALUE _args, VALUE _eobj) {
300
+ HandleData *data;
301
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
302
+
303
+ void *graph;
304
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
305
+
306
+ struct ReferencesIter *iter = rdx_declaration_references_iter_new(graph, data->id);
307
+ size_t len = rdx_references_iter_len(iter);
308
+ rdx_references_iter_free(iter);
309
+
310
+ return SIZET2NUM(len);
311
+ }
312
+
313
+ // Returns an enumerator for all references to this declaration
314
+ //
315
+ // Declaration#references: () -> Enumerator[Reference]
316
+ static VALUE rdxr_declaration_references(VALUE self) {
317
+ if (!rb_block_given_p()) {
318
+ return rb_enumeratorize_with_size(self, rb_str_new2("references"), 0, NULL, declaration_references_size);
319
+ }
320
+
321
+ HandleData *data;
322
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
323
+
324
+ void *graph;
325
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
326
+
327
+ void *iter = rdx_declaration_references_iter_new(graph, data->id);
328
+ VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
329
+ rb_ensure(rdxi_references_yield, args, rdxi_references_ensure, args);
330
+
331
+ return self;
332
+ }
333
+
294
334
  void rdxi_initialize_declaration(VALUE mRubydex) {
295
335
  cDeclaration = rb_define_class_under(mRubydex, "Declaration", rb_cObject);
296
336
  cNamespace = rb_define_class_under(mRubydex, "Namespace", cDeclaration);
297
337
  cClass = rb_define_class_under(mRubydex, "Class", cNamespace);
298
338
  cModule = rb_define_class_under(mRubydex, "Module", cNamespace);
299
339
  cSingletonClass = rb_define_class_under(mRubydex, "SingletonClass", cNamespace);
340
+ cTodo = rb_define_class_under(mRubydex, "Todo", cNamespace);
300
341
  cConstant = rb_define_class_under(mRubydex, "Constant", cDeclaration);
301
342
  cConstantAlias = rb_define_class_under(mRubydex, "ConstantAlias", cDeclaration);
302
343
  cMethod = rb_define_class_under(mRubydex, "Method", cDeclaration);
@@ -309,6 +350,7 @@ void rdxi_initialize_declaration(VALUE mRubydex) {
309
350
  rb_define_method(cDeclaration, "name", rdxr_declaration_name, 0);
310
351
  rb_define_method(cDeclaration, "unqualified_name", rdxr_declaration_unqualified_name, 0);
311
352
  rb_define_method(cDeclaration, "definitions", rdxr_declaration_definitions, 0);
353
+ rb_define_method(cDeclaration, "references", rdxr_declaration_references, 0);
312
354
  rb_define_method(cDeclaration, "owner", rdxr_declaration_owner, 0);
313
355
 
314
356
  // Namespace only methods
@@ -9,6 +9,7 @@ extern VALUE cNamespace;
9
9
  extern VALUE cClass;
10
10
  extern VALUE cModule;
11
11
  extern VALUE cSingletonClass;
12
+ extern VALUE cTodo;
12
13
  extern VALUE cConstant;
13
14
  extern VALUE cConstantAlias;
14
15
  extern VALUE cMethod;
data/ext/rubydex/graph.c CHANGED
@@ -228,31 +228,6 @@ static VALUE rdxr_graph_aref(VALUE self, VALUE key) {
228
228
  return rb_class_new_instance(2, argv, decl_class);
229
229
  }
230
230
 
231
- // Body function for rb_ensure for the reference enumerators
232
- static VALUE graph_references_yield(VALUE args) {
233
- VALUE self = rb_ary_entry(args, 0);
234
- void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
235
-
236
- uint64_t id = 0;
237
- ReferenceKind kind;
238
- while (rdx_references_iter_next(iter, &id, &kind)) {
239
- VALUE ref_class = rdxi_reference_class_for_kind(kind);
240
- VALUE argv[] = {self, ULL2NUM(id)};
241
- VALUE obj = rb_class_new_instance(2, argv, ref_class);
242
- rb_yield(obj);
243
- }
244
-
245
- return Qnil;
246
- }
247
-
248
- // Ensure function for rb_ensure for the reference enumerators to always free the iterator
249
- static VALUE graph_references_ensure(VALUE args) {
250
- void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
251
- rdx_references_iter_free(iter);
252
-
253
- return Qnil;
254
- }
255
-
256
231
  // Size function for the constant_references enumerator
257
232
  static VALUE graph_constant_references_size(VALUE self, VALUE _args, VALUE _eobj) {
258
233
  void *graph;
@@ -278,7 +253,7 @@ static VALUE rdxr_graph_constant_references(VALUE self) {
278
253
 
279
254
  void *iter = rdx_graph_constant_references_iter_new(graph);
280
255
  VALUE args = rb_ary_new_from_args(2, self, ULL2NUM((uintptr_t)iter));
281
- rb_ensure(graph_references_yield, args, graph_references_ensure, args);
256
+ rb_ensure(rdxi_references_yield, args, rdxi_references_ensure, args);
282
257
 
283
258
  return self;
284
259
  }
@@ -308,7 +283,7 @@ static VALUE rdxr_graph_method_references(VALUE self) {
308
283
 
309
284
  void *iter = rdx_graph_method_references_iter_new(graph);
310
285
  VALUE args = rb_ary_new_from_args(2, self, ULL2NUM((uintptr_t)iter));
311
- rb_ensure(graph_references_yield, args, graph_references_ensure, args);
286
+ rb_ensure(rdxi_references_yield, args, rdxi_references_ensure, args);
312
287
 
313
288
  return self;
314
289
  }
data/ext/rubydex/utils.c CHANGED
@@ -1,5 +1,6 @@
1
1
  #include "utils.h"
2
2
  #include "declaration.h"
3
+ #include "reference.h"
3
4
  #include "rustbindings.h"
4
5
 
5
6
  // Convert a Ruby array of strings into a double char pointer so that we can pass that to Rust.
@@ -50,3 +51,26 @@ VALUE rdxi_declarations_ensure(VALUE args) {
50
51
  rdx_graph_declarations_iter_free(iter);
51
52
  return Qnil;
52
53
  }
54
+
55
+ // Yield body for iterating over references
56
+ VALUE rdxi_references_yield(VALUE args) {
57
+ VALUE graph_obj = rb_ary_entry(args, 0);
58
+ void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
59
+
60
+ CReference cref;
61
+ while (rdx_references_iter_next(iter, &cref)) {
62
+ VALUE ref_class = rdxi_reference_class_for_kind(cref.kind);
63
+ VALUE argv[] = {graph_obj, ULL2NUM(cref.id)};
64
+ VALUE obj = rb_class_new_instance(2, argv, ref_class);
65
+ rb_yield(obj);
66
+ }
67
+
68
+ return Qnil;
69
+ }
70
+
71
+ // Ensure function for iterating over references to always free the iterator
72
+ VALUE rdxi_references_ensure(VALUE args) {
73
+ void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
74
+ rdx_references_iter_free(iter);
75
+ return Qnil;
76
+ }
data/ext/rubydex/utils.h CHANGED
@@ -16,4 +16,10 @@ VALUE rdxi_declarations_yield(VALUE args);
16
16
  // Ensure function for iterating over declarations to always free the iterator
17
17
  VALUE rdxi_declarations_ensure(VALUE args);
18
18
 
19
+ // Yield body for iterating over references
20
+ VALUE rdxi_references_yield(VALUE args);
21
+
22
+ // Ensure function for iterating over references to always free the iterator
23
+ VALUE rdxi_references_ensure(VALUE args);
24
+
19
25
  #endif // RUBYDEX_UTILS_H
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubydex
4
- VERSION = "0.1.0.beta7"
4
+ VERSION = "0.1.0.beta9"
5
5
  end