fix generated code for derived classes when csbase or javabase typemaps are used with the replace=1 attribute.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10016 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a1052bab4f
commit
a43e50ac07
5 changed files with 163 additions and 62 deletions
|
|
@ -170,6 +170,7 @@ CPP_TEST_CASES += \
|
|||
inherit \
|
||||
inherit_missing \
|
||||
inherit_same_name \
|
||||
inherit_target_language \
|
||||
inherit_void_arg \
|
||||
inline_initializer \
|
||||
kind \
|
||||
|
|
|
|||
63
Examples/test-suite/inherit_target_language.i
Normal file
63
Examples/test-suite/inherit_target_language.i
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
// Test using a target language specified base class, primarily for Java/C# and possibly other single inheritance languages
|
||||
|
||||
// Note the multiple inheritance warnings don't appear because of the two techniques used in here: typemaps and %ignore
|
||||
|
||||
%module inherit_target_language
|
||||
|
||||
#if defined(SWIGJAVA)
|
||||
# define csbase javabase
|
||||
#endif
|
||||
|
||||
%pragma(csharp) moduleimports=%{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
public class TargetLanguageBase { public virtual void targetLanguageBaseMethod() {} };
|
||||
%}
|
||||
|
||||
%pragma(java) moduleimports=%{
|
||||
class TargetLanguageBase { public void targetLanguageBaseMethod() {} };
|
||||
%}
|
||||
|
||||
|
||||
%typemap(csbase) SWIGTYPE "TargetLanguageBase"
|
||||
|
||||
// Two ways to replace a C++ base with a completely different target language base
|
||||
%ignore Base1; // another way to use the target language base
|
||||
%typemap(csbase, replace="1") Derived2 "TargetLanguageBase"
|
||||
|
||||
%inline %{
|
||||
struct Base1 { virtual ~Base1() {} };
|
||||
struct Base2 { virtual ~Base2() {} };
|
||||
struct Derived1 : Base1 {};
|
||||
struct Derived2 : Base2 {};
|
||||
%}
|
||||
|
||||
// Multiple inheritance
|
||||
%ignore MBase1a;
|
||||
%ignore MBase1b;
|
||||
%typemap(csbase, replace="1") MultipleDerived2 "TargetLanguageBase"
|
||||
|
||||
%inline %{
|
||||
struct MBase1a { virtual ~MBase1a() {} virtual void a() {} };
|
||||
struct MBase1b { virtual ~MBase1b() {} virtual void b() {} };
|
||||
struct MBase2a { virtual ~MBase2a() {} virtual void c() {} };
|
||||
struct MBase2b { virtual ~MBase2b() {} virtual void d() {} };
|
||||
struct MultipleDerived1 : MBase1a, MBase1b {};
|
||||
struct MultipleDerived2 : MBase1a, MBase2b {};
|
||||
%}
|
||||
|
||||
|
||||
%ignore MBase3a;
|
||||
%ignore MBase4b;
|
||||
%typemap(csbase) MultipleDerived3 ""
|
||||
%typemap(csbase) MultipleDerived4 ""
|
||||
|
||||
%inline %{
|
||||
struct MBase3a { virtual ~MBase3a() {} virtual void e() {} };
|
||||
struct MBase3b { virtual ~MBase3b() {} virtual void f() {} };
|
||||
struct MBase4a { virtual ~MBase4a() {} virtual void g() {} };
|
||||
struct MBase4b { virtual ~MBase4b() {} virtual void h() {} };
|
||||
struct MultipleDerived3 : MBase3a, MBase3b {};
|
||||
struct MultipleDerived4 : MBase4a, MBase4b {};
|
||||
%}
|
||||
|
||||
26
Examples/test-suite/java/inherit_target_language_runme.java
Normal file
26
Examples/test-suite/java/inherit_target_language_runme.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
import inherit_target_language.*;
|
||||
|
||||
|
||||
public class inherit_target_language_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("inherit_target_language");
|
||||
} 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[]) {
|
||||
new Derived1().targetLanguageBaseMethod();
|
||||
new Derived2().targetLanguageBaseMethod();
|
||||
|
||||
new MultipleDerived1().targetLanguageBaseMethod();
|
||||
new MultipleDerived2().targetLanguageBaseMethod();
|
||||
new MultipleDerived3().f();
|
||||
new MultipleDerived4().g();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue