The dirprot feature is now disabled by default. Added dirprot option and ruby runtime examples.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5510 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2003-12-09 02:52:08 +00:00
commit 634b973f31
11 changed files with 154 additions and 41 deletions

View file

@ -1,5 +1,32 @@
Version 1.3.20 (In progress)
============================
12/08/2003: mmatus (Marcelo Matus)
The director protected member support (dirprot)
is disabled by default.
It can be enable by using '-dirprot' or by adding
the option to the module declaration, like:
%module(directors="1",dirprot="1") my_module
This module option was added to properly compile the
director_protected.i and director_nested.i examples.
The feature has been tested with python[2.2,2.3]
and ruby[1.6.7], both at compilation and runtime, and
java[j2sdk1.4.1_01], but only at compilation (my java
installation doesn't run any of the director examples,
olds nor news).
Please test for ocaml and java.
The errors reported by William and Scott were fixed,
except for a warning about SWIG_JavaThrowExecption()
multiply defined. I can't reproduce this error with my
examples. We will wait for Scott to send us a minimal
case.
12/07/2003: mmatus (Marcelo Matus)
The director protected member support has been
completly moved out from python.cxx, and now

View file

@ -1,4 +1,4 @@
%module(directors="1") director_nested
%module(directors="1",dirprot="1") director_nested
%{
#include <string>
@ -11,7 +11,7 @@
%newobject *::create();
%inline %{
%inline {
template <class C>
class Foo {
public:
@ -25,11 +25,11 @@
protected:
virtual std::string do_advance() = 0;
};
%}
}
%template(Foo_int) Foo<int>;
%inline %{
%inline {
class Bar : public Foo<int>
{
@ -47,7 +47,12 @@
}
#if defined(SWIGPYTHON) || defined(SWIGRUBY) || \
defined(SWIGJAVA) || defined(SWIGOCAML)
virtual std::string do_step() const = 0;
#else
virtual std::string do_step() const {return "";};
#endif
};
template <class C>
@ -56,7 +61,7 @@
public:
virtual C get_value() const = 0;
};
%}
}
%template(FooBar_int) FooBar<int>;

View file

@ -1,4 +1,4 @@
%module(directors="1") director_protected
%module(directors="1",dirprot="1") director_protected
%{
#include <string>
@ -12,7 +12,7 @@
%newobject *::create();
%inline %{
%inline {
class Foo {
public:
virtual ~Foo() {}
@ -20,7 +20,15 @@ public:
return "Foo::pong();" + ping();
}
protected:
#if defined(SWIGPYTHON) || defined(SWIGRUBY) \
|| defined(SWIGJAVA) || defined(SWIGOCAML)
virtual std::string ping() = 0;
#else
virtual std::string ping() { return "";};
#endif
void hellom() {}
};
class Bar : public Foo
@ -43,8 +51,9 @@ protected:
};
int hi;
void him() {}
};
%}
}

View file

@ -0,0 +1,34 @@
require 'director_nested'
class A < Director_nested::FooBar_int
def do_step
"A::do_step;"
end
def get_value
"A::get_value"
end
end
a = A.new
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
def do_step
"B::do_step;"
end
def get_value
"B::get_value"
end
end
b = B.new
raise RuntimeError if b.step != "Bar::step;Foo::advance;B::do_advance;B::do_step;"

View file

@ -0,0 +1,13 @@
require 'director_protected'
class FooBar < Director_protected::Bar
def ping
"FooBar::ping();"
end
end
b = Director_protected::Bar.new
fb = FooBar.new
raise RuntimeError if b.pong != "Bar::pong();Foo::pong();Bar::ping();"
raise RuntimeError if fb.pong != "Bar::pong();Foo::pong();FooBar::ping();"

View file

@ -268,6 +268,9 @@ class JAVA : public Language {
if (Getattr(optionsnode, "directors")) {
allow_directors();
}
if (Getattr(optionsnode, "dirprot")) {
allow_dirprot();
}
}
/* Initialize all of the output files */

View file

