Merge branch 'templates-scope-enforcement'

* templates-scope-enforcement:
  Test a few %template errors
  Add using declarations to templates into typedef table.
  Fix type lookup in the presence of using directives and using declarations
  More docs on %template
  Testcase fix for nameclash in php
  %template scope enforcement and class definition fixes
  Template documentation tweaks
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  Documentation corrections to use targetlang formatting
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  Namespace documentation minor corrections
  Improve description of template_parameters_resolve
  Minor code optimisation in template_parameters_resolve
  Fix scope lookup for template parameters containing unary scope operators
  Typemap change for templates
This commit is contained in:
William S Fulton 2017-08-16 21:44:51 +01:00
commit 32a454cfef
51 changed files with 1924 additions and 700 deletions

View file

@ -0,0 +1,152 @@
// Test a mix of forward class declarations, class definitions, using declarations and using directives.
%module class_scope_namespace
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) H::HH;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Space8::I::II;
%inline %{
struct A;
namespace Space1 {
namespace SubSpace1 {
struct A {
void aa(Space1::SubSpace1::A, SubSpace1::A, A) {}
};
void aaa(Space1::SubSpace1::A, SubSpace1::A, A) {}
}
}
namespace Space2 {
struct B;
}
using Space2::B;
struct B {
void bb(Space2::B, B) {}
};
void bbb(Space2::B, B) {}
namespace Space3 {
namespace SubSpace3 {
struct C;
struct D;
}
}
struct C;
struct D;
namespace Space3 {
struct C;
struct SubSpace3::C {
void cc(Space3::SubSpace3::C, SubSpace3::C) {}
};
using SubSpace3::D;
struct SubSpace3::D {
void dd(Space3::SubSpace3::D, SubSpace3::D, D) {}
};
void ccc(Space3::SubSpace3::C, SubSpace3::C) {}
void ddd(Space3::SubSpace3::D, SubSpace3::D, D) {}
}
namespace Space4 {
namespace SubSpace4 {
struct E;
}
}
using namespace Space4;
using SubSpace4::E;
// Was added to incorrect namespace in swig-3.0.12
struct SubSpace4::E {
void ee(Space4::SubSpace4::E, SubSpace4::E, E) {}
};
void eee(Space4::SubSpace4::E, SubSpace4::E, E) {}
namespace Space5 {
namespace SubSpace5 {
namespace SubSubSpace5 {
struct F;
}
}
}
namespace Space5 {
using namespace SubSpace5;
using SubSubSpace5::F;
// Was added to incorrect namespace in swig-3.0.12
struct SubSubSpace5::F {
void ff(Space5::SubSpace5::SubSubSpace5::F, SubSpace5::SubSubSpace5::F, SubSubSpace5::F, F) {}
};
void fff(Space5::SubSpace5::SubSubSpace5::F, SubSpace5::SubSubSpace5::F, SubSubSpace5::F, F) {}
}
namespace Space6 {
struct G;
namespace SubSpace6 {
struct G;
}
}
namespace Space6 {
struct SubSpace6::G {
void gg(Space6::SubSpace6::G, SubSpace6::G) {}
};
void ggg(Space6::SubSpace6::G, SubSpace6::G) {}
}
struct HH;
struct H {
struct HH {
void hh(H::HH) {}
};
};
void hhh(H::HH) {}
namespace Space8 {
struct II;
struct I {
struct II {
void ii(Space8::I::II, I::II) {}
};
};
void iii(Space8::I::II, I::II) {}
}
struct J;
namespace Space9 {
namespace SubSpace9 {
struct J {
void jj(Space9::SubSpace9::J, SubSpace9::J, J) {}
};
void jjj(Space9::SubSpace9::J, SubSpace9::J, J) {}
}
}
namespace Space10 {
struct K;
}
namespace Space10 {
namespace SubSpace10 {
struct K {
void kk(Space10::SubSpace10::K, SubSpace10::K, K) {}
};
void kkk(Space10::SubSpace10::K, SubSpace10::K, K) {}
}
}
namespace OtherSpace {
struct L;
struct M;
}
using OtherSpace::L;
namespace Space11 {
using OtherSpace::M;
namespace SubSpace11 {
struct L {
void ll(Space11::SubSpace11::L, SubSpace11::L, L) {}
};
void lll(Space11::SubSpace11::L, SubSpace11::L, L) {}
struct M {
void mm(Space11::SubSpace11::M, SubSpace11::M, M) {}
};
void mmm(Space11::SubSpace11::M, SubSpace11::M, M) {}
}
}
%}

View file

@ -136,6 +136,7 @@ CPP_TEST_CASES += \
char_binary \
char_strings \
chartest \
class_scope_namespace \
class_forward \
class_ignore \
class_scope_weird \
@ -291,6 +292,7 @@ CPP_TEST_CASES += \
multiple_inheritance_shared_ptr \
name_cxx \
name_warnings \
namespace_chase \
namespace_class \
namespace_enum \
namespace_extend \
@ -435,6 +437,7 @@ CPP_TEST_CASES += \
template_methods \
template_namespace_forward_declaration \
template_using_directive_and_declaration_forward \
template_using_directive_typedef \
template_nested \
template_nested_typemaps \
template_ns \
@ -445,6 +448,7 @@ CPP_TEST_CASES += \
template_ns_enum2 \
template_ns_inherit \
template_ns_scope \
template_parameters_global_scope \
template_partial_arg \
template_partial_specialization \
template_partial_specialization_typedef \

View file

@ -0,0 +1,26 @@
%module xxx
// This should error but doesn't
#if 0
namespace OtherSpace {
struct L;
}
namespace Space11 {
namespace SubSpace11 {
using OtherSpace::L;
struct L {
void ll();
};
}
}
#endif
namespace Space1 {
struct A;
}
namespace Space2 {
struct Space1::A {
void x();
};
}

View file

@ -0,0 +1 @@
cpp_class_definition.i:22: Error: 'Space1::A' resolves to 'Space1::A' and was incorrectly instantiated in scope 'Space2' instead of within scope 'Space1'.

View file

@ -0,0 +1,9 @@
%module cpp_invalid_scope
%template(abc) SSS::AAA<int>;
namespace UUU {
struct JJJ;
}
%template(xxx) UUU::JJJ<int>;

View file

@ -0,0 +1,3 @@
cpp_invalid_template.i:3: Error: Undefined scope 'SSS'
cpp_invalid_template.i:3: Error: Template 'SSS::AAA' undefined.
cpp_invalid_template.i:9: Error: 'JJJ' is not defined as a template. (classforward)

View file

@ -0,0 +1,40 @@
%module namespace_template
namespace test {
template<typename T> T max(T a, T b) { return (a > b) ? a : b; }
template<typename T> class vector {
public:
vector() { }
~vector() { }
};
}
namespace test2 {
using namespace test;
%template(maxshort) max<short>;
%template(vectorshort) vector<short>;
}
namespace test3 {
using test::max;
using test::vector;
%template(maxlong) max<long>;
%template(vectorlong) vector<long>;
}
namespace test4 {
using namespace test;
typedef int Integer;
}
namespace test4 {
%template(maxInteger) max<Integer>;
%template(vectorInteger) vector<Integer>;
}
using namespace test;
namespace test5 {
%template(maxdouble) max<double>;
%template(vectordouble) vector<double>;
}

View file

@ -0,0 +1,9 @@
cpp_namespace_template_bad.i:14: Error: 'max' resolves to 'test::max' and was incorrectly instantiated in scope 'test2' instead of within scope 'test'.
cpp_namespace_template_bad.i:15: Error: 'vector' resolves to 'test::vector' and was incorrectly instantiated in scope 'test2' instead of within scope 'test'.
cpp_namespace_template_bad.i:21: Error: 'max' resolves to 'test::max' and was incorrectly instantiated in scope 'test3' instead of within scope 'test'.
cpp_namespace_template_bad.i:22: Error: 'vector' resolves to 'test::vector' and was incorrectly instantiated in scope 'test3' instead of within scope 'test'.
cpp_namespace_template_bad.i:31: Error: 'max' resolves to 'test::max' and was incorrectly instantiated in scope 'test4' instead of within scope 'test'.
cpp_namespace_template_bad.i:32: Error: 'vector' resolves to 'test::vector' and was incorrectly instantiated in scope 'test4' instead of within scope 'test'.
cpp_namespace_template_bad.i:37: Error: 'max' resolves to 'test::max' and was incorrectly instantiated in scope 'test5' instead of within scope 'test'.
cpp_namespace_template_bad.i:37: Error: Template 'max' undefined.
cpp_namespace_template_bad.i:38: Error: 'vector' resolves to 'test::vector' and was incorrectly instantiated in scope 'test5' instead of within scope 'test'.

View file

@ -1,2 +1,4 @@
cpp_nested_template.i:9: Error: 'Temply' resolves to '::Temply' and was incorrectly instantiated in scope 'A' instead of within scope ''.
cpp_nested_template.i:9: Warning 324: Named nested template instantiations not supported. Processing as if no name was given to %template().
cpp_nested_template.i:18: Error: 'Temply' resolves to '::Temply' and was incorrectly instantiated in scope 'B' instead of within scope ''.
cpp_nested_template.i:18: Warning 324: Named nested template instantiations not supported. Processing as if no name was given to %template().

