Don't use "this" method parameter for disambiguating overloads

When building the unique suffix for each member of the overloaded functions
set, don't use the first "this" parameter of the object methods in it as it's
the same for all of them and so is completely useless for disambiguation
purposes and just results in unnecessarily long and ugly names.

Use "_const" suffix for the methods differing by their const-ness only, this
is necessary now that we don't use "_pFoo" or "_pcFoo" in their names.

This makes it superfluous to check for c:objstruct in
functionWrapperAppendOverloaded() (and checking for it there was not enough
neither, as the changes in the test suite show, sometimes the "this" parameter
type still found its way into the generated wrappers).
This commit is contained in:
Vadim Zeitlin 2016-04-24 19:48:33 +02:00
commit 8e30abf7ab
3 changed files with 37 additions and 10 deletions

View file

@ -99,9 +99,9 @@ int main(int argc, const char *argv[]) {
Fl_Window *w = new_Fl_Window();
// Test whether macro worked for code extension
// and test optional function parameters
Fl_Window_show_pFl_Window(w);
Fl_Window_show_pFl_Window_pv(w, 0);
Fl_Window_show_pFl_Window_pv_pv(w, 0, 0);
Fl_Window_show(w);
Fl_Window_show_pv(w, 0);
Fl_Window_show_pv_pv(w, 0, 0);
delete_Fl_Window(w);
w = 0;

View file

@ -15,8 +15,8 @@ int main() {
assert(Op_GreaterThanEqual(op2, op1), "geq failed");
Op_PlusEqual(op3, op1);
assert(Op_LessThan(op1, op2) && Op_LessThan(op2, op3), "lt failed");
assert(3 == *Op_IndexInto(op3, Op_IndexIntoConst(op2, Op_Functor_pOp(op1))), "[] or () failed");
assert(5 == Op_Functor_pOp_i(op3, 2), "f(x) failed");
assert(3 == *Op_IndexInto(op3, Op_IndexIntoConst(op2, Op_Functor(op1))), "[] or () failed");
assert(5 == Op_Functor_i(op3, 2), "f(x) failed");
delete_Op(op1);
delete_Op(op2);

View file

@ -722,15 +722,13 @@ ready:
}
}
virtual void functionWrapperAppendOverloaded(String *name, const ParmList *parms)
virtual void functionWrapperAppendOverloaded(String *name, Parm* first_param)
{
String *over_suffix = NewString("");
Parm *p;
String *mangled;
for (p = (Parm*)parms; p; p = nextSibling(p)) {
if (Getattr(p, "c:objstruct"))
continue;
for (p = first_param; p; p = nextSibling(p)) {
mangled = get_mangled_type(Getattr(p, "type"));
Printv(over_suffix, "_", mangled, NIL);
}
@ -1117,7 +1115,36 @@ ready:
// mangle name if function is overloaded
if (Getattr(n, "sym:overloaded")) {
if (!Getattr(n, "copy_constructor")) {
functionWrapperAppendOverloaded(name, parms);
Parm* first_param = (Parm*)parms;
if (first_param) {
// Skip the first "this" parameter of the wrapped methods, it doesn't participate in overload resolution and would just result in extra long
// and ugly names.
//
// The check for c:globalfun is needed to avoid dropping the first argument of static methods which don't have "this" pointer neither, in
// spite of being members. Of course, the constructors don't have it neither.
if (!Checkattr(n, "nodeType", "constructor") &&
Checkattr(n, "ismember", "1") &&
!Checkattr(n, "c:globalfun", "1")) {
first_param = nextSibling(first_param);
// A special case of overloading on const/non-const "this" pointer only, we still need to distinguish between those.
if (SwigType_isconst(Getattr(n, "decl"))) {
const char * const nonconst = Char(Getattr(n, "decl")) + 9 /* strlen("q(const).") */;
for (Node* nover = Getattr(n, "sym:overloaded"); nover; nover = Getattr(nover, "sym:nextSibling")) {
if (nover == n)
continue;
if (Cmp(Getattr(nover, "decl"), nonconst) == 0) {
// We have an overload differing by const only, disambiguate.
Append(name, "_const");
break;
}
}
}
}
functionWrapperAppendOverloaded(name, first_param);
}
}
}