Replaced SwigObjXXX with one type SwigObj. Added typemaps for bool.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10674 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Maciej Drwal 2008-07-17 09:53:05 +00:00
commit e90a0692c7
4 changed files with 51 additions and 34 deletions

View file

@ -3,9 +3,13 @@
#include "example_proxy.h"
int main(int argc, char **argv) {
int a = 35;
int b = 15;
printf("Foo is %f\n", Foo);
int a = 42;
int b = 105;
int g = gcd(a, b);
printf("The gcd of %d and %d is %d\n", a, b, g);
printf("Foo = %f\n", Foo);
Foo = 3.1415926;
printf("Foo = %f\n", Foo);
SWIG_exit(0);
}

View file

@ -38,7 +38,7 @@
*/
#if defined(SWIGC)
%typemap(throws) SWIGTYPE {
SwigObj$1_basetype *_c_ex = _wrap_new_$1_basetype();
SwigObj *_c_ex = _wrap_new_$1_basetype();
SWIG_CThrowException(_c_ex, "C++ $1_type exception thrown");
}

View file

@ -22,22 +22,27 @@ typedef struct {
// typemaps for function parameters
%typemap(ctype) void, short, int, long, char, float, double, bool "$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) void *, short *, int *, long *, char *, float *, double *, bool * "$1_type"
%typemap(ctype) void **, short **, int **, long **, char **, float **, double **, bool ** "$1_type"
%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 &, bool & "$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, const bool "$1_type"
%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 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) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY], bool * [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(ctype) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY], bool * [ANY] "$1_basetype **"
%typemap(ctype) SWIGTYPE "SwigObj *"
%typemap(ctype) SWIGTYPE * "SwigObj *"
%typemap(ctype) SWIGTYPE & "SwigObj *"
%typemap(ctype) SWIGTYPE * [ANY] "SwigObj *"
%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(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;"
@ -52,6 +57,8 @@ typedef struct {
%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, 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) SWIGTYPE {
$1 = * ($1_type *) ($input->obj);
@ -85,18 +92,21 @@ typedef struct {
// typemaps for return values
%typemap(couttype) void, short, int, long, char, float, double, bool "$1_type"
%typemap(couttype) void *, short *, int *, long *, char *, float *, double*, bool* "$1_type"
%typemap(couttype) const short, const int, const long, const char, const float, const double, const bool "$1_basetype"
%typemap(couttype) const void *, const short *, const int *, const long *, const char *, const float *, const double *, const bool * "$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 &, bool & "$1_basetype *"
%typemap(couttype) const short &, const int &, const long &, const char &, const float &, const double &, const bool & "$1_basetype const *"
%typemap(couttype) SWIGTYPE "struct SwigObj$1_type *"
%typemap(couttype) SWIGTYPE * "struct SwigObj$1_type"
%typemap(couttype) SWIGTYPE & "struct SwigObj$1_basetype *"
%typemap(couttype) const short &, const int &, const long &, const char &, const float &, const double & "$1_basetype const *"
%typemap(couttype) SWIGTYPE "SwigObj *"
%typemap(couttype) SWIGTYPE * "SwigObj *"
%typemap(couttype) SWIGTYPE & "SwigObj *"
%typemap(out) short, int, long, char, float, double, bool "$result = $1;"
%typemap(out) void*, short*, int*, long*, char*, float*, double*, bool* "$result = $1;"
%typemap(couttype, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$1_type"
%typemap(couttype, fragment="stdbool_inc") bool &, const bool & "$1_basetype *"
%typemap(out) short, int, long, char, float, double "$result = $1;"
%typemap(out) void*, short*, int*, long*, char*, float*, double* "$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;"
@ -107,10 +117,13 @@ typedef struct {
%typemap(out) const unsigned short &, const unsigned int &, const unsigned long &, const unsigned char & "$result = $1;"
%typemap(out) void ""
%typemap(out, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$result = $1;"
%typemap(out, fragment="stdbool_inc") bool &, const bool & "$result = $1;"
// allocate new "object-struct" by default
%typemap(out) SWIGTYPE {
$result = (struct SwigObj$1_type *) malloc(sizeof(struct SwigObj$1_type));
$result = (SwigObj *) malloc(sizeof(SwigObj));
$result->obj = (void*) &$1;
#if SWIG_C_RUNTIME
$result->typenames[0] = 0; // FIXME
@ -118,7 +131,7 @@ typedef struct {
}
%typemap(out) SWIGTYPE * {
$result = (struct SwigObj$1_type) malloc(sizeof(struct SwigObj$*1_type));
$result = (SwigObj *) malloc(sizeof(SwigObj));
$result->obj = (void*) $1;
#if SWIG_C_RUNTIME
$result->typenames[0] = 0; // FIXME
@ -126,7 +139,7 @@ typedef struct {
}
%typemap(out) SWIGTYPE & {
$result = (struct SwigObj$1_basetype *) malloc(sizeof(struct SwigObj$1_basetype));
$result = (SwigObj *) malloc(sizeof(SwigObj));
$result->obj = (void*) $1;
#if SWIG_C_RUNTIME
$result->typenames[0] = 0; // FIXME
@ -271,7 +284,6 @@ SWIGINTERN void SWIG_CThrowException(void *klass, const char *msg) {
// special value indicating any type of exception like 'catch(...)'
#define SWIG_AnyException "SWIG_AnyException"
#include <stdbool.h>
#include <setjmp.h>
SWIGIMPORT jmp_buf SWIG_rt_env;

View file

@ -627,7 +627,8 @@ public:
// declare it in the proxy header
if (proxy_flag)
Printv(f_proxy_header, "#define ", name, " SwigObj\n\n", NIL);
//Printv(f_proxy_header, "#define ", name, " SwigObj\n\n", NIL);
Printv(f_proxy_header, "typedef SwigObj ", name, ";\n\n", NIL);
Delete(sobj);
Delete(name);
@ -708,7 +709,7 @@ public:
ParmList *parms = Getattr(n, "parms");
// create first argument
Printv(sobj_name, "struct SwigObj", newclassname, NIL);
Printf(sobj_name, "SwigObj");
ctype = Copy(sobj_name);
SwigType_add_pointer(ctype);
Parm *p = NewParm(ctype, "self");
@ -867,7 +868,7 @@ public:
String *new_name = NewString("");
// create first argument
Printv(sobj_name, "struct SwigObj", newclassname, NIL);
Printf(sobj_name, "SwigObj");
ctype = Copy(sobj_name);
SwigType_add_pointer(ctype);
Parm *p = NewParm(ctype, "self");
@ -943,7 +944,7 @@ public:
Append(arg_lnames, Swig_cfunction_call(empty_string, parms));
// set the function return type to the pointer to struct
Printv(sobj_name, "struct SwigObj", newclassname, NIL);
Printf(sobj_name, "SwigObj");
ctype = Copy(sobj_name);
SwigType_add_pointer(ctype);
Setattr(n, "type", ctype);
@ -993,7 +994,7 @@ public:
Setattr(parms, "lname", "arg1");
// set the function return type to the pointer to struct
Printv(sobj_name, "struct SwigObj", newclassname, NIL);
Printf(sobj_name, "SwigObj");
ctype = Copy(sobj_name);
SwigType_add_pointer(ctype);
Setattr(n, "type", ctype);
@ -1040,7 +1041,7 @@ public:
Parm *p;
// create first argument
Printv(sobj_name, "struct SwigObj", newclassname, " ", NIL);
Printf(sobj_name, "SwigObj");
ctype = Copy(sobj_name);
SwigType_add_pointer(ctype);
p = NewParm(ctype, "self");