More %ignore director fixes

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9370 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2006-09-27 21:24:44 +00:00
commit 95958855cf
7 changed files with 787 additions and 710 deletions

View file

@ -12,6 +12,14 @@
%ignore DIgnoreOnlyConstructor(bool b); %ignore DIgnoreOnlyConstructor(bool b);
%ignore Pointers; %ignore Pointers;
%ignore References; %ignore References;
%ignore PublicMethod1;
%ignore PublicMethod2;
%ignore PublicPureVirtualMethod1;
%ignore PublicPureVirtualMethod2;
%ignore ProtectedMethod1;
%ignore ProtectedMethod2;
%ignore ProtectedPureVirtualMethod1;
%ignore ProtectedPureVirtualMethod2;
%inline %{ %inline %{
@ -25,9 +33,18 @@ class DIgnores
virtual int Triple(int n) { return n*3; } virtual int Triple(int n) { return n*3; }
virtual int& References(int& n) { static int nn; nn=n; return nn; } virtual int& References(int& n) { static int nn; nn=n; return nn; }
virtual int* Pointers(int* n) { static int nn; nn=*n; return &nn; } virtual int* Pointers(int* n) { static int nn; nn=*n; return &nn; }
virtual double PublicMethod1() {}
virtual double PublicPureVirtualMethod1() = 0;
virtual void PublicMethod2() {}
virtual void PublicPureVirtualMethod2() = 0;
virtual void TempMethod() = 0;
protected: protected:
virtual void OverloadedProtectedMethod(int n, int xoffset = 0, int yoffset = 0) {} virtual void OverloadedProtectedMethod(int n, int xoffset = 0, int yoffset = 0) {}
virtual void OverloadedProtectedMethod() {} virtual void OverloadedProtectedMethod() {}
virtual double ProtectedMethod1() {}
virtual double ProtectedPureVirtualMethod1() = 0;
virtual void ProtectedMethod2() {}
virtual void ProtectedPureVirtualMethod2() = 0;
}; };
class DAbstractIgnores class DAbstractIgnores

View file

