Fix 1832613 - template function pointer typedefs

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10195 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2007-12-16 20:55:43 +00:00
commit da509bd641
4 changed files with 80 additions and 18 deletions

View file

@ -1,6 +1,9 @@
Version 1.3.34 (in progress) Version 1.3.34 (in progress)
============================ ============================
12/16/2007: wsfulton
Fix #1832613 - Templates and some typedefs involving pointers or function pointers
12/12/2007: wsfulton 12/12/2007: wsfulton
[Java] Fix #1632625 - Compilation errors on Visual C++ 6 when using directors. [Java] Fix #1632625 - Compilation errors on Visual C++ 6 when using directors.

View file

@ -307,6 +307,7 @@ CPP_TEST_CASES += \
template_typedef_cplx3 \ template_typedef_cplx3 \
template_typedef_cplx4 \ template_typedef_cplx4 \
template_typedef_cplx5 \ template_typedef_cplx5 \
template_typedef_funcptr \
template_typedef_ns \ template_typedef_ns \
template_typedef_ptr \ template_typedef_ptr \
template_typedef_rec \ template_typedef_rec \

View file

@ -0,0 +1,48 @@
%module template_typedef_funcptr
//Bug #1832613
%include <std_string.i>
%inline %{
#include <string>
template<typename T> class Ptr {};
class MCContract {};
typedef Ptr<MCContract> MCContractPtr;
%}
%template() Ptr<MCContract>;
%inline %{
template <class Contract, typename ContractID, typename CallbackType>
class ContractFactory
{
public:
static ContractFactory<Contract,ContractID,CallbackType> &getInstance() {
static ContractFactory<Contract, ContractID, CallbackType> instance;
return instance;
}
};
/**
* CreateXXContractCallback is a pointer to a function taking no arguments and
* returning a pointer to an XXContract.
*/
typedef MCContractPtr (*CreateMCContractCallback)();
%}
//Get around it by changing this:
%template(MCContractFactory) ContractFactory<MCContract, std::string, CreateMCContractCallback>;
//to a form which expands the typedef:
//%template(MCContractFactory) ContractFactory<MCContract, std::string, Ptr<MCContract>(*)()>;
%inline %{
typedef MCContractPtr* ContractPtrPtr;
%}
// Plain pointers were also causing problems...
%template(MCContractFactory2) ContractFactory<MCContract, std::string, ContractPtrPtr>;

View file

@ -974,10 +974,6 @@ static Node *symbol_lookup_qualified(String_or_char *name, Symtab *symtab, Strin
* to get the real node. * to get the real node.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static
SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab);
Node *Swig_symbol_clookup(String_or_char *name, Symtab *n) { Node *Swig_symbol_clookup(String_or_char *name, Symtab *n) {
Hash *hsym = 0; Hash *hsym = 0;
Node *s = 0; Node *s = 0;
@ -1336,11 +1332,7 @@ Node *Swig_symbol_isoverloaded(Node *n) {
* Create a fully qualified type name * Create a fully qualified type name
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static int no_constructor(Node *n) { /* This cache produces problems with OSS, don't active it */
return !Checkattr(n, "nodeType", "constructor");
}
/* This cache produce problems with OSS, don't active it */
/* #define SWIG_TEMPLATE_QUALIFY_CACHE */ /* #define SWIG_TEMPLATE_QUALIFY_CACHE */
static SwigType *Swig_symbol_template_qualify(const SwigType *e, Symtab *st) { static SwigType *Swig_symbol_template_qualify(const SwigType *e, Symtab *st) {
String *tprefix, *tsuffix; String *tprefix, *tsuffix;
@ -1407,6 +1399,10 @@ static SwigType *Swig_symbol_template_qualify(const SwigType *e, Symtab *st) {
} }
static int no_constructor(Node *n) {
return !Checkattr(n, "nodeType", "constructor");
}
SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
List *elements; List *elements;
String *result = NewStringEmpty(); String *result = NewStringEmpty();
@ -1483,15 +1479,22 @@ SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_symbol_typedef_reduce() * Swig_symbol_template_reduce()
* * Resolves template parameter types
* Chase a typedef through symbol tables looking for a match. * For example:
* typedef int Int;
* typedef Int Integer;
* with input:
* Foo<(Int,Integer)>
* returns:
* Foo<(int,int)>
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static static
SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab) { SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab) {
Parm *p; Parm *p;
List *parms = SwigType_parmlist(qt); String *templateargs = SwigType_templateargs(qt);
List *parms = SwigType_parmlist(templateargs);
Iterator pi = First(parms); Iterator pi = First(parms);
String *tprefix = SwigType_templateprefix(qt); String *tprefix = SwigType_templateprefix(qt);
String *tsuffix = SwigType_templatesuffix(qt); String *tsuffix = SwigType_templatesuffix(qt);
@ -1528,10 +1531,17 @@ SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab) {
Delete(parms); Delete(parms);
Delete(tprefix); Delete(tprefix);
Delete(tsuffix); Delete(tsuffix);
Delete(templateargs);
return qprefix; return qprefix;
} }
/* -----------------------------------------------------------------------------
* Swig_symbol_typedef_reduce()
*
* Chase a typedef through symbol tables looking for a match.
* ----------------------------------------------------------------------------- */
SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) { SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) {
SwigType *prefix, *base; SwigType *prefix, *base;
Node *n; Node *n;
@ -1547,14 +1557,14 @@ SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) {
Append(prefix, qt); Append(prefix, qt);
Delete(qt); Delete(qt);
#ifdef SWIG_DEBUG #ifdef SWIG_DEBUG
Printf(stderr, "symbol_reduce %s %s\n", ty, prefix); Printf(stderr, "symbol_reduce (a) %s %s\n", ty, prefix);
#endif #endif
Delete(base); Delete(base);
return prefix; return prefix;
} else { } else {
Delete(prefix); Delete(prefix);
#ifdef SWIG_DEBUG #ifdef SWIG_DEBUG
Printf(stderr, "symbol_reduce %s %s\n", ty, ty); Printf(stderr, "symbol_reduce (b) %s %s\n", ty, ty);
#endif #endif
return Copy(ty); return Copy(ty);
} }
@ -1568,7 +1578,7 @@ SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) {
Delete(base); Delete(base);
Delete(prefix); Delete(prefix);
#ifdef SWIG_DEBUG #ifdef SWIG_DEBUG
Printf(stderr, "symbol_reduce %s %s\n", ty, ty); Printf(stderr, "symbol_reduce (c) %s %s\n", ty, ty);
#endif #endif
return Copy(ty); return Copy(ty);
} }
@ -1612,7 +1622,7 @@ SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) {
Delete(nt); Delete(nt);
Delete(rt); Delete(rt);
#ifdef SWIG_DEBUG #ifdef SWIG_DEBUG
Printf(stderr, "symbol_reduce %s %s\n", qt, ty); Printf(stderr, "symbol_reduce (d) %s %s\n", qt, ty);
#endif #endif
return qt; return qt;
} }
@ -1620,7 +1630,7 @@ SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) {
Delete(base); Delete(base);
Delete(prefix); Delete(prefix);
#ifdef SWIG_DEBUG #ifdef SWIG_DEBUG
Printf(stderr, "symbol_reduce %s %s\n", ty, ty); Printf(stderr, "symbol_reduce (e) %s %s\n", ty, ty);
#endif #endif
return Copy(ty); return Copy(ty);
} }