Various cleanup.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@629 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-08-07 21:18:24 +00:00
commit 27eee69dbd
6 changed files with 104 additions and 80 deletions

View file

@ -467,8 +467,8 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
i = 0;
int j = 0;
p = Firstitem(l);
for (i = 0; i < pcount; ++i) {
Parm *p = Getitem(l,i);
DataType *pt = Gettype(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);
mreplace (cleanup, argnum, arg, proc_name);
}
p = Nextitem(l);
}
// Now write code to make the function call

View file

@ -538,6 +538,7 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
DOHString *cleanup, *outarg, *body;
char *javaReturnSignature = 0;
DOHString *javaParameterSignature;
Parm *p;
cleanup = NewString("");
outarg = NewString("");
@ -593,8 +594,8 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
int gencomma = 0;
// Now walk the function parameter list and generate code to get arguments
for (int i = 0; i < pcount ; i++) {
Parm *p = Getitem(l,i); // Get the ith argument
p = Firstitem(l);
for (int i = 0; i < pcount ; i++, p = Nextitem(l)) {
DataType *pt = Gettype(p);
char *pn = Getname(p);
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);
for (int i = 0; i < pcount ; i++) {
Parm *p = Getitem(l,i); // Get the ith argument
Parm *p = Firstitem(l);
for (int i = 0; i < pcount ; i++, p = Nextitem(l)) {
DataType *pt = Gettype(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 gencomma = 0;
for (int i = 0; i < pcount ; i++) {
Parm *p = Getitem(l,i); // Get the ith argument
Parm *p = Firstitem(l);
for (int i = 0; i < pcount ; i++, p = Nextitem(l)) {
DataType *pt = Gettype(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
have_default_constructor = 1;
for (int i = 0; i < pcount ; i++) {
Parm *p = Getitem(l,i); // Get the ith argument
Parm *p = Firstitem(l);
for (int i = 0; i < pcount ; i++, p = Nextitem(l)) {
DataType *pt = Gettype(p);
char *pn = Getname(p);

View file

@ -281,7 +281,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
Wrapper *f;
DOHString *cleanup = 0;
DOHString *proc_name = 0;
Parm *p;
DOHString *outarg = 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)
int i = 0;
for (i = 0; i < pcount; ++i) {
Parm *p = Getitem(l,i);
p = Firstitem(l);
for (i = 0; i < pcount; ++i, p = Nextitem(l)) {
DataType *pt = Gettype(p);
char *pn = Getname(p);

View file

@ -441,8 +441,10 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
int numreq = 0;
int numoptreal = 0;
for (i = start; i < Len(l); i++) {
if (!Getignore(Getitem(l,i))) {
Parm *p = Firstitem(l);
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++;
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);
} else {
Printv(f->def, "VALUE self", 0);
for (i = start; i < Len(l); i++) {
if (!Getignore(Getitem(l,i))) {
p = Firstitem(l);
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);
}
}
@ -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.
if (vararg) {
for (i = start; i < Len(l); i++) {
if (!Getignore(Getitem(l,i))) {
p = Firstitem(l);
for (i = 0; i < start; i++) p = Nextitem(l);
for (i = start; p; i++, p = Nextitem(l)) {
if (!Getignore(p)) {
char s[256];
sprintf(s,"varg%d",i);
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
if (vararg) {
Printf(f->code," rb_scan_args(argc, argv, \"%d%d\"", (numarg-numoptreal), numoptreal);
for (i = start; i < Len(l); i++) {
if (!Getignore(Getitem(l,i))) {
p = Firstitem(l);
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);
}
}
@ -507,8 +515,8 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
// to get arguments
int j = 0; // Total number of non-optional arguments
for (i = 0; i < pcount ; i++) {
Parm *p = Getitem(l,i);
p = Firstitem(l);
for (i = 0; i < pcount ; i++, p = Nextitem(l)) {
DataType *pt = Gettype(p);
char *pn = Getname(p);

View file

@ -17,70 +17,49 @@ static char cvsroot[] = "$Header$";
/* -----------------------------------------------------------------------------
* Synopsis
*
* One of the biggest problems in wrapper generation is that of defining
* the handling of various datatypes and function parameters. This module
* provides support for a generic object known as a 'mapping rule' that is
* defined using the %map directive like this:
* One of the problems in creating wrappers is that of defining rules for
* managing various datatypes and function parameters. In SWIG1.1,
* this sort of customization was managed using a mechanism known as
* "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) {
* vars;
* rule1 { ... }
* 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.
*
* The functions in this file are intended to be rather generic. They are only
* responsible for the storage and matching of rules. Other parts of the
* code can use these to implement typemaps, argmaps, or anything else.
* ----------------------------------------------------------------------------- */
/* -----------------------------------------------------------------------------
* Swig_map_add()
* Swig_map_add_parmrule()
*
* Adds a new mapping rule. The parms input to this function should be a
* properly constructed parameter list with associated attributes. The rules
* field can technically be any valid object.
* Adds a new mapping rule for a list of parameters. The parms input to this
* function should be a properly constructed parameter list with associated
* 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)
* --------------
* rulename ------> nameset (hash)
* --------------
* parm1 ---------> rule (hash)
* -------------
* parm2 -----------> rule (hash)
* *obj* --> obj
* parm1 ---------> rule (hash)
* -------------
* parm2 -----------> rule (hash)
* *obj* --> obj ------------
* parm3
* *obj* -->obj
*
*
* 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.
* ----------------------------------------------------------------------------- */
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;
/* Locate the appropriate nameset */
nameset = Getattr(ruleset,rulename);
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 */
/* Walk down the parms list and create a series of hash tables */
p = parms;
n = nameset;
n = ruleset;
while (p) {
DOHString *ty, *name, *key;
DOHHash *nn;
@ -107,14 +86,32 @@ Swig_map_add(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, DOH
We'll stick our object there */
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 {
DOH *ruleset; /* Hash table of rules */
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 */
} MatchObject;
@ -122,7 +119,7 @@ typedef struct MatchObject {
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.
* Returns the corresponding rule object and the number of parameters that were
@ -130,9 +127,8 @@ static MatchObject *matchstack = 0;
* ----------------------------------------------------------------------------- */
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;
DOH *bestobj = 0;
@ -140,12 +136,8 @@ Swig_map_match(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, in
*nmatch = 0;
/* Get the nameset */
nameset = Getattr(ruleset,rulename);
if (!nameset) return 0;
mo = (MatchObject *) malloc(sizeof(MatchObject));
mo->ruleset = nameset;
mo->ruleset = ruleset;
mo->depth = 0;
mo->p = parms;
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"));
key = NewStringf("-%s",dty);
rs = Getattr(nameset,key);
rs = Getattr(ruleset,key);
if (rs) {
bestobj = Getattr(rs,"*obj*");
if (bestobj) *nmatch = 1;
@ -322,3 +314,25 @@ Swig_map_match(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, in
}
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;
}

View file

@ -317,8 +317,8 @@ extern char *Swig_name_destroy(DOHString_or_char *classname);
/* --- Mapping interface --- */
extern void Swig_map_add(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, DOH *obj);
extern DOH *Swig_map_match(DOHHash *ruleset, DOHString_or_char *rulename, DOHHash *parms, int *nmatch);
extern void Swig_map_add(DOHHash *ruleset, DOHHash *parms, DOH *obj);
extern DOH *Swig_map_match(DOHHash *ruleset, DOHHash *parms, int *nmatch);
/* --- Misc --- */
extern char *Swig_copy_string(const char *c);