API cleanup (Parms)

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9633 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2007-01-10 23:43:07 +00:00
commit b00cef436b
12 changed files with 94 additions and 78 deletions

View file

@ -10,7 +10,7 @@
<p>
David M. Beazley <br>
dave-swig@dabeaz.com<br>
January 2, 2007<br>
January 9, 2007<br>
</b>
</center>
@ -59,12 +59,6 @@ Copies at most <tt>count</tt> parameters from the parameter list <tt>p</tt>.
Returns the total number of parameters in a parameter list.
</blockquote>
<p>
<b><tt>int ParmList_numarg(ParmList *p)</tt></b>
<blockquote>
Returns the number of non-ignored parameters in a parameter list. Any parameter with an "ignore" attribute is ignored in the count.
</blockquote>
<p>
<b><tt>int ParmList_numrequired(ParmList *p)</tt></b>
<blockquote>
@ -95,7 +89,7 @@ Creates a C prototype string of the parameters and includes the default values (
<p>
<b><tt>String *ParmList_protostr(ParmList *p)</tt></b>
<blockquote>
Creates a C prototype string of the parameters. Does not include any hidden parameters.
Creates a C prototype string of the parameters.
</blockquote>

View file

@ -1790,13 +1790,13 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s) ignored. Method %s(%s) const at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
}
}
nodes[j].error = 1;
@ -1806,13 +1806,13 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s) const ignored. Method %s(%s) at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
}
}
nodes[j].error = 1;
@ -1827,17 +1827,17 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s)%s is shadowed by %s(%s)%s at %s:%d.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "",
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms),
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms),
SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s)%s ignored. Method %s(%s)%s at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "",
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms),
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms),
SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n));
}
nodes[j].error = 1;
@ -1854,7 +1854,7 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (nodes[i].error)
Setattr(nodes[i].n, "overload:ignore", "1");
Append(result, nodes[i].n);
// Printf(stdout,"[ %d ] %s\n", i, ParmList_protostr(nodes[i].parms));
// Printf(stdout,"[ %d ] %s\n", i, ParmList_errorstr(nodes[i].parms));
// Swig_print_node(nodes[i].n);
}
}

View file

@ -106,7 +106,7 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) {
Printv(f->code, tm, "\n", NIL);
np = Getattr(p, "tmap:in:next");
while (p && (p != np)) {
Setattr(p, "ignore", "1");
/* Setattr(p,"ignore","1"); Deprecate */
p = nextSibling(p);
}
} else if (tm) {

View file

@ -224,13 +224,13 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s) ignored. Method %s(%s) const at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
}
}
nodes[j].error = 1;
@ -240,13 +240,13 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s) const ignored. Method %s(%s) at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
}
}
nodes[j].error = 1;
@ -261,17 +261,17 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s)%s is shadowed by %s(%s)%s at %s:%d.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "",
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms),
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms),
SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s)%s ignored. Method %s(%s)%s at %s:%d used.\n",
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[j].n, "name"), ParmList_errorstr(nodes[j].parms),
SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "",
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms),
Getattr(nodes[i].n, "name"), ParmList_errorstr(nodes[i].parms),
SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n));
}
nodes[j].error = 1;
@ -288,7 +288,7 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
if (nodes[i].error)
Setattr(nodes[i].n, "overload:ignore", "1");
Append(result, nodes[i].n);
// Printf(stdout,"[ %d ] %s\n", i, ParmList_protostr(nodes[i].parms));
// Printf(stdout,"[ %d ] %s\n", i, ParmList_errorstr(nodes[i].parms));
// Swig_print_node(nodes[i].n);
}
}

View file

@ -974,7 +974,7 @@ public:
while (p != 0) {
SwigType *pt = Getattr(p, "type");
String *pn = Getattr(p, "name");
if (!Getattr(p, "ignore")) {
if (!checkAttribute(p,"tmap:in:numinputs","0")) {
/* If parameter has been named, use that. Otherwise, just print a type */
if (SwigType_type(pt) != T_VOID) {
if (Len(pn) > 0) {
@ -986,12 +986,12 @@ public:
i++;
p = nextSibling(p);
if (p)
if (!Getattr(p, "ignore"))
if (!checkAttribute(p,"tmap:in:numinputs","0"))
Putc(',', temp);
} else {
p = nextSibling(p);
if (p)
if ((i > 0) && (!Getattr(p, "ignore")))
if ((i > 0) && (!checkAttribute(p,"tmap:in:numinputs","0")))
Putc(',', temp);
}
}

View file

@ -1706,7 +1706,7 @@ public:
if (Len(pn)) {
String *tmp = 0;
String *name = pn;
if (!Getattr(p, "hidden")) {
if (!Getattr(p,"hidden")) {
name = tmp = Swig_name_make(p, 0, pn, 0, 0);
}
Printf(kwargs, "(char *) \"%s\",", name);
@ -1739,7 +1739,7 @@ public:
if (Getattr(p, "tmap:in:implicitconv")) {
const char *convflag = "0";
if (!Getattr(p, "hidden")) {
if (!Getattr(p,"hidden")) {
SwigType *ptype = Getattr(p, "type");
convflag = get_implicitconv_flag(classLookup(ptype));
}
@ -1842,7 +1842,7 @@ public:
if (!Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) {
if (Getattr(p, "tmap:freearg:implicitconv")) {
const char *convflag = "0";
if (!Getattr(p, "hidden")) {
if (!Getattr(p,"hidden")) {
SwigType *ptype = Getattr(p, "type");
convflag = get_implicitconv_flag(classLookup(ptype));
}

View file

@ -1451,14 +1451,14 @@ static List * Swig_overload_rank(Node *n,
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
Getfile(nodes[i].n), Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s) ignored. Method %s(%s) const at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms),
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
Getattr(nodes[i].n,"name"), ParmList_errorstr(nodes[i].parms),
Getfile(nodes[i].n), Getline(nodes[i].n));
}
}
@ -1469,14 +1469,14 @@ static List * Swig_overload_rank(Node *n,
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
Getfile(nodes[i].n), Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s) const ignored. Method %s(%s) at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms),
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
Getattr(nodes[i].n,"name"), ParmList_errorstr(nodes[i].parms),
Getfile(nodes[i].n), Getline(nodes[i].n));
}
}
@ -1492,18 +1492,18 @@ static List * Swig_overload_rank(Node *n,
if (script_lang_wrapping) {
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s)%s is shadowed by %s(%s)%s at %s:%d.\n",
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "",
Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms),
Getattr(nodes[i].n,"name"), ParmList_errorstr(nodes[i].parms),
SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "",
Getfile(nodes[i].n),Getline(nodes[i].n));
} else {
if (!Getattr(nodes[j].n, "overload:ignore"))
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded method %s(%s)%s ignored. Method %s(%s)%s at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[j].n,"name"), ParmList_errorstr(nodes[j].parms),
SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "",
Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms),
Getattr(nodes[i].n,"name"), ParmList_errorstr(nodes[i].parms),
SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "",
Getfile(nodes[i].n),Getline(nodes[i].n));
}
@ -1521,7 +1521,7 @@ static List * Swig_overload_rank(Node *n,
if (nodes[i].error)
Setattr(nodes[i].n, "overload:ignore", "1");
Append(result,nodes[i].n);
// Printf(stdout,"[ %d ] %s\n", i, ParmList_protostr(nodes[i].parms));
// Printf(stdout,"[ %d ] %s\n", i, ParmList_errorstr(nodes[i].parms));
// Swig_print_node(nodes[i].n);
}
}

View file

@ -807,7 +807,7 @@ int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *direc
SwigType_add_pointer(type);
p = NewParm(type, "self");
Setattr(p, "self", "1");
Setattr(p, "hidden", "1");
Setattr(p, "hidden","1");
/*
Disable the 'this' ownership in 'self' to manage inplace
operations like:
@ -1239,7 +1239,7 @@ int Swig_MembersetToFunction(Node *n, String *classname, int flags) {
SwigType_add_pointer(t);
parms = NewParm(t, "self");
Setattr(parms, "self", "1");
Setattr(parms, "hidden", "1");
Setattr(parms, "hidden","1");
Delete(t);
ty = Swig_wrapped_member_var_type(type, varcref);
@ -1325,7 +1325,7 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) {
SwigType_add_pointer(t);
parms = NewParm(t, "self");
Setattr(parms, "self", "1");
Setattr(parms, "hidden", "1");
Setattr(parms, "hidden","1");
Delete(t);
ty = Swig_wrapped_member_var_type(type, varcref);

View file

@ -68,3 +68,38 @@ int ParmList_is_compactdefargs(ParmList *p) {
return compactdefargs;
}
/* ---------------------------------------------------------------------
* ParmList_errorstr()
*
* Generate a prototype string suitable for use in error/warning messages.
* This function is aware of hidden parameters.
* ---------------------------------------------------------------------- */
/* Discussion. This function is used to generate error messages, but take
into account that there might be a hidden parameter. Although this involves
parameter lists, it really isn't a core feature of swigparm.h or parms.c.
This is because the "hidden" attribute of parameters is added elsewhere (cwrap.c).
For now, this function is placed here because it doesn't really seem to fit in
with the parms.c interface.
*/
String *ParmList_errorstr(ParmList *p) {
String *out = NewStringEmpty();
while (p) {
if (Getattr(p,"hidden")) {
p = nextSibling(p);
} else {
String *pstr = SwigType_str(Getattr(p, "type"), 0);
Append(out, pstr);
p = nextSibling(p);
if (p) {
Append(out, ",");
}
Delete(pstr);
}
}
return out;
}

View file

@ -81,20 +81,6 @@ ParmList *CopyParmList(ParmList *p) {
return CopyParmListMax(p,-1);
}
/* ------------------------------------------------------------------
* int ParmList_numarg()
* ------------------------------------------------------------------ */
int ParmList_numarg(ParmList *p) {
int n = 0;
while (p) {
if (!Getattr(p, "ignore"))
n++;
p = nextSibling(p);
}
return n;
}
/* -----------------------------------------------------------------------------
* int ParmList_numrequired(). Return number of required arguments
* ----------------------------------------------------------------------------- */
@ -181,17 +167,13 @@ String *ParmList_str_defaultargs(ParmList *p) {
String *ParmList_protostr(ParmList *p) {
String *out = NewStringEmpty();
while (p) {
if (Getattr(p, "hidden")) {
p = nextSibling(p);
} else {
String *pstr = SwigType_str(Getattr(p, "type"), 0);
Append(out, pstr);
p = nextSibling(p);
if (p) {
Append(out, ",");
}
Delete(pstr);
String *pstr = SwigType_str(Getattr(p, "type"), 0);
Append(out, pstr);
p = nextSibling(p);
if (p) {
Append(out, ",");
}
Delete(pstr);
}
return out;
}

View file

@ -297,6 +297,9 @@ extern "C" {
#include "swigparm.h"
extern String *ParmList_errorstr(ParmList *);
extern int ParmList_is_compactdefargs(ParmList *p);
/* --- Parse tree support --- */
#include "swigtree.h"

View file

@ -18,10 +18,12 @@ extern Parm *CopyParm(Parm *p);
extern ParmList *CopyParmList(ParmList *);
extern ParmList *CopyParmListMax(ParmList *, int count);
extern int ParmList_len(ParmList *);
extern int ParmList_numarg(ParmList *);
extern int ParmList_numrequired(ParmList *);
extern int ParmList_has_defaultargs(ParmList *p);
/* Output functions */
extern String *ParmList_str(ParmList *);
extern String *ParmList_str_defaultargs(ParmList *);
extern String *ParmList_protostr(ParmList *);
extern int ParmList_is_compactdefargs(ParmList *p);
extern int ParmList_has_defaultargs(ParmList *p);