Major slash and burn. Virtually all of the 1.1 core has been divorced from the C++ String class and migrated to DOHString instead.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@536 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
27a1a623ff
commit
bfab30a055
11 changed files with 609 additions and 641 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -219,29 +219,30 @@ int emit_args(DataType *rt, ParmList *l, WrapperFunction &f) {
|
||||||
// Figure out default values
|
// Figure out default values
|
||||||
if (((p->t->is_reference) && (p->defvalue)) ||
|
if (((p->t->is_reference) && (p->defvalue)) ||
|
||||||
((p->t->type == T_USER) && (p->call_type == CALL_REFERENCE) && (p->defvalue))) {
|
((p->t->type == T_USER) && (p->call_type == CALL_REFERENCE) && (p->defvalue))) {
|
||||||
String deftmp;
|
char deftmp[1024];
|
||||||
deftmp << "(" << p->t->print_type() << ") &" << p->defvalue;
|
sprintf(deftmp,"(%s) &%s", p->t->print_type(), p->defvalue);
|
||||||
f.add_local(p->t->print_type(),temp,deftmp.get());
|
f.add_local(p->t->print_type(),temp,deftmp);
|
||||||
} else {
|
} else {
|
||||||
String deftmp;
|
char deftmp[1024];
|
||||||
char *dv = 0;
|
|
||||||
if (p->defvalue) {
|
if (p->defvalue) {
|
||||||
deftmp << "(" << p->t->print_type() << ") " << p->defvalue;
|
sprintf(deftmp,"(%s) %s", p->t->print_type(), p->defvalue);
|
||||||
dv = deftmp.get();
|
f.add_local(p->t->print_type(), temp, deftmp);
|
||||||
|
} else {
|
||||||
|
f.add_local(p->t->print_type(), temp, 0);
|
||||||
}
|
}
|
||||||
f.add_local(p->t->print_type(), temp, dv);
|
|
||||||
tm = typemap_lookup((char*)"arginit", typemap_lang, p->t,p->name,(char*)"",temp,&f);
|
tm = typemap_lookup((char*)"arginit", typemap_lang, p->t,p->name,(char*)"",temp,&f);
|
||||||
if (tm) {
|
if (tm) {
|
||||||
f.code << tm << "\n";
|
Printv(f._code,tm,"\n",0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for ignore or default typemaps
|
// Check for ignore or default typemaps
|
||||||
tm = typemap_lookup((char*)"default",typemap_lang,p->t,p->name,(char*)"",temp,&f);
|
tm = typemap_lookup((char*)"default",typemap_lang,p->t,p->name,(char*)"",temp,&f);
|
||||||
if (tm)
|
if (tm)
|
||||||
f.code << tm << "\n";
|
Printv(f._code,tm,"\n",0);
|
||||||
tm = typemap_lookup((char*)"ignore",typemap_lang,p->t,p->name,(char*)"",temp,&f);
|
tm = typemap_lookup((char*)"ignore",typemap_lang,p->t,p->name,(char*)"",temp,&f);
|
||||||
if (tm) {
|
if (tm) {
|
||||||
f.code << tm << "\n";
|
Printv(f._code,tm,"\n",0);
|
||||||
p->ignore = 1;
|
p->ignore = 1;
|
||||||
}
|
}
|
||||||
tm = typemap_check((char*)"build",typemap_lang,p->t,p->name);
|
tm = typemap_check((char*)"build",typemap_lang,p->t,p->name);
|
||||||
|
|
@ -274,12 +275,12 @@ void emit_func_call(char *decl, DataType *t, ParmList *l, WrapperFunction &f) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
Parm *p;
|
Parm *p;
|
||||||
String fcall;
|
DOHString *fcall;
|
||||||
String exc;
|
DOHString *exc;
|
||||||
char *tm;
|
char *tm;
|
||||||
|
|
||||||
// f.code << "#line " << line_number << " \"" << input_file << "\"\n";
|
fcall = NewString(tab4);
|
||||||
fcall << tab4;
|
exc = NewString("");
|
||||||
|
|
||||||
// First check if there is a return value
|
// First check if there is a return value
|
||||||
|
|
||||||
|
|
@ -291,77 +292,78 @@ void emit_func_call(char *decl, DataType *t, ParmList *l, WrapperFunction &f) {
|
||||||
// used properly.
|
// used properly.
|
||||||
|
|
||||||
if (CPlusPlus) {
|
if (CPlusPlus) {
|
||||||
fcall << "_result = new " << t->print_type() << "(";
|
Printv(fcall, "_result = new ", t->print_type(), "(", 0);
|
||||||
} else {
|
} else {
|
||||||
t->is_pointer++;
|
t->is_pointer++;
|
||||||
fcall << "_result = " << t->print_cast() << " malloc(sizeof(";
|
Printv(fcall, "_result = ", t->print_cast(), " malloc(sizeof(", 0);
|
||||||
t->is_pointer--;
|
t->is_pointer--;
|
||||||
fcall << t->print_type() << "));\n";
|
Printv(fcall, t->print_type(), "));\n", 0);
|
||||||
fcall << tab4 << "*(_result) = ";
|
Printv(fcall, tab4, "*(_result) = ", 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check if this is a C++ reference
|
// Check if this is a C++ reference
|
||||||
if (t->is_reference) {
|
if (t->is_reference) {
|
||||||
t->is_pointer--;
|
t->is_pointer--;
|
||||||
fcall << t->print_full() << "& _result_ref = ";
|
Printv(fcall, t->print_full(), "& _result_ref = ", 0);
|
||||||
t->is_pointer++;
|
t->is_pointer++;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Normal return value
|
// Normal return value
|
||||||
fcall << "_result = " << t->print_cast();
|
Printv(fcall, "_result = ", t->print_cast(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now print out function call
|
// Now print out function call
|
||||||
|
Printv(fcall, decl, "(", 0);
|
||||||
fcall << decl << "(";
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
p = l->get_first();
|
p = l->get_first();
|
||||||
while(p != 0) {
|
while(p != 0) {
|
||||||
if ((p->t->type != T_VOID) || (p->t->is_pointer)){
|
if ((p->t->type != T_VOID) || (p->t->is_pointer)){
|
||||||
fcall << p->t->print_arraycast();
|
Printf(fcall,p->t->print_arraycast());
|
||||||
if ((!p->t->is_reference) && (p->call_type & CALL_VALUE))
|
if ((!p->t->is_reference) && (p->call_type & CALL_VALUE))
|
||||||
fcall << "&";
|
Printf(fcall, "&");
|
||||||
if ((!(p->call_type & CALL_VALUE)) &&
|
if ((!(p->call_type & CALL_VALUE)) &&
|
||||||
((p->t->is_reference) || (p->call_type & CALL_REFERENCE)))
|
((p->t->is_reference) || (p->call_type & CALL_REFERENCE)))
|
||||||
fcall << "*";
|
Printf(fcall, "*");
|
||||||
fcall << emit_local(i);
|
Printf(fcall, emit_local(i));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
p = l->get_next();
|
p = l->get_next();
|
||||||
if (p != 0)
|
if (p != 0)
|
||||||
fcall << ",";
|
Printf(fcall,",");
|
||||||
}
|
}
|
||||||
fcall << ")";
|
Printf(fcall,")");
|
||||||
|
|
||||||
if ((t->type == T_USER) && (!t->is_pointer)) {
|
if ((t->type == T_USER) && (!t->is_pointer)) {
|
||||||
if (CPlusPlus) {
|
if (CPlusPlus) {
|
||||||
fcall << ")";
|
Printf(fcall,")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fcall << ";\n";
|
Printf(fcall,";\n");
|
||||||
|
|
||||||
if (t->is_reference) {
|
if (t->is_reference) {
|
||||||
fcall << tab4 << "_result = "<< t->print_cast() << " &_result_ref;\n";
|
Printv(fcall, tab4, "_result = ", t->print_cast(), " &_result_ref;\n", 0);
|
||||||
}
|
}
|
||||||
// Check for exception handling
|
// Check for exception handling
|
||||||
|
|
||||||
if ((tm = typemap_lookup((char*)"except",typemap_lang,t,decl,(char*)"_result",(char*)""))) {
|
if ((tm = typemap_lookup((char*)"except",typemap_lang,t,decl,(char*)"_result",(char*)""))) {
|
||||||
// Found a type-specific mapping
|
// Found a type-specific mapping
|
||||||
exc << tm;
|
Printv(exc,tm);
|
||||||
exc.replace("$function",fcall.get());
|
Replace(exc,"$function",fcall,DOH_REPLACE_ANY);
|
||||||
exc.replace("$name",decl);
|
Replace(exc,"$name",decl,DOH_REPLACE_ANY);
|
||||||
f.code << exc;
|
Printv(f._code,exc,0);
|
||||||
} else if ((tm = fragment_lookup((char*)"except",typemap_lang, t->id))) {
|
} else if ((tm = fragment_lookup((char*)"except",typemap_lang, t->id))) {
|
||||||
exc << tm;
|
Printv(exc,tm);
|
||||||
exc.replace("$function",fcall.get());
|
Replace(exc,"$function",fcall,DOH_REPLACE_ANY);
|
||||||
exc.replace("$name",decl);
|
Replace(exc,"$name",decl,DOH_REPLACE_ANY);
|
||||||
f.code << exc;
|
Printv(f._code,exc,0);
|
||||||
} else {
|
} else {
|
||||||
f.code << fcall;
|
Printv(f._code,fcall,0);
|
||||||
}
|
}
|
||||||
|
Delete(fcall);
|
||||||
|
Delete(exc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
@ -401,9 +403,7 @@ void emit_set_get(char *name, char *iname, DataType *t) {
|
||||||
|
|
||||||
Parm *p;
|
Parm *p;
|
||||||
ParmList *l;
|
ParmList *l;
|
||||||
String new_name;
|
char *new_name = 0, *new_iname = 0;
|
||||||
String new_iname;
|
|
||||||
String wname;
|
|
||||||
|
|
||||||
// First write a function to set the variable of the variable
|
// First write a function to set the variable of the variable
|
||||||
|
|
||||||
|
|
@ -467,15 +467,15 @@ void emit_set_get(char *name, char *iname, DataType *t) {
|
||||||
p->name[0] = 0;
|
p->name[0] = 0;
|
||||||
l->append(p);
|
l->append(p);
|
||||||
|
|
||||||
new_name = Swig_name_set(name);
|
new_name = copy_string(Swig_name_set(name));
|
||||||
new_iname = Swig_name_set(iname);
|
new_iname = copy_string(Swig_name_set(iname));
|
||||||
|
|
||||||
if ((t->type == T_USER) && (!t->is_pointer)) {
|
if ((t->type == T_USER) && (!t->is_pointer)) {
|
||||||
t->is_pointer++;
|
t->is_pointer++;
|
||||||
lang->create_function(new_name.get(), new_iname.get(), t, l);
|
lang->create_function(new_name, new_iname, t, l);
|
||||||
t->is_pointer--;
|
t->is_pointer--;
|
||||||
} else {
|
} else {
|
||||||
lang->create_function(new_name.get(), new_iname.get(), t, l);
|
lang->create_function(new_name, new_iname, t, l);
|
||||||
}
|
}
|
||||||
delete l;
|
delete l;
|
||||||
delete p;
|
delete p;
|
||||||
|
|
@ -501,17 +501,22 @@ void emit_set_get(char *name, char *iname, DataType *t) {
|
||||||
|
|
||||||
l = new ParmList;
|
l = new ParmList;
|
||||||
|
|
||||||
new_name = Swig_name_get(name);
|
if (new_name) delete [] new_name;
|
||||||
new_iname = Swig_name_get(iname);
|
if (new_iname) delete [] new_iname;
|
||||||
|
|
||||||
|
new_name = copy_string(Swig_name_get(name));
|
||||||
|
new_iname = copy_string(Swig_name_get(iname));
|
||||||
|
|
||||||
if ((t->type == T_USER) && (!t->is_pointer)) {
|
if ((t->type == T_USER) && (!t->is_pointer)) {
|
||||||
t->is_pointer++;
|
t->is_pointer++;
|
||||||
lang->create_function(new_name.get(), new_iname.get(), t, l);
|
lang->create_function(new_name, new_iname, t, l);
|
||||||
t->is_pointer--;
|
t->is_pointer--;
|
||||||
} else {
|
} else {
|
||||||
lang->create_function(new_name.get(), new_iname.get(), t, l);
|
lang->create_function(new_name, new_iname, t, l);
|
||||||
}
|
}
|
||||||
delete l;
|
delete l;
|
||||||
|
delete [] new_name;
|
||||||
|
delete [] new_iname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
extern Language *lang;
|
extern Language *lang;
|
||||||
extern int ForceExtern;
|
extern int ForceExtern;
|
||||||
extern int WrapExtern;
|
extern int WrapExtern;
|
||||||
extern String CCode;
|
extern void *CCode;
|
||||||
extern int GenerateDefault;
|
extern int GenerateDefault;
|
||||||
extern int type_id;
|
extern int type_id;
|
||||||
extern char *objc_construct;
|
extern char *objc_construct;
|
||||||
|
|
|
||||||
|
|
@ -148,6 +148,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
||||||
extern int check_suffix(char *);
|
extern int check_suffix(char *);
|
||||||
extern void scanner_file(FILE *);
|
extern void scanner_file(FILE *);
|
||||||
extern void typemap_initialize(void);
|
extern void typemap_initialize(void);
|
||||||
|
extern void parser_init(void);
|
||||||
|
|
||||||
DOH *libfiles = 0;
|
DOH *libfiles = 0;
|
||||||
|
|
||||||
#ifdef MACSWIG
|
#ifdef MACSWIG
|
||||||
|
|
@ -481,6 +483,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
||||||
fprintf (stdout, "Starting language-specific parse...\n");
|
fprintf (stdout, "Starting language-specific parse...\n");
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
}
|
}
|
||||||
|
parser_init();
|
||||||
lang->parse();
|
lang->parse();
|
||||||
if (Verbose) {
|
if (Verbose) {
|
||||||
fprintf (stdout, "Finished language-specific parse.\n");
|
fprintf (stdout, "Finished language-specific parse.\n");
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ static char cvsroot[] = "$Header$";
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "doh.h"
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Parm::Parm(DataType *type, char *n)
|
// Parm::Parm(DataType *type, char *n)
|
||||||
//
|
//
|
||||||
|
|
@ -320,7 +324,7 @@ Parm * ParmList::get_next() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// void ParmList::print_types(FILE *f)
|
// void ParmList::print_types(DOHFile *f)
|
||||||
//
|
//
|
||||||
// Prints a comma separated list of all of the parameter types.
|
// Prints a comma separated list of all of the parameter types.
|
||||||
// This is for generating valid C prototypes. Has to do some
|
// This is for generating valid C prototypes. Has to do some
|
||||||
|
|
@ -328,7 +332,7 @@ Parm * ParmList::get_next() {
|
||||||
// variable has been set.
|
// variable has been set.
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
void ParmList::print_types(FILE *f) {
|
void ParmList::print_types(DOHFile *f) {
|
||||||
|
|
||||||
int is_pointer;
|
int is_pointer;
|
||||||
int pn;
|
int pn;
|
||||||
|
|
@ -338,59 +342,23 @@ void ParmList::print_types(FILE *f) {
|
||||||
if (parms[pn]->t->is_reference) {
|
if (parms[pn]->t->is_reference) {
|
||||||
if (parms[pn]->t->is_pointer) {
|
if (parms[pn]->t->is_pointer) {
|
||||||
parms[pn]->t->is_pointer--;
|
parms[pn]->t->is_pointer--;
|
||||||
fprintf(f,"%s&", parms[pn]->t->print_real());
|
Printf(f,"%s&", parms[pn]->t->print_real());
|
||||||
parms[pn]->t->is_pointer++;
|
parms[pn]->t->is_pointer++;
|
||||||
} else {
|
} else {
|
||||||
fprintf(f,"%s&", parms[pn]->t->print_real());
|
Printf(f,"%s&", parms[pn]->t->print_real());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (parms[pn]->call_type & CALL_VALUE) parms[pn]->t->is_pointer++;
|
if (parms[pn]->call_type & CALL_VALUE) parms[pn]->t->is_pointer++;
|
||||||
if (parms[pn]->call_type & CALL_REFERENCE) parms[pn]->t->is_pointer--;
|
if (parms[pn]->call_type & CALL_REFERENCE) parms[pn]->t->is_pointer--;
|
||||||
fprintf(f,"%s", parms[pn]->t->print_real());
|
Printf(f,"%s", parms[pn]->t->print_real());
|
||||||
parms[pn]->t->is_pointer = is_pointer;
|
parms[pn]->t->is_pointer = is_pointer;
|
||||||
}
|
}
|
||||||
pn++;
|
pn++;
|
||||||
if (pn < nparms)
|
if (pn < nparms)
|
||||||
fprintf(f,",");
|
Printf(f,",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
// void ParmList::print_types(String &f)
|
|
||||||
//
|
|
||||||
// Generates a comma separated list of function types. Is used in
|
|
||||||
// C++ code generation when generating hash keys and for function overloading.
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
void ParmList::print_types(String &f) {
|
|
||||||
|
|
||||||
int is_pointer;
|
|
||||||
int pn;
|
|
||||||
pn = 0;
|
|
||||||
while(pn < nparms) {
|
|
||||||
is_pointer = parms[pn]->t->is_pointer;
|
|
||||||
if (parms[pn]->t->is_reference) {
|
|
||||||
if (parms[pn]->t->is_pointer) {
|
|
||||||
parms[pn]->t->is_pointer--;
|
|
||||||
f << parms[pn]->t->print_real() << "&";
|
|
||||||
parms[pn]->t->is_pointer++;
|
|
||||||
} else {
|
|
||||||
f << parms[pn]->t->print_real() << "&";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (parms[pn]->call_type & CALL_VALUE) parms[pn]->t->is_pointer++;
|
|
||||||
if (parms[pn]->call_type & CALL_REFERENCE) parms[pn]->t->is_pointer--;
|
|
||||||
f << parms[pn]->t->print_real();
|
|
||||||
parms[pn]->t->is_pointer = is_pointer;
|
|
||||||
}
|
|
||||||
pn++;
|
|
||||||
if (pn < nparms)
|
|
||||||
f << ",";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// void ParmList::print_args(FILE *f)
|
// void ParmList::print_args(FILE *f)
|
||||||
//
|
//
|
||||||
|
|
@ -424,27 +392,3 @@ void ParmList::print_args(FILE *f) {
|
||||||
fprintf(f,",");
|
fprintf(f,",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
|
||||||
// void ParmList::sub_parmnames(String &s)
|
|
||||||
//
|
|
||||||
// Given a string, this function substitutes all of the parameter
|
|
||||||
// names with their internal representation. Used in very special
|
|
||||||
// kinds of typemaps.
|
|
||||||
// -------------------------------------------------------------------
|
|
||||||
|
|
||||||
void ParmList::sub_parmnames(String &s) {
|
|
||||||
Parm *p;
|
|
||||||
extern char *emit_local(int i);
|
|
||||||
for (int i = 0; i < nparms; i++) {
|
|
||||||
p = get(i);
|
|
||||||
if (strlen(p->name) > 0) {
|
|
||||||
s.replaceid(p->name, emit_local(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,8 @@ static int Active_extern = 0; // Whether or not list is externa
|
||||||
static int Active_static = 0;
|
static int Active_static = 0;
|
||||||
static DataType *Active_typedef = 0; // Used for typedef lists
|
static DataType *Active_typedef = 0; // Used for typedef lists
|
||||||
static int InArray = 0; // Used when an array declaration is found
|
static int InArray = 0; // Used when an array declaration is found
|
||||||
static String ArrayString; // Array type attached to parameter names
|
static DOHString *ArrayString = 0; // Array type attached to parameter names
|
||||||
static String ArrayBackup; // Array backup string
|
static DOHString *ArrayBackup = 0;
|
||||||
static char *DefArg = 0; // Default argument hack
|
static char *DefArg = 0; // Default argument hack
|
||||||
static char *ConstChar = 0; // Used to store raw character constants
|
static char *ConstChar = 0; // Used to store raw character constants
|
||||||
static ParmList *tm_parm = 0; // Parameter list used to hold typemap parameters
|
static ParmList *tm_parm = 0; // Parameter list used to hold typemap parameters
|
||||||
|
|
@ -116,7 +116,11 @@ extern void cplus_add_pragma(char *, char *, char *);
|
||||||
extern void cplus_set_class(char *);
|
extern void cplus_set_class(char *);
|
||||||
extern void cplus_unset_class();
|
extern void cplus_unset_class();
|
||||||
extern void cplus_abort();
|
extern void cplus_abort();
|
||||||
|
|
||||||
|
void parser_init() {
|
||||||
|
ArrayString = NewString("");
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// static init_language()
|
// static init_language()
|
||||||
//
|
//
|
||||||
|
|
@ -181,11 +185,12 @@ static char *make_name(char *name) {
|
||||||
} else {
|
} else {
|
||||||
// Now check to see if the name contains a $
|
// Now check to see if the name contains a $
|
||||||
if (strchr(name,'$')) {
|
if (strchr(name,'$')) {
|
||||||
static String temp;
|
static DOHString *temp = 0;
|
||||||
temp = "";
|
if (!temp) temp= NewString("");
|
||||||
temp << name;
|
Clear(temp);
|
||||||
temp.replace("$","_S_");
|
Append(temp,name);
|
||||||
return temp.get();
|
Replace(temp,"$","_S_",DOH_REPLACE_ANY);
|
||||||
|
return Char(temp);
|
||||||
} else {
|
} else {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
@ -312,7 +317,7 @@ void print_array() {
|
||||||
// Structures for handling code fragments built for nested classes
|
// Structures for handling code fragments built for nested classes
|
||||||
|
|
||||||
struct Nested {
|
struct Nested {
|
||||||
String code; // Associated code fragment
|
DOHString *code; // Associated code fragment
|
||||||
int line; // line number where it starts
|
int line; // line number where it starts
|
||||||
char *name; // Name associated with this nested class
|
char *name; // Name associated with this nested class
|
||||||
DataType *type; // Datatype associated with the name
|
DataType *type; // Datatype associated with the name
|
||||||
|
|
@ -347,7 +352,7 @@ static void dump_nested(char *parent) {
|
||||||
Status = STAT_READONLY;
|
Status = STAT_READONLY;
|
||||||
while (n) {
|
while (n) {
|
||||||
// Token replace the name of the parent class
|
// Token replace the name of the parent class
|
||||||
n->code.replace("$classname",parent);
|
Replace(n->code, "$classname", parent, DOH_REPLACE_ANY);
|
||||||
|
|
||||||
// Fix up the name of the datatype (for building typedefs and other stuff)
|
// Fix up the name of the datatype (for building typedefs and other stuff)
|
||||||
sprintf(n->type->name,"%s_%s",parent,n->name);
|
sprintf(n->type->name,"%s_%s",parent,n->name);
|
||||||
|
|
@ -357,10 +362,11 @@ static void dump_nested(char *parent) {
|
||||||
|
|
||||||
// Dump the code to the scanner
|
// Dump the code to the scanner
|
||||||
|
|
||||||
fprintf(f_header,"\n%s\n", n->code.get());
|
fprintf(f_header,"\n%s\n", Char(n->code));
|
||||||
start_inline(n->code.get(),n->line);
|
start_inline(Char(n->code),n->line);
|
||||||
|
|
||||||
n1 = n->next;
|
n1 = n->next;
|
||||||
|
Delete(n->code);
|
||||||
delete n;
|
delete n;
|
||||||
n = n1;
|
n = n1;
|
||||||
}
|
}
|
||||||
|
|
@ -548,7 +554,7 @@ statement : INCLUDE STRING LBRACE {
|
||||||
if ($4 > 0) {
|
if ($4 > 0) {
|
||||||
$2->is_pointer++;
|
$2->is_pointer++;
|
||||||
$2->status = STAT_READONLY;
|
$2->status = STAT_READONLY;
|
||||||
$2->arraystr = copy_string(ArrayString.get());
|
$2->arraystr = copy_string(Char(ArrayString));
|
||||||
}
|
}
|
||||||
if ($3.is_reference) {
|
if ($3.is_reference) {
|
||||||
fprintf(stderr,"%s : Line %d. Error. Linkage to C++ reference not allowed.\n", input_file, line_number);
|
fprintf(stderr,"%s : Line %d. Error. Linkage to C++ reference not allowed.\n", input_file, line_number);
|
||||||
|
|
@ -632,7 +638,7 @@ statement : INCLUDE STRING LBRACE {
|
||||||
|
|
||||||
| STATIC type declaration LPAREN parms RPAREN func_end {
|
| STATIC type declaration LPAREN parms RPAREN func_end {
|
||||||
if (Inline) {
|
if (Inline) {
|
||||||
if (strlen(CCode.get())) {
|
if (strlen(Char(CCode))) {
|
||||||
init_language();
|
init_language();
|
||||||
$2->is_pointer += $3.is_pointer;
|
$2->is_pointer += $3.is_pointer;
|
||||||
$2->is_reference = $3.is_reference;
|
$2->is_reference = $3.is_reference;
|
||||||
|
|
@ -653,10 +659,10 @@ statement : INCLUDE STRING LBRACE {
|
||||||
fprintf(stderr,"%s : Line %d. Repeated %%inline directive.\n",input_file,line_number);
|
fprintf(stderr,"%s : Line %d. Repeated %%inline directive.\n",input_file,line_number);
|
||||||
FatalError();
|
FatalError();
|
||||||
} else {
|
} else {
|
||||||
if (strlen(CCode.get())) {
|
if (strlen(Char(CCode))) {
|
||||||
fprintf(f_header,"static ");
|
fprintf(f_header,"static ");
|
||||||
emit_extern_func($3.id,$2,$5,3,f_header);
|
emit_extern_func($3.id,$2,$5,3,f_header);
|
||||||
fprintf(f_header,"%s\n",CCode.get());
|
fprintf(f_header,"%s\n",Char(CCode));
|
||||||
}
|
}
|
||||||
create_function(0, $3.id, $2, $5);
|
create_function(0, $3.id, $2, $5);
|
||||||
}
|
}
|
||||||
|
|
@ -929,7 +935,7 @@ statement : INCLUDE STRING LBRACE {
|
||||||
skip_brace();
|
skip_brace();
|
||||||
p = $7;
|
p = $7;
|
||||||
while (p) {
|
while (p) {
|
||||||
typemap_register($5,$3,p->p->t,p->p->name,CCode.get(),p->args);
|
typemap_register($5,$3,p->p->t,p->p->name,Char(CCode),p->args);
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
delete $3;
|
delete $3;
|
||||||
|
|
@ -947,7 +953,7 @@ statement : INCLUDE STRING LBRACE {
|
||||||
skip_brace();
|
skip_brace();
|
||||||
p = $5;
|
p = $5;
|
||||||
while (p) {
|
while (p) {
|
||||||
typemap_register($3,typemap_lang,p->p->t,p->p->name,CCode.get(),p->args);
|
typemap_register($3,typemap_lang,p->p->t,p->p->name,Char(CCode),p->args);
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1052,14 +1058,14 @@ statement : INCLUDE STRING LBRACE {
|
||||||
/* An exception definition */
|
/* An exception definition */
|
||||||
| EXCEPT LPAREN ID RPAREN LBRACE {
|
| EXCEPT LPAREN ID RPAREN LBRACE {
|
||||||
skip_brace();
|
skip_brace();
|
||||||
fragment_register((char *)"except",$3, CCode.get());
|
fragment_register((char *)"except",$3, Char(CCode));
|
||||||
delete $3;
|
delete $3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A Generic Exception (no language specified */
|
/* A Generic Exception (no language specified */
|
||||||
| EXCEPT LBRACE {
|
| EXCEPT LBRACE {
|
||||||
skip_brace();
|
skip_brace();
|
||||||
fragment_register((char *) "except",typemap_lang, CCode.get());
|
fragment_register((char *) "except",typemap_lang, Char(CCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear an exception */
|
/* Clear an exception */
|
||||||
|
|
@ -1194,7 +1200,7 @@ typedef_decl : TYPEDEF type declaration {
|
||||||
$2->is_pointer += $3.is_pointer;
|
$2->is_pointer += $3.is_pointer;
|
||||||
// Turn this into a "pointer" corresponding to the array
|
// Turn this into a "pointer" corresponding to the array
|
||||||
$2->is_pointer++;
|
$2->is_pointer++;
|
||||||
$2->arraystr = copy_string(ArrayString.get());
|
$2->arraystr = copy_string(Char(ArrayString));
|
||||||
$2->typedef_add($3.id);
|
$2->typedef_add($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);
|
||||||
|
|
@ -1227,7 +1233,7 @@ typedeflist : COMMA declaration typedeflist {
|
||||||
t = new DataType(Active_typedef);
|
t = new DataType(Active_typedef);
|
||||||
t->status = STAT_READONLY | STAT_REPLACETYPE;
|
t->status = STAT_READONLY | STAT_REPLACETYPE;
|
||||||
t->is_pointer += $2.is_pointer + 1;
|
t->is_pointer += $2.is_pointer + 1;
|
||||||
t->arraystr = copy_string(ArrayString.get());
|
t->arraystr = copy_string(Char(ArrayString));
|
||||||
t->typedef_add($2.id);
|
t->typedef_add($2.id);
|
||||||
cplus_register_type($2.id);
|
cplus_register_type($2.id);
|
||||||
delete t;
|
delete t;
|
||||||
|
|
@ -1264,7 +1270,7 @@ stail : SEMI { }
|
||||||
if ($3 > 0) {
|
if ($3 > 0) {
|
||||||
temp_typeptr->is_pointer++;
|
temp_typeptr->is_pointer++;
|
||||||
temp_typeptr->status = STAT_READONLY;
|
temp_typeptr->status = STAT_READONLY;
|
||||||
temp_typeptr->arraystr = copy_string(ArrayString.get());
|
temp_typeptr->arraystr = copy_string(Char(ArrayString));
|
||||||
}
|
}
|
||||||
if ($2.is_reference) {
|
if ($2.is_reference) {
|
||||||
fprintf(stderr,"%s : Line %d. Error. Linkage to C++ reference not allowed.\n", input_file, line_number);
|
fprintf(stderr,"%s : Line %d. Error. Linkage to C++ reference not allowed.\n", input_file, line_number);
|
||||||
|
|
@ -1357,7 +1363,7 @@ parm_type : type pname {
|
||||||
if (InArray) {
|
if (InArray) {
|
||||||
$1->is_pointer++;
|
$1->is_pointer++;
|
||||||
// Add array string to the type
|
// Add array string to the type
|
||||||
$1->arraystr = copy_string(ArrayString.get());
|
$1->arraystr = copy_string(Char(ArrayString));
|
||||||
}
|
}
|
||||||
$$ = new Parm($1,$2);
|
$$ = new Parm($1,$2);
|
||||||
$$->call_type = 0;
|
$$->call_type = 0;
|
||||||
|
|
@ -1378,7 +1384,7 @@ parm_type : type pname {
|
||||||
if (InArray) {
|
if (InArray) {
|
||||||
$$->t->is_pointer++;
|
$$->t->is_pointer++;
|
||||||
// Add array string to the type
|
// Add array string to the type
|
||||||
$$->t->arraystr = copy_string(ArrayString.get());
|
$$->t->arraystr = copy_string(Char(ArrayString));
|
||||||
}
|
}
|
||||||
delete $1;
|
delete $1;
|
||||||
delete $3;
|
delete $3;
|
||||||
|
|
@ -1500,20 +1506,20 @@ stars : STAR empty { $$ = 1; }
|
||||||
|
|
||||||
array : LBRACKET RBRACKET array2 {
|
array : LBRACKET RBRACKET array2 {
|
||||||
$$ = $3 + 1;
|
$$ = $3 + 1;
|
||||||
"[]" >> ArrayString;
|
Insert(ArrayString,0,"[]");
|
||||||
}
|
}
|
||||||
| LBRACKET expr RBRACKET array2 {
|
| LBRACKET expr RBRACKET array2 {
|
||||||
$$ = $4 + 1;
|
$$ = $4 + 1;
|
||||||
"]" >> ArrayString;
|
Insert(ArrayString,0,"]");
|
||||||
$2.id >> ArrayString;
|
Insert(ArrayString,0,$2.id);
|
||||||
"[" >> ArrayString;
|
Insert(ArrayString,0,"[");
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
array2 : array {
|
array2 : array {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
| empty { $$ = 0;
|
| empty { $$ = 0;
|
||||||
ArrayString = "";
|
Clear(ArrayString);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
@ -2399,7 +2405,7 @@ cpp_member : type declaration LPAREN parms RPAREN cpp_end {
|
||||||
Active_type = new DataType($1);
|
Active_type = new DataType($1);
|
||||||
$1->is_pointer += $2.is_pointer + 1;
|
$1->is_pointer += $2.is_pointer + 1;
|
||||||
$1->is_reference = $2.is_reference;
|
$1->is_reference = $2.is_reference;
|
||||||
$1->arraystr = copy_string(ArrayString.get());
|
$1->arraystr = copy_string(Char(ArrayString));
|
||||||
if (!(tm = typemap_lookup((char*)"memberin",typemap_lang,$1,$2.id,(char*)"",(char*)"")))
|
if (!(tm = typemap_lookup((char*)"memberin",typemap_lang,$1,$2.id,(char*)"",(char*)"")))
|
||||||
Status = STAT_READONLY;
|
Status = STAT_READONLY;
|
||||||
|
|
||||||
|
|
@ -2567,8 +2573,9 @@ cpp_pragma : PRAGMA ID stylearg {
|
||||||
/* Generate some code for a new class */
|
/* Generate some code for a new class */
|
||||||
} else {
|
} else {
|
||||||
Nested *n = new Nested;
|
Nested *n = new Nested;
|
||||||
n->code << "typedef " << $1 << " "
|
n->code = NewString("");
|
||||||
<< CCode.get() << " $classname_" << $5.id << ";\n";
|
Printv(n->code, "typedef ", $1, " ",
|
||||||
|
Char(CCode), " $classname_", $5.id, ";\n", 0);
|
||||||
n->name = copy_string($5.id);
|
n->name = copy_string($5.id);
|
||||||
n->line = start_line;
|
n->line = start_line;
|
||||||
n->type = new DataType;
|
n->type = new DataType;
|
||||||
|
|
@ -2592,8 +2599,9 @@ cpp_pragma : PRAGMA ID stylearg {
|
||||||
/* Generate some code for a new class */
|
/* Generate some code for a new class */
|
||||||
|
|
||||||
Nested *n = new Nested;
|
Nested *n = new Nested;
|
||||||
n->code << "typedef " << $1 << " "
|
n->code = NewString("");
|
||||||
<< CCode.get() << " $classname_" << $4.id << ";\n";
|
Printv(n->code, "typedef ", $1, " " ,
|
||||||
|
Char(CCode), " $classname_", $4.id, ";\n",0);
|
||||||
n->name = copy_string($4.id);
|
n->name = copy_string($4.id);
|
||||||
n->line = start_line;
|
n->line = start_line;
|
||||||
n->type = new DataType;
|
n->type = new DataType;
|
||||||
|
|
@ -2906,10 +2914,10 @@ objc_inherit : COLON ID objc_protolist { $$ = $2;}
|
||||||
|
|
||||||
|
|
||||||
objc_protolist : LESSTHAN { skip_template();
|
objc_protolist : LESSTHAN { skip_template();
|
||||||
CCode.strip(); // Strip whitespace
|
/* CCode.strip(); // Strip whitespace
|
||||||
CCode.replace("<","< ");
|
CCode.replace("<","< ");
|
||||||
CCode.replace(">"," >");
|
CCode.replace(">"," >"); */
|
||||||
$$ = CCode.get();
|
$$ = Char(CCode);
|
||||||
}
|
}
|
||||||
| empty {
|
| empty {
|
||||||
$$ = (char*)"";
|
$$ = (char*)"";
|
||||||
|
|
@ -2979,7 +2987,7 @@ objc_var : type declaration {
|
||||||
Active_type = new DataType($1);
|
Active_type = new DataType($1);
|
||||||
$1->is_pointer += $2.is_pointer;
|
$1->is_pointer += $2.is_pointer;
|
||||||
$1->is_reference = $2.is_reference;
|
$1->is_reference = $2.is_reference;
|
||||||
$1->arraystr = copy_string(ArrayString.get());
|
$1->arraystr = copy_string(Char(ArrayString));
|
||||||
if ($1->status & STAT_READONLY) {
|
if ($1->status & STAT_READONLY) {
|
||||||
if (!(tm = typemap_lookup((char*)"memberin",typemap_lang,$1,$2.id,(char*)"",(char*)"")))
|
if (!(tm = typemap_lookup((char*)"memberin",typemap_lang,$1,$2.id,(char*)"",(char*)"")))
|
||||||
Status = Status | STAT_READONLY;
|
Status = Status | STAT_READONLY;
|
||||||
|
|
@ -3024,7 +3032,7 @@ objc_vartail : COMMA declaration objc_vartail {
|
||||||
DataType *t = new DataType (Active_type);
|
DataType *t = new DataType (Active_type);
|
||||||
t->is_pointer += $2.is_pointer;
|
t->is_pointer += $2.is_pointer;
|
||||||
t->is_reference = $2.is_reference;
|
t->is_reference = $2.is_reference;
|
||||||
t->arraystr = copy_string(ArrayString.get());
|
t->arraystr = copy_string(Char(ArrayString));
|
||||||
if (t->status & STAT_READONLY) {
|
if (t->status & STAT_READONLY) {
|
||||||
if (!(tm = typemap_lookup((char*)"memberin",typemap_lang,t,$2.id,(char*)"",(char*)"")))
|
if (!(tm = typemap_lookup((char*)"memberin",typemap_lang,t,$2.id,(char*)"",(char*)"")))
|
||||||
Status = Status | STAT_READONLY;
|
Status = Status | STAT_READONLY;
|
||||||
|
|
@ -3222,7 +3230,7 @@ tm_tail : COMMA typemap_parm tm_tail {
|
||||||
typemap_parm : type typemap_name {
|
typemap_parm : type typemap_name {
|
||||||
if (InArray) {
|
if (InArray) {
|
||||||
$1->is_pointer++;
|
$1->is_pointer++;
|
||||||
$1->arraystr = copy_string(ArrayString.get());
|
$1->arraystr = copy_string(Char(ArrayString));
|
||||||
}
|
}
|
||||||
$$ = new TMParm;
|
$$ = new TMParm;
|
||||||
$$->p = new Parm($1,$2);
|
$$->p = new Parm($1,$2);
|
||||||
|
|
@ -3239,7 +3247,7 @@ typemap_parm : type typemap_name {
|
||||||
$$->p->call_type = 0;
|
$$->p->call_type = 0;
|
||||||
if (InArray) {
|
if (InArray) {
|
||||||
$$->p->t->is_pointer++;
|
$$->p->t->is_pointer++;
|
||||||
$$->p->t->arraystr = copy_string(ArrayString.get());
|
$$->p->t->arraystr = copy_string(Char(ArrayString));
|
||||||
}
|
}
|
||||||
$$->args = tm_parm;
|
$$->args = tm_parm;
|
||||||
delete $1;
|
delete $1;
|
||||||
|
|
@ -3279,23 +3287,23 @@ typemap_name : ID typemap_args {
|
||||||
InArray = 0;
|
InArray = 0;
|
||||||
}
|
}
|
||||||
| ID array {
|
| ID array {
|
||||||
ArrayBackup = "";
|
ArrayBackup = Copy(ArrayString);
|
||||||
ArrayBackup << ArrayString;
|
|
||||||
} typemap_args {
|
} typemap_args {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
InArray = $2;
|
InArray = $2;
|
||||||
ArrayString = "";
|
Clear(ArrayString);
|
||||||
ArrayString << ArrayBackup;
|
Append(ArrayString,ArrayBackup);
|
||||||
|
Delete(ArrayBackup);
|
||||||
}
|
}
|
||||||
| array {
|
| array {
|
||||||
ArrayBackup = "";
|
ArrayBackup = Copy(ArrayString);
|
||||||
ArrayBackup << ArrayString;
|
|
||||||
} typemap_args {
|
} typemap_args {
|
||||||
$$ = new char[1];
|
$$ = new char[1];
|
||||||
$$[0] = 0;
|
$$[0] = 0;
|
||||||
InArray = $1;
|
InArray = $1;
|
||||||
ArrayString = "";
|
Clear(ArrayString);
|
||||||
ArrayString << ArrayBackup;
|
Append(ArrayString,ArrayBackup);
|
||||||
|
Delete(ArrayBackup);
|
||||||
}
|
}
|
||||||
| typemap_args { $$ = new char[1];
|
| typemap_args { $$ = new char[1];
|
||||||
$$[0] = 0;
|
$$[0] = 0;
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ static char cvsroot[] = "$Header$";
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "doh.h"
|
||||||
|
}
|
||||||
|
|
||||||
#define YYBSIZE 8192
|
#define YYBSIZE 8192
|
||||||
|
|
||||||
struct InFile {
|
struct InFile {
|
||||||
|
|
@ -44,9 +48,9 @@ InFile *in_head;
|
||||||
|
|
||||||
FILE *LEX_in = NULL;
|
FILE *LEX_in = NULL;
|
||||||
|
|
||||||
static String header;
|
static DOHString *header = 0;
|
||||||
static String comment;
|
static DOHString *comment = 0;
|
||||||
String CCode; // String containing C code
|
DOHString *CCode = 0; // String containing C code
|
||||||
static char *yybuffer;
|
static char *yybuffer;
|
||||||
static int lex_pos = 0;
|
static int lex_pos = 0;
|
||||||
static int lex_len = 0;
|
static int lex_len = 0;
|
||||||
|
|
@ -83,6 +87,9 @@ void scanner_init() {
|
||||||
|
|
||||||
yybuffer = (char *) malloc(YYBSIZE);
|
yybuffer = (char *) malloc(YYBSIZE);
|
||||||
scan_init = 1;
|
scan_init = 1;
|
||||||
|
header = NewString("");
|
||||||
|
comment = NewString("");
|
||||||
|
CCode = NewString("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************
|
/**************************************************************
|
||||||
|
|
@ -299,7 +306,8 @@ void yycomment(char *, int, int) {
|
||||||
void skip_brace(void) {
|
void skip_brace(void) {
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
CCode = "{";
|
Clear(CCode);
|
||||||
|
Putc('{',CCode);
|
||||||
while (num_brace > last_brace) {
|
while (num_brace > last_brace) {
|
||||||
if ((c = nextchar()) == 0) {
|
if ((c = nextchar()) == 0) {
|
||||||
fprintf(stderr,"%s : Line %d. Missing '}'. Reached end of input.\n",
|
fprintf(stderr,"%s : Line %d. Missing '}'. Reached end of input.\n",
|
||||||
|
|
@ -307,7 +315,7 @@ void skip_brace(void) {
|
||||||
FatalError();
|
FatalError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CCode << c;
|
Putc(c,CCode);
|
||||||
if (c == '{') num_brace++;
|
if (c == '{') num_brace++;
|
||||||
if (c == '}') num_brace--;
|
if (c == '}') num_brace--;
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
|
|
@ -328,7 +336,8 @@ void skip_brace(void) {
|
||||||
void skip_template(void) {
|
void skip_template(void) {
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
CCode = "<";
|
Clear(CCode);
|
||||||
|
Putc('<',CCode);
|
||||||
int num_lt = 1;
|
int num_lt = 1;
|
||||||
while (num_lt > 0) {
|
while (num_lt > 0) {
|
||||||
if ((c = nextchar()) == 0) {
|
if ((c = nextchar()) == 0) {
|
||||||
|
|
@ -337,7 +346,7 @@ void skip_template(void) {
|
||||||
FatalError();
|
FatalError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CCode << c;
|
Putc(c,CCode);
|
||||||
if (c == '<') num_lt++;
|
if (c == '<') num_lt++;
|
||||||
if (c == '>') num_lt--;
|
if (c == '>') num_lt--;
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
|
|
@ -689,12 +698,14 @@ int yylook(void) {
|
||||||
if (c == '/') {
|
if (c == '/') {
|
||||||
comment_start = line_number;
|
comment_start = line_number;
|
||||||
column_start = column;
|
column_start = column;
|
||||||
comment = " ";
|
Clear(comment);
|
||||||
|
Printf(comment," ");
|
||||||
state = 10; // C++ style comment
|
state = 10; // C++ style comment
|
||||||
} else if (c == '*') {
|
} else if (c == '*') {
|
||||||
comment_start = line_number;
|
comment_start = line_number;
|
||||||
column_start = column;
|
column_start = column;
|
||||||
comment = " ";
|
Clear(comment);
|
||||||
|
Printf(comment," ");
|
||||||
state = 11; // C style comment
|
state = 11; // C style comment
|
||||||
} else {
|
} else {
|
||||||
retract(1);
|
retract(1);
|
||||||
|
|
@ -708,9 +719,9 @@ int yylook(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
comment << c;
|
Putc(c,comment);
|
||||||
// Add the comment to documentation
|
// Add the comment to documentation
|
||||||
yycomment(comment.get(),comment_start, column_start);
|
yycomment(Char(comment),comment_start, column_start);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
state = 0;
|
state = 0;
|
||||||
if (in_define == 1) {
|
if (in_define == 1) {
|
||||||
|
|
@ -719,7 +730,7 @@ int yylook(void) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state = 10;
|
state = 10;
|
||||||
comment << c;
|
Putc(c,comment);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -732,7 +743,7 @@ int yylook(void) {
|
||||||
if (c == '*') {
|
if (c == '*') {
|
||||||
state = 12;
|
state = 12;
|
||||||
} else {
|
} else {
|
||||||
comment << c;
|
Putc(c,comment);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
state = 11;
|
state = 11;
|
||||||
}
|
}
|
||||||
|
|
@ -744,15 +755,16 @@ int yylook(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (c == '*') {
|
if (c == '*') {
|
||||||
comment << c;
|
Putc(c,comment);
|
||||||
state = 12;
|
state = 12;
|
||||||
} else if (c == '/') {
|
} else if (c == '/') {
|
||||||
comment << " \n";
|
Printf(comment," \n");
|
||||||
yycomment(comment.get(),comment_start,column_start);
|
yycomment(Char(comment),comment_start,column_start);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
state = 0;
|
state = 0;
|
||||||
} else {
|
} else {
|
||||||
comment << '*' << c;
|
Putc('*',comment);
|
||||||
|
Putc(c,comment);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
state = 11;
|
state = 11;
|
||||||
}
|
}
|
||||||
|
|
@ -794,7 +806,7 @@ int yylook(void) {
|
||||||
if (( c= nextchar()) == 0) return 0;
|
if (( c= nextchar()) == 0) return 0;
|
||||||
if (c == '{') {
|
if (c == '{') {
|
||||||
state = 40; /* Include block */
|
state = 40; /* Include block */
|
||||||
header = "";
|
Clear(header);
|
||||||
start_line = line_number;
|
start_line = line_number;
|
||||||
}
|
}
|
||||||
else if ((isalpha(c)) || (c == '_')) state = 7;
|
else if ((isalpha(c)) || (c == '_')) state = 7;
|
||||||
|
|
@ -813,7 +825,7 @@ int yylook(void) {
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
if (c == '%') state = 41;
|
if (c == '%') state = 41;
|
||||||
else {
|
else {
|
||||||
header << c;
|
Putc(c,header);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
state = 40;
|
state = 40;
|
||||||
}
|
}
|
||||||
|
|
@ -825,11 +837,11 @@ int yylook(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (c == '}') {
|
if (c == '}') {
|
||||||
yylval.id = header.get();
|
yylval.id = Char(header);
|
||||||
return(HBLOCK);
|
return(HBLOCK);
|
||||||
} else {
|
} else {
|
||||||
header << '%';
|
Putc('%',header);
|
||||||
header << c;
|
Putc(c,header);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
state = 40;
|
state = 40;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ public:
|
||||||
String(const char *s);
|
String(const char *s);
|
||||||
~String();
|
~String();
|
||||||
char *get() const;
|
char *get() const;
|
||||||
|
void *doh() { return str; }
|
||||||
friend String& operator<<(String&,const char *s);
|
friend String& operator<<(String&,const char *s);
|
||||||
friend String& operator<<(String&,const int);
|
friend String& operator<<(String&,const int);
|
||||||
friend String& operator<<(String&,const char);
|
friend String& operator<<(String&,const char);
|
||||||
|
|
@ -232,10 +233,9 @@ public:
|
||||||
|
|
||||||
Parm *get_first(); // Get first parameter from list
|
Parm *get_first(); // Get first parameter from list
|
||||||
Parm *get_next(); // Get next parameter from list
|
Parm *get_next(); // Get next parameter from list
|
||||||
void print_types(FILE *f); // Print list of datatypes
|
|
||||||
void print_types(String &f); // Generate list of datatypes.
|
void print_types(void *f); // Print list of datatypes
|
||||||
void print_args(FILE *f); // Print argument list
|
void print_args(FILE *f); // Print argument list
|
||||||
void sub_parmnames(String &s); // Remaps real parameter names in code fragment
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Modes for different types of inheritance
|
// Modes for different types of inheritance
|
||||||
|
|
@ -452,7 +452,11 @@ public:
|
||||||
String locals;
|
String locals;
|
||||||
String code;
|
String code;
|
||||||
String init;
|
String init;
|
||||||
void print(FILE *f);
|
void *_def; /* Migration code */
|
||||||
|
void *_locals;
|
||||||
|
void *_code;
|
||||||
|
void *_init;
|
||||||
|
void print(void *f);
|
||||||
void print(String &f);
|
void print(String &f);
|
||||||
void add_local(char *type, char *name, char *defvalue = 0);
|
void add_local(char *type, char *name, char *defvalue = 0);
|
||||||
char *new_local(char *type, char *name, char *defvalue = 0);
|
char *new_local(char *type, char *name, char *defvalue = 0);
|
||||||
|
|
|
||||||
|
|
@ -68,31 +68,17 @@ extern "C" {
|
||||||
struct TypeMap {
|
struct TypeMap {
|
||||||
char *lang;
|
char *lang;
|
||||||
DataType *type;
|
DataType *type;
|
||||||
String code;
|
DOHString *code;
|
||||||
int first;
|
int first;
|
||||||
int last;
|
int last;
|
||||||
TypeMap *next;
|
TypeMap *next;
|
||||||
TypeMap *previous; // Previously defined typemap (if any)
|
TypeMap *previous; // Previously defined typemap (if any)
|
||||||
ParmList *args; // Local variables (if any)
|
ParmList *args; // Local variables (if any)
|
||||||
|
|
||||||
TypeMap(char *l, DataType *t, String &c, ParmList *p = 0) {
|
|
||||||
lang = copy_string(l);
|
|
||||||
type = new DataType(t);
|
|
||||||
code << c;
|
|
||||||
first = type_id;
|
|
||||||
last = INT_MAX;
|
|
||||||
next = 0;
|
|
||||||
previous = 0;
|
|
||||||
if (p) {
|
|
||||||
args = new ParmList(p);
|
|
||||||
} else {
|
|
||||||
args = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TypeMap(char *l, DataType *t, char *c, ParmList *p = 0) {
|
TypeMap(char *l, DataType *t, char *c, ParmList *p = 0) {
|
||||||
lang = copy_string(l);
|
lang = copy_string(l);
|
||||||
type = new DataType(t);
|
type = new DataType(t);
|
||||||
code << c;
|
code = NewString(c);
|
||||||
first = type_id;
|
first = type_id;
|
||||||
last = INT_MAX;
|
last = INT_MAX;
|
||||||
next = 0;
|
next = 0;
|
||||||
|
|
@ -106,7 +92,7 @@ struct TypeMap {
|
||||||
TypeMap(char *l, char *c) {
|
TypeMap(char *l, char *c) {
|
||||||
lang = copy_string(l);
|
lang = copy_string(l);
|
||||||
type = 0;
|
type = 0;
|
||||||
code << c;
|
code = NewString(c);
|
||||||
first = type_id;
|
first = type_id;
|
||||||
last = INT_MAX;
|
last = INT_MAX;
|
||||||
next = 0;
|
next = 0;
|
||||||
|
|
@ -116,7 +102,7 @@ struct TypeMap {
|
||||||
TypeMap(TypeMap *t) {
|
TypeMap(TypeMap *t) {
|
||||||
lang = copy_string(t->lang);
|
lang = copy_string(t->lang);
|
||||||
type = new DataType(t->type);
|
type = new DataType(t->type);
|
||||||
code << t->code;
|
code = Copy(t->code);
|
||||||
first = type_id;
|
first = type_id;
|
||||||
last = INT_MAX;
|
last = INT_MAX;
|
||||||
next = 0;
|
next = 0;
|
||||||
|
|
@ -236,20 +222,21 @@ void typemap_clear_apply(DataType *type, char *pname) {
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
static char *typemap_string(char *lang, DataType *type, char *pname, char *ary, char *suffix) {
|
static char *typemap_string(char *lang, DataType *type, char *pname, char *ary, char *suffix) {
|
||||||
static String str;
|
static DOHString *str = 0;
|
||||||
|
|
||||||
int old_status;
|
int old_status;
|
||||||
|
if (!str) str = NewString("");
|
||||||
old_status = type->status;
|
old_status = type->status;
|
||||||
type->status = 0;
|
type->status = 0;
|
||||||
str = "";
|
Clear(str);
|
||||||
|
|
||||||
if (ary)
|
if (ary)
|
||||||
str << lang << type->print_type() << pname << ary << suffix;
|
Printv(str, lang, type->print_type(), pname, ary, suffix, 0);
|
||||||
else
|
else
|
||||||
str << lang << type->print_type() << pname << suffix;
|
Printv(str, lang, type->print_type(), pname, suffix,0);
|
||||||
|
|
||||||
type->status = old_status;
|
type->status = old_status;
|
||||||
return str.get();
|
return Char(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
@ -292,7 +279,7 @@ void typemap_register(char *op, char *lang, DataType *type, char *pname,
|
||||||
|
|
||||||
if (type_id < tm_old->last) {
|
if (type_id < tm_old->last) {
|
||||||
sprintf(temp,"$%s",op);
|
sprintf(temp,"$%s",op);
|
||||||
tm->code.replace(temp,tm_old->code.get());
|
Replace(tm->code,temp,tm_old->code, DOH_REPLACE_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If found, we need to attach the old version to the new one
|
// If found, we need to attach the old version to the new one
|
||||||
|
|
@ -407,7 +394,7 @@ TypeMap *typemap_search(char *key, int id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname, String &str)
|
// TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname, DOHString *str)
|
||||||
//
|
//
|
||||||
// Performs a typemap lookup on an array type. This is abit complicated
|
// Performs a typemap lookup on an array type. This is abit complicated
|
||||||
// because we need to look for ANY tags specifying that any array dimension
|
// because we need to look for ANY tags specifying that any array dimension
|
||||||
|
|
@ -415,7 +402,7 @@ TypeMap *typemap_search(char *key, int id) {
|
||||||
// substituted.
|
// substituted.
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname, String &str) {
|
TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname, DOHString *str) {
|
||||||
char *origarr = type->arraystr;
|
char *origarr = type->arraystr;
|
||||||
char *key;
|
char *key;
|
||||||
int ndim,i,j,k,n;
|
int ndim,i,j,k,n;
|
||||||
|
|
@ -437,23 +424,22 @@ TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname,
|
||||||
|
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
// We're going to go search for matches with the ANY tag
|
// We're going to go search for matches with the ANY tag
|
||||||
String tempastr;
|
DOHString *tempastr = NewString("");
|
||||||
ndim = type->array_dimensions(); // Get number of dimensions
|
ndim = type->array_dimensions(); // Get number of dimensions
|
||||||
j = (1 << ndim) - 1; // Status bits
|
j = (1 << ndim) - 1; // Status bits
|
||||||
for (i = 0; i < (1 << ndim); i++) {
|
for (i = 0; i < (1 << ndim); i++) {
|
||||||
// Form an array string
|
// Form an array string
|
||||||
tempastr = "";
|
Clear(tempastr);
|
||||||
k = j;
|
k = j;
|
||||||
for (n = 0; n < ndim; n++) {
|
for (n = 0; n < ndim; n++) {
|
||||||
if (k & 1) {
|
if (k & 1) {
|
||||||
tempastr << "[" << type->get_dimension(n) << "]";
|
Printf(tempastr,"[%s]",type->get_dimension(n));
|
||||||
} else {
|
} else {
|
||||||
tempastr << "[ANY]";
|
Printf(tempastr,"[ANY]");
|
||||||
}
|
}
|
||||||
k = k >> 1;
|
k = k >> 1;
|
||||||
}
|
}
|
||||||
// printf("checking (%s) : %s\n",origarr,tempastr.get());
|
type->arraystr = Char(tempastr);
|
||||||
type->arraystr = tempastr.get();
|
|
||||||
key = typemap_string(lang,type,pname,type->arraystr,op);
|
key = typemap_string(lang,type,pname,type->arraystr,op);
|
||||||
tm = typemap_search(key,type->id);
|
tm = typemap_search(key,type->id);
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
|
|
@ -461,19 +447,23 @@ TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname,
|
||||||
tm = typemap_search(key,type->id);
|
tm = typemap_search(key,type->id);
|
||||||
}
|
}
|
||||||
type->arraystr = origarr;
|
type->arraystr = origarr;
|
||||||
if (tm) break;
|
if (tm) {
|
||||||
|
Delete(tempastr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
j--;
|
j--;
|
||||||
}
|
}
|
||||||
|
Delete(tempastr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tm) {
|
if (tm) {
|
||||||
str << tm->code;
|
Printf(str,"%s",tm->code);
|
||||||
ndim = type->array_dimensions();
|
ndim = type->array_dimensions();
|
||||||
sprintf(temp,"%d",ndim);
|
sprintf(temp,"%d",ndim);
|
||||||
str.replace("$ndim",temp);
|
Replace(str,"$ndim",temp, DOH_REPLACE_ANY);
|
||||||
for (i = 0; i < ndim; i++) {
|
for (i = 0; i < ndim; i++) {
|
||||||
sprintf(temp,"$dim%d",i);
|
sprintf(temp,"$dim%d",i);
|
||||||
str.replace(temp,type->get_dimension(i));
|
Replace(str,temp,type->get_dimension(i), DOH_REPLACE_ANY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tm;
|
return tm;
|
||||||
|
|
@ -488,7 +478,7 @@ TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname,
|
||||||
// Substitutes locals in the string with actual values used.
|
// Substitutes locals in the string with actual values used.
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
static void typemap_locals(DataType *t, char *pname, String &s, ParmList *l, WrapperFunction &f) {
|
static void typemap_locals(DataType *t, char *pname, DOHString *s, ParmList *l, WrapperFunction &f) {
|
||||||
Parm *p;
|
Parm *p;
|
||||||
char *new_name;
|
char *new_name;
|
||||||
|
|
||||||
|
|
@ -496,9 +486,10 @@ static void typemap_locals(DataType *t, char *pname, String &s, ParmList *l, Wra
|
||||||
while (p) {
|
while (p) {
|
||||||
if (p->name) {
|
if (p->name) {
|
||||||
if (strlen(p->name) > 0) {
|
if (strlen(p->name) > 0) {
|
||||||
String str;
|
DOHString *str;
|
||||||
DataType *tt;
|
DataType *tt;
|
||||||
|
|
||||||
|
str = NewString("");
|
||||||
// If the user gave us $type as the name of the local variable, we'll use
|
// If the user gave us $type as the name of the local variable, we'll use
|
||||||
// the passed datatype instead
|
// the passed datatype instead
|
||||||
|
|
||||||
|
|
@ -511,30 +502,30 @@ static void typemap_locals(DataType *t, char *pname, String &s, ParmList *l, Wra
|
||||||
// Have a real parameter here
|
// Have a real parameter here
|
||||||
if (tt->arraystr) {
|
if (tt->arraystr) {
|
||||||
tt->is_pointer--;
|
tt->is_pointer--;
|
||||||
str << p->name << tt->arraystr;
|
Printf(str,"%s%s",p->name, tt->arraystr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
str << p->name;
|
Printf(str,"%s",p->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Substitute parameter names
|
// Substitute parameter names
|
||||||
str.replace("$arg",pname);
|
Replace(str,"$arg",pname, DOH_REPLACE_ANY);
|
||||||
if (strcmp(p->t->name,"$basetype")==0) {
|
if (strcmp(p->t->name,"$basetype")==0) {
|
||||||
// use $basetype
|
// use $basetype
|
||||||
char temp_ip = tt->is_pointer;
|
char temp_ip = tt->is_pointer;
|
||||||
char temp_ip1 = tt->implicit_ptr;
|
char temp_ip1 = tt->implicit_ptr;
|
||||||
tt->is_pointer = 0;
|
tt->is_pointer = 0;
|
||||||
tt->implicit_ptr = 0;
|
tt->implicit_ptr = 0;
|
||||||
new_name = f.new_local(tt->print_type(),str.get());
|
new_name = f.new_local(tt->print_type(),Char(str));
|
||||||
tt->is_pointer = temp_ip;
|
tt->is_pointer = temp_ip;
|
||||||
tt->implicit_ptr = temp_ip1;
|
tt->implicit_ptr = temp_ip1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
new_name = f.new_local(tt->print_full(),str.get());
|
new_name = f.new_local(tt->print_full(),Char(str));
|
||||||
|
|
||||||
if (tt->arraystr) tt->is_pointer++;
|
if (tt->arraystr) tt->is_pointer++;
|
||||||
// Substitute
|
// Substitute
|
||||||
s.replaceid(p->name,new_name);
|
Replace(s,p->name,new_name,DOH_REPLACE_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p = l->get_next();
|
p = l->get_next();
|
||||||
|
|
@ -546,7 +537,7 @@ static void typemap_locals(DataType *t, char *pname, String &s, ParmList *l, Wra
|
||||||
char temp[10];
|
char temp[10];
|
||||||
for (int i = 0; i < t->array_dimensions(); i++) {
|
for (int i = 0; i < t->array_dimensions(); i++) {
|
||||||
sprintf(temp,"$dim%d",i);
|
sprintf(temp,"$dim%d",i);
|
||||||
f.locals.replace(temp,t->get_dimension(i));
|
Replace(f._locals,temp,t->get_dimension(i), DOH_REPLACE_ANY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -591,16 +582,17 @@ static char *realname = 0; // Real parameter name
|
||||||
|
|
||||||
char *typemap_lookup_internal(char *op, char *lang, DataType *type, char *pname, char *source,
|
char *typemap_lookup_internal(char *op, char *lang, DataType *type, char *pname, char *source,
|
||||||
char *target, WrapperFunction *f) {
|
char *target, WrapperFunction *f) {
|
||||||
static String str;
|
static DOHString *str = 0;
|
||||||
char *key = 0;
|
char *key = 0;
|
||||||
TypeMap *tm = 0;
|
TypeMap *tm = 0;
|
||||||
|
|
||||||
|
if (!str) str = NewString("");
|
||||||
if (!lang) {
|
if (!lang) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First check for named array
|
// First check for named array
|
||||||
str = "";
|
Clear(str);
|
||||||
tm = typemap_search_array(op,lang,type,pname,str);
|
tm = typemap_search_array(op,lang,type,pname,str);
|
||||||
|
|
||||||
// Check for named argument
|
// Check for named argument
|
||||||
|
|
@ -608,7 +600,7 @@ char *typemap_lookup_internal(char *op, char *lang, DataType *type, char *pname,
|
||||||
key = typemap_string(lang,type,pname,0,op);
|
key = typemap_string(lang,type,pname,0,op);
|
||||||
tm = typemap_search(key,type->id);
|
tm = typemap_search(key,type->id);
|
||||||
if (tm)
|
if (tm)
|
||||||
str << tm->code;
|
Printf(str,"%s",tm->code);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for unnamed type
|
// Check for unnamed type
|
||||||
|
|
@ -616,19 +608,19 @@ char *typemap_lookup_internal(char *op, char *lang, DataType *type, char *pname,
|
||||||
key = typemap_string(lang,type,(char*)"",0,op);
|
key = typemap_string(lang,type,(char*)"",0,op);
|
||||||
tm = typemap_search(key,type->id);
|
tm = typemap_search(key,type->id);
|
||||||
if (tm)
|
if (tm)
|
||||||
str << tm->code;
|
Printf(str,"%s", tm->code);
|
||||||
}
|
}
|
||||||
if (!tm) return 0;
|
if (!tm) return 0;
|
||||||
|
|
||||||
// Now perform character replacements
|
// Now perform character replacements
|
||||||
|
|
||||||
str.replace("$source",source);
|
Replace(str,"$source",source,DOH_REPLACE_ANY);
|
||||||
str.replace("$target",target);
|
Replace(str,"$target",target,DOH_REPLACE_ANY);
|
||||||
str.replace("$type", realtype->print_type());
|
Replace(str,"$type",realtype->print_type(),DOH_REPLACE_ANY);
|
||||||
if (realname) {
|
if (realname) {
|
||||||
str.replace("$parmname", realname);
|
Replace(str,"$parmname",realname,DOH_REPLACE_ANY);
|
||||||
} else {
|
} else {
|
||||||
str.replace("$parmname","");
|
Replace(str,"$parmname","", DOH_REPLACE_ANY);
|
||||||
}
|
}
|
||||||
// Print base type (without any pointers)
|
// Print base type (without any pointers)
|
||||||
{
|
{
|
||||||
|
|
@ -639,13 +631,13 @@ char *typemap_lookup_internal(char *op, char *lang, DataType *type, char *pname,
|
||||||
char *bt = realtype->print_type();
|
char *bt = realtype->print_type();
|
||||||
if (bt[strlen(bt)-1] == ' ')
|
if (bt[strlen(bt)-1] == ' ')
|
||||||
bt[strlen(bt)-1] = 0;
|
bt[strlen(bt)-1] = 0;
|
||||||
str.replace("$basetype",bt);
|
Replace(str,"$basetype",bt,DOH_REPLACE_ANY);
|
||||||
str.replace("$basemangle",realtype->print_mangle());
|
Replace(str,"$basemangle",realtype->print_mangle(), DOH_REPLACE_ANY);
|
||||||
realtype->is_pointer = temp_ip;
|
realtype->is_pointer = temp_ip;
|
||||||
realtype->implicit_ptr = temp_ip1;
|
realtype->implicit_ptr = temp_ip1;
|
||||||
}
|
}
|
||||||
|
|
||||||
str.replace("$mangle",realtype->print_mangle());
|
Replace(str,"$mangle",realtype->print_mangle(), DOH_REPLACE_ANY);
|
||||||
|
|
||||||
// If there were locals and a wrapper function, replace
|
// If there were locals and a wrapper function, replace
|
||||||
if ((tm->args) && f) {
|
if ((tm->args) && f) {
|
||||||
|
|
@ -661,7 +653,7 @@ char *typemap_lookup_internal(char *op, char *lang, DataType *type, char *pname,
|
||||||
|
|
||||||
// Return character string
|
// Return character string
|
||||||
|
|
||||||
return str.get();
|
return Char(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
|
|
@ -708,7 +700,8 @@ char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *so
|
||||||
m = m->next;
|
m = m->next;
|
||||||
while (m) {
|
while (m) {
|
||||||
char *oldary = 0;
|
char *oldary = 0;
|
||||||
static String newarray;
|
static DOHString *newarray = 0;
|
||||||
|
if (!newarray) newarray = NewString("");
|
||||||
if (*(m->name)) ppname = m->name;
|
if (*(m->name)) ppname = m->name;
|
||||||
else ppname = pname;
|
else ppname = pname;
|
||||||
m->type->is_pointer += drop_pointer;
|
m->type->is_pointer += drop_pointer;
|
||||||
|
|
@ -722,16 +715,16 @@ char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *so
|
||||||
|
|
||||||
if ((m->type->arraystr) && (type->arraystr)) {
|
if ((m->type->arraystr) && (type->arraystr)) {
|
||||||
// Build up the new array string
|
// Build up the new array string
|
||||||
newarray = "";
|
Clear(newarray);
|
||||||
for (int n = 0; n < m->type->array_dimensions(); n++) {
|
for (int n = 0; n < m->type->array_dimensions(); n++) {
|
||||||
char *d = m->type->get_dimension(n);
|
char *d = m->type->get_dimension(n);
|
||||||
if (strcmp(d,"ANY") == 0) {
|
if (strcmp(d,"ANY") == 0) {
|
||||||
newarray << "[" << type->get_dimension(n) << "]";
|
Printf(newarray,"[%s]", type->get_dimension(n));
|
||||||
} else {
|
} else {
|
||||||
newarray << "[" << d << "]";
|
Printf(newarray,"[%s]", d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m->type->arraystr = newarray.get();
|
m->type->arraystr = Char(newarray);
|
||||||
} else if (type->arraystr) {
|
} else if (type->arraystr) {
|
||||||
// If an array string is available for the current datatype,
|
// If an array string is available for the current datatype,
|
||||||
// make it available.
|
// make it available.
|
||||||
|
|
@ -785,15 +778,17 @@ char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *so
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
char *typemap_check_internal(char *op, char *lang, DataType *type, char *pname) {
|
char *typemap_check_internal(char *op, char *lang, DataType *type, char *pname) {
|
||||||
static String str;
|
static DOHString *str = 0;
|
||||||
char *key = 0;
|
char *key = 0;
|
||||||
TypeMap *tm = 0;
|
TypeMap *tm = 0;
|
||||||
|
|
||||||
|
if (!str) str = NewString("");
|
||||||
if (!lang) {
|
if (!lang) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// First check for named array
|
// First check for named array
|
||||||
str = "";
|
|
||||||
|
Clear(str);
|
||||||
tm = typemap_search_array(op,lang,type,pname,str);
|
tm = typemap_search_array(op,lang,type,pname,str);
|
||||||
|
|
||||||
// First check for named array
|
// First check for named array
|
||||||
|
|
@ -822,12 +817,11 @@ char *typemap_check_internal(char *op, char *lang, DataType *type, char *pname)
|
||||||
}
|
}
|
||||||
if (!tm) return 0;
|
if (!tm) return 0;
|
||||||
|
|
||||||
str = "";
|
Clear(str);
|
||||||
str << tm->code;
|
Printf(str,"%s",tm->code);
|
||||||
|
|
||||||
// Return character string
|
// Return character string
|
||||||
|
Char(str);
|
||||||
return str.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function for checking with applications
|
// Function for checking with applications
|
||||||
|
|
@ -865,7 +859,8 @@ char *typemap_check(char *op, char *lang, DataType *type, char *pname) {
|
||||||
m = m->next;
|
m = m->next;
|
||||||
while (m) {
|
while (m) {
|
||||||
char *oldary = 0;
|
char *oldary = 0;
|
||||||
static String newarray;
|
static DOHString *newarray = 0;
|
||||||
|
if (!newarray) newarray = NewString("");
|
||||||
if (*(m->name)) ppname = m->name;
|
if (*(m->name)) ppname = m->name;
|
||||||
else ppname = pname;
|
else ppname = pname;
|
||||||
m->type->is_pointer += drop_pointer;
|
m->type->is_pointer += drop_pointer;
|
||||||
|
|
@ -876,17 +871,17 @@ char *typemap_check(char *op, char *lang, DataType *type, char *pname) {
|
||||||
|
|
||||||
if ((m->type->arraystr) && (type->arraystr)) {
|
if ((m->type->arraystr) && (type->arraystr)) {
|
||||||
// Build up the new array string
|
// Build up the new array string
|
||||||
newarray = "";
|
Clear(newarray);
|
||||||
for (int n = 0; n < m->type->array_dimensions(); n++) {
|
for (int n = 0; n < m->type->array_dimensions(); n++) {
|
||||||
char *d = m->type->get_dimension(n);
|
char *d = m->type->get_dimension(n);
|
||||||
if (strcmp(d,"ANY") == 0) {
|
if (strcmp(d,"ANY") == 0) {
|
||||||
newarray << "[" << type->get_dimension(n) << "]";
|
Printf(newarray,"[%s]", type->get_dimension(n));
|
||||||
} else {
|
} else {
|
||||||
newarray << "[" << d << "]";
|
Printf(newarray,"[%s]", d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oldary = m->type->arraystr;
|
oldary = m->type->arraystr;
|
||||||
m->type->arraystr = newarray.get();
|
m->type->arraystr = Char(newarray);
|
||||||
} else if (type->arraystr) {
|
} else if (type->arraystr) {
|
||||||
m->type->arraystr = type->arraystr;
|
m->type->arraystr = type->arraystr;
|
||||||
}
|
}
|
||||||
|
|
@ -982,7 +977,7 @@ void typemap_copy(char *op, char *lang, DataType *stype, char *sname,
|
||||||
SetVoid(typemap_hash,key, tn);
|
SetVoid(typemap_hash,key, tn);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
typemap_register(op,lang,ttype,tname,tm->code.get(),tm->args);
|
typemap_register(op,lang,ttype,tname,Char(tm->code),tm->args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -994,12 +989,9 @@ void typemap_copy(char *op, char *lang, DataType *stype, char *sname,
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
static char *fragment_string(char *op, char *lang) {
|
static char *fragment_string(char *op, char *lang) {
|
||||||
static String str;
|
static char str[512];
|
||||||
|
sprintf(str,"fragment:%s%s", lang, op);
|
||||||
str = "";
|
return str;
|
||||||
|
|
||||||
str << "fragment:" << lang << op;
|
|
||||||
return str.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
@ -1027,7 +1019,7 @@ void fragment_register(char *op, char *lang, char *code) {
|
||||||
|
|
||||||
sprintf(temp,"$%s",op);
|
sprintf(temp,"$%s",op);
|
||||||
if (type_id < tm_old->last)
|
if (type_id < tm_old->last)
|
||||||
tm->code.replace(temp,tm_old->code.get());
|
Replace(tm->code,temp,tm_old->code,DOH_REPLACE_ANY);
|
||||||
|
|
||||||
tm->next = tm_old;
|
tm->next = tm_old;
|
||||||
tm_old->last = type_id;
|
tm_old->last = type_id;
|
||||||
|
|
@ -1039,7 +1031,7 @@ void fragment_register(char *op, char *lang, char *code) {
|
||||||
|
|
||||||
// Perform a default chaining operation if needed (defaults to nothing)
|
// Perform a default chaining operation if needed (defaults to nothing)
|
||||||
sprintf(temp,"$%s",op);
|
sprintf(temp,"$%s",op);
|
||||||
tm->code.replace(temp,"");
|
Replace(tm->code,temp,"", DOH_REPLACE_ANY);
|
||||||
|
|
||||||
// Add new typemap to the hash table
|
// Add new typemap to the hash table
|
||||||
SetVoid(typemap_hash,key,tm);
|
SetVoid(typemap_hash,key,tm);
|
||||||
|
|
@ -1059,22 +1051,23 @@ void fragment_register(char *op, char *lang, char *code) {
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
char *fragment_lookup(char *op, char *lang, int age) {
|
char *fragment_lookup(char *op, char *lang, int age) {
|
||||||
static String str;
|
static DOHString *str = 0;
|
||||||
char *key = 0;
|
char *key = 0;
|
||||||
TypeMap *tm = 0;
|
TypeMap *tm = 0;
|
||||||
|
|
||||||
|
if (!str) str = NewString("");
|
||||||
if (!lang) {
|
if (!lang) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = "";
|
Clear(str);
|
||||||
key = fragment_string(op,lang);
|
key = fragment_string(op,lang);
|
||||||
tm = typemap_search(key,age);
|
tm = typemap_search(key,age);
|
||||||
|
|
||||||
if (!tm) return 0;
|
if (!tm) return 0;
|
||||||
|
|
||||||
str << tm->code;
|
Append(str,tm->code);
|
||||||
return str.get();
|
return Char(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -432,7 +432,7 @@ char *DataType::get_array() {
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
static DOHHash *typedef_hash[MAXSCOPE];
|
static DOHHash *typedef_hash[MAXSCOPE];
|
||||||
static int scope = 0; // Current scope
|
static int scope = 0; // Current scope
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// void DataType::init_typedef()
|
// void DataType::init_typedef()
|
||||||
|
|
@ -464,7 +464,7 @@ void DataType::init_typedef() {
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
void DataType::typedef_add(char *tname, int mode) {
|
void DataType::typedef_add(char *tname, int mode) {
|
||||||
char *name1, *name2;
|
char *name1, *name2;
|
||||||
DataType *nt, t1;
|
DataType *nt, t1;
|
||||||
void typeeq_addtypedef(char *name, char *eqname, DataType *);
|
void typeeq_addtypedef(char *name, char *eqname, DataType *);
|
||||||
|
|
||||||
|
|
@ -708,11 +708,10 @@ void *DataType::collapse_scope(char *prefix) {
|
||||||
while (key) {
|
while (key) {
|
||||||
t = (DataType *) GetVoid(typedef_hash[scope],key);
|
t = (DataType *) GetVoid(typedef_hash[scope],key);
|
||||||
nt = new DataType(t);
|
nt = new DataType(t);
|
||||||
temp = new char[strlen(prefix)+strlen(Char(key))+3];
|
temp = new char[strlen(prefix)+strlen(Char(key))+4];
|
||||||
sprintf(temp,"%s::%s",prefix,Char(key));
|
sprintf(temp,"%s::%s",prefix,Char(key));
|
||||||
// printf("creating %s\n", temp);
|
|
||||||
SetVoid(typedef_hash[scope-1],temp, (void *)nt);
|
SetVoid(typedef_hash[scope-1],temp, (void *)nt);
|
||||||
delete temp;
|
delete [] temp;
|
||||||
key = Nextkey(typedef_hash[scope]);
|
key = Nextkey(typedef_hash[scope]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -860,15 +859,18 @@ void emit_ptr_equivalence(FILE *f) {
|
||||||
EqEntry *e1,*e2;
|
EqEntry *e1,*e2;
|
||||||
DOH *k;
|
DOH *k;
|
||||||
void typeeq_standard();
|
void typeeq_standard();
|
||||||
String ttable;
|
DOHString *ttable;
|
||||||
|
|
||||||
if (!te_init) typeeq_init();
|
if (!te_init) typeeq_init();
|
||||||
|
|
||||||
ttable << "\
|
ttable = NewString("");
|
||||||
|
|
||||||
|
Printv(ttable,"\
|
||||||
/*\n\
|
/*\n\
|
||||||
* This table is used by the pointer type-checker\n\
|
* This table is used by the pointer type-checker\n\
|
||||||
*/\n\
|
*/\n\
|
||||||
static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {\n";
|
static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {\n",
|
||||||
|
0);
|
||||||
|
|
||||||
k = Firstkey(typeeq_hash);
|
k = Firstkey(typeeq_hash);
|
||||||
while (k) {
|
while (k) {
|
||||||
|
|
@ -877,47 +879,26 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
|
||||||
// Walk through the equivalency list
|
// Walk through the equivalency list
|
||||||
while (e2) {
|
while (e2) {
|
||||||
if (e2->cast)
|
if (e2->cast)
|
||||||
ttable << tab4 << "{ \"" << e1->name << "\",\"" << e2->name << "\"," << e2->cast << "},\n";
|
Printv(ttable,
|
||||||
|
tab4, "{ \"", e1->name, "\",\"", e2->name, "\"," , e2->cast , "},\n",
|
||||||
|
0);
|
||||||
else
|
else
|
||||||
ttable << tab4 << "{ \"" << e1->name << "\",\"" << e2->name << "\",0},\n";
|
Printv(ttable,
|
||||||
|
tab4, "{ \"", e1->name, "\",\"", e2->name, "\",0},\n",
|
||||||
|
0);
|
||||||
|
|
||||||
e2 = e2->next;
|
e2 = e2->next;
|
||||||
}
|
}
|
||||||
k = Nextkey(typeeq_hash);
|
k = Nextkey(typeeq_hash);
|
||||||
}
|
}
|
||||||
ttable << "{0,0,0}};\n";
|
Printf(ttable,"{0,0,0}};\n");
|
||||||
fprintf(f_wrappers,"%s\n", ttable.get());
|
fprintf(f_wrappers,"%s\n", Char(ttable));
|
||||||
fprintf(f,"{\n");
|
fprintf(f,"{\n");
|
||||||
fprintf(f," int i;\n");
|
fprintf(f," int i;\n");
|
||||||
fprintf(f," for (i = 0; _swig_mapping[i].n1; i++)\n");
|
fprintf(f," for (i = 0; _swig_mapping[i].n1; i++)\n");
|
||||||
fprintf(f," SWIG_RegisterMapping(_swig_mapping[i].n1,_swig_mapping[i].n2,_swig_mapping[i].pcnv);\n");
|
fprintf(f," SWIG_RegisterMapping(_swig_mapping[i].n1,_swig_mapping[i].n2,_swig_mapping[i].pcnv);\n");
|
||||||
fprintf(f,"}\n");
|
fprintf(f,"}\n");
|
||||||
|
Delete(ttable);
|
||||||
String ctable;
|
|
||||||
ctable << "/*\n";
|
|
||||||
ctable << "typedef struct {\n"
|
|
||||||
<< " const char *name; \n"
|
|
||||||
<< " void *(*convert)(void *);\n"
|
|
||||||
<< "} SwigType;\n";
|
|
||||||
|
|
||||||
k = Firstkey(typeeq_hash);
|
|
||||||
while (k) {
|
|
||||||
e1 = (EqEntry *) GetVoid(typeeq_hash,k);
|
|
||||||
e2 = e1->next;
|
|
||||||
ctable << "static SwigType " << e1->name << "[] = {";
|
|
||||||
// Walk through the equivalency list
|
|
||||||
while (e2) {
|
|
||||||
ctable << "{ \"" << e2->name << "\", ";
|
|
||||||
if (e2->cast)
|
|
||||||
ctable << e2->cast << "},";
|
|
||||||
else
|
|
||||||
ctable << "0},";
|
|
||||||
e2 = e2->next;
|
|
||||||
}
|
|
||||||
ctable << "{0,0}};\n";
|
|
||||||
k = Nextkey(typeeq_hash);
|
|
||||||
}
|
|
||||||
ctable << "*/\n";
|
|
||||||
fprintf(f_wrappers,"%s\n", ctable.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
|
|
@ -995,43 +976,45 @@ void typeeq_standard(void) {
|
||||||
static char *
|
static char *
|
||||||
check_equivalent(DataType *t) {
|
check_equivalent(DataType *t) {
|
||||||
EqEntry *e1, *e2;
|
EqEntry *e1, *e2;
|
||||||
static String out;
|
static DOHString *out = 0;
|
||||||
int npointer = t->is_pointer;
|
int npointer = t->is_pointer;
|
||||||
String m;
|
char *m;
|
||||||
DOH *k;
|
DOHString *k;
|
||||||
|
|
||||||
|
if (!out) out = NewString("");
|
||||||
|
Clear(out);
|
||||||
|
|
||||||
out = "";
|
|
||||||
while (t->is_pointer >= t->implicit_ptr) {
|
while (t->is_pointer >= t->implicit_ptr) {
|
||||||
m = t->print_mangle();
|
m = copy_string(t->print_mangle());
|
||||||
|
|
||||||
if (!te_init) typeeq_init();
|
if (!te_init) typeeq_init();
|
||||||
|
|
||||||
k = Firstkey(typeeq_hash);
|
k = Firstkey(typeeq_hash);
|
||||||
while (k) {
|
while (k) {
|
||||||
e1 = (EqEntry *) GetVoid(typeeq_hash,k);
|
e1 = (EqEntry *) GetVoid(typeeq_hash,k);
|
||||||
/* printf("'%s', '%s'\n", m.get(),e1->name); */
|
if (strcmp(m,e1->name) == 0) {
|
||||||
if (strcmp(m.get(),e1->name) == 0) {
|
|
||||||
e2 = e1->next;
|
e2 = e1->next;
|
||||||
while (e2) {
|
while (e2) {
|
||||||
if (e2->type) {
|
if (e2->type) {
|
||||||
e2->type->is_pointer += (npointer - t->is_pointer);
|
e2->type->is_pointer += (npointer - t->is_pointer);
|
||||||
out << "{ \"" << e2->type->print_mangle() << "\",";
|
Printf(out,"{ \"%s\",", e2->type->print_mangle());
|
||||||
e2->type->is_pointer -= (npointer - t->is_pointer);
|
e2->type->is_pointer -= (npointer - t->is_pointer);
|
||||||
if (e2->cast)
|
if (e2->cast)
|
||||||
out << e2->cast << "}, ";
|
Printf(out,"%s}, ", e2->cast);
|
||||||
else
|
else
|
||||||
out << "0}, ";
|
Printf(out,"0}, ");
|
||||||
}
|
}
|
||||||
e2 = e2->next;
|
e2 = e2->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
k = Nextkey(typeeq_hash);
|
k = Nextkey(typeeq_hash);
|
||||||
}
|
}
|
||||||
|
delete [] m;
|
||||||
t->is_pointer--;
|
t->is_pointer--;
|
||||||
}
|
}
|
||||||
t->is_pointer = npointer;
|
t->is_pointer = npointer;
|
||||||
out << "{0}";
|
Printf(out,"{0}");
|
||||||
return out.get();
|
return Char(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
@ -1093,29 +1076,33 @@ void DataType::remember() {
|
||||||
void
|
void
|
||||||
emit_type_table() {
|
emit_type_table() {
|
||||||
DOH *key;
|
DOH *key;
|
||||||
String types, table;
|
DOHString *types, *table;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (!remembered) remembered = NewHash();
|
if (!remembered) remembered = NewHash();
|
||||||
|
|
||||||
table << "static _swig_type_info *_swig_types_initial[] = {\n";
|
table = NewString("");
|
||||||
|
types = NewString("");
|
||||||
|
Printf(table,"static _swig_type_info *_swig_types_initial[] = {\n");
|
||||||
key = Firstkey(remembered);
|
key = Firstkey(remembered);
|
||||||
fprintf(f_runtime,"/* ---- TYPES TABLE (BEGIN) ---- */\n");
|
fprintf(f_runtime,"/* ---- TYPES TABLE (BEGIN) ---- */\n");
|
||||||
while (key) {
|
while (key) {
|
||||||
fprintf(f_runtime,"#define SWIGTYPE%s _swig_types[%d] \n", Char(key), i);
|
fprintf(f_runtime,"#define SWIGTYPE%s _swig_types[%d] \n", Char(key), i);
|
||||||
types << "static _swig_type_info _swigt_" << Char(key) << "[] = {";
|
Printv(types,"static _swig_type_info _swigt_", Char(key), "[] = {", 0);
|
||||||
types << "{\"" << Char(key) << "\",0},";
|
Printv(types,"{\"", Char(key), "\",0},", 0);
|
||||||
types << "{\"" << Char(key) << "\",0},";
|
Printv(types, "{\"", Char(key), "\",0},", 0);
|
||||||
types << check_equivalent((DataType *)GetVoid(remembered,key)) << "};\n";
|
Printv(types, check_equivalent((DataType *)GetVoid(remembered,key)), "};\n", 0);
|
||||||
table << "_swigt_" << Char(key) << ", \n";
|
Printv(table, "_swigt_", Char(key), ", \n", 0);
|
||||||
key = Nextkey(remembered);
|
key = Nextkey(remembered);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
table << "0\n};\n";
|
Printf(table, "0\n};\n");
|
||||||
fprintf(f_wrappers,"%s\n", types.get());
|
fprintf(f_wrappers,"%s\n", Char(types));
|
||||||
fprintf(f_wrappers,"%s\n", table.get());
|
fprintf(f_wrappers,"%s\n", Char(table));
|
||||||
fprintf(f_runtime,"static _swig_type_info *_swig_types[%d];\n", i+1);
|
fprintf(f_runtime,"static _swig_type_info *_swig_types[%d];\n", i+1);
|
||||||
fprintf(f_runtime,"/* ---- TYPES TABLE (END) ---- */\n\n");
|
fprintf(f_runtime,"/* ---- TYPES TABLE (END) ---- */\n\n");
|
||||||
|
Delete(types);
|
||||||
|
Delete(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ extern "C" {
|
||||||
WrapperFunction::WrapperFunction() {
|
WrapperFunction::WrapperFunction() {
|
||||||
h = NewHash();
|
h = NewHash();
|
||||||
localh = NewHash();
|
localh = NewHash();
|
||||||
|
_def = def.doh();
|
||||||
|
_locals = locals.doh();
|
||||||
|
_code = code.doh();
|
||||||
|
_init = init.doh();
|
||||||
}
|
}
|
||||||
|
|
||||||
WrapperFunction::~WrapperFunction() {
|
WrapperFunction::~WrapperFunction() {
|
||||||
|
|
@ -47,38 +51,38 @@ WrapperFunction::~WrapperFunction() {
|
||||||
// isolate the type name. This is a hack (sorry).
|
// isolate the type name. This is a hack (sorry).
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
||||||
static String type_ext;
|
static char type_ext[512];
|
||||||
static char *isolate_type_name(char *tname) {
|
static char *isolate_type_name(char *tname) {
|
||||||
static String s;
|
static char s[512];
|
||||||
s = "";
|
char *c = s;
|
||||||
|
|
||||||
while ((*tname) && (isalnum(*tname) || (*tname == '_') || (*tname == '$') || (*tname == ' ') || (*tname == ':'))) {
|
while ((*tname) && (isalnum(*tname) || (*tname == '_') || (*tname == '$') || (*tname == ' ') || (*tname == ':'))) {
|
||||||
s << *tname;
|
*(c++) = *tname;
|
||||||
tname++;
|
tname++;
|
||||||
}
|
}
|
||||||
type_ext = "";
|
*c = 0;
|
||||||
type_ext = tname;
|
strcpy(type_ext,tname);
|
||||||
return s.get();
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Print out a wrapper function.
|
// Print out a wrapper function.
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
||||||
void WrapperFunction::print(FILE *f) {
|
void WrapperFunction::print(DOHFile *f) {
|
||||||
String *s;
|
DOHString *s;
|
||||||
DOH *key;
|
DOH *key;
|
||||||
|
|
||||||
key = Firstkey(localh);
|
key = Firstkey(localh);
|
||||||
while (key) {
|
while (key) {
|
||||||
s = (String *) GetVoid(localh,key);
|
s = Getattr(localh,key);
|
||||||
char *c = s->get();
|
Delitem(s,DOH_END);
|
||||||
c[strlen(c)-1] = 0;
|
Printv(_locals,tab4,s,";\n",0);
|
||||||
locals << tab4 << c << ";\n";
|
|
||||||
key = Nextkey(localh);
|
key = Nextkey(localh);
|
||||||
}
|
}
|
||||||
fprintf(f,"%s\n",def.get());
|
Printf(f,"%s\n",_def);
|
||||||
fprintf(f,"%s",locals.get());
|
Printf(f,"%s",_locals);
|
||||||
fprintf(f,"%s\n",code.get());
|
Printf(f,"%s\n",_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
@ -86,14 +90,13 @@ void WrapperFunction::print(FILE *f) {
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
||||||
void WrapperFunction::print(String &f) {
|
void WrapperFunction::print(String &f) {
|
||||||
String *s;
|
DOHString *s;
|
||||||
DOH *key;
|
DOH *key;
|
||||||
key = Firstkey(localh);
|
key = Firstkey(localh);
|
||||||
while (key) {
|
while (key) {
|
||||||
s = (String *) GetVoid(localh,key);
|
s = Getattr(localh,key);
|
||||||
char *c = s->get();
|
Delitem(s,DOH_END);
|
||||||
c[strlen(c)-1] = 0;
|
Printv(_locals,tab4,s,";\n",0);
|
||||||
locals << tab4 << c << ";\n";
|
|
||||||
key = Nextkey(localh);
|
key = Nextkey(localh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,21 +142,18 @@ void WrapperFunction::add_local(char *type, char *name, char *defarg) {
|
||||||
// See if any wrappers have been generated with this type
|
// See if any wrappers have been generated with this type
|
||||||
|
|
||||||
char *tname = isolate_type_name(type);
|
char *tname = isolate_type_name(type);
|
||||||
String *lstr = (String *) GetVoid(localh,tname);
|
DOHString *lstr = Getattr(localh,tname);
|
||||||
if (!lstr) {
|
if (!lstr) {
|
||||||
lstr = new String;
|
lstr = NewStringf("%s ", tname);
|
||||||
*(lstr) << tname << " ";
|
Setattr(localh,tname,lstr);
|
||||||
SetVoid(localh,tname,lstr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Successful, write some wrapper code
|
// Successful, write some wrapper code
|
||||||
|
|
||||||
if (!defarg) {
|
if (!defarg) {
|
||||||
*(lstr) << type_ext << name << ",";
|
Printv(lstr,type_ext,name,",",0);
|
||||||
// locals << tab4 << type << " " << name << ";\n";
|
|
||||||
} else {
|
} else {
|
||||||
*(lstr) << type_ext << name << "=" << defarg << ",";
|
Printv(lstr,type_ext,name, "=", defarg, ",", 0);
|
||||||
// locals << tab4 << type << " " << name << " = " << defarg << ";\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,54 +168,55 @@ void WrapperFunction::add_local(char *type, char *name, char *defarg) {
|
||||||
|
|
||||||
char *WrapperFunction::new_local(char *type, char *name, char *defarg) {
|
char *WrapperFunction::new_local(char *type, char *name, char *defarg) {
|
||||||
char *new_type;
|
char *new_type;
|
||||||
static String new_name;
|
static DOHString *new_name = 0;
|
||||||
char *c;
|
char *c;
|
||||||
new_type = new char[strlen(type)+1];
|
new_type = new char[strlen(type)+1];
|
||||||
|
|
||||||
|
if (!new_name) new_name = NewString("");
|
||||||
strcpy(new_type,type);
|
strcpy(new_type,type);
|
||||||
new_name = "";
|
Clear(new_name);
|
||||||
c = name;
|
c = name;
|
||||||
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
|
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
|
||||||
new_name << *c;
|
Putc(*c,new_name);
|
||||||
|
|
||||||
// Try to add a new local variable
|
// Try to add a new local variable
|
||||||
if (Getattr(h,new_name.get())) {
|
if (Getattr(h,new_name)) {
|
||||||
// Local variable already exists, try to generate a new name
|
// Local variable already exists, try to generate a new name
|
||||||
int i = 0;
|
int i = 0;
|
||||||
new_name = "";
|
Clear(new_name);
|
||||||
// This is a little funky. We copy characters until we reach a nonvalid
|
// This is a little funky. We copy characters until we reach a nonvalid
|
||||||
// identifier symbol, add a number, then append the rest. This is
|
// identifier symbol, add a number, then append the rest. This is
|
||||||
// needed to properly handle arrays.
|
// needed to properly handle arrays.
|
||||||
c = name;
|
c = name;
|
||||||
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
|
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
|
||||||
new_name << *c;
|
Putc(*c,new_name);
|
||||||
new_name << i;
|
Printf(new_name,"%d",i);
|
||||||
while (Getattr(h,new_name.get())) {
|
while (Getattr(h,new_name)) {
|
||||||
i++;
|
i++;
|
||||||
c = name;
|
c = name;
|
||||||
new_name = "";
|
Clear(new_name);
|
||||||
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
|
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
|
||||||
new_name << *c;
|
Putc(*c,new_name);
|
||||||
new_name << i;
|
Printf(new_name,"%d",i);
|
||||||
}
|
}
|
||||||
Setattr(h,new_name.get(),new_type);
|
Setattr(h,new_name,new_type);
|
||||||
} else {
|
} else {
|
||||||
Setattr(h,new_name.get(),new_type);
|
Setattr(h,new_name,new_type);
|
||||||
}
|
}
|
||||||
new_name << c;
|
Printf(new_name,"%s",c);
|
||||||
// Successful, write some wrapper code
|
// Successful, write some wrapper code
|
||||||
if (!defarg)
|
if (!defarg)
|
||||||
locals << tab4 << type << " " << new_name << ";\n";
|
Printv(_locals,tab4,type, " ", new_name, ";\n");
|
||||||
else
|
else
|
||||||
locals << tab4 << type << " " << new_name << " = " << defarg << ";\n";
|
Printv(_locals,tab4,type, " ", new_name, " = ", defarg, ";\n");
|
||||||
|
|
||||||
// Need to strip off the array symbols now
|
// Need to strip off the array symbols now
|
||||||
|
|
||||||
c = new_name.get();
|
c = Char(new_name);
|
||||||
while ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c))
|
while ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c))
|
||||||
c++;
|
c++;
|
||||||
*c = 0;
|
*c = 0;
|
||||||
return new_name.get();
|
return Char(new_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue