Fix scope lookup for template parameters containing unary scope operators

Fixes cases like:

namespace Alloc {
  template<typename T> struct Rebind {
    typedef int Integer;
  };
}
%template(RebindBucket) Alloc::Rebind< Bucket >;
OR
%template(RebindBucket) Alloc::Rebind< ::Bucket >;

Alloc::Rebind< Bucket >::Integer Bucket1() { return 1; }
Alloc::Rebind< ::Bucket >::Integer Bucket2() { return 2; }
Alloc::Rebind<::template TemplateBucket<double>>::Integer Bucket3() { return 3; };
This commit is contained in:
William S Fulton 2017-07-22 13:17:23 +01:00
commit 26e14c4f18
5 changed files with 260 additions and 6 deletions

View file

@ -444,6 +444,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,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,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

@ -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