Add %proxycode directive for adding code into proxy classes for C#, D and Java

This commit is contained in:
William S Fulton 2017-01-13 20:42:12 +00:00
commit 3d2e57b0f2
18 changed files with 478 additions and 5 deletions

View file

@ -335,6 +335,7 @@ CPP_TEST_CASES += \
preproc_constants \
primitive_ref \
private_assign \
proxycode \
protected_rename \
pure_virtual \
redefined \

View file

@ -0,0 +1,33 @@
using System;
using proxycodeNamespace;
public class proxycode_runme {
public static void Main() {
if (new Proxy1().proxycode1(100) != 101)
throw new Exception("Fail");
if (new Proxy2().proxycode2a(100) != 102)
throw new Exception("Fail");
if (new Proxy2().proxycode2b(100) != 102)
throw new Exception("Fail");
if (new Proxy3().proxycode3(100) != 103)
throw new Exception("Fail");
if (new Proxy4().proxycode4(100) != 104)
throw new Exception("Fail");
if (new Proxy4.Proxy4Nested().proxycode4nested(100) != 144)
throw new Exception("Fail");
if (new Proxy5a().proxycode5((short)100) != (short)100)
throw new Exception("Fail");
if (new Proxy5b().proxycode5(100) != 100)
throw new Exception("Fail");
if (new Proxy5b().proxycode5(100, 100) != 255)
throw new Exception("Fail");
uint t1 = 10;
uint t2 = 100;
Proxy6 p = new Proxy6().proxyUseT(t1, t2);
p.useT(t1, t2);
}
}

View file

@ -0,0 +1,41 @@
module proxycode_runme;
import std.exception;
import proxycode.Proxy1;
import proxycode.Proxy2;
import proxycode.Proxy3;
import proxycode.Proxy4;
import proxycode.Proxy5a;
import proxycode.Proxy5b;
import proxycode.Proxy6;
void main() {
if (new Proxy1().proxycode1(100) != 101)
throw new Exception("Fail");
if (new Proxy1().proxycode1(100) != 101)
throw new Exception("Fail");
if (new Proxy2().proxycode2a(100) != 102)
throw new Exception("Fail");
if (new Proxy2().proxycode2b(100) != 102)
throw new Exception("Fail");
if (new Proxy3().proxycode3(100) != 103)
throw new Exception("Fail");
if (new Proxy4().proxycode4(100) != 104)
throw new Exception("Fail");
// if (new Proxy4.Proxy4Nested().proxycode4nested(100) != 144)
// throw new Exception("Fail");
if (new Proxy5a().proxycode5(100) != 100)
throw new Exception("Fail");
if (new Proxy5b().proxycode5(100) != 100)
throw new Exception("Fail");
if (new Proxy5b().proxycode5(100, 100) != 255)
throw new Exception("Fail");
uint t1 = 10;
uint t2 = 100;
Proxy6 p = new Proxy6().proxyUseT(t1, t2);
p.useT(t1, t2);
}

View file

@ -0,0 +1,42 @@
import proxycode.*;
public class proxycode_runme {
static {
try {
System.loadLibrary("proxycode");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[]) throws Throwable
{
if (new Proxy1().proxycode1(100) != 101)
throw new RuntimeException("Fail");
if (new Proxy2().proxycode2a(100) != 102)
throw new RuntimeException("Fail");
if (new Proxy2().proxycode2b(100) != 102)
throw new RuntimeException("Fail");
if (new Proxy3().proxycode3(100) != 103)
throw new RuntimeException("Fail");
if (new Proxy4().proxycode4(100) != 104)
throw new RuntimeException("Fail");
if (new Proxy4.Proxy4Nested().proxycode4nested(100) != 144)
throw new RuntimeException("Fail");
if (new Proxy5a().proxycode5((short)100) != (short)100)
throw new RuntimeException("Fail");
if (new Proxy5b().proxycode5(100) != 100)
throw new RuntimeException("Fail");
if (new Proxy5b().proxycode5(100, 100) != 255)
throw new RuntimeException("Fail");
long t1 = 10;
long t2 = 100;
Proxy6 p = new Proxy6().proxyUseT(t1, t2);
p.useT(t1, t2);
}
}

View file

@ -0,0 +1,141 @@
%module proxycode
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Proxy4::Proxy4Nested;
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
%{
struct Proxy1 {};
%}
struct Proxy1 {
%proxycode %{
public int proxycode1(int i) {
return i+1;
}
%}
};
%proxycode %{
this should be ignored as it is not in scope of a class
%}
%extend Proxy2 {
%proxycode %{
public int proxycode2a(int i) {
return i+2;
}
%}
}
%extend Proxy2 {
%proxycode %{
public int proxycode2b(int i) {
return i+2;
}
%}
}
%inline %{
struct Proxy2 {};
struct Proxy3 {};
struct Proxy4 {
struct Proxy4Nested {};
};
%}
%extend Proxy3 {
%proxycode %{
public int proxycode3(int i) {
return i+3;
}
%}
}
%extend Proxy4 {
%proxycode %{
public int proxycode4(int i) {
return i+4;
}
%}
}
%extend Proxy4::Proxy4Nested {
%proxycode %{
public int proxycode4nested(int i) {
return i+44;
}
%}
}
%extend TemplateProxy {
%proxycode %{
public T proxycode5(T i) {
return i;
}
%}
}
%extend TemplateProxy<int> {
%proxycode %{
public int proxycode5(int i, int j) {
return i+j+55;
}
%}
}
%inline %{
template <typename T> struct TemplateProxy {};
%}
%template(Proxy5a) TemplateProxy<short>;
%template(Proxy5b) TemplateProxy<int>;
%inline %{
template <typename T> struct TypemapProxy {
T useT(T t1, T const& t2) {
return t1+t2;
}
};
%}
%extend TypemapProxy {
#if defined(SWIGJAVA)
%proxycode %{
public $javaclassname proxyUseT(long t1, long t2) {
$typemap(jstype, unsigned int) tt1 = t1;
$typemap(jstype, unsigned int const&) tt2 = t2;
long ret = useT(tt1, tt2);
if (ret != t1+t2)
throw new RuntimeException("wrong sum");
return this;
}
%}
#elif defined(SWIGCSHARP)
%proxycode %{
public $csclassname proxyUseT(uint t1, uint t2) {
$typemap(cstype, unsigned int) tt1 = t1;
$typemap(cstype, unsigned int const&) tt2 = t2;
uint ret = useT(tt1, tt2);
if (ret != t1+t2)
throw new System.Exception("wrong sum");
return this;
}
%}
#elif defined(SWIGD)
%proxycode %{
public $dclassname proxyUseT(uint t1, uint t2) {
$typemap(dtype, unsigned int) tt1 = t1;
$typemap(dtype, unsigned int const&) tt2 = t2;
uint ret = useT(tt1, tt2);
if (ret != t1+t2)
throw new Exception("wrong sum");
return this;
}
%}
#else
#error "missing test"
#endif
}
%template(Proxy6) TypemapProxy<unsigned int>;
#endif