API cleanup
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9630 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
264b7dff90
commit
52dcbb9001
5 changed files with 72 additions and 78 deletions
|
|
@ -1170,7 +1170,7 @@ static void new_feature(const char *featurename, String *val, Hash *featureattri
|
||||||
|
|
||||||
/* Create a parameter list for the new feature by copying all
|
/* Create a parameter list for the new feature by copying all
|
||||||
but the last (defaulted) parameter */
|
but the last (defaulted) parameter */
|
||||||
ParmList* newparms = ParmList_copy_all_except_last_parm(declparms);
|
ParmList* newparms = CopyParmListMax(declparms, ParmList_len(declparms)-1);
|
||||||
|
|
||||||
/* Create new declaration - with the last parameter removed */
|
/* Create new declaration - with the last parameter removed */
|
||||||
SwigType *newtype = Copy(type);
|
SwigType *newtype = Copy(type);
|
||||||
|
|
@ -1246,7 +1246,7 @@ static void default_arguments(Node *n) {
|
||||||
|
|
||||||
/* Create a parameter list for the new function by copying all
|
/* Create a parameter list for the new function by copying all
|
||||||
but the last (defaulted) parameter */
|
but the last (defaulted) parameter */
|
||||||
ParmList* newparms = ParmList_copy_all_except_last_parm(parms);
|
ParmList* newparms = CopyParmListMax(parms,ParmList_len(parms)-1);
|
||||||
|
|
||||||
/* Create new function and add to symbol table */
|
/* Create new function and add to symbol table */
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1371,7 +1371,7 @@ void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *ne
|
||||||
|
|
||||||
/* Create a parameter list for the new rename by copying all
|
/* Create a parameter list for the new rename by copying all
|
||||||
but the last (defaulted) parameter */
|
but the last (defaulted) parameter */
|
||||||
ParmList *newparms = ParmList_copy_all_except_last_parm(declparms);
|
ParmList *newparms = CopyParmListMax(declparms,ParmList_len(declparms)-1);
|
||||||
|
|
||||||
/* Create new declaration - with the last parameter removed */
|
/* Create new declaration - with the last parameter removed */
|
||||||
SwigType *newdecl = Copy(decl);
|
SwigType *newdecl = Copy(decl);
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,10 @@ Parm *NewParm(SwigType *type, const String_or_char *name) {
|
||||||
set_nodeType(p, "parm");
|
set_nodeType(p, "parm");
|
||||||
if (type) {
|
if (type) {
|
||||||
SwigType *ntype = Copy(type);
|
SwigType *ntype = Copy(type);
|
||||||
Setattr(p, k_type, ntype);
|
Setattr(p, "type", ntype);
|
||||||
Delete(ntype);
|
Delete(ntype);
|
||||||
}
|
}
|
||||||
Setattr(p, k_name, name);
|
Setattr(p, "name", name);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,59 +52,59 @@ Parm *NewParmFromNode(SwigType *type, const String_or_char *name, Node *n) {
|
||||||
|
|
||||||
Parm *CopyParm(Parm *p) {
|
Parm *CopyParm(Parm *p) {
|
||||||
Parm *np = NewHash();
|
Parm *np = NewHash();
|
||||||
SwigType *t = Getattr(p, k_type);
|
SwigType *t = Getattr(p, "type");
|
||||||
String *name = Getattr(p, k_name);
|
String *name = Getattr(p, "name");
|
||||||
String *lname = Getattr(p, k_lname);
|
String *lname = Getattr(p, "lname");
|
||||||
String *value = Getattr(p, k_value);
|
String *value = Getattr(p, "value");
|
||||||
String *ignore = Getattr(p, k_ignore);
|
String *ignore = Getattr(p, "ignore");
|
||||||
String *alttype = Getattr(p, k_alttype);
|
String *alttype = Getattr(p, "alttype");
|
||||||
String *byname = Getattr(p, k_argbyname);
|
String *byname = Getattr(p, "arg:byname");
|
||||||
String *compactdefargs = Getattr(p, k_compactdefargs);
|
String *compactdefargs = Getattr(p, "compactdefargs");
|
||||||
String *self = Getattr(p, k_self);
|
String *self = Getattr(p, "self");
|
||||||
|
|
||||||
if (t) {
|
if (t) {
|
||||||
SwigType *nt = Copy(t);
|
SwigType *nt = Copy(t);
|
||||||
Setattr(np, k_type, nt);
|
Setattr(np, "type", nt);
|
||||||
Delete(nt);
|
Delete(nt);
|
||||||
}
|
}
|
||||||
if (name) {
|
if (name) {
|
||||||
String *str = Copy(name);
|
String *str = Copy(name);
|
||||||
Setattr(np, k_name, str);
|
Setattr(np, "name", str);
|
||||||
Delete(str);
|
Delete(str);
|
||||||
}
|
}
|
||||||
if (lname) {
|
if (lname) {
|
||||||
String *str = Copy(lname);
|
String *str = Copy(lname);
|
||||||
Setattr(np, k_lname, str);
|
Setattr(np, "lname", str);
|
||||||
Delete(str);
|
Delete(str);
|
||||||
}
|
}
|
||||||
if (value) {
|
if (value) {
|
||||||
String *str = Copy(value);
|
String *str = Copy(value);
|
||||||
Setattr(np, k_value, str);
|
Setattr(np, "value", str);
|
||||||
Delete(str);
|
Delete(str);
|
||||||
}
|
}
|
||||||
if (ignore) {
|
if (ignore) {
|
||||||
String *str = Copy(ignore);
|
String *str = Copy(ignore);
|
||||||
Setattr(np, k_ignore, str);
|
Setattr(np, "ignore", str);
|
||||||
Delete(str);
|
Delete(str);
|
||||||
}
|
}
|
||||||
if (alttype) {
|
if (alttype) {
|
||||||
String *str = Copy(alttype);
|
String *str = Copy(alttype);
|
||||||
Setattr(np, k_alttype, str);
|
Setattr(np, "alttype", str);
|
||||||
Delete(str);
|
Delete(str);
|
||||||
}
|
}
|
||||||
if (byname) {
|
if (byname) {
|
||||||
String *str = Copy(byname);
|
String *str = Copy(byname);
|
||||||
Setattr(np, k_argbyname, str);
|
Setattr(np, "arg:byname", str);
|
||||||
Delete(str);
|
Delete(str);
|
||||||
}
|
}
|
||||||
if (compactdefargs) {
|
if (compactdefargs) {
|
||||||
String *str = Copy(compactdefargs);
|
String *str = Copy(compactdefargs);
|
||||||
Setattr(np, k_compactdefargs, str);
|
Setattr(np, "compactdefargs", str);
|
||||||
Delete(str);
|
Delete(str);
|
||||||
}
|
}
|
||||||
if (self) {
|
if (self) {
|
||||||
String *str = Copy(self);
|
String *str = Copy(self);
|
||||||
Setattr(np, k_self, str);
|
Setattr(np, "self", str);
|
||||||
Delete(str);
|
Delete(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,10 +115,11 @@ Parm *CopyParm(Parm *p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------
|
/* ------------------------------------------------------------------
|
||||||
|
* CopyParmListMax()
|
||||||
* CopyParmList()
|
* CopyParmList()
|
||||||
* ------------------------------------------------------------------ */
|
* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
ParmList *CopyParmList(ParmList *p) {
|
ParmList *CopyParmListMax(ParmList *p, int count) {
|
||||||
Parm *np;
|
Parm *np;
|
||||||
Parm *pp = 0;
|
Parm *pp = 0;
|
||||||
Parm *fp = 0;
|
Parm *fp = 0;
|
||||||
|
|
@ -127,6 +128,7 @@ ParmList *CopyParmList(ParmList *p) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while (p) {
|
while (p) {
|
||||||
|
if (count == 0) break;
|
||||||
np = CopyParm(p);
|
np = CopyParm(p);
|
||||||
if (pp) {
|
if (pp) {
|
||||||
set_nextSibling(pp, np);
|
set_nextSibling(pp, np);
|
||||||
|
|
@ -136,10 +138,15 @@ ParmList *CopyParmList(ParmList *p) {
|
||||||
}
|
}
|
||||||
pp = np;
|
pp = np;
|
||||||
p = nextSibling(p);
|
p = nextSibling(p);
|
||||||
|
count--;
|
||||||
}
|
}
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ParmList *CopyParmList(ParmList *p) {
|
||||||
|
return CopyParmListMax(p,-1);
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------
|
/* ------------------------------------------------------------------
|
||||||
* int ParmList_numarg()
|
* int ParmList_numarg()
|
||||||
* ------------------------------------------------------------------ */
|
* ------------------------------------------------------------------ */
|
||||||
|
|
@ -147,7 +154,7 @@ ParmList *CopyParmList(ParmList *p) {
|
||||||
int ParmList_numarg(ParmList *p) {
|
int ParmList_numarg(ParmList *p) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (p) {
|
while (p) {
|
||||||
if (!Getattr(p, k_ignore))
|
if (!Getattr(p, "ignore"))
|
||||||
n++;
|
n++;
|
||||||
p = nextSibling(p);
|
p = nextSibling(p);
|
||||||
}
|
}
|
||||||
|
|
@ -161,8 +168,8 @@ int ParmList_numarg(ParmList *p) {
|
||||||
int ParmList_numrequired(ParmList *p) {
|
int ParmList_numrequired(ParmList *p) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (p) {
|
while (p) {
|
||||||
SwigType *t = Getattr(p, k_type);
|
SwigType *t = Getattr(p, "type");
|
||||||
String *value = Getattr(p, k_value);
|
String *value = Getattr(p, "value");
|
||||||
if (value)
|
if (value)
|
||||||
return i;
|
return i;
|
||||||
if (!(SwigType_type(t) == T_VOID))
|
if (!(SwigType_type(t) == T_VOID))
|
||||||
|
|
@ -196,7 +203,7 @@ int ParmList_len(ParmList *p) {
|
||||||
String *ParmList_str(ParmList *p) {
|
String *ParmList_str(ParmList *p) {
|
||||||
String *out = NewStringEmpty();
|
String *out = NewStringEmpty();
|
||||||
while (p) {
|
while (p) {
|
||||||
String *pstr = SwigType_str(Getattr(p, k_type), Getattr(p, k_name));
|
String *pstr = SwigType_str(Getattr(p, "type"), Getattr(p, "name"));
|
||||||
StringAppend(out, pstr);
|
StringAppend(out, pstr);
|
||||||
p = nextSibling(p);
|
p = nextSibling(p);
|
||||||
if (p) {
|
if (p) {
|
||||||
|
|
@ -216,8 +223,8 @@ String *ParmList_str(ParmList *p) {
|
||||||
String *ParmList_str_defaultargs(ParmList *p) {
|
String *ParmList_str_defaultargs(ParmList *p) {
|
||||||
String *out = NewStringEmpty();
|
String *out = NewStringEmpty();
|
||||||
while (p) {
|
while (p) {
|
||||||
String *value = Getattr(p, k_value);
|
String *value = Getattr(p, "value");
|
||||||
String *pstr = SwigType_str(Getattr(p, k_type), Getattr(p, k_name));
|
String *pstr = SwigType_str(Getattr(p, "type"), Getattr(p, "name"));
|
||||||
StringAppend(out, pstr);
|
StringAppend(out, pstr);
|
||||||
if (value) {
|
if (value) {
|
||||||
Printf(out, "=%s", value);
|
Printf(out, "=%s", value);
|
||||||
|
|
@ -240,10 +247,10 @@ String *ParmList_str_defaultargs(ParmList *p) {
|
||||||
String *ParmList_protostr(ParmList *p) {
|
String *ParmList_protostr(ParmList *p) {
|
||||||
String *out = NewStringEmpty();
|
String *out = NewStringEmpty();
|
||||||
while (p) {
|
while (p) {
|
||||||
if (Getattr(p, k_hidden)) {
|
if (Getattr(p, "hidden")) {
|
||||||
p = nextSibling(p);
|
p = nextSibling(p);
|
||||||
} else {
|
} else {
|
||||||
String *pstr = SwigType_str(Getattr(p, k_type), 0);
|
String *pstr = SwigType_str(Getattr(p, "type"), 0);
|
||||||
StringAppend(out, pstr);
|
StringAppend(out, pstr);
|
||||||
p = nextSibling(p);
|
p = nextSibling(p);
|
||||||
if (p) {
|
if (p) {
|
||||||
|
|
@ -266,14 +273,14 @@ int ParmList_is_compactdefargs(ParmList *p) {
|
||||||
int compactdefargs = 0;
|
int compactdefargs = 0;
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
compactdefargs = Getattr(p, k_compactdefargs) ? 1 : 0;
|
compactdefargs = Getattr(p, "compactdefargs") ? 1 : 0;
|
||||||
|
|
||||||
/* The "compactdefargs" attribute should only be set on the first parameter in the list.
|
/* 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,
|
* However, sometimes an extra parameter is inserted at the beginning of the parameter list,
|
||||||
* so we check the 2nd parameter too. */
|
* so we check the 2nd parameter too. */
|
||||||
if (!compactdefargs) {
|
if (!compactdefargs) {
|
||||||
Parm *nextparm = nextSibling(p);
|
Parm *nextparm = nextSibling(p);
|
||||||
compactdefargs = (nextparm && Getattr(nextparm, k_compactdefargs)) ? 1 : 0;
|
compactdefargs = (nextparm && Getattr(nextparm, "compactdefargs")) ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -291,7 +298,7 @@ int ParmList_is_compactdefargs(ParmList *p) {
|
||||||
int ParmList_has_defaultargs(ParmList *p) {
|
int ParmList_has_defaultargs(ParmList *p) {
|
||||||
int default_args = 0;
|
int default_args = 0;
|
||||||
while (p) {
|
while (p) {
|
||||||
if (Getattr(p, k_value)) {
|
if (Getattr(p, "value")) {
|
||||||
default_args = 1;
|
default_args = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -299,30 +306,3 @@ int ParmList_has_defaultargs(ParmList *p) {
|
||||||
}
|
}
|
||||||
return default_args;
|
return default_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------
|
|
||||||
* ParmList_copy_all_except_last_parm()
|
|
||||||
*
|
|
||||||
* Create a new parameter list by copying all the parameters barring the
|
|
||||||
* last parameter.
|
|
||||||
* ---------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
ParmList *ParmList_copy_all_except_last_parm(ParmList *p) {
|
|
||||||
ParmList *newparms = 0;
|
|
||||||
Parm *newparm = 0;
|
|
||||||
Parm *pp = 0;
|
|
||||||
Parm *fp = 0;
|
|
||||||
while (nextSibling(p)) {
|
|
||||||
newparm = CopyParm(p);
|
|
||||||
if (pp) {
|
|
||||||
set_nextSibling(pp, newparm);
|
|
||||||
Delete(newparm);
|
|
||||||
} else {
|
|
||||||
fp = newparm;
|
|
||||||
}
|
|
||||||
pp = newparm;
|
|
||||||
p = nextSibling(p);
|
|
||||||
}
|
|
||||||
newparms = fp;
|
|
||||||
return newparms;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -295,22 +295,7 @@ extern "C" {
|
||||||
|
|
||||||
/* --- Parameters and Parameter Lists --- */
|
/* --- Parameters and Parameter Lists --- */
|
||||||
|
|
||||||
/* Parameters are really just hidden behind a DOH object. The following
|
#include "swigparm.h"
|
||||||
interface will probably be simplified even further. */
|
|
||||||
|
|
||||||
extern Parm *NewParm(SwigType *type, const String_or_char *name);
|
|
||||||
extern Parm *NewParmFromNode(SwigType *type, const String_or_char *name, Node *n);
|
|
||||||
extern Parm *CopyParm(Parm *p);
|
|
||||||
extern ParmList *CopyParmList(ParmList *);
|
|
||||||
extern int ParmList_len(ParmList *);
|
|
||||||
extern int ParmList_numarg(ParmList *);
|
|
||||||
extern int ParmList_numrequired(ParmList *);
|
|
||||||
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);
|
|
||||||
extern ParmList *ParmList_copy_all_except_last_parm(ParmList *p);
|
|
||||||
|
|
||||||
/* --- Parse tree support --- */
|
/* --- Parse tree support --- */
|
||||||
|
|
||||||
|
|
|
||||||
29
Source/Swig/swigparm.h
Normal file
29
Source/Swig/swigparm.h
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* See the LICENSE file for information on copyright, usage and redistribution
|
||||||
|
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||||
|
*
|
||||||
|
* swigparm.h
|
||||||
|
*
|
||||||
|
* Functions related to the handling of function/method parameters and
|
||||||
|
* parameter lists.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/* $Id: swig.h 9629 2006-12-30 18:27:47Z beazley $ */
|
||||||
|
|
||||||
|
/* Individual parameters */
|
||||||
|
extern Parm *NewParm(SwigType *type, const String_or_char *name);
|
||||||
|
extern Parm *NewParmFromNode(SwigType *type, const String_or_char *name, Node *n);
|
||||||
|
extern Parm *CopyParm(Parm *p);
|
||||||
|
|
||||||
|
/* Parameter lists */
|
||||||
|
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 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);
|
||||||
|
extern ParmList *ParmList_copy_all_except_last_parm(ParmList *p);
|
||||||
Loading…
Add table
Add a link
Reference in a new issue