Add the parameters typemap attribute to D and Java destructor wrapper typemaps

Added to the javadestruct, javadestruct_derived, ddispose, ddispose_derived
typemaps to mirror enhanced flexibility in the csdisposing and
csdisposing_derived (C#) typemaps. If provided the contents are generated
as the delete/dispose method's parameters declaration.
This commit is contained in:
William S Fulton 2019-03-30 12:34:06 +00:00
commit 831fae3c69
7 changed files with 32 additions and 14 deletions

View file

@ -7,6 +7,12 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.0.0 (in progress) Version 4.0.0 (in progress)
=========================== ===========================
2019-03-30: wsfulton
[Java, D] Add the parameters typemap attribute to the javadestruct,
javadestruct_derived, ddispose, ddispose_derived typemaps to mirror enhanced
flexibility in the csdisposing and csdisposing_derived (C#) typemaps. If provided
the contents are generated as the delete/dispose method's parameters declaration.
2019-03-30: wsfulton 2019-03-30: wsfulton
[C#] #421 Fix CA1063 warning by implementing the recommended Dispose methods for [C#] #421 Fix CA1063 warning by implementing the recommended Dispose methods for
the IDisposable interface. Previously just the Dispose() method was generated. the IDisposable interface. Previously just the Dispose() method was generated.

View file

@ -107,8 +107,8 @@
csimports <-> dimports csimports <-> dimports
csbody <-> dbody csbody <-> dbody
csfinalize <-> ddestructor csfinalize <-> ddestructor
csdestruct <-> ddispose csdisposing <-> ddispose
csdestruct_derived <-> ddispose_derived csdisposing_derived <-> ddispose_derived
</pre></div> </pre></div>

View file

@ -6552,7 +6552,7 @@ As there can only be one "javacode" typemap per class, also consider using the
and offers nearly identical functionality. and offers nearly identical functionality.
</div> </div>
<p><tt>%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized")</tt> <br></p> <p><tt>%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized", parameters="")</tt> <br></p>
<div class="indent"> <div class="indent">
destructor wrapper - the <tt>delete()</tt> method (proxy classes only), destructor wrapper - the <tt>delete()</tt> method (proxy classes only),
used for all proxy classes except those which have a base class used for all proxy classes except those which have a base class
@ -6563,9 +6563,10 @@ Note that the <tt>delete()</tt> method name is configurable and is specified by
The method modifiers are also configurable via the <tt>methodmodifiers</tt> attribute. The method modifiers are also configurable via the <tt>methodmodifiers</tt> attribute.
If a <tt>%javamethodmodifiers</tt> is attached to the class' destructor, If a <tt>%javamethodmodifiers</tt> is attached to the class' destructor,
it will be used in preference to the <tt>methodmodifiers</tt> typemap attribute for the class. it will be used in preference to the <tt>methodmodifiers</tt> typemap attribute for the class.
The <tt>delete</tt> method's parameters declaration can be provided in the optional <tt>parameters</tt> typemap attribute.
</div> </div>
<p><tt>%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized")</tt></p> <p><tt>%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized", parameters="")</tt></p>
<div class="indent"> <div class="indent">
destructor wrapper - the <tt>delete()</tt> method (proxy classes only), destructor wrapper - the <tt>delete()</tt> method (proxy classes only),
same as "javadestruct" but only used for derived proxy classes same as "javadestruct" but only used for derived proxy classes
@ -6576,6 +6577,7 @@ Note that the <tt>delete()</tt> method name is configurable and is specified by
The method modifiers are also configurable via the <tt>methodmodifiers</tt> attribute. The method modifiers are also configurable via the <tt>methodmodifiers</tt> attribute.
If a <tt>%javamethodmodifiers</tt> is attached to the class' destructor, If a <tt>%javamethodmodifiers</tt> is attached to the class' destructor,
it will be used in preference to the <tt>methodmodifiers</tt> typemap attribute for the class. it will be used in preference to the <tt>methodmodifiers</tt> typemap attribute for the class.
The <tt>delete</tt> method's parameters declaration can be provided in the optional <tt>parameters</tt> typemap attribute.
</div> </div>
<p><tt>%typemap(javaimports)</tt></p> <p><tt>%typemap(javaimports)</tt></p>

View file

@ -33,7 +33,7 @@
// We do not use »override« attribute for generated dispose() methods to stay // We do not use »override« attribute for generated dispose() methods to stay
// somewhat compatible to Phobos and older Tango versions where Object.dispose() // somewhat compatible to Phobos and older Tango versions where Object.dispose()
// does not exist. // does not exist.
%typemap(ddispose, methodname="dispose", methodmodifiers="public") SWIGTYPE { %typemap(ddispose, methodname="dispose", methodmodifiers="public", parameters="") SWIGTYPE {
synchronized(this) { synchronized(this) {
if (swigCPtr !is null) { if (swigCPtr !is null) {
if (swigCMemOwn) { if (swigCMemOwn) {
@ -45,7 +45,7 @@
} }
} }
%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public") SWIGTYPE { %typemap(ddispose_derived, methodname="dispose", methodmodifiers="public", parameters="") SWIGTYPE {
synchronized(this) { synchronized(this) {
if (swigCPtr !is null) { if (swigCPtr !is null) {
if (swigCMemOwn) { if (swigCMemOwn) {

View file

@ -1313,7 +1313,7 @@ SWIG_PROXY_CONSTRUCTOR(true, false, TYPENAME)
// Set the default for SWIGTYPE: Java owns the C/C++ object. // Set the default for SWIGTYPE: Java owns the C/C++ object.
SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") SWIGTYPE { %typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized", parameters="") SWIGTYPE {
if (swigCPtr != 0) { if (swigCPtr != 0) {
if (swigCMemOwn) { if (swigCMemOwn) {
swigCMemOwn = false; swigCMemOwn = false;
@ -1323,7 +1323,7 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
} }
} }
%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") SWIGTYPE { %typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized", parameters="") SWIGTYPE {
if (swigCPtr != 0) { if (swigCPtr != 0) {
if (swigCMemOwn) { if (swigCMemOwn) {
swigCMemOwn = false; swigCMemOwn = false;

View file

@ -3274,17 +3274,20 @@ private:
// attribute called »methodname«. // attribute called »methodname«.
const String *tm = NULL; const String *tm = NULL;
String *dispose_methodname; const String *dispose_methodname;
String *dispose_methodmodifiers; const String *dispose_methodmodifiers;
const String *dispose_parameters;
attributes = NewHash(); attributes = NewHash();
if (derived) { if (derived) {
tm = lookupCodeTypemap(n, "ddispose_derived", typemap_lookup_type, WARN_NONE, attributes); tm = lookupCodeTypemap(n, "ddispose_derived", typemap_lookup_type, WARN_NONE, attributes);
dispose_methodname = Getattr(attributes, "tmap:ddispose_derived:methodname"); dispose_methodname = Getattr(attributes, "tmap:ddispose_derived:methodname");
dispose_methodmodifiers = Getattr(attributes, "tmap:ddispose_derived:methodmodifiers"); dispose_methodmodifiers = Getattr(attributes, "tmap:ddispose_derived:methodmodifiers");
dispose_parameters = Getattr(attributes, "tmap:ddispose_derived:parameters");
} else { } else {
tm = lookupCodeTypemap(n, "ddispose", typemap_lookup_type, WARN_NONE, attributes); tm = lookupCodeTypemap(n, "ddispose", typemap_lookup_type, WARN_NONE, attributes);
dispose_methodname = Getattr(attributes, "tmap:ddispose:methodname"); dispose_methodname = Getattr(attributes, "tmap:ddispose:methodname");
dispose_methodmodifiers = Getattr(attributes, "tmap:ddispose:methodmodifiers"); dispose_methodmodifiers = Getattr(attributes, "tmap:ddispose:methodmodifiers");
dispose_parameters = Getattr(attributes, "tmap:ddispose:parameters");
} }
if (tm && *Char(tm)) { if (tm && *Char(tm)) {
@ -3298,6 +3301,8 @@ private:
"No methodmodifiers attribute defined in ddispose%s typemap for %s.\n", "No methodmodifiers attribute defined in ddispose%s typemap for %s.\n",
(derived ? "_derived" : ""), proxy_class_name); (derived ? "_derived" : ""), proxy_class_name);
} }
if (!dispose_parameters)
dispose_parameters = empty_string;
} }
if (tm) { if (tm) {
@ -3324,7 +3329,7 @@ private:
Printv(body, methodmods, NIL); Printv(body, methodmods, NIL);
else else
Printv(body, dispose_methodmodifiers, (derived ? " override" : ""), NIL); Printv(body, dispose_methodmodifiers, (derived ? " override" : ""), NIL);
Printv(body, " void ", dispose_methodname, "() ", dispose_code, "\n", NIL); Printv(body, " void ", dispose_methodname, "(", dispose_parameters, ") ", dispose_code, "\n", NIL);
} }
} }

View file

@ -2035,16 +2035,19 @@ public:
String *destruct = NewString(""); String *destruct = NewString("");
const String *tm = NULL; const String *tm = NULL;
attributes = NewHash(); attributes = NewHash();
String *destruct_methodname = NULL; const String *destruct_methodname = NULL;
String *destruct_methodmodifiers = NULL; const String *destruct_methodmodifiers = NULL;
const String *destruct_parameters = NULL;
if (derived) { if (derived) {
tm = typemapLookup(n, "javadestruct_derived", typemap_lookup_type, WARN_NONE, attributes); tm = typemapLookup(n, "javadestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:javadestruct_derived:methodname"); destruct_methodname = Getattr(attributes, "tmap:javadestruct_derived:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:javadestruct_derived:methodmodifiers"); destruct_methodmodifiers = Getattr(attributes, "tmap:javadestruct_derived:methodmodifiers");
destruct_parameters = Getattr(attributes, "tmap:javadestruct_derived:parameters");
} else { } else {
tm = typemapLookup(n, "javadestruct", typemap_lookup_type, WARN_NONE, attributes); tm = typemapLookup(n, "javadestruct", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:javadestruct:methodname"); destruct_methodname = Getattr(attributes, "tmap:javadestruct:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:javadestruct:methodmodifiers"); destruct_methodmodifiers = Getattr(attributes, "tmap:javadestruct:methodmodifiers");
destruct_parameters = Getattr(attributes, "tmap:javadestruct:parameters");
} }
if (tm && *Char(tm)) { if (tm && *Char(tm)) {
if (!destruct_methodname) { if (!destruct_methodname) {
@ -2053,6 +2056,8 @@ public:
if (!destruct_methodmodifiers) { if (!destruct_methodmodifiers) {
Swig_error(Getfile(n), Getline(n), "No methodmodifiers attribute defined in javadestruct%s typemap for %s.\n", (derived ? "_derived" : ""), proxy_class_name); Swig_error(Getfile(n), Getline(n), "No methodmodifiers attribute defined in javadestruct%s typemap for %s.\n", (derived ? "_derived" : ""), proxy_class_name);
} }
if (!destruct_parameters)
destruct_parameters = empty_string;
} }
// Emit the finalize and delete methods // Emit the finalize and delete methods
if (tm) { if (tm) {
@ -2073,7 +2078,7 @@ public:
Printv(proxy_class_def, methodmods, NIL); Printv(proxy_class_def, methodmods, NIL);
else else
Printv(proxy_class_def, destruct_methodmodifiers, NIL); Printv(proxy_class_def, destruct_methodmodifiers, NIL);
Printv(proxy_class_def, " void ", destruct_methodname, "()", destructor_throws_clause, " ", destruct, "\n", NIL); Printv(proxy_class_def, " void ", destruct_methodname, "(", destruct_parameters, ") ", destructor_throws_clause, " ", destruct, "\n", NIL);
} }
} }
if (*Char(interface_upcasts)) if (*Char(interface_upcasts))