emitting and testing protected methods for director protected members

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5512 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2003-12-09 10:38:34 +00:00
commit ae75ec65dd
3 changed files with 45 additions and 24 deletions

View file

@ -1,32 +1,41 @@
require 'director_nested'
NoProtectedError = Kernel.const_defined?("NoMethodError") ? NoMethodError : NameError
class A < Director_nested::FooBar_int
def do_step
"A::do_step;"
end
protected
def do_step
"A::do_step;"
end
def get_value
"A::get_value"
end
def get_value
"A::get_value"
end
end
a = A.new
begin
a.do_advance
rescue NoProtectedError
end
raise RuntimeError if a.step != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;"
class B < Director_nested::FooBar_int
def do_advance
"B::do_advance;" + do_step
end
protected
def do_advance
"B::do_advance;" + do_step
end
def do_step
"B::do_step;"
end
def do_step
"B::do_step;"
end
def get_value
"B::get_value"
end
def get_value
"B::get_value"
end
end

View file

@ -1,13 +1,21 @@
require 'director_protected'
NoProtectedError = Kernel.const_defined?("NoMethodError") ? NoMethodError : NameError
class FooBar < Director_protected::Bar
def ping
"FooBar::ping();"
end
protected
def ping
"FooBar::ping();"
end
end
b = Director_protected::Bar.new
fb = FooBar.new
begin
fb.ping
rescue NoProtectedError
end
raise RuntimeError if b.pong != "Bar::pong();Foo::pong();Bar::ping();"
raise RuntimeError if fb.pong != "Bar::pong();Foo::pong();FooBar::ping();"

View file

@ -588,13 +588,17 @@ public:
String *temp = NewString("");
switch (current) {
case MEMBER_FUNC:
if (multipleInheritance) {
Printv(klass->init, tab4, "rb_define_method(", klass->mImpl, ", \"",
iname, "\", ", wname, ", -1);\n", NIL);
case MEMBER_FUNC:
if (multipleInheritance) {
const char* rb_define_method = !is_protected(n) ?
"rb_define_method" : "rb_define_protected_method";
Printv(klass->init, tab4, rb_define_method,"(", klass->mImpl, ", \"",
iname, "\", ", wname, ", -1);\n", NIL);
} else {
Printv(klass->init, tab4, "rb_define_method(", klass->vname, ", \"",
iname, "\", ", wname, ", -1);\n", NIL);
const char* rb_define_method = !is_protected(n) ?
"rb_define_method" : "rb_define_protected_method";
Printv(klass->init, tab4, rb_define_method, "(", klass->vname, ", \"",
iname, "\", ", wname, ", -1);\n", NIL);
}
break;
case CONSTRUCTOR_ALLOCATE: