fix dirprot mode
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5874 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
f6340798c4
commit
553698d489
5 changed files with 34 additions and 31 deletions
|
|
@ -364,7 +364,7 @@ void emit_action(Node *n, Wrapper *f) {
|
||||||
action = Getattr(n,"wrap:action");
|
action = Getattr(n,"wrap:action");
|
||||||
assert(action != 0);
|
assert(action != 0);
|
||||||
|
|
||||||
if (is_protected(n) && is_member_director(n)) {
|
if (!(is_public(n)) && is_member_director(n)) {
|
||||||
/* We need to add an extra dynamic_cast to
|
/* We need to add an extra dynamic_cast to
|
||||||
access the director class, where the virtual
|
access the director class, where the virtual
|
||||||
methods are all public */
|
methods are all public */
|
||||||
|
|
@ -375,6 +375,15 @@ void emit_action(Node *n, Wrapper *f) {
|
||||||
Wrapper_add_local(f, "darg", dirdecl);
|
Wrapper_add_local(f, "darg", dirdecl);
|
||||||
Printf(f->code, "darg = dynamic_cast<%s *>(arg1);\n",dirname);
|
Printf(f->code, "darg = dynamic_cast<%s *>(arg1);\n",dirname);
|
||||||
Replace(action, "arg1", "darg", DOH_REPLACE_FIRST);
|
Replace(action, "arg1", "darg", DOH_REPLACE_FIRST);
|
||||||
|
if (Getattr(n,"qualifier")) {
|
||||||
|
/* fix constant casting introduced by a const method decl */
|
||||||
|
String* classtype = Getattr(parent, "classtype");
|
||||||
|
/*
|
||||||
|
String *ccast = NewStringf("((%s const *)darg)",classtype);
|
||||||
|
if (Strstr(action,ccast) != 0)
|
||||||
|
*/
|
||||||
|
Replace(action, classtype, dirname, DOH_REPLACE_FIRST);
|
||||||
|
}
|
||||||
Delete(dirname);
|
Delete(dirname);
|
||||||
Delete(dirdecl);
|
Delete(dirdecl);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1636,7 +1636,7 @@ class JAVA : public Language {
|
||||||
|
|
||||||
/* Start generating the proxy function */
|
/* Start generating the proxy function */
|
||||||
const String *methodmods = Getattr(n,"feature:java:methodmodifiers");
|
const String *methodmods = Getattr(n,"feature:java:methodmodifiers");
|
||||||
methodmods = methodmods ? methodmods : (is_protected(n) ? protected_string : public_string);
|
methodmods = methodmods ? methodmods : (!is_public(n) ? protected_string : public_string);
|
||||||
Printf(function_code, " %s ", methodmods);
|
Printf(function_code, " %s ", methodmods);
|
||||||
if (static_flag)
|
if (static_flag)
|
||||||
Printf(function_code, "static ");
|
Printf(function_code, "static ");
|
||||||
|
|
@ -1760,7 +1760,7 @@ class JAVA : public Language {
|
||||||
String *imcall = NewString("");
|
String *imcall = NewString("");
|
||||||
|
|
||||||
const String *methodmods = Getattr(n,"feature:java:methodmodifiers");
|
const String *methodmods = Getattr(n,"feature:java:methodmodifiers");
|
||||||
methodmods = methodmods ? methodmods : (is_protected(n) ? protected_string : public_string);
|
methodmods = methodmods ? methodmods : (!is_public(n) ? protected_string : public_string);
|
||||||
Printf(proxy_class_code, " %s %s(", methodmods, proxy_class_name);
|
Printf(proxy_class_code, " %s %s(", methodmods, proxy_class_name);
|
||||||
Printv(imcall, "this(", imclass_name, ".", mangled_overname, "(", NIL);
|
Printv(imcall, "this(", imclass_name, ".", mangled_overname, "(", NIL);
|
||||||
|
|
||||||
|
|
@ -2015,7 +2015,7 @@ class JAVA : public Language {
|
||||||
|
|
||||||
/* Start generating the function */
|
/* Start generating the function */
|
||||||
const String *methodmods = Getattr(n,"feature:java:methodmodifiers");
|
const String *methodmods = Getattr(n,"feature:java:methodmodifiers");
|
||||||
methodmods = methodmods ? methodmods : (is_protected(n) ? protected_string : public_string);
|
methodmods = methodmods ? methodmods : (!is_public(n) ? protected_string : public_string);
|
||||||
Printf(function_code, " %s static %s %s(", methodmods, return_type, func_name);
|
Printf(function_code, " %s static %s %s(", methodmods, return_type, func_name);
|
||||||
Printv(imcall, imclass_name, ".", overloaded_name, "(", NIL);
|
Printv(imcall, imclass_name, ".", overloaded_name, "(", NIL);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,11 @@ void Wrapper_template_extmode_set(int flag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
int Swig_director_mode()
|
||||||
|
{
|
||||||
|
return director_mode;
|
||||||
|
}
|
||||||
|
|
||||||
int Swig_need_protected()
|
int Swig_need_protected()
|
||||||
{
|
{
|
||||||
return director_protected_mode;
|
return director_protected_mode;
|
||||||
|
|
@ -730,9 +735,9 @@ int Language::cDeclaration(Node *n) {
|
||||||
Node *over;
|
Node *over;
|
||||||
File *f_header = 0;
|
File *f_header = 0;
|
||||||
SwigType *ty, *fullty;
|
SwigType *ty, *fullty;
|
||||||
|
|
||||||
/* discarts nodes following the access control rules */
|
/* discarts nodes following the access control rules */
|
||||||
if (cplus_mode != CPLUS_PUBLIC) {
|
if (cplus_mode != CPLUS_PUBLIC || !is_public(n)) {
|
||||||
/* except for friends, they are not affected by access control */
|
/* except for friends, they are not affected by access control */
|
||||||
int isfriend = storage && (Cmp(storage,"friend") == 0);
|
int isfriend = storage && (Cmp(storage,"friend") == 0);
|
||||||
if (!isfriend ) {
|
if (!isfriend ) {
|
||||||
|
|
@ -745,7 +750,7 @@ int Language::cDeclaration(Node *n) {
|
||||||
return SWIG_NOWRAP;
|
return SWIG_NOWRAP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cmp(storage,"typedef") == 0) {
|
if (Cmp(storage,"typedef") == 0) {
|
||||||
Swig_save("cDeclaration",n,"type",NIL);
|
Swig_save("cDeclaration",n,"type",NIL);
|
||||||
SwigType *t = Copy(type);
|
SwigType *t = Copy(type);
|
||||||
|
|
@ -1510,7 +1515,8 @@ int Language::unrollVirtualMethods(Node *n,
|
||||||
String *fqname = NewStringf("%s::%s", classname, name);
|
String *fqname = NewStringf("%s::%s", classname, name);
|
||||||
Hash *item = NewHash();
|
Hash *item = NewHash();
|
||||||
Setattr(item, "fqName", fqname);
|
Setattr(item, "fqName", fqname);
|
||||||
Setattr(item, "methodNode", Copy(ni));
|
Node *m = Copy(ni);
|
||||||
|
Setattr(item, "methodNode", m);
|
||||||
Setattr(vm, method_id, item);
|
Setattr(vm, method_id, item);
|
||||||
Delete(fqname);
|
Delete(fqname);
|
||||||
Delete(item);
|
Delete(item);
|
||||||
|
|
@ -1566,7 +1572,7 @@ int Language::unrollVirtualMethods(Node *n,
|
||||||
*/
|
*/
|
||||||
Node *c = Copy(m);
|
Node *c = Copy(m);
|
||||||
Setattr(c, "parentNode", n);
|
Setattr(c, "parentNode", n);
|
||||||
int cdir = checkAttribute(c, "feature:director", "1");
|
int cdir = checkAttribute(c, "feature:director", "1") || director_mode;
|
||||||
int cndir = checkAttribute(c, "feature:nodirector", "1");
|
int cndir = checkAttribute(c, "feature:nodirector", "1");
|
||||||
dir = (cdir || cndir) ? (cdir && !cndir) : dir;
|
dir = (cdir || cndir) ? (cdir && !cndir) : dir;
|
||||||
Delete(c);
|
Delete(c);
|
||||||
|
|
@ -1862,30 +1868,14 @@ int Language::classHandler(Node *n) {
|
||||||
cplus_mode = CPLUS_PROTECTED;
|
cplus_mode = CPLUS_PROTECTED;
|
||||||
for (k = First(vtable); k.key; k = Next(k)) {
|
for (k = First(vtable); k.key; k = Next(k)) {
|
||||||
item = k.item;
|
item = k.item;
|
||||||
String* director = Getattr(item,"director");
|
|
||||||
Node *method = Getattr(item, "methodNode");
|
Node *method = Getattr(item, "methodNode");
|
||||||
Node* parentnode = Getattr(method, "parentNode");
|
|
||||||
String* methodname = Getattr(method,"sym:name");
|
String* methodname = Getattr(method,"sym:name");
|
||||||
String* wrapname = NewStringf("%s_%s", symname,methodname);
|
String* wrapname = NewStringf("%s_%s", symname,methodname);
|
||||||
/* only pure virtual abstract private methods are needed */
|
|
||||||
int need_private = (is_private(method)
|
|
||||||
&& (Cmp(Getattr(method,"value"),"0") == 0));
|
|
||||||
if (!Getattr(symbols,wrapname)
|
if (!Getattr(symbols,wrapname)
|
||||||
&& !Cmp(director,"1")
|
&& (!is_public(method))) {
|
||||||
&& (n != parentnode)
|
|
||||||
&& (is_protected(method) || need_private)) {
|
|
||||||
Node* m = Copy(method);
|
Node* m = Copy(method);
|
||||||
String* mdecl = Getattr(m,"decl");
|
Setattr(m, "director", "1");
|
||||||
Setattr(m,"parentNode", n);
|
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);
|
cDeclaration(m);
|
||||||
Delete(m);
|
Delete(m);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -598,8 +598,8 @@ public:
|
||||||
case MEMBER_FUNC:
|
case MEMBER_FUNC:
|
||||||
{
|
{
|
||||||
#ifdef SWIG_PROTECTED_TARGET_METHODS
|
#ifdef SWIG_PROTECTED_TARGET_METHODS
|
||||||
const char* rb_define_method = is_protected(n) ?
|
const char* rb_define_method = is_public(n) ?
|
||||||
"rb_define_protected_method" : "rb_define_method";
|
"rb_define_method" : "rb_define_protected_method" ;
|
||||||
#else
|
#else
|
||||||
const char* rb_define_method = "rb_define_method";
|
const char* rb_define_method = "rb_define_method";
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,13 @@ int is_protected(Node* n)
|
||||||
|
|
||||||
int is_member_director(Node* parentnode, Node* member)
|
int is_member_director(Node* parentnode, Node* member)
|
||||||
{
|
{
|
||||||
|
int director_mode = Swig_director_mode();
|
||||||
|
|
||||||
if (checkAttribute(member,"director","1")) return 1;
|
if (checkAttribute(member,"director","1")) return 1;
|
||||||
if (parentnode && checkAttribute(member, "storage", "virtual")) {
|
if (parentnode && checkAttribute(member, "storage", "virtual")) {
|
||||||
int parent_director = checkAttribute(parentnode,"feature:director","1");
|
int parent_nodirector = checkAttribute(parentnode,"feature:nodirector","1");
|
||||||
|
if (parent_nodirector) return 0;
|
||||||
|
int parent_director = director_mode|| checkAttribute(parentnode,"feature:director","1");
|
||||||
int cdecl_director = parent_director || checkAttribute(member,"feature:director","1");
|
int cdecl_director = parent_director || checkAttribute(member,"feature:director","1");
|
||||||
int cdecl_nodirector = checkAttribute(member,"feature:nodirector","1");
|
int cdecl_nodirector = checkAttribute(member,"feature:nodirector","1");
|
||||||
return cdecl_director && !cdecl_nodirector;
|
return cdecl_director && !cdecl_nodirector;
|
||||||
|
|
@ -32,7 +36,7 @@ int is_member_director(Node* parentnode, Node* member)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_member_director(Node* member)
|
int is_member_director(Node* member)
|
||||||
{
|
{
|
||||||
return is_member_director(Getattr(member, "parentNode"), member);
|
return is_member_director(Getattr(member, "parentNode"), member);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue