mirror of https://github.com/swig/swig
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)
This commit is contained in:
parent
1341df17fb
commit
7dccbf8694
|
@ -225,6 +225,7 @@ CPP_TEST_CASES += \
|
|||
director_wombat \
|
||||
disown \
|
||||
duplicate_class_name_in_ns \
|
||||
duplicate_parm_names \
|
||||
dynamic_cast \
|
||||
empty \
|
||||
enum_ignore \
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
%module duplicate_parm_names
|
||||
|
||||
// Testing duplicate argument name handling
|
||||
|
||||
%{
|
||||
void fn_2parms(int, int) {}
|
||||
void fn_3parms(int, int, double) {}
|
||||
void fn_4parms(int, short, double, const char *) {}
|
||||
|
||||
struct SameParmNameCheck {
|
||||
void metho(int, short, double, const char *) {}
|
||||
};
|
||||
%}
|
||||
|
||||
void fn_2parms(int argx, int argx) {}
|
||||
void fn_3parms(int p_a, int p_a, double p_c) {}
|
||||
void fn_4parms(int duplicate, short duplicate, double duplicate, const char *duplicate) {}
|
||||
|
||||
struct SameParmNameCheck {
|
||||
void metho(int dup, short dup, double uniq, const char *dup) {}
|
||||
};
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue