Fixes for the family of %interface macros for overloaded methods

When C++ methods are not able to be overloaded in a derived class,
such as when they differ by just const, or the target language
parameters types are identical even when the C++ parameter types
are different, SWIG will ignore one of the overloaded methods with
a warning. A %ignore is required to explicitly ignore one of the
overloaded methods to avoid the warning message. Methods added
in the derived classes due to one of the %interface macros are now
similarly ignored/not added to the derived class.

The adding of additional methods into the parse tree is now more
robust and complete resulting in support for %feature and %rename
for the added methods.

Closes #1277
This commit is contained in:
William S Fulton 2022-03-12 12:46:59 +00:00
commit b6ece11fc1
12 changed files with 259 additions and 15 deletions

View file

@ -15,6 +15,7 @@
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
#include "cparse.h"
static bool interface_feature_enabled = false;
@ -38,11 +39,19 @@ static List *collect_interface_methods(Node *n) {
if (Cmp(nodeType(child), "cdecl") == 0) {
if (GetFlag(child, "feature:ignore") || Getattr(child, "interface:owner"))
continue; // skip methods propagated to bases
Node *m = Copy(child);
set_nextSibling(m, NIL);
set_previousSibling(m, NIL);
Setattr(m, "interface:owner", cls);
Append(methods, m);
if (!checkAttribute(child, "kind", "function"))
continue;
if (checkAttribute(child, "storage", "static"))
continue; // accept virtual methods, non-virtual methods too... mmm??. Warn that the interface class has something that is not a virtual method?
Node *nn = copyNode(child);
Setattr(nn, "interface:owner", cls);
ParmList *parms = CopyParmList(Getattr(child, "parms"));
Setattr(nn, "parms", parms);
Delete(parms);
ParmList *throw_parm_list = Getattr(child, "throws");
if (throw_parm_list)
Setattr(nn, "throws", CopyParmList(throw_parm_list));
Append(methods, nn);
}
}
}
@ -164,8 +173,25 @@ void Swig_interface_propagate_methods(Node *n) {
}
Delete(this_decl_resolved);
if (!identically_overloaded_method) {
// TODO: Fix if the method is overloaded with different arguments / has default args
appendChild(n, mi.item);
// Add method copied from base class to this derived class
Node *cn = mi.item;
Delattr(cn, "sym:overname");
String *prefix = Getattr(n, "name");
String *name = Getattr(cn, "name");
String *decl = Getattr(cn, "decl");
String *oldname = Getattr(cn, "sym:name");
String *symname = Swig_name_make(cn, prefix, name, decl, oldname);
if (Strcmp(symname, "$ignore") != 0) {
Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab"));
Node *on = Swig_symbol_add(symname, cn);
assert(on == cn);
// Features from the copied base class method are already present, now add in features specific to the added method in the derived class
Swig_features_get(Swig_cparse_features(), Swig_symbol_qualifiedscopename(0), name, decl, cn);
Swig_symbol_setscope(oldscope);
appendChild(n, cn);
}
} else {
Delete(mi.item);
}