View file

@ -0,0 +1,57 @@
%module xxx
namespace std {
template<typename T> class vector {};
}
struct S1 {};
struct S2 {};
struct S3 {};
struct S4 {};
struct S5 {};
struct S6 {};
struct S7 {};
// valid
namespace std {
%template(vi1) vector<S1>;
template class vector<S1>;
}
// valid
using namespace std;
%template(vi2) vector<S2>;
template class vector<S2>;
// valid
using std::vector;
%template(vi3) vector<S3>;
template class vector<S3>;
// ill-formed
namespace unrelated {
using std::vector;
%template(vi4) vector<S4>;
template class vector<S4>;
}
// ill-formed
namespace unrelated {
using namespace std;
%template(vi5) vector<S5>;
template class vector<S5>;
}
// ill-formed
namespace unrelated {
namespace std {
%template(vi6) vector<S6>;
template class vector<S6>;
}
}
// ill-formed
namespace unrelated {
%template(vi7) std::vector<S7>;
template class std::vector<S7>;
}

View file

@ -0,0 +1,11 @@
cpp_template_scope.i:18: Warning 320: Explicit template instantiation ignored.
cpp_template_scope.i:24: Warning 320: Explicit template instantiation ignored.
cpp_template_scope.i:29: Warning 320: Explicit template instantiation ignored.
cpp_template_scope.i:34: Error: 'vector' resolves to 'std::vector' and was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.
cpp_template_scope.i:35: Warning 320: Explicit template instantiation ignored.
cpp_template_scope.i:41: Error: 'vector' resolves to 'std::vector' and was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.
cpp_template_scope.i:42: Warning 320: Explicit template instantiation ignored.
cpp_template_scope.i:48: Error: 'vector' resolves to 'std::vector' and was incorrectly instantiated in scope 'unrelated::std' instead of within scope 'std'.
cpp_template_scope.i:49: Warning 320: Explicit template instantiation ignored.
cpp_template_scope.i:55: Error: 'std::vector' resolves to 'std::vector' and was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.
cpp_template_scope.i:56: Warning 320: Explicit template instantiation ignored.

View file

@ -0,0 +1,59 @@
import class_scope_namespace.*;
public class class_scope_namespace_runme {
static {
try {
System.loadLibrary("class_scope_namespace");
} 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[])
{
A a = new A();
B b = new B();
C c = new C();
D d = new D();
E e = new E();
F f = new F();
G g = new G();
H.HH h = new H.HH();
I.II i = new I.II();
J j = new J();
K k = new K();
L l = new L();
M m = new M();
a.aa(a, a, a);
b.bb(b, b);
c.cc(c, c);
d.dd(d, d, d);
e.ee(e, e, e);
f.ff(f, f, f, f);
g.gg(g, g);
h.hh(h);
i.ii(i, i);
j.jj(j, j, j);
k.kk(k, k, k);
l.ll(l, l, l);
m.mm(m, m, m);
class_scope_namespace.aaa(a, a, a);
class_scope_namespace.bbb(b, b);
class_scope_namespace.ccc(c, c);
class_scope_namespace.ddd(d, d, d);
class_scope_namespace.eee(e, e, e);
class_scope_namespace.fff(f, f, f, f);
class_scope_namespace.ggg(g, g);
class_scope_namespace.hhh(h);
class_scope_namespace.iii(i, i);
class_scope_namespace.jjj(j, j, j);
class_scope_namespace.kkk(k, k, k);
class_scope_namespace.lll(l, l, l);
class_scope_namespace.mmm(m, m, m);
}
}

View file

@ -0,0 +1,19 @@
import cpp11_template_typedefs.*;
public class cpp11_template_typedefs_runme {
static {
try {
System.loadLibrary("cpp11_template_typedefs");
} 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[]) {
int alloc1 = cpp11_template_typedefs.get_bucket_allocator1();
int alloc2 = cpp11_template_typedefs.get_bucket_allocator2();
}
}

View file

@ -0,0 +1,26 @@
import namespace_chase.*;
public class namespace_chase_runme {
static {
try {
System.loadLibrary("namespace_chase");
} 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[])
{
Struct1A s1a = new Struct1A();
Struct1B s1b = new Struct1B();
Struct1C s1c = new Struct1C();
namespace_chase.sss3a(s1a, s1b, s1c);
namespace_chase.sss3b(s1a, s1b, s1c);
// needs fixing
// namespace_chase.sss3c(s1a, s1b, s1c);
}
}

View file

@ -0,0 +1,32 @@
import namespace_template.*;
public class namespace_template_runme {
static {
try {
System.loadLibrary("namespace_template");
} 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[]) {
vectorchar vc = new vectorchar();
vectorshort vs = new vectorshort();
vectorint vi = new vectorint();
vectorlong vl = new vectorlong();
vc.blah((char)10);
vs.blah((short)10);
vi.blah(10);
vl.blah(10);
vc.vectoruse(vc, vc);
vs.vectoruse(vs, vs);
vi.vectoruse(vi, vi);
vl.vectoruse(vl, vl);
}
}

View file

@ -0,0 +1,75 @@
import template_parameters_global_scope.*;
public class template_parameters_global_scope_runme {
static {
try {
System.loadLibrary("template_parameters_global_scope");
} 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[]) {
int alloc = 0;
// Check 1
alloc = template_parameters_global_scope.Bucket1();
alloc = template_parameters_global_scope.Bucket2();
alloc = template_parameters_global_scope.Bucket3();
alloc = template_parameters_global_scope.Bucket4();
alloc = template_parameters_global_scope.Bucket5();
alloc = template_parameters_global_scope.Bucket6();
// Check 2
alloc = template_parameters_global_scope.Spade1();
alloc = template_parameters_global_scope.Spade2();
alloc = template_parameters_global_scope.Spade3();
alloc = template_parameters_global_scope.Spade4();
alloc = template_parameters_global_scope.Spade5();
alloc = template_parameters_global_scope.Spade6();
// Check 3
alloc = template_parameters_global_scope.Ball1();
alloc = template_parameters_global_scope.Ball2();
alloc = template_parameters_global_scope.Ball3();
alloc = template_parameters_global_scope.Ball4();
alloc = template_parameters_global_scope.Ball5();
alloc = template_parameters_global_scope.Ball6();
// Check 4
alloc = template_parameters_global_scope.Bat1();
alloc = template_parameters_global_scope.Bat2();
alloc = template_parameters_global_scope.Bat3();
alloc = template_parameters_global_scope.Bat4();
alloc = template_parameters_global_scope.Bat5();
alloc = template_parameters_global_scope.Bat6();
// Check 5
alloc = template_parameters_global_scope.Chair1();
alloc = template_parameters_global_scope.Chair2();
alloc = template_parameters_global_scope.Chair3();
alloc = template_parameters_global_scope.Chair4();
alloc = template_parameters_global_scope.Chair5();
alloc = template_parameters_global_scope.Chair6();
// Check 6
alloc = template_parameters_global_scope.Table1();
alloc = template_parameters_global_scope.Table2();
alloc = template_parameters_global_scope.Table3();
alloc = template_parameters_global_scope.Table4();
alloc = template_parameters_global_scope.Table5();
alloc = template_parameters_global_scope.Table6();
/*
alloc = template_parameters_global_scope.rejig1();
alloc = template_parameters_global_scope.rejig2();
alloc = template_parameters_global_scope.rejig3();
alloc = template_parameters_global_scope.rejig4();
alloc = template_parameters_global_scope.rejig5();
alloc = template_parameters_global_scope.rejig6();
*/
}
}

View file

@ -19,32 +19,32 @@ public class template_using_directive_and_declaration_forward_runme {
template_using_directive_and_declaration_forward.useit1b(new Thing1Int());
template_using_directive_and_declaration_forward.useit1c(new Thing1Int());
//BROKEN template_using_directive_and_declaration_forward.useit2(new Thing2Int());
template_using_directive_and_declaration_forward.useit2(new Thing2Int());
template_using_directive_and_declaration_forward.useit2a(new Thing2Int());
template_using_directive_and_declaration_forward.useit2b(new Thing2Int());
template_using_directive_and_declaration_forward.useit2c(new Thing2Int());
template_using_directive_and_declaration_forward.useit2d(new Thing2Int());
//BROKEN template_using_directive_and_declaration_forward.useit3(new Thing3Int());
template_using_directive_and_declaration_forward.useit3(new Thing3Int());
template_using_directive_and_declaration_forward.useit3a(new Thing3Int());
template_using_directive_and_declaration_forward.useit3b(new Thing3Int());
template_using_directive_and_declaration_forward.useit3c(new Thing3Int());
template_using_directive_and_declaration_forward.useit3d(new Thing3Int());
//BROKEN template_using_directive_and_declaration_forward.useit4(new Thing4Int());
template_using_directive_and_declaration_forward.useit4(new Thing4Int());
template_using_directive_and_declaration_forward.useit4a(new Thing4Int());
template_using_directive_and_declaration_forward.useit4b(new Thing4Int());
template_using_directive_and_declaration_forward.useit4c(new Thing4Int());
template_using_directive_and_declaration_forward.useit4d(new Thing4Int());
//BROKEN template_using_directive_and_declaration_forward.useit5(new Thing5Int());
template_using_directive_and_declaration_forward.useit5(new Thing5Int());
template_using_directive_and_declaration_forward.useit5a(new Thing5Int());
template_using_directive_and_declaration_forward.useit5b(new Thing5Int());
template_using_directive_and_declaration_forward.useit5c(new Thing5Int());
template_using_directive_and_declaration_forward.useit5d(new Thing5Int());
//BROKEN template_using_directive_and_declaration_forward.useit7(new Thing7Int());
template_using_directive_and_declaration_forward.useit7(new Thing7Int());
template_using_directive_and_declaration_forward.useit7a(new Thing7Int());
template_using_directive_and_declaration_forward.useit7b(new Thing7Int());
template_using_directive_and_declaration_forward.useit7c(new Thing7Int());

View file

@ -0,0 +1,31 @@
import template_using_directive_typedef.*;
public class template_using_directive_typedef_runme {
static {
try {
System.loadLibrary("template_using_directive_typedef");
} 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[]) {
Vector_Obj vo = new Vector_Obj();
Holder h = new Holder();
h.holder_use1(vo, vo, vo);
h.holder_use2(vo, vo, vo);
h.holder_use3(vo, vo, vo);
template_using_directive_typedef.tns_holder_use(vo, vo);
template_using_directive_typedef.tns_use(vo, vo, vo);
template_using_directive_typedef.global_holder_use(vo);
template_using_directive_typedef.global_use(vo, vo, vo);
template_using_directive_typedef.ns1_holder_use(vo);
template_using_directive_typedef.ns2_holder_use(vo, vo, vo, vo);
}
}

View file

@ -0,0 +1,36 @@
%module namespace_chase
%inline %{
namespace Space1A {
struct Struct1A {};
namespace Space1B {
struct Struct1B {};
namespace Space1C {
struct Struct1C {};
}
}
}
namespace Space2A {
using namespace Space1A;
namespace Space2B {
using namespace Space1B;
namespace Space2C {
using namespace Space1C;
}
}
}
namespace Space3 {
using namespace Space2A;
void sss3a(Space1A::Struct1A, Space1A::Space1B::Struct1B, Space1A::Space1B::Space1C::Struct1C) {}
void sss3b(Struct1A, Space1B::Struct1B, Space1B::Space1C::Struct1C) {}
// To fix: the last two parameters below fail and result in SWIGTYPE_ types instead of proxy classes
void sss3c(Space2A::Struct1A, Space2A::Space1B::Struct1B, Space2A::Space1B::Space1C::Struct1C) {}
}
namespace Space4 {
using namespace Space2A;
using namespace Space2A::Space2B;
using namespace Space2A::Space2B::Space2C;
void sss4a(Struct1A, Struct1B, Space2C::Struct1C) {}
void sss4b(Struct1A, Struct1B, Struct1C) {}
}
%}

View file

@ -2,10 +2,10 @@
%module namespace_template
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector<int>; /* Ruby, wrong class name */
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test2::vector<short>; /* Ruby, wrong class name */
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test3::vector<long>; /* Ruby, wrong class name */
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector<test4::Integer>; /* Ruby, wrong class name */
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test::vector<int>; /* Ruby, wrong class name */
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test::vector<short>; /* Ruby, wrong class name */
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test::vector<long>; /* Ruby, wrong class name */
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test::vector<test::Char>; /* Ruby, wrong class name */
%{
#ifdef max
@ -23,20 +23,9 @@ namespace test {
char * blah(T x) {
return (char *) "vector::blah";
}
void vectoruse(vector<T> a, test::vector<T> b) {}
};
}
namespace test2 {
using namespace test;
}
namespace test3 {
using test::max;
using test::vector;
}
using namespace test2;
namespace T4 = test;
%}
namespace test {
@ -48,6 +37,7 @@ namespace test {
char * blah(T x) {
return (char *) "vector::blah";
}
void vectoruse(vector<T> a, test::vector<T> b) {}
};
}
@ -55,30 +45,26 @@ using namespace test;
%template(maxint) max<int>;
%template(vectorint) vector<int>;
namespace test2 {
using namespace test;
namespace test {
%template(maxshort) max<short>;
%template(vectorshort) vector<short>;
}
namespace test3 {
using test::max;
using test::vector;
namespace test {
%template(maxlong) max<long>;
%template(vectorlong) vector<long>;
}
%inline %{
namespace test4 {
using namespace test;
typedef int Integer;
namespace test {
typedef char Char;
}
%}
namespace test4 {
%template(maxInteger) max<Integer>;
%template(vectorInteger) vector<Integer>;
namespace test {
%template(maxchar) max<Char>;
%template(vectorchar) vector<Char>;
}

View file

@ -0,0 +1,15 @@
import template_using_directive_typedef
vo = template_using_directive_typedef.Vector_Obj();
h = template_using_directive_typedef.Holder();
h.holder_use1(vo, vo, vo);
h.holder_use2(vo, vo, vo);
h.holder_use3(vo, vo, vo);
template_using_directive_typedef.tns_holder_use(vo, vo);
template_using_directive_typedef.tns_use(vo, vo, vo);
template_using_directive_typedef.global_holder_use(vo);
template_using_directive_typedef.global_use(vo, vo, vo);
template_using_directive_typedef.ns1_holder_use(vo);
template_using_directive_typedef.ns2_holder_use(vo, vo, vo, vo);

View file

@ -0,0 +1,32 @@
from typemap_template_typedef import *
def check(got, expected):
if got != expected:
raise RuntimeError("got: " + str(got) + " expected: " + str(expected))
x = XXXInt()
check(x.aa1(0), 0)
check(x.aa2(0), 55)
check(x.aa3(0), 0)
check(aa1(0), 0)
check(aa2(0), 0)
check(x.bb1(0), 0)
check(x.bb2(0), 66)
check(x.bb3(0), 0)
check(bb1(0), 0)
check(bb2(0), 0)
check(x.cc1(0), 0)
check(x.cc2(0), 77)
check(x.cc3(0), 77)
check(cc1(0), 0)
check(cc2(0), 0)
check(x.dd1(0), 0)
check(x.dd2(0), 88)
check(x.dd3(0), 0)
check(dd1(0), 0)
check(dd2(0), 0)

View file

@ -49,11 +49,6 @@ namespace one
};
}
%define PTR_DEF(o)
typedef one::Ptr<o> o ## _ptr;
%template(o ## _ptr) one::Ptr<o>;
%enddef
namespace one
{
class Obj1
@ -63,7 +58,8 @@ namespace one
void donothing() {}
};
PTR_DEF(Obj1)
typedef one::Ptr<Obj1> Obj1_ptr;
%template(Obj1_ptr) one::Ptr<Obj1>;
}
namespace two
@ -75,6 +71,9 @@ namespace two
void donothing() {}
};
PTR_DEF(Obj2)
typedef one::Ptr<Obj2> Obj2_ptr;
}
using two::Obj2;
%template(Obj2_ptr) one::Ptr<Obj2>;

View file

@ -1,25 +1,30 @@
#pragma SWIG nowarn=SWIGWARN_PARSE_NESTED_TEMPLATE
%module template_nested_typemaps
// Testing that the typemaps invoked within a class via %template are picked up by appropriate methods
#pragma SWIG nowarn=SWIGWARN_PARSE_NAMED_NESTED_CLASS
template <typename T> struct Typemap {
%typemap(in) T {
$1 = -99;
}
};
template <> struct Typemap<short> { // Note explicit specialization
%typemap(in) short {
$1 = -77;
}
};
// Testing that the typemaps invoked within a class via %template are picked up by appropriate methods
// Only for languages that support nested classes
%inline %{
int globalInt1(int s) { return s; }
short globalShort1(short s) { return s; }
template <typename T> struct Breeze {
template <typename TMT> struct Typemap {
#ifdef SWIG
%typemap(in) TMT {
$1 = -99;
}
#endif
};
template <typename TMT> struct TypemapShort {
#ifdef SWIG
%typemap(in) short {
$1 = -77;
}
#endif
};
int methodInt1(int s) { return s; }
#if defined(SWIG)
%template() Typemap<int>;
@ -29,7 +34,7 @@ template <typename T> struct Breeze {
short methodShort1(short s) { return s; }
#if defined(SWIG)
%template(TypemapShort) Typemap<short>; // should issue warning SWIGWARN_PARSE_NESTED_TEMPLATE
%template() TypemapShort<short>;
#endif
short methodShort2(short s) { return s; } // should pick up the typemap within Typemap<short>
};

View file

@ -0,0 +1,133 @@
%module template_parameters_global_scope
%inline %{
namespace Alloc {
template<typename T> struct Rebind {
typedef int Integer;
};
}
%}
%inline %{
struct Bucket_ {};
typedef Bucket_ TDBucket;
typedef ::Bucket_ TDGlobalBucket;
%}
// Check 1: %template no unary scope operator
%template(RebindBucket) Alloc::Rebind< Bucket_ >;
%inline %{
Alloc::Rebind< Bucket_ >::Integer Bucket1() { return 1; }
Alloc::Rebind< ::Bucket_ >::Integer Bucket2() { return 2; }
Alloc::Rebind< TDBucket >::Integer Bucket3() { return 3; }
Alloc::Rebind< ::TDBucket >::Integer Bucket4() { return 4; }
Alloc::Rebind< TDGlobalBucket >::Integer Bucket5() { return 5; }
Alloc::Rebind< ::TDGlobalBucket >::Integer Bucket6() { return 6; }
%}
// Check 2: %template with unary scope operator
%inline %{
struct Spade {};
typedef Spade TDSpade;
typedef ::Spade TDGlobalSpade;
%}
%template(RebindSpade) Alloc::Rebind< ::Spade >;
%inline %{
Alloc::Rebind< Spade >::Integer Spade1() { return 1; }
Alloc::Rebind< ::Spade >::Integer Spade2() { return 2; }
Alloc::Rebind< TDSpade >::Integer Spade3() { return 3; }
Alloc::Rebind< ::TDSpade >::Integer Spade4() { return 4; }
Alloc::Rebind< TDGlobalSpade >::Integer Spade5() { return 5; }
Alloc::Rebind< ::TDGlobalSpade >::Integer Spade6() { return 6; }
%}
// Check 3: %template typedef no unary scope operator
%inline %{
struct Ball {};
typedef Ball TDBall;
typedef ::Ball TDGlobalBall;
%}
%template(RebindBall) Alloc::Rebind< TDBall >;
%inline %{
Alloc::Rebind< Ball >::Integer Ball1() { return 1; }
Alloc::Rebind< ::Ball >::Integer Ball2() { return 2; }
Alloc::Rebind< TDBall >::Integer Ball3() { return 3; }
Alloc::Rebind< ::TDBall >::Integer Ball4() { return 4; }
Alloc::Rebind< TDGlobalBall >::Integer Ball5() { return 5; }
Alloc::Rebind< ::TDGlobalBall >::Integer Ball6() { return 6; }
%}
// Check 4: %template typedef with unary scope operator
%inline %{
struct Bat {};
typedef Bat TDBat;
typedef ::Bat TDGlobalBat;
%}
%template(RebindBat) Alloc::Rebind< ::TDBat >;
%inline %{
Alloc::Rebind< Bat >::Integer Bat1() { return 1; }
Alloc::Rebind< ::Bat >::Integer Bat2() { return 2; }
Alloc::Rebind< TDBat >::Integer Bat3() { return 3; }
Alloc::Rebind< ::TDBat >::Integer Bat4() { return 4; }
Alloc::Rebind< TDGlobalBat >::Integer Bat5() { return 5; }
Alloc::Rebind< ::TDGlobalBat >::Integer Bat6() { return 6; }
%}
// Check 5: %template double typedef no unary scope operator
%inline %{
struct Chair {};
typedef Chair TDChair;
typedef ::Chair TDGlobalChair;
%}
%template(RebindChair) Alloc::Rebind< TDGlobalChair >;
%inline %{
Alloc::Rebind< Chair >::Integer Chair1() { return 1; }
Alloc::Rebind< ::Chair >::Integer Chair2() { return 2; }
Alloc::Rebind< TDChair >::Integer Chair3() { return 3; }
Alloc::Rebind< ::TDChair >::Integer Chair4() { return 4; }
Alloc::Rebind< TDGlobalChair >::Integer Chair5() { return 5; }
Alloc::Rebind< ::TDGlobalChair >::Integer Chair6() { return 6; }
%}
// Check 6: %template double typedef with unary scope operator
%inline %{
struct Table {};
typedef Table TDTable;
typedef ::Table TDGlobalTable;
%}
%template(RebindTable) Alloc::Rebind< ::TDGlobalTable >;
%inline %{
Alloc::Rebind< Table >::Integer Table1() { return 1; }
Alloc::Rebind< ::Table >::Integer Table2() { return 2; }
Alloc::Rebind< TDTable >::Integer Table3() { return 3; }
Alloc::Rebind< ::TDTable >::Integer Table4() { return 4; }
Alloc::Rebind< TDGlobalTable >::Integer Table5() { return 5; }
Alloc::Rebind< ::TDGlobalTable >::Integer Table6() { return 6; }
%}
#if 0
%inline %{
namespace Alloc {
template<typename T=::Spade/*, typename T2=TDSpade, typename T3=::TDSpade, typename T4=TDGlobalSpade, typename T5=::TDGlobalSpade*/> struct Rejig {
typedef int Integer;
};
}
%}
%template(RejigSpade) Alloc::Rejig<::Spade>;
%inline %{
Alloc::Rejig<>::Integer rejig1() { return 1; }
Alloc::Rejig< ::Spade >::Integer rejig2() { return 2; }
Alloc::Rejig< ::TDSpade >::Integer rejig3() { return 3; }
Alloc::Rejig< ::TDSpade >::Integer rejig4() { return 4; }
Alloc::Rejig< TDGlobalSpade >::Integer rejig5() { return 5; }
Alloc::Rejig< ::TDGlobalSpade >::Integer rejig6() { return 6; }
%}
#endif

View file

@ -32,7 +32,7 @@ namespace One {
%template(H) One::OneParm<int **>;
// %template scope explicit specializations
namespace ONE {
namespace One {
%template(I) One::OneParm<float>;
%template(J) ::One::OneParm<float *>;
}
@ -42,7 +42,7 @@ namespace One {
}
// %template scope partial specializations
namespace ONE {
namespace One {
%template(BB) One::OneParm<bool *>;
%template(BBB) ::One::OneParm<char *>;
}

View file

@ -59,7 +59,7 @@ namespace One {
%template(H) One::OneParm<TypeDef::IntPtrPtr>;
// %template scope explicit specializations
namespace ONE {
namespace One {
%template(I) One::OneParm<TypeDef::Float>;
%template(J) ::One::OneParm<TypeDef::FloatPtr>;
}
@ -69,7 +69,7 @@ namespace One {
}
// %template scope partial specializations
namespace ONE {
namespace One {
%template(BB) One::OneParm<TypeDef::BoolPtr>;
%template(BBB) ::One::OneParm<TypeDef::CharPtr>;
}

View file

@ -0,0 +1,66 @@
%module typemap_template_typedef
//%module("templatereduce") typemap_template_typedef
%typemap(in) int TMAP55 %{ $1 = 55; /* int TMAP55 typemap */ %}
%typemap(in) int TMAP66 %{ $1 = 66; /* int TMAP66 typemap */ %}
%typemap(in) int TMAP77 %{ $1 = 77; /* int TMAP77 typemap */ %}
%typemap(in) int TMAP88 %{ $1 = 88; /* int TMAP88 typemap */ %}
%apply int TMAP77 { XXX<int>::Long cc }
%inline %{
typedef int Integer;
template<typename T> struct XXX {
#ifdef SWIG
// In swig-3.0.12 'Long aa' was actually stored as 'long aa' in typemap table instead of 'XXX<int>::Long aa'
%apply int TMAP55 { Long aa }
%apply int TMAP66 { XXX<int>::Long bb }
%apply int TMAP88 { XXX<Integer>::Long dd }
#endif
typedef long Long;
long aa1(long aa) { return aa; }
long aa2(Long aa) { return aa; }
long bb1(long bb) { return bb; }
long bb2(Long bb) { return bb; }
long cc1(long cc) { return cc; }
long cc2(Long cc) { return cc; }
long dd1(long dd) { return dd; }
long dd2(Long dd) { return dd; }
#ifdef SWIG
%clear Long aa;
%clear XXX<int>::Long bb;
%clear XXX<Integer>::Long dd;
#endif
long aa3(Long aa) { return aa; }
long bb3(Long bb) { return bb; }
long cc3(Long cc) { return cc; }
long dd3(Long dd) { return dd; }
};
%}
%template(XXXInt) XXX<Integer>;
%clear XXX<int>::Long cc;
%inline %{
long aa1(XXX<int>::Long aa) { return aa; }
long aa2(long aa) { return aa; }
long bb1(XXX<int>::Long bb) { return bb; }
long bb2(long bb) { return bb; }
long cc1(XXX<int>::Long cc) { return cc; }
long cc2(long cc) { return cc; }
long dd1(XXX<Integer>::Long dd) { return dd; }
long dd2(long dd) { return dd; }
%}
%inline %{
typedef Integer INTEGER;
template<typename T1, typename T2 = INTEGER> struct YYY {
void meff(T1 t1, T2 t2) {}
};
%}
%template(YYYIntInt) YYY<INTEGER>;
%inline %{
void whyohwhy(YYY<INTEGER> yy) {}
%}