Recover original types in template expansions.
Added the module option "tpltreduc" to force Swig to reduce all the typedef found in a template, usually as a compiler will do. This allows swig to parse very ugly template + typedef code, but it can prevent some typemaps for working. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6527 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
0b2cb3849f
commit
cf7b11c3fd
4 changed files with 55 additions and 23 deletions
|
|
@ -1,5 +1,8 @@
|
||||||
|
#ifdef SWIGPYTHON
|
||||||
|
%module("tpltreduc") template_typedef
|
||||||
|
#else
|
||||||
%module template_typedef
|
%module template_typedef
|
||||||
|
#endif
|
||||||
//
|
//
|
||||||
// Change this to #if 1 to test the 'test'
|
// Change this to #if 1 to test the 'test'
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,13 @@
|
||||||
%module template_typedef_ptr
|
%module("tpltreduc") template_typedef_ptr
|
||||||
|
|
||||||
|
/*
|
||||||
|
Use the "tpltreduc" to force swig to reduce the temaplate
|
||||||
|
typedef as much as possible.
|
||||||
|
|
||||||
|
This fix cases like this one, but it can prevent some
|
||||||
|
typemaps for working.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
struct C{};
|
struct C{};
|
||||||
|
|
@ -13,7 +22,7 @@
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class A, class B>
|
template <class A, class B>
|
||||||
struct Test<A, B*>
|
struct Test<A, B*>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,33 @@
|
||||||
%module template_typemap
|
%module template_typemap
|
||||||
|
|
||||||
|
|
||||||
%typemap(in) Integer
|
%typemap(in) Integer1
|
||||||
{
|
{
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(out) Integer
|
%typemap(out) Integer1
|
||||||
|
{
|
||||||
|
/* do nothing */
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(in) Integer2
|
||||||
|
{
|
||||||
|
/* do nothing */
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) Integer2
|
||||||
{
|
{
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
}
|
}
|
||||||
|
|
||||||
%{
|
%{
|
||||||
typedef int Integer;
|
typedef int Integer1;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
typedef int Integer2;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct Foo
|
struct Foo
|
||||||
|
|
@ -35,8 +46,8 @@
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%template(Foo_i) Foo<int>;
|
%template(Foo_I1) Foo<Integer1>;
|
||||||
%template(Foo_I) Foo<Integer>;
|
%template(Foo_I2) Foo<Integer2>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ static Parm *template_parameters = 0;
|
||||||
static int extendmode = 0;
|
static int extendmode = 0;
|
||||||
static int dirprot_mode = 0;
|
static int dirprot_mode = 0;
|
||||||
static int compact_default_args = 0;
|
static int compact_default_args = 0;
|
||||||
|
static int template_typedef_reduction = 0;
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Assist Functions
|
* Assist Functions
|
||||||
|
|
@ -1614,14 +1615,19 @@ insert_directive : HBLOCK {
|
||||||
module_directive: MODULE options idstring {
|
module_directive: MODULE options idstring {
|
||||||
$$ = new_node("module");
|
$$ = new_node("module");
|
||||||
Setattr($$,"name",$3);
|
Setattr($$,"name",$3);
|
||||||
if ($2) Setattr($$,"options",$2);
|
if ($2) {
|
||||||
if ($2 && Getattr($2,"directors")) {
|
Setattr($$,"options",$2);
|
||||||
/*
|
if (Getattr($2,"directors")) {
|
||||||
we set dirprot_mode here to 1, just to save the
|
/*
|
||||||
symbols. Later, the language module must decide
|
we set dirprot_mode here to 1, just to save the
|
||||||
what to do with them.
|
symbols. Later, the language module must decide
|
||||||
*/
|
what to do with them.
|
||||||
dirprot_mode = 1;
|
*/
|
||||||
|
dirprot_mode = 1;
|
||||||
|
}
|
||||||
|
if (Getattr($2,"tpltreduc")) {
|
||||||
|
template_typedef_reduction = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!ModuleName) ModuleName = NewString($3);
|
if (!ModuleName) ModuleName = NewString($3);
|
||||||
if (!module_node) module_node = $$;
|
if (!module_node) module_node = $$;
|
||||||
|
|
@ -2128,16 +2134,19 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
|
||||||
if (!value) {
|
if (!value) {
|
||||||
SwigType *ty = Getattr(p,"type");
|
SwigType *ty = Getattr(p,"type");
|
||||||
if (ty) {
|
if (ty) {
|
||||||
SwigType *rty = Swig_symbol_typedef_reduce(ty,0);
|
if (template_typedef_reduction) {
|
||||||
ty = Swig_symbol_type_qualify(rty,0);
|
SwigType *rty = Swig_symbol_typedef_reduce(ty,0);
|
||||||
Setattr(p,"type",ty);
|
ty = Swig_symbol_type_qualify(rty,0);
|
||||||
Delete(rty);
|
Setattr(p,"type",ty);
|
||||||
|
Delete(rty);
|
||||||
|
} else {
|
||||||
|
ty = Swig_symbol_type_qualify(ty,0);
|
||||||
|
Setattr(p,"type",ty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SwigType *rty = Swig_symbol_typedef_reduce(value,0);
|
value = Swig_symbol_type_qualify(value,0);
|
||||||
value = Swig_symbol_type_qualify(rty,0);
|
|
||||||
Setattr(p,"value",value);
|
Setattr(p,"value",value);
|
||||||
Delete(rty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p = nextSibling(p);
|
p = nextSibling(p);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue