Initial C++ exceptions support (still work in progress). Some typemap fixes.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10661 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Maciej Drwal 2008-07-14 19:38:10 +00:00
commit 03d275e42f
3 changed files with 261 additions and 113 deletions

View file

@ -5,11 +5,14 @@
int main(int argc, char** argv) {
Bar *b = foo_ret_val();
printf("x = %d\n", Bar_get(b));
Bar *bp = foo_ret_ptr(NULL);
Bar *br = foo_ret_ref(new_Bar());
Bar *c = new_Bar();
Bar *bp = foo_ret_ptr(c);
//Bar *br = foo_ret_ref(c);
delete_Bar(b);
delete_Bar(br);
delete_Bar(bp);
delete_Bar(c);
return 0;
}

View file

@ -8,46 +8,57 @@
%insert("runtime") "clabels.swg"
%insert("proxy_header") "cproxy.swg"
%insert("runtime") %{
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
%}
// typemaps for function parameters
%typemap(ctype) void, short, int, long, char, float, double "$1_type"
%typemap(ctype) unsigned short, unsigned int, unsigned long, unsigned char "$1_type"
%typemap(ctype) void*, short*, int*, long*, char*, float*, double* "$1_type"
%typemap(ctype) unsigned short*, unsigned int*, unsigned long*, unsigned char* "$1_type"
%typemap(ctype) short&, int&, long&, char&, float&, double& "$1_basetype *"
%typemap(ctype) unsigned short&, unsigned int&, unsigned long&, unsigned char& "$1_basetype *"
%typemap(ctype) const short, const int, const long, const char, const float, const double "$1_basetype"
%typemap(ctype) const unsigned short, const unsigned int, const unsigned long, const unsigned char "$1_basetype"
%typemap(ctype) void *, short *, int *, long *, char *, float *, double * "$1_type"
%typemap(ctype) void **, short **, int **, long **, char **, float **, double ** "$1_type"
%typemap(ctype) unsigned short *, unsigned int *, unsigned long *, unsigned char * "$1_type"
%typemap(ctype) unsigned short **, unsigned int **, unsigned long **, unsigned char ** "$1_type"
%typemap(ctype) short &, int &, long &, char &, float &, double & "$1_basetype *"
%typemap(ctype) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$1_basetype *"
%typemap(ctype) const short, const int, const long, const char, const float, const double "$1_type"
%typemap(ctype) const unsigned short, const unsigned int, const unsigned long, const unsigned char "$1_type"
%typemap(ctype) const void *, const short *, const int *, const long *, const char *, const float *, const double * "$1_type"
%typemap(ctype) bool "_Bool"
%typemap(ctype) SWIGTYPE "$1_type"
%typemap(ctype) SWIGTYPE * "$1_type"
%typemap(ctype) SWIGTYPE & "$1_type"
%typemap(ctype) SWIGTYPE * [ANY] "$1_basetype*"
%typemap(ctype) SWIGCLASSTYPE "struct SwigObj$1_type *"
%typemap(ctype) SWIGCLASSTYPE * "struct SwigObj$1_type"
%typemap(ctype) SWIGCLASSTYPE & "struct SwigObj$1_basetype *"
%typemap(ctype) SWIGCLASSTYPE * [ANY] "struct SwigObj$1_basetype *"
%typemap(ctype) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY] "$1 = ($1_basetype*) $input;"
%typemap(ctype) SWIGTYPE "struct SwigObj$1_type *"
%typemap(ctype) SWIGTYPE * "struct SwigObj$1_type"
%typemap(ctype) SWIGTYPE & "struct SwigObj$1_basetype*"
%typemap(ctype) SWIGTYPE * [ANY] "struct SwigObj$1_basetype*"
%typemap(in) short, int, long, char, float, double, bool "$1 = ($1_basetype) $input;"
%typemap(in) void*, short*, int*, long*, char*, float*, double*, bool* "$1 = ($1_basetype *) $input;"
%typemap(in) short&, int&, long&, char&, float&, double&, bool& "$1 = ($1_basetype *) $input;"
%typemap(in) short, int, long, char, float, double, bool "$1 = ($1_type) $input;"
%typemap(in) void *, short *, int *, long *, char *, float *, double *, bool * "$1 = ($1_type) $input;"
%typemap(in) void **, short **, int **, long **, char **, float **, double **, bool * "$1 = ($1_type) $input;"
%typemap(in) unsigned short *, unsigned int *, unsigned long *, unsigned char * "$1 = ($1_type) $input;"
%typemap(in) unsigned short **, unsigned int **, unsigned long **, unsigned char ** "$1 = ($1_type) $input;"
%typemap(in) const void *, const short *, const int *, const long *, const char *, const float *, const double *, const bool * "$1 = ($1_basetype *) $input;"
%typemap(in) const unsigned short *, const unsigned int *, const unsigned long *, const unsigned char * "$1 = ($1_type) $input;"
%typemap(in) unsigned short, unsigned int, unsigned long, unsigned char "$1 = ($1_type) $input;"
%typemap(in) short &, int &, long &, char &, float &, double &, bool & "$1 = ($1_basetype *) $input;"
%typemap(in) const short &, const int &, const long &, const char &, const float &, const double &, const bool & "$1 = ($1_basetype const *) $input;"
%typemap(in) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$1 = ($1_basetype *) $input;"
%typemap(in) const unsigned short &, const unsigned int &, const unsigned long &, const unsigned char & "$1 = ($1_basetype const *) $input;"
%typemap(in) SWIGTYPE "$1 = ($1_type) $input;"
%typemap(in) SWIGTYPE * "$1 = ($1_type) $input;"
%typemap(in) SWIGTYPE & "$1 = ($1_type) $input;"
%typemap(in) SWIGTYPE * [ANY] "$1 = ($1_basetype*) $input;"
%typemap(in) SWIGCLASSTYPE {
%typemap(in) SWIGTYPE {
$1 = * ($1_type *) ($input->obj);
}
%typemap(in) SWIGCLASSTYPE * {
%typemap(in) SWIGTYPE * {
if ($input)
$1 = ($1_type) $input->obj;
else
$1 = ($1_type) 0;
}
%typemap(in) SWIGCLASSTYPE * [ANY] {
%typemap(in) SWIGTYPE * [ANY] {
if ($input) {
$1 = ($1_basetype*) malloc($1_dim0 * sizeof($1_basetype));
int i;
@ -61,7 +72,7 @@
$1 = ($1_basetype*) 0;
}
%typemap(in) SWIGCLASSTYPE & {
%typemap(in) SWIGTYPE & {
if ($input)
$1 = ($1_basetype *) $input->obj;
else
@ -71,18 +82,31 @@
// typemaps for return values
%typemap(couttype) void, short, int, long, char, float, double "$1_type"
%typemap(couttype) void*, short*, int*, long*, char*, float*, double* "$1_type"
%typemap(couttype) void *, short *, int *, long *, char *, float *, double* "$1_type"
%typemap(couttype) const short, const int, const long, const char, const float, const double "$1_basetype"
%typemap(couttype) const void *, const short *, const int *, const long *, const char *, const float *, const double * "$1_type"
%typemap(couttype) short &, int &, long &, char &, float &, double & "$1_basetype *"
%typemap(couttype) const short &, const int &, const long &, const char &, const float &, const double & "$1_basetype const *"
%typemap(couttype) bool "_Bool"
%typemap(couttype) SWIGCLASSTYPE "struct SwigObj$1_type *"
%typemap(couttype) SWIGCLASSTYPE * "struct SwigObj$1_type"
%typemap(couttype) SWIGCLASSTYPE & "struct SwigObj$1_basetype *"
%typemap(couttype) SWIGTYPE "struct SwigObj$1_type *"
%typemap(couttype) SWIGTYPE * "struct SwigObj$1_type"
%typemap(couttype) SWIGTYPE & "struct SwigObj$1_basetype *"
%typemap(out) short, int, long, char, float, double, bool "$result = $1;"
%typemap(out) void*, short*, int*, long*, char*, float*, double*, bool* "$result = $1;"
%typemap(out) const short, const int, const long, const char, const float, const double "$result = $1;"
%typemap(out) const void *, const short *, const int *, const long *, const char *, const float *, const double * "$result = $1;"
%typemap(out) unsigned short, unsigned int, unsigned long, unsigned char "$result = $1;"
%typemap(out) unsigned short *, unsigned int *, unsigned long *, unsigned char * "$result = $1;"
%typemap(out) short &, int &, long &, char &, float &, double & "$result = $1;"
%typemap(out) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$result = $1;"
%typemap(out) const short &, const int &, const long &, const char &, const float &, const double & "$result = $1;"
%typemap(out) const unsigned short &, const unsigned int &, const unsigned long &, const unsigned char & "$result = $1;"
%typemap(out) void ""
%typemap(out) SWIGCLASSTYPE {
// allocate new "object-struct" by default
%typemap(out) SWIGTYPE {
$result = (struct SwigObj$1_type *) malloc(sizeof(struct SwigObj$1_type));
$result->obj = (void*) &$1;
#if SWIG_C_RUNTIME
@ -90,7 +114,7 @@
#endif
}
%typemap(out) SWIGCLASSTYPE * {
%typemap(out) SWIGTYPE * {
$result = (struct SwigObj$1_type) malloc(sizeof(struct SwigObj$*1_type));
$result->obj = (void*) $1;
#if SWIG_C_RUNTIME
@ -98,7 +122,7 @@
#endif
}
%typemap(out) SWIGCLASSTYPE & {
%typemap(out) SWIGTYPE & {
$result = (struct SwigObj$1_basetype *) malloc(sizeof(struct SwigObj$1_basetype));
$result->obj = (void*) $1;
#if SWIG_C_RUNTIME
@ -106,3 +130,138 @@
#endif
}
// exception handling
%typemap(throws) SWIGTYPE {
(void)_e;
SWIG_CThrowException(3, "C++ $1_type exception thrown");
}
%insert("runtime") %{
#define SWIG_MAX_HANDLERS 256
#define SWIG_MAX_RT_STACK 256
SWIGEXPORTC int SWIG_exception_code;
SWIGEXPORTC jmp_buf SWIG_rt_env;
SWIGEXPORTC int SWIG_rt_init = 0;
SWIGINTERN struct {
int reg;
int code;
void (*fun)();
} SWIG_Handlers[SWIG_MAX_HANDLERS];
SWIGINTERN int SWIG_next_handler = 0;
SWIGINTERN jmp_buf *SWIG_rt_stack_base = 0;
SWIGINTERN jmp_buf *SWIG_rt_stack_ptr = 0;
SWIGINTERN void SWIG_rt_stack_push() {
// TODO: check for stack overflow
memcpy(SWIG_rt_stack_ptr, SWIG_rt_env, sizeof(SWIG_rt_env));
SWIG_rt_stack_ptr++;
}
SWIGINTERN void SWIG_rt_stack_pop() {
if (SWIG_rt_stack_ptr == SWIG_rt_stack_base)
return;
SWIG_rt_stack_ptr--;
memcpy(SWIG_rt_env, SWIG_rt_stack_ptr, sizeof(SWIG_rt_env));
}
#ifdef __cplusplus
extern "C" {
#endif
SWIGEXPORTC void SWIG_rt_try() {
SWIG_rt_stack_push();
}
SWIGEXPORTC int SWIG_rt_catch(int code) {
int result = (SWIG_exception_code == code);
if (result)
SWIG_rt_stack_pop();
return result;
}
SWIGEXPORTC void SWIG_rt_throw(int code) {
longjmp(SWIG_rt_env, code);
}
SWIGEXPORTC void SWIG_rt_endtry() {
SWIG_rt_stack_pop();
longjmp(SWIG_rt_env, SWIG_exception_code);
}
SWIGEXPORTC void SWIG_Register_Handler(int code, void (*fun)()) {
if (SWIG_next_handler < SWIG_MAX_HANDLERS) {
int i = SWIG_next_handler++;
SWIG_Handlers[i].reg = 1;
SWIG_Handlers[i].code = code;
SWIG_Handlers[i].fun = fun;
}
}
SWIGEXPORTC void SWIG_Unregister_Handler(int code) {
int i;
for (i = 0; i < SWIG_next_handler; ++i) {
if (SWIG_Handlers[i].code == code)
SWIG_Handlers[i].reg = 0;
}
}
#ifdef __cplusplus
}
#endif
SWIGINTERN void SWIG_Runtime_init() {
int i, code;
if (!SWIG_rt_init) {
SWIG_rt_init = 1;
for (i = 0; i < SWIG_MAX_HANDLERS; ++i)
SWIG_Handlers[i].reg = 0;
SWIG_rt_stack_base = SWIG_rt_stack_ptr = (jmp_buf *) malloc(sizeof(jmp_buf) * SWIG_MAX_RT_STACK);
if (code = setjmp(SWIG_rt_env)) {
for (i = 0; i < SWIG_next_handler; ++i) {
if (SWIG_Handlers[i].reg)
if (SWIG_Handlers[i].code == code)
SWIG_Handlers[i].fun();
}
fprintf(stderr, "Unhandled exception. Exitting...\n");
exit(code);
}
}
}
SWIGINTERN void SWIG_CThrowException(int code, char *msg) {
if (SWIG_rt_init)
longjmp(SWIG_rt_env, code);
else {
fprintf(stderr, "%s\n", msg);
exit(code);
}
}
%}
%insert("proxy_header") %{
#include <setjmp.h>
void SWIG_Register_Handler(int code, void (*fun)());
void SWIG_Unregister_Handler(int code);
int SWIG_exception_try();
void SWIG_exception_throw();
SWIGIMPORT jmp_buf SWIG_rt_env;
SWIGIMPORT int SWIG_exception_code;
SWIGIMPORT void SWIG_rt_try();
SWIGIMPORT int SWIG_rt_catch();
SWIGIMPORT void SWIG_rt_throw(int val);
SWIGIMPORT int SWIG_rt_endtry();
#define SWIG_try \
SWIG_rt_try(); \
if ((SWIG_exception_code = setjmp(SWIG_rt_env)) == 0)
#define SWIG_catch(val) else if (SWIG_rt_catch(val))
#define SWIG_throw(val) SWIG_rt_throw(val);
#define SWIG_endtry else SWIG_rt_endtry();
%}

View file

@ -29,6 +29,7 @@ class C:public Language {
bool proxy_flag;
bool runtime_flag;
bool typecheck_flag;
public:
@ -39,7 +40,8 @@ public:
C() :
empty_string(NewString("")),
proxy_flag(true),
runtime_flag(false) {
runtime_flag(true),
typecheck_flag(false) {
}
/* ------------------------------------------------------------
@ -59,7 +61,7 @@ public:
SWIG_typemap_lang("c");
SWIG_config_file("c.swg");
Swig_typemap_class_distinguish(true);
Swig_typemap_class_distinguish(false);
// look for certain command line options
for (int i = 1; i < argc; i++) {
@ -105,25 +107,6 @@ public:
Swig_banner(f_runtime);
Printf(f_header, "#include <stdlib.h>\n");
if (runtime_flag) {
Printf(f_header, "#include <stdio.h>\n");
//Printf(f_header, "#include <stdlib.h>\n");
Printf(f_header, "#include <string.h>\n");
Printf(f_header, "#include <setjmp.h>\n\n");
Printf(f_header, "static jmp_buf Swig_rt_env;\n");
Printf(f_header, "static int Swig_rt_init = 0;\n\n");
Printf(f_header, "void Swig_runtime_init() {\n");
Printf(f_header, " if (!Swig_rt_init) {\n");
Printf(f_header, " Swig_rt_init = 1;\n");
Printf(f_header, " if (setjmp(Swig_rt_env)) {\n");
Printf(f_header, " fprintf(stderr, \"An error occured. Exitting...\\n\");\n");
Printf(f_header, " exit(1);\n");
Printf(f_header, " }\n");
Printf(f_header, " }\n");
Printf(f_header, "}\n\n");
}
// generate proxy files if enabled
if (proxy_flag) {
f_proxy_code_init = NewString("");
@ -150,6 +133,7 @@ public:
Swig_banner(f_proxy_code_init);
Swig_banner(f_proxy_header);
Printf(f_proxy_code_init, "#include \"%s\"\n\n", proxy_header_filename);
Printf(f_proxy_header, "#ifndef _%s_proxy_H_\n#define _%s_proxy_H_\n\n", Char(module), Char(module));
}
Swig_register_filebyname("header", f_header);
@ -172,7 +156,7 @@ public:
if (proxy_flag) {
Printv(f_proxy_c, f_proxy_code_init, "\n", NIL);
Printv(f_proxy_c, f_proxy_code_body, "\n", NIL);
Printv(f_proxy_h, f_proxy_header, "\n", NIL);
Printv(f_proxy_h, f_proxy_header, "\n#endif /* _", Char(module), "_proxy_H_ */\n", NIL);
Close(f_proxy_c);
Close(f_proxy_h);
Delete(f_proxy_code_init);
@ -222,7 +206,7 @@ public:
String *arg_list = NewString("");
if (SwigType_type(Getattr(n, "type")) != T_VOID) {
Printv(action, "$cppresult = (", SwigType_str(Getattr(n, "type"), 0), ") ", NIL);
Printv(action, "$cppresult = $mod (", SwigType_str(Getattr(n, "type"), 0), ") ", NIL);
}
Printv(action, Swig_cfunction_call(Getattr(n, "name"), parms), ";", NIL);
Setattr(n, "wrap:action", action);
@ -342,7 +326,7 @@ public:
Printf(wrapper->code, "}");
}
else {
// mangle name if functions is overloaded
// mangle name if function is overloaded
if (Getattr(n, "sym:overloaded")) {
if (!Getattr(n, "copy_constructor")) {
if (parms)
@ -373,7 +357,7 @@ public:
Printf(return_type, "%s", tm);
}
else {
Swig_warning(WARN_C_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(type, 0));
Swig_warning(WARN_C_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No couttype typemap defined for %s\n", SwigType_str(type, 0));
}
// attach 'ctype' typemaps
@ -467,9 +451,20 @@ public:
String *action = emit_action(n);
Replaceall(action, "$cppresult", "cppresult");
// return-by-reference hack
if (SwigType_isreference(type))
Replaceall(action, "&)", "*)&");
// handle return-by-reference
if (SwigType_isreference(type)) {
String *ref_cast = NewString("");
if (SwigType_isconst(SwigType_del_reference(type))) {
Printf(ref_cast, "const_cast<%s*>(&", SwigType_str(SwigType_base(type), 0));
Replaceall(action, ";", ");");
}
else
Printf(ref_cast, "&");
Replaceall(action, "$mod", ref_cast);
Delete(ref_cast);
}
else
Replaceall(action, "$mod", "");
// emit output typemap if needed
if (!is_void_return && (Cmp(Getattr(n, "c:objstruct"), "1") != 0)) {
@ -502,7 +497,7 @@ public:
}
// emit proxy functions prototypes
Printv(f_proxy_code_init, "extern ", return_type, " ", wname, "(", proto, ");\n", NIL);
Printv(f_proxy_code_init, return_type, " ", wname, "(", proto, ");\n", NIL);
Printv(f_proxy_code_body, return_type, " ", name, "(", proto, ") {\n", NIL);
// call to the wrapper function
@ -578,10 +573,15 @@ public:
* --------------------------------------------------------------------- */
virtual int classHandler(Node *n) {
String *name = Copy(Getattr(n, "name"));
String *name = NewString("");
String *sobj = NewString("");
List *baselist = Getattr(n, "bases");
Replaceall(name, "::", "_");
String *prefix = Swig_scopename_prefix(Getattr(n, "classtype"));
if (prefix)
Printf(name, "%s_", Swig_name_mangle(prefix));
Append(name, Getattr(n, "sym:name"));
Setattr(n, "sym:name", name);
if (CPlusPlus) {
// inheritance support: attach all members from base classes to this class
@ -598,6 +598,7 @@ public:
if (!is_in(Getattr(node, "name"), n)) {
Node* new_node = copy_node(node);
Setattr(new_node, "sym:name", Getattr(new_node, "name"));
Setattr(new_node, "sym:symtab", Getattr(n, "symtab"));
set_nodeType(new_node, "cdecl");
// make sure there are no copyied object-structs params
ParmList* all_parms = Getattr(new_node, "parms"), * parms;
@ -661,15 +662,13 @@ public:
virtual int staticmemberfunctionHandler(Node *n) {
String *name = Getattr(n, "name");
String *classname = Getattr(parentNode(n), "sym:name");
String *newclassname = Copy(classname);
String *classname = Getattr(parentNode(n), "typename");
String *newclassname = Getattr(parentNode(n), "sym:name");
String *new_name = NewString("");
String *code = NewString("");
String *arg_lnames = NewString("");
ParmList *parms = Getattr(n, "parms");
Replaceall(newclassname, "::", "_");
// prepare function call
Append(arg_lnames, Swig_cfunction_call(empty_string, parms));
Delitem(arg_lnames, 0);
@ -680,7 +679,7 @@ public:
Setattr(n, "sym:name", new_name);
// generate action code
Printv(code, (Strcmp(Getattr(n, "type"), "void") != 0) ? "$cppresult = " : "", NIL);
Printv(code, (Strcmp(Getattr(n, "type"), "void") != 0) ? "$cppresult = $mod " : "", NIL);
Printv(code, classname, "::", name, "(", arg_lnames, ");\n", NIL);
Setattr(n, "wrap:action", code);
@ -689,7 +688,6 @@ public:
Delete(arg_lnames);
Delete(code);
Delete(new_name);
Delete(newclassname);
return SWIG_OK;
}
@ -699,8 +697,8 @@ public:
virtual int memberfunctionHandler(Node *n) {
String *name = Getattr(n, "name");
String *classname = Getattr(parentNode(n), "sym:name");
String *newclassname = Copy(classname);
String *classname = Getattr(parentNode(n), "classtype");
String *newclassname = Getattr(parentNode(n), "sym:name");
String *sobj_name = NewString("");
String *ctype = NewString("");
String *stype = NewString("");
@ -709,8 +707,6 @@ public:
String *arg_lnames = NewString("");
ParmList *parms = Getattr(n, "parms");
Replaceall(newclassname, "::", "_");
// create first argument
Printv(sobj_name, "struct SwigObj", newclassname, NIL);
ctype = Copy(sobj_name);
@ -742,9 +738,9 @@ public:
Setattr(n, "sym:name", new_name);
// generate action code
if (runtime_flag)
if (typecheck_flag)
emit_runtime_typecheck(newclassname, new_name, code);
Printv(code, (Strcmp(Getattr(n, "type"), "void") != 0) ? "$cppresult = " : "", NIL);
Printv(code, (Strcmp(Getattr(n, "type"), "void") != 0) ? "$cppresult = $mod " : "", NIL);
Printv(code, "((", classname, "*) arg1->obj)->", name, "(", arg_call_lnames, ");\n", NIL);
Setattr(n, "wrap:action", code);
@ -756,7 +752,6 @@ public:
Delete(stype);
Delete(ctype);
Delete(sobj_name);
Delete(newclassname);
return SWIG_OK;
}
@ -774,11 +769,11 @@ public:
String *action = NewString("");
ParmList *parms = Getattr(n, "parms");
if (parms)
if (runtime_flag && Getattr(parms, "c:objstruct"))
if (typecheck_flag && Getattr(parms, "c:objstruct"))
emit_runtime_typecheck(newclassname, new_name, action);
if (!code) {
code = NewString("");
Printv(code, "$cppresult = ((", classname, "*) arg1->obj)->", name, ";\n", NIL);
Printv(code, "$cppresult = $mod ((", classname, "*) arg1->obj)->", name, ";\n", NIL);
}
Append(action, code);
@ -805,7 +800,7 @@ public:
String *action = NewString("");
ParmList *parms = Getattr(n, "parms");
if (parms)
if (runtime_flag && Getattr(parms, "c:objstruct"))
if (typecheck_flag && Getattr(parms, "c:objstruct"))
emit_runtime_typecheck(newclassname, new_name, action);
if (!code) {
code = NewString("");
@ -829,14 +824,13 @@ public:
virtual int staticmembervariableHandler(Node *n) {
String *name = Getattr(n, "sym:name");
SwigType *type = Copy(Getattr(n, "type"));
String *classname = Getattr(parentNode(n), "sym:name");
String *newclassname = Copy(classname);
String *classname = Getattr(parentNode(n), "classtype");
String *newclassname = Getattr(parentNode(n), "sym:name");
String *new_name = NewString("");
String *code = NewString("");
Replaceall(newclassname, "::", "_");
// create code for 'get' function
Printv(code, "$cppresult = ", classname, "::", name, ";\n", NIL);
Printv(code, "$cppresult = $mod ", classname, "::", name, ";\n", NIL);
wrap_get_variable(n, classname, newclassname, name, code);
// create parameter for 'set' function
@ -865,13 +859,12 @@ public:
virtual int membervariableHandler(Node *n) {
String *name = Getattr(n, "sym:name");
SwigType *type = Copy(Getattr(n, "type"));
String *classname = Getattr(parentNode(n), "sym:name");
String *newclassname = Copy(classname);
String *classname = Getattr(parentNode(n), "classtype");
String *newclassname = Getattr(parentNode(n), "sym:name");
String *sobj_name = NewString("");
String *ctype = NewString("");
String *stype;
String *new_name = NewString("");
Replaceall(newclassname, "::", "_");
// create first argument
Printv(sobj_name, "struct SwigObj", newclassname, NIL);
@ -904,7 +897,6 @@ public:
Delete(stype);
Delete(ctype);
Delete(sobj_name);
Delete(newclassname);
Delete(type);
return SWIG_OK;
}
@ -925,7 +917,7 @@ public:
}
}
Printf(code, "result->typenames[%d] = 0;\n", i);
Printf(code, "Swig_runtime_init();\n");
Printf(code, "SWIG_Runtime_init();\n");
}
/* ---------------------------------------------------------------------
@ -936,8 +928,8 @@ public:
if (Getattr(n, "copy_constructor"))
return copyconstructorHandler(n);
String *classname = Getattr(parentNode(n), "sym:name");
String *newclassname = Copy(classname);
String *classname = Getattr(parentNode(n), "classtype");
String *newclassname = Getattr(parentNode(n), "sym:name");
String *sobj_name = NewString("");
String *ctype;
String *stype;
@ -946,8 +938,6 @@ public:
String *arg_lnames = NewString("");
ParmList *parms = Getattr(n, "parms");
Replaceall(newclassname, "::", "_");
// prepare argument names
Append(arg_lnames, Swig_cfunction_call(empty_string, parms));
@ -962,7 +952,7 @@ public:
Setattr(n, "c:stype", stype);
// modify the constructor name
Printv(constr_name, "new_", newclassname, NIL);
constr_name = Swig_name_construct(newclassname);
Setattr(n, "name", constr_name);
Setattr(n, "sym:name", constr_name);
@ -982,7 +972,6 @@ public:
Delete(stype);
Delete(ctype);
Delete(sobj_name);
Delete(newclassname);
return SWIG_OK;
}
@ -991,8 +980,8 @@ public:
* --------------------------------------------------------------------- */
virtual int copyconstructorHandler(Node *n) {
String *classname = Getattr(parentNode(n), "sym:name");
String *newclassname = Copy(classname);
String *classname = Getattr(parentNode(n), "classtype");
String *newclassname = Getattr(parentNode(n), "sym:name");
String *sobj_name = NewString("");
String *ctype;
String *stype;
@ -1000,7 +989,6 @@ public:
String *constr_name = NewString("");
ParmList *parms = Getattr(n, "parms");
Replaceall(newclassname, "::", "_");
Setattr(parms, "lname", "arg1");
// set the function return type to the pointer to struct
@ -1014,7 +1002,7 @@ public:
Setattr(n, "c:stype", stype);
// modify the constructor name
Printv(constr_name, "copy_", newclassname, NIL);
constr_name = Swig_name_construct(newclassname);
Setattr(n, "name", constr_name);
Setattr(n, "sym:name", constr_name);
@ -1033,7 +1021,6 @@ public:
Delete(stype);
Delete(ctype);
Delete(sobj_name);
Delete(newclassname);
return SWIG_OK;
}
@ -1042,8 +1029,8 @@ public:
* --------------------------------------------------------------------- */
virtual int destructorHandler(Node *n) {
String *classname = Getattr(parentNode(n), "sym:name");
String *newclassname = Copy(classname);
String *classname = Getattr(parentNode(n), "classtype");
String *newclassname = Getattr(parentNode(n), "sym:name");
String *sobj_name = NewString("");
String *ctype;
String *stype;
@ -1051,9 +1038,6 @@ public:
String *destr_name = NewString("");
Parm *p;
Replaceall(newclassname, "::", "_");
Replaceall(newclassname, "~", "");
// create first argument
Printv(sobj_name, "struct SwigObj", newclassname, " ", NIL);
ctype = Copy(sobj_name);
@ -1068,13 +1052,16 @@ public:
Setattr(n, "type", "void");
// modify the destructor name
Printv(destr_name, "delete_", newclassname, NIL);
destr_name = Swig_name_destroy(newclassname);
Setattr(n, "sym:name", destr_name);
// create action code
if (runtime_flag)
if (typecheck_flag)
emit_runtime_typecheck(newclassname, destr_name, code);
Printv(code, "delete (", classname, "*) (arg1->obj);\nfree(arg1);\n", NIL);
Printv(code, "if (arg1)\n if (arg1->obj) {\n", NIL);
Printv(code, " delete (", classname, "*) (arg1->obj);\nfree(arg1);\n", NIL);
Printv(code, " arg1 = (", sobj_name, "*)0;\n}\n", NIL);
Setattr(n, "wrap:action", code);
functionWrapper(n);
@ -1085,7 +1072,6 @@ public:
Delete(stype);
Delete(ctype);
Delete(sobj_name);
Delete(newclassname);
return SWIG_OK;
}