@ -38,7 +38,15 @@ namespace Swig {
class DirectorMethodException : public Swig::DirectorException {}; class DirectorMethodException : public Swig::DirectorException {};
/* attempt to call a pure virtual method via a director method */ /* attempt to call a pure virtual method via a director method */
class DirectorPureVirtualException : public Swig::DirectorException {}; class DirectorPureVirtualException : public Swig::DirectorException {
public:
DirectorTypeMismatchException(const char* msg="") {
}
static void raise(const char *msg) {
throw DirectorPureVirtualException(msg);
}
};
/* simple thread abstraction for pthreads on win32 */ /* simple thread abstraction for pthreads on win32 */
#ifdef __THREAD__ #ifdef __THREAD__

View file

@ -3118,14 +3118,14 @@ class CSHARP : public Language {
Printf(w->code, "if (!swig_callback%s) {\n", overloaded_name); Printf(w->code, "if (!swig_callback%s) {\n", overloaded_name);
if (!pure_virtual) { if (!pure_virtual) {
String *super_call = Swig_method_call(super, l);
if (is_void) { if (is_void) {
Printf(w->code, "%s;\n", Swig_method_call(super,l)); Printf(w->code, "%s;\n", super_call);
Printf(w->code, "return;\n"); Printf(w->code, "return;\n");
} else { } else {
String *super_call = Swig_method_call(super, l);
Printf(w->code, "return %s;\n", super_call); Printf(w->code, "return %s;\n", super_call);
Delete(super_call);
} }
Delete(super_call);
} else { } else {
Printf(w->code, " throw Swig::DirectorPureVirtualException(\"%s::%s\");\n", c_classname, name); Printf(w->code, " throw Swig::DirectorPureVirtualException(\"%s::%s\");\n", c_classname, name);
} }

View file

@ -3196,14 +3196,14 @@ class JAVA : public Language {
} }
if (!pure_virtual) { if (!pure_virtual) {
String *super_call = Swig_method_call(super, l);
if (is_void) { if (is_void) {
Printf(w->code, "%s;\n", Swig_method_call(super,l)); Printf(w->code, "%s;\n", super_call);
Printf(w->code, "return;\n"); Printf(w->code, "return;\n");
} else { } else {
String *super_call = Swig_method_call(super, l);
Printf(w->code, "return %s;\n", super_call); Printf(w->code, "return %s;\n", super_call);
Delete(super_call);
} }
Delete(super_call);
} else { } else {
Printf(w->code, "SWIG_JavaThrowException(JNIEnvWrapper(this).getJNIEnv(), SWIG_JavaDirectorPureVirtual, "); Printf(w->code, "SWIG_JavaThrowException(JNIEnvWrapper(this).getJNIEnv(), SWIG_JavaDirectorPureVirtual, ");
Printf(w->code, "\"Attempted to invoke pure virtual method %s::%s.\");\n", c_classname, name); Printf(w->code, "\"Attempted to invoke pure virtual method %s::%s.\");\n", c_classname, name);

View file

@ -1490,11 +1490,12 @@ public:
ParmList *l; ParmList *l;
Wrapper *w; Wrapper *w;
String *tm; String *tm;
String *wrap_args; String *wrap_args = NewString("");
String *return_type; String *return_type;
int status = SWIG_OK; int status = SWIG_OK;
int idx; int idx;
bool pure_virtual = false; bool pure_virtual = false;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
storage = Getattr(n, "storage"); storage = Getattr(n, "storage");
value = Getattr(n, "value"); value = Getattr(n, "value");
@ -1545,6 +1546,27 @@ public:
Printf(declaration, " virtual %s %s;\n", rtype, target); Printf(declaration, " virtual %s %s;\n", rtype, target);
Delete(target); Delete(target);
/* declare method return value
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL);
}
}
if (ignored_method) {
if (!pure_virtual) {
if (is_void)
Printf(w->code, "return ");
String *super_call = Swig_method_call(super, l);
Printf(w->code, "%s;\n", super_call);
Delete(super_call);
} else {
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", classname, name);
}
} else {
/* attach typemaps to arguments (C/C++ -> Ocaml) */ /* attach typemaps to arguments (C/C++ -> Ocaml) */
String *arglist = NewString(""); String *arglist = NewString("");
@ -1557,7 +1579,6 @@ public:
int i; int i;
char source[256]; char source[256];
wrap_args = NewString("");
int outputs = 0; int outputs = 0;
if (!is_void) outputs++; if (!is_void) outputs++;
@ -1650,14 +1671,6 @@ public:
p = nextSibling(p); p = nextSibling(p);
} }
/* declare method return value
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL);
}
Printv(w->code, "swig_result = Val_unit;\n",0); Printv(w->code, "swig_result = Val_unit;\n",0);
Printf(w->code,"args = Val_unit;\n"); Printf(w->code,"args = Val_unit;\n");
@ -1742,8 +1755,14 @@ public:
} }
} }
Delete(arglist);
Delete(cleanup);
Delete(outarg);
}
/* any existing helper functions to handle this? */ /* any existing helper functions to handle this? */
if (!is_void) { if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
/* A little explanation: /* A little explanation:
* The director_enum test case makes a method whose return type * The director_enum test case makes a method whose return type
* is an enum type. return_type here is "int". gcc complains * is an enum type. return_type here is "int". gcc complains
@ -1760,6 +1779,7 @@ public:
Printf(w->code, "CAMLreturn(*c_result);\n"); Printf(w->code, "CAMLreturn(*c_result);\n");
} }
} }
}
Printf(w->code, "}\n"); Printf(w->code, "}\n");
@ -1790,12 +1810,9 @@ public:
/* clean up */ /* clean up */
Delete(wrap_args); Delete(wrap_args);
Delete(arglist);
Delete(rtype); Delete(rtype);
Delete(return_type); Delete(return_type);
Delete(pclassname); Delete(pclassname);
Delete(cleanup);
Delete(outarg);
DelWrapper(w); DelWrapper(w);
return status; return status;
} }

