Changed the handling of types in parameter lists and removed the %val
and %out directives. This result of this change is that SWIG does a lot less manipulation of types before they are given to language modules. It also means that a lot of stuff is going to be broken for a short period of time. I am working on cleaning all of this up so give me a few days to sort it out. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@588 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
bb715e08c1
commit
22662ce490
11 changed files with 40 additions and 121 deletions
|
|
@ -2,7 +2,7 @@
|
|||
/* SWIG version information */
|
||||
|
||||
#ifndef SWIG_VERSION
|
||||
#define SWIG_VERSION "1.3u-20000705-2008"
|
||||
#define SWIG_VERSION "1.3u-20000712-1502"
|
||||
#endif
|
||||
|
||||
#ifndef SWIG_SPIN
|
||||
|
|
|
|||
|
|
@ -779,15 +779,22 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
case T_VOID :
|
||||
break;
|
||||
|
||||
// User defined. This is usually invalid. No way to pass a
|
||||
// complex type by "value". We'll just pass into the unsupported
|
||||
// datatype case.
|
||||
|
||||
|
||||
case T_USER:
|
||||
|
||||
// Unsupported data type
|
||||
Putc('O',parse_args);
|
||||
sprintf(source,"_argo%d", i);
|
||||
sprintf(target,"_arg%d", i);
|
||||
sprintf(temp,"argument %d",i+1);
|
||||
|
||||
Wrapper_add_localv(f,source,"PyObject *",source,"=0",0);
|
||||
Printf(arglist,"&%s",source);
|
||||
pt->is_pointer++;
|
||||
get_pointer(iname, temp, source, target, pt, get_pointers, (char*)"NULL");
|
||||
pt->is_pointer--;
|
||||
// Unsupported data type
|
||||
break;
|
||||
|
||||
default :
|
||||
Printf(stderr,"%s : Line %d. Unable to use type %s as a function argument.\n",input_file, line_number, DataType_print_type(pt));
|
||||
break;
|
||||
|
|
@ -795,7 +802,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
// Emit code for parameter list
|
||||
|
||||
if ((pt->type != T_VOID) && (pt->type != T_BOOL))
|
||||
if ((pt->type != T_VOID) && (pt->type != T_BOOL) && (pt->type != T_USER))
|
||||
Printf(arglist,"&_arg%d",i);
|
||||
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1598,11 +1598,11 @@ void cplus_emit_member_func(char *classname, char *classtype, char *classrename,
|
|||
DataType *pt = Parm_Gettype(p);
|
||||
if ((pt->type != T_VOID) || (pt->is_pointer)) {
|
||||
Printf(wrap,",");
|
||||
if ((p->call_type & CALL_REFERENCE) || (pt->is_reference)) {
|
||||
if (pt->is_reference) {
|
||||
pt->is_pointer--;
|
||||
}
|
||||
Printf(wrap, DataType_print_full(pt));
|
||||
if ((p->call_type & CALL_REFERENCE) || (pt->is_reference)) {
|
||||
if (pt->is_reference) {
|
||||
pt->is_pointer++;
|
||||
if (pt->is_reference)
|
||||
Printf(wrap,"&");
|
||||
|
|
@ -1630,7 +1630,6 @@ void cplus_emit_member_func(char *classname, char *classtype, char *classrename,
|
|||
Parm_Settype(p,pt);
|
||||
DelDataType(pt);
|
||||
}
|
||||
p->call_type = 0;
|
||||
Parm_Setname(p,(char*)"self");
|
||||
ParmList_insert(newparms,p,0); // Attach parameter to beginning of list
|
||||
|
||||
|
|
@ -1932,7 +1931,6 @@ void cplus_emit_destructor(char *classname, char *classtype, char *classrename,
|
|||
Parm_Settype(p,pt);
|
||||
DelDataType(pt);
|
||||
}
|
||||
p->call_type = 0;
|
||||
Parm_Setname(p,(char*)"self");
|
||||
ParmList_insert(l,p,0);
|
||||
|
||||
|
|
@ -2058,13 +2056,7 @@ void cplus_emit_constructor(char *classname, char *classtype, char *classrename,
|
|||
DataType *pt = Parm_Gettype(p);
|
||||
|
||||
if ((pt->type != T_VOID) || (pt->is_pointer)) {
|
||||
if (p->call_type & CALL_REFERENCE) {
|
||||
pt->is_pointer--;
|
||||
}
|
||||
Printf(wrap, DataType_str(pt,Parm_Getname(p)));
|
||||
if (p->call_type & CALL_REFERENCE) {
|
||||
pt->is_pointer++;
|
||||
}
|
||||
p = ParmList_next(l);
|
||||
if (p) {
|
||||
Printf(wrap,",");
|
||||
|
|
@ -2252,7 +2244,6 @@ void cplus_emit_variable_get(char *classname, char *classtype, char *classrename
|
|||
DelDataType(pt);
|
||||
}
|
||||
Parm_Setname(p,(char*)"self");
|
||||
p->call_type = 0;
|
||||
|
||||
ParmList_insert(l,p,0);
|
||||
|
||||
|
|
@ -2475,7 +2466,6 @@ void cplus_emit_variable_set(char *classname, char *classtype, char *classrename
|
|||
Parm_Settype(p,pt);
|
||||
DelDataType(pt);
|
||||
}
|
||||
p->call_type = 0;
|
||||
if (mrename)
|
||||
Parm_Setname(p,mrename);
|
||||
else
|
||||
|
|
@ -2491,7 +2481,6 @@ void cplus_emit_variable_set(char *classname, char *classtype, char *classrename
|
|||
Parm_Settype(p,pt);
|
||||
DelDataType(pt);
|
||||
}
|
||||
p->call_type = 0;
|
||||
Parm_Setname(p,(char*)"self");
|
||||
ParmList_insert(l,p,0);
|
||||
|
||||
|
|
|
|||
|
|
@ -202,7 +202,6 @@ int emit_args(DataType *rt, ParmList *l, Wrapper *f) {
|
|||
Wrapper_add_localv(f, "_result", DataType_print_type(rt), "_result",0);
|
||||
rt->is_pointer--;
|
||||
} else {
|
||||
|
||||
// Normal return value
|
||||
Wrapper_add_localv(f, "_result", DataType_print_type(rt), "_result",0);
|
||||
}
|
||||
|
|
@ -220,14 +219,20 @@ int emit_args(DataType *rt, ParmList *l, Wrapper *f) {
|
|||
char *pvalue = Parm_Getvalue(p);
|
||||
char *pname = Parm_Getname(p);
|
||||
if (((pt->is_reference) && (pvalue)) ||
|
||||
((pt->type == T_USER) && (p->call_type == CALL_REFERENCE) && (pvalue))) {
|
||||
((pt->type == T_USER) && (pt->is_pointer == 0) && (pvalue))) {
|
||||
Wrapper_add_localv(f,temp, DataType_print_type(pt), temp," = (", DataType_print_type(pt), ") &", pvalue,0);
|
||||
} else {
|
||||
char deftmp[1024];
|
||||
if (pvalue) {
|
||||
Wrapper_add_localv(f,temp, DataType_print_type(pt), temp, " = (", DataType_print_type(pt), ") ", pvalue, 0);
|
||||
} else {
|
||||
Wrapper_add_localv(f,temp, DataType_print_type(pt), temp, 0);
|
||||
if ((pt->type == T_USER) && (pt->is_pointer == 0)) {
|
||||
pt->is_pointer++;
|
||||
Wrapper_add_localv(f,temp, DataType_print_type(pt), temp, 0);
|
||||
pt->is_pointer--;
|
||||
} else {
|
||||
Wrapper_add_localv(f,temp, DataType_print_type(pt), temp, 0);
|
||||
}
|
||||
}
|
||||
|
||||
tm = typemap_lookup((char*)"arginit", typemap_lang, pt,pname,(char*)"",temp,f);
|
||||
|
|
@ -322,10 +327,7 @@ void emit_func_call(char *decl, DataType *t, ParmList *l, Wrapper *f) {
|
|||
DataType *pt = Parm_Gettype(p);
|
||||
if ((pt->type != T_VOID) || (pt->is_pointer)){
|
||||
Printf(fcall,DataType_print_arraycast(pt));
|
||||
if ((!pt->is_reference) && (p->call_type & CALL_VALUE))
|
||||
Printf(fcall, "&");
|
||||
if ((!(p->call_type & CALL_VALUE)) &&
|
||||
((pt->is_reference) || (p->call_type & CALL_REFERENCE)))
|
||||
if ((pt->is_reference) || ((pt->is_pointer == 0) && (pt->type == T_USER)))
|
||||
Printf(fcall, "*");
|
||||
Printf(fcall, emit_local(i));
|
||||
i++;
|
||||
|
|
|
|||
|
|
@ -449,7 +449,7 @@ static void dump_nested(char *parent) {
|
|||
%left UMINUS NOT LNOT
|
||||
%left DCOLON
|
||||
|
||||
%type <ivalue> extern array array2 parm_specifier parm_specifier_list;
|
||||
%type <ivalue> extern array array2;
|
||||
%type <pl> parms ptail;
|
||||
%type <p> parm parm_type;
|
||||
%type <tmparm> typemap_parm tm_list tm_tail;
|
||||
|
|
@ -1355,21 +1355,6 @@ parm : parm_type {
|
|||
if (typemap_check((char *)"ignore",typemap_lang,Parm_Gettype($$),Parm_Getname($$)))
|
||||
$$->ignore = 1;
|
||||
}
|
||||
| parm_specifier_list parm_type {
|
||||
$$ = $2;
|
||||
$$->call_type = $$->call_type | $1;
|
||||
if (InArray && ($$->call_type & CALL_VALUE)) {
|
||||
fprintf(stderr,"%s : Line %d. Error. Can't use %%val with an array.\n", input_file, line_number);
|
||||
FatalError();
|
||||
}
|
||||
DataType *pt = Parm_Gettype($$);
|
||||
if (!pt->is_pointer) {
|
||||
fprintf(stderr,"%s : Line %d. Error. Can't use %%val or %%out with a non-pointer argument.\n", input_file, line_number);
|
||||
FatalError();
|
||||
} else {
|
||||
pt->is_pointer--;
|
||||
}
|
||||
}
|
||||
|
||||
parm_type : type pname {
|
||||
if (InArray) {
|
||||
|
|
@ -1378,12 +1363,7 @@ parm_type : type pname {
|
|||
DataType_set_arraystr($1, Char(ArrayString));
|
||||
}
|
||||
$$ = NewParm($1,$2);
|
||||
$$->call_type = 0;
|
||||
Parm_Setvalue($$,DefArg);
|
||||
if (($1->type == T_USER) && !($1->is_pointer)) {
|
||||
$$->call_type = CALL_REFERENCE;
|
||||
Parm_Gettype($$)->is_pointer++;
|
||||
}
|
||||
DelDataType($1);
|
||||
delete $2;
|
||||
}
|
||||
|
|
@ -1391,7 +1371,6 @@ parm_type : type pname {
|
|||
| type stars pname {
|
||||
$$ = NewParm($1,$3);
|
||||
Parm_Gettype($$)->is_pointer+=$2;
|
||||
$$->call_type = 0;
|
||||
Parm_Setvalue($$,DefArg);
|
||||
if (InArray) {
|
||||
Parm_Gettype($$)->is_pointer++;
|
||||
|
|
@ -1406,7 +1385,6 @@ parm_type : type pname {
|
|||
$$ = NewParm($1,$3);
|
||||
DataType *pt = Parm_Gettype($$);
|
||||
pt->is_reference = 1;
|
||||
$$->call_type = 0;
|
||||
pt->is_pointer++;
|
||||
Parm_Setvalue($$,DefArg);
|
||||
if (!CPlusPlus) {
|
||||
|
|
@ -1481,18 +1459,6 @@ def_args : EQUAL definetype { $$ = $2; }
|
|||
| empty {$$.id = 0; $$.type = T_INT;}
|
||||
;
|
||||
|
||||
parm_specifier : CVALUE { $$ = CALL_VALUE; }
|
||||
| COUT { $$ = CALL_OUTPUT; }
|
||||
;
|
||||
|
||||
parm_specifier_list : parm_specifier_list parm_specifier {
|
||||
$$ = $1 | $2;
|
||||
}
|
||||
| parm_specifier {
|
||||
$$ = $1;
|
||||
}
|
||||
;
|
||||
|
||||
/* Declaration must be an identifier, possibly preceded by a * for pointer types */
|
||||
|
||||
declaration : ID { $$.id = $1;
|
||||
|
|
@ -3254,7 +3220,6 @@ typemap_parm : type typemap_name {
|
|||
}
|
||||
$$ = new TMParm;
|
||||
$$->p = NewParm($1,$2);
|
||||
$$->p->call_type = 0;
|
||||
$$->args = tm_parm;
|
||||
DelDataType($1);
|
||||
delete $2;
|
||||
|
|
@ -3265,7 +3230,6 @@ typemap_parm : type typemap_name {
|
|||
$$->p = NewParm($1,$3);
|
||||
DataType *pt = Parm_Gettype($$->p);
|
||||
pt->is_pointer += $2;
|
||||
$$->p->call_type = 0;
|
||||
if (InArray) {
|
||||
pt->is_pointer++;
|
||||
DataType_set_arraystr(pt,Char(ArrayString));
|
||||
|
|
@ -3280,7 +3244,6 @@ typemap_parm : type typemap_name {
|
|||
$$->p = NewParm($1,$3);
|
||||
DataType *pt = Parm_Gettype($$->p);
|
||||
pt->is_reference = 1;
|
||||
$$->p->call_type = 0;
|
||||
pt->is_pointer++;
|
||||
if (!CPlusPlus) {
|
||||
fprintf(stderr,"%s : Line %d. Warning. Use of C++ Reference detected. Use the -c++ option.\n", input_file, line_number);
|
||||
|
|
|
|||
|
|
@ -1240,8 +1240,14 @@ extern "C" int yylex(void) {
|
|||
if (strcmp(yytext,"%rename") == 0) return(RENAME);
|
||||
if (strcmp(yytext,"%includefile") == 0) return(INCLUDE);
|
||||
if (strcmp(yytext,"%externfile") == 0) return(WEXTERN);
|
||||
if (strcmp(yytext,"%val") == 0) return(CVALUE);
|
||||
if (strcmp(yytext,"%out") == 0) return(COUT);
|
||||
if (strcmp(yytext,"%val") == 0) {
|
||||
fprintf(stderr,"%s:%d %%val directive deprecated (ignored).\n", input_file, line_number);
|
||||
return (yylex());
|
||||
}
|
||||
if (strcmp(yytext,"%out") == 0) {
|
||||
fprintf(stderr,"%s:%d %%out directive deprecated (ignored).\n", input_file, line_number);
|
||||
return(yylex());
|
||||
}
|
||||
if (strcmp(yytext,"%constant") == 0) return(CONSTANT);
|
||||
if (strcmp(yytext,"%macro") == 0) return(SWIGMACRO);
|
||||
|
||||
|
|
|
|||
|
|
@ -318,11 +318,6 @@ void typemap_register(char *op, char *lang, DataType *type, char *pname,
|
|||
fprintf(stderr,"%s:%d: Typemap error. Local variables must have a name\n",
|
||||
input_file, line_number);
|
||||
}
|
||||
// If a call by reference thingy, fix that
|
||||
if (p->call_type & CALL_REFERENCE) {
|
||||
pt->is_pointer--;
|
||||
p->call_type = 0;
|
||||
}
|
||||
p = ParmList_next(tm->args);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ Parm *NewParm(DataType *type, char *n) {
|
|||
p->_type = 0;
|
||||
}
|
||||
p->_name = Swig_copy_string(n);
|
||||
p->call_type = 0;
|
||||
p->_defvalue = 0;
|
||||
p->ignore = 0;
|
||||
return p;
|
||||
|
|
@ -48,7 +47,6 @@ Parm *CopyParm(Parm *p) {
|
|||
Parm *np = (Parm *) malloc(sizeof(Parm));
|
||||
if (p->_type) np->_type = CopyDataType(p->_type);
|
||||
np->_name = Swig_copy_string(p->_name);
|
||||
np->call_type = p->call_type;
|
||||
np->_defvalue = Swig_copy_string(p->_defvalue);
|
||||
np->ignore = p->ignore;
|
||||
return np;
|
||||
|
|
@ -278,9 +276,7 @@ Parm * ParmList_next(ParmList *l) {
|
|||
* void ParmList_print_types(DOHFile *f)
|
||||
*
|
||||
* Prints a comma separated list of all of the parameter types.
|
||||
* This is for generating valid C prototypes. Has to do some
|
||||
* manipulation of pointer types depending on how the call_type
|
||||
* variable has been set.
|
||||
* This is for generating valid C prototypes.
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
void ParmList_print_types(ParmList *l, DOHFile *f) {
|
||||
|
|
@ -291,21 +287,7 @@ void ParmList_print_types(ParmList *l, DOHFile *f) {
|
|||
pn = 0;
|
||||
while(pn < l->nparms) {
|
||||
t = Parm_Gettype(l->parms[pn]);
|
||||
is_pointer = t->is_pointer;
|
||||
/* if (t->is_reference) {
|
||||
if (t->is_pointer) {
|
||||
t->is_pointer--;
|
||||
Printf(f,"%s&", DataType_str(t,0));
|
||||
t->is_pointer++;
|
||||
} else {
|
||||
Printf(f,"%s&", DataType_str(t,0));
|
||||
}
|
||||
} else { */
|
||||
if (l->parms[pn]->call_type & CALL_VALUE) t->is_pointer++;
|
||||
if (l->parms[pn]->call_type & CALL_REFERENCE) t->is_pointer--;
|
||||
Printf(f,"%s", DataType_str(t,0));
|
||||
t->is_pointer = is_pointer;
|
||||
/* }*/
|
||||
Printf(f,"%s", DataType_str(t,0));
|
||||
pn++;
|
||||
if (pn < l->nparms)
|
||||
Printf(f,",");
|
||||
|
|
@ -326,30 +308,11 @@ void ParmList_print_args(ParmList *l, DOHFile *f) {
|
|||
pn = 0;
|
||||
while(pn < l->nparms) {
|
||||
t = Parm_Gettype(l->parms[pn]);
|
||||
is_pointer = t->is_pointer;
|
||||
/* if (t->is_reference) {
|
||||
if (t->is_pointer) {
|
||||
t->is_pointer--;
|
||||
Printf(f,"%s&", DataType_print_full(t));
|
||||
t->is_pointer++;
|
||||
} else {
|
||||
Printf(f,"%s&", DataType_print_full(t));
|
||||
}
|
||||
} else {
|
||||
*/
|
||||
|
||||
if (l->parms[pn]->call_type & CALL_VALUE) t->is_pointer++;
|
||||
if (l->parms[pn]->call_type & CALL_REFERENCE) t->is_pointer--;
|
||||
Printf(f,"%s", DataType_str(t,0));
|
||||
|
||||
t->is_pointer = is_pointer;
|
||||
/*
|
||||
}
|
||||
*/
|
||||
Printf(f,"%s",Parm_Getname(l->parms[pn]));
|
||||
Printf(f,"%s", DataType_str(t,Parm_Getname(l->parms[pn])));
|
||||
pn++;
|
||||
if (pn < l->nparms)
|
||||
Printf(f,",");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ char *DataType_print_mangle_default(DataType *t) {
|
|||
|
||||
result[ri][0] = '_';
|
||||
|
||||
d = result[ri];
|
||||
d = result[ri] + 1;
|
||||
|
||||
if ((strncmp(c,"struct ",7) == 0) || (strncmp(c,"class ",6) == 0) || (strncmp(c,"union ",6) == 0)) {
|
||||
c = strchr(c,' ') + 1;
|
||||
|
|
|
|||
|
|
@ -293,13 +293,8 @@ extern void typeeq_addtypedef(char *name, char *eqname, DataType *t);
|
|||
|
||||
/* --- Deprecated parameter list structure */
|
||||
|
||||
#define CALL_VALUE 0x01
|
||||
#define CALL_REFERENCE 0x02
|
||||
#define CALL_OUTPUT 0x04
|
||||
|
||||
typedef struct Parm {
|
||||
DataType *_type; /* Datatype of this parameter */
|
||||
int call_type; /* Call type (value or reference or value) */
|
||||
char *_name; /* Name of parameter (optional) */
|
||||
char *_defvalue; /* Default value (as a string) */
|
||||
int ignore; /* Ignore flag */
|
||||
|
|
|
|||
|
|
@ -249,7 +249,6 @@ Wrapper_new_localv(Wrapper *w, const DOHString_or_char *name, ...) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
int main() {
|
||||
Wrapper *w;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue