Esempio n. 1
0
static VALUE
rb_mod_modfunc(VALUE module, SEL sel, int argc, VALUE *argv)
{
    if (TYPE(module) != T_MODULE) {
	rb_raise(rb_eTypeError, "module_function must be called for modules");
    }

    secure_visibility(module);
    if (argc == 0) {
	rb_vm_set_current_scope(module, SCOPE_MODULE_FUNC);
	return module;
    }

    set_method_visibility(module, argc, argv, NOEX_PRIVATE);

    for (int i = 0; i < argc; i++) {
	ID id = rb_to_id(argv[i]);
	IMP imp = NULL;
	rb_vm_method_node_t *node = NULL;
	SEL sel = 0;

	if (rb_vm_lookup_method2((Class)module, id, &sel, &imp, &node)
		|| (TYPE(module) == T_MODULE
		    && rb_vm_lookup_method2((Class)rb_cObject, id, &sel,
			&imp, &node))) {
	    rb_vm_define_method2(*(Class *)module, sel, node, -1, false);
	}
	else {
	    rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
	}
    }

    return module;
}
Esempio n. 2
0
static VALUE
rb_mod_modfunc(VALUE module, SEL sel, int argc, VALUE *argv)
{
    int i;

    if (TYPE(module) != T_MODULE) {
	rb_raise(rb_eTypeError, "module_function must be called for modules");
    }

    secure_visibility(module);
    if (argc == 0) {
	// TODO change scope!
	return module;
    }

    set_method_visibility(module, argc, argv, NOEX_PRIVATE);

    for (i = 0; i < argc; i++) {
	ID id = rb_to_id(argv[i]);
	IMP imp;
	rb_vm_method_node_t *node;
	SEL sel;

	if (!rb_vm_lookup_method2((Class)module, id, &sel, &imp, &node)) {
	    // Methods are checked in set_method_visibility().
	    rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
	}

	rb_vm_define_method2(*(Class *)module, sel, node, false);
    }

    return module;
}
Esempio n. 3
0
static VALUE
set_visibility(int argc, const VALUE *argv, VALUE module, rb_method_flag_t ex)
{
    if (argc == 0) {
	SCOPE_SET(ex);
    }
    else {
	set_method_visibility(module, argc, argv, ex);
    }
    return module;
}
Esempio n. 4
0
static VALUE
rb_mod_private(int argc, VALUE *argv, VALUE module)
{
    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_PRIVATE);
    }
    else {
	set_method_visibility(module, argc, argv, NOEX_PRIVATE);
    }
    return module;
}
Esempio n. 5
0
static VALUE
rb_mod_protected(int argc, VALUE *argv, VALUE module)
{
    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_PROTECTED);
    }
    else {
	set_method_visibility(module, argc, argv, NOEX_PROTECTED);
    }
    return module;
}
Esempio n. 6
0
static VALUE
rb_mod_public(int argc, VALUE *argv, VALUE module)
{
    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_PUBLIC);
    }
    else {
	set_method_visibility(module, argc, argv, NOEX_PUBLIC);
    }
    return module;
}
Esempio n. 7
0
static VALUE
rb_mod_private(VALUE module, SEL sel, int argc, VALUE *argv)
{
    secure_visibility(module);
    if (argc == 0) {
	rb_vm_set_current_scope(module, SCOPE_PRIVATE);
    }
    else {
	set_method_visibility(module, argc, argv, NOEX_PRIVATE);
    }
    return module;
}
Esempio n. 8
0
static VALUE
rb_mod_private(VALUE module, SEL sel, int argc, VALUE *argv)
{
    secure_visibility(module);
    if (argc == 0) {
	// TODO change scope!
    }
    else {
	set_method_visibility(module, argc, argv, NOEX_PRIVATE);
    }
    return module;
}
Esempio n. 9
0
static VALUE
rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
{
    int i;
    ID id;
    NODE *fbody;

    if (TYPE(module) != T_MODULE) {
	rb_raise(rb_eTypeError, "module_function must be called for modules");
    }

    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_MODFUNC);
	return module;
    }

    set_method_visibility(module, argc, argv, NOEX_PRIVATE);

    for (i = 0; i < argc; i++) {
	VALUE m = module;

	id = rb_to_id(argv[i]);
	for (;;) {
	    fbody = search_method(m, id, &m);
	    if (fbody == 0) {
		fbody = search_method(rb_cObject, id, &m);
	    }
	    if (fbody == 0 || fbody->nd_body == 0) {
		rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
	    }
	    if (nd_type(fbody->nd_body->nd_body) != NODE_ZSUPER) {
		break;		/* normal case: need not to follow 'super' link */
	    }
	    m = RCLASS_SUPER(m);
	    if (!m)
		break;
	}
	rb_add_method(rb_singleton_class(module), id, fbody->nd_body->nd_body,
		      NOEX_PUBLIC);
    }
    return module;
}
static VALUE
rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
{
    int i;
    ID id;
    const rb_method_entry_t *me;

    if (!RB_TYPE_P(module, T_MODULE)) {
	rb_raise(rb_eTypeError, "module_function must be called for modules");
    }

    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_MODFUNC);
	return module;
    }

    set_method_visibility(module, argc, argv, NOEX_PRIVATE);

    for (i = 0; i < argc; i++) {
	VALUE m = module;

	id = rb_to_id(argv[i]);
	for (;;) {
	    me = search_method(m, id);
	    if (me == 0) {
		me = search_method(rb_cObject, id);
	    }
	    if (UNDEFINED_METHOD_ENTRY_P(me)) {
		rb_print_undef(module, id, 0);
	    }
	    if (me->def->type != VM_METHOD_TYPE_ZSUPER) {
		break; /* normal case: need not to follow 'super' link */
	    }
	    m = RCLASS_SUPER(m);
	    if (!m)
		break;
	}
	rb_method_entry_set(rb_singleton_class(module), id, me, NOEX_PUBLIC);
    }
    return module;
}
Esempio n. 11
0
static VALUE
rb_mod_private_method(int argc, VALUE *argv, VALUE obj)
{
    set_method_visibility(CLASS_OF(obj), argc, argv, NOEX_PRIVATE);
    return obj;
}
Esempio n. 12
0
static VALUE
rb_mod_public_method(int argc, VALUE *argv, VALUE obj)
{
    set_method_visibility(CLASS_OF(obj), argc, argv, NOEX_PUBLIC);
    return obj;
}
Esempio n. 13
0
static VALUE
rb_mod_private_method(int argc, VALUE *argv, VALUE obj)
{
    set_method_visibility(rb_singleton_class(obj), argc, argv, NOEX_PRIVATE);
    return obj;
}
Esempio n. 14
0
static VALUE
rb_mod_public_method(int argc, VALUE *argv, VALUE obj)
{
    set_method_visibility(rb_singleton_class(obj), argc, argv, NOEX_PUBLIC);
    return obj;
}