Some function return cases fixed.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10748 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Maciej Drwal 2008-08-09 20:14:41 +00:00
commit ea556b565d
3 changed files with 91 additions and 55 deletions

View file

@ -28,14 +28,14 @@ typedef struct {
%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) 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 short, const int, const long, const char, const float, const double "$1_type"
%typemap(ctype) const short &, const int &, const long &, const char &, const float &, const double & "$1_basetype const *"
%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 *, const bool * "$1_type"
%typemap(ctype) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY], bool [ANY] "$1_basetype *"
%typemap(ctype) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY], bool * [ANY] "$1_basetype **"
%typemap(ctype) const void *, const short *, const int *, const long *, const char *, const float *, const double * "$1_type"
%typemap(ctype) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY] "$1_basetype *"
%typemap(ctype) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY] "$1_basetype **"
%typemap(ctype) SWIGTYPE "SwigObj *"
%typemap(ctype) SWIGTYPE * "SwigObj *"
%typemap(ctype) SWIGTYPE & "SwigObj *"
@ -44,25 +44,27 @@ typedef struct {
%fragment("stdbool_inc", "proxy_header") {#include <stdbool.h>}
%typemap(ctype, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool *, bool * [ANY] "$1_type"
%typemap(ctype, fragment="stdbool_inc") bool &, const bool & "$1_basetype *"
%typemap(ctype, fragment="stdbool_inc") bool & "$1_basetype *"
%typemap(ctype, fragment="stdbool_inc") const bool & "$1_basetype const *"
%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_basetype **) $input;"
%typemap(in) short, int, long, char, float, double "$1 = ($1_type) $input;"
%typemap(in) void *, short *, int *, long *, char *, float *, double * "$1 = ($1_type) $input;"
%typemap(in) void **, short **, int **, long **, char **, float **, double ** "$1 = ($1_basetype **) $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 void *, const short *, const int *, const long *, const char *, const float *, const double * "$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 *) $input;"
%typemap(in) const short &, const int &, const long &, const char &, const float &, const double & "$1 = ($1_basetype *) $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 *) $input;"
%typemap(in) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY], bool [ANY] "$1 = ($1_basetype *) $input;"
%typemap(in) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY], bool * [ANY] "$1 = ($1_basetype *) $input;"
%typemap(in) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY] "$1 = ($1_basetype *) $input;"
%typemap(in) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY] "$1 = ($1_basetype *) $input;"
%typemap(in, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool *, bool * [ANY] "$1 = ($1_type) $input;"
%typemap(in, fragment="stdbool_inc") bool &, const bool & "$1 = ($1_basetype *) $input;"
%typemap(in, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool * "$1 = ($1_type) $input;"
%typemap(in, fragment="stdbool_inc") bool & "$1 = ($1_basetype *) $input;"
%typemap(in, fragment="stdbool_inc") const bool &, const bool * "$1 = ($1_basetype *) $input;"
%typemap(in) enum SWIGTYPE "$1 = ($1_type) $input;"
@ -102,16 +104,17 @@ typedef struct {
%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 &, bool & "$1_basetype *"
%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) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY], bool [ANY] "$1_basetype *"
%typemap(couttype) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY] "$1_basetype *"
%typemap(couttype) SWIGTYPE "SwigObj *"
%typemap(couttype) SWIGTYPE * "SwigObj *"
%typemap(couttype) SWIGTYPE & "SwigObj *"
%typemap(couttype) enum SWIGTYPE "$1_type"
%typemap(couttype, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$1_type"
%typemap(couttype, fragment="stdbool_inc") bool &, const bool & "$1_basetype *"
%typemap(couttype, fragment="stdbool_inc") bool & "$1_basetype*"
%typemap(couttype, fragment="stdbool_inc") const bool & "$1_basetype const *"
%typemap(out) short, int, long, char, float, double "$result = $1;"
%typemap(out) void*, short*, int*, long*, char*, float*, double* "$result = $1;"
@ -123,7 +126,7 @@ typedef struct {
%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) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY], bool [ANY] "$result = $1;"
%typemap(out) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY] "$result = $1;"
%typemap(out) void ""
%typemap(out, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$result = $1;"

View file

@ -38,8 +38,8 @@ class string;
delete $1;
}
%typemap(out) string, const string & {
const char *str = cppresult.c_str();
%typemap(out) string, const string &, string * {
const char *str = cppresult->c_str();
size_t len = strlen(str);
$result = (char *) malloc(len + 1);
memcpy($result, str, len);

View file

@ -254,7 +254,7 @@ public:
* globalfunctionHandler()
* ------------------------------------------------------------------------ */
virtual int globalfunctionHandler(Node *n ) {
virtual int globalfunctionHandler(Node *n) {
String *action = NewString("");
String *vis_hint = NewString("");
String *return_type_str = SwigType_str(Getattr(n, "type"), 0);
@ -390,9 +390,7 @@ ready:
Node *node = Swig_symbol_clookup(query, symtab);
if (node)
newtype = NewStringf("enum %s", Getattr(node, "name"));
else
newtype = Copy(enumtype);
return newtype;
}
@ -411,6 +409,7 @@ ready:
String *tm;
String *proto = NewString("");
String *over_suffix = NewString("");
SwigType *return_var_type = empty_string;
int gencomma;
bool is_void_return = (SwigType_type(type) == T_VOID);
@ -503,10 +502,6 @@ ready:
// add variable for holding result of original function
bool return_object = false;
if (!is_void_return && (Cmp(Getattr(n, "c:objstruct"), "1") != 0)) {
if (SwigType_isconst(type))
SwigType_del_qualifier(type);
SwigType *return_var_type;
SwigType *tdtype = SwigType_typedef_resolve(type);
if (tdtype)
type = tdtype;
@ -515,11 +510,29 @@ ready:
Wrapper_add_localv(wrapper, "cppresult", "int", "cppresult", NIL);
}
else if (SwigType_isbuiltin(SwigType_base(type))) {
if (SwigType_isconst(type))
SwigType_del_qualifier(type);
// type is built-in (int, char, double, etc.)
if (SwigType_isreference(type) || SwigType_isarray(type))
return_var_type = SwigType_add_pointer(SwigType_base(type));
else
if (SwigType_isreference(type)) {
if (SwigType_isconst(SwigType_del_reference(type))) {
return_var_type = SwigType_base(type);
SwigType_add_qualifier(return_var_type, "const");
SwigType_add_pointer(return_var_type);
}
else {
return_var_type = SwigType_base(type);
SwigType_add_pointer(return_var_type);
}
SwigType_add_reference(type);
}
else if (SwigType_isarray(type)) {
return_var_type = SwigType_base(type);
SwigType_add_pointer(return_var_type);
}
else {
return_var_type = type;
}
Wrapper_add_localv(wrapper, "cppresult", SwigType_str(return_var_type, 0), "cppresult", NIL);
}
@ -527,10 +540,14 @@ ready:
// type is class
if (SwigType_ispointer(type))
return_var_type = type;
else if (SwigType_isreference(type) || SwigType_isarray(type))
return_var_type = SwigType_add_pointer(SwigType_base(type));
else
return_var_type = SwigType_add_pointer(type);
else if (SwigType_isreference(type) || SwigType_isarray(type)) {
return_var_type = SwigType_base(type);
SwigType_add_pointer(return_var_type);
}
else {
return_var_type = type;
SwigType_add_pointer(return_var_type);
}
Wrapper_add_localv(wrapper, "cppresult", SwigType_str(return_var_type, 0), "cppresult", NIL);
return_object = true;
@ -643,24 +660,24 @@ ready:
}
if (Cmp(nodeType(n), "constructor") != 0)
Replace(action, "result =", "cppresult = $mod", DOH_REPLACE_FIRST);
// handle return-by-reference
if (SwigType_isreference(type)) {
String *ref_cast = NewString("");
if (SwigType_isconst(SwigType_del_reference(type))) {
//Printf(ref_cast, "(%s*)", SwigType_str(SwigType_base(type), 0));
Printf(ref_cast, "*");
}
Replaceall(action, "$mod", ref_cast);
Delete(ref_cast);
}
// handle special cases of cpp return result
String *mod = NewString("$mod");
if (SwigType_isreference(type))
Replaceall(mod, "$mod", "");
else if (SwigType_isenum(type))
Replaceall(action, "$mod", "(int)");
else if (return_object && Getattr(n, "c:retval")) {
Replaceall(action, "$mod", "&");
Replaceall(mod, "$mod", "(int)");
else if (return_object && Getattr(n, "c:retval"))
Replaceall(mod, "$mod", "&");
else {
Delete(mod);
mod = empty_string;
}
else
Replaceall(action, "$mod", "");
Printf(stderr, "\n%s, %s, mod = %s\n", name, type, mod);
Replaceall(action, "$mod", mod);
// emit output typemap if needed
if (!is_void_return && (Cmp(Getattr(n, "c:objstruct"), "1") != 0)) {
@ -854,6 +871,15 @@ ready:
* --------------------------------------------------------------------- */
virtual int staticmemberfunctionHandler(Node *n) {
SwigType *type = Getattr(n, "type");
SwigType *tdtype;
tdtype = SwigType_typedef_resolve(type);
if (tdtype)
type = tdtype;
if (type) {
if (!SwigType_ispointer(type) && !SwigType_isreference(type))
Setattr(n, "c:retval", "1");
}
return Language::staticmemberfunctionHandler(n);
}
@ -863,8 +889,14 @@ ready:
virtual int memberfunctionHandler(Node *n) {
SwigType *type = Getattr(n, "type");
if (!SwigType_ispointer(type) && !SwigType_ispointer(SwigType_typedef_resolve(type)))
Setattr(n, "c:retval", "1");
SwigType *tdtype;
tdtype = SwigType_typedef_resolve(type);
if (tdtype)
type = tdtype;
if (type) {
if (!SwigType_ispointer(type) && !SwigType_isreference(type))
Setattr(n, "c:retval", "1");
}
return Language::memberfunctionHandler(n);
}
@ -923,6 +955,7 @@ ready:
/* ---------------------------------------------------------------------
* staticmembervariableHandler()
* TODO: refactor
* --------------------------------------------------------------------- */
virtual int staticmembervariableHandler(Node *n) {