Harmonize parameters in autodoc in Ruby and Octave with Python

Backport changes to Python version of make_autodocParmList() to Ruby and
Octave modules, which use similar code.

In particular, this improves handling of parameters clashing with the
language keywords/reserved words for these languages as well.
This commit is contained in:
Vadim Zeitlin 2019-01-21 01:08:45 +01:00
commit cd526caed4
2 changed files with 24 additions and 20 deletions

View file

@ -418,13 +418,14 @@ public:
* The "lname" attribute in each parameter in plist will be contain a parameter name * The "lname" attribute in each parameter in plist will be contain a parameter name
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void addMissingParameterNames(ParmList *plist, int arg_offset) { void addMissingParameterNames(Node* n, ParmList *plist, int arg_offset) {
Parm *p = plist; Parm *p = plist;
int i = arg_offset; int i = arg_offset;
while (p) { while (p) {
if (!Getattr(p, "lname")) { if (!Getattr(p, "lname")) {
String *pname = Swig_cparm_name(p, i); String *name = makeParameterName(n, p, i);
Delete(pname); Setattr(p, "lname", name);
Delete(name);
} }
i++; i++;
p = nextSibling(p); p = nextSibling(p);
@ -436,14 +437,14 @@ public:
ParmList *plist = CopyParmList(Getattr(n, "parms")); ParmList *plist = CopyParmList(Getattr(n, "parms"));
Parm *p; Parm *p;
Parm *pnext; Parm *pnext;
int start_arg_num = is_wrapping_class() ? 1 : 0; int arg_num = is_wrapping_class() ? 1 : 0;
addMissingParameterNames(plist, start_arg_num); // for $1_name substitutions done in Swig_typemap_attach_parms addMissingParameterNames(n, plist, arg_num); // for $1_name substitutions done in Swig_typemap_attach_parms
Swig_typemap_attach_parms("in", plist, 0); Swig_typemap_attach_parms("in", plist, 0);
Swig_typemap_attach_parms("doc", plist, 0); Swig_typemap_attach_parms("doc", plist, 0);
for (p = plist; p; p = pnext) { for (p = plist; p; p = pnext, arg_num++) {
String *tm = Getattr(p, "tmap:in"); String *tm = Getattr(p, "tmap:in");
if (tm) { if (tm) {
@ -465,9 +466,10 @@ public:
value = Getattr(p, "tmap:doc:value"); value = Getattr(p, "tmap:doc:value");
} }
name = name ? name : Getattr(p, "name"); String *made_name = 0;
name = name ? name : Getattr(p, "lname"); if (!name) {
name = Swig_name_make(p, 0, name, 0, 0); // rename parameter if a keyword name = made_name = makeParameterName(n, p, arg_num);
}
type = type ? type : Getattr(p, "type"); type = type ? type : Getattr(p, "type");
value = value ? value : Getattr(p, "value"); value = value ? value : Getattr(p, "value");
@ -503,7 +505,7 @@ public:
Delete(type_str); Delete(type_str);
Delete(tex_name); Delete(tex_name);
Delete(name); Delete(made_name);
} }
if (pdocs) if (pdocs)
Setattr(n, "feature:pdocs", pdocs); Setattr(n, "feature:pdocs", pdocs);

View file

@ -290,13 +290,14 @@ private:
* The "lname" attribute in each parameter in plist will be contain a parameter name * The "lname" attribute in each parameter in plist will be contain a parameter name
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void addMissingParameterNames(ParmList *plist, int arg_offset) { void addMissingParameterNames(Node* n, ParmList *plist, int arg_offset) {
Parm *p = plist; Parm *p = plist;
int i = arg_offset; int i = arg_offset;
while (p) { while (p) {
if (!Getattr(p, "lname")) { if (!Getattr(p, "lname")) {
String *pname = Swig_cparm_name(p, i); String *name = makeParameterName(n, p, i);
Delete(pname); Setattr(p, "lname", name);
Delete(name);
} }
i++; i++;
p = nextSibling(p); p = nextSibling(p);
@ -315,10 +316,10 @@ private:
Parm *p; Parm *p;
Parm *pnext; Parm *pnext;
int lines = 0; int lines = 0;
int start_arg_num = is_wrapping_class() ? 1 : 0; int arg_num = is_wrapping_class() ? 1 : 0;
const int maxwidth = 80; const int maxwidth = 80;
addMissingParameterNames(plist, start_arg_num); // for $1_name substitutions done in Swig_typemap_attach_parms addMissingParameterNames(n, plist, arg_num); // for $1_name substitutions done in Swig_typemap_attach_parms
Swig_typemap_attach_parms("in", plist, 0); Swig_typemap_attach_parms("in", plist, 0);
Swig_typemap_attach_parms("doc", plist, 0); Swig_typemap_attach_parms("doc", plist, 0);
@ -328,7 +329,7 @@ private:
return doc; return doc;
} }
for (p = plist; p; p = pnext) { for (p = plist; p; p = pnext, arg_num++) {
String *tm = Getattr(p, "tmap:in"); String *tm = Getattr(p, "tmap:in");
if (tm) { if (tm) {
@ -351,9 +352,10 @@ private:
} }
// Note: the generated name should be consistent with that in kwnames[] // Note: the generated name should be consistent with that in kwnames[]
name = name ? name : Getattr(p, "name"); String *made_name = 0;
name = name ? name : Getattr(p, "lname"); if (!name) {
name = Swig_name_make(p, 0, name, 0, 0); // rename parameter if a keyword name = made_name = makeParameterName(n, p, arg_num);
}
type = type ? type : Getattr(p, "type"); type = type ? type : Getattr(p, "type");
value = value ? value : Getattr(p, "value"); value = value ? value : Getattr(p, "value");
@ -404,7 +406,7 @@ private:
Printf(doc, "=%s", value); Printf(doc, "=%s", value);
} }
Delete(type_str); Delete(type_str);
Delete(name); Delete(made_name);
} }
if (pdocs) if (pdocs)
Setattr(n, "feature:pdocs", pdocs); Setattr(n, "feature:pdocs", pdocs);