Fix detection of virtual/overridden methods when derived class has private or protected inheritance from base class

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7243 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2005-06-01 20:51:20 +00:00
commit b891717ad8

View file

@ -193,7 +193,8 @@ class Allocate : public Dispatcher {
Setattr(n, "storage", "virtual");
if (both_have_public_access)
Setattr(n, "override", base);
if (!is_non_public_base(inclass, b))
Setattr(n, "override", base);
// Try and find the most base's covariant return type
SwigType *most_base_covariant_type = Getattr(base, "covariant");
@ -213,7 +214,8 @@ class Allocate : public Dispatcher {
} else {
// Found an identical method in the base class, but it is not polymorphic.
if (both_have_public_access)
Setattr(n, "hides", base);
if (!is_non_public_base(inclass, b))
Setattr(n, "hides", base);
}
return 1;
}
@ -223,6 +225,29 @@ class Allocate : public Dispatcher {
return 0;
}
/* Determines whether the base class, b, is in the list of private
* or protected base classes for class n. */
bool is_non_public_base(Node *n, Node *b) {
bool non_public_base = false;
Node *bases = Getattr(n, "privatebases");
if (bases) {
for (int i = 0; i < Len(bases); i++) {
Node *base = Getitem(bases,i);
if (base == b)
non_public_base = true;
}
}
bases = Getattr(n, "protectedbases");
if (bases) {
for (int i = 0; i < Len(bases); i++) {
Node *base = Getitem(bases,i);
if (base == b)
non_public_base = true;
}
}
return non_public_base;
}
/* Returns the return type for a function. The node n should be a function.
If resolve is true the fully returned type is fully resolved.
Caller is responsible for deleting returned string. */