From 83ae863d4a21b1f699b248417efe9a019516b91b Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Fri, 17 Feb 2023 18:55:32 -0700 Subject: [PATCH] Add names to c function params --- Source/Modules/c.cxx | 19 +++++++++++++++---- Source/Swig/cwrap.c | 3 ++- Source/Swig/typemap.c | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Source/Modules/c.cxx b/Source/Modules/c.cxx index f8aed2a02..57bd664ea 100644 --- a/Source/Modules/c.cxx +++ b/Source/Modules/c.cxx @@ -869,7 +869,7 @@ public: // We want to use readable parameter names in our wrappers instead of the autogenerated arg$N if possible, so do it, and do it before calling // Swig_typemap_attach_parms(), as this uses the parameter names for typemap expansion. for (Parm* p2 = p; p2; p2 = nextSibling(p2)) { - String* name = Getattr(p, "name"); + String* name = Getattr(p2, "name"); if (!name) { // Can't do anything for unnamed parameters. continue; @@ -2411,10 +2411,21 @@ public: String *lname = 0; for (p = (Parm*)parms, index = 1; p; (p = nextSibling(p)), index++) { - if(!(lname = Getattr(p, "lname"))) { - lname = NewStringf("arg%d", index); - Setattr(p, "lname", lname); + String* name = Getattr(p, "name"); + if (!name) { + // Can't do anything for unnamed parameters. + if(!(lname = Getattr(p, "lname"))) { + lname = NewStringf("arg%d", index); + Setattr(p, "lname", lname); + } + continue; + } + scoped_dohptr name_ptr; + if (Strstr(name, "::")) { + name_ptr = Swig_scopename_last(name); + name = name_ptr.get(); } + Setattr(p, "lname", name); } // C++ function wrapper diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 3b20f4e4f..ae932f277 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -58,7 +58,8 @@ const char *Swig_cresult_name(void) { String *Swig_cparm_name(Parm *p, int i) { String *name = NewStringf("arg%d", i + 1); if (p) { - Setattr(p, "lname", name); + String *lname = Getattr(p, "lname"); + if (!lname) Setattr(p, "lname", name); } return name; diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index d6f48814d..d0fec2570 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1834,7 +1834,7 @@ void Swig_typemap_attach_parms(const_String_or_char_ptr tmap_method, ParmList *p for (i = 0; i < nmatch; i++) { SwigType *type = Getattr(p, "type"); String *pname = Getattr(p, "name"); - String *lname = Getattr(p, "lname"); + String *lname = Swig_cparm_name(p, argnum-1); SwigType *mtype = Getattr(p, "tmap:match"); SwigType *matchtype = mtype ? mtype : type;