diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2023-02-18 12:47:34 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2023-02-18 14:16:29 +0000 |
commit | 1341df17fb463b472e8d199627f36df8ff617fab (patch) | |
tree | 5967f7a4f5fe1cc2bd0e14b4cce9e18cc0f94271 /Source | |
parent | 63bf998b30cfac572dd368dc9d66bfb00b86fc52 (diff) | |
download | swig-1341df17fb463b472e8d199627f36df8ff617fab.tar.gz |
Improved variadic parameter names expansion
Number the variadic parm names instead of not naming them.
Such as:
template<typename... T> int variadicmix1(T... t) { return 20; }
%template(variadicmix1) variadicmix1<A,B,C>;
Used to expand to:
int variadicmix1(A T, B arg1, C arg2)
now:
int variadicmix1(A t1, B t2, C t3)
Also test for generating duplicate parameter names which required
a fix in R. Also results in a few minor changes to parameter names
in generated R code.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CParse/templ.c | 3 | ||||
-rw-r--r-- | Source/Modules/r.cxx | 27 |
2 files changed, 13 insertions, 17 deletions
diff --git a/Source/CParse/templ.c b/Source/CParse/templ.c index a126ad29c..8c00570be 100644 --- a/Source/CParse/templ.c +++ b/Source/CParse/templ.c @@ -78,14 +78,17 @@ static void expand_variadic_parms(Node *n, const char *attribute, Parm *unexpand Parm *variadic = ParmList_variadic_parm(p); if (variadic) { SwigType *type = Getattr(variadic, "type"); + String *name = Getattr(variadic, "name"); String *unexpanded_name = Getattr(unexpanded_variadic_parm, "name"); ParmList *expanded = CopyParmList(expanded_variadic_parms); Parm *ep = expanded; + int i = 0; while (ep) { SwigType *newtype = Copy(type); SwigType_del_variadic(newtype); Replaceid(newtype, unexpanded_name, Getattr(ep, "type")); Setattr(ep, "type", newtype); + Setattr(ep, "name", name ? NewStringf("%s%d", name, ++i) : 0); ep = nextSibling(ep); } expanded = ParmList_replace_last(p, expanded); diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 9b465a571..1c2da3ac4 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1854,27 +1854,20 @@ int R::functionWrapper(Node *n) { int nargs = -1; String *funcptr_name = processType(tt, p, &nargs); - // SwigType *tp = Getattr(p, "type"); - String *name = Getattr(p,"name"); - String *lname = Getattr(p,"lname"); + String *name = makeParameterName(n, p, i+1, false); + String *lname = Getattr(p, "lname"); - // R keyword renaming if (name) { - if (Swig_name_warning(p, 0, name, 0)) { - name = 0; - } else { - /* If we have a :: in the parameter name because we are accessing a static member of a class, say, then - we need to remove that prefix. */ - while (Strstr(name, "::")) { - //XXX need to free. - name = NewStringf("%s", Strchr(name, ':') + 2); - if (debugMode) - Printf(stdout, "+++ parameter name with :: in it %s\n", name); - } + /* If we have a :: in the parameter name because we are accessing a static member of a class, say, then + we need to remove that prefix. */ + while (Strstr(name, "::")) { + String *oldname = name; + name = NewStringf("%s", Strchr(name, ':') + 2); + if (debugMode) + Printf(stdout, "+++ parameter name with :: in it %s\n", name); + Delete(oldname); } } - if (!name || Len(name) == 0) - name = NewStringf("s_arg%d", i+1); name = replaceInitialDash(name); |