Stop mangling dtors of nested classes instead a template class

cparse_template_expand() incorrectly appended template parameters to all
destructor nodes it encountered during the tree traversal, including the
dtors of any nested classes.

This resulted in WARN_LANG_ILLEGAL_DESTRUCTOR warnings from
Language::destructorDeclaration() later and possibly other problems due
to not actually wrapping these dtors.

Fix this by explicitly checking if the dtor is a child or, to account
for %extend, a grandchild of the template node itself before appending
template parameters to it.

This commit is best viewed with "-w" (ignore whitespace changes) option
as it indents, without changing, a block of code.
This commit is contained in:
Vadim Zeitlin 2018-11-23 02:45:24 +01:00
commit 4af2e95010

View file

@ -49,7 +49,7 @@ void Swig_cparse_debug_templates(int x) {
* template parameters * template parameters
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static void 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;
String *nodeType; String *nodeType;
if (!n) if (!n)
@ -63,7 +63,7 @@ static void cparse_template_expand(Node *n, String *tname, String *rname, String
if (!expanded) { if (!expanded) {
expanded = 1; expanded = 1;
set_nodeType(n, Getattr(n, "templatetype")); set_nodeType(n, Getattr(n, "templatetype"));
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; return;
} else { } else {
@ -71,7 +71,7 @@ static void cparse_template_expand(Node *n, String *tname, String *rname, String
/* Member templates */ /* Member templates */
set_nodeType(n, Getattr(n, "templatetype")); set_nodeType(n, Getattr(n, "templatetype"));
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; return;
} }
@ -130,7 +130,7 @@ static void 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);
} }
} }
@ -176,25 +176,30 @@ static void 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), '<')) {
@ -216,7 +221,7 @@ static void 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);
} }
} }
@ -304,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 */
{ {