From b0ecf14e31d64bdc06669c50e571bbdfd6876712 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 7 May 2008 20:59:00 +0000 Subject: [PATCH] Fix wrapping of overloaded protected methods when using allprotected mode git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10423 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Examples/test-suite/allprotected.i | 8 ++++++++ .../test-suite/csharp/allprotected_runme.cs | 18 +++++++++++++++++- .../test-suite/java/allprotected_runme.java | 18 +++++++++++++++++- Source/Modules/lang.cxx | 5 ++++- Source/Modules/utils.cxx | 2 +- 6 files changed, 51 insertions(+), 4 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a46a82ff7..b014c94de 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.36 (in progress) ============================= +05/07/2008: wsfulton + Fix wrapping of overloaded protected methods when using allprotected mode. + Bug reported by Warren Wang. + 05/03/2008: wsfulton Commit patch #1956607 to add -MT support from Richard Boulton. This patch mirrors the gcc -MT option which allows one to change the default diff --git a/Examples/test-suite/allprotected.i b/Examples/test-suite/allprotected.i index afd2fe919..3588a98ac 100644 --- a/Examples/test-suite/allprotected.i +++ b/Examples/test-suite/allprotected.i @@ -32,7 +32,11 @@ public: virtual ~PublicBase() { } virtual std::string virtualMethod() const { return "PublicBase"; } Klass instanceMethod(Klass k) const { return k; } + Klass *instanceOverloaded(Klass *k) const { return k; } + Klass *instanceOverloaded(Klass *k, std::string name) const { return new Klass(name); } static Klass staticMethod(Klass k) { return k; } + static Klass *staticOverloaded(Klass *k) { return k; } + static Klass *staticOverloaded(Klass *k, std::string name) { return new Klass(name); } int instanceMemberVariable; static int staticMemberVariable; static const int staticConstMemberVariable = 20; @@ -50,7 +54,11 @@ protected: virtual ~ProtectedBase() { } virtual std::string virtualMethod() const { return "ProtectedBase"; } Klass instanceMethod(Klass k) const { return k; } + Klass *instanceOverloaded(Klass *k) const { return k; } + Klass *instanceOverloaded(Klass *k, std::string name) const { return new Klass(name); } static Klass staticMethod(Klass k) { return k; } + static Klass *staticOverloaded(Klass *k) { return k; } + static Klass *staticOverloaded(Klass *k, std::string name) { return new Klass(name); } int instanceMemberVariable; static int staticMemberVariable; static const int staticConstMemberVariable = 20; diff --git a/Examples/test-suite/csharp/allprotected_runme.cs b/Examples/test-suite/csharp/allprotected_runme.cs index 2ce659a31..99a791d58 100644 --- a/Examples/test-suite/csharp/allprotected_runme.cs +++ b/Examples/test-suite/csharp/allprotected_runme.cs @@ -29,7 +29,23 @@ class MyProtectedBase : ProtectedBase if (k.getName() != "xyz") throw new Exception("Failed"); - k = staticMethod(new Klass("abc")); + k = instanceOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = instanceOverloaded(new Klass("xyz"), "abc"); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = ProtectedBase.staticMethod(new Klass("abc")); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = ProtectedBase.staticOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = ProtectedBase.staticOverloaded(new Klass("xyz"), "abc"); if (k.getName() != "abc") throw new Exception("Failed"); diff --git a/Examples/test-suite/java/allprotected_runme.java b/Examples/test-suite/java/allprotected_runme.java index 04c74262c..aa5413a95 100755 --- a/Examples/test-suite/java/allprotected_runme.java +++ b/Examples/test-suite/java/allprotected_runme.java @@ -31,7 +31,23 @@ class MyProtectedBase extends ProtectedBase if (!k.getName().equals("xyz")) throw new RuntimeException("Failed"); - k = staticMethod(new Klass("abc")); + k = instanceOverloaded(new Klass("xyz")); + if (!k.getName().equals("xyz")) + throw new RuntimeException("Failed"); + + k = instanceOverloaded(new Klass("xyz"), "abc"); + if (!k.getName().equals("abc")) + throw new RuntimeException("Failed"); + + k = ProtectedBase.staticMethod(new Klass("abc")); + if (!k.getName().equals("abc")) + throw new RuntimeException("Failed"); + + k = ProtectedBase.staticOverloaded(new Klass("xyz")); + if (!k.getName().equals("xyz")) + throw new RuntimeException("Failed"); + + k = ProtectedBase.staticOverloaded(new Klass("xyz"), "abc"); if (!k.getName().equals("abc")) throw new RuntimeException("Failed"); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index b3dc28604..1f68cc4ad 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2111,7 +2111,10 @@ int Language::classDirector(Node *n) { bool cdecl = (Cmp(nodeType, "cdecl") == 0); if (cdecl && !GetFlag(ni, "feature:ignore")) { if (is_non_virtual_protected_access(ni)) { - Printf(using_protected_members_code, " using %s::%s;\n", SwigType_namestr(ClassName), Getattr(ni, "name")); + Node *overloaded = Getattr(ni, "sym:overloaded"); + // emit the using base::member statement (but only once if the method is overloaded) + if (!overloaded || (overloaded && (overloaded == ni))) + Printf(using_protected_members_code, " using %s::%s;\n", SwigType_namestr(ClassName), Getattr(ni, "name")); } } } diff --git a/Source/Modules/utils.cxx b/Source/Modules/utils.cxx index ea7a3dde0..bf8211903 100644 --- a/Source/Modules/utils.cxx +++ b/Source/Modules/utils.cxx @@ -69,7 +69,7 @@ void clean_overloaded(Node *n) { if ((GetFlag(nn, "feature:ignore")) || (Getattr(nn, "error")) || (Strcmp(ntype, "template") == 0) || - ((Strcmp(ntype, "cdecl") == 0) && is_protected(nn) && !is_member_director(nn))) { + ((Strcmp(ntype, "cdecl") == 0) && is_protected(nn) && !is_member_director(nn) && !is_non_virtual_protected_access(n))) { /* Remove from overloaded list */ Node *ps = Getattr(nn, "sym:previousSibling"); Node *ns = Getattr(nn, "sym:nextSibling");