More work on smoothing out the type system. Needs more work however.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@592 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-07-23 04:43:39 +00:00
commit 9bb0ec4a19
17 changed files with 940 additions and 731 deletions

View file

@ -6,9 +6,9 @@ srcdir = @srcdir@
VPATH = @srcdir@
SRCS = map.c wrapfunc.c naming.c tree.c stype.c scanner.c include.c getopt.c misc.c \
oldtypes.c oldparms.c
oldtypes.c oldparms.c cwrap.c
OBJS = map.o wrapfunc.o naming.o tree.o stype.o scanner.o include.o getopt.o misc.o \
oldtypes.o oldparms.o
oldtypes.o oldparms.o cwrap.o
prefix = @prefix@
exec_prefix = @exec_prefix@

405
Source/Swig/cwrap.c Normal file
View file

@ -0,0 +1,405 @@
/* -----------------------------------------------------------------------------
* cwrap.c
*
* This file defines a variety of wrapping rules for C/C++ handling including
* the naming of local variables, calling conventions, and so forth.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1998-2000. The University of Chicago
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
* University of California.
*
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
#include "swig.h"
/* -----------------------------------------------------------------------------
* Swig_parm_name()
*
* Generates a name for the ith argument in an argument list
* ----------------------------------------------------------------------------- */
char *
Swig_cparm_name(Parm *p, int i) {
static char name[256];
sprintf(name,"arg%d",i);
Parm_Setlname(p,name);
return Parm_Getlname(p);
}
/* -----------------------------------------------------------------------------
* Swig_clocal()
*
* Creates a string that declares a C local variable type. Converts references
* and user defined types to pointers.
* ----------------------------------------------------------------------------- */
char *
Swig_clocal(DataType *t, DOHString_or_char *name, DOHString_or_char *value) {
static DOHString *decl = 0;
if (!decl) decl = NewString("");
Clear(decl);
if ((t->type != T_VOID) || (t->is_pointer)) {
if ((t->type == T_USER) && (!t->is_pointer)) {
t->is_pointer++;
if (value)
Printf(decl,"%s = &%s", DataType_lstr(t,name), value);
else
Printf(decl,"%s", DataType_lstr(t,name));
t->is_pointer--;
} else if (t->is_reference) {
if (value)
Printf(decl,"%s = &%s", DataType_lstr(t,name), value);
else
Printf(decl,"%s", DataType_lstr(t,name));
} else {
if (value)
Printf(decl,"%s = %s", DataType_lstr(t,name), value);
else
Printf(decl,"%s", DataType_lstr(t,name));
}
}
return Char(decl);
}
/* -----------------------------------------------------------------------------
* Swig_clocal_type()
*
* Creates a string that declares a C local variable type. Converts references
* and user defined types to pointers.
* ----------------------------------------------------------------------------- */
DataType *
Swig_clocal_type(DataType *t) {
DataType *ty;
if ((t->type != T_VOID) || (t->is_pointer)) {
if ((t->type == T_USER) && (!t->is_pointer)) {
t->is_pointer++;
ty = DataType_ltype(t);
t->is_pointer--;
} else {
ty = DataType_ltype(t);
}
} else {
ty = DataType_ltype(t);
}
return ty;
}
/* -----------------------------------------------------------------------------
* Swig_clocal_deref()
*
* Creates a string that can be used to deref a local variable wrapped with
* the Swig_clocal() function.
* ----------------------------------------------------------------------------- */
char *
Swig_clocal_deref(DataType *t, DOHString_or_char *name) {
static char temp[256];
if ((t->type != T_VOID) || (t->is_pointer)) {
if ((t->type == T_USER) && (!t->is_pointer)) {
sprintf(temp,"*%s",Char(name));
} else {
sprintf(temp,DataType_rcaststr(t,name));
}
} else {
strcpy(temp,"");
}
return temp;
}
/* -----------------------------------------------------------------------------
* Swig_clocal_assign()
*
* Assigns a value to a local
* ----------------------------------------------------------------------------- */
char *
Swig_clocal_assign(DataType *t, DOHString_or_char *name) {
static char temp[256];
if ((t->type != T_VOID) || (t->is_pointer)) {
if ((t->type == T_USER) && (!t->is_pointer)) {
sprintf(temp,"&%s",Char(name));
} else {
sprintf(temp,DataType_lcaststr(t,name));
}
} else {
strcpy(temp,"");
}
return temp;
}
/* -----------------------------------------------------------------------------
* Swig_cargs()
*
* Emit all of the local variables for a list of parameters. Returns the
* number of parameters.
* ----------------------------------------------------------------------------- */
int Swig_cargs(Wrapper *w, ParmList *l) {
Parm *p;
int i;
DataType *pt;
char *pvalue;
char *pname;
char *local;
char *lname;
i = 0;
p = ParmList_first(l);
while (p != 0) {
lname = Swig_cparm_name(p,i);
pt = Parm_Gettype(p);
pname = Parm_Getname(p);
pvalue = Parm_Getvalue(p);
local = Swig_clocal(pt,lname,pvalue);
Wrapper_add_localv(w,lname,local,0);
i++;
p = ParmList_next(l);
}
return(i);
}
/* -----------------------------------------------------------------------------
* Swig_cresult()
*
* This function generates the C code needed to set the result of a C
* function call.
* ----------------------------------------------------------------------------- */
void Swig_cresult(Wrapper *w, DataType *t, DOHString_or_char *name, DOHString_or_char *decl) {
int i;
Parm *p;
DOHString *fcall;
char *tm;
fcall = NewString("");
if ((t->type != T_VOID) || (t->is_pointer)) {
Wrapper_add_localv(w,name, Swig_clocal(t,name,0), 0);
if ((t->type == T_USER) && (!t->is_pointer)) {
t->is_pointer++;
Printv(fcall, name, " = (", DataType_lstr(t,0), ") malloc(sizeof(", 0);
t->is_pointer--;
Printv(fcall, DataType_str(t,0), "));\n", 0);
Printv(fcall, "*(", name, ") = ", 0);
} else {
/* Is this a reference? */
if (t->is_reference) {
Printv(fcall, DataType_str(t,"_result_ref")," = ", 0);
} else {
/* Normal return value */
if (DataType_qualifier(t)) {
Printv(fcall, name, " = (", DataType_lstr(t,0), ")", 0);
} else {
Printv(fcall, name, " = ", 0);
}
}
}
}
/* Now print out function call */
Printv(fcall, decl, ";\n", 0);
if (t->is_reference) {
Printv(fcall, name, " = (", DataType_lstr(t,0), ") &_result_ref;\n", 0);
}
if (Replace(w->code,"$function",fcall, DOH_REPLACE_ANY) == 0) {
Printv(w->code, fcall, 0);
}
Delete(fcall);
}
/* -----------------------------------------------------------------------------
* Swig_cppresult()
*
* This function generates the C++ code needed to set the result. This uses
* the C++ default copy constructor for user defined objects.
* ----------------------------------------------------------------------------- */
void Swig_cppresult(Wrapper *w, DataType *t, DOHString_or_char *name, DOHString_or_char *decl) {
int i;
Parm *p;
DOHString *fcall;
char *tm;
fcall = NewString("");
if ((t->type != T_VOID) || (t->is_pointer)) {
Wrapper_add_localv(w,name, Swig_clocal(t,name,0), 0);
if ((t->type == T_USER) && (!t->is_pointer)) {
Printv(fcall, name, " = new ", DataType_str(t,0), "(", 0);
} else {
/* Is this a reference? */
if (t->is_reference) {
Printv(fcall, DataType_str(t,"_result_ref")," = ", 0);
} else {
/* Normal return value */
Printv(fcall, name, " = (", DataType_lstr(t,0), ")", 0);
}
}
}
/* Now print out function call */
Printv(fcall, decl, 0);
if ((t->type == T_USER) && (!t->is_pointer)) {
Printf(fcall,")");
}
Printf(fcall,";\n");
if (t->is_reference) {
Printv(fcall, name, " = (", DataType_lstr(t,0), ") &_result_ref;\n", 0);
}
if (Replace(w->code,"$function",fcall, DOH_REPLACE_ANY) == 0) {
Printv(w->code, fcall, 0);
}
Delete(fcall);
}
/* -----------------------------------------------------------------------------
* Swig_cfunction()
*
* Creates a string that calls a C function using the local variable rules
* defined above.
*
* name(arg0, arg1, arg2, ... argn)
*
* ----------------------------------------------------------------------------- */
char *
Swig_cfunction(DOHString_or_char *name, ParmList *parms) {
static DOH *func = 0;
int i = 0;
Parm *p;
DataType *pt;
if (!func) func = NewString("");
Clear(func);
Printf(func,"%s(", name);
p = ParmList_first(parms);
while (p) {
pt = Parm_Gettype(p);
Printf(func,"%s", Swig_clocal_deref(pt, Swig_cparm_name(p,i)));
i++;
p = ParmList_next(parms);
if (p)
Printf(func,",");
}
Printf(func,")");
return Char(func);
}
/* -----------------------------------------------------------------------------
* Swig_cmethod()
*
* Generates a string that calls a C++ method from a list of parameters.
*
* arg0->name(arg1, arg2, arg3, ..., argn)
*
* ----------------------------------------------------------------------------- */
char *
Swig_cmethod(DOHString_or_char *name, ParmList *parms) {
static DOH *func = 0;
int i = 0;
Parm *p;
DataType *pt;
if (!func) func = NewString("");
Clear(func);
p = ParmList_first(parms);
if (!p) return "";
Printf(func,"%s->%s(", Swig_cparm_name(p,0), name);
i++;
p = ParmList_next(parms);
while (p) {
pt = Parm_Gettype(p);
Printf(func,"%s", Swig_clocal_deref(pt, Swig_cparm_name(p,i)));
i++;
p = ParmList_next(parms);
if (p)
Printf(func,",");
}
Printf(func,")");
return Char(func);
}
/* -----------------------------------------------------------------------------
* Swig_cmember_set()
*
* Generates a string that sets the name of a member in a C++ class or C struct.
*
* arg0->name = arg1
*
* ----------------------------------------------------------------------------- */
char *
Swig_cmember_set(DOHString_or_char *name, ParmList *parms) {
static DOH *func = 0;
Parm *p;
DataType *pt;
if (!func) func = NewString("");
Clear(func);
if (ParmList_numarg(parms) != 2) {
printf("Swig_cmember_set called with wrong # args!\n");
abort();
}
p = ParmList_first(parms);
Printf(func,"(%s->%s = ", Swig_cparm_name(p,0), name);
p = ParmList_next(parms);
pt = Parm_Gettype(p);
Printf(func,"%s", Swig_clocal_deref(pt, Swig_cparm_name(p,1)));
Printf(func,")");
return Char(func);
}
/* -----------------------------------------------------------------------------
* Swig_cmember_get()
*
* Generates a string that sets the name of a member in a C++ class or C struct.
*
* arg0->name
*
* ----------------------------------------------------------------------------- */
char *
Swig_cmember_get(DOHString_or_char *name, ParmList *parms) {
static DOH *func = 0;
Parm *p;
DataType *pt;
if (!func) func = NewString("");
Clear(func);
if (ParmList_numarg(parms) != 1) {
printf("Swig_cmember_get called with wrong # args!\n");
abort();
}
p = ParmList_first(parms);
Printf(func,"(%s->%s)", Swig_cparm_name(p,0), name);
return Char(func);
}

View file

@ -34,6 +34,7 @@ Parm *NewParm(DataType *type, char *n) {
p->_type = 0;
}
p->_name = Swig_copy_string(n);
p->_lname = 0;
p->_defvalue = 0;
p->ignore = 0;
return p;
@ -48,6 +49,7 @@ Parm *CopyParm(Parm *p) {
if (p->_type) np->_type = CopyDataType(p->_type);
np->_name = Swig_copy_string(p->_name);
np->_defvalue = Swig_copy_string(p->_defvalue);
np->_lname = Swig_copy_string(p->_lname);
np->ignore = p->ignore;
return np;
}
@ -60,6 +62,7 @@ void DelParm(Parm *p) {
if (p->_type) DelDataType(p->_type);
if (p->_name) free(p->_name);
if (p->_defvalue) free(p->_defvalue);
if (p->_lname) free(p->_lname);
free(p);
}
@ -81,6 +84,15 @@ char *Parm_Getname(Parm *p) {
return p->_name;
}
void Parm_Setlname(Parm *p, char *n) {
if (p->_lname) free(p->_lname);
p->_lname = Swig_copy_string(n);
}
char *Parm_Getlname(Parm *p) {
return p->_lname;
}
void Parm_Setvalue(Parm *p, char *v) {
if (p->_defvalue) free(p->_defvalue);
p->_defvalue = Swig_copy_string(v);
@ -301,7 +313,6 @@ void ParmList_print_types(ParmList *l, DOHFile *f) {
* ---------------------------------------------------------------------- */
void ParmList_print_args(ParmList *l, DOHFile *f) {
int is_pointer;
int pn;
DataType *t;
@ -316,3 +327,4 @@ void ParmList_print_args(ParmList *l, DOHFile *f) {
}

View file

@ -183,134 +183,14 @@ void DataType_primitive(DataType *t) {
}
/* --------------------------------------------------------------------
* char *print_type()
*
* Print the datatype, but without qualifiers (ie. const, volatile)
* Returns a string containing the result.
*
* If a datatype is marked as an implicit ptr it means that is_pointer
* is at least one, but we don't print '*'.
*
* If the type status is STAT_REPLACETYPE, it means that we can't
* use this type as a valid type. We'll substitute it's old name in.
* -------------------------------------------------------------------- */
char *DataType_print_type(DataType *ty) {
static char result[8][256];
static int ri = 0;
int i;
DataType *t = ty;
if (ty->status & STAT_REPLACETYPE) {
t = CopyDataType(ty);
DataType_typedef_replace(t);
}
ri = ri % 8;
sprintf(result[ri],"%s ", t->name);
for (i = 0; i < (t->is_pointer-t->implicit_ptr); i++)
strcat(result[ri],"*");
if (ty->status & STAT_REPLACETYPE) {
DelDataType(t);
};
return result[ri++];
}
/* --------------------------------------------------------------------
* char *print_full()
*
* Prints full type, with qualifiers.
* -------------------------------------------------------------------- */
char *DataType_print_full(DataType *t) {
static char result[8][256];
static int ri = 0;
ri = ri % 8;
if (t->_qualifier) {
sprintf(result[ri],"%s %s", t->_qualifier, DataType_print_type(t));
return result[ri++];
} else {
return DataType_print_type(t);
}
}
/* --------------------------------------------------------------------
* char *print_cast()
*
* Prints a cast. (Basically just a type but with parens added).
* -------------------------------------------------------------------- */
char *DataType_print_cast(DataType *t) {
static char result[8][256];
static int ri = 0;
ri = ri % 8;
sprintf(result[ri],"(%s)", DataType_print_type(t));
return result[ri++];
}
/* --------------------------------------------------------------------
* char *print_arraycast()
*
* Prints a cast, but for array datatypes. Super ugly, but necessary
* for multidimensional arrays.
* -------------------------------------------------------------------- */
char *DataType_print_arraycast(DataType *ty) {
static char result[8][256];
static int ri = 0;
int ndim;
char *c;
DataType *t;
t = ty;
if (ty->status & STAT_REPLACETYPE) {
t = CopyDataType(ty);
DataType_typedef_replace(t);
}
ri = ri % 8;
if (t->_arraystr) {
ndim = 0;
c = t->_arraystr;
while (*c) {
if (*c == '[') ndim++;
c++;
}
if (ndim > 1) {
/* a Multidimensional array. Provide a special cast for it */
int oldstatus = ty->status;
t->status = t->status & (~STAT_REPLACETYPE);
t->is_pointer--;
sprintf(result[ri],"(%s", DataType_print_type(t));
t->is_pointer++;
t->status = oldstatus;
strcat(result[ri]," (*)");
c = t->_arraystr;
while (*c) {
if (*c == ']') break;
c++;
}
if (*c) c++;
strcat(result[ri],c);
strcat(result[ri],")");
}
}
if (ty->status & STAT_REPLACETYPE) {
DelDataType(t);
}
return result[ri++];
}
/* --------------------------------------------------------------------
* char *print_mangle_default()
* char *mangle_default()
*
* Prints a mangled version of this datatype. Used for run-time type
* checking in order to print out a "language friendly" version (ie. no
* spaces and no weird characters).
* -------------------------------------------------------------------- */
char *DataType_print_mangle_default(DataType *t) {
char *DataType_mangle_default(DataType *t) {
static char result[8][256];
static int ri = 0;
int i;
@ -342,9 +222,9 @@ char *DataType_print_mangle_default(DataType *t) {
/* This is kind of ugly but needed for each language to support a
custom name mangling mechanism. (ie. Perl5). */
static char *(*mangler)(DataType *t) = DataType_print_mangle_default;
static char *(*mangler)(DataType *t) = DataType_mangle_default;
char *DataType_print_mangle(DataType *t) {
char *DataType_manglestr(DataType *t) {
/* Call into target language for name mangling. */
return (*mangler)(t);
}
@ -360,7 +240,7 @@ void DataType_set_mangle(char *(*m)(DataType *t)) {
* variable name.
* ----------------------------------------------------------------------------- */
char *DataType_str(DataType *t, char *name) {
char *DataType_str(DataType *t, DOHString_or_char *name) {
static char result[8][256];
static int ri = 0;
int i;
@ -378,7 +258,7 @@ char *DataType_str(DataType *t, char *name) {
strcat(result[ri],"*");
}
if (t->is_reference) strcat(result[ri],"&");
if (name) strcat(result[ri],name);
if (name) strcat(result[ri],Char(name));
if (t->_arraystr) {
strcat(result[ri],t->_arraystr);
t->is_pointer++;
@ -387,6 +267,177 @@ char *DataType_str(DataType *t, char *name) {
return result[ri++];
}
/* --------------------------------------------------------------------
* char *DataType_lstr()
*
* Produces a type-string that is suitable as a lvalue in an expression.
* That is, a type that can be freely assigned a value without violating
* any C assignment rules.
*
* - Qualifiers such as 'const' and 'volatile' are stripped.
* - Arrays are converted into a *single* pointer (i.e.,
* double [][] becomes double *).
* - References are converted into a pointer.
* - Typedef names that refer to read-only types will be replaced
* with an equivalent assignable version.
* -------------------------------------------------------------------- */
char *DataType_lstr(DataType *ty, DOHString_or_char *name) {
static char result[8][256];
static int ri = 0;
int i;
DataType *t = ty;
if (ty->status & STAT_REPLACETYPE) {
t = CopyDataType(ty);
DataType_typedef_replace(t); /* Replace the type with its typedef value */
}
ri = ri % 8;
sprintf(result[ri],"%s ", t->name);
for (i = 0; i < (t->is_pointer-t->implicit_ptr); i++)
strcat(result[ri],"*");
if (ty->status & STAT_REPLACETYPE) {
DelDataType(t);
}
if (name) {
strcat(result[ri],Char(name));
}
return result[ri++];
}
/* -----------------------------------------------------------------------------
* DataType_ltype(DataType *ty)
*
* Returns a type object corresponding to the string created by lstr
* ----------------------------------------------------------------------------- */
DataType *DataType_ltype(DataType *t) {
DataType *ty = CopyDataType(t);
if (ty->status & STAT_REPLACETYPE) {
DataType_typedef_replace(ty); /* Replace the type with its typedef value */
}
if (ty->_qualifier) {
free(ty->_qualifier);
ty->_qualifier = 0;
}
if (ty->_arraystr) {
free(ty->_arraystr);
ty->_arraystr = 0;
}
ty->is_reference = 0;
return ty;
}
/* -----------------------------------------------------------------------------
* char *DataType_rcaststr(DataType *t, char *name)
*
* Produces a casting string that maps the type returned by lstr() to the real
* datatype printed by str().
* ----------------------------------------------------------------------------- */
char *DataType_rcaststr(DataType *ty, DOHString_or_char *name) {
static char result[8][256];
static int ri = 0;
DataType *t = 0;
ri = ri % 8;
strcpy(result[ri],"");
if (ty->_arraystr) {
t = ty;
if (ty->status & STAT_REPLACETYPE) {
t = CopyDataType(ty);
DataType_typedef_replace(t);
}
ri = ri % 8;
if (t->_arraystr) {
int ndim;
char *c;
ndim = 0;
c = t->_arraystr;
while (*c) {
if (*c == '[') ndim++;
c++;
}
if (ndim > 1) {
/* a Multidimensional array. Provide a special cast for it */
char *oldarr = 0;
int oldstatus = ty->status;
t->status = t->status & (~STAT_REPLACETYPE);
t->is_pointer--;
oldarr = t->_arraystr;
t->_arraystr = 0;
sprintf(result[ri],"(%s", DataType_str(t,0));
t->_arraystr = oldarr;
t->is_pointer++;
t->status = oldstatus;
strcat(result[ri]," (*)");
c = t->_arraystr;
while (*c) {
if (*c == ']') break;
c++;
}
if (*c) c++;
strcat(result[ri],c);
strcat(result[ri],")");
}
}
if (ty->status & STAT_REPLACETYPE) {
DelDataType(t);
}
} else if (ty->_qualifier) {
/* Make a cast to restore const/volatile */
sprintf(result[ri],"(%s)", DataType_str(ty,0));
}
if (name) {
if (ty->is_reference) {
strcat(result[ri],"*");
}
strcat(result[ri],Char(name));
}
return result[ri++];
}
/* -----------------------------------------------------------------------------
* DataType_lcaststr()
*
* Casts a variable from the real type to the local datatype.
* ----------------------------------------------------------------------------- */
char *DataType_lcaststr(DataType *ty, DOHString_or_char *name) {
static char result[8][256];
static int ri = 0;
DataType *t = 0;
ri = ri % 8;
strcpy(result[ri],"");
if (ty->_arraystr) {
sprintf(result[ri],"(%s)", DataType_lstr(ty,0));
if (name)
strcat(result[ri], Char(name));
} else if (ty->is_reference) {
sprintf(result[ri],"(%s)", DataType_lstr(ty,0));
if (name) {
strcat(result[ri], "&");
strcat(result[ri], Char(name));
}
} else if (ty->_qualifier) {
sprintf(result[ri],"(%s)", DataType_lstr(ty,0));
if (name) {
strcat(result[ri], Char(name));
}
} else {
if (name) {
strcat(result[ri], Char(name));
}
}
return result[ri++];
}
/* --------------------------------------------------------------------
* int DataType_array_dimensions()
*
@ -507,8 +558,8 @@ int DataType_typedef_add(DataType *t,char *tname, int mode) {
if ((t->type != T_VOID) && (strcmp(t->name,tname) != 0)) {
t1 = NewDataType(0);
strcpy(t1->name,tname);
name2 = DataType_print_mangle(t1);
name1 = DataType_print_mangle(t);
name2 = DataType_manglestr(t1);
name1 = DataType_manglestr(t);
typeeq_addtypedef(name1,name2,t1);
typeeq_addtypedef(name2,name1,t);
DelDataType(t1);
@ -933,8 +984,8 @@ void typeeq_derived(char *n1, char *n2, char *cast) {
t1->type = T_USER;
strcpy(t->name,n1);
strcpy(t1->name,n2);
name = DataType_print_mangle(t);
name2 = DataType_print_mangle(t1);
name = DataType_manglestr(t);
name2 = DataType_manglestr(t1);
typeeq_add(name,name2, cast, t1);
DelDataType(t);
DelDataType(t1);
@ -956,8 +1007,8 @@ void typeeq_mangle(char *n1, char *n2, char *cast) {
strcpy(t->name,n1);
strcpy(t1->name,n2);
name = DataType_print_mangle(t);
name2 = DataType_print_mangle(t1);
name = DataType_manglestr(t);
name2 = DataType_manglestr(t1);
typeeq_add(name,name2,cast,0);
DelDataType(t);
DelDataType(t1);
@ -1007,7 +1058,7 @@ check_equivalent(DataType *t) {
Clear(out);
while (t->is_pointer >= t->implicit_ptr) {
m = Swig_copy_string(DataType_print_mangle(t));
m = Swig_copy_string(DataType_manglestr(t));
if (!te_init) typeeq_init();
@ -1019,7 +1070,7 @@ check_equivalent(DataType *t) {
while (e2) {
if (e2->type) {
e2->type->is_pointer += (npointer - t->is_pointer);
Printf(out,"{ \"%s\",", DataType_print_mangle(e2->type));
Printf(out,"{ \"%s\",", DataType_manglestr(e2->type));
e2->type->is_pointer -= (npointer - t->is_pointer);
if (e2->cast)
Printf(out,"%s}, ", e2->cast);
@ -1076,7 +1127,7 @@ void DataType_remember(DataType *ty) {
DataType *t = CopyDataType(ty);
if (!remembered) remembered = NewHash();
SetVoid(remembered, DataType_print_mangle(t), t);
SetVoid(remembered, DataType_manglestr(t), t);
if (!bases) bases = NewHash();
/* Now, do the base-class hack */
@ -1087,7 +1138,7 @@ void DataType_remember(DataType *ty) {
while (key) {
DataType *nt = CopyDataType(t);
strcpy(nt->name,Char(key));
if (!Getattr(remembered,DataType_print_mangle(nt)))
if (!Getattr(remembered,DataType_manglestr(nt)))
DataType_remember(nt);
DelDataType(nt);
key = Nextkey(h);

View file

@ -250,7 +250,12 @@ extern void DelDataType(DataType *type);
/* -- New type interface -- */
extern char *DataType_str(DataType *, char *name); /* Exact datatype */
extern char *DataType_str(DataType *, DOHString_or_char *name); /* Exact datatype */
extern char *DataType_lstr(DataType *, DOHString_or_char *name); /* Assignable datatype */
extern char *DataType_rcaststr(DataType *, DOHString_or_char *name); /* Cast from lstr to str */
extern char *DataType_lcaststr(DataType *, DOHString_or_char *name); /* Cast from str to lstr */
extern char *DataType_manglestr(DataType *t); /* Mangled type name */
extern DataType *DataType_ltype(DataType *); /* Create local type object */
/* -- Old type interface -- */
@ -258,14 +263,8 @@ extern char *DataType_qualifier(DataType *);
extern void DataType_set_qualifier(DataType *, char *q);
extern char *DataType_arraystr(DataType *);
extern void DataType_set_arraystr(DataType *, char *a);
extern char *DataType_mangle_default(DataType *t); /* Default name mangler */
extern void DataType_primitive(DataType *);
extern char *DataType_print_type(DataType *);
extern char *DataType_print_full(DataType *);
extern char *DataType_print_cast(DataType *);
extern char *DataType_print_mangle(DataType *);
extern char *DataType_print_arraycast(DataType *);
extern char *DataType_print_mangle_default(DataType *);
extern void DataType_set_mangle(char *(*m)(DataType *));
extern int DataType_array_dimensions(DataType *);
extern char *DataType_get_dimension(DataType *, int);
@ -294,10 +293,11 @@ extern void typeeq_addtypedef(char *name, char *eqname, DataType *t);
/* --- Deprecated parameter list structure */
typedef struct Parm {
DataType *_type; /* Datatype of this parameter */
DataType *_type; /* Datatype of this parameter */
char *_name; /* Name of parameter (optional) */
char *_defvalue; /* Default value (as a string) */
int ignore; /* Ignore flag */
char *_defvalue; /* Default value (as a string) */
char *_lname; /* Local name */
int ignore; /* Ignore flag */
} Parm;
extern Parm *NewParm(DataType *type, char *n);
@ -307,6 +307,8 @@ extern void Parm_Settype(Parm *p, DataType *t);
extern DataType *Parm_Gettype(Parm *p);
extern void Parm_Setname(Parm *p, char *name);
extern char *Parm_Getname(Parm *p);
extern void Parm_Setlname(Parm *p, char *lname);
extern char *Parm_Getlname(Parm *p);
extern void Parm_Setvalue(Parm *p, char *value);
extern char *Parm_Getvalue(Parm *p);
@ -330,6 +332,24 @@ extern Parm *ParmList_next(ParmList *);
extern void ParmList_print_types(ParmList*,DOHFile *f);
extern void ParmList_print_args(ParmList *, DOHFile *f);
extern void Wrapper_local(Wrapper *w, DataType *t, DOHString_or_char *name, DOHString_or_char *value);
extern char *Wrapper_local_deref(DataType *t, DOHString_or_char *name);
/* --- C Wrappers --- */
extern char *Swig_clocal(DataType *t, DOHString_or_char *name, DOHString_or_char *value);
extern DataType *Swig_clocal_type(DataType *t);
extern char *Swig_clocal_deref(DataType *t, DOHString_or_char *name);
extern char *Swig_clocal_assign(DataType *t, DOHString_or_char *name);
extern char *Swig_cparm_name(Parm *p, int i);
extern int Swig_cargs(Wrapper *w, ParmList *l);
extern void Swig_cresult(Wrapper *w, DataType *t, DOHString_or_char *name, DOHString_or_char *decl);
extern void Swig_cppresult(Wrapper *w, DataType *t, DOHString_or_char *name, DOHString_or_char *decl);
extern char *Swig_cfunction(DOHString_or_char *name, ParmList *parms);
extern char *Swig_cmethod(DOHString_or_char *name, ParmList *parms);
extern char *Swig_cmember_set(DOHString_or_char *name, ParmList *parms);
extern char *Swig_cmember_get(DOHString_or_char *name, ParmList *parms);
#endif

View file

@ -3,7 +3,7 @@
*
* This file defines a object for creating wrapper functions. Primarily
* this is used for convenience since it allows pieces of a wrapper function
* to be created in a non-linear manner.
* to be created in a piecemeal manner.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
@ -249,23 +249,3 @@ Wrapper_new_localv(Wrapper *w, const DOHString_or_char *name, ...) {
return ret;
}
#ifdef TEST
int main() {
Wrapper *w;
w = NewWrapper();
Printf(w->def,"int foo_wrap(ClientData clientdata, Tcl_Interp *interp, int argc, char *argv[]) {");
Wrapper_add_local(w,"int a", "a");
Wrapper_add_local(w,"int a", "a");
Wrapper_add_local(w,"int b", "b");
Wrapper_add_local(w,"char temp[256]","temp");
Printf(w->code,"for (i = 0; i < 10; i++) { printf(\"%%d\", i); }\n");
Printf(w->code,"if (1) { foo;\n} else { bar; \n}\n");
Printf(w->code,"}\n");
Wrapper_print(w,stdout);
DelWrapper(w);
}
#endif