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/SWIG@536 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
05192f5b55
commit
0c5c878bf9
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
|
||||
if (((p->t->is_reference) && (p->defvalue)) ||
|
||||
((p->t->type == T_USER) && (p->call_type == CALL_REFERENCE) && (p->defvalue))) {
|
||||
String deftmp;
|
||||
deftmp << "(" << p->t->print_type() << ") &" << p->defvalue;
|
||||
f.add_local(p->t->print_type(),temp,deftmp.get());
|
||||
char deftmp[1024];
|
||||
sprintf(deftmp,"(%s) &%s", p->t->print_type(), p->defvalue);
|
||||
f.add_local(p->t->print_type(),temp,deftmp);
|
||||
} else {
|
||||
String deftmp;
|
||||
char *dv = 0;
|
||||
char deftmp[1024];
|
||||
if (p->defvalue) {
|
||||
deftmp << "(" << p->t->print_type() << ") " << p->defvalue;
|
||||
dv = deftmp.get();
|
||||
sprintf(deftmp,"(%s) %s", p->t->print_type(), p->defvalue);
|
||||
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);
|
||||
if (tm) {
|
||||
f.code << tm << "\n";
|
||||
Printv(f._code,tm,"\n",0);
|
||||
}
|
||||
}
|
||||
// Check for ignore or default typemaps
|
||||
tm = typemap_lookup((char*)"default",typemap_lang,p->t,p->name,(char*)"",temp,&f);
|
||||
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);
|
||||
if (tm) {
|
||||
f.code << tm << "\n";
|
||||
Printv(f._code,tm,"\n",0);
|
||||
p->ignore = 1;
|
||||
}
|
||||
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;
|
||||
Parm *p;
|
||||
String fcall;
|
||||
String exc;
|
||||
DOHString *fcall;
|
||||
DOHString *exc;
|
||||
char *tm;
|
||||
|
||||
// f.code << "#line " << line_number << " \"" << input_file << "\"\n";
|
||||
fcall << tab4;
|
||||
fcall = NewString(tab4);
|
||||
exc = NewString("");
|
||||
|
||||
// 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.
|
||||
|
||||
if (CPlusPlus) {
|
||||
fcall << "_result = new " << t->print_type() << "(";
|
||||
Printv(fcall, "_result = new ", t->print_type(), "(", 0);
|
||||
} else {
|
||||
t->is_pointer++;
|
||||
fcall << "_result = " << t->print_cast() << " malloc(sizeof(";
|
||||
Printv(fcall, "_result = ", t->print_cast(), " malloc(sizeof(", 0);
|
||||
t->is_pointer--;
|
||||
fcall << t->print_type() << "));\n";
|
||||
fcall << tab4 << "*(_result) = ";
|
||||
Printv(fcall, t->print_type(), "));\n", 0);
|
||||
Printv(fcall, tab4, "*(_result) = ", 0);
|
||||
}
|
||||
} else {
|
||||
// Check if this is a C++ reference
|
||||
if (t->is_reference) {
|
||||
t->is_pointer--;
|
||||
fcall << t->print_full() << "& _result_ref = ";
|
||||
Printv(fcall, t->print_full(), "& _result_ref = ", 0);
|
||||
t->is_pointer++;
|
||||
} else {
|
||||
|
||||
// Normal return value
|
||||
fcall << "_result = " << t->print_cast();
|
||||
Printv(fcall, "_result = ", t->print_cast(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now print out function call
|
||||
|
||||
fcall << decl << "(";
|
||||
Printv(fcall, decl, "(", 0);
|
||||
|
||||
i = 0;
|
||||
p = l->get_first();
|
||||
while(p != 0) {
|
||||
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))
|
||||
fcall << "&";
|
||||
Printf(fcall, "&");
|
||||
if ((!(p->call_type & CALL_VALUE)) &&
|
||||
((p->t->is_reference) || (p->call_type & CALL_REFERENCE)))
|
||||
fcall << "*";
|
||||
fcall << emit_local(i);
|
||||
Printf(fcall, "*");
|
||||
Printf(fcall, emit_local(i));
|
||||
i++;
|
||||
}
|
||||
p = l->get_next();
|
||||
if (p != 0)
|
||||
fcall << ",";
|
||||
Printf(fcall,",");
|
||||
}
|
||||
fcall << ")";
|
||||
Printf(fcall,")");
|
||||
|
||||
if ((t->type == T_USER) && (!t->is_pointer)) {
|
||||
if (CPlusPlus) {
|
||||
fcall << ")";
|
||||
Printf(fcall,")");
|
||||
}
|
||||
}
|
||||
fcall << ";\n";
|
||||
Printf(fcall,";\n");
|
||||
|
||||
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
|
||||
|
||||
if ((tm = typemap_lookup((char*)"except",typemap_lang,t,decl,(char*)"_result",(char*)""))) {
|
||||
// Found a type-specific mapping
|
||||
exc << tm;
|
||||
exc.replace("$function",fcall.get());
|
||||
exc.replace("$name",decl);
|
||||
f.code << exc;
|
||||
Printv(exc,tm);
|
||||
Replace(exc,"$function",fcall,DOH_REPLACE_ANY);
|
||||
Replace(exc,"$name",decl,DOH_REPLACE_ANY);
|
||||
Printv(f._code,exc,0);
|
||||
} else if ((tm = fragment_lookup((char*)"except",typemap_lang, t->id))) {
|
||||
exc << tm;
|
||||
exc.replace("$function",fcall.get());
|
||||
exc.replace("$name",decl);
|
||||
f.code << exc;
|
||||
Printv(exc,tm);
|
||||
Replace(exc,"$function",fcall,DOH_REPLACE_ANY);
|
||||
Replace(exc,"$name",decl,DOH_REPLACE_ANY);
|
||||
Printv(f._code,exc,0);
|
||||
} 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;
|
||||
ParmList *l;
|
||||
String new_name;
|
||||
String new_iname;
|
||||
String wname;
|
||||
char *new_name = 0, *new_iname = 0;
|
||||
|
||||
// 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;
|
||||
l->append(p);
|
||||
|
||||
new_name = Swig_name_set(name);
|
||||
new_iname = Swig_name_set(iname);
|
||||
new_name = copy_string(Swig_name_set(name));
|
||||
new_iname = copy_string(Swig_name_set(iname));
|
||||
|
||||
if ((t->type == T_USER) && (!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--;
|
||||
} else {
|
||||
lang->create_function(new_name.get(), new_iname.get(), t, l);
|
||||
lang->create_function(new_name, new_iname, t, l);
|
||||
}
|
||||
delete l;
|
||||
delete p;
|
||||
|
|
@ -501,17 +501,22 @@ void emit_set_get(char *name, char *iname, DataType *t) {
|
|||
|
||||
l = new ParmList;
|
||||
|
||||
new_name = Swig_name_get(name);
|
||||
new_iname = Swig_name_get(iname);
|
||||
if (new_name) delete [] new_name;
|
||||
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)) {
|
||||
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--;
|
||||
} else {
|
||||
lang->create_function(new_name.get(), new_iname.get(), t, l);
|
||||
lang->create_function(new_name, new_iname, t, l);
|
||||
}
|
||||
delete l;
|
||||
delete [] new_name;
|
||||
delete [] new_iname;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
extern Language *lang;
|
||||
extern int ForceExtern;
|
||||
extern int WrapExtern;
|
||||
extern String CCode;
|
||||
extern void *CCode;
|
||||
extern int GenerateDefault;
|
||||
extern int type_id;
|
||||
extern char *objc_construct;
|
||||
|
|
|
|||
|
|
@ -148,6 +148,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
|||
extern int check_suffix(char *);
|
||||
extern void scanner_file(FILE *);
|
||||
extern void typemap_initialize(void);
|
||||
extern void parser_init(void);
|
||||
|
||||
DOH *libfiles = 0;
|
||||
|
||||
#ifdef MACSWIG
|
||||
|
|
@ -481,6 +483,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
|||
fprintf (stdout, "Starting language-specific parse...\n");
|
||||
fflush (stdout);
|
||||
}
|
||||
parser_init();
|
||||
lang->parse();
|
||||
if (Verbose) {
|
||||
fprintf (stdout, "Finished language-specific parse.\n");
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ static char cvsroot[] = "$Header$";
|
|||
|
||||
#include "internal.h"
|
||||
|
||||
extern "C" {
|
||||
#include "doh.h"
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// 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.
|
||||
// This is for generating valid C prototypes. Has to do some
|
||||
|
|
@ -328,7 +332,7 @@ Parm * ParmList::get_next() {
|
|||
// variable has been set.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void ParmList::print_types(FILE *f) {
|
||||
void ParmList::print_types(DOHFile *f) {
|
||||
|
||||
int is_pointer;
|
||||
int pn;
|
||||
|
|
@ -338,59 +342,23 @@ void ParmList::print_types(FILE *f) {
|
|||
if (parms[pn]->t->is_reference) {
|
||||
if (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++;
|
||||
} else {
|
||||
fprintf(f,"%s&", parms[pn]->t->print_real());
|
||||
Printf(f,"%s&", 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--;
|
||||
fprintf(f,"%s", parms[pn]->t->print_real());
|
||||
Printf(f,"%s", parms[pn]->t->print_real());
|
||||
parms[pn]->t->is_pointer = is_pointer;
|
||||
}
|
||||
pn++;
|
||||
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)
|
||||
//
|
||||
|
|
@ -424,27 +392,3 @@ void ParmList::print_args(FILE *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 DataType *Active_typedef = 0; // Used for typedef lists
|
||||
static int InArray = 0; // Used when an array declaration is found
|
||||
static String ArrayString; // Array type attached to parameter names
|
||||
static String ArrayBackup; // Array backup string
|
||||
static DOHString *ArrayString = 0; // Array type attached to parameter names
|
||||
static DOHString *ArrayBackup = 0;
|
||||
static char *DefArg = 0; // Default argument hack
|
||||
static char *ConstChar = 0; // Used to store raw character constants
|
||||
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_unset_class();
|
||||
extern void cplus_abort();
|
||||
|
||||
|
||||
void parser_init() {
|
||||
ArrayString = NewString("");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// static init_language()
|
||||
//
|
||||
|
|
@ -181,11 +185,12 @@ static char *make_name(char *name) {
|
|||
} else {
|
||||
// Now check to see if the name contains a $
|
||||
if (strchr(name,'$')) {
|
||||
static String temp;
|
||||
temp = "";
|
||||
temp << name;
|
||||
temp.replace("$","_S_");
|
||||
return temp.get();
|
||||
static DOHString *temp = 0;
|
||||
if (!temp) temp= NewString("");
|
||||
Clear(temp);
|
||||
Append(temp,name);
|
||||
Replace(temp,"$","_S_",DOH_REPLACE_ANY);
|
||||
return Char(temp);
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
|
|
@ -312,7 +317,7 @@ void print_array() {
|
|||
// Structures for handling code fragments built for nested classes
|
||||
|
||||
struct Nested {
|
||||
String code; // Associated code fragment
|
||||
DOHString *code; // Associated code fragment
|
||||
int line; // line number where it starts
|
||||
char *name; // Name associated with this nested class
|
||||
DataType *type; // Datatype associated with the name
|
||||
|
|
@ -347,7 +352,7 @@ static void dump_nested(char *parent) {
|
|||
Status = STAT_READONLY;
|
||||
while (n) {
|
||||
// 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)
|
||||
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
|
||||
|
||||
fprintf(f_header,"\n%s\n", n->code.get());
|
||||
start_inline(n->code.get(),n->line);
|
||||
fprintf(f_header,"\n%s\n", Char(n->code));
|
||||
start_inline(Char(n->code),n->line);
|
||||
|
||||
n1 = n->next;
|
||||
Delete(n->code);
|
||||
delete n;
|
||||
n = n1;
|
||||
}
|
||||
|
|
@ -548,7 +554,7 @@ statement : INCLUDE STRING LBRACE {
|
|||
if ($4 > 0) {
|
||||
$2->is_pointer++;
|
||||
$2->status = STAT_READONLY;
|
||||
$2->arraystr = copy_string(ArrayString.get());
|
||||
$2->arraystr = copy_string(Char(ArrayString));
|
||||
}
|
||||
if ($3.is_reference) {
|
||||
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 {
|
||||
if (Inline) {
|
||||
if (strlen(CCode.get())) {
|
||||
if (strlen(Char(CCode))) {
|
||||
init_language();
|
||||
$2->is_pointer += $3.is_pointer;
|
||||
$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);
|
||||
FatalError();
|
||||
} else {
|
||||
if (strlen(CCode.get())) {
|
||||
if (strlen(Char(CCode))) {
|
||||
fprintf(f_header,"static ");
|
||||
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);
|
||||
}
|
||||
|
|
@ -929,7 +935,7 @@ statement : INCLUDE STRING LBRACE {
|
|||
skip_brace();
|
||||
p = $7;
|
||||
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;
|
||||
}
|
||||
delete $3;
|
||||
|
|
@ -947,7 +953,7 @@ statement : INCLUDE STRING LBRACE {
|
|||
skip_brace();
|
||||
p = $5;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1052,14 +1058,14 @@ statement : INCLUDE STRING LBRACE {
|
|||
/* An exception definition */
|
||||
| EXCEPT LPAREN ID RPAREN LBRACE {
|
||||
skip_brace();
|
||||
fragment_register((char *)"except",$3, CCode.get());
|
||||
fragment_register((char *)"except",$3, Char(CCode));
|
||||
delete $3;
|
||||
}
|
||||
|
||||
/* A Generic Exception (no language specified */
|
||||
| EXCEPT LBRACE {
|
||||
skip_brace();
|
||||
fragment_register((char *) "except",typemap_lang, CCode.get());
|
||||
fragment_register((char *) "except",typemap_lang, Char(CCode));
|
||||
}
|
||||
|
||||
/* Clear an exception */
|
||||
|
|
@ -1194,7 +1200,7 @@ typedef_decl : TYPEDEF type declaration {
|
|||
$2->is_pointer += $3.is_pointer;
|
||||
// Turn this into a "pointer" corresponding to the array
|
||||
$2->is_pointer++;
|
||||
$2->arraystr = copy_string(ArrayString.get());
|
||||
$2->arraystr = copy_string(Char(ArrayString));
|
||||
$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);
|
||||
cplus_register_type($3.id);
|
||||
|
|
@ -1227,7 +1233,7 @@ typedeflist : COMMA declaration typedeflist {
|
|||
t = new DataType(Active_typedef);
|
||||
t->status = STAT_READONLY | STAT_REPLACETYPE;
|
||||
t->is_pointer += $2.is_pointer + 1;
|
||||
t->arraystr = copy_string(ArrayString.get());
|
||||
t->arraystr = copy_string(Char(ArrayString));
|
||||
t->typedef_add($2.id);
|
||||
cplus_register_type($2.id);
|
||||
delete t;
|
||||
|
|
@ -1264,7 +1270,7 @@ stail : SEMI { }
|
|||
if ($3 > 0) {
|
||||
temp_typeptr->is_pointer++;
|
||||
temp_typeptr->status = STAT_READONLY;
|
||||
temp_typeptr->arraystr = copy_string(ArrayString.get());
|
||||
temp_typeptr->arraystr = copy_string(Char(ArrayString));
|
||||
}
|
||||
if ($2.is_reference) {
|
||||
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) {
|
||||
$1->is_pointer++;
|
||||
// Add array string to the type
|
||||
$1->arraystr = copy_string(ArrayString.get());
|
||||
$1->arraystr = copy_string(Char(ArrayString));
|
||||
}
|
||||
$$ = new Parm($1,$2);
|
||||
$$->call_type = 0;
|
||||
|
|
@ -1378,7 +1384,7 @@ parm_type : type pname {
|
|||
if (InArray) {
|
||||
$$->t->is_pointer++;
|
||||
// Add array string to the type
|
||||
$$->t->arraystr = copy_string(ArrayString.get());
|
||||
$$->t->arraystr = copy_string(Char(ArrayString));
|
||||
}
|
||||
delete $1;
|
||||
delete $3;
|
||||
|
|
@ -1500,20 +1506,20 @@ stars : STAR empty { $$ = 1; }
|
|||
|
||||
array : LBRACKET RBRACKET array2 {
|
||||
$$ = $3 + 1;
|
||||
"[]" >> ArrayString;
|
||||
Insert(ArrayString,0,"[]");
|
||||
}
|
||||
| LBRACKET expr RBRACKET array2 {
|
||||
$$ = $4 + 1;
|
||||
"]" >> ArrayString;
|
||||
$2.id >> ArrayString;
|
||||
"[" >> ArrayString;
|
||||
Insert(ArrayString,0,"]");
|
||||
Insert(ArrayString,0,$2.id);
|
||||
Insert(ArrayString,0,"[");
|
||||
}
|
||||
;
|
||||
array2 : array {
|
||||
$$ = $1;
|
||||
}
|
||||
| empty { $$ = 0;
|
||||
ArrayString = "";
|
||||
Clear(ArrayString);
|
||||
}
|
||||
;
|
||||
|
||||
|
|
@ -2399,7 +2405,7 @@ cpp_member : type declaration LPAREN parms RPAREN cpp_end {
|
|||
Active_type = new DataType($1);
|
||||
$1->is_pointer += $2.is_pointer + 1;
|
||||
$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*)"")))
|
||||
Status = STAT_READONLY;
|
||||
|
||||
|
|
@ -2567,8 +2573,9 @@ cpp_pragma : PRAGMA ID stylearg {
|
|||
/* Generate some code for a new class */
|
||||
} else {
|
||||
Nested *n = new Nested;
|
||||
n->code << "typedef " << $1 << " "
|
||||
<< CCode.get() << " $classname_" << $5.id << ";\n";
|
||||
n->code = NewString("");
|
||||
Printv(n->code, "typedef ", $1, " ",
|
||||
Char(CCode), " $classname_", $5.id, ";\n", 0);
|
||||
n->name = copy_string($5.id);
|
||||
n->line = start_line;
|
||||
n->type = new DataType;
|
||||
|
|
@ -2592,8 +2599,9 @@ cpp_pragma : PRAGMA ID stylearg {
|
|||
/* Generate some code for a new class */
|
||||
|
||||
Nested *n = new Nested;
|
||||
n->code << "typedef " << $1 << " "
|
||||
<< CCode.get() << " $classname_" << $4.id << ";\n";
|
||||
n->code = NewString("");
|
||||
Printv(n->code, "typedef ", $1, " " ,
|
||||
Char(CCode), " $classname_", $4.id, ";\n",0);
|
||||
n->name = copy_string($4.id);
|
||||
n->line = start_line;
|
||||
n->type = new DataType;
|
||||
|
|
@ -2906,10 +2914,10 @@ objc_inherit : COLON ID objc_protolist { $$ = $2;}
|
|||
|
||||
|
||||
objc_protolist : LESSTHAN { skip_template();
|
||||
CCode.strip(); // Strip whitespace
|
||||
/* CCode.strip(); // Strip whitespace
|
||||
CCode.replace("<","< ");
|
||||
CCode.replace(">"," >");
|
||||
$$ = CCode.get();
|
||||
CCode.replace(">"," >"); */
|
||||
$$ = Char(CCode);
|
||||
}
|
||||
| empty {
|
||||
$$ = (char*)"";
|
||||
|
|
@ -2979,7 +2987,7 @@ objc_var : type declaration {
|
|||
Active_type = new DataType($1);
|
||||
$1->is_pointer += $2.is_pointer;
|
||||
$1->is_reference = $2.is_reference;
|
||||
$1->arraystr = copy_string(ArrayString.get());
|
||||
$1->arraystr = copy_string(Char(ArrayString));
|
||||
if ($1->status & STAT_READONLY) {
|
||||
if (!(tm = typemap_lookup((char*)"memberin",typemap_lang,$1,$2.id,(char*)"",(char*)"")))
|
||||
Status = Status | STAT_READONLY;
|
||||
|
|
@ -3024,7 +3032,7 @@ objc_vartail : COMMA declaration objc_vartail {
|
|||
DataType *t = new DataType (Active_type);
|
||||
t->is_pointer += $2.is_pointer;
|
||||
t->is_reference = $2.is_reference;
|
||||
t->arraystr = copy_string(ArrayString.get());
|
||||
t->arraystr = copy_string(Char(ArrayString));
|
||||
if (t->status & STAT_READONLY) {
|
||||
if (!(tm = typemap_lookup((char*)"memberin",typemap_lang,t,$2.id,(char*)"",(char*)"")))
|
||||
Status = Status | STAT_READONLY;
|
||||
|
|
@ -3222,7 +3230,7 @@ tm_tail : COMMA typemap_parm tm_tail {
|
|||
typemap_parm : type typemap_name {
|
||||
if (InArray) {
|
||||
$1->is_pointer++;
|
||||
$1->arraystr = copy_string(ArrayString.get());
|
||||
$1->arraystr = copy_string(Char(ArrayString));
|
||||
}
|
||||
$$ = new TMParm;
|
||||
$$->p = new Parm($1,$2);
|
||||
|
|
@ -3239,7 +3247,7 @@ typemap_parm : type typemap_name {
|
|||
$$->p->call_type = 0;
|
||||
if (InArray) {
|
||||
$$->p->t->is_pointer++;
|
||||
$$->p->t->arraystr = copy_string(ArrayString.get());
|
||||
$$->p->t->arraystr = copy_string(Char(ArrayString));
|
||||
}
|
||||
$$->args = tm_parm;
|
||||
delete $1;
|
||||
|
|
@ -3279,23 +3287,23 @@ typemap_name : ID typemap_args {
|
|||
InArray = 0;
|
||||
}
|
||||
| ID array {
|
||||
ArrayBackup = "";
|
||||
ArrayBackup << ArrayString;
|
||||
ArrayBackup = Copy(ArrayString);
|
||||
} typemap_args {
|
||||
$$ = $1;
|
||||
InArray = $2;
|
||||
ArrayString = "";
|
||||
ArrayString << ArrayBackup;
|
||||
Clear(ArrayString);
|
||||
Append(ArrayString,ArrayBackup);
|
||||
Delete(ArrayBackup);
|
||||
}
|
||||
| array {
|
||||
ArrayBackup = "";
|
||||
ArrayBackup << ArrayString;
|
||||
ArrayBackup = Copy(ArrayString);
|
||||
} typemap_args {
|
||||
$$ = new char[1];
|
||||
$$[0] = 0;
|
||||
InArray = $1;
|
||||
ArrayString = "";
|
||||
ArrayString << ArrayBackup;
|
||||
Clear(ArrayString);
|
||||
Append(ArrayString,ArrayBackup);
|
||||
Delete(ArrayBackup);
|
||||
}
|
||||
| typemap_args { $$ = new char[1];
|
||||
$$[0] = 0;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ static char cvsroot[] = "$Header$";
|
|||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
extern "C" {
|
||||
#include "doh.h"
|
||||
}
|
||||
|
||||
#define YYBSIZE 8192
|
||||
|
||||
struct InFile {
|
||||
|
|
@ -44,9 +48,9 @@ InFile *in_head;
|
|||
|
||||
FILE *LEX_in = NULL;
|
||||
|
||||
static String header;
|
||||
static String comment;
|
||||
String CCode; // String containing C code
|
||||
static DOHString *header = 0;
|
||||
static DOHString *comment = 0;
|
||||
DOHString *CCode = 0; // String containing C code
|
||||
static char *yybuffer;
|
||||
static int lex_pos = 0;
|
||||
static int lex_len = 0;
|
||||
|
|
@ -83,6 +87,9 @@ void scanner_init() {
|
|||
|
||||
yybuffer = (char *) malloc(YYBSIZE);
|
||||
scan_init = 1;
|
||||
header = NewString("");
|
||||
comment = NewString("");
|
||||
CCode = NewString("");
|
||||
}
|
||||
|
||||
/**************************************************************
|
||||
|
|
@ -299,7 +306,8 @@ void yycomment(char *, int, int) {
|
|||
void skip_brace(void) {
|
||||
|
||||
char c;
|
||||
CCode = "{";
|
||||
Clear(CCode);
|
||||
Putc('{',CCode);
|
||||
while (num_brace > last_brace) {
|
||||
if ((c = nextchar()) == 0) {
|
||||
fprintf(stderr,"%s : Line %d. Missing '}'. Reached end of input.\n",
|
||||
|
|
@ -307,7 +315,7 @@ void skip_brace(void) {
|
|||
FatalError();
|
||||
return;
|
||||
}
|
||||
CCode << c;
|
||||
Putc(c,CCode);
|
||||
if (c == '{') num_brace++;
|
||||
if (c == '}') num_brace--;
|
||||
yylen = 0;
|
||||
|
|
@ -328,7 +336,8 @@ void skip_brace(void) {
|
|||
void skip_template(void) {
|
||||
|
||||
char c;
|
||||
CCode = "<";
|
||||
Clear(CCode);
|
||||
Putc('<',CCode);
|
||||
int num_lt = 1;
|
||||
while (num_lt > 0) {
|
||||
if ((c = nextchar()) == 0) {
|
||||
|
|
@ -337,7 +346,7 @@ void skip_template(void) {
|
|||
FatalError();
|
||||
return;
|
||||
}
|
||||
CCode << c;
|
||||
Putc(c,CCode);
|
||||
if (c == '<') num_lt++;
|
||||
if (c == '>') num_lt--;
|
||||
yylen = 0;
|
||||
|
|
@ -689,12 +698,14 @@ int yylook(void) {
|
|||
if (c == '/') {
|
||||
comment_start = line_number;
|
||||
column_start = column;
|
||||
comment = " ";
|
||||
Clear(comment);
|
||||
Printf(comment," ");
|
||||
state = 10; // C++ style comment
|
||||
} else if (c == '*') {
|
||||
comment_start = line_number;
|
||||
column_start = column;
|
||||
comment = " ";
|
||||
Clear(comment);
|
||||
Printf(comment," ");
|
||||
state = 11; // C style comment
|
||||
} else {
|
||||
retract(1);
|
||||
|
|
@ -708,9 +719,9 @@ int yylook(void) {
|
|||
return 0;
|
||||
}
|
||||
if (c == '\n') {
|
||||
comment << c;
|
||||
Putc(c,comment);
|
||||
// Add the comment to documentation
|
||||
yycomment(comment.get(),comment_start, column_start);
|
||||
yycomment(Char(comment),comment_start, column_start);
|
||||
yylen = 0;
|
||||
state = 0;
|
||||
if (in_define == 1) {
|
||||
|
|
@ -719,7 +730,7 @@ int yylook(void) {
|
|||
}
|
||||
} else {
|
||||
state = 10;
|
||||
comment << c;
|
||||
Putc(c,comment);
|
||||
yylen = 0;
|
||||
}
|
||||
break;
|
||||
|
|
@ -732,7 +743,7 @@ int yylook(void) {
|
|||
if (c == '*') {
|
||||
state = 12;
|
||||
} else {
|
||||
comment << c;
|
||||
Putc(c,comment);
|
||||
yylen = 0;
|
||||
state = 11;
|
||||
}
|
||||
|
|
@ -744,15 +755,16 @@ int yylook(void) {
|
|||
return 0;
|
||||
}
|
||||
if (c == '*') {
|
||||
comment << c;
|
||||
Putc(c,comment);
|
||||
state = 12;
|
||||
} else if (c == '/') {
|
||||
comment << " \n";
|
||||
yycomment(comment.get(),comment_start,column_start);
|
||||
Printf(comment," \n");
|
||||
yycomment(Char(comment),comment_start,column_start);
|
||||
yylen = 0;
|
||||
state = 0;
|
||||
} else {
|
||||
comment << '*' << c;
|
||||
Putc('*',comment);
|
||||
Putc(c,comment);
|
||||
yylen = 0;
|
||||
state = 11;
|
||||
}
|
||||
|
|
@ -794,7 +806,7 @@ int yylook(void) {
|
|||
if (( c= nextchar()) == 0) return 0;
|
||||
if (c == '{') {
|
||||
state = 40; /* Include block */
|
||||
header = "";
|
||||
Clear(header);
|
||||
start_line = line_number;
|
||||
}
|
||||
else if ((isalpha(c)) || (c == '_')) state = 7;
|
||||
|
|
@ -813,7 +825,7 @@ int yylook(void) {
|
|||
yylen = 0;
|
||||
if (c == '%') state = 41;
|
||||
else {
|
||||
header << c;
|
||||
Putc(c,header);
|
||||
yylen = 0;
|
||||
state = 40;
|
||||
}
|
||||
|
|
@ -825,11 +837,11 @@ int yylook(void) {
|
|||
return 0;
|
||||
}
|
||||
if (c == '}') {
|
||||
yylval.id = header.get();
|
||||
yylval.id = Char(header);
|
||||
return(HBLOCK);
|
||||
} else {
|
||||
header << '%';
|
||||
header << c;
|
||||
Putc('%',header);
|
||||
Putc(c,header);
|
||||
yylen = 0;
|
||||
state = 40;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ public:
|
|||
String(const char *s);
|
||||
~String();
|
||||
char *get() const;
|
||||
void *doh() { return str; }
|
||||
friend String& operator<<(String&,const char *s);
|
||||
friend String& operator<<(String&,const int);
|
||||
friend String& operator<<(String&,const char);
|
||||
|
|
@ -232,10 +233,9 @@ public:
|
|||
|
||||
Parm *get_first(); // Get first 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 sub_parmnames(String &s); // Remaps real parameter names in code fragment
|
||||
};
|
||||
|
||||
// Modes for different types of inheritance
|
||||
|
|
@ -452,7 +452,11 @@ public:
|
|||
String locals;
|
||||
String code;
|
||||
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 add_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 {
|
||||
char *lang;
|
||||
DataType *type;
|
||||
String code;
|
||||
DOHString *code;
|
||||
int first;
|
||||
int last;
|
||||
TypeMap *next;
|
||||
TypeMap *previous; // Previously defined typemap (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) {
|
||||
lang = copy_string(l);
|
||||
type = new DataType(t);
|
||||
code << c;
|
||||
code = NewString(c);
|
||||
first = type_id;
|
||||
last = INT_MAX;
|
||||
next = 0;
|
||||
|
|
@ -106,7 +92,7 @@ struct TypeMap {
|
|||
TypeMap(char *l, char *c) {
|
||||
lang = copy_string(l);
|
||||
type = 0;
|
||||
code << c;
|
||||
code = NewString(c);
|
||||
first = type_id;
|
||||
last = INT_MAX;
|
||||
next = 0;
|
||||
|
|
@ -116,7 +102,7 @@ struct TypeMap {
|
|||
TypeMap(TypeMap *t) {
|
||||
lang = copy_string(t->lang);
|
||||
type = new DataType(t->type);
|
||||
code << t->code;
|
||||
code = Copy(t->code);
|
||||
first = type_id;
|
||||
last = INT_MAX;
|
||||
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 String str;
|
||||
static DOHString *str = 0;
|
||||
|
||||
int old_status;
|
||||
if (!str) str = NewString("");
|
||||
old_status = type->status;
|
||||
type->status = 0;
|
||||
str = "";
|
||||
Clear(str);
|
||||
|
||||
if (ary)
|
||||
str << lang << type->print_type() << pname << ary << suffix;
|
||||
Printv(str, lang, type->print_type(), pname, ary, suffix, 0);
|
||||
else
|
||||
str << lang << type->print_type() << pname << suffix;
|
||||
Printv(str, lang, type->print_type(), pname, suffix,0);
|
||||
|
||||
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) {
|
||||
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
|
||||
|
|
@ -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
|
||||
// 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.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
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 *key;
|
||||
int ndim,i,j,k,n;
|
||||
|
|
@ -437,23 +424,22 @@ TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname,
|
|||
|
||||
if (!tm) {
|
||||
// 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
|
||||
j = (1 << ndim) - 1; // Status bits
|
||||
for (i = 0; i < (1 << ndim); i++) {
|
||||
// Form an array string
|
||||
tempastr = "";
|
||||
Clear(tempastr);
|
||||
k = j;
|
||||
for (n = 0; n < ndim; n++) {
|
||||
if (k & 1) {
|
||||
tempastr << "[" << type->get_dimension(n) << "]";
|
||||
Printf(tempastr,"[%s]",type->get_dimension(n));
|
||||
} else {
|
||||
tempastr << "[ANY]";
|
||||
Printf(tempastr,"[ANY]");
|
||||
}
|
||||
k = k >> 1;
|
||||
}
|
||||
// printf("checking (%s) : %s\n",origarr,tempastr.get());
|
||||
type->arraystr = tempastr.get();
|
||||
type->arraystr = Char(tempastr);
|
||||
key = typemap_string(lang,type,pname,type->arraystr,op);
|
||||
tm = typemap_search(key,type->id);
|
||||
if (!tm) {
|
||||
|
|
@ -461,19 +447,23 @@ TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname,
|
|||
tm = typemap_search(key,type->id);
|
||||
}
|
||||
type->arraystr = origarr;
|
||||
if (tm) break;
|
||||
if (tm) {
|
||||
Delete(tempastr);
|
||||
break;
|
||||
}
|
||||
j--;
|
||||
}
|
||||
Delete(tempastr);
|
||||
}
|
||||
|
||||
if (tm) {
|
||||
str << tm->code;
|
||||
Printf(str,"%s",tm->code);
|
||||
ndim = type->array_dimensions();
|
||||
sprintf(temp,"%d",ndim);
|
||||
str.replace("$ndim",temp);
|
||||
Replace(str,"$ndim",temp, DOH_REPLACE_ANY);
|
||||
for (i = 0; i < ndim; 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;
|
||||
|
|
@ -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.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
char *new_name;
|
||||
|
||||
|
|
@ -496,9 +486,10 @@ static void typemap_locals(DataType *t, char *pname, String &s, ParmList *l, Wra
|
|||
while (p) {
|
||||
if (p->name) {
|
||||
if (strlen(p->name) > 0) {
|
||||
String str;
|
||||
DOHString *str;
|
||||
DataType *tt;
|
||||
|
||||
str = NewString("");
|
||||
// If the user gave us $type as the name of the local variable, we'll use
|
||||
// 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
|
||||
if (tt->arraystr) {
|
||||
tt->is_pointer--;
|
||||
str << p->name << tt->arraystr;
|
||||
Printf(str,"%s%s",p->name, tt->arraystr);
|
||||
}
|
||||
else {
|
||||
str << p->name;
|
||||
Printf(str,"%s",p->name);
|
||||
}
|
||||
|
||||
// Substitute parameter names
|
||||
str.replace("$arg",pname);
|
||||
Replace(str,"$arg",pname, DOH_REPLACE_ANY);
|
||||
if (strcmp(p->t->name,"$basetype")==0) {
|
||||
// use $basetype
|
||||
char temp_ip = tt->is_pointer;
|
||||
char temp_ip1 = tt->implicit_ptr;
|
||||
tt->is_pointer = 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->implicit_ptr = temp_ip1;
|
||||
}
|
||||
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++;
|
||||
// Substitute
|
||||
s.replaceid(p->name,new_name);
|
||||
Replace(s,p->name,new_name,DOH_REPLACE_ID);
|
||||
}
|
||||
}
|
||||
p = l->get_next();
|
||||
|
|
@ -546,7 +537,7 @@ static void typemap_locals(DataType *t, char *pname, String &s, ParmList *l, Wra
|
|||
char temp[10];
|
||||
for (int i = 0; i < t->array_dimensions(); 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 *target, WrapperFunction *f) {
|
||||
static String str;
|
||||
static DOHString *str = 0;
|
||||
char *key = 0;
|
||||
TypeMap *tm = 0;
|
||||
|
||||
if (!str) str = NewString("");
|
||||
if (!lang) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// First check for named array
|
||||
str = "";
|
||||
Clear(str);
|
||||
tm = typemap_search_array(op,lang,type,pname,str);
|
||||
|
||||
// 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);
|
||||
tm = typemap_search(key,type->id);
|
||||
if (tm)
|
||||
str << tm->code;
|
||||
Printf(str,"%s",tm->code);
|
||||
}
|
||||
|
||||
// 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);
|
||||
tm = typemap_search(key,type->id);
|
||||
if (tm)
|
||||
str << tm->code;
|
||||
Printf(str,"%s", tm->code);
|
||||
}
|
||||
if (!tm) return 0;
|
||||
|
||||
// Now perform character replacements
|
||||
|
||||
str.replace("$source",source);
|
||||
str.replace("$target",target);
|
||||
str.replace("$type", realtype->print_type());
|
||||
Replace(str,"$source",source,DOH_REPLACE_ANY);
|
||||
Replace(str,"$target",target,DOH_REPLACE_ANY);
|
||||
Replace(str,"$type",realtype->print_type(),DOH_REPLACE_ANY);
|
||||
if (realname) {
|
||||
str.replace("$parmname", realname);
|
||||
Replace(str,"$parmname",realname,DOH_REPLACE_ANY);
|
||||
} else {
|
||||
str.replace("$parmname","");
|
||||
Replace(str,"$parmname","", DOH_REPLACE_ANY);
|
||||
}
|
||||
// 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();
|
||||
if (bt[strlen(bt)-1] == ' ')
|
||||
bt[strlen(bt)-1] = 0;
|
||||
str.replace("$basetype",bt);
|
||||
str.replace("$basemangle",realtype->print_mangle());
|
||||
Replace(str,"$basetype",bt,DOH_REPLACE_ANY);
|
||||
Replace(str,"$basemangle",realtype->print_mangle(), DOH_REPLACE_ANY);
|
||||
realtype->is_pointer = temp_ip;
|
||||
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 ((tm->args) && f) {
|
||||
|
|
@ -661,7 +653,7 @@ char *typemap_lookup_internal(char *op, char *lang, DataType *type, char *pname,
|
|||
|
||||
// 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;
|
||||
while (m) {
|
||||
char *oldary = 0;
|
||||
static String newarray;
|
||||
static DOHString *newarray = 0;
|
||||
if (!newarray) newarray = NewString("");
|
||||
if (*(m->name)) ppname = m->name;
|
||||
else ppname = pname;
|
||||
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)) {
|
||||
// Build up the new array string
|
||||
newarray = "";
|
||||
Clear(newarray);
|
||||
for (int n = 0; n < m->type->array_dimensions(); n++) {
|
||||
char *d = m->type->get_dimension(n);
|
||||
if (strcmp(d,"ANY") == 0) {
|
||||
newarray << "[" << type->get_dimension(n) << "]";
|
||||
Printf(newarray,"[%s]", type->get_dimension(n));
|
||||
} else {
|
||||
newarray << "[" << d << "]";
|
||||
Printf(newarray,"[%s]", d);
|
||||
}
|
||||
}
|
||||
m->type->arraystr = newarray.get();
|
||||
m->type->arraystr = Char(newarray);
|
||||
} else if (type->arraystr) {
|
||||
// If an array string is available for the current datatype,
|
||||
// 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) {
|
||||
static String str;
|
||||
static DOHString *str = 0;
|
||||
char *key = 0;
|
||||
TypeMap *tm = 0;
|
||||
|
||||
if (!str) str = NewString("");
|
||||
if (!lang) {
|
||||
return 0;
|
||||
}
|
||||
// First check for named array
|
||||
str = "";
|
||||
|
||||
Clear(str);
|
||||
tm = typemap_search_array(op,lang,type,pname,str);
|
||||
|
||||
// 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;
|
||||
|
||||
str = "";
|
||||
str << tm->code;
|
||||
Clear(str);
|
||||
Printf(str,"%s",tm->code);
|
||||
|
||||
// Return character string
|
||||
|
||||
return str.get();
|
||||
Char(str);
|
||||
}
|
||||
|
||||
// Function for checking with applications
|
||||
|
|
@ -865,7 +859,8 @@ char *typemap_check(char *op, char *lang, DataType *type, char *pname) {
|
|||
m = m->next;
|
||||
while (m) {
|
||||
char *oldary = 0;
|
||||
static String newarray;
|
||||
static DOHString *newarray = 0;
|
||||
if (!newarray) newarray = NewString("");
|
||||
if (*(m->name)) ppname = m->name;
|
||||
else ppname = pname;
|
||||
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)) {
|
||||
// Build up the new array string
|
||||
newarray = "";
|
||||
Clear(newarray);
|
||||
for (int n = 0; n < m->type->array_dimensions(); n++) {
|
||||
char *d = m->type->get_dimension(n);
|
||||
if (strcmp(d,"ANY") == 0) {
|
||||
newarray << "[" << type->get_dimension(n) << "]";
|
||||
Printf(newarray,"[%s]", type->get_dimension(n));
|
||||
} else {
|
||||
newarray << "[" << d << "]";
|
||||
Printf(newarray,"[%s]", d);
|
||||
}
|
||||
}
|
||||
oldary = m->type->arraystr;
|
||||
m->type->arraystr = newarray.get();
|
||||
m->type->arraystr = Char(newarray);
|
||||
} else if (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);
|
||||
}
|
||||
} 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 String str;
|
||||
|
||||
str = "";
|
||||
|
||||
str << "fragment:" << lang << op;
|
||||
return str.get();
|
||||
static char str[512];
|
||||
sprintf(str,"fragment:%s%s", lang, op);
|
||||
return str;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
|
@ -1027,7 +1019,7 @@ void fragment_register(char *op, char *lang, char *code) {
|
|||
|
||||
sprintf(temp,"$%s",op);
|
||||
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_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)
|
||||
sprintf(temp,"$%s",op);
|
||||
tm->code.replace(temp,"");
|
||||
Replace(tm->code,temp,"", DOH_REPLACE_ANY);
|
||||
|
||||
// Add new typemap to the hash table
|
||||
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) {
|
||||
static String str;
|
||||
static DOHString *str = 0;
|
||||
char *key = 0;
|
||||
TypeMap *tm = 0;
|
||||
|
||||
|
||||
if (!str) str = NewString("");
|
||||
if (!lang) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
str = "";
|
||||
Clear(str);
|
||||
key = fragment_string(op,lang);
|
||||
tm = typemap_search(key,age);
|
||||
|
||||
if (!tm) return 0;
|
||||
|
||||
str << tm->code;
|
||||
return str.get();
|
||||
Append(str,tm->code);
|
||||
return Char(str);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -432,7 +432,7 @@ char *DataType::get_array() {
|
|||
// --------------------------------------------------------------------
|
||||
|
||||
static DOHHash *typedef_hash[MAXSCOPE];
|
||||
static int scope = 0; // Current scope
|
||||
static int scope = 0; // Current scope
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// void DataType::init_typedef()
|
||||
|
|
@ -464,7 +464,7 @@ void DataType::init_typedef() {
|
|||
// --------------------------------------------------------------------
|
||||
|
||||
void DataType::typedef_add(char *tname, int mode) {
|
||||
char *name1, *name2;
|
||||
char *name1, *name2;
|
||||
DataType *nt, t1;
|
||||
void typeeq_addtypedef(char *name, char *eqname, DataType *);
|
||||
|
||||
|
|
@ -708,11 +708,10 @@ void *DataType::collapse_scope(char *prefix) {
|
|||
while (key) {
|
||||
t = (DataType *) GetVoid(typedef_hash[scope],key);
|
||||
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));
|
||||
// printf("creating %s\n", temp);
|
||||
SetVoid(typedef_hash[scope-1],temp, (void *)nt);
|
||||
delete temp;
|
||||
delete [] temp;
|
||||
key = Nextkey(typedef_hash[scope]);
|
||||
}
|
||||
}
|
||||
|
|
@ -860,15 +859,18 @@ void emit_ptr_equivalence(FILE *f) {
|
|||
EqEntry *e1,*e2;
|
||||
DOH *k;
|
||||
void typeeq_standard();
|
||||
String ttable;
|
||||
DOHString *ttable;
|
||||
|
||||
if (!te_init) typeeq_init();
|
||||
|
||||
ttable << "\
|
||||
ttable = NewString("");
|
||||
|
||||
Printv(ttable,"\
|
||||
/*\n\
|
||||
* This table is used by the pointer type-checker\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);
|
||||
while (k) {
|
||||
|
|
@ -877,47 +879,26 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
|
|||
// Walk through the equivalency list
|
||||
while (e2) {
|
||||
if (e2->cast)
|
||||
ttable << tab4 << "{ \"" << e1->name << "\",\"" << e2->name << "\"," << e2->cast << "},\n";
|
||||
Printv(ttable,
|
||||
tab4, "{ \"", e1->name, "\",\"", e2->name, "\"," , e2->cast , "},\n",
|
||||
0);
|
||||
else
|
||||
ttable << tab4 << "{ \"" << e1->name << "\",\"" << e2->name << "\",0},\n";
|
||||
Printv(ttable,
|
||||
tab4, "{ \"", e1->name, "\",\"", e2->name, "\",0},\n",
|
||||
0);
|
||||
|
||||
e2 = e2->next;
|
||||
}
|
||||
k = Nextkey(typeeq_hash);
|
||||
}
|
||||
ttable << "{0,0,0}};\n";
|
||||
fprintf(f_wrappers,"%s\n", ttable.get());
|
||||
Printf(ttable,"{0,0,0}};\n");
|
||||
fprintf(f_wrappers,"%s\n", Char(ttable));
|
||||
fprintf(f,"{\n");
|
||||
fprintf(f," int 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,"}\n");
|
||||
|
||||
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());
|
||||
Delete(ttable);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
|
@ -995,43 +976,45 @@ void typeeq_standard(void) {
|
|||
static char *
|
||||
check_equivalent(DataType *t) {
|
||||
EqEntry *e1, *e2;
|
||||
static String out;
|
||||
static DOHString *out = 0;
|
||||
int npointer = t->is_pointer;
|
||||
String m;
|
||||
DOH *k;
|
||||
char *m;
|
||||
DOHString *k;
|
||||
|
||||
if (!out) out = NewString("");
|
||||
Clear(out);
|
||||
|
||||
out = "";
|
||||
while (t->is_pointer >= t->implicit_ptr) {
|
||||
m = t->print_mangle();
|
||||
m = copy_string(t->print_mangle());
|
||||
|
||||
if (!te_init) typeeq_init();
|
||||
|
||||
k = Firstkey(typeeq_hash);
|
||||
while (k) {
|
||||
e1 = (EqEntry *) GetVoid(typeeq_hash,k);
|
||||
/* printf("'%s', '%s'\n", m.get(),e1->name); */
|
||||
if (strcmp(m.get(),e1->name) == 0) {
|
||||
if (strcmp(m,e1->name) == 0) {
|
||||
e2 = e1->next;
|
||||
while (e2) {
|
||||
if (e2->type) {
|
||||
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);
|
||||
if (e2->cast)
|
||||
out << e2->cast << "}, ";
|
||||
Printf(out,"%s}, ", e2->cast);
|
||||
else
|
||||
out << "0}, ";
|
||||
Printf(out,"0}, ");
|
||||
}
|
||||
e2 = e2->next;
|
||||
}
|
||||
}
|
||||
k = Nextkey(typeeq_hash);
|
||||
}
|
||||
delete [] m;
|
||||
t->is_pointer--;
|
||||
}
|
||||
t->is_pointer = npointer;
|
||||
out << "{0}";
|
||||
return out.get();
|
||||
Printf(out,"{0}");
|
||||
return Char(out);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -1093,29 +1076,33 @@ void DataType::remember() {
|
|||
void
|
||||
emit_type_table() {
|
||||
DOH *key;
|
||||
String types, table;
|
||||
DOHString *types, *table;
|
||||
int i = 0;
|
||||
|
||||
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);
|
||||
fprintf(f_runtime,"/* ---- TYPES TABLE (BEGIN) ---- */\n");
|
||||
while (key) {
|
||||
fprintf(f_runtime,"#define SWIGTYPE%s _swig_types[%d] \n", Char(key), i);
|
||||
types << "static _swig_type_info _swigt_" << Char(key) << "[] = {";
|
||||
types << "{\"" << Char(key) << "\",0},";
|
||||
types << "{\"" << Char(key) << "\",0},";
|
||||
types << check_equivalent((DataType *)GetVoid(remembered,key)) << "};\n";
|
||||
table << "_swigt_" << Char(key) << ", \n";
|
||||
Printv(types,"static _swig_type_info _swigt_", Char(key), "[] = {", 0);
|
||||
Printv(types,"{\"", Char(key), "\",0},", 0);
|
||||
Printv(types, "{\"", Char(key), "\",0},", 0);
|
||||
Printv(types, check_equivalent((DataType *)GetVoid(remembered,key)), "};\n", 0);
|
||||
Printv(table, "_swigt_", Char(key), ", \n", 0);
|
||||
key = Nextkey(remembered);
|
||||
i++;
|
||||
}
|
||||
|
||||
table << "0\n};\n";
|
||||
fprintf(f_wrappers,"%s\n", types.get());
|
||||
fprintf(f_wrappers,"%s\n", table.get());
|
||||
Printf(table, "0\n};\n");
|
||||
fprintf(f_wrappers,"%s\n", Char(types));
|
||||
fprintf(f_wrappers,"%s\n", Char(table));
|
||||
fprintf(f_runtime,"static _swig_type_info *_swig_types[%d];\n", i+1);
|
||||
fprintf(f_runtime,"/* ---- TYPES TABLE (END) ---- */\n\n");
|
||||
Delete(types);
|
||||
Delete(table);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ extern "C" {
|
|||
WrapperFunction::WrapperFunction() {
|
||||
h = NewHash();
|
||||
localh = NewHash();
|
||||
_def = def.doh();
|
||||
_locals = locals.doh();
|
||||
_code = code.doh();
|
||||
_init = init.doh();
|
||||
}
|
||||
|
||||
WrapperFunction::~WrapperFunction() {
|
||||
|
|
@ -47,38 +51,38 @@ WrapperFunction::~WrapperFunction() {
|
|||
// 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 String s;
|
||||
s = "";
|
||||
static char s[512];
|
||||
char *c = s;
|
||||
|
||||
while ((*tname) && (isalnum(*tname) || (*tname == '_') || (*tname == '$') || (*tname == ' ') || (*tname == ':'))) {
|
||||
s << *tname;
|
||||
*(c++) = *tname;
|
||||
tname++;
|
||||
}
|
||||
type_ext = "";
|
||||
type_ext = tname;
|
||||
return s.get();
|
||||
*c = 0;
|
||||
strcpy(type_ext,tname);
|
||||
return s;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Print out a wrapper function.
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
void WrapperFunction::print(FILE *f) {
|
||||
String *s;
|
||||
void WrapperFunction::print(DOHFile *f) {
|
||||
DOHString *s;
|
||||
DOH *key;
|
||||
|
||||
key = Firstkey(localh);
|
||||
while (key) {
|
||||
s = (String *) GetVoid(localh,key);
|
||||
char *c = s->get();
|
||||
c[strlen(c)-1] = 0;
|
||||
locals << tab4 << c << ";\n";
|
||||
s = Getattr(localh,key);
|
||||
Delitem(s,DOH_END);
|
||||
Printv(_locals,tab4,s,";\n",0);
|
||||
key = Nextkey(localh);
|
||||
}
|
||||
fprintf(f,"%s\n",def.get());
|
||||
fprintf(f,"%s",locals.get());
|
||||
fprintf(f,"%s\n",code.get());
|
||||
Printf(f,"%s\n",_def);
|
||||
Printf(f,"%s",_locals);
|
||||
Printf(f,"%s\n",_code);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
|
@ -86,14 +90,13 @@ void WrapperFunction::print(FILE *f) {
|
|||
// -------------------------------------------------------------------
|
||||
|
||||
void WrapperFunction::print(String &f) {
|
||||
String *s;
|
||||
DOHString *s;
|
||||
DOH *key;
|
||||
key = Firstkey(localh);
|
||||
while (key) {
|
||||
s = (String *) GetVoid(localh,key);
|
||||
char *c = s->get();
|
||||
c[strlen(c)-1] = 0;
|
||||
locals << tab4 << c << ";\n";
|
||||
s = Getattr(localh,key);
|
||||
Delitem(s,DOH_END);
|
||||
Printv(_locals,tab4,s,";\n",0);
|
||||
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
|
||||
|
||||
char *tname = isolate_type_name(type);
|
||||
String *lstr = (String *) GetVoid(localh,tname);
|
||||
DOHString *lstr = Getattr(localh,tname);
|
||||
if (!lstr) {
|
||||
lstr = new String;
|
||||
*(lstr) << tname << " ";
|
||||
SetVoid(localh,tname,lstr);
|
||||
lstr = NewStringf("%s ", tname);
|
||||
Setattr(localh,tname,lstr);
|
||||
}
|
||||
|
||||
// Successful, write some wrapper code
|
||||
|
||||
if (!defarg) {
|
||||
*(lstr) << type_ext << name << ",";
|
||||
// locals << tab4 << type << " " << name << ";\n";
|
||||
Printv(lstr,type_ext,name,",",0);
|
||||
} else {
|
||||
*(lstr) << type_ext << name << "=" << defarg << ",";
|
||||
// locals << tab4 << type << " " << name << " = " << defarg << ";\n";
|
||||
Printv(lstr,type_ext,name, "=", defarg, ",", 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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 *new_type;
|
||||
static String new_name;
|
||||
static DOHString *new_name = 0;
|
||||
char *c;
|
||||
new_type = new char[strlen(type)+1];
|
||||
|
||||
if (!new_name) new_name = NewString("");
|
||||
strcpy(new_type,type);
|
||||
new_name = "";
|
||||
Clear(new_name);
|
||||
c = name;
|
||||
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
|
||||
new_name << *c;
|
||||
Putc(*c,new_name);
|
||||
|
||||
// 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
|
||||
int i = 0;
|
||||
new_name = "";
|
||||
Clear(new_name);
|
||||
// This is a little funky. We copy characters until we reach a nonvalid
|
||||
// identifier symbol, add a number, then append the rest. This is
|
||||
// needed to properly handle arrays.
|
||||
c = name;
|
||||
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
|
||||
new_name << *c;
|
||||
new_name << i;
|
||||
while (Getattr(h,new_name.get())) {
|
||||
Putc(*c,new_name);
|
||||
Printf(new_name,"%d",i);
|
||||
while (Getattr(h,new_name)) {
|
||||
i++;
|
||||
c = name;
|
||||
new_name = "";
|
||||
Clear(new_name);
|
||||
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
|
||||
new_name << *c;
|
||||
new_name << i;
|
||||
Putc(*c,new_name);
|
||||
Printf(new_name,"%d",i);
|
||||
}
|
||||
Setattr(h,new_name.get(),new_type);
|
||||
Setattr(h,new_name,new_type);
|
||||
} 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
|
||||
if (!defarg)
|
||||
locals << tab4 << type << " " << new_name << ";\n";
|
||||
Printv(_locals,tab4,type, " ", new_name, ";\n");
|
||||
else
|
||||
locals << tab4 << type << " " << new_name << " = " << defarg << ";\n";
|
||||
Printv(_locals,tab4,type, " ", new_name, " = ", defarg, ";\n");
|
||||
|
||||
// Need to strip off the array symbols now
|
||||
|
||||
c = new_name.get();
|
||||
c = Char(new_name);
|
||||
while ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c))
|
||||
c++;
|
||||
*c = 0;
|
||||
return new_name.get();
|
||||
return Char(new_name);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue