Correct behaviour for templated methods used with %rename or %ignore and %template()

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9906 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2007-08-17 20:42:19 +00:00
commit 3fd28bf45c
7 changed files with 135 additions and 2 deletions

View file

@ -1,6 +1,11 @@
Version 1.3.32 (in progress)
============================
08/17/2007: wsfulton
Correct behaviour for templated methods used with %rename or %ignore and the empty
template declaration - %template(). A warning is issued if the method has not been
renamed.
08/16/2007: mutandiz (Mikel Bancroft)
[allegrocl] Name generated cl file based on input file rather than by
module name. It was possible to end up with a mypackage.cl and a test_wrap.c

View file

@ -451,6 +451,7 @@ example.i(4): Syntax error in input.
<li>516. Overloaded method <em>declaration</em> ignored. Method <em>declaration</em> at <em>file</em>:<em>line</em> used.
<li>517.
<li>518. Portability warning: File <em>file1</em> will be overwritten by <em>file2</em> on case insensitive filesystems such as Windows' FAT32 and NTFS unless the class/module name is renamed.
<li>519. %template() contains no name. Template method ignored: <em>declaration</em>
</ul>
<H3><a name="Warnings_nn15"></a>14.8.6 Language module specific (800-899) </H3>

View file

@ -279,6 +279,7 @@ CPP_TEST_CASES += \
template_inherit \
template_inherit_abstract \
template_int_const \
template_method \
template_ns \
template_ns2 \
template_ns3 \

View file

@ -0,0 +1,37 @@
import template_methods.*;
public class template_methods_runme {
static {
try {
System.loadLibrary("template_methods");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[]) {
float num = (float)1.1;
// Global templated functions
int i = template_methods.convolve1Bool();
template_methods.convolve1Bool(true);
i = template_methods.convolve2Float();
template_methods.convolve3FloatRenamed(num);
i = template_methods.convolve4Float();
template_methods.convolve4FloatRenamed(num);
i = template_methods.convolve5FloatRenamed();
template_methods.convolve5FloatRenamed(num);
// Static templated methods
Klass k = new Klass();
boolean b = k.KlassTMethodBoolRenamed(true);
k.KlassTMethodBool();
b = Klass.KlassStaticTMethodBoolRenamed(true);
Klass.KlassStaticTMethodBool();
}
}

View file

@ -0,0 +1,78 @@
// Test %ignore and %rename for templated methods
%module template_methods
%warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve1<float>();
%warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve3<float>();
///////////////////
%ignore convolve1<float>(float a);
%inline %{
template <typename ImageT> int convolve1() { ImageT t; return 0; }
template <typename ImageT> void convolve1(ImageT a) { ImageT t = a; }
%}
%template() convolve1<float>;
%template(convolve1Bool) convolve1<bool>;
///////////////////
%ignore convolve2<float>(float a);
%inline %{
template <typename ImageT> int convolve2() { ImageT t; return 0; }
template <typename ImageT> void convolve2(ImageT a) { ImageT t = a; }
%}
%template(convolve2Float) convolve2<float>;
///////////////////
%rename(convolve3FloatRenamed) convolve3<float>(float a);
%inline %{
template <typename ImageT> int convolve3() { ImageT t; return 0; }
template <typename ImageT> void convolve3(ImageT a) { ImageT t = a; }
%}
%template() convolve3<float>;
///////////////////
%rename(convolve4FloatRenamed) convolve4<float>(float a);
%inline %{
template <typename ImageT> int convolve4() { ImageT t; return 0; }
template <typename ImageT> void convolve4(ImageT a) { ImageT t = a; }
%}
%template(convolve4Float) convolve4<float>;
///////////////////
%rename(convolve5FloatRenamed) convolve5<float>;
%ignore convolve5<bool>;
%inline %{
template <typename ImageT> int convolve5() { ImageT t; return 0; }
template <typename ImageT> void convolve5(ImageT a) { ImageT t = a; }
%}
%template() convolve5<float>;
%template() convolve5<bool>;
////////////////////////////////////////////////////////////////////////////
%rename(KlassTMethodBoolRenamed) Klass::tmethod(bool);
%rename(KlassStaticTMethodBoolRenamed) Klass::statictmethod(bool);
%inline %{
struct Klass {
template<typename X> X tmethod(X x) { return x; }
template<typename X> void tmethod() {}
template<typename X> static X statictmethod(X x) { return x; }
template<typename X> static void statictmethod() {}
};
%}
%template(KlassTMethodBool) Klass::tmethod<bool>;
%template(KlassStaticTMethodBool) Klass::statictmethod<bool>;

View file

@ -185,6 +185,7 @@
#define WARN_LANG_OVERLOAD_IGNORED 516
#define WARN_LANG_DIRECTOR_ABSTRACT 517
#define WARN_LANG_PORTABILITY_FILENAME 518
#define WARN_LANG_TEMPLATE_METHOD_IGNORE 519
/* -- Reserved (600-799) -- */

View file

@ -819,7 +819,7 @@ int Language::cDeclaration(Node *n) {
return SWIG_NOWRAP;
}
/* prevent wrapping the method twice due to overload */
String *wrapname = NewStringf("nonpublic_%s%s", Getattr(n, "sym:name"), Getattr(n, "sym:overname"));
String *wrapname = NewStringf("nonpublic_%s%s", symname, Getattr(n, "sym:overname"));
if (Getattr(CurrentClass, wrapname)) {
Delete(wrapname);
return SWIG_NOWRAP;
@ -959,7 +959,17 @@ int Language::cDeclaration(Node *n) {
Delete(SwigType_pop_function(ty));
DohIncref(type);
Setattr(n, "type", ty);
functionHandler(n);
if (GetFlag(n, "feature:onlychildren") && !GetFlag(n, "feature:ignore")) {
// Found an unignored templated method that has a an empty template instantiation (%template())
// Ignore it unless it has been %rename'd
if (Strncmp(symname, "__dummy_", 8) == 0) {
SetFlag(n, "feature:ignore");
Swig_warning(WARN_LANG_TEMPLATE_METHOD_IGNORE, input_file, line_number,
"%%template() contains no name. Template method ignored: %s\n", SwigType_str(decl, SwigType_namestr(Getattr(n,"name"))));
}
}
if (!GetFlag(n, "feature:ignore"))
functionHandler(n);
Setattr(n, "type", type);
Delete(ty);
Delete(type);