Cleanup. Some changes to the type interface.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@576 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-07-13 04:26:25 +00:00
commit 0d0978675d
8 changed files with 414 additions and 387 deletions

View file

@ -390,8 +390,8 @@ throw_unhandled_guile_type_error (DataType *d)
Printf (stderr, "implicit_ptr %d\n", d->implicit_ptr);
Printf (stderr, "is_reference %d\n", d->is_reference);
Printf (stderr, " status %d\n", d->status);
Printf (stderr, " qualifier %s\n", (d->qualifier ? d->qualifier : ""));
Printf (stderr, " arraystr %s\n", (d->arraystr ? d->arraystr : ""));
/* Printf (stderr, " qualifier %s\n", (d->qualifier ? d->qualifier : ""));
Printf (stderr, " arraystr %s\n", (d->arraystr ? d->arraystr : ""));*/
Printf (stderr, " id %d\n", d->id);
Printf (stderr, "\n\nBAILING...\n"); // for now -ttn

View file

@ -278,8 +278,8 @@ throw_unhandled_mzscheme_type_error (DataType *d)
Printf (stderr, "implicit_ptr %d\n", d->implicit_ptr);
Printf (stderr, "is_reference %d\n", d->is_reference);
Printf (stderr, " status %d\n", d->status);
Printf (stderr, " qualifier %s\n", (d->qualifier ? d->qualifier : ""));
Printf (stderr, " arraystr %s\n", (d->arraystr ? d->arraystr : ""));
/* Printf (stderr, " qualifier %s\n", (d->qualifier ? d->qualifier : ""));
Printf (stderr, " arraystr %s\n", (d->arraystr ? d->arraystr : "")); */
Printf (stderr, " id %d\n", d->id);
Printf (stderr, "\n\nBAILING...\n"); // for now -ttn

View file

