Add special variable imfuncname expansion for C# and D

Same functionality as Java
This commit is contained in:
William S Fulton 2022-05-30 19:43:04 +01:00
parent 62e0685df6
commit 954f29b032
7 changed files with 79 additions and 0 deletions

View File

@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress)
===========================
2022-05-30: wsfulton
[C#, D] Add new special variable expansion: $imfuncname.
Expands to the function name called in the intermediary class.
2022-05-30: LindleyF
[Java] #2042 Add new special variable expansion: $imfuncname.
Expands to the function name called in the intermediary class.

View File

@ -550,6 +550,12 @@ This special variable expands to the intermediary class name. For C# this is usu
unless the imclassname attribute is specified in the <a href="CSharp.html#CSharp_module_directive">%module directive</a>.
</p>
<p>
<b><tt>$imfuncname</tt></b><br>
This special variable expands to the name of the function in the intermediary class that will be used in $imcall.
Like, $imcall, this special variable is only expanded in the "csout", "csvarin" and "csvarout" typemaps.
</p>
<p>
The directory <tt>Examples/csharp</tt> has a number of simple examples.
Visual Studio .NET 2003 solution and project files are available for compiling with the Microsoft .NET C#

View File

@ -267,6 +267,12 @@ SomeClass bar() {
</pre></div>
</dd>
<dt><tt>$imfuncname</tt></dt>
<dd><p>
This special variable expands to the name of the function in the intermediary class that will be used in $imcall.
Like, $imcall, this special variable is only expanded in the "dout" typemap.
</p></dd>
<dt><a name="D_importtype"></a><tt>$importtype(SomeDType)</tt></dt>
<dd>
<p>This macro is used in the <tt>dimports</tt> typemap if a dependency on another D type generated by SWIG is added by a custom typemap.</p>

View File

@ -107,6 +107,22 @@ public class TestThread {
Console.Error.WriteLine("Test failed (thread " + threadId + "): " + e.Message);
Failed = true;
}
// $imfuncname substitution
ProxyA pa = new ProxyA();
if (pa.imfuncname_test() != 123)
throw new ApplicationException("imfuncname_test is not 123");
if (ProxyA.imfuncname_static_test() != 234)
throw new ApplicationException("imfuncname_test is not 234");
if (csharp_typemaps.imfuncname_global_test() != 345)
throw new ApplicationException("imfuncname_test is not 345");
pa.variab = 1000;
if (pa.variab != 1000 + 111 + 222)
throw new ApplicationException("pa.variab is not 1333");
csharp_typemaps.global_variab = 1000;
if (csharp_typemaps.global_variab != 1000 + 333 + 444)
throw new ApplicationException("csharp_typemaps.variab is not 1777");
}
}

View File

@ -136,3 +136,42 @@ namespace Glob {
bool MVar::svar = false;
%}
// $imfuncname substitution
%typemap(csout) int imfuncname_test {
return $modulePINVOKE.$imfuncname(swigCPtr) + 123;
}
%typemap(csout) int imfuncname_static_test {
return $modulePINVOKE.$imfuncname() + 234;
}
%typemap(csout) int imfuncname_global_test {
return $modulePINVOKE.$imfuncname() + 345;
}
%typemap(csvarout, excode=SWIGEXCODE2) int variab %{
get {
int ret = $modulePINVOKE.$imfuncname(swigCPtr) + 222;$excode
return ret;
} %}
%typemap(csvarin, excode=SWIGEXCODE2) int variab %{
set {
$modulePINVOKE.$imfuncname(swigCPtr, value + 111);$excode
} %}
%typemap(csvarout, excode=SWIGEXCODE2) int global_variab %{
get {
int ret = $modulePINVOKE.$imfuncname() + 333;$excode
return ret;
} %}
%typemap(csvarin, excode=SWIGEXCODE2) int global_variab %{
set {
$modulePINVOKE.$imfuncname(value + 444);$excode
} %}
%inline %{
struct ProxyA {
int imfuncname_test() { return 0; }
static int imfuncname_static_test() { return 0; }
int variab;
};
int imfuncname_global_test() { return 0; }
int global_variab;
%}

View File

@ -2572,6 +2572,7 @@ public:
} else {
Replaceall(imcall, "$imfuncname", intermediary_function_name);
}
Replaceall(tm, "$imfuncname", intermediary_function_name);
Replaceall(tm, "$imcall", imcall);
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csout typemap defined for %s\n", SwigType_str(t, 0));
@ -2615,6 +2616,7 @@ public:
if ((tm = Swig_typemap_lookup("csvarin", variable_parm, "", 0))) {
substituteClassname(cvariable_type, tm);
Replaceall(tm, "$csinput", "value");
Replaceall(tm, "$imfuncname", intermediary_function_name);
Replaceall(tm, "$imcall", imcall);
excodeSubstitute(n, tm, "csvarin", variable_parm);
Printf(proxy_class_code, "%s", tm);
@ -2629,6 +2631,7 @@ public:
else
Replaceall(tm, "$owner", "false");
substituteClassname(t, tm);
Replaceall(tm, "$imfuncname", intermediary_function_name);
Replaceall(tm, "$imcall", imcall);
excodeSubstitute(n, tm, "csvarout", n);
Printf(proxy_class_code, "%s", tm);
@ -3141,6 +3144,7 @@ public:
else
Replaceall(tm, "$owner", "false");
substituteClassname(t, tm);
Replaceall(tm, "$imfuncname", overloaded_name);
Replaceall(tm, "$imcall", imcall);
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csout typemap defined for %s\n", SwigType_str(t, 0));
@ -3179,6 +3183,7 @@ public:
if ((tm = Getattr(p, "tmap:csvarin"))) {
substituteClassname(pt, tm);
Replaceall(tm, "$csinput", "value");
Replaceall(tm, "$imfuncname", overloaded_name);
Replaceall(tm, "$imcall", imcall);
excodeSubstitute(n, tm, "csvarin", p);
Printf(module_class_code, "%s", tm);
@ -3193,6 +3198,7 @@ public:
else
Replaceall(tm, "$owner", "false");
substituteClassname(t, tm);
Replaceall(tm, "$imfuncname", overloaded_name);
Replaceall(tm, "$imcall", imcall);
excodeSubstitute(n, tm, "csvarout", n);
Printf(module_class_code, "%s", tm);

View File

@ -2898,6 +2898,7 @@ private:
} else {
Replaceall(imcall, "$imfuncname", intermediary_function_name);
}
Replaceall(tm, "$imfuncname", intermediary_function_name);
Replaceall(tm, "$imcall", imcall);
} else {
Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,
@ -3100,6 +3101,7 @@ private:
else
Replaceall(tm, "$owner", "false");
replaceClassname(tm, t);
Replaceall(tm, "$imfuncname", overloaded_name);
Replaceall(tm, "$imcall", imcall);
} else {
Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,