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:
Marcelo Matus 2004-10-27 01:57:36 +00:00
commit cf7b11c3fd
4 changed files with 55 additions and 23 deletions

View file

@ -1,5 +1,8 @@
#ifdef SWIGPYTHON
%module("tpltreduc") template_typedef
#else
%module template_typedef
#endif
//
// Change this to #if 1 to test the 'test'
//

View file

@ -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 %{
struct C{};
@ -13,7 +22,7 @@
};
template <class A, class B>
struct Test<A, B*>
{

View file

@ -1,22 +1,33 @@
%module template_typemap
%typemap(in) Integer
%typemap(in) Integer1
{
/* do nothing */
}
%typemap(out) Integer
%typemap(out) Integer1
{
/* do nothing */
}
%typemap(in) Integer2
{
/* do nothing */
}
%typemap(out) Integer2
{
/* do nothing */
}
%{
typedef int Integer;
typedef int Integer1;
%}
%inline %{
typedef int Integer2;
template <class T>
struct Foo
@ -35,8 +46,8 @@
};
%}
%template(Foo_i) Foo<int>;
%template(Foo_I) Foo<Integer>;
%template(Foo_I1) Foo<Integer1>;
%template(Foo_I2) Foo<Integer2>;

View file

@ -53,6 +53,7 @@ static Parm *template_parameters = 0;
static int extendmode = 0;
static int dirprot_mode = 0;
static int compact_default_args = 0;
static int template_typedef_reduction = 0;
/* -----------------------------------------------------------------------------
* Assist Functions
@ -1614,14 +1615,19 @@ insert_directive : HBLOCK {
module_directive: MODULE options idstring {
$$ = new_node("module");
Setattr($$,"name",$3);
if ($2) Setattr($$,"options",$2);
if ($2 && Getattr($2,"directors")) {
/*
we set dirprot_mode here to 1, just to save the
symbols. Later, the language module must decide
what to do with them.
*/
dirprot_mode = 1;
if ($2) {
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
what to do with them.
*/
dirprot_mode = 1;
}
if (Getattr($2,"tpltreduc")) {
template_typedef_reduction = 1;
}
}
if (!ModuleName) ModuleName = NewString($3);
if (!module_node) module_node = $$;
@ -2128,16 +2134,19 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
if (!value) {
SwigType *ty = Getattr(p,"type");
if (ty) {
SwigType *rty = Swig_symbol_typedef_reduce(ty,0);
ty = Swig_symbol_type_qualify(rty,0);
Setattr(p,"type",ty);
Delete(rty);
if (template_typedef_reduction) {
SwigType *rty = Swig_symbol_typedef_reduce(ty,0);
ty = Swig_symbol_type_qualify(rty,0);
Setattr(p,"type",ty);
Delete(rty);
} else {
ty = Swig_symbol_type_qualify(ty,0);
Setattr(p,"type",ty);
}
}
} else {
SwigType *rty = Swig_symbol_typedef_reduce(value,0);
value = Swig_symbol_type_qualify(rty,0);
value = Swig_symbol_type_qualify(value,0);
Setattr(p,"value",value);
Delete(rty);
}
p = nextSibling(p);