@ -405,9 +405,6 @@ public:
ccode = code;
t = CopyDataType(type);
if (t->qualifier) {
// if (strcmp(t->qualifier,"const") == 0) Status = Status | STAT_READONLY;
}
update_local_type(t);
if (!is_static) {
lang->cpp_variable(name,iname,t);

View file

@ -39,14 +39,14 @@ static char cvsroot[] = "$Header$";
void emit_extern_var(char *decl, DataType *t, int extern_type, FILE *f) {
char *arr = 0;
if (t->arraystr) arr = t->arraystr;
else arr = (char*)"";
arr = DataType_arraystr(t);
if (!arr) arr = (char*)"";
switch(extern_type) {
case 0:
// No extern. Just a forward reference
if (t->arraystr)
if (DataType_arraystr(t))
t->is_pointer--;
if (t->is_reference) {
@ -56,11 +56,11 @@ void emit_extern_var(char *decl, DataType *t, int extern_type, FILE *f) {
} else {
fprintf(f,"%s %s%s; \n", DataType_print_full(t), decl,arr);
}
if (t->arraystr)
if (DataType_arraystr(t))
t->is_pointer++;
break;
case 1: case 2:
if (t->arraystr)
if (DataType_arraystr(t))
t->is_pointer--;
// Normal C/C++ extern
@ -72,7 +72,7 @@ void emit_extern_var(char *decl, DataType *t, int extern_type, FILE *f) {
} else {
fprintf(f,"extern %s %s%s; \n", DataType_print_full(t), decl,arr);
}
if (t->arraystr)
if (DataType_arraystr(t))
t->is_pointer++;
default:

View file

@ -555,14 +555,14 @@ statement : INCLUDE STRING LBRACE {
if ($4 > 0) {
$2->is_pointer++;
$2->status = STAT_READONLY;
$2->arraystr = copy_string(Char(ArrayString));
DataType_set_arraystr($2,Char(ArrayString));
}
if ($3.is_reference) {
fprintf(stderr,"%s : Line %d. Error. Linkage to C++ reference not allowed.\n", input_file, line_number);
FatalError();
} else {
if ($2->qualifier) {
if ((strcmp($2->qualifier,"const") == 0)) {
if (DataType_qualifier($2)) {
if ((strcmp(DataType_qualifier($2),"const") == 0)) {
if ($5.type != T_ERROR)
create_constant($3.id, $2, $5.id);
} else
@ -1207,7 +1207,7 @@ typedef_decl : TYPEDEF type declaration {
$2->is_pointer += $3.is_pointer;
// Turn this into a "pointer" corresponding to the array
$2->is_pointer++;
$2->arraystr = copy_string(Char(ArrayString));
DataType_set_arraystr($2,Char(ArrayString));
DataType_typedef_add($2,$3.id,0);
lang->add_typedef($2,$3.id);
fprintf(stderr,"%s : Line %d. Warning. Array type %s will be read-only without a typemap\n",input_file,line_number, $3.id);
@ -1242,7 +1242,7 @@ typedeflist : COMMA declaration typedeflist {
t = CopyDataType(Active_typedef);
t->status = STAT_READONLY | STAT_REPLACETYPE;
t->is_pointer += $2.is_pointer + 1;
t->arraystr = copy_string(Char(ArrayString));
DataType_set_arraystr(t,Char(ArrayString));
DataType_typedef_add(t,$2.id,0);
lang->add_typedef(t,$2.id);
cplus_register_type($2.id);
@ -1280,14 +1280,14 @@ stail : SEMI { }
if ($3 > 0) {
temp_typeptr->is_pointer++;
temp_typeptr->status = STAT_READONLY;
temp_typeptr->arraystr = copy_string(Char(ArrayString));
DataType_set_arraystr(temp_typeptr,Char(ArrayString));
}
if ($2.is_reference) {
fprintf(stderr,"%s : Line %d. Error. Linkage to C++ reference not allowed.\n", input_file, line_number);
FatalError();
} else {
if (temp_typeptr->qualifier) {
if ((strcmp(temp_typeptr->qualifier,"const") == 0)) {
if (DataType_qualifier(temp_typeptr)) {
if ((strcmp(DataType_qualifier(temp_typeptr),"const") == 0)) {
/* Okay. This is really some sort of C++ constant here. */
if ($4.type != T_ERROR)
create_constant($2.id, temp_typeptr, $4.id);
@ -1373,7 +1373,7 @@ parm_type : type pname {
if (InArray) {
$1->is_pointer++;
// Add array string to the type
$1->arraystr = copy_string(Char(ArrayString));
DataType_set_arraystr($1, Char(ArrayString));
}
$$ = NewParm($1,$2);
$$->call_type = 0;
@ -1394,7 +1394,7 @@ parm_type : type pname {
if (InArray) {
$$->t->is_pointer++;
// Add array string to the type
$$->t->arraystr = copy_string(Char(ArrayString));
DataType_set_arraystr($$->t, Char(ArrayString));
}
DelDataType($1);
delete $3;
@ -1596,8 +1596,7 @@ type : TYPE_INT {
}
| CONST type {
$$ = $2;
$$->qualifier = new char[6];
strcpy($$->qualifier,"const");
DataType_set_qualifier($$,"const");
}
| cpptype ID {
$$ = NewDataType(0);
@ -1667,8 +1666,7 @@ strict_type : TYPE_INT {
}
| CONST type {
$$ = $2;
$$->qualifier = new char[6];
strcpy($$->qualifier,"const");
DataType_set_qualifier($$,"const");
}
| cpptype ID {
$$ = NewDataType(0);
@ -2374,8 +2372,8 @@ cpp_member : type declaration LPAREN parms RPAREN cpp_end {
Active_type = CopyDataType($1);
$1->is_pointer += $2.is_pointer;
$1->is_reference = $2.is_reference;
if ($1->qualifier) {
if ((strcmp($1->qualifier,"const") == 0) && ($1->is_pointer == 0)) {
if (DataType_qualifier($1)) {
if ((strcmp(DataType_qualifier($1),"const") == 0) && ($1->is_pointer == 0)) {
// Okay. This is really some sort of C++ constant here.
if ($3.type != T_ERROR) {
iname = make_name($2.id);
@ -2421,7 +2419,7 @@ cpp_member : type declaration LPAREN parms RPAREN cpp_end {
Active_type = CopyDataType($1);
$1->is_pointer += $2.is_pointer + 1;
$1->is_reference = $2.is_reference;
$1->arraystr = copy_string(Char(ArrayString));
DataType_set_arraystr($1,Char(ArrayString));
if (!(tm = typemap_lookup((char*)"memberin",typemap_lang,$1,$2.id,(char*)"",(char*)"")))
Status = STAT_READONLY;
@ -3004,7 +3002,7 @@ objc_var : type declaration {
Active_type = CopyDataType($1);
$1->is_pointer += $2.is_pointer;
$1->is_reference = $2.is_reference;
$1->arraystr = copy_string(Char(ArrayString));
DataType_set_arraystr($1, Char(ArrayString));
if ($1->status & STAT_READONLY) {
if (!(tm = typemap_lookup((char*)"memberin",typemap_lang,$1,$2.id,(char*)"",(char*)"")))
Status = Status | STAT_READONLY;
@ -3049,7 +3047,7 @@ objc_vartail : COMMA declaration objc_vartail {
DataType *t = CopyDataType (Active_type);
t->is_pointer += $2.is_pointer;
t->is_reference = $2.is_reference;
t->arraystr = copy_string(Char(ArrayString));
DataType_set_arraystr(t,Char(ArrayString));
if (t->status & STAT_READONLY) {
if (!(tm = typemap_lookup((char*)"memberin",typemap_lang,t,$2.id,(char*)"",(char*)"")))
Status = Status | STAT_READONLY;
@ -3247,7 +3245,7 @@ tm_tail : COMMA typemap_parm tm_tail {
typemap_parm : type typemap_name {
if (InArray) {
$1->is_pointer++;
$1->arraystr = copy_string(Char(ArrayString));
DataType_set_arraystr($1,Char(ArrayString));
}
$$ = new TMParm;
$$->p = NewParm($1,$2);
@ -3264,7 +3262,7 @@ typemap_parm : type typemap_name {
$$->p->call_type = 0;
if (InArray) {
$$->p->t->is_pointer++;
$$->p->t->arraystr = copy_string(Char(ArrayString));
DataType_set_arraystr($$->p->t,Char(ArrayString));
}
$$->args = tm_parm;
DelDataType($1);

View file

@ -112,8 +112,8 @@ typedef struct DataType {
char implicit_ptr; // Implicit ptr
char is_reference; // A C++ reference type
char status; // Is this datatype read-only?
char *qualifier; // A qualifier string (ie. const).
char *arraystr; // String containing array part
char *_qualifier; // A qualifier string (ie. const).
char *_arraystr; // String containing array part
int id; // type identifier (unique for every type).
// Temporary: catches accidental use.
@ -127,6 +127,11 @@ extern DataType *NewDataType(int type);
extern DataType *CopyDataType(DataType *type);
extern void DelDataType(DataType *type);
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 void DataType_primitive(DataType *);
extern char *DataType_print_type(DataType *);
extern char *DataType_print_full(DataType *);

View file

@ -168,14 +168,14 @@ void typemap_apply(DataType *tm_type, char *tm_name, DataType *type, char *pname
// Check to see if an array typemap has been applied to a non-array type
if ((tm_type->arraystr) && (!type->arraystr)) {
if ((DataType_arraystr(tm_type)) && (!DataType_arraystr(type))) {
fprintf(stderr,"%s:%d: Warning. Array typemap has been applied to a non-array type.\n",
input_file,line_number);
}
// If both are arrays, make sure they have the same dimension
if ((tm_type->arraystr) && (type->arraystr)) {
if ((DataType_arraystr(tm_type)) && (DataType_arraystr(type))) {
char s[128],*t;
if (DataType_array_dimensions(tm_type) != DataType_array_dimensions(type)) {
fprintf(stderr,"%s:%d: Warning. Array types have different number of dimensions.\n",
@ -266,7 +266,7 @@ void typemap_register(char *op, char *lang, DataType *type, char *pname,
is_default = 1;
}
key = typemap_string(lang,tm->type,pname,tm->type->arraystr, op);
key = typemap_string(lang,tm->type,pname,DataType_arraystr(tm->type), op);
// Get any previous setting of the typemap
@ -362,7 +362,7 @@ void typemap_register_default(char *op, char *lang, int type, int ptr, char *arr
// Create a raw datatype from the arguments
t->is_pointer = ptr;
t->arraystr = copy_string(arraystr);
DataType_set_arraystr(t,arraystr);
// Now, go register this as a default type
@ -405,22 +405,23 @@ TypeMap *typemap_search(char *key, int id) {
// ------------------------------------------------------------------------
TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname, DOHString *str) {
char *origarr = type->arraystr;
char origarr[1024];
char *key;
int ndim,i,j,k,n;
TypeMap *tm;
char temp[10];
if (!type->arraystr) return 0;
if (!DataType_arraystr(type)) return 0;
strcpy(origarr,DataType_arraystr(type));
// First check to see if exactly this array has been mapped
key = typemap_string(lang,type,pname,type->arraystr,op);
key = typemap_string(lang,type,pname,DataType_arraystr(type),op);
tm = typemap_search(key,type->id);
// Check for unnamed array of specific dimensions
if (!tm) {
key = typemap_string(lang,type,(char*)"",type->arraystr,op);
key = typemap_string(lang,type,(char*)"",DataType_arraystr(type),op);
tm = typemap_search(key,type->id);
}
@ -441,14 +442,14 @@ TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname,
}
k = k >> 1;
}
type->arraystr = Char(tempastr);
key = typemap_string(lang,type,pname,type->arraystr,op);
DataType_set_arraystr(type, Char(tempastr));
key = typemap_string(lang,type,pname,DataType_arraystr(type),op);
tm = typemap_search(key,type->id);
if (!tm) {
key = typemap_string(lang,type,(char*)"",type->arraystr,op);
key = typemap_string(lang,type,(char*)"",DataType_arraystr(type),op);
tm = typemap_search(key,type->id);
}
type->arraystr = origarr;
DataType_set_arraystr(type,origarr);
if (tm) {
Delete(tempastr);
break;
@ -502,9 +503,9 @@ static void typemap_locals(DataType *t, char *pname, DOHString *s, ParmList *l,
}
// Have a real parameter here
if (tt->arraystr) {
if (DataType_arraystr(tt)) {
tt->is_pointer--;
Printf(str,"%s%s",p->name, tt->arraystr);
Printf(str,"%s%s",p->name, DataType_arraystr(tt));
}
else {
Printf(str,"%s",p->name);
@ -525,7 +526,7 @@ static void typemap_locals(DataType *t, char *pname, DOHString *s, ParmList *l,
else
new_name = Wrapper_new_localv(f,str, DataType_print_full(tt), str, 0);
if (tt->arraystr) tt->is_pointer++;
if (DataType_arraystr(tt)) tt->is_pointer++;
// Substitute
Replace(s,p->name,new_name,DOH_REPLACE_ID);
}
@ -535,7 +536,7 @@ static void typemap_locals(DataType *t, char *pname, DOHString *s, ParmList *l,
// If the original datatype was an array. We're going to go through and substitute
// it's array dimensions
if (t->arraystr) {
if (DataType_arraystr(t)) {
char temp[10];
for (int i = 0; i < DataType_array_dimensions(t); i++) {
sprintf(temp,"$dim%d",i);
@ -709,13 +710,16 @@ char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *so
m->type->is_pointer += drop_pointer;
// Copy old array string (just in case)
oldary = m->type->arraystr;
if (DataType_arraystr(m->type))
oldary = copy_string(DataType_arraystr(m->type));
else
oldary = 0;
// If the mapping type is an array and has the 'ANY' keyword, we
// have to play some magic
if ((m->type->arraystr) && (type->arraystr)) {
if ((DataType_arraystr(m->type)) && (DataType_arraystr(type))) {
// Build up the new array string
Clear(newarray);
for (int n = 0; n < DataType_array_dimensions(m->type); n++) {
@ -726,14 +730,16 @@ char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *so
Printf(newarray,"[%s]", d);
}
}
m->type->arraystr = Char(newarray);
} else if (type->arraystr) {
DataType_set_arraystr(m->type, Char(newarray));
} else if (DataType_arraystr(type)) {
// If an array string is available for the current datatype,
// make it available.
m->type->arraystr = type->arraystr;
DataType_set_arraystr(m->type,DataType_arraystr(type));
}
result = typemap_lookup_internal(op,lang,m->type,ppname,source,target,f);
m->type->arraystr = oldary;
DataType_set_arraystr(m->type,oldary);
if (oldary)
delete oldary;
m->type->is_pointer -= drop_pointer;
if (result) {
type->is_pointer += drop_pointer;
@ -762,8 +768,7 @@ char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *so
// Still no result, go even more primitive
t->type = T_USER;
t->is_pointer = 1;
if (t->arraystr) delete [] t->arraystr;
t->arraystr = 0;
DataType_set_arraystr(t,0);
DataType_primitive(t);
result = typemap_lookup_internal(op,lang,t,(char*)"SWIG_DEFAULT_TYPE",source,target,f);
}
@ -807,8 +812,8 @@ char *typemap_check_internal(char *op, char *lang, DataType *type, char *pname)
}
// Check for unnamed array
if ((!tm) && (type->arraystr)) {
key = typemap_string(lang,type,(char*)"",type->arraystr,op);
if ((!tm) && (DataType_arraystr(type))) {
key = typemap_string(lang,type,(char*)"",DataType_arraystr(type),op);
tm = typemap_search(key,type->id);
}
@ -866,12 +871,15 @@ char *typemap_check(char *op, char *lang, DataType *type, char *pname) {
if (*(m->name)) ppname = m->name;
else ppname = pname;
m->type->is_pointer += drop_pointer;
oldary = m->type->arraystr;
if (DataType_arraystr(m->type))
oldary = copy_string(DataType_arraystr(m->type));
else
oldary = 0;
// If the mapping type is an array and has the 'ANY' keyword, we
// have to play some magic
if ((m->type->arraystr) && (type->arraystr)) {
if ((DataType_arraystr(m->type)) && (DataType_arraystr(type))) {
// Build up the new array string
Clear(newarray);
for (int n = 0; n < DataType_array_dimensions(m->type); n++) {
@ -882,13 +890,13 @@ char *typemap_check(char *op, char *lang, DataType *type, char *pname) {
Printf(newarray,"[%s]", d);
}
}
oldary = m->type->arraystr;
m->type->arraystr = Char(newarray);
} else if (type->arraystr) {
m->type->arraystr = type->arraystr;
DataType_set_arraystr(m->type, Char(newarray));
} else if (DataType_arraystr(type)) {
DataType_set_arraystr(m->type, DataType_arraystr(type));
}
result = typemap_check_internal(op,lang,m->type,ppname);
m->type->arraystr = oldary;
DataType_set_arraystr(m->type,oldary);
if (oldary) delete oldary;
m->type->is_pointer -= drop_pointer;
if (result) {
type->is_pointer += drop_pointer;
@ -916,8 +924,7 @@ char *typemap_check(char *op, char *lang, DataType *type, char *pname) {
// Still no result, go even more primitive
t->type = T_USER;
t->is_pointer = 1;
if (t->arraystr) delete [] t->arraystr;
t->arraystr = 0;
DataType_set_arraystr(t,0);
DataType_primitive(t);
result = typemap_check_internal(op,lang,t,(char*)"SWIG_DEFAULT_TYPE");
}
@ -939,7 +946,7 @@ void typemap_clear(char *op, char *lang, DataType *type, char *pname) {
char *key;
TypeMap *tm;
key = typemap_string(lang,type,pname,type->arraystr,op);
key = typemap_string(lang,type,pname,DataType_arraystr(type),op);
// Look for any previous version, simply set the last id if
// applicable.
@ -966,7 +973,7 @@ void typemap_copy(char *op, char *lang, DataType *stype, char *sname,
// Try to locate a previous typemap
key = typemap_string(lang,stype,sname,stype->arraystr,op);
key = typemap_string(lang,stype,sname,DataType_arraystr(stype),op);
tm = typemap_search(key,stype->id);
if (!tm) return;
if (strcmp(ttype->name,"PREVIOUS") == 0) {

File diff suppressed because it is too large Load diff