From f15126aee33ad19bde50229c2a1801c51e34619d Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Thu, 28 Oct 2004 23:49:41 +0000 Subject: [PATCH] add templatereduce option git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6543 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 49 +++++++++++++++++++++++++++++++++++++++++ Source/CParse/cparse.h | 1 + Source/CParse/parser.y | 4 ++++ Source/Modules/main.cxx | 4 ++++ 4 files changed, 58 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index e573dfdb6..5108a67a9 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,55 @@ Version 1.3.23 (in progress) ============================ + +10/28/2004:mmatus + - Added module and swig option "templatereduce" to force swig + to reduce any type needed with templates, ie, in these cases + + %module("templatereduce") test + + template struct A { }; + + typedef int Int; + %template(A_Int) A ==> %template(A_Int) A + + typedef B* Bp; + %template(A_Bp) A ==> %template(A_Bp) A + + swig reduces the types Int and Bp to their primitives + int and B*. This is closer to the usual compiler + resolution mechanism, and it is really needed sometimes + when you mix templates + typedefs + specializations. + + Don't use it if you don't have any problem already, + since the type reduction can interfere with some + user typemaps, specially if you defined something like + + typedef int Int; + %typemap(in) Int ...; + + in this case, when you use the "templatereduce" option, + swig will ignore the user typemap, since the "typedef int Int" + will take precedence, and the usual "int" typemap will be + applied. + + Note that the previous case is not common, and should be + avoided, ie, is not recommended to use a typedef and a + typemap at the same time, specially if you are going to + use templates + specializations. + + - Directors: + + virtual destructor is always emitted now, this doesn't + cause any harm, and could solve some nasty and + mysterious errors, like the one mentioned by Scott. + + also the destructor is not in-lined, so, that can solve + some other mysterious errors when mixing directors + + imports + embedded applications + some specific compilers. + + + 10/27/2004: wsfulton [C#] typemaps.i library file with INPUT, OUTPUT and INOUT typemaps added. diff --git a/Source/CParse/cparse.h b/Source/CParse/cparse.h index 43170e6bf..fdc997056 100644 --- a/Source/CParse/cparse.h +++ b/Source/CParse/cparse.h @@ -45,6 +45,7 @@ extern SwigType *Swig_cparse_type(String *); extern Node *Swig_cparse(File *); extern Hash *Swig_cparse_features(); extern void SWIG_cparse_set_compact_default_args(int defargs); +extern void SWIG_cparse_template_reduce(int treduce); /* util.c */ extern void Swig_cparse_replace_descriptor(String *s); diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 383257918..876fd8e38 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -171,6 +171,10 @@ void SWIG_cparse_set_compact_default_args(int defargs) { compact_default_args = defargs; } +void SWIG_cparse_template_reduce(int treduce) { + template_reduce = treduce; +} + /* ----------------------------------------------------------------------------- * Assist functions * ----------------------------------------------------------------------------- */ diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index c4fa7f5cd..6a31778de 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -83,6 +83,7 @@ static const char *usage2 = (const char*)"\ -outdir - Set language specific files output directory\n\ -small - Compile in virtual elimination & compact mode\n\ -swiglib - Report location of SWIG library and exit\n\ + -templatereduce - Swig reduce all the typedefs in templates \n\ -v - Run in verbose mode\n\ -version - Print SWIG version number\n\ -Wall - Enable all warning messages\n\ @@ -332,6 +333,9 @@ void SWIG_getoptions(int argc, char *argv[]) } else if (strcmp(argv[i],"-show_templates") == 0) { Swig_cparse_debug_templates(1); Swig_mark_arg(i); + } else if (strcmp(argv[i],"-templatereduce") == 0) { + SWIG_cparse_template_reduce(1); + Swig_mark_arg(i); } else if (strcmp(argv[i],"-swiglib") == 0) { printf("%s\n", LibDir); SWIG_exit (EXIT_SUCCESS);