fix java reg. tests and add -directors flag
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5867 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
fc5012d5e8
commit
405a7335a7
7 changed files with 96 additions and 29 deletions
|
|
@ -52,6 +52,7 @@ static int inherit_list = 0;
|
||||||
static Parm *template_parameters = 0;
|
static Parm *template_parameters = 0;
|
||||||
static int extendmode = 0;
|
static int extendmode = 0;
|
||||||
static int dirprot_mode = 0;
|
static int dirprot_mode = 0;
|
||||||
|
static int tempext_mode = 0;
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Assist Functions
|
* Assist Functions
|
||||||
|
|
@ -307,6 +308,12 @@ static void add_symbols(Node *n) {
|
||||||
only_csymbol = !need_protected(n, dirprot_mode);
|
only_csymbol = !need_protected(n, dirprot_mode);
|
||||||
} else {
|
} else {
|
||||||
Setattr(n,"access", "private");
|
Setattr(n,"access", "private");
|
||||||
|
if ((Cmp(Getattr(n,"storage"),"virtual") == 0)
|
||||||
|
&& (Cmp(Getattr(n,"value"),"0") == 0)) {
|
||||||
|
only_csymbol = !need_protected(n, dirprot_mode);
|
||||||
|
} else {
|
||||||
|
Setattr(n,"feature:ignore","1");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (only_csymbol) {
|
if (only_csymbol) {
|
||||||
/* Only add to C symbol table and continue */
|
/* Only add to C symbol table and continue */
|
||||||
|
|
@ -2062,9 +2069,12 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
|
||||||
String *nname = NewStringf("__dummy_%d__", cnt++);
|
String *nname = NewStringf("__dummy_%d__", cnt++);
|
||||||
Swig_cparse_template_expand($$,nname,temparms);
|
Swig_cparse_template_expand($$,nname,temparms);
|
||||||
Setattr($$,"sym:name",nname);
|
Setattr($$,"sym:name",nname);
|
||||||
/* Setattr($$,"feature:ignore","1"); */
|
if (!Swig_template_extmode()) {
|
||||||
Setattr($$,"feature:onlychildren",
|
Setattr($$,"feature:ignore","1");
|
||||||
"typemap,typemapitem,typemapcopy,typedef,types,fragment");
|
} else {
|
||||||
|
Setattr($$,"feature:onlychildren",
|
||||||
|
"typemap,typemapitem,typemapcopy,typedef,types,fragment");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Delattr($$,"templatetype");
|
Delattr($$,"templatetype");
|
||||||
Setattr($$,"template",n);
|
Setattr($$,"template",n);
|
||||||
|
|
|
||||||
|
|
@ -18,18 +18,33 @@ char cvsroot_lang_cxx[] = "$Header$";
|
||||||
#include "cparse.h"
|
#include "cparse.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
static int director_mode = 0; /* set to 0 on default */
|
||||||
static int director_protected_mode = 0; /* set to 0 on default */
|
static int director_protected_mode = 0; /* set to 0 on default */
|
||||||
|
static int template_extmode = 0; /* set to 0 on default */
|
||||||
|
|
||||||
/* Set director_protected_mode */
|
/* Set director_protected_mode */
|
||||||
|
void Wrapper_director_mode_set(int flag) {
|
||||||
|
director_mode = flag;
|
||||||
|
}
|
||||||
|
|
||||||
void Wrapper_director_protected_mode_set(int flag) {
|
void Wrapper_director_protected_mode_set(int flag) {
|
||||||
director_protected_mode = flag;
|
director_protected_mode = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Wrapper_template_extmode_set(int flag) {
|
||||||
|
template_extmode = flag;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int Swig_need_protected()
|
int Swig_need_protected()
|
||||||
{
|
{
|
||||||
return director_protected_mode;
|
return director_protected_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Swig_template_extmode()
|
||||||
|
{
|
||||||
|
return template_extmode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -721,13 +736,10 @@ int Language::cDeclaration(Node *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) {
|
||||||
if (cplus_mode == CPLUS_PRIVATE) {
|
/* and for protected/private members, we check what director needs */
|
||||||
|
if ((cplus_mode == CPLUS_PRIVATE) && (IsVirtual != PURE_VIRTUAL)) return SWIG_NOWRAP;
|
||||||
|
if (!(dirprot_mode() && is_member_director(CurrentClass,n)))
|
||||||
return SWIG_NOWRAP;
|
return SWIG_NOWRAP;
|
||||||
} else {
|
|
||||||
/* and for protected members, we check what director needs */
|
|
||||||
if (!(dirprot_mode() && is_member_director(CurrentClass,n)))
|
|
||||||
return SWIG_NOWRAP;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1473,8 +1485,12 @@ int Language::unrollVirtualMethods(Node *n,
|
||||||
if ((Cmp(nodeType, "cdecl") == 0)) {
|
if ((Cmp(nodeType, "cdecl") == 0)) {
|
||||||
decl = Getattr(ni, "decl");
|
decl = Getattr(ni, "decl");
|
||||||
/* extra check for function type and proper access */
|
/* extra check for function type and proper access */
|
||||||
|
int need_nopublic = dirprot_mode() &&
|
||||||
|
(is_protected(ni) || (is_private(ni)
|
||||||
|
&& (Cmp(Getattr(ni,"value"),"0") == 0)));
|
||||||
|
|
||||||
if (SwigType_isfunction(decl) &&
|
if (SwigType_isfunction(decl) &&
|
||||||
(is_public(ni) || (dirprot_mode() && is_protected(ni)))) {
|
(is_public(ni) || need_nopublic)) {
|
||||||
String *name = Getattr(ni, "name");
|
String *name = Getattr(ni, "name");
|
||||||
String *local_decl = SwigType_typedef_resolve_all(decl);
|
String *local_decl = SwigType_typedef_resolve_all(decl);
|
||||||
Node *method_id = NewStringf("%s|%s", name, local_decl);
|
Node *method_id = NewStringf("%s|%s", name, local_decl);
|
||||||
|
|
@ -1515,7 +1531,7 @@ int Language::unrollVirtualMethods(Node *n,
|
||||||
for (k = First(vm); k.key; k = Next(k)) {
|
for (k = First(vm); k.key; k = Next(k)) {
|
||||||
Node *m = Getattr(k.item, "methodNode");
|
Node *m = Getattr(k.item, "methodNode");
|
||||||
/* retrieve the director features */
|
/* retrieve the director features */
|
||||||
int mdir = checkAttribute(m, "feature:director", "1");
|
int mdir = checkAttribute(m, "feature:director", "1") || director_mode;
|
||||||
int mndir = checkAttribute(m, "feature:nodirector", "1");
|
int mndir = checkAttribute(m, "feature:nodirector", "1");
|
||||||
/* 'nodirector' has precedence over 'director' */
|
/* 'nodirector' has precedence over 'director' */
|
||||||
int dir = (mdir || mndir) ? (mdir && !mndir) : 1;
|
int dir = (mdir || mndir) ? (mdir && !mndir) : 1;
|
||||||
|
|
@ -1769,7 +1785,11 @@ int Language::classDeclaration(Node *n) {
|
||||||
|
|
||||||
/* Call classHandler() here */
|
/* Call classHandler() here */
|
||||||
if (!ImportMode) {
|
if (!ImportMode) {
|
||||||
if (directorsEnabled() && Getattr(n, "feature:director")) {
|
int ndir = checkAttribute(n, "feature:director", "1") || director_mode;
|
||||||
|
int nndir = checkAttribute(n, "feature:nodirector", "1");
|
||||||
|
/* 'nodirector' has precedence over 'director' */
|
||||||
|
int dir = (ndir || nndir) ? (ndir && !nndir) : 1;
|
||||||
|
if (directorsEnabled() && dir) {
|
||||||
classDirector(n);
|
classDirector(n);
|
||||||
}
|
}
|
||||||
classHandler(n);
|
classHandler(n);
|
||||||
|
|
@ -1844,10 +1864,13 @@ int Language::classHandler(Node *n) {
|
||||||
Node* parentnode = Getattr(method, "parentNode");
|
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);
|
||||||
|
int need_private = (is_private(method)
|
||||||
|
&& (Cmp(Getattr(method,"storage"),"virtual") == 0)
|
||||||
|
&& (Cmp(Getattr(method,"value"),"0") == 0));
|
||||||
if (!Getattr(symbols,wrapname)
|
if (!Getattr(symbols,wrapname)
|
||||||
&& !Cmp(director,"1")
|
&& !Cmp(director,"1")
|
||||||
&& (n != parentnode)
|
&& (n != parentnode)
|
||||||
&& is_protected(method)) {
|
&& (is_protected(method) || need_private)) {
|
||||||
Node* m = Copy(method);
|
Node* m = Copy(method);
|
||||||
String* mdecl = Getattr(m,"decl");
|
String* mdecl = Getattr(m,"decl");
|
||||||
Setattr(m,"parentNode", n);
|
Setattr(m,"parentNode", n);
|
||||||
|
|
@ -2375,7 +2398,7 @@ void Language::allow_directors(int val) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int Language::directorsEnabled() const {
|
int Language::directorsEnabled() const {
|
||||||
return directors && CPlusPlus;
|
return (directors || director_mode) && CPlusPlus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ static const char *usage1 = (const char*)"\
|
||||||
\nGeneral Options\n\
|
\nGeneral Options\n\
|
||||||
-c++ - Enable C++ processing\n\
|
-c++ - Enable C++ processing\n\
|
||||||
-co - Check a file out of the SWIG library\n\
|
-co - Check a file out of the SWIG library\n\
|
||||||
|
-directors - Turn on director mode for all the classes, mainly for testing \n\
|
||||||
-dirprot - Turn on wrapping of protected members for director classes\n\
|
-dirprot - Turn on wrapping of protected members for director classes\n\
|
||||||
-D<symbol> - Define a symbol <symbol> (for conditional compilation)\n\
|
-D<symbol> - Define a symbol <symbol> (for conditional compilation)\n\
|
||||||
-E - Preprocess only, does not generate wrapper code\n\
|
-E - Preprocess only, does not generate wrapper code\n\
|
||||||
|
|
@ -278,9 +279,13 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
||||||
Swig_contract_mode_set(1);
|
Swig_contract_mode_set(1);
|
||||||
Preprocessor_define(vers,0);
|
Preprocessor_define(vers,0);
|
||||||
|
|
||||||
/* Turn on director protected mode */
|
/* Turn off directors mode */
|
||||||
|
Wrapper_director_mode_set(0);
|
||||||
Wrapper_director_protected_mode_set(0);
|
Wrapper_director_protected_mode_set(0);
|
||||||
|
|
||||||
|
/* Turn off template extmode */
|
||||||
|
Wrapper_template_extmode_set(0);
|
||||||
|
|
||||||
|
|
||||||
// Check for SWIG_LIB environment variable
|
// Check for SWIG_LIB environment variable
|
||||||
|
|
||||||
|
|
@ -324,10 +329,13 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
||||||
Wrapper_compact_print_mode_set(1);
|
Wrapper_compact_print_mode_set(1);
|
||||||
} else if (strcmp(temp, "-fvirtual") == 0) {
|
} else if (strcmp(temp, "-fvirtual") == 0) {
|
||||||
Wrapper_virtual_elimination_mode_set(1);
|
Wrapper_virtual_elimination_mode_set(1);
|
||||||
|
} else if (strcmp(temp,"-directors") == 0) {
|
||||||
|
Wrapper_director_mode_set(1);
|
||||||
|
Wrapper_director_protected_mode_set(1);
|
||||||
} else if (strcmp(temp,"-dirprot") == 0) {
|
} else if (strcmp(temp,"-dirprot") == 0) {
|
||||||
Wrapper_director_protected_mode_set(1);
|
Wrapper_director_protected_mode_set(1);
|
||||||
} else if (strcmp(temp,"-nodirprot") == 0) {
|
} else if (strcmp(temp,"-nodirprot") == 0) {
|
||||||
Wrapper_director_protected_mode_set(0);
|
Wrapper_director_protected_mode_set(0);
|
||||||
} else if (strcmp(temp, "-small") == 0) {
|
} else if (strcmp(temp, "-small") == 0) {
|
||||||
Wrapper_compact_print_mode_set(1);
|
Wrapper_compact_print_mode_set(1);
|
||||||
Wrapper_virtual_elimination_mode_set(1);
|
Wrapper_virtual_elimination_mode_set(1);
|
||||||
|
|
@ -366,6 +374,10 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
||||||
} else if (strcmp(argv[i],"-fvirtual") == 0) {
|
} else if (strcmp(argv[i],"-fvirtual") == 0) {
|
||||||
Wrapper_virtual_elimination_mode_set(1);
|
Wrapper_virtual_elimination_mode_set(1);
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
|
} else if (strcmp(argv[i],"-directors") == 0) {
|
||||||
|
Wrapper_director_mode_set(1);
|
||||||
|
Wrapper_director_protected_mode_set(1);
|
||||||
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i],"-dirprot") == 0) {
|
} else if (strcmp(argv[i],"-dirprot") == 0) {
|
||||||
Wrapper_director_protected_mode_set(1);
|
Wrapper_director_protected_mode_set(1);
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,9 @@ public:
|
||||||
|
|
||||||
SWIG_library_directory("python");
|
SWIG_library_directory("python");
|
||||||
|
|
||||||
|
/* Turn on template extmode */
|
||||||
|
Wrapper_template_extmode_set(1);
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (argv[i]) {
|
if (argv[i]) {
|
||||||
if(strcmp(argv[i],"-interface") == 0) {
|
if(strcmp(argv[i],"-interface") == 0) {
|
||||||
|
|
@ -748,7 +751,7 @@ public:
|
||||||
if (/*directorbase &&*/ !constructor && !destructor && isVirtual) {
|
if (/*directorbase &&*/ !constructor && !destructor && isVirtual) {
|
||||||
Wrapper_add_local(f, "director", "Swig::Director *director = 0");
|
Wrapper_add_local(f, "director", "Swig::Director *director = 0");
|
||||||
Printf(f->code, "director = dynamic_cast<Swig::Director *>(arg1);\n");
|
Printf(f->code, "director = dynamic_cast<Swig::Director *>(arg1);\n");
|
||||||
if (dirprot_mode() && is_protected(n)) {
|
if (dirprot_mode() && !is_public(n)) {
|
||||||
Printf(f->code, "if (!director || !(director->swig_get_inner(\"%s\"))) {\n", name);
|
Printf(f->code, "if (!director || !(director->swig_get_inner(\"%s\"))) {\n", name);
|
||||||
Printf(f->code, "PyErr_SetString(PyExc_RuntimeError,\"accessing protected member %s\");\n", name);
|
Printf(f->code, "PyErr_SetString(PyExc_RuntimeError,\"accessing protected member %s\");\n", name);
|
||||||
Printf(f->code, "SWIG_fail;\n");
|
Printf(f->code, "SWIG_fail;\n");
|
||||||
|
|
@ -1394,7 +1397,7 @@ public:
|
||||||
String *pyname = Getattr(n,"sym:name");
|
String *pyname = Getattr(n,"sym:name");
|
||||||
|
|
||||||
/* pass the method call on to the Python object */
|
/* pass the method call on to the Python object */
|
||||||
if (dirprot_mode() && is_protected(n))
|
if (dirprot_mode() && !is_public(n))
|
||||||
Printf(w->code, "swig_set_inner(\"%s\", true);\n", name);
|
Printf(w->code, "swig_set_inner(\"%s\", true);\n", name);
|
||||||
|
|
||||||
if (Len(parse_args) > 0) {
|
if (Len(parse_args) > 0) {
|
||||||
|
|
@ -1403,7 +1406,7 @@ public:
|
||||||
Printf(w->code, "result = PyObject_CallMethod(swig_get_self(), \"%s\", NULL);\n", pyname);
|
Printf(w->code, "result = PyObject_CallMethod(swig_get_self(), \"%s\", NULL);\n", pyname);
|
||||||
}
|
}
|
||||||
Printv(xdecref, "Py_XDECREF(result);\n", NULL);
|
Printv(xdecref, "Py_XDECREF(result);\n", NULL);
|
||||||
if (dirprot_mode() && is_protected(n))
|
if (dirprot_mode() && !is_public(n))
|
||||||
Printf(w->code, "swig_set_inner(\"%s\", false);\n", name);
|
Printf(w->code, "swig_set_inner(\"%s\", false);\n", name);
|
||||||
|
|
||||||
/* exception handling */
|
/* exception handling */
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,9 @@ int is_protected(Node* n);
|
||||||
int is_member_director(Node* parentnode, Node* member);
|
int is_member_director(Node* parentnode, Node* member);
|
||||||
int is_member_director(Node* member);
|
int is_member_director(Node* member);
|
||||||
void Wrapper_virtual_elimination_mode_set(int);
|
void Wrapper_virtual_elimination_mode_set(int);
|
||||||
|
void Wrapper_director_mode_set(int);
|
||||||
void Wrapper_director_protected_mode_set(int);
|
void Wrapper_director_protected_mode_set(int);
|
||||||
|
void Wrapper_template_extmode_set(int);
|
||||||
|
|
||||||
|
|
||||||
/* Contracts */
|
/* Contracts */
|
||||||
|
|
|
||||||
|
|
@ -757,9 +757,11 @@ String *SwigType_lcaststr(SwigType *s, const String_or_char *name) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* keep old mangling since Java codes need it */
|
||||||
String *SwigType_manglestr_default(SwigType *s) {
|
String *SwigType_manglestr_default(SwigType *s) {
|
||||||
String *result,*base,*mbase;
|
char *c;
|
||||||
SwigType *lt, *ltp;
|
String *result,*base;
|
||||||
|
SwigType *lt;
|
||||||
SwigType *ss = 0;
|
SwigType *ss = 0;
|
||||||
|
|
||||||
if (SwigType_istemplate(s)) {
|
if (SwigType_istemplate(s)) {
|
||||||
|
|
@ -767,11 +769,14 @@ String *SwigType_manglestr_default(SwigType *s) {
|
||||||
s = ss;
|
s = ss;
|
||||||
}
|
}
|
||||||
lt = SwigType_ltype(s);
|
lt = SwigType_ltype(s);
|
||||||
ltp = SwigType_prefix(lt);
|
result = SwigType_prefix(lt);
|
||||||
base = SwigType_base(lt);
|
base = SwigType_base(lt);
|
||||||
|
|
||||||
result = Swig_string_mangle(ltp);
|
c = Char(result);
|
||||||
|
while (*c) {
|
||||||
|
if (!isalnum((int)*c)) *c = '_';
|
||||||
|
c++;
|
||||||
|
}
|
||||||
if (SwigType_istemplate(base)) {
|
if (SwigType_istemplate(base)) {
|
||||||
String *b = SwigType_namestr(base);
|
String *b = SwigType_namestr(base);
|
||||||
Delete(base);
|
Delete(base);
|
||||||
|
|
@ -782,13 +787,23 @@ String *SwigType_manglestr_default(SwigType *s) {
|
||||||
Replace(base,"class ","", DOH_REPLACE_ANY);
|
Replace(base,"class ","", DOH_REPLACE_ANY);
|
||||||
Replace(base,"union ","", DOH_REPLACE_ANY);
|
Replace(base,"union ","", DOH_REPLACE_ANY);
|
||||||
|
|
||||||
mbase = Swig_string_mangle(base);
|
c = Char(base);
|
||||||
Append(result,mbase);
|
while (*c) {
|
||||||
|
if (*c == '<') *c = 'T';
|
||||||
|
else if (*c == '>') *c = 't';
|
||||||
|
else if (*c == '*') *c = 'p';
|
||||||
|
else if (*c == '[') *c = 'a';
|
||||||
|
else if (*c == ']') *c = 'A';
|
||||||
|
else if (*c == '&') *c = 'R';
|
||||||
|
else if (*c == '(') *c = 'f';
|
||||||
|
else if (*c == ')') *c = 'F';
|
||||||
|
else if (!isalnum((int)*c)) *c = '_';
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
Append(result,base);
|
||||||
Insert(result,0,"_");
|
Insert(result,0,"_");
|
||||||
Delete(lt);
|
Delete(lt);
|
||||||
Delete(ltp);
|
|
||||||
Delete(base);
|
Delete(base);
|
||||||
Delete(mbase);
|
|
||||||
if (ss) Delete(ss);
|
if (ss) Delete(ss);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -501,6 +501,8 @@ extern void Swig_fragment_emit(String *name);
|
||||||
|
|
||||||
/* hacks defined in C++ ! */
|
/* hacks defined in C++ ! */
|
||||||
extern int Swig_need_protected();
|
extern int Swig_need_protected();
|
||||||
|
extern int Swig_director_mode();
|
||||||
|
extern int Swig_template_extmode();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue