class Rubydex::Definition
Public Instance Methods
static VALUE rdxr_definition_comments(VALUE self) {
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
CommentArray *arr = rdx_definition_comments(graph, data->id);
if (arr == NULL || arr->len == 0) {
if (arr != NULL) {
rdx_definition_comments_free(arr);
}
return rb_ary_new();
}
VALUE ary = rb_ary_new_capa((long)arr->len);
for (size_t i = 0; i < arr->len; i++) {
CommentEntry entry = arr->items[i];
VALUE string = rb_utf8_str_new_cstr(entry.string);
Location *loc = entry.location;
VALUE location = rdxi_build_location_value(loc);
VALUE comment_kwargs = rb_hash_new();
rb_hash_aset(comment_kwargs, ID2SYM(rb_intern("string")), string);
rb_hash_aset(comment_kwargs, ID2SYM(rb_intern("location")), location);
VALUE comment = rb_class_new_instance_kw(1, &comment_kwargs, cComment, RB_PASS_KEYWORDS);
rb_ary_push(ary, comment);
}
// Free the array and all inner allocations on the Rust side
rdx_definition_comments_free(arr);
return ary;
}
Returns the source comments associated with this definition.
static VALUE rdxr_definition_declaration(VALUE self) {
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
const struct CDeclaration *decl = rdx_definition_declaration(graph, data->id);
if (decl == NULL) {
return Qnil;
}
VALUE decl_class = rdxi_declaration_class_for_kind(decl->kind);
VALUE argv[] = {data->graph_obj, ULL2NUM(decl->id)};
free_c_declaration(decl);
return rb_class_new_instance(2, argv, decl_class);
}
Returns the declaration this definition belongs to or nil when it cannot be located.
Source
static VALUE rdxr_definition_deprecated(VALUE self) {
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
bool deprecated = rdx_definition_is_deprecated(graph, data->id);
return deprecated ? Qtrue : Qfalse;
}
Returns whether this definition is marked as deprecated.
static VALUE rdxr_definition_lexical_nesting(VALUE self) {
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
VALUE nesting = rb_ary_new();
uint64_t definition_id = data->id;
while (true) {
const uint64_t *owner_id = rdx_definition_lexical_nesting_id(graph, definition_id);
if (owner_id == NULL) {
break;
}
rb_ary_push(nesting, rdxi_build_definition(data->graph_obj, graph, *owner_id));
definition_id = *owner_id;
free_u64(owner_id);
}
return nesting;
}
Returns the lexical nesting from the direct owner up to the root.
static VALUE rdxr_definition_lexical_owner(VALUE self) {
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
const uint64_t *owner_id = rdx_definition_lexical_nesting_id(graph, data->id);
if (owner_id == NULL) {
return Qnil;
}
VALUE owner = rdxi_build_definition(data->graph_obj, graph, *owner_id);
free_u64(owner_id);
return owner;
}
Returns the lexically enclosing definition, if any.
Source
static VALUE rdxr_definition_location(VALUE self) {
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
Location *loc = rdx_definition_location(graph, data->id);
VALUE location = rdxi_build_location_value(loc);
rdx_location_free(loc);
return location;
}
Returns the source location for this definition.
Source
static VALUE rdxr_definition_name(VALUE self) {
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
const char *name = rdx_definition_name(graph, data->id);
return rdxi_owned_c_string_to_ruby(name);
}
Returns the definition name.
static VALUE rdxr_definition_name_location(VALUE self) {
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
Location *loc = rdx_definition_name_location(graph, data->id);
if (loc == NULL) {
return Qnil;
}
VALUE location = rdxi_build_location_value(loc);
rdx_location_free(loc);
return location;
}
For class, module, singleton class, and method definitions, returns the location of just the name, such as “Bar” in “class Foo::Bar” or “foo” in “def foo”. For other definition types, returns nil.