diff --git a/CHANGES.current b/CHANGES.current index 880e56acb..7e653c667 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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 diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index f6f1a9d28..b1bf25462 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -451,6 +451,7 @@ example.i(4): Syntax error in input.
  • 516. Overloaded method declaration ignored. Method declaration at file:line used.
  • 517.
  • 518. Portability warning: File file1 will be overwritten by file2 on case insensitive filesystems such as Windows' FAT32 and NTFS unless the class/module name is renamed. +
  • 519. %template() contains no name. Template method ignored: declaration

    14.8.6 Language module specific (800-899)

    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 312e5443c..99173f823 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -279,6 +279,7 @@ CPP_TEST_CASES += \ template_inherit \ template_inherit_abstract \ template_int_const \ + template_method \ template_ns \ template_ns2 \ template_ns3 \ diff --git a/Examples/test-suite/java/template_methods_runme.java b/Examples/test-suite/java/template_methods_runme.java new file mode 100644 index 000000000..cc179aa49 --- /dev/null +++ b/Examples/test-suite/java/template_methods_runme.java @@ -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(); + } +} + diff --git a/Examples/test-suite/template_methods.i b/Examples/test-suite/template_methods.i new file mode 100644 index 000000000..451c2d936 --- /dev/null +++ b/Examples/test-suite/template_methods.i @@ -0,0 +1,78 @@ +// Test %ignore and %rename for templated methods + +%module template_methods + +%warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve1(); +%warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve3(); + +/////////////////// +%ignore convolve1(float a); + +%inline %{ +template int convolve1() { ImageT t; return 0; } +template void convolve1(ImageT a) { ImageT t = a; } +%} + +%template() convolve1; +%template(convolve1Bool) convolve1; + + +/////////////////// +%ignore convolve2(float a); + +%inline %{ +template int convolve2() { ImageT t; return 0; } +template void convolve2(ImageT a) { ImageT t = a; } +%} + +%template(convolve2Float) convolve2; + +/////////////////// +%rename(convolve3FloatRenamed) convolve3(float a); + +%inline %{ +template int convolve3() { ImageT t; return 0; } +template void convolve3(ImageT a) { ImageT t = a; } +%} + +%template() convolve3; + +/////////////////// +%rename(convolve4FloatRenamed) convolve4(float a); + +%inline %{ +template int convolve4() { ImageT t; return 0; } +template void convolve4(ImageT a) { ImageT t = a; } +%} + +%template(convolve4Float) convolve4; + + +/////////////////// +%rename(convolve5FloatRenamed) convolve5; +%ignore convolve5; + +%inline %{ +template int convolve5() { ImageT t; return 0; } +template void convolve5(ImageT a) { ImageT t = a; } +%} + +%template() convolve5; +%template() convolve5; + + +//////////////////////////////////////////////////////////////////////////// +%rename(KlassTMethodBoolRenamed) Klass::tmethod(bool); +%rename(KlassStaticTMethodBoolRenamed) Klass::statictmethod(bool); + +%inline %{ +struct Klass { + template X tmethod(X x) { return x; } + template void tmethod() {} + template static X statictmethod(X x) { return x; } + template static void statictmethod() {} +}; +%} +%template(KlassTMethodBool) Klass::tmethod; +%template(KlassStaticTMethodBool) Klass::statictmethod; + diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index e6f9b256b..5c6634063 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -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) -- */ diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index f39ea7319..d81a61c22 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -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);