Class: Rubydex::Definition
- Inherits:
-
Object
- Object
- Rubydex::Definition
- Defined in:
- ext/rubydex/definition.c
Direct Known Subclasses
AttrAccessorDefinition, AttrReaderDefinition, AttrWriterDefinition, ClassDefinition, ClassVariableDefinition, ConstantAliasDefinition, ConstantDefinition, ConstantVisibilityDefinition, GlobalVariableAliasDefinition, GlobalVariableDefinition, InstanceVariableDefinition, MethodAliasDefinition, MethodDefinition, MethodVisibilityDefinition, ModuleDefinition, SingletonClassDefinition
Instance Method Summary collapse
-
#comments ⇒ Object
Definition#comments -> [Rubydex::Comment].
-
#declaration ⇒ Object
‘Graph#resolve` has run).
-
#deprecated? ⇒ Boolean
Definition#deprecated? -> bool.
- #initialize ⇒ Object constructor
-
#location ⇒ Object
Definition#location -> Rubydex::Location.
-
#name ⇒ Object
Definition#name -> String.
-
#name_location ⇒ Object
(e.g., “Bar” in “class Foo::Bar”).
Constructor Details
#initialize ⇒ Object
Instance Method Details
#comments ⇒ Object
Definition#comments -> [Rubydex::Comment]
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'ext/rubydex/definition.c', line 90
static VALUE rdxr_definition_comments(VALUE self) {
HandleData *data;
TypedData_Get_Struct(self, HandleData, &handle_type, data);
void *graph;
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
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;
}
|
#declaration ⇒ Object
‘Graph#resolve` has run).
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'ext/rubydex/definition.c', line 179
static VALUE rdxr_definition_declaration(VALUE self) {
HandleData *data;
TypedData_Get_Struct(self, HandleData, &handle_type, data);
void *graph;
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
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);
}
|
#deprecated? ⇒ Boolean
Definition#deprecated? -> bool
145 146 147 148 149 150 151 152 153 154 |
# File 'ext/rubydex/definition.c', line 145
static VALUE rdxr_definition_deprecated(VALUE self) {
HandleData *data;
TypedData_Get_Struct(self, HandleData, &handle_type, data);
void *graph;
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
bool deprecated = rdx_definition_is_deprecated(graph, data->id);
return deprecated ? Qtrue : Qfalse;
}
|
#location ⇒ Object
Definition#location -> Rubydex::Location
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'ext/rubydex/definition.c', line 75
static VALUE rdxr_definition_location(VALUE self) {
HandleData *data;
TypedData_Get_Struct(self, HandleData, &handle_type, data);
void *graph;
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
Location *loc = rdx_definition_location(graph, data->id);
VALUE location = rdxi_build_location_value(loc);
rdx_location_free(loc);
return location;
}
|
#name ⇒ Object
Definition#name -> String
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'ext/rubydex/definition.c', line 128
static VALUE rdxr_definition_name(VALUE self) {
HandleData *data;
TypedData_Get_Struct(self, HandleData, &handle_type, data);
void *graph;
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
const char *name = rdx_definition_name(graph, data->id);
if (name == NULL) {
return Qnil;
}
VALUE str = rb_utf8_str_new_cstr(name);
free_c_string(name);
return str;
}
|
#name_location ⇒ Object
(e.g., “Bar” in “class Foo::Bar”). For other definition types, returns nil.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'ext/rubydex/definition.c', line 159
static VALUE rdxr_definition_name_location(VALUE self) {
HandleData *data;
TypedData_Get_Struct(self, HandleData, &handle_type, data);
void *graph;
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
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;
}
|