diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2023-02-18 16:28:33 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2023-02-18 16:28:33 +0000 |
commit | 7dccbf86945f166f907ceb4b993cd625d98527c3 (patch) | |
tree | 02eb036859fd9bbb5e29c972f56f93676a90874d /Source | |
parent | 1341df17fb463b472e8d199627f36df8ff617fab (diff) | |
download | swig-7dccbf86945f166f907ceb4b993cd625d98527c3.tar.gz |
Duplicate parameter name handling improvements
When a method with duplicate parameter names is wrapped such as:
void fn_3parms(int p_a, int p_a, double p_c);
Previously all duplicate parameter names were changed in order to
provide unique parameter names:
void fn_3parms(int arg0, int arg1, double p_c)
Now the parameter names changed are just the 2nd and subsequent duplicate
parameter names:
void fn_3parms(int p_a, int arg1, double p_c)
Diffstat (limited to 'Source')
-rw-r--r-- | Source/Modules/lang.cxx | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 0aecc70ad..7a85c2d63 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3633,15 +3633,20 @@ String *Language::makeParameterName(Node *n, Parm *p, int arg_num, bool setter) // Check if parameter name is a duplicate. int count = 0; + Parm *first_duplicate_parm = 0; ParmList *plist = Getattr(n, "parms"); while (plist) { - if ((Cmp(pn, Getattr(plist, "name")) == 0)) + if ((Cmp(pn, Getattr(plist, "name")) == 0)) { + if (!first_duplicate_parm) + first_duplicate_parm = plist; count++; + } plist = nextSibling(plist); } // If the parameter has no name at all or has a non-unique name, replace it with "argN". - if (!pn || count > 1) { + // On the assumption that p is pointer/element in plist, only replace the 2nd and subsequent duplicates + if (!pn || (count > 1 && p != first_duplicate_parm)) { arg = NewStringf("arg%d", arg_num); } else { // Otherwise, try to use the original C name, but modify it if necessary to avoid conflicting with the language keywords. |