Various cleanup.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@629 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
34bcab20dd
commit
27eee69dbd
6 changed files with 104 additions and 80 deletions
|
|
@ -467,8 +467,8 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
p = Firstitem(l);
|
||||||
for (i = 0; i < pcount; ++i) {
|
for (i = 0; i < pcount; ++i) {
|
||||||
Parm *p = Getitem(l,i);
|
|
||||||
DataType *pt = Gettype(p);
|
DataType *pt = Gettype(p);
|
||||||
char *pn = Getname(p);
|
char *pn = Getname(p);
|
||||||
|
|
||||||
|
|
@ -520,6 +520,7 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
||||||
Printv(cleanup, tm, "\n", 0);
|
Printv(cleanup, tm, "\n", 0);
|
||||||
mreplace (cleanup, argnum, arg, proc_name);
|
mreplace (cleanup, argnum, arg, proc_name);
|
||||||
}
|
}
|
||||||
|
p = Nextitem(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now write code to make the function call
|
// Now write code to make the function call
|
||||||
|
|
|
||||||
|
|
@ -538,6 +538,7 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
||||||
DOHString *cleanup, *outarg, *body;
|
DOHString *cleanup, *outarg, *body;
|
||||||
char *javaReturnSignature = 0;
|
char *javaReturnSignature = 0;
|
||||||
DOHString *javaParameterSignature;
|
DOHString *javaParameterSignature;
|
||||||
|
Parm *p;
|
||||||
|
|
||||||
cleanup = NewString("");
|
cleanup = NewString("");
|
||||||
outarg = NewString("");
|
outarg = NewString("");
|
||||||
|
|
@ -593,8 +594,8 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
||||||
int gencomma = 0;
|
int gencomma = 0;
|
||||||
|
|
||||||
// Now walk the function parameter list and generate code to get arguments
|
// Now walk the function parameter list and generate code to get arguments
|
||||||
for (int i = 0; i < pcount ; i++) {
|
p = Firstitem(l);
|
||||||
Parm *p = Getitem(l,i); // Get the ith argument
|
for (int i = 0; i < pcount ; i++, p = Nextitem(l)) {
|
||||||
DataType *pt = Gettype(p);
|
DataType *pt = Gettype(p);
|
||||||
char *pn = Getname(p);
|
char *pn = Getname(p);
|
||||||
char *target_copy = NULL;
|
char *target_copy = NULL;
|
||||||
|
|
@ -1077,8 +1078,8 @@ void JAVA::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l) {
|
||||||
|
|
||||||
int pcount = Len(l);
|
int pcount = Len(l);
|
||||||
|
|
||||||
for (int i = 0; i < pcount ; i++) {
|
Parm *p = Firstitem(l);
|
||||||
Parm *p = Getitem(l,i); // Get the ith argument
|
for (int i = 0; i < pcount ; i++, p = Nextitem(l)) {
|
||||||
DataType *pt = Gettype(p);
|
DataType *pt = Gettype(p);
|
||||||
char *pn = Getname(p);
|
char *pn = Getname(p);
|
||||||
|
|
||||||
|
|
@ -1150,8 +1151,8 @@ void JAVA::cpp_static_func(char *name, char *iname, DataType *t, ParmList *l) {
|
||||||
int pcount = Len(l);
|
int pcount = Len(l);
|
||||||
int gencomma = 0;
|
int gencomma = 0;
|
||||||
|
|
||||||
for (int i = 0; i < pcount ; i++) {
|
Parm *p = Firstitem(l);
|
||||||
Parm *p = Getitem(l,i); // Get the ith argument
|
for (int i = 0; i < pcount ; i++, p = Nextitem(l)) {
|
||||||
DataType *pt = Gettype(p);
|
DataType *pt = Gettype(p);
|
||||||
char *pn = Getname(p);
|
char *pn = Getname(p);
|
||||||
|
|
||||||
|
|
@ -1218,8 +1219,8 @@ void JAVA::cpp_constructor(char *name, char *iname, ParmList *l) {
|
||||||
if(pcount == 0) // We must have a default constructor
|
if(pcount == 0) // We must have a default constructor
|
||||||
have_default_constructor = 1;
|
have_default_constructor = 1;
|
||||||
|
|
||||||
for (int i = 0; i < pcount ; i++) {
|
Parm *p = Firstitem(l);
|
||||||
Parm *p = Getitem(l,i); // Get the ith argument
|
for (int i = 0; i < pcount ; i++, p = Nextitem(l)) {
|
||||||
DataType *pt = Gettype(p);
|
DataType *pt = Gettype(p);
|
||||||
char *pn = Getname(p);
|
char *pn = Getname(p);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
||||||
Wrapper *f;
|
Wrapper *f;
|
||||||
DOHString *cleanup = 0;
|
DOHString *cleanup = 0;
|
||||||
DOHString *proc_name = 0;
|
DOHString *proc_name = 0;
|
||||||
|
Parm *p;
|
||||||
|
|
||||||
DOHString *outarg = 0;
|
DOHString *outarg = 0;
|
||||||
int argout_set = 0;
|
int argout_set = 0;
|
||||||
|
|
@ -321,8 +321,8 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
||||||
// Now write code to extract the parameters (this is super ugly)
|
// Now write code to extract the parameters (this is super ugly)
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < pcount; ++i) {
|
p = Firstitem(l);
|
||||||
Parm *p = Getitem(l,i);
|
for (i = 0; i < pcount; ++i, p = Nextitem(l)) {
|
||||||
DataType *pt = Gettype(p);
|
DataType *pt = Gettype(p);
|
||||||
char *pn = Getname(p);
|
char *pn = Getname(p);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -441,8 +441,10 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
||||||
|
|
||||||
int numreq = 0;
|
int numreq = 0;
|
||||||
int numoptreal = 0;
|
int numoptreal = 0;
|
||||||
for (i = start; i < Len(l); i++) {
|
Parm *p = Firstitem(l);
|
||||||
if (!Getignore(Getitem(l,i))) {
|
for (i = 0; i < start; i++) p = Nextitem(l);
|
||||||
|
for (i = start; p; i++, p = Nextitem(l)) {
|
||||||
|
if (!Getignore(p)) {
|
||||||
if (i >= Len(l) - numopt) numoptreal++;
|
if (i >= Len(l) - numopt) numoptreal++;
|
||||||
else numreq++;
|
else numreq++;
|
||||||
}
|
}
|
||||||
|
|
@ -455,8 +457,10 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
||||||
Printv(f->def, "int argc, VALUE *argv, VALUE self",0);
|
Printv(f->def, "int argc, VALUE *argv, VALUE self",0);
|
||||||
} else {
|
} else {
|
||||||
Printv(f->def, "VALUE self", 0);
|
Printv(f->def, "VALUE self", 0);
|
||||||
for (i = start; i < Len(l); i++) {
|
p = Firstitem(l);
|
||||||
if (!Getignore(Getitem(l,i))) {
|
for (i = 0; i < start; i++) p = Nextitem(l);
|
||||||
|
for (i = start; p; i++, p = Nextitem(l)) {
|
||||||
|
if (!Getignore(p)) {
|
||||||
Printf(f->def,", VALUE varg%d", i);
|
Printf(f->def,", VALUE varg%d", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -465,8 +469,10 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
||||||
|
|
||||||
// Emit all of the local variables for holding arguments.
|
// Emit all of the local variables for holding arguments.
|
||||||
if (vararg) {
|
if (vararg) {
|
||||||
for (i = start; i < Len(l); i++) {
|
p = Firstitem(l);
|
||||||
if (!Getignore(Getitem(l,i))) {
|
for (i = 0; i < start; i++) p = Nextitem(l);
|
||||||
|
for (i = start; p; i++, p = Nextitem(l)) {
|
||||||
|
if (!Getignore(p)) {
|
||||||
char s[256];
|
char s[256];
|
||||||
sprintf(s,"varg%d",i);
|
sprintf(s,"varg%d",i);
|
||||||
Wrapper_add_localv(f,s,"VALUE",s,0);
|
Wrapper_add_localv(f,s,"VALUE",s,0);
|
||||||
|
|
@ -495,8 +501,10 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
||||||
// Emit count to check the number of arguments
|
// Emit count to check the number of arguments
|
||||||
if (vararg) {
|
if (vararg) {
|
||||||
Printf(f->code," rb_scan_args(argc, argv, \"%d%d\"", (numarg-numoptreal), numoptreal);
|
Printf(f->code," rb_scan_args(argc, argv, \"%d%d\"", (numarg-numoptreal), numoptreal);
|
||||||
for (i = start; i < Len(l); i++) {
|
p = Firstitem(l);
|
||||||
if (!Getignore(Getitem(l,i))) {
|
for (i = 0; i < start; i++) p = Nextitem(l);
|
||||||
|
for (i = start; p; i++, p = Nextitem(l)) {
|
||||||
|
if (!Getignore(p)) {
|
||||||
Printf(f->code,", &varg%d", i);
|
Printf(f->code,", &varg%d", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -507,8 +515,8 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
||||||
// to get arguments
|
// to get arguments
|
||||||
int j = 0; // Total number of non-optional arguments
|
int j = 0; // Total number of non-optional arguments
|
||||||
|
|
||||||
for (i = 0; i < pcount ; i++) {
|
p = Firstitem(l);
|
||||||
Parm *p = Getitem(l,i);
|
for (i = 0; i < pcount ; i++, p = Nextitem(l)) {
|
||||||
DataType *pt = Gettype(p);
|
DataType *pt = Gettype(p);
|
||||||
char *pn = Getname(p);
|
char *pn = Getname(p);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,70 +17,49 @@ static char cvsroot[] = "$Header$";
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Synopsis
|
* Synopsis
|
||||||
*
|
*
|
||||||
* One of the biggest problems in wrapper generation is that of defining
|
* One of the problems in creating wrappers is that of defining rules for
|
||||||
* the handling of various datatypes and function parameters. This module
|
* managing various datatypes and function parameters. In SWIG1.1,
|
||||||
* provides support for a generic object known as a 'mapping rule' that is
|
* this sort of customization was managed using a mechanism known as
|
||||||
* defined using the %map directive like this:
|
* "typemaps". This module generalizes the idea even further and provides
|
||||||
|
* generic set of functions that can be used to define and match rules
|
||||||
|
* that are associated with lists of datatypes.
|
||||||
*
|
*
|
||||||
* %map rulename(typelist) {
|
* The functions in this file are intended to be rather generic. They are only
|
||||||
* vars;
|
* responsible for the storage and matching of rules. Other parts of the
|
||||||
* rule1 { ... }
|
* code can use these to implement typemaps, argmaps, or anything else.
|
||||||
* rule2 { ... }
|
|
||||||
* rule3 { ... }
|
|
||||||
* rule4 { ... }
|
|
||||||
* ...
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* A mapping rule is somewhat similar to a class or structure definition. The
|
|
||||||
* "vars" field is a list of variable declarations that will be local to the
|
|
||||||
* mapping rule when it is used. The "rulen" fields simply define code
|
|
||||||
* fragments and other information that language specific modules can examine
|
|
||||||
* for their own nefarious purposes.
|
|
||||||
*
|
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Swig_map_add()
|
* Swig_map_add_parmrule()
|
||||||
*
|
*
|
||||||
* Adds a new mapping rule. The parms input to this function should be a
|
* Adds a new mapping rule for a list of parameters. The parms input to this
|
||||||
* properly constructed parameter list with associated attributes. The rules
|
* function should be a properly constructed parameter list with associated
|
||||||
* field can technically be any valid object.
|
* attributes (type and name). The 'obj' attribute can be any DOH object.
|
||||||
*
|
*
|
||||||
* The structure of how data is stored is as follows:
|
* The structure of how data might be stored is as follows:
|
||||||
*
|
*
|
||||||
* ruleset (hash)
|
* ruleset (hash)
|
||||||
* --------------
|
* --------------
|
||||||
* rulename ------> nameset (hash)
|
* parm1 ---------> rule (hash)
|
||||||
* --------------
|
* -------------
|
||||||
* parm1 ---------> rule (hash)
|
* parm2 -----------> rule (hash)
|
||||||
* -------------
|
* *obj* --> obj ------------
|
||||||
* parm2 -----------> rule (hash)
|
* parm3
|
||||||
* *obj* --> obj
|
* *obj* -->obj
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* For multiple arguments, we end up building a large tree of hash tables.
|
* For multiple arguments, we end up building a large tree of hash tables.
|
||||||
* The object will be stored in the *obj* attribute of the last hash table.
|
* The object will be stored in the *obj* attribute of the last hash table.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
Swig_map_add(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, DOH *obj)
|
Swig_map_add_parmrule(DOHHash *ruleset, DOHHash *parms, DOH *obj)
|
||||||
{
|
{
|
||||||
|
|
||||||
DOHHash *nameset;
|
|
||||||
DOHHash *p, *n;
|
DOHHash *p, *n;
|
||||||
/* Locate the appropriate nameset */
|
|
||||||
|
|
||||||
nameset = Getattr(ruleset,rulename);
|
/* Walk down the parms list and create a series of hash tables */
|
||||||
if (!nameset) {
|
|
||||||
/* Hmmm. First time we've seen this. Let's add it to our mapping table */
|
|
||||||
nameset = NewHash();
|
|
||||||
Setattr(ruleset,rulename,nameset);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now, we walk down the parms list and create a series of hash tables */
|
|
||||||
|
|
||||||
p = parms;
|
p = parms;
|
||||||
n = nameset;
|
n = ruleset;
|
||||||
|
|
||||||
while (p) {
|
while (p) {
|
||||||
DOHString *ty, *name, *key;
|
DOHString *ty, *name, *key;
|
||||||
DOHHash *nn;
|
DOHHash *nn;
|
||||||
|
|
@ -107,14 +86,32 @@ Swig_map_add(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, DOH
|
||||||
We'll stick our object there */
|
We'll stick our object there */
|
||||||
|
|
||||||
Setattr(n,"*obj*",obj);
|
Setattr(n,"*obj*",obj);
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* Swig_map_add_typerule()
|
||||||
|
*
|
||||||
|
* Adds a rule for a single type and name.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void
|
||||||
|
Swig_map_add_typerule(DOHHash *ruleset, DOH *type, DOHString_or_char *name, DOH *obj) {
|
||||||
|
DOHHash *p;
|
||||||
|
|
||||||
|
p = NewHash();
|
||||||
|
Setattr(p,"type",type);
|
||||||
|
if (name)
|
||||||
|
Setattr(p,"name", name);
|
||||||
|
|
||||||
|
Swig_map_add_parmrule(ruleset,p,obj);
|
||||||
|
Delete(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef struct MatchObject {
|
typedef struct MatchObject {
|
||||||
DOH *ruleset; /* Hash table of rules */
|
DOH *ruleset; /* Hash table of rules */
|
||||||
DOHHash *p; /* Parameter on which checking starts */
|
DOHHash *p; /* Parameter on which checking starts */
|
||||||
int depth; /* Depth of the match */
|
int depth; /* Depth of the match */
|
||||||
struct MatchObject *next; /* Next match object */
|
struct MatchObject *next; /* Next match object */
|
||||||
} MatchObject;
|
} MatchObject;
|
||||||
|
|
||||||
|
|
@ -122,7 +119,7 @@ typedef struct MatchObject {
|
||||||
static MatchObject *matchstack = 0;
|
static MatchObject *matchstack = 0;
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Swig_map_match()
|
* Swig_map_match_parms()
|
||||||
*
|
*
|
||||||
* Perform a longest map match for a list of parameters and a set of mapping rules.
|
* Perform a longest map match for a list of parameters and a set of mapping rules.
|
||||||
* Returns the corresponding rule object and the number of parameters that were
|
* Returns the corresponding rule object and the number of parameters that were
|
||||||
|
|
@ -130,9 +127,8 @@ static MatchObject *matchstack = 0;
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
DOH *
|
DOH *
|
||||||
Swig_map_match(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, int *nmatch)
|
Swig_map_match_parms(DOHHash *ruleset, DOHHash *parms, int *nmatch)
|
||||||
{
|
{
|
||||||
DOHHash *nameset;
|
|
||||||
MatchObject *mo;
|
MatchObject *mo;
|
||||||
|
|
||||||
DOH *bestobj = 0;
|
DOH *bestobj = 0;
|
||||||
|
|
@ -140,12 +136,8 @@ Swig_map_match(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, in
|
||||||
|
|
||||||
*nmatch = 0;
|
*nmatch = 0;
|
||||||
|
|
||||||
/* Get the nameset */
|
|
||||||
nameset = Getattr(ruleset,rulename);
|
|
||||||
if (!nameset) return 0;
|
|
||||||
|
|
||||||
mo = (MatchObject *) malloc(sizeof(MatchObject));
|
mo = (MatchObject *) malloc(sizeof(MatchObject));
|
||||||
mo->ruleset = nameset;
|
mo->ruleset = ruleset;
|
||||||
mo->depth = 0;
|
mo->depth = 0;
|
||||||
mo->p = parms;
|
mo->p = parms;
|
||||||
mo->next = 0;
|
mo->next = 0;
|
||||||
|
|
@ -312,7 +304,7 @@ Swig_map_match(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, in
|
||||||
DOHString *dty = SwigType_default(Getattr(parms,"type"));
|
DOHString *dty = SwigType_default(Getattr(parms,"type"));
|
||||||
key = NewStringf("-%s",dty);
|
key = NewStringf("-%s",dty);
|
||||||
|
|
||||||
rs = Getattr(nameset,key);
|
rs = Getattr(ruleset,key);
|
||||||
if (rs) {
|
if (rs) {
|
||||||
bestobj = Getattr(rs,"*obj*");
|
bestobj = Getattr(rs,"*obj*");
|
||||||
if (bestobj) *nmatch = 1;
|
if (bestobj) *nmatch = 1;
|
||||||
|
|
@ -322,3 +314,25 @@ Swig_map_match(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, in
|
||||||
}
|
}
|
||||||
return bestobj;
|
return bestobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* Swig_map_match_type()
|
||||||
|
*
|
||||||
|
* Match a rule for a single type
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
DOH *
|
||||||
|
Swig_map_match_type(DOHHash *ruleset, DOH *type, DOHString_or_char *name) {
|
||||||
|
DOHHash *p;
|
||||||
|
DOH *obj;
|
||||||
|
int nmatch;
|
||||||
|
|
||||||
|
p = NewHash();
|
||||||
|
Setattr(p,"type",type);
|
||||||
|
if (name)
|
||||||
|
Setattr(p,"name",name);
|
||||||
|
|
||||||
|
obj = Swig_map_match_parms(ruleset,p,&nmatch);
|
||||||
|
Delete(p);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -317,8 +317,8 @@ extern char *Swig_name_destroy(DOHString_or_char *classname);
|
||||||
|
|
||||||
/* --- Mapping interface --- */
|
/* --- Mapping interface --- */
|
||||||
|
|
||||||
extern void Swig_map_add(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, DOH *obj);
|
extern void Swig_map_add(DOHHash *ruleset, DOHHash *parms, DOH *obj);
|
||||||
extern DOH *Swig_map_match(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, int *nmatch);
|
extern DOH *Swig_map_match(DOHHash *ruleset, DOHHash *parms, int *nmatch);
|
||||||
|
|
||||||
/* --- Misc --- */
|
/* --- Misc --- */
|
||||||
extern char *Swig_copy_string(const char *c);
|
extern char *Swig_copy_string(const char *c);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue