compact default arguments feature (original default argument wrapping mode)
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6449 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
2128e98a15
commit
97c2eeaf90
9 changed files with 68 additions and 17 deletions
|
|
@ -44,6 +44,7 @@ extern int yylex();
|
||||||
extern SwigType *Swig_cparse_type(String *);
|
extern SwigType *Swig_cparse_type(String *);
|
||||||
extern Node *Swig_cparse(File *);
|
extern Node *Swig_cparse(File *);
|
||||||
extern Hash *Swig_cparse_features();
|
extern Hash *Swig_cparse_features();
|
||||||
|
extern void SWIG_cparse_set_compact_default_args(int defargs);
|
||||||
|
|
||||||
/* util.c */
|
/* util.c */
|
||||||
extern void Swig_cparse_replace_descriptor(String *s);
|
extern void Swig_cparse_replace_descriptor(String *s);
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ static int num_brace = 0;
|
||||||
static int last_brace = 0;
|
static int last_brace = 0;
|
||||||
static int last_id = 0;
|
static int last_id = 0;
|
||||||
static int rename_active = 0;
|
static int rename_active = 0;
|
||||||
int cparse_cplusplus;
|
int cparse_cplusplus = 0;
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Swig_cparse_cplusplus()
|
* Swig_cparse_cplusplus()
|
||||||
|
|
|
||||||
|
|
@ -220,22 +220,26 @@ int emit_num_arguments(ParmList *parms) {
|
||||||
*
|
*
|
||||||
* Computes the number of required arguments. This 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. Note that it does count parameters which have a default value.
|
* properly. Note that parameters with default values are counted unless
|
||||||
|
* the compact default args option is on.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
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;
|
Parm *first_default_arg = 0;
|
||||||
|
int compactdefargs = ParmList_is_compactdefargs(p);
|
||||||
|
|
||||||
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,"tmap:default")) break;
|
if (Getattr(p,"tmap:default")) break;
|
||||||
if (Getattr(p,"value"))
|
if (Getattr(p,"value")) {
|
||||||
if (!first_default_arg)
|
if (!first_default_arg)
|
||||||
first_default_arg = p;
|
first_default_arg = p;
|
||||||
|
if (compactdefargs) break;
|
||||||
|
}
|
||||||
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");
|
||||||
|
|
|
||||||
|
|
@ -1089,7 +1089,8 @@ Language::staticmemberfunctionHandler(Node *n) {
|
||||||
if (!defaultargs && code) {
|
if (!defaultargs && code) {
|
||||||
/* Hmmm. An added static member. We have to create a little wrapper for this */
|
/* Hmmm. An added static member. We have to create a little wrapper for this */
|
||||||
String *body;
|
String *body;
|
||||||
String *tmp = NewStringf("%s(%s)", cname, ParmList_str_defaultargs(parms));
|
String *parmstring = CPlusPlus ? ParmList_str_defaultargs(parms) : ParmList_str(parms);
|
||||||
|
String *tmp = NewStringf("%s(%s)", cname, parmstring);
|
||||||
body = SwigType_str(type,tmp);
|
body = SwigType_str(type,tmp);
|
||||||
Printv(body,code,"\n",NIL);
|
Printv(body,code,"\n",NIL);
|
||||||
Setattr(n,"wrap:code",body);
|
Setattr(n,"wrap:code",body);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
char cvsroot_python_cxx[] = "$Header$";
|
char cvsroot_python_cxx[] = "$Header$";
|
||||||
|
|
||||||
#include "swigmod.h"
|
#include "swigmod.h"
|
||||||
|
#include "cparse.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
@ -131,6 +132,7 @@ public:
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i],"-keyword") == 0) {
|
} else if (strcmp(argv[i],"-keyword") == 0) {
|
||||||
use_kw = 1;
|
use_kw = 1;
|
||||||
|
SWIG_cparse_set_compact_default_args(1);
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i],"-classic") == 0) {
|
} else if (strcmp(argv[i],"-classic") == 0) {
|
||||||
classic = 1;
|
classic = 1;
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,6 @@ private:
|
||||||
File *f_wrappers;
|
File *f_wrappers;
|
||||||
File *f_init;
|
File *f_init;
|
||||||
|
|
||||||
bool use_kw;
|
|
||||||
bool useGlobalModule;
|
bool useGlobalModule;
|
||||||
bool multipleInheritance;
|
bool multipleInheritance;
|
||||||
|
|
||||||
|
|
@ -186,7 +185,6 @@ public:
|
||||||
f_header = 0;
|
f_header = 0;
|
||||||
f_wrappers = 0;
|
f_wrappers = 0;
|
||||||
f_init = 0;
|
f_init = 0;
|
||||||
use_kw = false;
|
|
||||||
useGlobalModule = false;
|
useGlobalModule = false;
|
||||||
multipleInheritance = false;
|
multipleInheritance = false;
|
||||||
}
|
}
|
||||||
|
|
@ -996,7 +994,7 @@ public:
|
||||||
int numarg = emit_num_arguments(l);
|
int numarg = emit_num_arguments(l);
|
||||||
int numreq = emit_num_required(l);
|
int numreq = emit_num_required(l);
|
||||||
int varargs = emit_isvarargs(l);
|
int varargs = emit_isvarargs(l);
|
||||||
bool allow_kwargs = use_kw || Getattr(n,"feature:kwargs");
|
bool allow_kwargs = Getattr(n,"feature:kwargs");
|
||||||
|
|
||||||
bool use_director = (current == CONSTRUCTOR_INITIALIZE && Swig_directorclass(n));
|
bool use_director = (current == CONSTRUCTOR_INITIALIZE && Swig_directorclass(n));
|
||||||
int start = (current == MEMBER_FUNC || current == MEMBER_VAR || use_director) ? 1 : 0;
|
int start = (current == MEMBER_FUNC || current == MEMBER_VAR || use_director) ? 1 : 0;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ char cvsroot_cwrap_c[] = "$Header$";
|
||||||
|
|
||||||
#include "swig.h"
|
#include "swig.h"
|
||||||
|
|
||||||
|
extern int cparse_cplusplus;
|
||||||
|
|
||||||
static Parm *nonvoid_parms(Parm *p) {
|
static Parm *nonvoid_parms(Parm *p) {
|
||||||
if (p) {
|
if (p) {
|
||||||
SwigType *t = Getattr(p,"type");
|
SwigType *t = Getattr(p,"type");
|
||||||
|
|
@ -136,6 +138,8 @@ Swig_wrapped_var_assign(SwigType *t, const String_or_char *name) {
|
||||||
*
|
*
|
||||||
* Emit all of the local variables for a list of parameters. Returns the
|
* Emit all of the local variables for a list of parameters. Returns the
|
||||||
* number of parameters.
|
* number of parameters.
|
||||||
|
* Default values for the local variables are only emitted if the compact default
|
||||||
|
* argument behaviour is required.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
int Swig_cargs(Wrapper *w, ParmList *p) {
|
int Swig_cargs(Wrapper *w, ParmList *p) {
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -147,15 +151,22 @@ int Swig_cargs(Wrapper *w, ParmList *p) {
|
||||||
SwigType *altty;
|
SwigType *altty;
|
||||||
String *type;
|
String *type;
|
||||||
int tycode;
|
int tycode;
|
||||||
|
int compactdefargs = ParmList_is_compactdefargs(p);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
while (p != 0) {
|
while (p != 0) {
|
||||||
lname = Swig_cparm_name(p,i);
|
lname = Swig_cparm_name(p,i);
|
||||||
pt = Getattr(p,"type");
|
pt = Getattr(p,"type");
|
||||||
if ((SwigType_type(pt) != T_VOID)) {
|
if ((SwigType_type(pt) != T_VOID)) {
|
||||||
pname = Getattr(p,"name");
|
pname = Getattr(p,"name");
|
||||||
/* pvalue = Getattr(p,"value");*/
|
|
||||||
pvalue = 0;
|
/* default values only emitted if in compact default args mode */
|
||||||
|
if (compactdefargs)
|
||||||
|
pvalue = Getattr(p,"value");
|
||||||
|
else
|
||||||
|
pvalue = 0;
|
||||||
|
|
||||||
type = Getattr(p,"type");
|
type = Getattr(p,"type");
|
||||||
altty = SwigType_alttype(type,0);
|
altty = SwigType_alttype(type,0);
|
||||||
tycode = SwigType_type(type);
|
tycode = SwigType_type(type);
|
||||||
|
|
@ -683,11 +694,12 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) {
|
||||||
/* See if there is any code that we need to emit */
|
/* See if there is any code that we need to emit */
|
||||||
if (!defaultargs && code) {
|
if (!defaultargs && code) {
|
||||||
String *body;
|
String *body;
|
||||||
String *tmp = NewStringf("%s(%s)", mangled, ParmList_str_defaultargs(p));
|
String *parmstring = cparse_cplusplus ? ParmList_str_defaultargs(p) : ParmList_str(p);
|
||||||
|
String *tmp = NewStringf("%s(%s)", mangled, parmstring);
|
||||||
body = SwigType_str(type,tmp);
|
body = SwigType_str(type,tmp);
|
||||||
Delete(tmp);
|
|
||||||
Printv(body,code,"\n",NIL);
|
Printv(body,code,"\n",NIL);
|
||||||
Setattr(n,"wrap:code",body);
|
Setattr(n,"wrap:code",body);
|
||||||
|
Delete(tmp);
|
||||||
Delete(body);
|
Delete(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -844,12 +856,13 @@ Swig_ConstructorToFunction(Node *n, String *classname,
|
||||||
|
|
||||||
/* See if there is any code that we need to emit */
|
/* See if there is any code that we need to emit */
|
||||||
if (!defaultargs && code) {
|
if (!defaultargs && code) {
|
||||||
String *body, *tmp;
|
String *body;
|
||||||
tmp = NewStringf("%s(%s)", mangled, ParmList_str_defaultargs(parms));
|
String *parmstring = cparse_cplusplus ? ParmList_str_defaultargs(parms) : ParmList_str(parms);
|
||||||
|
String *tmp = NewStringf("%s(%s)", mangled, parmstring);
|
||||||
body = SwigType_str(type,tmp);
|
body = SwigType_str(type,tmp);
|
||||||
Delete(tmp);
|
|
||||||
Printv(body,code,"\n",NIL);
|
Printv(body,code,"\n",NIL);
|
||||||
Setattr(n,"wrap:code",body);
|
Setattr(n,"wrap:code",body);
|
||||||
|
Delete(tmp);
|
||||||
Delete(body);
|
Delete(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -942,7 +955,8 @@ Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags)
|
||||||
mangled = Swig_name_mangle(membername);
|
mangled = Swig_name_mangle(membername);
|
||||||
code = Getattr(n,"code");
|
code = Getattr(n,"code");
|
||||||
if (code) {
|
if (code) {
|
||||||
String *s = NewStringf("void %s(%s)", mangled, ParmList_str(p));
|
String *parmstring = cparse_cplusplus ? ParmList_str_defaultargs(p) : ParmList_str(p);
|
||||||
|
String *s = NewStringf("void %s(%s)", mangled, parmstring);
|
||||||
Printv(s,code,"\n",NIL);
|
Printv(s,code,"\n",NIL);
|
||||||
Setattr(n,"wrap:code",s);
|
Setattr(n,"wrap:code",s);
|
||||||
Delete(s);
|
Delete(s);
|
||||||
|
|
@ -1011,7 +1025,8 @@ Swig_MembersetToFunction(Node *n, String *classname, int flags) {
|
||||||
if (flags & CWRAP_EXTEND) {
|
if (flags & CWRAP_EXTEND) {
|
||||||
String *code = Getattr(n,"code");
|
String *code = Getattr(n,"code");
|
||||||
if (code) {
|
if (code) {
|
||||||
String *s = NewStringf("void %s(%s)", mangled, ParmList_str(parms));
|
String *parmstring = cparse_cplusplus ? ParmList_str_defaultargs(parms) : ParmList_str(parms);
|
||||||
|
String *s = NewStringf("void %s(%s)", mangled, parmstring);
|
||||||
Printv(s,code,"\n",NIL);
|
Printv(s,code,"\n",NIL);
|
||||||
Setattr(n,"wrap:code",s);
|
Setattr(n,"wrap:code",s);
|
||||||
Delete(s);
|
Delete(s);
|
||||||
|
|
@ -1068,7 +1083,8 @@ Swig_MembergetToFunction(Node *n, String *classname, int flags) {
|
||||||
if (flags & CWRAP_EXTEND) {
|
if (flags & CWRAP_EXTEND) {
|
||||||
String *code = Getattr(n,"code");
|
String *code = Getattr(n,"code");
|
||||||
if (code) {
|
if (code) {
|
||||||
String *tmp = NewStringf("%s(%s)", mangled, ParmList_str(parms));
|
String *parmstring = cparse_cplusplus ? ParmList_str_defaultargs(parms) : ParmList_str(parms);
|
||||||
|
String *tmp = NewStringf("%s(%s)", mangled, parmstring);
|
||||||
String *s = SwigType_str(ty,tmp);
|
String *s = SwigType_str(ty,tmp);
|
||||||
Delete(tmp);
|
Delete(tmp);
|
||||||
Printv(s,code,"\n",NIL);
|
Printv(s,code,"\n",NIL);
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ Parm *CopyParm(Parm *p) {
|
||||||
String *ignore;
|
String *ignore;
|
||||||
String *alttype;
|
String *alttype;
|
||||||
String *byname;
|
String *byname;
|
||||||
|
String *compactdefargs;
|
||||||
|
|
||||||
Parm *np = NewHash();
|
Parm *np = NewHash();
|
||||||
t = Getattr(p,"type");
|
t = Getattr(p,"type");
|
||||||
|
|
@ -57,6 +58,7 @@ Parm *CopyParm(Parm *p) {
|
||||||
ignore = Getattr(p,"ignore");
|
ignore = Getattr(p,"ignore");
|
||||||
alttype = Getattr(p,"alttype");
|
alttype = Getattr(p,"alttype");
|
||||||
byname = Getattr(p, "arg:byname");
|
byname = Getattr(p, "arg:byname");
|
||||||
|
compactdefargs = Getattr(p, "compactdefargs");
|
||||||
|
|
||||||
if (t)
|
if (t)
|
||||||
Setattr(np,"type",Copy(t));
|
Setattr(np,"type",Copy(t));
|
||||||
|
|
@ -72,6 +74,8 @@ Parm *CopyParm(Parm *p) {
|
||||||
Setattr(np,"alttype", Copy(alttype));
|
Setattr(np,"alttype", Copy(alttype));
|
||||||
if (byname)
|
if (byname)
|
||||||
Setattr(np, "arg:byname", Copy(byname));
|
Setattr(np, "arg:byname", Copy(byname));
|
||||||
|
if (compactdefargs)
|
||||||
|
Setattr(np, "compactdefargs", Copy(compactdefargs));
|
||||||
|
|
||||||
Setfile(np,Getfile(p));
|
Setfile(np,Getfile(p));
|
||||||
Setline(np,Getline(p));
|
Setline(np,Getline(p));
|
||||||
|
|
@ -218,5 +222,29 @@ String *ParmList_protostr(ParmList *p) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------
|
||||||
|
* ParmList_is_compactdefargs()
|
||||||
|
*
|
||||||
|
* Returns 1 if the parameter list passed in is marked for compact argument
|
||||||
|
* handling (by the "compactdefargs" attribute). Otherwise returns 0.
|
||||||
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int ParmList_is_compactdefargs(ParmList *p) {
|
||||||
|
int compactdefargs = 0;
|
||||||
|
|
||||||
|
if (p) {
|
||||||
|
compactdefargs = Getattr(p,"compactdefargs") ? 1 : 0;
|
||||||
|
|
||||||
|
/* The "compactdefargs" attribute should only be set on the first parameter in the list.
|
||||||
|
* However, sometimes an extra parameter is inserted at the beginning of the parameter list,
|
||||||
|
* so we check the 2nd parameter too. */
|
||||||
|
if (!compactdefargs) {
|
||||||
|
Parm *nextparm = nextSibling(p);
|
||||||
|
compactdefargs = (nextparm && Getattr(nextparm,"compactdefargs")) ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return compactdefargs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -334,6 +334,7 @@ extern int ParmList_numrequired(ParmList *);
|
||||||
extern String *ParmList_str(ParmList *);
|
extern String *ParmList_str(ParmList *);
|
||||||
extern String *ParmList_str_defaultargs(ParmList *);
|
extern String *ParmList_str_defaultargs(ParmList *);
|
||||||
extern String *ParmList_protostr(ParmList *);
|
extern String *ParmList_protostr(ParmList *);
|
||||||
|
extern int ParmList_is_compactdefargs(ParmList *p);
|
||||||
|
|
||||||
/* --- Parse tree support --- */
|
/* --- Parse tree support --- */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue