Refactor: move makeParameterName() to common Language base class.
This method was duplicated more or less identically for 4 languages and will be needed for another one soon, so put it in the base class from which it can be simply reused instead. No changes in the program behaviour whatsoever.
This commit is contained in:
parent
07e2568a20
commit
9f1af8921f
6 changed files with 42 additions and 137 deletions
|
|
@ -3499,6 +3499,44 @@ int Language::is_smart_pointer() const {
|
|||
return SmartPointer;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Language::makeParameterName()
|
||||
*
|
||||
* Inputs:
|
||||
* n - Node
|
||||
* p - parameter node
|
||||
* arg_num - parameter argument number
|
||||
* setter - set this flag when wrapping variables
|
||||
* Return:
|
||||
* arg - a unique parameter name
|
||||
* ----------------------------------------------------------------------------- */
|
||||
String *Language::makeParameterName(Node *n, Parm *p, int arg_num, bool setter) const {
|
||||
|
||||
String *arg = 0;
|
||||
String *pn = Getattr(p, "name");
|
||||
|
||||
// Use C parameter name unless it is a duplicate or an empty parameter name
|
||||
int count = 0;
|
||||
ParmList *plist = Getattr(n, "parms");
|
||||
while (plist) {
|
||||
if ((Cmp(pn, Getattr(plist, "name")) == 0))
|
||||
count++;
|
||||
plist = nextSibling(plist);
|
||||
}
|
||||
String *wrn = pn ? Swig_name_warning(p, 0, pn, 0) : 0;
|
||||
arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d", arg_num) : Copy(pn);
|
||||
|
||||
if (setter && Cmp(arg, "self") != 0) {
|
||||
// Some languages (C#) insist on calling the input variable "value" while
|
||||
// others (D, Java) could, in principle, use something different but this
|
||||
// would require more work, and so we just use "value" for them too.
|
||||
Delete(arg);
|
||||
arg = NewString("value");
|
||||
}
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Language::()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue