Minor refactor of D, C#, Java director code

for overloaded methods. Fixes regression (crash) in director_ignore D
testcase since string mangling names change.
This commit is contained in:
William S Fulton 2022-11-12 16:25:17 +00:00
parent e3ccabbd4d
commit 777fd2c280
3 changed files with 51 additions and 34 deletions

View File

@ -2973,7 +2973,7 @@ public:
/* A C# HandleRef is used for all classes in the SWIG intermediary class.
* The intermediary class methods are thus mangled when overloaded to give
* a unique name. */
String *overloaded_name = NewStringf("%s", Getattr(n, "sym:name"));
String *overloaded_name = Copy(Getattr(n, "sym:name"));
if (Getattr(n, "sym:overloaded")) {
Printv(overloaded_name, Getattr(n, "sym:overname"), NIL);
@ -3817,7 +3817,7 @@ public:
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *returntype = Getattr(n, "type");
String *overloaded_name = getOverloadedName(n);
String *overloaded_name = 0;
String *storage = Getattr(n, "storage");
String *value = Getattr(n, "value");
String *decl = Getattr(n, "decl");
@ -3839,7 +3839,6 @@ public:
String *qualified_name = NewStringf("%s::%s", dirclassname, name);
SwigType *c_ret_type = NULL;
String *jupcall_args = NewString("");
String *imclass_dmethod;
String *callback_typedef_parms = NewString("");
String *delegate_parms = NewString("");
String *proxy_method_types = NewString("");
@ -3853,7 +3852,8 @@ public:
// we're consistent with the sym:overload name in functionWrapper. (?? when
// does the overloaded method name get set?)
imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), getClassPrefix(), overloaded_name));
if (!ignored_method)
overloaded_name = getOverloadedName(n);
qualified_return = SwigType_rcaststr(returntype, "c_result");
@ -3906,28 +3906,28 @@ public:
}
}
/* Create the intermediate class wrapper */
tm = Swig_typemap_lookup("imtype", n, "", 0);
if (tm) {
String *imtypeout = Getattr(n, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap
if (imtypeout)
tm = imtypeout;
const String *im_directoroutattributes = Getattr(n, "tmap:imtype:directoroutattributes");
if (im_directoroutattributes) {
Printf(callback_def, " %s\n", im_directoroutattributes);
if (!ignored_method)
Printf(director_delegate_definitions, " %s\n", im_directoroutattributes);
}
if (!ignored_method) {
/* Create the intermediate class wrapper */
tm = Swig_typemap_lookup("imtype", n, "", 0);
if (tm) {
String *imtypeout = Getattr(n, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap
if (imtypeout)
tm = imtypeout;
const String *im_directoroutattributes = Getattr(n, "tmap:imtype:directoroutattributes");
if (im_directoroutattributes) {
Printf(callback_def, " %s\n", im_directoroutattributes);
if (!ignored_method)
Printf(director_delegate_definitions, " %s\n", im_directoroutattributes);
}
Printf(callback_def, " private %s SwigDirectorMethod%s(", tm, overloaded_name);
if (!ignored_method) {
Printf(callback_def, " private %s SwigDirectorMethod%s(", tm, overloaded_name);
const String *csdirectordelegatemodifiers = Getattr(n, "feature:csdirectordelegatemodifiers");
String *modifiers = (csdirectordelegatemodifiers ? NewStringf("%s%s", csdirectordelegatemodifiers, Len(csdirectordelegatemodifiers) > 0 ? " " : "") : NewStringf("public "));
Printf(director_delegate_definitions, " %sdelegate %s", modifiers, tm);
Delete(modifiers);
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
if ((c_ret_type = Swig_typemap_lookup("ctype", n, "", 0))) {
@ -4285,6 +4285,8 @@ public:
if (!ignored_method) {
/* Emit the actual upcall through */
String *member_name = Swig_name_member(getNSpace(), getClassPrefix(), overloaded_name);
String *imclass_dmethod = NewStringf("SwigDirector_%s", member_name);
UpcallData *udata = addUpcallMethod(imclass_dmethod, symname, decl, overloaded_name);
String *methid = Getattr(udata, "class_methodidx");
Setattr(n, "upcalldata", udata);
@ -4300,6 +4302,9 @@ public:
Printf(director_delegate_instances, " private SwigDelegate%s_%s swigDelegate%s;\n", classname, methid, methid);
Printf(director_method_types, " private static global::System.Type[] swigMethodTypes%s = new global::System.Type[] { %s };\n", methid, proxy_method_types);
Printf(director_connect_parms, "SwigDirector%s%s delegate%s", classname, methid, methid);
Delete(imclass_dmethod);
Delete(member_name);
}
Delete(pre_code);

View File

@ -1943,7 +1943,7 @@ public:
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *returntype = Getattr(n, "type");
String *overloaded_name = getOverloadedName(n);
String *overloaded_name = 0;
String *storage = Getattr(n, "storage");
String *value = Getattr(n, "value");
String *decl = Getattr(n, "decl");
@ -1962,7 +1962,6 @@ public:
String *qualified_name = NewStringf("%s::%s", dirclassname, name);
SwigType *c_ret_type = NULL;
String *dcallback_call_args = NewString("");
String *imclass_dmethod;
String *callback_typedef_parms = NewString("");
String *delegate_parms = NewString("");
String *proxy_method_param_list = NewString("");
@ -1977,7 +1976,8 @@ public:
// we're consistent with the sym:overload name in functionWrapper. (?? when
// does the overloaded method name get set?)
imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name));
if (!ignored_method)
overloaded_name = getOverloadedName(n);
qualified_return = SwigType_rcaststr(returntype, "c_result");
@ -2381,8 +2381,9 @@ public:
dp_return_type = NewString("");
}
String *member_name = Swig_name_member(getNSpace(), classname, overloaded_name);
String *imclass_dmethod = NewStringf("SwigDirector_%s", member_name);
UpcallData *udata = addUpcallMethod(imclass_dmethod, symname, decl, overloaded_name, dp_return_type, proxy_method_param_list);
Delete(dp_return_type);
// Write the global callback function pointer on the C code.
String *methid = Getattr(udata, "class_methodidx");
@ -2396,6 +2397,10 @@ public:
String *dirClassName = directorClassName(parent);
Printf(proxy_callback_type, "%s_Callback%s", dirClassName, methid);
Printf(im_dmodule_code, "alias extern(C) %s function(void*%s) %s;\n", proxy_callback_return_type, delegate_parms, proxy_callback_type);
Delete(imclass_dmethod);
Delete(member_name);
Delete(dp_return_type);
Delete(proxy_callback_type);
Delete(dirClassName);
}
@ -4281,6 +4286,7 @@ private:
* D::getOverloadedName()
* --------------------------------------------------------------------------- */
String *getOverloadedName(Node *n) const {
// A void* parameter is used for all wrapped classes in the wrapper code.
// Thus, the wrapper function names for overloaded functions are postfixed
// with a counter string to make them unique.

View File

@ -2988,7 +2988,7 @@ public:
* a Java long is used for all classes in the SWIG intermediary class.
* The intermediary class methods are thus mangled when overloaded to give
* a unique name. */
String *overloaded_name = NewStringf("%s", Getattr(n, "sym:name"));
String *overloaded_name = Copy(Getattr(n, "sym:name"));
if (Getattr(n, "sym:overloaded")) {
Printv(overloaded_name, Getattr(n, "sym:overname"), NIL);
@ -4003,7 +4003,7 @@ public:
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *returntype = Getattr(n, "type");
String *overloaded_name = getOverloadedName(n);
String *overloaded_name = 0;
String *storage = Getattr(n, "storage");
String *value = Getattr(n, "value");
String *decl = Getattr(n, "decl");
@ -4026,7 +4026,7 @@ public:
String *classret_desc = NewString("");
SwigType *c_ret_type = NULL;
String *jupcall_args = NewString("swigjobj");
String *imclass_dmethod;
String *imclass_dmethod = 0;
String *callback_def = NewString("");
String *callback_code = NewString("");
String *imcall_args = NewString("");
@ -4039,7 +4039,11 @@ public:
// we're consistent with the sym:overload name in functionWrapper. (?? when
// does the overloaded method name get set?)
imclass_dmethod = NewStringf("%s", Swig_name_member(getNSpace(), dirclassname, overloaded_name));
if (!ignored_method) {
overloaded_name = getOverloadedName(n);
imclass_dmethod = Swig_name_member(getNSpace(), dirclassname, overloaded_name);
}
qualified_return = SwigType_rcaststr(returntype, "c_result");
@ -4092,12 +4096,14 @@ public:
}
}
/* Create the intermediate class wrapper */
tm = Swig_typemap_lookup("jtype", n, "", 0);
if (tm) {
Printf(callback_def, " public static %s %s(%s jself", tm, imclass_dmethod, qualified_classname);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0));
if (!ignored_method) {
/* Create the intermediate class wrapper */
tm = Swig_typemap_lookup("jtype", n, "", 0);
if (tm) {
Printf(callback_def, " public static %s %s(%s jself", tm, imclass_dmethod, qualified_classname);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
}
String *cdesc = NULL;