Broke dependence between the DataType class and the Language class.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@575 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
82029dfd3b
commit
5b2c0ecc1c
5 changed files with 59 additions and 50 deletions
|
|
@ -143,6 +143,41 @@ static DOHString *modinit = 0;
|
||||||
static DOHString *modextern = 0;
|
static DOHString *modextern = 0;
|
||||||
static DOHString *pragma_include = 0;
|
static DOHString *pragma_include = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Perl specific type mangler function
|
||||||
|
static char *
|
||||||
|
type_mangle(DataType *t) {
|
||||||
|
static char result[128];
|
||||||
|
int i;
|
||||||
|
char *r, *c;
|
||||||
|
|
||||||
|
if (blessed) {
|
||||||
|
|
||||||
|
// Check to see if we've blessed this datatype
|
||||||
|
|
||||||
|
if ((Getattr(classes,t->name)) && (t->is_pointer <= 1)) {
|
||||||
|
|
||||||
|
// This is a blessed class. Return just the type-name
|
||||||
|
strcpy(result, GetChar(classes,t->name));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r = result;
|
||||||
|
c = t->name;
|
||||||
|
|
||||||
|
for ( c = t->name; *c; c++,r++) {
|
||||||
|
*r = *c;
|
||||||
|
}
|
||||||
|
for (i = 0; i < (t->is_pointer-t->implicit_ptr); i++, r++) {
|
||||||
|
strcpy(r,"Ptr");
|
||||||
|
r+=2;
|
||||||
|
}
|
||||||
|
*r = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// PERL5::parse_args(int argc, char *argv[])
|
// PERL5::parse_args(int argc, char *argv[])
|
||||||
//
|
//
|
||||||
|
|
@ -258,6 +293,8 @@ PERL5::parse() {
|
||||||
modextern = NewString("");
|
modextern = NewString("");
|
||||||
pragma_include = NewString("");
|
pragma_include = NewString("");
|
||||||
|
|
||||||
|
DataType_set_mangle(type_mangle);
|
||||||
|
|
||||||
// Print out PERL5 specific headers
|
// Print out PERL5 specific headers
|
||||||
|
|
||||||
headers();
|
headers();
|
||||||
|
|
@ -648,45 +685,6 @@ void PERL5::close(void)
|
||||||
Delete(base);
|
Delete(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// char *PERL5::type_mangle(DataType *t)
|
|
||||||
//
|
|
||||||
// Mangles a datatype into a Perl5 name compatible with xsubpp type
|
|
||||||
// T_PTROBJ.
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
char *
|
|
||||||
PERL5::type_mangle(DataType *t) {
|
|
||||||
static char result[128];
|
|
||||||
int i;
|
|
||||||
char *r, *c;
|
|
||||||
|
|
||||||
if (blessed) {
|
|
||||||
|
|
||||||
// Check to see if we've blessed this datatype
|
|
||||||
|
|
||||||
if ((Getattr(classes,t->name)) && (t->is_pointer <= 1)) {
|
|
||||||
|
|
||||||
// This is a blessed class. Return just the type-name
|
|
||||||
strcpy(result, GetChar(classes,t->name));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
r = result;
|
|
||||||
c = t->name;
|
|
||||||
|
|
||||||
for ( c = t->name; *c; c++,r++) {
|
|
||||||
*r = *c;
|
|
||||||
}
|
|
||||||
for (i = 0; i < (t->is_pointer-t->implicit_ptr); i++, r++) {
|
|
||||||
strcpy(r,"Ptr");
|
|
||||||
r+=2;
|
|
||||||
}
|
|
||||||
*r = 0;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// PERL5::get_pointer(char *iname, char *srcname, char *src, char *target,
|
// PERL5::get_pointer(char *iname, char *srcname, char *src, char *target,
|
||||||
// DataType *t, String &f, char *ret)
|
// DataType *t, String &f, char *ret)
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ public :
|
||||||
virtual void set_init(char *);
|
virtual void set_init(char *);
|
||||||
virtual void add_native(char *, char *, DataType *, ParmList *);
|
virtual void add_native(char *, char *, DataType *, ParmList *);
|
||||||
virtual void create_command(char *, char *);
|
virtual void create_command(char *, char *);
|
||||||
virtual char *type_mangle(DataType *);
|
|
||||||
|
|
||||||
// Support for blessed perl thingies....
|
// Support for blessed perl thingies....
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -909,6 +909,7 @@ statement : INCLUDE STRING LBRACE {
|
||||||
temp_type->implicit_ptr = 0;
|
temp_type->implicit_ptr = 0;
|
||||||
sprintf(temp_type->name,"int");
|
sprintf(temp_type->name,"int");
|
||||||
DataType_typedef_add(temp_type,$3,1);
|
DataType_typedef_add(temp_type,$3,1);
|
||||||
|
lang->add_typedef(temp_type,$3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -922,6 +923,7 @@ statement : INCLUDE STRING LBRACE {
|
||||||
sprintf(temp_type->name,"int");
|
sprintf(temp_type->name,"int");
|
||||||
Active_typedef = CopyDataType(temp_type);
|
Active_typedef = CopyDataType(temp_type);
|
||||||
DataType_typedef_add(temp_type,$8,1);
|
DataType_typedef_add(temp_type,$8,1);
|
||||||
|
lang->add_typedef(temp_type,$8);
|
||||||
} typedeflist { }
|
} typedeflist { }
|
||||||
|
|
||||||
/* -----------------------------------------------------------------
|
/* -----------------------------------------------------------------
|
||||||
|
|
@ -1143,6 +1145,7 @@ typedef_decl : TYPEDEF type declaration {
|
||||||
Active_typedef = CopyDataType($2);
|
Active_typedef = CopyDataType($2);
|
||||||
$2->is_pointer += $3.is_pointer;
|
$2->is_pointer += $3.is_pointer;
|
||||||
DataType_typedef_add($2, $3.id,0);
|
DataType_typedef_add($2, $3.id,0);
|
||||||
|
lang->add_typedef($2,$3.id);
|
||||||
/* If this is %typedef, add it to the header */
|
/* If this is %typedef, add it to the header */
|
||||||
if ($1)
|
if ($1)
|
||||||
fprintf(f_header,"typedef %s %s;\n", DataType_print_full($2), $3.id);
|
fprintf(f_header,"typedef %s %s;\n", DataType_print_full($2), $3.id);
|
||||||
|
|
@ -1163,6 +1166,7 @@ typedef_decl : TYPEDEF type declaration {
|
||||||
$2->type = T_USER;
|
$2->type = T_USER;
|
||||||
$2->is_pointer = 1;
|
$2->is_pointer = 1;
|
||||||
DataType_typedef_add($2,$5,1);
|
DataType_typedef_add($2,$5,1);
|
||||||
|
lang->add_typedef($2,$5);
|
||||||
cplus_register_type($5);
|
cplus_register_type($5);
|
||||||
DelDataType($2);
|
DelDataType($2);
|
||||||
delete $5;
|
delete $5;
|
||||||
|
|
@ -1185,6 +1189,7 @@ typedef_decl : TYPEDEF type declaration {
|
||||||
$2->type = T_USER;
|
$2->type = T_USER;
|
||||||
$2->is_pointer = 1;
|
$2->is_pointer = 1;
|
||||||
DataType_typedef_add($2,$6,1);
|
DataType_typedef_add($2,$6,1);
|
||||||
|
lang->add_typedef($2,$6);
|
||||||
cplus_register_type($6);
|
cplus_register_type($6);
|
||||||
DelDataType($2);
|
DelDataType($2);
|
||||||
delete $6;
|
delete $6;
|
||||||
|
|
@ -1204,6 +1209,7 @@ typedef_decl : TYPEDEF type declaration {
|
||||||
$2->is_pointer++;
|
$2->is_pointer++;
|
||||||
$2->arraystr = copy_string(Char(ArrayString));
|
$2->arraystr = copy_string(Char(ArrayString));
|
||||||
DataType_typedef_add($2,$3.id,0);
|
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);
|
fprintf(stderr,"%s : Line %d. Warning. Array type %s will be read-only without a typemap\n",input_file,line_number, $3.id);
|
||||||
cplus_register_type($3.id);
|
cplus_register_type($3.id);
|
||||||
|
|
||||||
|
|
@ -1226,6 +1232,7 @@ typedeflist : COMMA declaration typedeflist {
|
||||||
t = CopyDataType(Active_typedef);
|
t = CopyDataType(Active_typedef);
|
||||||
t->is_pointer += $2.is_pointer;
|
t->is_pointer += $2.is_pointer;
|
||||||
DataType_typedef_add(t,$2.id,0);
|
DataType_typedef_add(t,$2.id,0);
|
||||||
|
lang->add_typedef(t,$2.id);
|
||||||
cplus_register_type($2.id);
|
cplus_register_type($2.id);
|
||||||
DelDataType(t);
|
DelDataType(t);
|
||||||
}
|
}
|
||||||
|
|
@ -1237,6 +1244,7 @@ typedeflist : COMMA declaration typedeflist {
|
||||||
t->is_pointer += $2.is_pointer + 1;
|
t->is_pointer += $2.is_pointer + 1;
|
||||||
t->arraystr = copy_string(Char(ArrayString));
|
t->arraystr = copy_string(Char(ArrayString));
|
||||||
DataType_typedef_add(t,$2.id,0);
|
DataType_typedef_add(t,$2.id,0);
|
||||||
|
lang->add_typedef(t,$2.id);
|
||||||
cplus_register_type($2.id);
|
cplus_register_type($2.id);
|
||||||
DelDataType(t);
|
DelDataType(t);
|
||||||
fprintf(stderr,"%s : Line %d. Warning. Array type %s will be read-only without a typemap.\n",input_file,line_number, $2.id);
|
fprintf(stderr,"%s : Line %d. Warning. Array type %s will be read-only without a typemap.\n",input_file,line_number, $2.id);
|
||||||
|
|
@ -2119,12 +2127,14 @@ cpp_class :
|
||||||
cplus_class_close($9.id);
|
cplus_class_close($9.id);
|
||||||
}
|
}
|
||||||
// Create a typedef in global scope
|
// Create a typedef in global scope
|
||||||
if ($9.is_pointer == 0)
|
if ($9.is_pointer == 0) {
|
||||||
DataType_typedef_add(Active_typedef,$9.id,0);
|
DataType_typedef_add(Active_typedef,$9.id,0);
|
||||||
else {
|
lang->add_typedef(Active_typedef,$9.id);
|
||||||
|
} else {
|
||||||
DataType *t = CopyDataType(Active_typedef);
|
DataType *t = CopyDataType(Active_typedef);
|
||||||
t->is_pointer += $9.is_pointer;
|
t->is_pointer += $9.is_pointer;
|
||||||
DataType_typedef_add(t,$9.id,0);
|
DataType_typedef_add(t,$9.id,0);
|
||||||
|
lang->add_typedef(t,$9.id);
|
||||||
cplus_register_type($9.id);
|
cplus_register_type($9.id);
|
||||||
DelDataType(t);
|
DelDataType(t);
|
||||||
}
|
}
|
||||||
|
|
@ -2507,6 +2517,7 @@ cpp_member : type declaration LPAREN parms RPAREN cpp_end {
|
||||||
temp_type->implicit_ptr = 0;
|
temp_type->implicit_ptr = 0;
|
||||||
sprintf(temp_type->name,"int");
|
sprintf(temp_type->name,"int");
|
||||||
DataType_typedef_add(temp_type,$2,1);
|
DataType_typedef_add(temp_type,$2,1);
|
||||||
|
lang->add_typedef(temp_type,$2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ extern char *DataType_print_mangle(DataType *);
|
||||||
extern char *DataType_print_real(DataType *, char *local);
|
extern char *DataType_print_real(DataType *, char *local);
|
||||||
extern char *DataType_print_arraycast(DataType *);
|
extern char *DataType_print_arraycast(DataType *);
|
||||||
extern char *DataType_print_mangle_default(DataType *);
|
extern char *DataType_print_mangle_default(DataType *);
|
||||||
|
extern void DataType_set_mangle(char *(*m)(DataType *));
|
||||||
extern int DataType_array_dimensions(DataType *);
|
extern int DataType_array_dimensions(DataType *);
|
||||||
extern char *DataType_get_dimension(DataType *, int);
|
extern char *DataType_get_dimension(DataType *, int);
|
||||||
|
|
||||||
|
|
@ -294,8 +294,6 @@ struct Pragma {
|
||||||
* add_native(char *name, char *funcname);
|
* add_native(char *name, char *funcname);
|
||||||
* Adds a native wrapper function to the initialize process
|
* Adds a native wrapper function to the initialize process
|
||||||
*
|
*
|
||||||
* type_mangle(DataType *t);
|
|
||||||
* Mangles the name of a datatype.
|
|
||||||
* --- C++ Functions ---
|
* --- C++ Functions ---
|
||||||
*
|
*
|
||||||
* These functions are optional additions to any of the target
|
* These functions are optional additions to any of the target
|
||||||
|
|
@ -338,9 +336,6 @@ public:
|
||||||
virtual void set_module(char *mod_name,char **mod_list) = 0;
|
virtual void set_module(char *mod_name,char **mod_list) = 0;
|
||||||
virtual void set_init(char *init_name);
|
virtual void set_init(char *init_name);
|
||||||
virtual void add_native(char *name, char *iname, DataType *t, ParmList *l);
|
virtual void add_native(char *name, char *iname, DataType *t, ParmList *l);
|
||||||
virtual char *type_mangle(DataType *t) {
|
|
||||||
return DataType_print_mangle_default(t);
|
|
||||||
}
|
|
||||||
virtual void add_typedef(DataType *t, char *name);
|
virtual void add_typedef(DataType *t, char *name);
|
||||||
virtual void create_command(char *cname, char *iname);
|
virtual void create_command(char *cname, char *iname);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -351,9 +351,15 @@ char *DataType_print_mangle_default(DataType *t) {
|
||||||
// This is kind of ugly but needed for each language to support a
|
// This is kind of ugly but needed for each language to support a
|
||||||
// custom name mangling mechanism. (ie. Perl5).
|
// custom name mangling mechanism. (ie. Perl5).
|
||||||
|
|
||||||
|
static char *(*mangler)(DataType *t) = DataType_print_mangle_default;
|
||||||
|
|
||||||
char *DataType_print_mangle(DataType *t) {
|
char *DataType_print_mangle(DataType *t) {
|
||||||
// Call into target language for name mangling.
|
// Call into target language for name mangling.
|
||||||
return lang->type_mangle(t);
|
return (*mangler)(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataType_set_mangle(char *(*m)(DataType *t)) {
|
||||||
|
mangler = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
@ -485,7 +491,7 @@ void DataType_typedef_add(DataType *t,char *tname, int mode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Call into the target language with this typedef
|
// Call into the target language with this typedef
|
||||||
lang->add_typedef(t,tname);
|
/* lang->add_typedef(t,tname); */
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue