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 \
|
||||||
inherit_missing \
|
inherit_missing \
|
||||||
inherit_same_name \
|
inherit_same_name \
|
||||||
|
inherit_target_language \
|
||||||
inherit_void_arg \
|
inherit_void_arg \
|
||||||
inline_initializer \
|
inline_initializer \
|
||||||
kind \
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1473,48 +1473,55 @@ public:
|
||||||
String *typemap_lookup_type = Getattr(n, "classtypeobj");
|
String *typemap_lookup_type = Getattr(n, "classtypeobj");
|
||||||
bool feature_director = Swig_directorclass(n) ? true : false;
|
bool feature_director = Swig_directorclass(n) ? true : false;
|
||||||
|
|
||||||
/* Deal with inheritance */
|
|
||||||
List *baselist = Getattr(n, "bases");
|
|
||||||
if (baselist) {
|
|
||||||
Iterator base = First(baselist);
|
|
||||||
while (base.item && GetFlag(base.item, "feature:ignore")) {
|
|
||||||
base = Next(base);
|
|
||||||
}
|
|
||||||
if (base.item) {
|
|
||||||
c_baseclassname = Getattr(base.item, "name");
|
|
||||||
baseclass = Copy(getProxyName(c_baseclassname));
|
|
||||||
if (baseclass)
|
|
||||||
c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
|
|
||||||
base = Next(base);
|
|
||||||
/* Warn about multiple inheritance for additional base class(es) */
|
|
||||||
while (base.item) {
|
|
||||||
if (GetFlag(base.item, "feature:ignore")) {
|
|
||||||
base = Next(base);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
|
|
||||||
String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
|
|
||||||
Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number,
|
|
||||||
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", proxyclassname, baseclassname);
|
|
||||||
base = Next(base);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Inheritance from pure C# classes
|
// Inheritance from pure C# classes
|
||||||
Node *attributes = NewHash();
|
Node *attributes = NewHash();
|
||||||
const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE, attributes);
|
const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE, attributes);
|
||||||
|
bool purebase_replace = GetFlag(attributes, "tmap:csbase:replace") ? true : false;
|
||||||
|
Delete(attributes);
|
||||||
|
|
||||||
|
// C++ inheritance
|
||||||
|
if (!purebase_replace) {
|
||||||
|
List *baselist = Getattr(n, "bases");
|
||||||
|
if (baselist) {
|
||||||
|
Iterator base = First(baselist);
|
||||||
|
while (base.item && GetFlag(base.item, "feature:ignore")) {
|
||||||
|
base = Next(base);
|
||||||
|
}
|
||||||
|
if (base.item) {
|
||||||
|
c_baseclassname = Getattr(base.item, "name");
|
||||||
|
baseclass = Copy(getProxyName(c_baseclassname));
|
||||||
|
if (baseclass)
|
||||||
|
c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
|
||||||
|
base = Next(base);
|
||||||
|
/* Warn about multiple inheritance for additional base class(es) */
|
||||||
|
while (base.item) {
|
||||||
|
if (GetFlag(base.item, "feature:ignore")) {
|
||||||
|
base = Next(base);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
|
||||||
|
String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
|
||||||
|
Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number,
|
||||||
|
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", proxyclassname, baseclassname);
|
||||||
|
base = Next(base);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const String *wanted_base = baseclass ? baseclass : pure_baseclass;
|
const String *wanted_base = baseclass ? baseclass : pure_baseclass;
|
||||||
bool derived = baseclass && getProxyName(c_baseclassname);
|
bool derived = baseclass && getProxyName(c_baseclassname);
|
||||||
|
|
||||||
if (GetFlag(attributes, "tmap:csbase:replace")) {
|
if (purebase_replace) {
|
||||||
wanted_base = pure_baseclass;
|
wanted_base = pure_baseclass;
|
||||||
derived = *Char(wanted_base) ? true : false;
|
derived = false;
|
||||||
Delete(baseclass);
|
Delete(baseclass);
|
||||||
baseclass = NULL;
|
baseclass = NULL;
|
||||||
} else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) {
|
} else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) {
|
||||||
Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number,
|
Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number,
|
||||||
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", typemap_lookup_type, pure_baseclass);
|
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#. Perhaps you need the replace attribute in the csbase typemap?\n", typemap_lookup_type, pure_baseclass);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pure C# interfaces
|
// Pure C# interfaces
|
||||||
const String *pure_interfaces = typemapLookup(derived ? "csinterfaces_derived" : "csinterfaces", typemap_lookup_type, WARN_NONE);
|
const String *pure_interfaces = typemapLookup(derived ? "csinterfaces_derived" : "csinterfaces", typemap_lookup_type, WARN_NONE);
|
||||||
// Start writing the proxy class
|
// Start writing the proxy class
|
||||||
|
|
|
||||||
|
|
@ -1551,50 +1551,54 @@ public:
|
||||||
String *typemap_lookup_type = Getattr(n, "classtypeobj");
|
String *typemap_lookup_type = Getattr(n, "classtypeobj");
|
||||||
bool feature_director = Swig_directorclass(n) ? true : false;
|
bool feature_director = Swig_directorclass(n) ? true : false;
|
||||||
|
|
||||||
/* Deal with inheritance */
|
// Inheritance from pure Java classes
|
||||||
List *baselist = Getattr(n, "bases");
|
Node *attributes = NewHash();
|
||||||
if (baselist) {
|
const String *pure_baseclass = typemapLookup("javabase", typemap_lookup_type, WARN_NONE, attributes);
|
||||||
Iterator base = First(baselist);
|
bool purebase_replace = GetFlag(attributes, "tmap:javabase:replace") ? true : false;
|
||||||
while (base.item && GetFlag(base.item, "feature:ignore")) {
|
Delete(attributes);
|
||||||
base = Next(base);
|
|
||||||
}
|
// C++ inheritance
|
||||||
if (base.item) {
|
if (!purebase_replace) {
|
||||||
c_baseclassname = Getattr(base.item, "name");
|
List *baselist = Getattr(n, "bases");
|
||||||
baseclass = Copy(getProxyName(c_baseclassname));
|
if (baselist) {
|
||||||
if (baseclass)
|
Iterator base = First(baselist);
|
||||||
c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
|
while (base.item && GetFlag(base.item, "feature:ignore")) {
|
||||||
base = Next(base);
|
base = Next(base);
|
||||||
/* Warn about multiple inheritance for additional base class(es) */
|
}
|
||||||
while (base.item) {
|
if (base.item) {
|
||||||
if (GetFlag(base.item, "feature:ignore")) {
|
c_baseclassname = Getattr(base.item, "name");
|
||||||
base = Next(base);
|
baseclass = Copy(getProxyName(c_baseclassname));
|
||||||
continue;
|
if (baseclass)
|
||||||
}
|
c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
|
||||||
String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
|
base = Next(base);
|
||||||
String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
|
/* Warn about multiple inheritance for additional base class(es) */
|
||||||
Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, input_file, line_number,
|
while (base.item) {
|
||||||
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", proxyclassname, baseclassname);
|
if (GetFlag(base.item, "feature:ignore")) {
|
||||||
base = Next(base);
|
base = Next(base);
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
|
||||||
|
String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
|
||||||
|
Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, input_file, line_number,
|
||||||
|
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", proxyclassname, baseclassname);
|
||||||
|
base = Next(base);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool derived = baseclass && getProxyName(c_baseclassname);
|
bool derived = baseclass && getProxyName(c_baseclassname);
|
||||||
// Inheritance from pure Java classes
|
|
||||||
Node *attributes = NewHash();
|
|
||||||
const String *pure_baseclass = typemapLookup("javabase", typemap_lookup_type, WARN_NONE, attributes);
|
|
||||||
const String *wanted_base = baseclass ? baseclass : pure_baseclass;
|
const String *wanted_base = baseclass ? baseclass : pure_baseclass;
|
||||||
|
|
||||||
if (GetFlag(attributes, "tmap:javabase:replace")) {
|
if (purebase_replace) {
|
||||||
wanted_base = pure_baseclass;
|
wanted_base = pure_baseclass;
|
||||||
derived = *Char(wanted_base) ? true : false;
|
derived = false;
|
||||||
Delete(baseclass);
|
Delete(baseclass);
|
||||||
baseclass = NULL;
|
baseclass = NULL;
|
||||||
} else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) {
|
} else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) {
|
||||||
Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, input_file, line_number,
|
Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, input_file, line_number,
|
||||||
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", typemap_lookup_type, pure_baseclass);
|
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java. Perhaps you need the replace attribute in the javabase typemap?\n", typemap_lookup_type, pure_baseclass);
|
||||||
}
|
}
|
||||||
Delete(attributes);
|
|
||||||
|
|
||||||
// Pure Java interfaces
|
// Pure Java interfaces
|
||||||
const String *pure_interfaces = typemapLookup("javainterfaces", typemap_lookup_type, WARN_NONE);
|
const String *pure_interfaces = typemapLookup("javainterfaces", typemap_lookup_type, WARN_NONE);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue