Skip to content

Commit 954f29b

Browse files
committed
Add special variable imfuncname expansion for C# and D
Same functionality as Java
1 parent 62e0685 commit 954f29b

File tree

7 files changed

+79
-0
lines changed

7 files changed

+79
-0
lines changed

CHANGES.current

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.1.0 (in progress)
88
===========================
99

10+
2022-05-30: wsfulton
11+
[C#, D] Add new special variable expansion: $imfuncname.
12+
Expands to the function name called in the intermediary class.
13+
1014
2022-05-30: LindleyF
1115
[Java] #2042 Add new special variable expansion: $imfuncname.
1216
Expands to the function name called in the intermediary class.

Doc/Manual/CSharp.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,12 @@ <H2><a name="CSharp_differences_java">23.2 Differences to the Java module</a></H
550550
unless the imclassname attribute is specified in the <a href="CSharp.html#CSharp_module_directive">%module directive</a>.
551551
</p>
552552

553+
<p>
554+
<b><tt>$imfuncname</tt></b><br>
555+
This special variable expands to the name of the function in the intermediary class that will be used in $imcall.
556+
Like, $imcall, this special variable is only expanded in the "csout", "csvarin" and "csvarout" typemaps.
557+
</p>
558+
553559
<p>
554560
The directory <tt>Examples/csharp</tt> has a number of simple examples.
555561
Visual Studio .NET 2003 solution and project files are available for compiling with the Microsoft .NET C#

Doc/Manual/D.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ <H3><a name="D_special_variables">24.3.7 Special variable macros</a></H3>
267267
</pre></div>
268268
</dd>
269269

270+
<dt><tt>$imfuncname</tt></dt>
271+
<dd><p>
272+
This special variable expands to the name of the function in the intermediary class that will be used in $imcall.
273+
Like, $imcall, this special variable is only expanded in the "dout" typemap.
274+
</p></dd>
275+
270276
<dt><a name="D_importtype"></a><tt>$importtype(SomeDType)</tt></dt>
271277
<dd>
272278
<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>

Examples/test-suite/csharp/csharp_typemaps_runme.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ public void Run() {
107107
Console.Error.WriteLine("Test failed (thread " + threadId + "): " + e.Message);
108108
Failed = true;
109109
}
110+
111+
// $imfuncname substitution
112+
ProxyA pa = new ProxyA();
113+
if (pa.imfuncname_test() != 123)
114+
throw new ApplicationException("imfuncname_test is not 123");
115+
if (ProxyA.imfuncname_static_test() != 234)
116+
throw new ApplicationException("imfuncname_test is not 234");
117+
if (csharp_typemaps.imfuncname_global_test() != 345)
118+
throw new ApplicationException("imfuncname_test is not 345");
119+
120+
pa.variab = 1000;
121+
if (pa.variab != 1000 + 111 + 222)
122+
throw new ApplicationException("pa.variab is not 1333");
123+
csharp_typemaps.global_variab = 1000;
124+
if (csharp_typemaps.global_variab != 1000 + 333 + 444)
125+
throw new ApplicationException("csharp_typemaps.variab is not 1777");
110126
}
111127
}
112128

Examples/test-suite/csharp_typemaps.i

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,42 @@ namespace Glob {
136136
bool MVar::svar = false;
137137
%}
138138

139+
// $imfuncname substitution
140+
%typemap(csout) int imfuncname_test {
141+
return $modulePINVOKE.$imfuncname(swigCPtr) + 123;
142+
}
143+
%typemap(csout) int imfuncname_static_test {
144+
return $modulePINVOKE.$imfuncname() + 234;
145+
}
146+
%typemap(csout) int imfuncname_global_test {
147+
return $modulePINVOKE.$imfuncname() + 345;
148+
}
149+
150+
%typemap(csvarout, excode=SWIGEXCODE2) int variab %{
151+
get {
152+
int ret = $modulePINVOKE.$imfuncname(swigCPtr) + 222;$excode
153+
return ret;
154+
} %}
155+
%typemap(csvarin, excode=SWIGEXCODE2) int variab %{
156+
set {
157+
$modulePINVOKE.$imfuncname(swigCPtr, value + 111);$excode
158+
} %}
159+
160+
%typemap(csvarout, excode=SWIGEXCODE2) int global_variab %{
161+
get {
162+
int ret = $modulePINVOKE.$imfuncname() + 333;$excode
163+
return ret;
164+
} %}
165+
%typemap(csvarin, excode=SWIGEXCODE2) int global_variab %{
166+
set {
167+
$modulePINVOKE.$imfuncname(value + 444);$excode
168+
} %}
169+
%inline %{
170+
struct ProxyA {
171+
int imfuncname_test() { return 0; }
172+
static int imfuncname_static_test() { return 0; }
173+
int variab;
174+
};
175+
int imfuncname_global_test() { return 0; }
176+
int global_variab;
177+
%}

Source/Modules/csharp.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,7 @@ class CSHARP:public Language {
25722572
} else {
25732573
Replaceall(imcall, "$imfuncname", intermediary_function_name);
25742574
}
2575+
Replaceall(tm, "$imfuncname", intermediary_function_name);
25752576
Replaceall(tm, "$imcall", imcall);
25762577
} else {
25772578
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 @@ class CSHARP:public Language {
26152616
if ((tm = Swig_typemap_lookup("csvarin", variable_parm, "", 0))) {
26162617
substituteClassname(cvariable_type, tm);
26172618
Replaceall(tm, "$csinput", "value");
2619+
Replaceall(tm, "$imfuncname", intermediary_function_name);
26182620
Replaceall(tm, "$imcall", imcall);
26192621
excodeSubstitute(n, tm, "csvarin", variable_parm);
26202622
Printf(proxy_class_code, "%s", tm);
@@ -2629,6 +2631,7 @@ class CSHARP:public Language {
26292631
else
26302632
Replaceall(tm, "$owner", "false");
26312633
substituteClassname(t, tm);
2634+
Replaceall(tm, "$imfuncname", intermediary_function_name);
26322635
Replaceall(tm, "$imcall", imcall);
26332636
excodeSubstitute(n, tm, "csvarout", n);
26342637
Printf(proxy_class_code, "%s", tm);
@@ -3141,6 +3144,7 @@ class CSHARP:public Language {
31413144
else
31423145
Replaceall(tm, "$owner", "false");
31433146
substituteClassname(t, tm);
3147+
Replaceall(tm, "$imfuncname", overloaded_name);
31443148
Replaceall(tm, "$imcall", imcall);
31453149
} else {
31463150
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 @@ class CSHARP:public Language {
31793183
if ((tm = Getattr(p, "tmap:csvarin"))) {
31803184
substituteClassname(pt, tm);
31813185
Replaceall(tm, "$csinput", "value");
3186+
Replaceall(tm, "$imfuncname", overloaded_name);
31823187
Replaceall(tm, "$imcall", imcall);
31833188
excodeSubstitute(n, tm, "csvarin", p);
31843189
Printf(module_class_code, "%s", tm);
@@ -3193,6 +3198,7 @@ class CSHARP:public Language {
31933198
else
31943199
Replaceall(tm, "$owner", "false");
31953200
substituteClassname(t, tm);
3201+
Replaceall(tm, "$imfuncname", overloaded_name);
31963202
Replaceall(tm, "$imcall", imcall);
31973203
excodeSubstitute(n, tm, "csvarout", n);
31983204
Printf(module_class_code, "%s", tm);

Source/Modules/d.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,6 +2898,7 @@ class D : public Language {
28982898
} else {
28992899
Replaceall(imcall, "$imfuncname", intermediary_function_name);
29002900
}
2901+
Replaceall(tm, "$imfuncname", intermediary_function_name);
29012902
Replaceall(tm, "$imcall", imcall);
29022903
} else {
29032904
Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,
@@ -3100,6 +3101,7 @@ class D : public Language {
31003101
else
31013102
Replaceall(tm, "$owner", "false");
31023103
replaceClassname(tm, t);
3104+
Replaceall(tm, "$imfuncname", overloaded_name);
31033105
Replaceall(tm, "$imcall", imcall);
31043106
} else {
31053107
Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,

0 commit comments

Comments
 (0)