Merge branch 'vadz-fix-dtor-nested-template'

* vadz-fix-dtor-nested-template:
  Stop mangling dtors of nested classes instead a template class
  Remove unused cparse_template_expand() return type
This commit is contained in:
William S Fulton 2018-12-06 08:13:25 +00:00
commit 45a8c8cfa3

View file

@ -49,32 +49,31 @@ void Swig_cparse_debug_templates(int x) {
* template parameters * template parameters
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static int cparse_template_expand(Node *n, String *tname, String *rname, String *templateargs, List *patchlist, List *typelist, List *cpatchlist) { static void cparse_template_expand(Node *templnode, Node *n, String *tname, String *rname, String *templateargs, List *patchlist, List *typelist, List *cpatchlist) {
static int expanded = 0; static int expanded = 0;
int ret;
String *nodeType; String *nodeType;
if (!n) if (!n)
return 0; return;
nodeType = nodeType(n); nodeType = nodeType(n);
if (Getattr(n, "error")) if (Getattr(n, "error"))
return 0; return;
if (Equal(nodeType, "template")) { if (Equal(nodeType, "template")) {
/* Change the node type back to normal */ /* Change the node type back to normal */
if (!expanded) { if (!expanded) {
expanded = 1; expanded = 1;
set_nodeType(n, Getattr(n, "templatetype")); set_nodeType(n, Getattr(n, "templatetype"));
ret = cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist); cparse_template_expand(templnode, n, tname, rname, templateargs, patchlist, typelist, cpatchlist);
expanded = 0; expanded = 0;
return ret; return;
} else { } else {
/* Called when template appears inside another template */ /* Called when template appears inside another template */
/* Member templates */ /* Member templates */
set_nodeType(n, Getattr(n, "templatetype")); set_nodeType(n, Getattr(n, "templatetype"));
ret = cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist); cparse_template_expand(templnode, n, tname, rname, templateargs, patchlist, typelist, cpatchlist);
set_nodeType(n, "template"); set_nodeType(n, "template");
return ret; return;
} }
} else if (Equal(nodeType, "cdecl")) { } else if (Equal(nodeType, "cdecl")) {
/* A simple C declaration */ /* A simple C declaration */
@ -131,7 +130,7 @@ static int cparse_template_expand(Node *n, String *tname, String *rname, String
{ {
Node *cn = firstChild(n); Node *cn = firstChild(n);
while (cn) { while (cn) {
cparse_template_expand(cn, tname, rname, templateargs, patchlist, typelist, cpatchlist); cparse_template_expand(templnode, cn, tname, rname, templateargs, patchlist, typelist, cpatchlist);
cn = nextSibling(cn); cn = nextSibling(cn);
} }
} }
@ -177,25 +176,30 @@ static int cparse_template_expand(Node *n, String *tname, String *rname, String
add_parms(Getattr(n, "parms"), cpatchlist, typelist); add_parms(Getattr(n, "parms"), cpatchlist, typelist);
add_parms(Getattr(n, "throws"), cpatchlist, typelist); add_parms(Getattr(n, "throws"), cpatchlist, typelist);
} else if (Equal(nodeType, "destructor")) { } else if (Equal(nodeType, "destructor")) {
String *name = Getattr(n, "name"); /* We only need to patch the dtor of the template itself, not the destructors of any nested classes, so check that the parent of this node is the root
if (name) { * template node, with the special exception for %extend which adds its methods under an intermediate node. */
if (strchr(Char(name), '<')) Node* parent = parentNode(n);
Append(patchlist, Getattr(n, "name")); if (parent == templnode || (parentNode(parent) == templnode && Equal(nodeType(parent), "extend"))) {
else String *name = Getattr(n, "name");
Append(name, templateargs); if (name) {
} if (strchr(Char(name), '<'))
name = Getattr(n, "sym:name"); Append(patchlist, Getattr(n, "name"));
if (name) { else
if (strchr(Char(name), '<')) { Append(name, templateargs);
String *sn = Copy(tname);
Setattr(n, "sym:name", sn);
Delete(sn);
} else {
Replace(name, tname, rname, DOH_REPLACE_ANY);
} }
name = Getattr(n, "sym:name");
if (name) {
if (strchr(Char(name), '<')) {
String *sn = Copy(tname);
Setattr(n, "sym:name", sn);
Delete(sn);
} else {
Replace(name, tname, rname, DOH_REPLACE_ANY);
}
}
/* Setattr(n,"sym:name",name); */
Append(cpatchlist, Getattr(n, "code"));
} }
/* Setattr(n,"sym:name",name); */
Append(cpatchlist, Getattr(n, "code"));
} else if (Equal(nodeType, "using")) { } else if (Equal(nodeType, "using")) {
String *uname = Getattr(n, "uname"); String *uname = Getattr(n, "uname");
if (uname && strchr(Char(uname), '<')) { if (uname && strchr(Char(uname), '<')) {
@ -217,11 +221,10 @@ static int cparse_template_expand(Node *n, String *tname, String *rname, String
add_parms(Getattr(n, "throws"), cpatchlist, typelist); add_parms(Getattr(n, "throws"), cpatchlist, typelist);
cn = firstChild(n); cn = firstChild(n);
while (cn) { while (cn) {
cparse_template_expand(cn, tname, rname, templateargs, patchlist, typelist, cpatchlist); cparse_template_expand(templnode, cn, tname, rname, templateargs, patchlist, typelist, cpatchlist);
cn = nextSibling(cn); cn = nextSibling(cn);
} }
} }
return 0;
} }
static static
@ -306,7 +309,7 @@ int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab
/* Printf(stdout,"targs = '%s'\n", templateargs); /* Printf(stdout,"targs = '%s'\n", templateargs);
Printf(stdout,"rname = '%s'\n", rname); Printf(stdout,"rname = '%s'\n", rname);
Printf(stdout,"tname = '%s'\n", tname); */ Printf(stdout,"tname = '%s'\n", tname); */
cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist); cparse_template_expand(n, n, tname, rname, templateargs, patchlist, typelist, cpatchlist);
/* Set the name */ /* Set the name */
{ {