View file

@ -3345,13 +3345,14 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
ParmList *l; ParmList *l;
Wrapper *w; Wrapper *w;
String *tm; String *tm;
String *wrap_args; String *wrap_args = NewString("");
String *return_type; String *return_type;
String *value = Getattr(n, "value"); String *value = Getattr(n, "value");
String *storage = Getattr(n,"storage"); String *storage = Getattr(n,"storage");
bool pure_virtual = false; bool pure_virtual = false;
int status = SWIG_OK; int status = SWIG_OK;
int idx; int idx;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
if (Cmp(storage,"virtual") == 0) { if (Cmp(storage,"virtual") == 0) {
if (Cmp(value,"0") == 0) { if (Cmp(value,"0") == 0) {
@ -3425,10 +3426,32 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Append(declaration, ")"); Append(declaration, ")");
} }
Append(w->def, " {"); Append(w->def, " {");
Append(declaration, ";\n"); Append(declaration, ";\n");
/* declare method return value
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *cres = SwigType_lstr(return_type, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
}
if (ignored_method) {
if (!pure_virtual) {
if (is_void)
Printf(w->code, "return ");
String *super_call = Swig_method_call(super, l);
Printf(w->code, "%s;\n", super_call);
Delete(super_call);
} else {
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", classname, name);
}
} else {
/* attach typemaps to arguments (C/C++ -> Python) */ /* attach typemaps to arguments (C/C++ -> Python) */
String *arglist = NewString(""); String *arglist = NewString("");
String* parse_args = NewString(""); String* parse_args = NewString("");
@ -3441,7 +3464,6 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Parm* p; Parm* p;
char source[256]; char source[256];
wrap_args = NewString("");
int outputs = 0; int outputs = 0;
if (!is_void) outputs++; if (!is_void) outputs++;
@ -3572,15 +3594,6 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
if (allow_thread) thread_begin_block(n, w->code); if (allow_thread) thread_begin_block(n, w->code);
/* declare method return value
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
String *cres = SwigType_lstr(return_type, "swig_c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
if (allow_thread) { if (allow_thread) {
Append(w->code, "{\n"); Append(w->code, "{\n");
} }
@ -3718,7 +3731,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
if (Getattr(n,"tmap:directorout:implicitconv")) { if (Getattr(n,"tmap:directorout:implicitconv")) {
Replaceall(tm,"$implicitconv", get_implicitconv_flag(n)); Replaceall(tm,"$implicitconv", get_implicitconv_flag(n));
} }
Replaceall(tm, "$result", "swig_c_result"); Replaceall(tm, "$result", "c_result");
Printv(w->code, tm, "\n", NIL); Printv(w->code, tm, "\n", NIL);
Delete(tm); Delete(tm);
} else { } else {
@ -3751,15 +3764,24 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
thread_end_block(n, w->code); thread_end_block(n, w->code);
} }
Delete(parse_args);
Delete(arglist);
Delete(cleanup);
Delete(outarg);
}
if (!is_void) { if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String* rettype = SwigType_str(return_type, 0); String* rettype = SwigType_str(return_type, 0);
if (!SwigType_isreference(return_type)) { if (!SwigType_isreference(return_type)) {
Printf(w->code, "return (%s) swig_c_result;\n", rettype); Printf(w->code, "return (%s) c_result;\n", rettype);
} else { } else {
Printf(w->code, "return (%s) *swig_c_result;\n", rettype); Printf(w->code, "return (%s) *c_result;\n", rettype);
} }
Delete(rettype); Delete(rettype);
} }
}
Append(w->code, "}\n"); Append(w->code, "}\n");
// We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
@ -3789,13 +3811,9 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
/* clean up */ /* clean up */
Delete(wrap_args); Delete(wrap_args);
Delete(parse_args);
Delete(arglist);
Delete(rtype); Delete(rtype);
Delete(return_type); Delete(return_type);
Delete(pclassname); Delete(pclassname);
Delete(cleanup);
Delete(outarg);
DelWrapper(w); DelWrapper(w);
return status; return status;
} }

View file

@ -2289,7 +2289,7 @@ public:
ParmList *l; ParmList *l;
Wrapper *w; Wrapper *w;
String *tm; String *tm;
String *wrap_args; String *wrap_args = NewString("");
String *return_type; String *return_type;
Parm* p; Parm* p;
String *value = Getattr(n, "value"); String *value = Getattr(n, "value");
@ -2297,6 +2297,7 @@ public:
bool pure_virtual = false; bool pure_virtual = false;
int status = SWIG_OK; int status = SWIG_OK;
int idx; int idx;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
if (Cmp(storage,"virtual") == 0) { if (Cmp(storage,"virtual") == 0) {
if (Cmp(value,"0") == 0) { if (Cmp(value,"0") == 0) {
@ -2372,11 +2373,30 @@ public:
Append(w->def, " {"); Append(w->def, " {");
Append(declaration, ";\n"); Append(declaration, ";\n");
/* declare method return value
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL);
}
}
if (ignored_method) {
if (!pure_virtual) {
if (is_void)
Printf(w->code, "return ");
String *super_call = Swig_method_call(super, l);
Printf(w->code, "%s;\n", super_call);
Delete(super_call);
} else {
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", classname, name);
}
} else {
/* attach typemaps to arguments (C/C++ -> Ruby) */ /* attach typemaps to arguments (C/C++ -> Ruby) */
String *arglist = NewString(""); String *arglist = NewString("");
/** /**
* For each parameter to the C++ member function, copy the parameter name * For each parameter to the C++ member function, copy the parameter name
* to its "lname"; this ensures that Swig_typemap_attach_parms() will do * to its "lname"; this ensures that Swig_typemap_attach_parms() will do
@ -2393,7 +2413,6 @@ public:
int i; int i;
char source[256]; char source[256];
wrap_args = NewString("");
int outputs = 0; int outputs = 0;
if (!is_void) outputs++; if (!is_void) outputs++;
@ -2488,13 +2507,6 @@ public:
p = nextSibling(p); p = nextSibling(p);
} }
/* declare method return value
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL);
}
/* declare Ruby return value */ /* declare Ruby return value */
Wrapper_add_local(w, "result", "VALUE result"); Wrapper_add_local(w, "result", "VALUE result");
@ -2578,8 +2590,14 @@ public:
} }
} }
Delete(arglist);
Delete(cleanup);
Delete(outarg);
}
/* any existing helper functions to handle this? */ /* any existing helper functions to handle this? */
if (!is_void) { if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String* rettype = SwigType_str(return_type, 0); String* rettype = SwigType_str(return_type, 0);
if (!SwigType_isreference(return_type)) { if (!SwigType_isreference(return_type)) {
Printf(w->code, "return (%s) c_result;\n", rettype); Printf(w->code, "return (%s) c_result;\n", rettype);
@ -2588,6 +2606,8 @@ public:
} }
Delete(rettype); Delete(rettype);
} }
}
Printf(w->code, "}\n"); Printf(w->code, "}\n");
// We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
@ -2617,12 +2637,9 @@ public:
/* clean up */ /* clean up */
Delete(wrap_args); Delete(wrap_args);
Delete(arglist);
Delete(rtype); Delete(rtype);
Delete(return_type); Delete(return_type);
Delete(pclassname); Delete(pclassname);
Delete(cleanup);
Delete(outarg);
DelWrapper(w); DelWrapper(w);
return status; return status;
} }