A bunch of cleanup

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@206 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-02-10 04:22:50 +00:00
commit e9cd55b7b8
6 changed files with 61 additions and 117 deletions

View file

@ -311,8 +311,6 @@ public:
} else {
lang->cpp_member_func(name, iname, t, l);
}
l->check_defined();
t->check_defined();
delete l;
delete t;
}
@ -361,7 +359,6 @@ public:
l = new ParmList(parms);
update_parms(l);
lang->cpp_constructor(name,iname,l);
l->check_defined();
delete l;
} else {
if (Verbose) {
@ -464,7 +461,6 @@ public:
} else {
lang->cpp_static_var(name,iname,t);
}
t->check_defined();
Status = old_status;
delete t;
}
@ -526,7 +522,6 @@ public:
input_file = file;
ccode = code;
lang->cpp_declare_const(name,iname,type,value);
type->check_defined();
}
void inherit(int mode) {
@ -560,7 +555,7 @@ public:
int line; // Line number
char **baseclass; // Base classes (if any)
Hash *local; // Hash table for local types
Hash *scope; // Local scope hash table
void *scope; // Local scope hash table
DocEntry *de; // Documentation entry of class
CPP_member *members; // Linked list of members
CPP_class *next; // Next class
@ -1089,6 +1084,7 @@ void cplus_generate_types(char **baseclass) {
} else {
typeeq_derived(bc->classname, current_class->classname,temp3.get());
}
DataType::record_base(current_class->classname, bc->classname);
// Now traverse the hierarchy some more
cplus_generate_types(bc->baseclass);
}
@ -2599,7 +2595,7 @@ void cplus_register_type(char *tname) {
};
// -----------------------------------------------------------------------------
// void cplus_register_scope(Hash *h)
// void cplus_register_scope(void *h)
//
// Saves the scope associated with a particular class. It will be needed
// later if anything inherits from us.
@ -2611,7 +2607,7 @@ void cplus_register_type(char *tname) {
// Side Effects : Saves h with current class
// -----------------------------------------------------------------------------
void cplus_register_scope(Hash *h) {
void cplus_register_scope(void *h) {
if (current_class) {
current_class->scope = h;
}

View file

@ -537,11 +537,6 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
if (DocOnly)
remove(fn_runtime);
// Check for undefined types that were used.
if (Verbose)
type_undefined_check();
if (checkout) {
// File was checked out from the SWIG library. Remove it now
remove(input_file);

View file

@ -436,25 +436,6 @@ void ParmList::print_args(FILE *f) {
}
}
// -------------------------------------------------------------------
// int check_defined()
//
// Checks to see if all of the datatypes are defined.
// -------------------------------------------------------------------
int ParmList::check_defined() {
int a = 0;
int i;
for (i = 0; i < nparms; i++) {
if (parms[i]) {
a+=parms[i]->t->check_defined();
}
}
if (a) return 1;
else return 0;
}
// -------------------------------------------------------------------
// void ParmList::sub_parmnames(String &s)
//

View file

@ -129,7 +129,7 @@ extern void cplus_inherit(int, char **);
extern void cplus_cleanup(void);
extern void cplus_static_var(char *, char *, DataType *);
extern void cplus_register_type(char *);
extern void cplus_register_scope(Hash *);
extern void cplus_register_scope(void *);
extern void cplus_inherit_scope(int, char **);
extern void cplus_add_pragma(char *, char *, char *);
extern DocEntry *cplus_set_class(char *);
@ -265,8 +265,6 @@ void create_function(int ext, char *name, DataType *t, ParmList *l) {
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
lang->create_function(name, iname, t, l);
l->check_defined();
t->check_defined();
}
scanner_clear_start();
}
@ -311,7 +309,6 @@ void create_variable(int ext, char *name, DataType *t) {
// Now dump it out
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
lang->link_variable(name, iname, t);
t->check_defined();
Status = oldstatus;
}
scanner_clear_start();
@ -354,7 +351,6 @@ void create_constant(char *name, DataType *type, char *value) {
doc_entry = new DocDecl(name,doc_stack[doc_stack_top]);
lang->declare_const(name, name, type, value);
type->check_defined();
}
}
scanner_clear_start();

View file

@ -165,9 +165,6 @@ public:
#define MAX_NAME 96
class DataType {
private:
static Hash *typedef_hash[MAXSCOPE];
static int scope;
public:
int type; // SWIG Type code
char name[MAX_NAME]; // Name of type
@ -204,14 +201,15 @@ public:
static int is_typedef(char *name); // See if this is a typedef
void typedef_updatestatus(int newstatus); // Change status of a typedef
static void init_typedef(void); // Initialize typedef manager
static void merge_scope(Hash *h); // Functions for managing scoping of datatypes
static void new_scope(Hash *h = 0);
static Hash *collapse_scope(char *);
int check_defined(); // Check to see if type is defined by a typedef.
static void merge_scope(void *h); // Functions for managing scoping of datatypes
static void new_scope(void *h = 0);
static void *collapse_scope(char *);
void remember();
static void record_base(char *derived, char *base);
};
#define STAT_REPLACETYPE 2
#define STAT_VISIT 4
/************************************************************************
* class Parm
@ -278,7 +276,6 @@ public:
void print_types(FILE *f); // Print list of datatypes
void print_types(String &f); // Generate list of datatypes.
void print_args(FILE *f); // Print argument list
int check_defined(); // Checks to make sure the arguments are defined
void sub_parmnames(String &s); // Remaps real parameter names in code fragment
};

View file

@ -173,17 +173,7 @@ void DataType::primitive() {
strcpy(name,"UNKNOWN");
break;
}
// if (is_pointer) {
// if (!((is_pointer == 1) && (type == T_CHAR))) {
// is_pointer = 1;
// strcpy(name,"POINTER");
// }
// }
implicit_ptr = 0; // Gets rid of typedef'd pointers
// Ditch qualifiers (const, volatile, etc...)
if (qualifier) {
delete qualifier;
qualifier = 0;
@ -215,7 +205,6 @@ char *DataType::print_type() {
t = new DataType(this);
t->typedef_replace(); // Upgrade type
}
ri = ri % 8;
result[ri] = "";
result[ri] << t->name << " ";
@ -229,13 +218,11 @@ char *DataType::print_type() {
return result[ri++].get();
}
// --------------------------------------------------------------------
// char *print_full()
//
// Prints full type, with qualifiers.
// --------------------------------------------------------------------
char *DataType::print_full() {
static String result[8];
static int ri = 0;
@ -256,7 +243,6 @@ char *DataType::print_full() {
//
// Prints real type, with qualifiers and arrays if necessary.
// --------------------------------------------------------------------
char *DataType::print_real(char *local) {
static String result[8];
static int ri = 0;
@ -456,37 +442,8 @@ char *DataType::get_array() {
// typedef support. This needs to be scoped.
// --------------------------------------------------------------------
Hash *DataType::typedef_hash[MAXSCOPE];
int DataType::scope = 0; // Current scope
static Hash undefined_types; // Hash table containing undefined datatypes.
// -----------------------------------------------------------------------------
// int DataType::check_defined()
//
// Checks to see if a datatype is defined. If not, returns -1 and puts an entry
// into an internal hash table
// -----------------------------------------------------------------------------
int DataType::check_defined() {
if (type == T_USER) {
// Type might be in typedef hash. Check for that
int s = scope;
while (s >= 0) {
if (typedef_hash[s]->lookup(name)) return 0;
s--;
}
// Nope. Add as an undefined type and continue.
char *st;
st = copy_string(name);
undefined_types.add(st,st);
return -1;
}
return 0;
}
static Hash *typedef_hash[MAXSCOPE];
static int scope = 0; // Current scope
// -----------------------------------------------------------------------------
// void DataType::init_typedef()
@ -558,7 +515,6 @@ void DataType::typedef_add(char *tname, int mode) {
lang->add_typedef(this,tname);
}
// --------------------------------------------------------------------
// void DataType::typedef_resolve(int level = 0)
//
@ -688,9 +644,10 @@ void DataType::typedef_updatestatus(int newstatus) {
// Side Effects : Copies all of the entries in h to current scope.
// -----------------------------------------------------------------------------
void DataType::merge_scope(Hash *h) {
void DataType::merge_scope(void *ho) {
char *key;
DataType *t, *nt;
Hash *h = (Hash *) ho;
if (h) {
// Copy all of the entries in the given hash table to this new one
@ -718,7 +675,8 @@ void DataType::merge_scope(Hash *h) {
// Side Effects : Creates a new hash table and increments the scope counter
// -----------------------------------------------------------------------------
void DataType::new_scope(Hash *h) {
void DataType::new_scope(void *ho) {
Hash *h = (Hash *) ho;
scope++;
typedef_hash[scope] = new Hash;
@ -749,7 +707,7 @@ void DataType::new_scope(Hash *h) {
// Side Effects : Returns the hash table corresponding to the current scope
// -----------------------------------------------------------------------------
Hash *DataType::collapse_scope(char *prefix) {
void *DataType::collapse_scope(char *prefix) {
DataType *t,*nt;
char *key;
char *temp;
@ -772,9 +730,9 @@ Hash *DataType::collapse_scope(char *prefix) {
h = typedef_hash[scope];
typedef_hash[scope] = 0;
scope--;
return h;
return (void *) h;
}
return (Hash *) 0;
return 0;
}
// -------------------------------------------------------------
@ -875,7 +833,7 @@ void typeeq_addtypedef(char *name, char *eqname, DataType *t) {
strcpy(t->name, eqname);
}
// printf("addtypedef: %s : %s : %s\n", name, eqname, t->print_type());
//printf("addtypedef: %s : %s : %s\n", name, eqname, t->print_type());
// First we're going to add the equivalence, no matter what
@ -1035,26 +993,6 @@ void typeeq_standard(void) {
}
// ------------------------------------------------------------------------------
// type_undefined_check(void)
//
// Checks the hash table for undefined datatypes and prints a warning message.
// -------------------------------------------------------------------------------
void type_undefined_check(void) {
char *s;
s = (char *) undefined_types.first();
if (s) {
fprintf(stderr,"The following datatypes were used, but undefined.\n");
while (s) {
fprintf(stderr," %s\n",s);
s = (char *) undefined_types.next();
}
}
}
// ----------------------------------------------------------------------
// char *check_equivalent(DataType *t)
//
@ -1076,6 +1014,7 @@ check_equivalent(DataType *t) {
if (!te_init) typeeq_init();
e1 = (EqEntry *) typeeq_hash.first();
while (e1) {
/* printf("'%s', '%s'\n", m.get(),e1->name); */
if (strcmp(m.get(),e1->name) == 0) {
e2 = e1->next;
while (e2) {
@ -1100,6 +1039,29 @@ check_equivalent(DataType *t) {
return out.get();
}
// -----------------------------------------------------------------------------
// void DataType::record_base(char *derived, char *base)
//
// Record base class information. This is a hack to make runtime libraries
// work across multiple files.
// -----------------------------------------------------------------------------
static Hash bases;
void DataType::record_base(char *derived, char *base)
{
Hash *nh;
nh = (Hash *) bases.lookup(derived);
if (!nh) {
nh = new Hash();
bases.add(derived, (void *) nh);
}
if (!nh->lookup(base)) {
char *bn = copy_string(base);
nh->add(base,(void *) bn);
}
}
// ----------------------------------------------------------------------
// void DataType::remember()
//
@ -1110,8 +1072,24 @@ check_equivalent(DataType *t) {
static Hash remembered;
void DataType::remember() {
Hash *h;
DataType *t = new DataType(this);
remembered.add(t->print_mangle(),(void *) t);
/* Now, do the base-class hack */
h = (Hash *) bases.lookup(t->name);
if (h) {
char *key;
key = h->firstkey();
while (key) {
DataType *nt = new DataType(t);
strcpy(nt->name,key);
if (!remembered.lookup(nt->print_mangle()))
nt->remember();
delete nt;
key = h->nextkey();
}
}
}
void
@ -1133,6 +1111,7 @@ emit_type_table() {
key = remembered.nextkey();
i++;
}
table << "0\n};\n";
fprintf(f_wrappers,"%s\n", types.get());
fprintf(f_wrappers,"%s\n", table.get());