More flexible variable wrappers (C# properties). The property set can now support a different type to that used in the intermediary layer. This is achieved by using a temporary variable and specifying the name of the temporary variable in a new 'valueparm' attribute in the csvarin typemap. Also Fix bug reported by Glenn A Watson and #1795260 where the cstype typemap used the 'ref' keyword in the typemap body. The type for the property now correctly comes from the 'out' attribute in the cstype typemap.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9946 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2007-09-19 23:54:19 +00:00
commit d737022daa
3 changed files with 42 additions and 10 deletions

View file

@ -19,7 +19,7 @@ public class runme
initialLetters.Append(myChar);
if (initialLetters.ToString() != "bhox")
throw new Exception("initial letters failed");
if (csharp_typemaps.go != "zzz")
if (csharp_typemaps.go != 'z')
throw new Exception("go variable failed");

View file

@ -2,9 +2,9 @@
// Test the C# types customisation by modifying the default char * typemaps to return a single char
%typemap(ctype, out="char /*ctype out override*/") char * "char *"
%typemap(imtype, out="char /*imtype out override*/") char * "string"
%typemap(cstype, out="char /*cstype out override*/") char * "string"
%typemap(ctype, out="char /*ctype out override*/") char * "char *"
%typemap(out) char * %{
// return the 0th element rather than the whole string
@ -16,12 +16,20 @@
return ret;
}
%typemap(csvarout, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
%typemap(csvarout, excode=SWIGEXCODE2) char * %{
get {
string ret = new string($imcall, 3);$excode
char ret = $imcall;$excode
return ret;
} %}
// test valueparm attribute
%typemap(csvarin, excode=SWIGEXCODE2, valueparm="tempValue") char * %{
set {
string tempValue = new string(value, 3);
$imcall;$excode
} %}
%inline %{
namespace Space {
class Things {
@ -33,8 +41,27 @@ namespace Space {
#define STRINGCONSTANT "xyz string"
char *go = "zap";
}
%}
// Test variables when ref is used in the cstype typemap - the variable name should come from the out attribute if specified
%typemap(cstype) MKVector, const MKVector& "MKVector"
%typemap(cstype, out="MKVector") MKVector &, MKVector * "ref MKVector"
%inline %{
struct MKVector {
};
struct MKRenderGameVector {
MKVector memberValue;
static MKVector staticValue;
};
MKVector MKRenderGameVector::staticValue;
MKVector globalValue;
%}
// Number and Obj are for the eager garbage collector runtime test
%inline %{
struct Number {
Number(double value) : Value(value) {}
double Value;

View file

@ -1909,6 +1909,8 @@ public:
if (proxy_flag && wrapping_member_flag && !enum_constant_flag) {
// Properties
setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) == 0);
if (setter_flag)
Swig_typemap_attach_parms("csvarin", l, NULL);
}
/* Start generating the proxy function */
@ -2097,7 +2099,8 @@ public:
SwigType *pt = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:cstype"))) {
substituteClassname(pt, tm);
variable_type = tm;
String *cstypeout = Getattr(p, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap
variable_type = cstypeout ? cstypeout : tm;
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0));
}
@ -2114,7 +2117,6 @@ public:
if (setter_flag) {
// Setter method
Swig_typemap_attach_parms("csvarin", l, NULL);
p = last_parm; // (last parameter is the only parameter for properties)
SwigType *pt = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:csvarin"))) {
@ -2499,6 +2501,8 @@ public:
Printf(func_name, "get");
Putc(toupper((int) *Char(variable_name)), func_name);
Printf(func_name, "%s", Char(variable_name) + 1);
if (setter_flag)
Swig_typemap_attach_parms("csvarin", l, NULL);
} else {
func_name = Copy(Getattr(n, "sym:name"));
}
@ -2626,7 +2630,8 @@ public:
SwigType *pt = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:cstype"))) {
substituteClassname(pt, tm);
variable_type = tm;
String *cstypeout = Getattr(p, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap
variable_type = cstypeout ? cstypeout : tm;
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0));
}
@ -2643,7 +2648,6 @@ public:
if (setter_flag) {
// Setter method
Swig_typemap_attach_parms("csvarin", l, NULL);
p = last_parm; // (last parameter is the only parameter for properties)
SwigType *pt = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:csvarin"))) {
@ -2864,8 +2868,9 @@ public:
String *arg = 0;
String *pn = Getattr(p, "name");
if (setter) {
// Note that in C# property setter names must always be called 'value'
arg = NewString("value");
// Note that in C# properties, the input variable name is always called 'value'
String *valueparm = Getattr(p, "tmap:csvarin:valueparm");
arg = valueparm ? Copy(valueparm) : NewString("value");
} else {
// Use C parameter name unless it is a duplicate or an empty parameter name
int count = 0;