@ -1720,41 +1720,43 @@ int Language::classHandler(Node *n) {
classDirectorDisown(n);
/* emit all the protected virtual members as needed */
Node *vtable = Getattr(n, "vtable");
String* symname = Getattr(n, "sym:name");
Node *item;
Iterator k;
int old_mode = cplus_mode;
cplus_mode = CPLUS_PROTECTED;
for (k = First(vtable); k.key; k = Next(k)) {
item = k.item;
String* director = Getattr(item,"director");
Node *method = Getattr(item, "methodNode");
Node* parentnode = Getattr(method, "parentNode");
String* methodname = Getattr(method,"sym:name");
String* wrapname = NewStringf("%s_%s", symname,methodname);
if (!Getattr(symbols,wrapname)
&& !Cmp(director,"1")
&& (n != parentnode)
&& is_protected(method)) {
Node* m = Copy(method);
String* mdecl = Getattr(m,"decl");
Setattr(m,"parentNode", n);
/* ugly trick, to avoid an uglier one later on emit. We take
the 'const' out from calling method to avoid the ugly const
casting latter. The casting from 'non-const' to 'const' is not
needed here, but it prevents the simple replacement of
arg1 by darg on emit.cxx.
*/
if (Strncmp(mdecl, "q(const).", 9)== 0)
Replace(mdecl,"q(const).","", DOH_REPLACE_FIRST);
cDeclaration(m);
Delete(m);
if (director_protected_mode) {
Node *vtable = Getattr(n, "vtable");
String* symname = Getattr(n, "sym:name");
Node *item;
Iterator k;
int old_mode = cplus_mode;
cplus_mode = CPLUS_PROTECTED;
for (k = First(vtable); k.key; k = Next(k)) {
item = k.item;
String* director = Getattr(item,"director");
Node *method = Getattr(item, "methodNode");
Node* parentnode = Getattr(method, "parentNode");
String* methodname = Getattr(method,"sym:name");
String* wrapname = NewStringf("%s_%s", symname,methodname);
if (!Getattr(symbols,wrapname)
&& !Cmp(director,"1")
&& (n != parentnode)
&& is_protected(method)) {
Node* m = Copy(method);
String* mdecl = Getattr(m,"decl");
Setattr(m,"parentNode", n);
/* ugly trick, to avoid an uglier one later on emit. We
take the 'const' out from calling method to avoid the
ugly const casting latter. The casting from 'non-const'
to 'const' is not needed here, but it prevents the simple
replacement of arg1 by darg on emit.cxx.
*/
if (Strncmp(mdecl, "q(const).", 9)== 0)
Replace(mdecl,"q(const).","", DOH_REPLACE_FIRST);
cDeclaration(m);
Delete(m);
}
Delete(wrapname);
}
Delete(wrapname);
cplus_mode = old_mode;
}
cplus_mode = old_mode;
}
return SWIG_OK;
@ -2184,6 +2186,14 @@ void Language::allow_directors(int val) {
directors = val;
}
/* -----------------------------------------------------------------------------
* Language::allow_dirprot()
* ----------------------------------------------------------------------------- */
void Language::allow_dirprot(int val) {
director_protected_mode = val;
}
/* -----------------------------------------------------------------------------
* Language::directorsEnabled()
* ----------------------------------------------------------------------------- */

View file

@ -196,6 +196,9 @@ public:
if (Getattr(options, "directors")) {
allow_directors();
}
if (Getattr(options, "dirprot")) {
allow_dirprot();
}
if (Getattr(options, "sizeof")) {
generate_sizeof = 1;
}

View file

@ -159,6 +159,9 @@ public:
if (Getattr(options, "directors")) {
allow_directors();
}
if (Getattr(options, "dirprot")) {
allow_dirprot();
}
}
}
}

View file

@ -335,6 +335,9 @@ public:
if (Getattr(options, "directors")) {
allow_directors();
}
if (Getattr(options, "dirprot")) {
allow_dirprot();
}
if (Getattr(options, "ruby_globalmodule")) {
useGlobalModule = true;
}

View file

@ -213,6 +213,9 @@ public:
/* Allow director related code generation */
void allow_directors(int val = 1);
/* Allow director protected members related code generation */
void allow_dirprot(int val = 1);
/* Return true if directors are enabled */
int directorsEnabled() const;