Fix scoping of forward class declarations nested within a class (for C++). Also fix %template and resolution of template parameters that are typedefs.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12764 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
931536594d
commit
7d038d4bd7
11 changed files with 442 additions and 54 deletions
|
|
@ -539,18 +539,10 @@ class TypePass:private Dispatcher {
|
|||
|
||||
virtual int classforwardDeclaration(Node *n) {
|
||||
|
||||
/* Temporary hack. Can't do inside a class because it breaks
|
||||
C nested structure wrapping */
|
||||
|
||||
/* Can't do inside a C struct because it breaks C nested structure wrapping */
|
||||
if ((!inclass) || (CPlusPlus)) {
|
||||
String *name = Getattr(n, "name");
|
||||
String *nname;
|
||||
SwigType_typedef_class(name);
|
||||
if (nsname) {
|
||||
nname = NewStringf("%s::%s", nsname, name);
|
||||
Setattr(n, "name", nname);
|
||||
}
|
||||
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,6 +223,9 @@ static void symbol_print_symbols(const char *symboltabletype) {
|
|||
while (it.key) {
|
||||
String *symname = it.key;
|
||||
Printf(stdout, " %s\n", symname);
|
||||
/*
|
||||
Printf(stdout, " %s - %p (%s)\n", symname, it.item, Getattr(it.item, "name"));
|
||||
*/
|
||||
it = Next(it);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,9 +91,11 @@ static Hash *get_typemap(int tm_scope, const SwigType *type) {
|
|||
static void set_typemap(int tm_scope, const SwigType *type, Hash *tm) {
|
||||
SwigType *hashtype = 0;
|
||||
if (SwigType_istemplate(type)) {
|
||||
String *ty = Swig_symbol_template_deftype(type, 0);
|
||||
SwigType *rty = SwigType_typedef_resolve_all(type);
|
||||
String *ty = Swig_symbol_template_deftype(rty, 0);
|
||||
String *tyq = Swig_symbol_type_qualify(ty, 0);
|
||||
hashtype = SwigType_remove_global_scope_prefix(tyq);
|
||||
Delete(rty);
|
||||
Delete(tyq);
|
||||
Delete(ty);
|
||||
} else {
|
||||
|
|
@ -2013,12 +2015,13 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper
|
|||
|
||||
void Swig_typemap_debug() {
|
||||
int ts;
|
||||
int nesting_level = 2;
|
||||
Printf(stdout, "---[ typemaps ]--------------------------------------------------------------\n");
|
||||
|
||||
ts = tm_scope;
|
||||
while (ts >= 0) {
|
||||
Printf(stdout, "::: scope %d\n\n", ts);
|
||||
Printf(stdout, "%s\n", typemaps[ts]);
|
||||
Swig_print(typemaps[ts], nesting_level);
|
||||
ts--;
|
||||
}
|
||||
Printf(stdout, "-----------------------------------------------------------------------------\n");
|
||||
|
|
|
|||
|
|
@ -425,8 +425,6 @@ static Typetab *SwigType_find_scope(Typetab *s, const SwigType *nameprefix) {
|
|||
return 0;
|
||||
Setmark(s, 1);
|
||||
|
||||
/* Printf(stdout,"find_scope: %x(%s) '%s'\n", s, Getattr(s,"name"), nameprefix); */
|
||||
|
||||
if (SwigType_istemplate(nameprefix)) {
|
||||
nnameprefix = SwigType_typedef_resolve_all(nameprefix);
|
||||
nameprefix = nnameprefix;
|
||||
|
|
@ -542,6 +540,53 @@ static SwigType *_typedef_resolve(Typetab *s, String *base, int look_parent) {
|
|||
return type;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* template_parameters_resolve()
|
||||
*
|
||||
* For use with templates only. The template parameters are resolved. If none
|
||||
* of the parameters can be resolved, zero is returned.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static String *template_parameters_resolve(const String *base) {
|
||||
List *tparms;
|
||||
String *suffix;
|
||||
String *type;
|
||||
int i, sz;
|
||||
int rep = 0;
|
||||
type = SwigType_templateprefix(base);
|
||||
suffix = SwigType_templatesuffix(base);
|
||||
Append(type, "<(");
|
||||
tparms = SwigType_parmlist(base);
|
||||
sz = Len(tparms);
|
||||
for (i = 0; i < sz; i++) {
|
||||
SwigType *tpr;
|
||||
SwigType *tp = Getitem(tparms, i);
|
||||
if (!rep) {
|
||||
tpr = SwigType_typedef_resolve(tp);
|
||||
} else {
|
||||
tpr = 0;
|
||||
}
|
||||
if (tpr) {
|
||||
Append(type, tpr);
|
||||
Delete(tpr);
|
||||
rep = 1;
|
||||
} else {
|
||||
Append(type, tp);
|
||||
}
|
||||
if ((i + 1) < sz)
|
||||
Append(type, ",");
|
||||
}
|
||||
Append(type, ")>");
|
||||
Append(type, suffix);
|
||||
Delete(suffix);
|
||||
Delete(tparms);
|
||||
if (!rep) {
|
||||
Delete(type);
|
||||
type = 0;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
static SwigType *typedef_resolve(Typetab *s, String *base) {
|
||||
return _typedef_resolve(s, base, 1);
|
||||
}
|
||||
|
|
@ -562,12 +607,6 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
|
|||
String *nameprefix = 0;
|
||||
int newtype = 0;
|
||||
|
||||
/*
|
||||
if (!noscope) {
|
||||
noscope = NewStringEmpty();
|
||||
}
|
||||
*/
|
||||
|
||||
resolved_scope = 0;
|
||||
|
||||
#ifdef SWIG_TYPEDEF_RESOLVE_CACHE
|
||||
|
|
@ -611,6 +650,9 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
|
|||
#endif
|
||||
if (nameprefix) {
|
||||
/* Name had a prefix on it. See if we can locate the proper scope for it */
|
||||
String *rnameprefix = template_parameters_resolve(nameprefix);
|
||||
nameprefix = rnameprefix ? Copy(rnameprefix) : nameprefix;
|
||||
Delete(rnameprefix);
|
||||
s = SwigType_find_scope(s, nameprefix);
|
||||
|
||||
/* Couldn't locate a scope for the type. */
|
||||
|
|
@ -677,42 +719,8 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
|
|||
template arguments one by one to see if they can be resolved. */
|
||||
|
||||
if (!type && SwigType_istemplate(base)) {
|
||||
List *tparms;
|
||||
String *suffix;
|
||||
int i, sz;
|
||||
int rep = 0;
|
||||
type = SwigType_templateprefix(base);
|
||||
newtype = 1;
|
||||
suffix = SwigType_templatesuffix(base);
|
||||
Append(type, "<(");
|
||||
tparms = SwigType_parmlist(base);
|
||||
sz = Len(tparms);
|
||||
for (i = 0; i < sz; i++) {
|
||||
SwigType *tpr;
|
||||
SwigType *tp = Getitem(tparms, i);
|
||||
if (!rep) {
|
||||
tpr = SwigType_typedef_resolve(tp);
|
||||
} else {
|
||||
tpr = 0;
|
||||
}
|
||||
if (tpr) {
|
||||
Append(type, tpr);
|
||||
Delete(tpr);
|
||||
rep = 1;
|
||||
} else {
|
||||
Append(type, tp);
|
||||
}
|
||||
if ((i + 1) < sz)
|
||||
Append(type, ",");
|
||||
}
|
||||
Append(type, ")>");
|
||||
Append(type, suffix);
|
||||
Delete(suffix);
|
||||
Delete(tparms);
|
||||
if (!rep) {
|
||||
Delete(type);
|
||||
type = 0;
|
||||
}
|
||||
type = template_parameters_resolve(base);
|
||||
}
|
||||
if (namebase)
|
||||
Delete(namebase);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue