Class: Rubydex::Namespace
- Inherits:
-
Declaration
- Object
- Declaration
- Rubydex::Namespace
- Defined in:
- lib/rubydex/declaration.rb,
ext/rubydex/declaration.c
Direct Known Subclasses
Instance Method Summary collapse
-
#ancestors ⇒ Enumerator[Rubydex::Namespace]
Returns an enumerator that yields ancestor namespaces.
-
#descendants ⇒ Enumerator[Rubydex::Namespace]
Returns an enumerator that yields descendant namespaces.
-
#find_member(name, only_inherited: false) ⇒ Rubydex::Declaration?
Searches for a member in the declaration's ancestor chain.
-
#has_ancestor?(*ancestor_names) ⇒ Boolean
: (*String ancestor_names) -> bool.
-
#member(name) ⇒ Rubydex::Declaration?
Returns a declaration handle for the named member, or nil if no member exists.
-
#members ⇒ Enumerator[Rubydex::Declaration]
Returns an enumerator that yields member declarations.
-
#references ⇒ Enumerator[Rubydex::ConstantReference]
Returns an enumerator that yields constant references to this declaration.
-
#singleton_class ⇒ Rubydex::SingletonClass?
Returns the singleton class declaration, or nil if none exists.
Methods inherited from Declaration
#definitions, #initialize, #name, #owner, #unqualified_name
Constructor Details
This class inherits a constructor from Rubydex::Declaration
Instance Method Details
#ancestors ⇒ Enumerator[Rubydex::Namespace]
Returns an enumerator that yields ancestor namespaces.
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'ext/rubydex/declaration.c', line 255
static VALUE rdxr_declaration_ancestors(VALUE self) {
if (!rb_block_given_p()) {
return rb_enumeratorize(self, rb_str_new2("ancestors"), 0, NULL);
}
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
void *iter = rdx_declaration_ancestors(graph, data->id);
if (iter == NULL) {
rb_raise(rb_eRuntimeError, "failed to create iterator");
}
VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
return self;
}
|
#descendants ⇒ Enumerator[Rubydex::Namespace]
Returns an enumerator that yields descendant namespaces.
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'ext/rubydex/declaration.c', line 280
static VALUE rdxr_declaration_descendants(VALUE self) {
if (!rb_block_given_p()) {
return rb_enumeratorize(self, rb_str_new2("descendants"), 0, NULL);
}
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
void *iter = rdx_declaration_descendants(graph, data->id);
if (iter == NULL) {
rb_raise(rb_eRuntimeError, "failed to create iterator");
}
VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
return self;
}
|
#find_member(name, only_inherited: false) ⇒ Rubydex::Declaration?
Searches for a member in the declaration's ancestor chain.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'ext/rubydex/declaration.c', line 174
static VALUE rdxr_declaration_find_member(int argc, VALUE *argv, VALUE self) {
VALUE member, opts;
rb_scan_args(argc, argv, "1:", &member, &opts);
Check_Type(member, T_STRING);
bool only_inherited = false;
if (!NIL_P(opts)) {
ID kwarg_id = rb_intern("only_inherited");
VALUE kwarg_val;
rb_get_kwargs(opts, &kwarg_id, 0, 1, &kwarg_val);
if (kwarg_val != Qundef) {
only_inherited = RTEST(kwarg_val);
}
}
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
const CDeclaration *decl = rdx_declaration_find_member(graph, data->id, StringValueCStr(member), only_inherited);
if (decl == NULL) {
return Qnil;
}
VALUE decl_class = rdxi_declaration_class_for_kind(decl->kind);
VALUE result_argv[] = {data->graph_obj, ULL2NUM(decl->id)};
free_c_declaration(decl);
return rb_class_new_instance(2, result_argv, decl_class);
}
|
#has_ancestor?(*ancestor_names) ⇒ Boolean
: (*String ancestor_names) -> bool
25 26 27 |
# File 'lib/rubydex/declaration.rb', line 25 def has_ancestor?(*ancestor_names) ancestors.any? { |ancestor| ancestor_names.include?(ancestor.name) } end |
#member(name) ⇒ Rubydex::Declaration?
Returns a declaration handle for the named member, or nil if no member exists.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'ext/rubydex/declaration.c', line 148
static VALUE rdxr_declaration_member(VALUE self, VALUE name) {
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
if (TYPE(name) != T_STRING) {
rb_raise(rb_eTypeError, "expected String");
}
const CDeclaration *decl = rdx_declaration_member(graph, data->id, StringValueCStr(name));
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);
}
|
#members ⇒ Enumerator[Rubydex::Declaration]
Returns an enumerator that yields member declarations.
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'ext/rubydex/declaration.c', line 305
static VALUE rdxr_declaration_members(VALUE self) {
if (!rb_block_given_p()) {
return rb_enumeratorize(self, rb_str_new2("members"), 0, NULL);
}
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
void *iter = rdx_declaration_members(graph, data->id);
if (iter == NULL) {
rb_raise(rb_eRuntimeError, "failed to create iterator");
}
VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
return self;
}
|
#references ⇒ Enumerator[Rubydex::ConstantReference]
Returns an enumerator that yields constant references to this declaration.
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'ext/rubydex/declaration.c', line 345
static VALUE rdxr_constant_declaration_references(VALUE self) {
if (!rb_block_given_p()) {
return rb_enumeratorize_with_size(self, rb_str_new2("references"), 0, NULL,
constant_declaration_references_size);
}
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
void *iter = rdx_declaration_constant_references_iter_new(graph, data->id);
if (iter == NULL) {
rb_raise(rb_eRuntimeError, "Declaration not found");
}
VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
rb_ensure(rdxi_constant_references_yield, args, rdxi_constant_references_ensure, args);
return self;
}
|
#singleton_class ⇒ Rubydex::SingletonClass?
Returns the singleton class declaration, or nil if none exists.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'ext/rubydex/declaration.c', line 211
static VALUE rdxr_declaration_singleton_class(VALUE self) {
HandleData *data;
void *graph = rdxi_graph_from_handle(self, &data);
const CDeclaration *decl = rdx_declaration_singleton_class(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);
}
|