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
This commit is contained in:
William S Fulton 2008-05-07 20:59:00 +00:00
commit b0ecf14e31
6 changed files with 51 additions and 4 deletions

View file

@ -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

View file

@ -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;

View file

@ -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");

View file

@ -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");

View file

@ -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"));
}
}
}

View file

@ -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");