diff options
author | Swati Sharma <itawswati@gmail.com> | 2012-08-20 13:38:56 +0000 |
---|---|---|
committer | Swati Sharma <itawswati@gmail.com> | 2012-08-20 13:38:56 +0000 |
commit | 506807da98f4325a0ecf1568c2828a909c447e48 (patch) | |
tree | cdbc46620632cfffa9874936daaf3f973bd87d45 | |
parent | 70595644aff327964fe1c9484af47f81148a9067 (diff) | |
download | swig-506807da98f4325a0ecf1568c2828a909c447e48.tar.gz |
Fixed typemaps for some primitive types.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-objc@13683 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r-- | Lib/objc/objc.swg | 72 | ||||
-rw-r--r-- | Lib/objc/typemaps.i | 20 |
2 files changed, 57 insertions, 35 deletions
diff --git a/Lib/objc/objc.swg b/Lib/objc/objc.swg index efebe0c91..0454c25b9 100644 --- a/Lib/objc/objc.swg +++ b/Lib/objc/objc.swg @@ -14,7 +14,6 @@ */ // Primary types: ObjectiveC++ understands C primary types. -%typemap(imtype) bool "bool" %typemap(imtype) char "char" %typemap(imtype) signed char "signed char" %typemap(imtype) unsigned char "unsigned char" @@ -31,7 +30,6 @@ %typemap(imtype) void "void" // References to primitive types are treated as pointers in the wrapper(ObjectiveC++) layer. -%typemap(imtype) const bool &, bool & "bool *" %typemap(imtype) const char &, char & "char *" %typemap(imtype) const signed char &, signed char & "signed char *" %typemap(imtype) const unsigned char &, unsigned char & "unsigned char *" @@ -46,16 +44,20 @@ %typemap(imtype) const float &, float & "float *" %typemap(imtype) const double &, double & "double *" +// Booleans +%typemap(imtype) bool "BOOL" +%typemap(imtype) const bool &, bool &, const bool *, bool * "BOOL *" + //C strings: %typemap(imtype) char *, const char *, char[ANY], char[] "NSString *" %typemap(imtype) char *& "NSString *" + // Objects will always be treated as pointers in ObjectiveC++ %typemap(imtype) SWIGTYPE "void*" // C/C++ prinitve pointers are treated as is in ObjectiveC++ // References to primitive types are treated as pointers in the wrapper(ObjectiveC++) layer. -%typemap(imtype) const bool *, bool * "bool *" %typemap(imtype) const signed char *, signed char * "signed char *" %typemap(imtype) const unsigned char *, unsigned char * "unsigned char *" %typemap(imtype) const short *, short * "short *" @@ -89,8 +91,7 @@ /* * IN TYPEMAPS: Used for "in" arguments type conversions: ObjectiveC++ to C++. */ -%typemap(in) bool, - char, +%typemap(in) char, signed char, unsigned char, short, @@ -109,8 +110,7 @@ %typemap(in) void "" // References: are treated as pointers in the wrapper layer (ObjectiveC++) -%typemap(in) const bool &, bool &, - const char &, char &, +%typemap(in) const char &, char &, const signed char &, signed char &, const unsigned char &, unsigned char &, const short &, short &, @@ -125,8 +125,7 @@ const double &, double & %{ $1 = ($1_ltype)$input; %} -%typemap(in) const bool *, bool *, - const signed char *, signed char *, +%typemap(in) const signed char *, signed char *, const unsigned char *, unsigned char *, const short *, short *, const unsigned short *, unsigned short *, @@ -140,6 +139,16 @@ const double *, double * %{ $1 = ($1_ltype)$input;%} +//Booleans: +%typemap(in) bool +%{ $1 = $input? true : false; %} + +%typemap(in) bool * (bool temp), const bool * (bool temp), const bool & (bool temp), bool & (bool temp) { + temp = ($input) ? true : false; + $1 = &temp; +} + + //C strings: %typemap(in) char *, char[ANY], char[] { $1 = 0; @@ -209,8 +218,7 @@ * OUT TYPEMAPS: Used for return-type type conversions: C++ to ObjectiveC++ */ //Primary types -%typemap(out) bool, - char, +%typemap(out) char, signed char, unsigned char, short, @@ -225,14 +233,10 @@ double %{ $result = $1; %} -//%typemap(out) bool -//%{ $result = $1? YES:NO; %} - %typemap(out) void "" // References as exported as pointers (by default) -%typemap(out)const bool &, bool &, - const char &, char &, +%typemap(out)const char &, char &, const signed char &, signed char &, const unsigned char &, unsigned char &, const short &, short &, @@ -248,22 +252,30 @@ %{ $result = $1; %} -%typemap(out)const bool *, bool *, - const char *, char *, +%typemap(out)const char *, char *, const signed char *, signed char *, const unsigned char *, unsigned char *, const short *, short *, const unsigned short *, unsigned short *, const int *, int *, const unsigned int *, unsigned int *, - const long *, long &, - const unsigned long *, unsigned long &, + const long *, long *, + const unsigned long *, unsigned long *, const long long *, long long *, const unsigned long long *,unsigned long long *, const float *, float *, const double *, double * %{ $result = $1; %} +// Booleans: +%typemap(out) bool +%{ $result = ($1)? YES:NO; %} + +%typemap(out) bool& (BOOL temp), bool* (BOOL temp), const bool& (BOOL temp), const bool& (BOOL temp) +%{ temp = (*$1)? YES:NO; + BOOL* ret = &temp; + return ret; %} + // C strings: %typemap(out)const char *,char * %{ if ($1) $result = [NSString stringWithUTF8String: (const char*)$1]; %} %typemap(out) char *& %{ if (*$1) $result = [NSString stringWithUTF8String: (const char*)*$1]; %} @@ -326,7 +338,7 @@ %typemap(objctype) void "void" // References will always be treated as pointers in the proxy layer (ObjectiveC) -%typemap(objctype) const bool &, bool & "bool *" +%typemap(objctype) const bool &, bool & "BOOL *" %typemap(objctype) const char &, char & "char *" %typemap(objctype) const signed char &, signed char & "signed char *" %typemap(objctype) const unsigned char &, unsigned char & "unsigned char *" @@ -350,7 +362,7 @@ // C/C++ Pointers to primitive types are treated as is // C/C++ prinitve pointers are treated as is in ObjectiveC++ // References to primitive types are treated as pointers in the wrapper(ObjectiveC++) layer. -%typemap(objctype) const bool *, bool * "bool *" +%typemap(objctype) const bool *, bool * "BOOL *" %typemap(objctype) const signed char *, signed char * "signed char *" %typemap(objctype) const unsigned char *, unsigned char * "unsigned char *" %typemap(objctype) const short *, short * "short *" @@ -386,9 +398,8 @@ */ // Primary types -%typemap(objcin) bool "$objcinput" - -%typemap(objcin) char, +%typemap(objcin) bool, + char, signed char, unsigned char, short, @@ -461,7 +472,8 @@ */ // Primary types are exported as ObjectiveC primary types -%typemap(objcout) char, +%typemap(objcout) bool, + char, signed char, unsigned char, short, @@ -476,10 +488,6 @@ double %{ return $imcall; %} -%typemap(objcout) bool -%{ bool ret = $imcall; - return (ret)? YES:NO; %} - %typemap(objcout) void "$imcall;" %typemap(objcout) const bool &, bool &, @@ -506,8 +514,8 @@ const unsigned short *, unsigned short *, const int *, int *, const unsigned int *, unsigned int *, - const long *, long &, - const unsigned long *, unsigned long &, + const long *, long *, + const unsigned long *, unsigned long *, const long long *, long long *, const unsigned long long *,unsigned long long *, const float *, float *, diff --git a/Lib/objc/typemaps.i b/Lib/objc/typemaps.i index eab6e669e..3a261d774 100644 --- a/Lib/objc/typemaps.i +++ b/Lib/objc/typemaps.i @@ -61,9 +61,11 @@ In ObjectiveC you could then use it like this: %typemap(in) TYPE *INPUT,TYPE &INPUT %{ $1 = ($1_ltype)&$input; %} +%typemap(out) TYPE *INPUT, TYPE &INPUT "" + %enddef -//INPUT_TYPEMAP(bool, bool, BOOL); +INPUT_TYPEMAP(bool, BOOL, BOOL); INPUT_TYPEMAP(signed char, signed char, signed char); INPUT_TYPEMAP(char, char, char); INPUT_TYPEMAP(unsigned char, unsigned char, unsigned char); @@ -78,6 +80,12 @@ INPUT_TYPEMAP(unsigned long long, unsigned long long, unsigned long long); INPUT_TYPEMAP(float, float, float); INPUT_TYPEMAP(double, double, double); +/* Override typemaps in the INPUT_TYPEMAP macro for bool represented as BOOL in ObjectiveC */ +%typemap(in) bool *INPUT (bool temp), bool &INPUT (bool temp) %{ + temp = ($input) ? true : false; + $1 = &temp; +%} + #undef INPUT_TYPEMAP /* @@ -139,7 +147,7 @@ value returned in the second output parameter. In ObjectiveC you would use it li %enddef -//OUTPUT_TYPEMAP(bool, bOOL, BOOL); +OUTPUT_TYPEMAP(bool, BOOL, BOOL); OUTPUT_TYPEMAP(signed char, signed char, signed char); OUTPUT_TYPEMAP(char, char, char); OUTPUT_TYPEMAP(unsigned char, unsigned char, unsigned char); @@ -226,7 +234,7 @@ OUTPUT_TYPEMAP(double, double, double); %enddef -//INOUT_TYPEMAP(bool, bool, BOOL); +INOUT_TYPEMAP(bool, BOOL, BOOL); INOUT_TYPEMAP(signed char, signed char, signed char); INOUT_TYPEMAP(char, char, char); INOUT_TYPEMAP(unsigned char, unsigned char, unsigned char); @@ -241,4 +249,10 @@ INOUT_TYPEMAP(unsigned long long, unsigned long long, unsigned long long); INOUT_TYPEMAP(float, float, float); INOUT_TYPEMAP(double, double, double); +/* Override typemaps in the INOUT_TYPEMAP macro for bool represented as BOOL in ObjectiveC */ +%typemap(in) bool *INOUT (bool temp), bool &INOUT (bool temp) { + temp = ($input) ? true : false; + $1 = &temp; +} + #undef INOUT_TYPEMAP |