New default argument wrapping approach. This adds default argument support for statically typed languages, fixes wrapping of default arguments that are non-public plus fixes other bugs where SWIG could not or failed to correctly lookup up the default value in the symbol table.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6310 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2004-10-04 20:32:28 +00:00
commit c4757bbbd4

View file

@ -218,21 +218,24 @@ int emit_num_arguments(ParmList *parms) {
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* emit_num_required() * emit_num_required()
* *
* Computes the number of required arguments. This is function is safe for * Computes the number of required arguments. This function is safe for
* use with multi-valued typemaps and knows how to skip over everything * use with multi-valued typemaps and knows how to skip over everything
* properly. * properly. Note that it does count parameters which have a default value.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int emit_num_required(ParmList *parms) { int emit_num_required(ParmList *parms) {
Parm *p = parms; Parm *p = parms;
int nargs = 0; int nargs = 0;
Parm *first_default_arg = 0;
while (p) { while (p) {
if (Getattr(p,"tmap:in") && checkAttribute(p,"tmap:in:numinputs","0")) { if (Getattr(p,"tmap:in") && checkAttribute(p,"tmap:in:numinputs","0")) {
p = Getattr(p,"tmap:in:next"); p = Getattr(p,"tmap:in:next");
} else { } else {
if (Getattr(p,"value")) break;
if (Getattr(p,"tmap:default")) break; if (Getattr(p,"tmap:default")) break;
if (Getattr(p,"value"))
if (!first_default_arg)
first_default_arg = p;
nargs+= GetInt(p,"tmap:in:numinputs"); nargs+= GetInt(p,"tmap:in:numinputs");
if (Getattr(p,"tmap:in")) { if (Getattr(p,"tmap:in")) {
p = Getattr(p,"tmap:in:next"); p = Getattr(p,"tmap:in:next");
@ -242,21 +245,26 @@ int emit_num_required(ParmList *parms) {
} }
} }
/* Print message for non-default arguments */ /* Print error message for non-default arguments following default arguments */
while (p) { /* The error message is printed more than once with most language modules, this ought to be fixed */
if (Getattr(p,"tmap:in") && checkAttribute(p,"tmap:in:numinputs","0")) { if (first_default_arg) {
p = Getattr(p,"tmap:in:next"); p = first_default_arg;
} else { while (p) {
if (!Getattr(p,"value") && (!Getattr(p,"tmap:default"))) { if (Getattr(p,"tmap:in") && checkAttribute(p,"tmap:in:numinputs","0")) {
Swig_error(Getfile(p),Getline(p),"Non-optional argument '%s' follows an optional argument.\n",Getattr(p,"name")); p = Getattr(p,"tmap:in:next");
}
if (Getattr(p,"tmap:in")) {
p = Getattr(p,"tmap:in:next");
} else { } else {
p = nextSibling(p); if (!Getattr(p,"value") && (!Getattr(p,"tmap:default"))) {
Swig_error(Getfile(p),Getline(p),"Non-optional argument '%s' follows an optional argument.\n",Getattr(p,"name"));
}
if (Getattr(p,"tmap:in")) {
p = Getattr(p,"tmap:in:next");
} else {
p = nextSibling(p);
}
} }
} }
} }
/* DB 04/02/2003: Not sure this is necessary with tmap:in:numinputs */ /* DB 04/02/2003: Not sure this is necessary with tmap:in:numinputs */
/* /*
if (parms && (p = Getattr(parms,"emit:varargs"))) { if (parms && (p = Getattr(parms,"emit:varargs"))) {