Lot's of cleanup. Removed some more source files. Migrated more functionality to C.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@494 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-06-18 20:34:21 +00:00
commit 4068ffc0f9
21 changed files with 241 additions and 482 deletions

View file

@ -1,5 +1,17 @@
SWIG (Simplified Wrapper and Interface Generator) SWIG (Simplified Wrapper and Interface Generator)
Version 1.3 Alpha 3 (June 18, 2000)
===================================
6/18/00 : beazley
Removed the naming.cxx, hash.cxx, and symbol.cxx files from
the SWIG1.1 directory. Continued to migrate things away
from the C++ base (although there's still a lot of work to do).
6/17/00 : beazley
Added a few more examples to the Examples directory. Still
need to do a lot of work on this.
6/16/00 : beazley 6/16/00 : beazley
Added -includeall to follow all #include statements in the Added -includeall to follow all #include statements in the
preprocessor. preprocessor.

View file

@ -22,15 +22,18 @@ SWIG release. The guilty parties working on this are:
***** IMPORTANT NOTICE -- READ THIS NOW! ***** ***** IMPORTANT NOTICE -- READ THIS NOW! *****
*********************************************************************** ***********************************************************************
If you downloaded SWIG as a prepackaged release such as SWIG1.3a2, be If you downloaded SWIG as a prepackaged release such as SWIG1.3a3, be
advised that this distribution represents a snapshot of the most advised that this distribution represents a snapshot of the most
stable part of the SWIG CVS repository. As this is an unstable stable part of the SWIG CVS repository. As this is an unstable
release, there is a pretty good chance that a number of features are release, there is a pretty good chance that a number of features are
broken or under repair. Currently, SWIG is undergoing a large broken or under repair. Currently, SWIG is undergoing a large
redevelopment effort. The SWIG1.3 series of releases should be viewed redevelopment effort in which it is being converted from C++ to ANSI
as a transitional releases leading to the eventual release of SWIG2.0. C. As a result, the source code is a little disorganized at the
First-time users may want to start with SWIG1.1p5 which is significantly moment. The SWIG1.3 series of releases should be viewed as
more stable (and includes a wider range of documentation and examples). transitional releases leading to the eventual release of
SWIG2.0. First-time users may want to start with SWIG1.1p5 which is
significantly more stable (and includes a wider range of documentation
and examples).
Please report any errors and submit patches (if possible)! We only Please report any errors and submit patches (if possible)! We only
have access to a limited variety of hardware (Linux, Solaris, and have access to a limited variety of hardware (Linux, Solaris, and
@ -70,6 +73,11 @@ What's Broken?
- SWIG requires an ANSI C compiler. - SWIG requires an ANSI C compiler.
- A number of low-level data structures have been converted
to C. Since things haven't yet been fully tested, there's
a chance that unusual corner cases might cause SWIG to crash.
If so, please send us a debugger traceback if possible.
Installation Installation
============ ============
To build and install SWIG, simply type the following: To build and install SWIG, simply type the following:

View file

@ -233,7 +233,7 @@ GUILE::set_init (char *iname)
void void
GUILE::headers (void) GUILE::headers (void)
{ {
emit_banner (f_header); Swig_banner (f_header);
fprintf (f_header, "/* Implementation : GUILE */\n\n"); fprintf (f_header, "/* Implementation : GUILE */\n\n");

View file

@ -399,7 +399,7 @@ void JAVA::set_module(char *mod_name, char **mod_list) {
void JAVA::headers(void) void JAVA::headers(void)
{ {
emit_banner(f_header); // Print the SWIG banner message Swig_banner(f_header); // Print the SWIG banner message
fprintf(f_header,"/* Implementation : Java */\n\n"); fprintf(f_header,"/* Implementation : Java */\n\n");
// Include header file code fragment into the output // Include header file code fragment into the output

View file

@ -179,7 +179,7 @@ MZSCHEME::set_init (char *iname)
void void
MZSCHEME::headers (void) MZSCHEME::headers (void)
{ {
emit_banner (f_header); Swig_banner (f_header);
fprintf (f_header, "/* Implementation : MZSCHEME */\n\n"); fprintf (f_header, "/* Implementation : MZSCHEME */\n\n");
fprintf (f_header, "#include <stdio.h>\n"); fprintf (f_header, "#include <stdio.h>\n");

View file

@ -290,7 +290,7 @@ void PERL5::set_init(char *iname) {
void PERL5::headers(void) void PERL5::headers(void)
{ {
emit_banner(f_header); Swig_banner(f_header);
if (!alt_header) { if (!alt_header) {
if (Swig_insert_file("headers.swg", f_header) == -1) { if (Swig_insert_file("headers.swg", f_header) == -1) {

View file

@ -258,7 +258,7 @@ void PYTHON::print_methods() {
void PYTHON::headers(void) void PYTHON::headers(void)
{ {
emit_banner(f_runtime); Swig_banner(f_runtime);
fprintf(f_runtime,"/* Implementation : PYTHON */\n\n"); fprintf(f_runtime,"/* Implementation : PYTHON */\n\n");
fprintf(f_runtime,"#define SWIGPYTHON\n"); fprintf(f_runtime,"#define SWIGPYTHON\n");

View file

@ -233,7 +233,7 @@ void TCL8::set_init(char *iname) {
void TCL8::headers(void) void TCL8::headers(void)
{ {
emit_banner(f_runtime); Swig_banner(f_runtime);
// Include a Tcl configuration file for Unix,Mac,Wintel. // Include a Tcl configuration file for Unix,Mac,Wintel.

View file

@ -14,12 +14,12 @@ RANLIB = @RANLIB@
TARGET = libswig11.a TARGET = libswig11.a
OBJS = parser.o main.o scanner.o symbol.o types.o parms.o \ OBJS = parser.o main.o scanner.o types.o parms.o \
emit.o cplus.o lang.o hash.o sstring.o wrapfunc.o \ emit.o cplus.o lang.o sstring.o wrapfunc.o \
typemap.o typemap.o
SRCS = main.cxx scanner.cxx symbol.cxx types.cxx parms.cxx \ SRCS = main.cxx scanner.cxx types.cxx parms.cxx \
emit.cxx cplus.cxx lang.cxx hash.cxx \ emit.cxx cplus.cxx lang.cxx \
sstring.cxx wrapfunc.cxx typemap.cxx sstring.cxx wrapfunc.cxx typemap.cxx
PARSER = $(srcdir)/parser.yxx PARSER = $(srcdir)/parser.yxx

View file

@ -86,7 +86,7 @@ static char cvstag[] = "$Header$";
static int Inherit_mode = 0; // Set if we're inheriting members static int Inherit_mode = 0; // Set if we're inheriting members
static char *ccode = 0; // Set to optional C code (if available) static char *ccode = 0; // Set to optional C code (if available)
static Hash *localtypes; // Localtype hash static DOHHash *localtypes = 0; // Localtype hash
static int abstract =0; // Status bit set during code generation static int abstract =0; // Status bit set during code generation
static int cpp_id = 0; static int cpp_id = 0;
@ -116,7 +116,7 @@ static void add_local_type(char *type, char *classname) {
if (!localtypes) return; // No hash table initialized, ignore this if (!localtypes) return; // No hash table initialized, ignore this
str << classname << "::" << type; str << classname << "::" << type;
localtypes->add(type,copy_string(str)); Setattr(localtypes,type,str.get());
} }
void add_local_type(DataType *type, char *classname) { void add_local_type(DataType *type, char *classname) {
@ -139,7 +139,7 @@ static void update_local_type(DataType *type) {
if (!localtypes) return; if (!localtypes) return;
newname = (char *) localtypes->lookup(type->name); newname = GetChar(localtypes,type->name);
if (newname) { if (newname) {
strcpy(type->name, newname); strcpy(type->name, newname);
} }
@ -162,7 +162,7 @@ static void update_parms(ParmList *l) {
if ((p->defvalue) && (localtypes)) { if ((p->defvalue) && (localtypes)) {
char *s; char *s;
s = (char *) localtypes->lookup(p->defvalue); s = (char *) GetChar(localtypes,p->defvalue);
if (s) { if (s) {
delete p->defvalue; delete p->defvalue;
p->defvalue = copy_string(s); p->defvalue = copy_string(s);
@ -501,7 +501,7 @@ public:
int error; // Set if this class can't be generated int error; // Set if this class can't be generated
int line; // Line number int line; // Line number
char **baseclass; // Base classes (if any) char **baseclass; // Base classes (if any)
Hash *local; // Hash table for local types DOHHash *local; // Hash table for local types
void *scope; // Local scope hash table void *scope; // Local scope hash table
CPP_member *members; // Linked list of members CPP_member *members; // Linked list of members
CPP_class *next; // Next class CPP_class *next; // Next class
@ -514,7 +514,7 @@ public:
classtype = copy_string(ctype); classtype = copy_string(ctype);
classrename = 0; classrename = 0;
baseclass = 0; baseclass = 0;
local = new Hash; // Create hash table for storing local datatypes local = NewHash(); // Create hash table for storing local datatypes
scope = 0; scope = 0;
error = 0; error = 0;
pragmas = 0; pragmas = 0;
@ -944,7 +944,7 @@ void cplus_inherit(int count, char **baseclass) {
// //
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static Hash convert; // Hash table of conversion functions static DOHHash *convert = 0; // Hash table of conversion functions
void cplus_generate_types(char **baseclass) { void cplus_generate_types(char **baseclass) {
CPP_class *bc; CPP_class *bc;
@ -956,6 +956,8 @@ void cplus_generate_types(char **baseclass) {
return; return;
} }
if (!convert) convert = NewHash();
// Generate type-conversion functions and type-equivalence // Generate type-conversion functions and type-equivalence
i = 0; i = 0;
@ -970,7 +972,8 @@ void cplus_generate_types(char **baseclass) {
temp3 = ""; temp3 = "";
temp3 << "Swig" << current_class->classname << "To" << bc->classname; temp3 << "Swig" << current_class->classname << "To" << bc->classname;
if (convert.add(temp3,(void *) 1) != -1) { if (!Getattr(convert,temp3.get())) {
SetVoid(convert,temp3.get(),(void*) 1);
// Write a function for casting derived type to parent class // Write a function for casting derived type to parent class
@ -1300,9 +1303,6 @@ void cplus_declare_const(char *name, char *iname, DataType *type, char *value) {
CPP_constant *c = new CPP_constant(name, temp_iname, type, value); CPP_constant *c = new CPP_constant(name, temp_iname, type, value);
current_class->add_member(c); current_class->add_member(c);
// Update this symbol in the symbol table
update_symbol(name, type, value);
// Add this symbol to local scope of a class // Add this symbol to local scope of a class
add_local_type(name, current_class->classname); add_local_type(name, current_class->classname);
} }
@ -1387,7 +1387,7 @@ void cplus_add_pragma(char *lang, char *name, char *value)
// sharing code between base and derived classes. // sharing code between base and derived classes.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static Hash member_hash; // Hash wrapping member function wrappers to scripting wrappers static DOHHash *member_hash = 0; // Hash wrapping member function wrappers to scripting wrappers
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// void cplus_emit_member_func(char *classname, char *classtype, char *classrename, // void cplus_emit_member_func(char *classname, char *classtype, char *classrename,
@ -1516,9 +1516,13 @@ void cplus_emit_member_func(char *classname, char *classtype, char *classrename,
l->print_types(key); l->print_types(key);
// printf("key = %s\n", (char *) key); // printf("key = %s\n", (char *) key);
char *temp = copy_string(iname); char *temp = copy_string(iname);
if ((member_hash.add(key,temp)) == -1) { if (!member_hash) member_hash = NewHash();
if (Getattr(member_hash,key.get())) {
delete [] temp;
prev_wrap = GetChar(member_hash,key.get());
} else {
Setattr(member_hash,key.get(),temp);
delete [] temp; delete [] temp;
prev_wrap = (char *) member_hash.lookup(key);
} }
// Only generate code if an already existing wrapper doesn't exist // Only generate code if an already existing wrapper doesn't exist
@ -1730,9 +1734,13 @@ void cplus_emit_static_func(char *classname, char *, char *classrename,
key << cname << "+"; key << cname << "+";
l->print_types(key); l->print_types(key);
char *temp = copy_string(iname); char *temp = copy_string(iname);
if ((member_hash.add(key,temp)) == -1) { if (!member_hash) member_hash = NewHash();
if (Getattr(member_hash,key.get())) {
delete [] temp;
prev_wrap = GetChar(member_hash,key.get());
} else {
Setattr(member_hash,key.get(),temp);
delete [] temp; delete [] temp;
prev_wrap = (char *) member_hash.lookup(key);
} }
if (!prev_wrap) { if (!prev_wrap) {
@ -2151,9 +2159,13 @@ void cplus_emit_variable_get(char *classname, char *classtype, char *classrename
key << cname; key << cname;
char *temp = copy_string(iname); char *temp = copy_string(iname);
if ((member_hash.add(key,temp)) == -1) { if (!member_hash) member_hash = NewHash();
if (Getattr(member_hash,key.get())) {
delete [] temp;
prev_wrap = GetChar(member_hash,key.get());
} else {
Setattr(member_hash,key.get(),temp);
delete [] temp; delete [] temp;
prev_wrap = (char *) member_hash.lookup(key);
} }
// Only generate code if already existing wrapper doesn't exist // Only generate code if already existing wrapper doesn't exist
@ -2328,9 +2340,13 @@ void cplus_emit_variable_set(char *classname, char *classtype, char *classrename
key << cname; key << cname;
char *temp = copy_string(iname); char *temp = copy_string(iname);
if ((member_hash.add(key,temp)) == -1) { if (!member_hash) member_hash = NewHash();
if (Getattr(member_hash,key.get())) {
delete [] temp;
prev_wrap = GetChar(member_hash,key.get());
} else {
Setattr(member_hash,key.get(),temp);
delete [] temp; delete [] temp;
prev_wrap = (char *) member_hash.lookup(key);
} }
// Only generate code if already existing wrapper doesn't exist // Only generate code if already existing wrapper doesn't exist
@ -2519,9 +2535,9 @@ void cplus_register_scope(void *h) {
void cplus_inherit_scope(int count, char **baseclass) { void cplus_inherit_scope(int count, char **baseclass) {
CPP_class *bc; CPP_class *bc;
int i; int i;
char *key, *val; char *val;
String str; String str;
DOH *key;
if (count && current_class) { if (count && current_class) {
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
bc = CPP_class::search(baseclass[i]); bc = CPP_class::search(baseclass[i]);
@ -2531,13 +2547,13 @@ void cplus_inherit_scope(int count, char **baseclass) {
if (bc->local) { if (bc->local) {
// Copy local symbol table // Copy local symbol table
key = bc->local->firstkey(); key = Firstkey(bc->local);
while (key) { while (key) {
val = (char *) bc->local->lookup(key); val = GetChar(bc->local,key);
str = val; str = val;
// str.replace(bc->classname,current_class->classname); // str.replace(bc->classname,current_class->classname);
localtypes->add(key,copy_string(str)); Setattr(localtypes,key,str.get());
key = bc->local->nextkey(); key = Nextkey(bc->local);
} }
} }
} }

View file

@ -17,43 +17,8 @@ extern "C" {
#include "swig.h" #include "swig.h"
} }
static char cvsroot[] = "$Header$"; static char cvsroot[] = "$Header$";
// -----------------------------------------------------------------------------
// void emit_banner(FILE *f)
//
// Emits the SWIG identifying banner in the wrapper file
// -----------------------------------------------------------------------------
void emit_banner(FILE *f) {
extern char *get_time();
extern char fn_runtime[];
fprintf(f,
"/*\n\
* FILE : %s\n\
* \n\
* This file was automatically generated by SWIG (http://www.swig.org).\n\
* Version %s %s\n\
* \n\
* Portions Copyright (c) 1995-1999\n\
* The University of Utah, The Regents of the University of California, and\n\
* The University of Chicago. Permission is granted to use and distribute this\n\
* file in any manner provided this notice remains intact.\n\
* \n\
* This file is not intended to be easily readable and contains a number of \n\
* coding conventions designed to improve portability and efficiency. Do not make\n\
* changes to this file unless you know what you are doing--modify the SWIG \n\
* interface file instead. \n\
*\n\
*/\n\n", fn_runtime, SWIG_VERSION, SWIG_SPIN);
fprintf(f,"\n#define SWIGCODE\n");
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// emit_extern_var(char *decl, DataType *t, int extern_type, FILE *f) // emit_extern_var(char *decl, DataType *t, int extern_type, FILE *f)
// //

View file

@ -1,90 +0,0 @@
/* -----------------------------------------------------------------------------
* hash.cxx
*
* Hash table object.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1998-2000. The University of Chicago
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
* University of California.
*
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
#include "internal.h"
extern "C" {
#include "doh.h"
}
static char cvsroot[] = "$Header$";
Hash::Hash() {
data = NewHash();
}
Hash::~Hash() {
Delete(data);
}
int Hash::add(const char *k, void *obj) {
DOH *v = NewVoid(obj,0);
if (Getattr(data, (DOH *) k)) return -1;
Setattr(data, (DOH *) k, v);
return 0;
}
int Hash::add(const char *k, void *obj, void (*d)(void *)) {
DOH *v = NewVoid(obj,d);
if (Getattr(data, (DOH *) k)) return -1;
Setattr(data, (DOH *) k, v);
return 0;
}
void *Hash::lookup(const char *k) {
DOH *v;
v = Getattr(data,(DOH *)k);
if (!v) return 0;
return Data(v);
}
void Hash::remove(const char *k) {
Delattr(data,(DOH *)k);
}
void *Hash::first() {
DOH *o;
DOH *v = Firstkey(data);
if (v) {
o = Getattr(data,v);
return Data(o);
}
return 0;
}
char *Hash::firstkey() {
DOH *v = Firstkey(data);
if (v) {
return Char(v);
}
return 0;
}
void *Hash::next() {
DOH *o;
DOH *v = Nextkey(data);
if (v) {
o = Getattr(data,v);
return Data(o);
}
return 0;
}
char *Hash::nextkey() {
DOH *v = Nextkey(data);
if (v) {
return Char(v);
}
return 0;
}

View file

@ -21,6 +21,8 @@ extern "C" {
#include "swig.h" #include "swig.h"
} }
extern int add_symbol(char *name);
// ----------------------------------------------------------------- // -----------------------------------------------------------------
// void Language::set_init(char *iname) // void Language::set_init(char *iname)
// //
@ -169,7 +171,7 @@ void Language::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l
// Now do a symbol table lookup on it : // Now do a symbol table lookup on it :
if (add_symbol(new_name, 0,0)) { if (add_symbol(new_name)) {
fprintf(stderr,"%s : Line %d. Function %s (member %s) multiply defined (2nd definition ignored).\n", fprintf(stderr,"%s : Line %d. Function %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, cname, name); input_file, line_number, cname, name);
return; return;
@ -212,7 +214,7 @@ void Language::cpp_constructor(char *name, char *iname, ParmList *l) {
// Add this function to the SWIG symbol table // Add this function to the SWIG symbol table
if (add_symbol(cname, 0,0)) { if (add_symbol(cname)) {
fprintf(stderr,"%s : Line %d. Constructor %s multiply defined (2nd definition ignored).\n", fprintf(stderr,"%s : Line %d. Constructor %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname); input_file, line_number, cname);
return; return;
@ -246,7 +248,7 @@ void Language::cpp_destructor(char *name, char *iname) {
// Add this function to the SWIG symbol table // Add this function to the SWIG symbol table
if (add_symbol(cname, 0,0)) { if (add_symbol(cname)) {
fprintf(stderr,"%s : Line %d. Destructor %s multiply defined (2nd definition ignored).\n", fprintf(stderr,"%s : Line %d. Destructor %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname); input_file, line_number, cname);
return; return;
@ -324,7 +326,7 @@ void Language::cpp_variable(char *name, char *iname, DataType *t) {
// Check the symbol table // Check the symbol table
if (add_symbol(cname,(DataType *) 0,(char *) 0)) { if (add_symbol(cname)) {
fprintf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n", input_file, line_number, cname); fprintf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n", input_file, line_number, cname);
return; return;
} }
@ -377,7 +379,7 @@ void Language::cpp_static_func(char *name, char *iname, DataType *t, ParmList *l
// Now do a symbol table lookup on it : // Now do a symbol table lookup on it :
if (add_symbol(cname, 0,0)) { if (add_symbol(cname)) {
if (ObjCClass) if (ObjCClass)
fprintf(stderr,"%s : Line %d. class function %s multiply defined (2nd definition ignored).\n", fprintf(stderr,"%s : Line %d. class function %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname); input_file, line_number, cname);
@ -428,7 +430,7 @@ void Language::cpp_declare_const(char *name, char *iname, DataType *type, char *
// Now do a symbol table lookup on it : // Now do a symbol table lookup on it :
if (add_symbol(cname, 0,0)) { if (add_symbol(cname)) {
fprintf(stderr,"%s : Line %d. Constant %s (member %s) multiply defined (2nd definition ignored).\n", fprintf(stderr,"%s : Line %d. Constant %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, cname, name); input_file, line_number, cname, name);
return; return;
@ -488,7 +490,7 @@ void Language::cpp_static_var(char *name, char *iname, DataType *t) {
// Now do a symbol table lookup on it : // Now do a symbol table lookup on it :
if (add_symbol(cname, 0,0)) { if (add_symbol(cname)) {
fprintf(stderr,"%s : Line %d. Variable %s (member %s) multiply defined (2nd definition ignored).\n", fprintf(stderr,"%s : Line %d. Variable %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, cname, name); input_file, line_number, cname, name);
return; return;

View file

@ -147,6 +147,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
int includecount = 0; int includecount = 0;
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);
DOH *libfiles = 0; DOH *libfiles = 0;
#ifdef MACSWIG #ifdef MACSWIG
@ -155,7 +156,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
// Initialize the preprocessor // Initialize the preprocessor
Preprocessor_init(); Preprocessor_init();
typemap_initialize();
f_wrappers = 0; f_wrappers = 0;
f_init = 0; f_init = 0;
f_header = 0; f_header = 0;

View file

@ -76,10 +76,12 @@ static String ArrayBackup; // Array backup string
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
static Hash name_hash; // Hash table containing renamings static DOHHash *name_hash = 0; // Hash table containing renamings
char *objc_construct = (char *) "new"; // Objective-C constructor char *objc_construct = (char *) "new"; // Objective-C constructor
char *objc_destruct = (char *) "free"; // Objective-C destructor char *objc_destruct = (char *) "free"; // Objective-C destructor
static DOHHash *symbols = 0;
/* Some macros for building constants */ /* Some macros for building constants */
#define E_BINARY(TARGET, SRC1, SRC2, OP) \ #define E_BINARY(TARGET, SRC1, SRC2, OP) \
@ -129,6 +131,14 @@ static void init_language() {
lang_init = 1; lang_init = 1;
} }
/* Add a symbol to the symbol table. Return -1 if it already exists */
int add_symbol(char *name) {
if (!symbols) symbols = NewHash();
if (Getattr(symbols,name)) return -1;
Setattr(symbols,name,name);
return 0;
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// int promote(int t1, int t2) // int promote(int t1, int t2)
// //
@ -160,7 +170,9 @@ int promote(int t1, int t2) {
static char *make_name(char *name) { static char *make_name(char *name) {
// Check to see if the name is in the hash // Check to see if the name is in the hash
char *nn = (char *) name_hash.lookup(name); if (!name_hash) name_hash = NewHash();
char *nn = GetChar(name_hash,name);
if (nn) return nn; // Yep, return it. if (nn) return nn; // Yep, return it.
if (Rename_true) { if (Rename_true) {
@ -197,7 +209,7 @@ void create_function(int ext, char *name, DataType *t, ParmList *l) {
// Check if symbol already exists // Check if symbol already exists
if (add_symbol(iname, t, (char *) 0)) { if (add_symbol(iname)) {
fprintf(stderr,"%s : Line %d. Function %s multiply defined (2nd definition ignored).\n", fprintf(stderr,"%s : Line %d. Function %s multiply defined (2nd definition ignored).\n",
input_file, line_number, iname); input_file, line_number, iname);
} else { } else {
@ -232,7 +244,7 @@ void create_variable(int ext, char *name, DataType *t) {
init_language(); init_language();
char *iname = make_name(name); char *iname = make_name(name);
if (add_symbol(iname, t, (char *) 0)) { if (add_symbol(iname)) {
fprintf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n", fprintf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n",
input_file, line_number, iname); input_file, line_number, iname);
} else { } else {
@ -278,13 +290,10 @@ void create_constant(char *name, DataType *type, char *value) {
if (!value) value = copy_string(name); if (!value) value = copy_string(name);
sprintf(temp_name,"const:%s", name); sprintf(temp_name,"const:%s", name);
if (add_symbol(temp_name, type, value)) { if (add_symbol(temp_name)) {
fprintf(stderr,"%s : Line %d. Constant %s multiply defined. (2nd definition ignored)\n", fprintf(stderr,"%s : Line %d. Constant %s multiply defined. (2nd definition ignored)\n",
input_file, line_number, name); input_file, line_number, name);
} else { } else {
// Update symbols value if already defined.
update_symbol(name, type, value);
if (!WrapExtern) { // Only wrap the constant if not in %extern mode if (!WrapExtern) { // Only wrap the constant if not in %extern mode
lang->declare_const(name, name, type, value); lang->declare_const(name, name, type, value);
} }
@ -685,10 +694,8 @@ statement : INCLUDE STRING LBRACE {
/* %rename directive */ /* %rename directive */
| RENAME ID ID SEMI { | RENAME ID ID SEMI {
if (name_hash.lookup($2)) { if (!name_hash) name_hash = NewHash();
name_hash.remove($2); Setattr(name_hash,$2,$3);
}
name_hash.add($2,copy_string($3));
} }
/* %new directive */ /* %new directive */
@ -714,7 +721,7 @@ statement : INCLUDE STRING LBRACE {
| NATIVE LPAREN ID RPAREN extern ID SEMI { | NATIVE LPAREN ID RPAREN extern ID SEMI {
if (!WrapExtern) { if (!WrapExtern) {
init_language(); init_language();
if (add_symbol($3,(DataType *) 0, (char *) 0)) { if (add_symbol($3)) {
fprintf(stderr,"%s : Line %d. Name of native function %s conflicts with previous declaration (ignored)\n", fprintf(stderr,"%s : Line %d. Name of native function %s conflicts with previous declaration (ignored)\n",
input_file, line_number, $3); input_file, line_number, $3);
} else { } else {
@ -726,7 +733,7 @@ statement : INCLUDE STRING LBRACE {
if (!WrapExtern) { if (!WrapExtern) {
init_language(); init_language();
$6->is_pointer += $7.is_pointer; $6->is_pointer += $7.is_pointer;
if (add_symbol($3,(DataType *) 0, (char *) 0)) { if (add_symbol($3)) {
fprintf(stderr,"%s : Line %d. Name of native function %s conflicts with previous declaration (ignored)\n", fprintf(stderr,"%s : Line %d. Name of native function %s conflicts with previous declaration (ignored)\n",
input_file, line_number, $3); input_file, line_number, $3);
} else { } else {
@ -877,7 +884,7 @@ statement : INCLUDE STRING LBRACE {
delete temp_typeptr; delete temp_typeptr;
} else if ($3.type == T_SYMBOL) { } else if ($3.type == T_SYMBOL) {
// Add a symbol to the SWIG symbol table // Add a symbol to the SWIG symbol table
if (add_symbol($2,(DataType *) 0, (char *) 0)) { if (add_symbol($2)) {
fprintf(stderr,"%s : Line %d. Warning. Symbol %s already defined.\n", fprintf(stderr,"%s : Line %d. Warning. Symbol %s already defined.\n",
input_file,line_number, $2); input_file,line_number, $2);
} }
@ -1843,16 +1850,8 @@ expr : NUM_INT {
$$.type = $2->type; $$.type = $2->type;
} }
| ID { | ID {
$$.id = lookup_symvalue($1); $$.id = $1;
if ($$.id == (char *) 0) $$.type = T_INT;
$$.id = $1;
else {
$$.id = new char[strlen($$.id)+3];
sprintf($$.id,"(%s)",lookup_symvalue($1));
}
temp_typeptr = lookup_symtype($1);
if (temp_typeptr) $$.type = temp_typeptr->type;
else $$.type = T_INT;
} }
| ID DCOLON ID { | ID DCOLON ID {
$$.id = new char[strlen($1)+strlen($3)+3]; $$.id = new char[strlen($1)+strlen($3)+3];
@ -1987,7 +1986,7 @@ cpp_class :
DataType::new_scope(); DataType::new_scope();
sprintf(temp_name,"CPP_CLASS:%s\n",$3); sprintf(temp_name,"CPP_CLASS:%s\n",$3);
if (add_symbol(temp_name, (DataType *) 0, (char *) 0)) { if (add_symbol(temp_name)) {
fprintf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $3); fprintf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $3);
FatalError(); FatalError();
} }
@ -2042,7 +2041,7 @@ cpp_class :
DataType::new_scope(); DataType::new_scope();
sprintf(temp_name,"CPP_CLASS:%s\n",$3); sprintf(temp_name,"CPP_CLASS:%s\n",$3);
if (add_symbol(temp_name, (DataType *) 0, (char *) 0)) { if (add_symbol(temp_name)) {
fprintf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $3); fprintf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $3);
FatalError(); FatalError();
} }
@ -2147,7 +2146,7 @@ cpp_class :
cplus_abort(); cplus_abort();
} else { } else {
sprintf(temp_name,"CPP_CLASS:%s\n",$7.id); sprintf(temp_name,"CPP_CLASS:%s\n",$7.id);
if (add_symbol(temp_name, (DataType *) 0, (char *) 0)) { if (add_symbol(temp_name)) {
fprintf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $7.id); fprintf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $7.id);
FatalError(); FatalError();
} }
@ -2855,7 +2854,7 @@ objective_c : OC_INTERFACE ID objc_inherit {
init_language(); init_language();
cplus_mode = CPLUS_PROTECTED; cplus_mode = CPLUS_PROTECTED;
sprintf(temp_name,"CPP_CLASS:%s\n",$2); sprintf(temp_name,"CPP_CLASS:%s\n",$2);
if (add_symbol(temp_name,(DataType *) 0, (char *) 0)) { if (add_symbol(temp_name)) {
fprintf(stderr,"%s : Line %d. @interface %s is multiple defined.\n", fprintf(stderr,"%s : Line %d. @interface %s is multiple defined.\n",
input_file,line_number,$2); input_file,line_number,$2);
FatalError(); FatalError();

View file

@ -123,7 +123,6 @@ void scanner_close() {
line_number = p->line_number; line_number = p->line_number;
input_file = p->in_file; input_file = p->in_file;
WrapExtern = p->extern_mode; WrapExtern = p->extern_mode;
if (!WrapExtern) remove_symbol((char*)"SWIGEXTERN");
ForceExtern = p->force_extern; ForceExtern = p->force_extern;
} else { } else {
LEX_in = NULL; LEX_in = NULL;

View file

@ -100,26 +100,6 @@ public:
#define endl "\n" #define endl "\n"
#define quote "\"" #define quote "\""
// -------------------------------------------------------------------
// Hash table class
// -------------------------------------------------------------------
class Hash {
private:
void *data;
public:
Hash();
~Hash();
int add(const char *key, void *object);
int add(const char *key, void *object, void (*del)(void *));
void *lookup(const char *key);
void remove(const char *key);
void *first();
void *next();
char *firstkey();
char *nextkey();
};
/************************************************************************ /************************************************************************
* class DataType * class DataType
* *
@ -424,16 +404,11 @@ public:
extern void emit_extern_var(char *, DataType *, int, FILE *); extern void emit_extern_var(char *, DataType *, int, FILE *);
extern void emit_extern_func(char *, DataType *, ParmList *, int, FILE *); extern void emit_extern_func(char *, DataType *, ParmList *, int, FILE *);
extern int emit_args(DataType *, ParmList *, FILE *);
extern void emit_func_call(char *, DataType *, ParmList *, FILE *); extern void emit_func_call(char *, DataType *, ParmList *, FILE *);
extern void emit_hex(FILE *);
extern void emit_set_get(char *, char *, DataType *); extern void emit_set_get(char *, char *, DataType *);
extern void emit_banner(FILE *);
extern void emit_ptr_equivalence(FILE *); extern void emit_ptr_equivalence(FILE *);
extern int SWIG_main(int, char **, Language *); extern int SWIG_main(int, char **, Language *);
extern void make_wrap_name(char *);
// Some functions for emitting some C++ helper code // Some functions for emitting some C++ helper code
@ -472,7 +447,6 @@ extern "C" {
extern FILE *Swig_open(const void *filename); extern FILE *Swig_open(const void *filename);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// Class for Creating Wrapper Functions // Class for Creating Wrapper Functions
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -499,15 +473,6 @@ extern int emit_args(DataType *, ParmList *, WrapperFunction &f);
extern void emit_func_call(char *, DataType *, ParmList *, WrapperFunction &f); extern void emit_func_call(char *, DataType *, ParmList *, WrapperFunction &f);
extern void SWIG_exit(int); extern void SWIG_exit(int);
// Symbol table management
extern int add_symbol(char *, DataType *, char *);
extern void remove_symbol(char *);
extern int update_symbol(char *, DataType *, char *);
extern char *lookup_symvalue(char *);
extern DataType *lookup_symtype(char *);
extern int lookup_symbol(char *);
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// Typemap support // Typemap support
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -535,16 +500,7 @@ extern void fragment_clear(char *op, char *lang);
extern void emit_ptr_equivalence(WrapperFunction &); extern void emit_ptr_equivalence(WrapperFunction &);
// -----------------------------------------------------------------------
// Naming system
// -----------------------------------------------------------------------
#define AS_IS 1
extern void name_register(char *method, char *format);
extern char *name_wrapper(char *fname, char *prefix, int suppress=0);
extern char *name_member(char *fname, char *classname, int suppress=0);
extern char *name_get(char *vname, int suppress=0);
extern char *name_set(char *vname, int suppress=0);
extern char *name_construct(char *classname, int suppress=0);
extern char *name_destroy(char *classname, int suppress=0);

View file

@ -1,146 +0,0 @@
/* -----------------------------------------------------------------------------
* symbol.cxx
*
* Symbol table management.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1998-2000. The University of Chicago
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
* University of California.
*
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
#include "internal.h"
static char cvstag[] = "$Header$";
// -----------------------------------------------------------------------------
// Symbol object
// -----------------------------------------------------------------------------
struct Symbol {
~Symbol() {
if (name) delete name;
if (type) delete type;
if (value) delete value;
}
char *name;
DataType *type; // Optional datatype
char *value; // Optional value (for constant expressions)
};
static Hash SymHash; // SWIG Symbol table
// -----------------------------------------------------------------------------
// int add_symbol(char *name, DataType *type, char *value)
//
// Adds a symbol to the symbol table. Returns -1 if symbol is already in the table.
// -----------------------------------------------------------------------------
int add_symbol(char *name, DataType *type, char *value) {
Symbol *s;
int ret;
s = new Symbol;
s->name = copy_string(name);
if (type)
s->type = new DataType(type);
else s->type = (DataType *) 0;
if (value)
s->value = copy_string(value);
else s->value = (char *) 0;
// Add this to the symbol table
ret = SymHash.add(s->name, s);
if (ret == -1) {
delete s;
}
return ret;
}
// -----------------------------------------------------------------------------
// int lookup_symbol(char *name)
//
// Checks to see if a symbol is in the symbol table.
// -----------------------------------------------------------------------------
int lookup_symbol(char *name) {
Symbol *s;
s = (Symbol *) SymHash.lookup(name);
if (s) return 1;
else return 0;
}
// -----------------------------------------------------------------------------
// DataType *lookup_symtype(char *name)
//
// Returns the datatype of a symbol or NULL if not found.
// -----------------------------------------------------------------------------
DataType *lookup_symtype(char *name) {
Symbol *s;
s = (Symbol *) SymHash.lookup(name);
if (s) return s->type;
else return (DataType *) 0;
}
// -----------------------------------------------------------------------------
// char *lookup_symvalue(char *name)
//
// Returns the value associate with a symbol.
// -----------------------------------------------------------------------------
char *lookup_symvalue(char *name) {
Symbol *s;
s = (Symbol *) SymHash.lookup(name);
if (s) return s->value;
else return (char *) 0;
}
// -----------------------------------------------------------------------------
// int update_symbol(char *name, DataType *type, char *value)
//
// Updates a symbol (or create it) in the hash table.
// -----------------------------------------------------------------------------
int update_symbol(char *name, DataType *type, char *value) {
Symbol *s;
s = (Symbol *) SymHash.lookup(name);
if (s) {
if (s->type) delete s->type;
if (s->value) delete s->value;
if (type)
s->type = new DataType(type);
else
s->type = (DataType *) 0;
if (value)
s->value = copy_string(value);
else
s->value = (char *) 0;
return 0;
} else {
return add_symbol(name, type, value);
}
}
// -----------------------------------------------------------------------------
// void remove_symbol(char *name)
//
// Removes a symbol from the symbol table.
// -----------------------------------------------------------------------------
void remove_symbol(char *name) {
SymHash.remove(name);
}

View file

@ -17,6 +17,10 @@ static char cvsroot[] = "$Header$";
#include "internal.h" #include "internal.h"
#include <limits.h> #include <limits.h>
extern "C" {
#include "doh.h"
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// This file provides universal support for typemaps. Typemaps are created // This file provides universal support for typemaps. Typemaps are created
// using the following SWIG command in an interface file: // using the following SWIG command in an interface file:
@ -127,7 +131,7 @@ struct TypeMap {
// Hash tables for storing type-mappings // Hash tables for storing type-mappings
static Hash typemap_hash; static DOH *typemap_hash = 0;
// Structure for holding "applications of a typemap" // Structure for holding "applications of a typemap"
@ -149,7 +153,7 @@ struct TmMethod {
// Hash table for storing applications of a datatype // Hash table for storing applications of a datatype
static Hash application_hash; static DOH *application_hash = 0;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// void typemap_apply(DataType *tm_type, char *tm_name, DataType *type, char *pname) // void typemap_apply(DataType *tm_type, char *tm_name, DataType *type, char *pname)
@ -168,11 +172,12 @@ void typemap_apply(DataType *tm_type, char *tm_name, DataType *type, char *pname
// See if there is a method already defined // See if there is a method already defined
m = (TmMethod *) application_hash.lookup(temp); if (!application_hash) application_hash = NewHash();
m = (TmMethod *) GetVoid(application_hash,temp);
if (!m) { if (!m) {
m = new TmMethod(temp,type,0); m = new TmMethod(temp,type,0);
application_hash.add(temp,m); SetVoid(application_hash,temp,m);
} }
// Check to see if an array typemap has been applied to a non-array type // Check to see if an array typemap has been applied to a non-array type
@ -219,7 +224,8 @@ void typemap_clear_apply(DataType *type, char *pname) {
char temp[512]; char temp[512];
if (!pname) pname = (char*)""; if (!pname) pname = (char*)"";
sprintf(temp,"%s$%s", type->print_type(), pname); sprintf(temp,"%s$%s", type->print_type(), pname);
application_hash.remove(temp); if (!application_hash) application_hash = NewHash();
Delattr(application_hash,temp);
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -263,6 +269,7 @@ void typemap_register(char *op, char *lang, DataType *type, char *pname,
// printf("Registering : %s %s %s %s\n%s\n", op, lang, type->print_type(), pname, getcode); // printf("Registering : %s %s %s %s\n%s\n", op, lang, type->print_type(), pname, getcode);
if (!typemap_hash) typemap_hash = NewHash();
tm = new TypeMap(lang,type,getcode,args); tm = new TypeMap(lang,type,getcode,args);
// If this is a default typemap, downgrade the type! // If this is a default typemap, downgrade the type!
@ -276,7 +283,7 @@ void typemap_register(char *op, char *lang, DataType *type, char *pname,
// Get any previous setting of the typemap // Get any previous setting of the typemap
tm_old = (TypeMap *) typemap_hash.lookup(key); tm_old = (TypeMap *) GetVoid(typemap_hash,key);
if (tm_old) { if (tm_old) {
@ -296,11 +303,11 @@ void typemap_register(char *op, char *lang, DataType *type, char *pname,
// Remove the old one from the hash // Remove the old one from the hash
typemap_hash.remove(key); Delattr(typemap_hash,key);
} }
// Add new typemap to the hash table // Add new typemap to the hash table
typemap_hash.add(key,(void *) tm); SetVoid(typemap_hash,key,tm);
// Now try to perform default chaining operation (if available) // Now try to perform default chaining operation (if available)
// if (!is_default) { // if (!is_default) {
@ -390,7 +397,8 @@ TypeMap *typemap_search(char *key, int id) {
TypeMap *tm; TypeMap *tm;
tm = (TypeMap *) typemap_hash.lookup(key); if (!typemap_hash) typemap_hash = NewHash();
tm = (TypeMap *) GetVoid(typemap_hash,key);
while (tm) { while (tm) {
if ((id >= tm->first) && (id < tm->last)) return tm; if ((id >= tm->first) && (id < tm->last)) return tm;
else tm = tm->next; else tm = tm->next;
@ -691,10 +699,10 @@ char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *so
tstr = type->print_type(); tstr = type->print_type();
sprintf(temp,"%s$%s",tstr,ppname); sprintf(temp,"%s$%s",tstr,ppname);
// No mapping was found. See if the name has been mapped with %apply // No mapping was found. See if the name has been mapped with %apply
m = (TmMethod *) application_hash.lookup(temp); m = (TmMethod *) GetVoid(application_hash,temp);
if (!m) { if (!m) {
sprintf(temp,"%s$",tstr); sprintf(temp,"%s$",tstr);
m = (TmMethod *) application_hash.lookup(temp); m = (TmMethod *) GetVoid(application_hash,temp);
} }
if (m) { if (m) {
m = m->next; m = m->next;
@ -847,10 +855,11 @@ char *typemap_check(char *op, char *lang, DataType *type, char *pname) {
tstr = type->print_type(); tstr = type->print_type();
sprintf(temp,"%s$%s",tstr,ppname); sprintf(temp,"%s$%s",tstr,ppname);
// No mapping was found. See if the name has been mapped with %apply // No mapping was found. See if the name has been mapped with %apply
m = (TmMethod *) application_hash.lookup(temp); if (!application_hash) application_hash = NewHash();
m = (TmMethod *) GetVoid(application_hash,temp);
if (!m) { if (!m) {
sprintf(temp,"%s$",tstr); sprintf(temp,"%s$",tstr);
m = (TmMethod *) application_hash.lookup(temp); m = (TmMethod *) GetVoid(application_hash,temp);
} }
if (m) { if (m) {
m = m->next; m = m->next;
@ -938,7 +947,8 @@ void typemap_clear(char *op, char *lang, DataType *type, char *pname) {
// Look for any previous version, simply set the last id if // Look for any previous version, simply set the last id if
// applicable. // applicable.
tm = (TypeMap *) typemap_hash.lookup(key); if (!typemap_hash) typemap_hash = NewHash();
tm = (TypeMap *) GetVoid(typemap_hash,key);
if (tm) { if (tm) {
if (tm->last > type_id) tm->last = type_id; if (tm->last > type_id) tm->last = type_id;
} }
@ -968,8 +978,8 @@ void typemap_copy(char *op, char *lang, DataType *stype, char *sname,
if (tk) { if (tk) {
tn = new TypeMap(tk); // Make a copy of the previous typemap tn = new TypeMap(tk); // Make a copy of the previous typemap
tn->next = tm; // Set up symlinks tn->next = tm; // Set up symlinks
typemap_hash.remove(key); // Remove old hash entry Delattr(typemap_hash,key); // Remove old hash entry
typemap_hash.add(key,(void *) tn); SetVoid(typemap_hash,key, tn);
} }
} else { } else {
typemap_register(op,lang,ttype,tname,tm->code,tm->args); typemap_register(op,lang,ttype,tname,tm->code,tm->args);
@ -1009,7 +1019,7 @@ void fragment_register(char *op, char *lang, char *code) {
// Get any previous setting of the typemap // Get any previous setting of the typemap
tm_old = (TypeMap *) typemap_hash.lookup(key); tm_old = (TypeMap *) GetVoid(typemap_hash,key);
if (tm_old) { if (tm_old) {
// 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
@ -1024,7 +1034,7 @@ void fragment_register(char *op, char *lang, char *code) {
// Remove the old one from the hash // Remove the old one from the hash
typemap_hash.remove(key); Delattr(typemap_hash,key);
} }
// Perform a default chaining operation if needed (defaults to nothing) // Perform a default chaining operation if needed (defaults to nothing)
@ -1032,7 +1042,7 @@ void fragment_register(char *op, char *lang, char *code) {
tm->code.replace(temp,""); tm->code.replace(temp,"");
// Add new typemap to the hash table // Add new typemap to the hash table
typemap_hash.add(key,(void *) tm); SetVoid(typemap_hash,key,tm);
} }
@ -1084,8 +1094,20 @@ void fragment_clear(char *op, char *lang) {
// Look for any previous version, simply set the last id if // Look for any previous version, simply set the last id if
// applicable. // applicable.
tm = (TypeMap *) typemap_hash.lookup(key); tm = (TypeMap *) GetVoid(typemap_hash,key);
if (tm) { if (tm) {
if (tm->last > type_id) tm->last = type_id; if (tm->last > type_id) tm->last = type_id;
} }
} }
// -----------------------------------------------------------------------------
// typemap_initialize()
//
// Initialize the hash tables
// -----------------------------------------------------------------------------
void
typemap_initialize() {
typemap_hash = NewHash();
application_hash = NewHash();
}

View file

@ -16,6 +16,10 @@ static char cvsroot[] = "$Header$";
#include "internal.h" #include "internal.h"
extern "C" {
#include "doh.h"
}
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// class DataType member functions. // class DataType member functions.
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -430,7 +434,7 @@ char *DataType::get_array() {
// typedef support. This needs to be scoped. // typedef support. This needs to be scoped.
// -------------------------------------------------------------------- // --------------------------------------------------------------------
static Hash *typedef_hash[MAXSCOPE]; static DOHHash *typedef_hash[MAXSCOPE];
static int scope = 0; // Current scope static int scope = 0; // Current scope
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -449,7 +453,7 @@ void DataType::init_typedef() {
typedef_hash[i] = 0; typedef_hash[i] = 0;
scope = 0; scope = 0;
// Create a new hash // Create a new hash
typedef_hash[scope] = new Hash; typedef_hash[scope] = NewHash();
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -471,7 +475,7 @@ void DataType::typedef_add(char *tname, int mode) {
// We only check in the local scope. C++ classes may make typedefs // We only check in the local scope. C++ classes may make typedefs
// that shadow global ones. // that shadow global ones.
if (typedef_hash[scope]->lookup(tname)) { if (Getattr(typedef_hash[scope],tname)) {
fprintf(stderr,"%s : Line %d. Warning. Datatype %s already defined (2nd definition ignored).\n", fprintf(stderr,"%s : Line %d. Warning. Datatype %s already defined (2nd definition ignored).\n",
input_file, line_number, tname); input_file, line_number, tname);
return; return;
@ -486,7 +490,7 @@ void DataType::typedef_add(char *tname, int mode) {
// strcpy(nt->name,tname); // Copy over the new name // strcpy(nt->name,tname); // Copy over the new name
// Add this type to our hash table // Add this type to our hash table
typedef_hash[scope]->add(tname,(void *) nt); SetVoid(typedef_hash[scope],tname, (void *) nt);
// Now add this type mapping to our type-equivalence table // Now add this type mapping to our type-equivalence table
@ -534,7 +538,7 @@ void DataType::typedef_resolve(int level) {
int s = scope - level; int s = scope - level;
while (s >= 0) { while (s >= 0) {
if ((td = (DataType *) typedef_hash[s]->lookup(name))) { if ((td = (DataType *) GetVoid(typedef_hash[s],name))) {
type = td->type; type = td->type;
is_pointer += td->is_pointer; is_pointer += td->is_pointer;
implicit_ptr += td->implicit_ptr; implicit_ptr += td->implicit_ptr;
@ -568,7 +572,7 @@ void DataType::typedef_replace () {
DataType *td; DataType *td;
String temp; String temp;
if ((td = (DataType *) typedef_hash[scope]->lookup(name))) { if ((td = (DataType *) GetVoid(typedef_hash[scope],name))) {
type = td->type; type = td->type;
is_pointer = td->is_pointer; is_pointer = td->is_pointer;
implicit_ptr -= td->implicit_ptr; implicit_ptr -= td->implicit_ptr;
@ -596,7 +600,7 @@ void DataType::typedef_replace () {
int DataType::is_typedef(char *t) { int DataType::is_typedef(char *t) {
int s = scope; int s = scope;
while (s >= 0) { while (s >= 0) {
if (typedef_hash[s]->lookup(t)) return 1; if (Getattr(typedef_hash[s],t)) return 1;
s--; s--;
} }
return 0; return 0;
@ -613,7 +617,7 @@ int DataType::is_typedef(char *t) {
void DataType::typedef_updatestatus(int newstatus) { void DataType::typedef_updatestatus(int newstatus) {
DataType *t; DataType *t;
if ((t = (DataType *) typedef_hash[scope]->lookup(name))) { if ((t = (DataType *) GetVoid(typedef_hash[scope],name))) {
t->status = newstatus; t->status = newstatus;
} }
} }
@ -633,19 +637,19 @@ void DataType::typedef_updatestatus(int newstatus) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void DataType::merge_scope(void *ho) { void DataType::merge_scope(void *ho) {
char *key; DOHString *key;
DataType *t, *nt; DataType *t, *nt;
Hash *h = (Hash *) ho; DOHHash *h = (DOHHash *) ho;
if (h) { if (h) {
// Copy all of the entries in the given hash table to this new one // Copy all of the entries in the given hash table to this new one
key = h->firstkey(); key = Firstkey(h);
while (key) { while (key) {
// printf("%s\n", key); // printf("%s\n", key);
t = (DataType *) h->lookup(key); t = (DataType *) GetVoid(h,key);
nt = new DataType(t); nt = new DataType(t);
typedef_hash[scope]->add(key,(void *) nt); SetVoid(typedef_hash[scope],key,(void *) nt);
key = h->nextkey(); key = Nextkey(h);
} }
} }
} }
@ -664,12 +668,10 @@ void DataType::merge_scope(void *ho) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void DataType::new_scope(void *ho) { void DataType::new_scope(void *ho) {
Hash *h = (Hash *) ho;
scope++; scope++;
typedef_hash[scope] = new Hash; typedef_hash[scope] = NewHash();
if (ho) {
if (h) { merge_scope(ho);
merge_scope(h);
} }
} }
@ -697,22 +699,22 @@ void DataType::new_scope(void *ho) {
void *DataType::collapse_scope(char *prefix) { void *DataType::collapse_scope(char *prefix) {
DataType *t,*nt; DataType *t,*nt;
char *key; DOHString *key;
char *temp; char *temp;
Hash *h; DOHHash *h;
if (scope > 0) { if (scope > 0) {
if (prefix) { if (prefix) {
key = typedef_hash[scope]->firstkey(); key = Firstkey(typedef_hash[scope]);
while (key) { while (key) {
t = (DataType *) typedef_hash[scope]->lookup(key); t = (DataType *) GetVoid(typedef_hash[scope],key);
nt = new DataType(t); nt = new DataType(t);
temp = new char[strlen(prefix)+strlen(key)+3]; temp = new char[strlen(prefix)+strlen(Char(key))+3];
sprintf(temp,"%s::%s",prefix,key); sprintf(temp,"%s::%s",prefix,Char(key));
// printf("creating %s\n", temp); // printf("creating %s\n", temp);
typedef_hash[scope-1]->add(temp,(void *) nt); SetVoid(typedef_hash[scope-1],temp, (void *)nt);
delete temp; delete temp;
key = typedef_hash[scope]->nextkey(); key = Nextkey(typedef_hash[scope]);
} }
} }
h = typedef_hash[scope]; h = typedef_hash[scope];
@ -740,11 +742,12 @@ struct EqEntry {
EqEntry *next; EqEntry *next;
}; };
static Hash typeeq_hash; static DOHHash *typeeq_hash = 0;
static int te_init = 0; static int te_init = 0;
void typeeq_init() { void typeeq_init() {
void typeeq_standard(); void typeeq_standard();
if (!typeeq_hash) typeeq_hash = NewHash();
te_init = 1; te_init = 1;
typeeq_standard(); typeeq_standard();
} }
@ -768,7 +771,7 @@ void typeeq_add(char *name, char *eqname, char *cast = 0, DataType *type = 0) {
// Search for "name" entry in the hash table // Search for "name" entry in the hash table
e1 = (EqEntry *) typeeq_hash.lookup(name); e1 = (EqEntry *) GetVoid(typeeq_hash,name);
if (!e1) { if (!e1) {
// Create a new entry // Create a new entry
@ -777,7 +780,7 @@ void typeeq_add(char *name, char *eqname, char *cast = 0, DataType *type = 0) {
e1->next = 0; e1->next = 0;
e1->cast = 0; e1->cast = 0;
// Add it to the hash table // Add it to the hash table
typeeq_hash.add(name,(void *) e1); SetVoid(typeeq_hash,name,(void *) e1);
} }
// Add new type to the list // Add new type to the list
@ -829,7 +832,7 @@ void typeeq_addtypedef(char *name, char *eqname, DataType *t) {
// Now find the hash entry // Now find the hash entry
e1 = (EqEntry *) typeeq_hash.lookup(name); e1 = (EqEntry *) GetVoid(typeeq_hash,name);
if (!e1) return; if (!e1) return;
// Walk down the list and make other equivalences // Walk down the list and make other equivalences
@ -856,6 +859,7 @@ void typeeq_addtypedef(char *name, char *eqname, DataType *t) {
void emit_ptr_equivalence(FILE *f) { void emit_ptr_equivalence(FILE *f) {
EqEntry *e1,*e2; EqEntry *e1,*e2;
DOH *k;
void typeeq_standard(); void typeeq_standard();
String ttable; String ttable;
@ -867,8 +871,9 @@ void emit_ptr_equivalence(FILE *f) {
*/\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";
e1 = (EqEntry *) typeeq_hash.first(); k = Firstkey(typeeq_hash);
while (e1) { while (k) {
e1 = (EqEntry *) GetVoid(typeeq_hash,k);
e2 = e1->next; e2 = e1->next;
// Walk through the equivalency list // Walk through the equivalency list
while (e2) { while (e2) {
@ -878,7 +883,7 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
ttable << tab4 << "{ \"" << e1->name << "\",\"" << e2->name << "\",0},\n"; ttable << tab4 << "{ \"" << e1->name << "\",\"" << e2->name << "\",0},\n";
e2 = e2->next; e2 = e2->next;
} }
e1 = (EqEntry *) typeeq_hash.next(); k = Nextkey(typeeq_hash);
} }
ttable << "{0,0,0}};\n"; ttable << "{0,0,0}};\n";
fprintf(f_wrappers,"%s\n", ttable.get()); fprintf(f_wrappers,"%s\n", ttable.get());
@ -895,8 +900,9 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
<< " void *(*convert)(void *);\n" << " void *(*convert)(void *);\n"
<< "} SwigType;\n"; << "} SwigType;\n";
e1 = (EqEntry *) typeeq_hash.first(); k = Firstkey(typeeq_hash);
while (e1) { while (k) {
e1 = (EqEntry *) GetVoid(typeeq_hash,k);
e2 = e1->next; e2 = e1->next;
ctable << "static SwigType " << e1->name << "[] = {"; ctable << "static SwigType " << e1->name << "[] = {";
// Walk through the equivalency list // Walk through the equivalency list
@ -909,7 +915,7 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
e2 = e2->next; e2 = e2->next;
} }
ctable << "{0,0}};\n"; ctable << "{0,0}};\n";
e1 = (EqEntry *) typeeq_hash.next(); k = Nextkey(typeeq_hash);
} }
ctable << "*/\n"; ctable << "*/\n";
fprintf(f_wrappers,"%s\n", ctable.get()); fprintf(f_wrappers,"%s\n", ctable.get());
@ -993,14 +999,17 @@ check_equivalent(DataType *t) {
static String out; static String out;
int npointer = t->is_pointer; int npointer = t->is_pointer;
String m; String m;
DOH *k;
out = ""; out = "";
while (t->is_pointer >= t->implicit_ptr) { while (t->is_pointer >= t->implicit_ptr) {
m = t->print_mangle(); m = t->print_mangle();
if (!te_init) typeeq_init(); if (!te_init) typeeq_init();
e1 = (EqEntry *) typeeq_hash.first();
while (e1) { k = Firstkey(typeeq_hash);
while (k) {
e1 = (EqEntry *) GetVoid(typeeq_hash,k);
/* printf("'%s', '%s'\n", m.get(),e1->name); */ /* printf("'%s', '%s'\n", m.get(),e1->name); */
if (strcmp(m.get(),e1->name) == 0) { if (strcmp(m.get(),e1->name) == 0) {
e2 = e1->next; e2 = e1->next;
@ -1017,7 +1026,7 @@ check_equivalent(DataType *t) {
e2 = e2->next; e2 = e2->next;
} }
} }
e1 = (EqEntry *) typeeq_hash.next(); k = Nextkey(typeeq_hash);
} }
t->is_pointer--; t->is_pointer--;
} }
@ -1033,19 +1042,19 @@ check_equivalent(DataType *t) {
// work across multiple files. // work across multiple files.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static Hash bases; static DOHHash *bases = 0;
void DataType::record_base(char *derived, char *base) void DataType::record_base(char *derived, char *base)
{ {
Hash *nh; DOHHash *nh;
nh = (Hash *) bases.lookup(derived); if (!bases) bases = NewHash();
nh = Getattr(bases,derived);
if (!nh) { if (!nh) {
nh = new Hash(); nh = NewHash();
bases.add(derived, (void *) nh); Setattr(bases,derived,nh);
} }
if (!nh->lookup(base)) { if (!Getattr(nh,base)) {
char *bn = copy_string(base); Setattr(nh,base,base);
nh->add(base,(void *) bn);
} }
} }
@ -1056,46 +1065,51 @@ void DataType::record_base(char *derived, char *base)
// construct a big table of pointer values at the end. // construct a big table of pointer values at the end.
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
static Hash remembered; static DOHHash *remembered = 0;
void DataType::remember() { void DataType::remember() {
Hash *h; DOHHash *h;
DataType *t = new DataType(this); DataType *t = new DataType(this);
remembered.add(t->print_mangle(),(void *) t);
if (!remembered) remembered = NewHash();
SetVoid(remembered, t->print_mangle(), t);
if (!bases) bases = NewHash();
/* Now, do the base-class hack */ /* Now, do the base-class hack */
h = (Hash *) bases.lookup(t->name); h = Getattr(bases,t->name);
if (h) { if (h) {
char *key; DOH *key;
key = h->firstkey(); key = Firstkey(h);
while (key) { while (key) {
DataType *nt = new DataType(t); DataType *nt = new DataType(t);
strcpy(nt->name,key); strcpy(nt->name,Char(key));
if (!remembered.lookup(nt->print_mangle())) if (!Getattr(remembered,nt->print_mangle()))
nt->remember(); nt->remember();
delete nt; delete nt;
key = h->nextkey(); key = Nextkey(h);
} }
} }
} }
void void
emit_type_table() { emit_type_table() {
char *key; DOH *key;
String types, table; String types, table;
int i = 0; int i = 0;
if (!remembered) remembered = NewHash();
table << "static _swig_type_info *_swig_types_initial[] = {\n"; table << "static _swig_type_info *_swig_types_initial[] = {\n";
key = remembered.firstkey(); 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", key, i); fprintf(f_runtime,"#define SWIGTYPE%s _swig_types[%d] \n", Char(key), i);
types << "static _swig_type_info _swigt_" << key << "[] = {"; types << "static _swig_type_info _swigt_" << Char(key) << "[] = {";
types << "{\"" << key << "\",0},"; types << "{\"" << Char(key) << "\",0},";
types << "{\"" << key << "\",0},"; types << "{\"" << Char(key) << "\",0},";
types << check_equivalent((DataType *)remembered.lookup(key)) << "};\n"; types << check_equivalent((DataType *)GetVoid(remembered,key)) << "};\n";
table << "_swigt_" << key << ", \n"; table << "_swigt_" << Char(key) << ", \n";
key = remembered.nextkey(); key = Nextkey(remembered);
i++; i++;
} }

View file

@ -53,6 +53,7 @@ Swig_banner(DOHFile *f) {
* changes to this file unless you know what you are doing--modify the SWIG \n\ * changes to this file unless you know what you are doing--modify the SWIG \n\
* interface file instead. \n\ * interface file instead. \n\
* ----------------------------------------------------------------------------- */\n\n", SWIG_VERSION, SWIG_SPIN); * ----------------------------------------------------------------------------- */\n\n", SWIG_VERSION, SWIG_SPIN);
} }