Since I have made several changes to SWIG over the years to accomodate

special cases and other things in wxPython, and since I plan on making
several more, I've decided to put the SWIG sources in wxPython's CVS
instead of relying on maintaining patches.  This effectivly becomes a
fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
doesn't have some things I rely on in 1.1, not to mention that my
custom patches would all have to be redone, I felt that this is the
easier road to take.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15307 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2002-04-29 19:56:57 +00:00
parent 3bd1e03385
commit c90f71dd8c
135 changed files with 51307 additions and 1 deletions

View File

@@ -0,0 +1,105 @@
#######################################################################
# $Header$
# Simplified Wrapper and Interface Generator (SWIG)
#
# Makefile for version 1.0 Final
# Dave Beazley
# August 1, 1996
#
# This makefile is now mostly constructed by ./configure.
#
# $Log$
# Revision 1.1 2002/04/29 19:56:47 RD
# Since I have made several changes to SWIG over the years to accomodate
# special cases and other things in wxPython, and since I plan on making
# several more, I've decided to put the SWIG sources in wxPython's CVS
# instead of relying on maintaining patches. This effectivly becomes a
# fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
# doesn't have some things I rely on in 1.1, not to mention that my
# custom patches would all have to be redone, I felt that this is the
# easier road to take.
#
# Revision 1.2 1999/08/17 03:31:30 beazley
# Minor cleanup. Removed Perl4
#
# Revision 1.1.1.1 1999/02/28 02:00:50 beazley
# Swig1.1
#
# Revision 1.1 1996/08/12 01:55:02 dmb
# Initial revision
#
#######################################################################
#.KEEP_STATE:
srcdir = @srcdir@
VPATH = @srcdir@
# Set your C++ compiler here. g++ works on most machines,
# but you might have to change it depending on your installation.
#
CC = @CXX@
#
# Set the prefix below to indicate where you want SWIG to install its
# files. Normally this is /usr/local
#
prefix = @prefix@
# Location of the SWIG library. Is normally put in /usr/local/lib/swig_lib
# The SWIG library contains configuration files and library modules
# so you should install it someplace where it can be easily accessed.
SWIG_LIB = $(prefix)/lib/swig_lib
########################################################################
# Normally, you shouldn't have to change anything below this point #
########################################################################
WRAPOBJS = swigmain.o tcl.o tcl8.o perl5.o python.o pycpp.o guile.o debug.o
WRAPSRCS = swigmain.cxx tcl.cxx tcl8.cxx perl5.cxx python.cxx pycpp.cxx guile.cxx debug.cxx
WRAPHEADERS = ../Include/swig.h swigtcl.h perl5.h python.h guile.h debug.h wrap.h
TARGET = ../wxswig
##-DSWIG_LIB='"$(SWIG_LIB)"'
CFLAGS = @CFLAGS@ -DSWIG_CC='"$(CC)"' @DEFS@
INCLUDE = -I../Include -I../SWIG
LIBS = -L.. -lswig
SHELL = /bin/sh
#
#
#
# Rules for creation of a .o file from .cxx
.SUFFIXES: .cxx
.cxx.o:
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
all: $(TARGET)
$(TARGET): $(WRAPOBJS) $(WRAPHEADERS) ../libswig.a
$(CC) $(INCLUDE) $(WRAPOBJS) $(LIBS) -o $(TARGET)
swigmain.o: swigmain.cxx
tcl.o: tcl.cxx
perl5.o: perl5.cxx
python.o: python.cxx
pycpp.o: pycpp.cxx
guile.o: guile.cxx
Makefile: $(srcdir)/Makefile.in ../config.status
(cd ..; CONFIG_FILES=Modules/Makefile $(SHELL) config.status)
.PRECIOUS: Makefile
clean::
rm -f *.o $(TARGET)
nuke::
rm -f Makefile *~ #* core a.out
wc::
wc $(WRAPSRCS) *.h

View File

@@ -0,0 +1,198 @@
/*******************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
*******************************************************************************/
/**************************************************************************
* $Header$
*
* debug.cxx
*
* This is a dummy language module that is used only for testing the SWIG
* parser.
*
* It creates a wrapper file, but only containing descriptions of what
* was wrapped.
*
***************************************************************************/
#include "swig.h"
#include "debug.h"
void DEBUGLANG::parse_args(int, char **) {
sprintf(LibDir,"%s",path);
typemap_lang = "debug";
}
void DEBUGLANG::parse() {
headers();
yyparse();
}
void DEBUGLANG::set_module(char *mod_name, char **) {
if (module) return;
module = new char[strlen(mod_name)+1];
strcpy(module,mod_name);
}
void DEBUGLANG::set_init(char *init_name) {
set_module(init_name,0);
}
void DEBUGLANG::headers(void) {
fprintf(f_header,"/* DEBUG : Language specific headers go here */\n\n");
fprintf(f_header,"/* DEBUG : Pointer conversion function here */\n\n");
fprintf(f_header,"/* DEBUG : Language specific code here */\n\n");
}
void DEBUGLANG::initialize(void) {
fprintf(f_header,"#define SWIG_init %s_init\n\n", module);
fprintf(f_header,"#define SWIG_name \"%s\"\n", module);
fprintf(f_init,"\n/* MODULE INITIALIZATION */\n\n");
fprintf(f_init,"void %s_init() {\n", module);
}
void DEBUGLANG::close(void) {
fprintf(f_init,"} /* END INIT */\n");
fprintf(f_wrappers,"SWIG POINTER-MAPPING TABLE\n\n");
emit_ptr_equivalence(f_init);
}
void DEBUGLANG::create_function(char *name, char *iname, DataType *d, ParmList *l) {
fprintf(f_wrappers,"WRAPPER : ");
emit_extern_func(name,d,l,0,f_wrappers);
fprintf(f_wrappers,"\n");
fprintf(f_init," ADD COMMAND : %s --> ", iname);
emit_extern_func(name,d,l,0,f_init);
}
void DEBUGLANG::link_variable(char *name, char *iname, DataType *t) {
fprintf(f_wrappers,"WRAPPER : ");
emit_extern_var(name,t,0,f_wrappers);
fprintf(f_init," ADD VARIABLE : %s --> ", iname);
emit_extern_var(name,t,0,f_init);
}
void DEBUGLANG::declare_const(char *name, char *, DataType *type, char *value) {
if (!value) value = "[None]";
fprintf(f_init," ADD CONSTANT : %s %s = %s\n", type->print_cast(),name,value);
}
void DEBUGLANG::add_native(char *name, char *funcname) {
fprintf(f_init," ADD NATIVE : %s --> %s\n", name, funcname);
}
void DEBUGLANG::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l) {
fprintf(f_wrappers," MEMBER FUNC : ");
emit_extern_func(name,t,l,0,f_wrappers);
fprintf(f_wrappers,"\n");
if (!iname) iname = name;
fprintf(f_init," ADD MEMBER FUN : %s --> ", iname);
emit_extern_func(name,t,l,0,f_init);
}
void DEBUGLANG::cpp_constructor(char *name, char *iname, ParmList *l) {
DataType *t;
fprintf(f_wrappers," CONSTRUCTOR : ");
t = new DataType(T_USER);
sprintf(t->name,"%s",name);
t->is_pointer=1;
emit_extern_func(name,t,l,0,f_wrappers);
if (!iname) iname = name;
fprintf(f_init," ADD CONSTRUCT : %s --> ", iname);
emit_extern_func(name,t,l,0,f_init);
}
void DEBUGLANG::cpp_destructor(char *name, char *iname) {
fprintf(f_wrappers," DESTRUCTOR : ~%s();\n", name);
if (!iname) iname = name;
fprintf(f_init," ADD DESTRUCT : %s --> ~%s();\n",iname,name);
}
void DEBUGLANG::cpp_open_class(char *name, char *iname, char *ctype, int strip) {
this->Language::cpp_open_class(name, iname, ctype,strip);
fprintf(f_wrappers,"C++ CLASS START : %s %s ========================================\n\n",ctype,name);
fprintf(f_init,"\n // C++ CLASS START : %s %s\n",ctype,name);
}
void DEBUGLANG::cpp_close_class() {
fprintf(f_wrappers,"C++ CLASS END ===================================================\n\n");
fprintf(f_init," // C++ CLASS END \n\n");
}
void DEBUGLANG::cpp_inherit(char **baseclass, int) {
int i = 0;
if (baseclass) {
fprintf(f_wrappers,"inheriting from baseclass :");
while (baseclass[i]) {
fprintf(f_wrappers," %s",baseclass[i]);
i++;
}
fprintf(f_wrappers,"\n");
}
this->Language::cpp_inherit(baseclass);
}
void DEBUGLANG::cpp_variable(char *name, char *iname, DataType *t) {
fprintf(f_wrappers," ATTRIBUTE : ");
emit_extern_var(name,t,0,f_wrappers);
if (!iname) iname = name;
fprintf(f_init," ADD MEMBER : %s --> ", iname);
emit_extern_var(name,t,0,f_init);
}
void DEBUGLANG::cpp_static_func(char *name, char *iname, DataType *t, ParmList *l) {
fprintf(f_wrappers," STATIC FUNC : ");
emit_extern_func(name,t,l,0,f_wrappers);
fprintf(f_init," ADD STATIC FUNC: %s --> ", iname);
emit_extern_func(name,t,l,0,f_init);
}
void DEBUGLANG::cpp_declare_const(char *name, char *iname, DataType *t, char *value) {
if (!value) value = "[None]";
fprintf(f_wrappers," C++ CONST : %s %s = %s\n", t->print_cast(), name, value);
if (!iname) iname = name;
fprintf(f_init," ADD C++ CONST : %s --> %s = %s\n", iname, t->print_cast(), value);
}
void DEBUGLANG::cpp_static_var(char *name, char *iname, DataType *t) {
fprintf(f_wrappers," C++ STATIC VAR: ");
emit_extern_var(name,t,0,f_wrappers);
if (!iname) iname = name;
fprintf(f_init," ADD STATIC VAR : %s --> ",iname);
emit_extern_var(name,t,0,f_init);
}
void DEBUGLANG::pragma(char *lname, char *name, char *value) {
fprintf(f_wrappers,"PRAGMA : LANG = %s, NAME = %s ", lname, name);
if (value) {
fprintf(f_wrappers,", VALUE = %s\n", value);
} else {
fprintf(f_wrappers,"\n");
}
}
void DEBUGLANG::cpp_class_decl(char *name, char *, char *type) {
fprintf(f_wrappers,"C++ CLASS DECLARATION : %s %s\n", type,name);
}

View File

@@ -0,0 +1,52 @@
/*******************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
*******************************************************************************/
class DEBUGLANG : public Language {
private:
char *path;
char *module;
public:
DEBUGLANG() {
path = "debug";
module = "swig";
}
void parse_args(int argc, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *) ;
void declare_const(char *, char *, DataType *, char *);
void initialize(void);
void headers(void);
void close(void);
void set_module(char *mod_name, char **mod_list);
void set_init(char *init_name);
void add_native(char *, char *);
char *type_mangle(DataType *t) {
return t->print_mangle_default();
}
void cpp_member_func(char *, char *, DataType *, ParmList *);
void cpp_constructor(char *, char *, ParmList *);
void cpp_destructor(char *, char *);
void cpp_open_class(char *, char *, char *, int strip);
void cpp_close_class();
void cpp_inherit(char **, int mode = INHERIT_ALL);
void cpp_variable(char *, char *, DataType *);
void cpp_static_func(char *, char *, DataType *, ParmList *);
void cpp_declare_const(char *, char *, DataType *, char *);
void cpp_static_var(char *, char *, DataType *);
void pragma(char *, char *, char *);
void cpp_class_decl(char *, char *, char *);
};

View File

@@ -0,0 +1,841 @@
/*******************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* guile.cxx
*
* Definitions for adding functions to Guile 3.0
***********************************************************************/
#include "swig.h"
#include "guile.h"
static char *guile_usage = "\
Guile Options (available with -guile)\n\
None available. \n\n";
// ---------------------------------------------------------------------
// GUILE::parse_args(int argc, char *argv[])
//
// Parse arguments.
// ---------------------------------------------------------------------
void GUILE::parse_args(int argc, char *argv[]) {
int i;
sprintf(LibDir,"%s",guile_path);
// Look for certain command line options
// Look for additional command line options.
for (i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i],"-help") == 0) {
fputs(guile_usage,stderr);
SWIG_exit(0);
}
}
}
// Add a symbol for this module
add_symbol("SWIGGUILE",0,0);
// Set name of typemaps
typemap_lang = "guile";
}
// --------------------------------------------------------------------
// GUILE::parse()
//
// Parse the input file
// --------------------------------------------------------------------
void GUILE::parse()
{
printf("Generating wrappers for Guile\n");
// Print out GUILE specific headers
headers();
// Run the parser
yyparse();
}
// ---------------------------------------------------------------------
// GUILE::set_module(char *mod_name)
//
// Sets the module name.
// Does nothing if it's already set (so it can be overridden as a command
// line option).
//
//----------------------------------------------------------------------
void GUILE::set_module(char *mod_name, char **) {
if (module) return;
module = new char[strlen(mod_name)+1];
strcpy(module,mod_name);
}
// ---------------------------------------------------------------------
// GUILE::set_init(char *iname)
//
// Sets the initialization function name.
// Does nothing if it's already set
//
//----------------------------------------------------------------------
void GUILE::set_init(char *iname) {
set_module(iname,0);
}
// ---------------------------------------------------------------------
// GUILE::headers(void)
//
// Generate the appropriate header files for GUILE interface.
// ----------------------------------------------------------------------
void GUILE::headers(void)
{
emit_banner(f_header);
fprintf(f_header,"/* Implementation : GUILE */\n\n");
fprintf(f_header,"#define SWIGGUILE\n");
fprintf(f_header,"#include <stdio.h>\n");
fprintf(f_header,"#include <string.h>\n");
fprintf(f_header,"#include <stdlib.h>\n");
// Write out hex conversion functions
if (!NoInclude) {
if (insert_file("guile.swg", f_header) == -1) {
fprintf(stderr,"SWIG : Fatal error. Unable to locate 'guile.swg' in SWIG library.\n");
SWIG_exit(1);
}
emit_hex(f_header);
} else {
fprintf(f_header,"#ifdef __cplusplus\n");
fprintf(f_header,"extern \"C\" {\n");
fprintf(f_header,"#endif\n");
fprintf(f_header,"extern void SWIG_MakePtr(char *, void *, char *);\n");
fprintf(f_header,"extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));\n");
fprintf(f_header,"extern char *SWIG_GetPtr(char *, void **, char *);\n");
fprintf(f_header,"#ifdef __cplusplus\n");
fprintf(f_header,"}\n");
fprintf(f_header,"#endif\n");
}
}
// --------------------------------------------------------------------
// GUILE::initialize()
//
// Output initialization code that registers functions with the
// interface.
// ---------------------------------------------------------------------
void GUILE::initialize()
{
int i;
if (!module) {
module = "swig_init";
fprintf(stderr,"SWIG : *** Warning. No module name specified.\n");
}
fprintf(f_header,"#define SWIG_init %s\n\n", module);
fprintf(f_init,"void %s() {\n", module);
if (InitNames) {
i = 0;
while (InitNames[i]) {
fprintf(f_init,"\t %s();\n",InitNames[i]);
i++;
}
}
}
// ---------------------------------------------------------------------
// GUILE::close(void)
//
// Wrap things up. Close initialization function.
// ---------------------------------------------------------------------
void GUILE::close(void)
{
emit_ptr_equivalence(f_init);
fprintf(f_init,"}\n");
}
// ----------------------------------------------------------------------
// GUILE::get_pointer(int parm, DataType *t)
//
// Emits code to get a pointer from a parameter and do type checking.
// parm is the parameter number. This function is only used
// in create_function().
// ----------------------------------------------------------------------
void GUILE::get_pointer(char *iname, int parm, DataType *t) {
// Pointers are read as hex-strings with encoded type information
fprintf(f_wrappers,"\t _tempc = gh_scm2newstr(s_%d, &_len);\n",parm);
fprintf(f_wrappers,"\t if (SWIG_GetPtr(_tempc, (void **) &_arg%d,",parm);
if (t->type == T_VOID) fprintf(f_wrappers,"(char *) 0)) {\n");
else
fprintf(f_wrappers,"\"%s\")) {\n", t->print_mangle());
// Now emit code according to the level of strictness desired
switch(TypeStrict) {
case 0: // No type checking
fprintf(f_wrappers,"\t}\n");
break;
case 1: // Warning message only
fprintf(f_wrappers,
"\t fprintf(stderr,\"Warning : type mismatch in argument %d of %s. Expected %s, received %%s\\n\", _tempc);\n", parm+1,iname, t->print_mangle());
fprintf(f_wrappers,"\t }\n");
break;
case 2: // Super strict mode.
// fprintf(f_wrappers,"\t\t gscm_error(\"Type error in argument %d of %s. Expected %s.\", s_%d);\n", parm+1,iname,t->print_mangle(),parm);
fprintf(f_wrappers,"\t}\n");
break;
default :
fprintf(stderr,"Unknown strictness level\n");
break;
}
}
// ----------------------------------------------------------------------
// GUILE::create_function(char *name, char *iname, DataType *d,
// ParmList *l)
//
// Create a function declaration and register it with the interpreter.
// ----------------------------------------------------------------------
void GUILE::create_function(char *name, char *iname, DataType *d, ParmList *l)
{
Parm *p;
int pcount;
char wname[256];
char source[64];
char target[64];
char *tm;
String cleanup;
int need_len = 0;
int need_tempc = 0;
// Make a wrapper name for this
strcpy(wname,iname);
make_wrap_name(wname);
// Now write the wrapper function itself....this is pretty ugly
fprintf(f_wrappers,"SCM _wrap_gscm_%s(",wname);
int i = 0;
p = l->get_first();
while (p != 0) {
if (p->t->is_pointer)
need_len = 1;
if ((p->t->type != T_CHAR) && (p->t->is_pointer))
need_tempc = 1;
if ((p->t->type != T_VOID) || (p->t->is_pointer))
fprintf(f_wrappers,"SCM s_%d", i);
if ((p = l->get_next()))
fprintf(f_wrappers,", ");
i++;
}
fprintf(f_wrappers,")\n{\n");
// Declare return variable and arguments
pcount = emit_args(d,l,f_wrappers);
// Now declare a few helper variables here
if (d->is_pointer && (d->type != T_CHAR) &&
!typemap_lookup("out","guile",d,name,"_result","scmresult"))
fprintf(f_wrappers," char _ptemp[128];\n");
if (need_tempc)
fprintf(f_wrappers," char *_tempc;\n");
if (need_len)
fprintf(f_wrappers," int _len;\n");
fprintf(f_wrappers," SCM scmresult; /* fun1 */\n");
// Now write code to extract the parameters(this is super ugly)
i = 0;
p = l->get_first();
while (p != 0) {
// Produce names of source and target
sprintf(source,"s_%d",i);
sprintf(target,"_arg%d",i);
if ((tm = typemap_lookup("in","guile",p->t,p->name,source,target))) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n", tm);
} else {
if (!p->t->is_pointer) {
switch(p->t->type) {
// Signed Integers
case T_INT :
case T_SINT :
case T_SHORT:
case T_SSHORT:
case T_LONG:
case T_SLONG:
case T_SCHAR:
fprintf(f_wrappers,"\t _arg%d = %s gh_scm2long(s_%d);\n",i, p->t->print_cast(), i);
break;
// Unsigned Integers
case T_UINT:
case T_USHORT:
case T_ULONG:
case T_UCHAR:
fprintf(f_wrappers,"\t _arg%d = %s gh_scm2ulong(s_%d);\n", i, p->t->print_cast(), i);
break;
// A single character
case T_CHAR :
fprintf(f_wrappers,"\t _arg%d = %s gh_scm2char(s_%d);\n", i, p->t->print_cast(), i);
break;
// Floating point
case T_DOUBLE :
case T_FLOAT:
fprintf(f_wrappers,"\t _arg%d = %s gh_scm2double(s_%d);\n", i, p->t->print_cast(), i);
break;
// Void.. Do nothing.
case T_VOID :
break;
// This is some sort of user-defined call by value type. We're
// going to try and wing it here....
case T_USER:
// User defined type not allowed by value.
default :
fprintf(stderr,"%s : Line %d. Unable to use type %s as a function argument.\n",
input_file, line_number, p->t->print_type());
break;
}
} else {
// Argument is a pointer type. Special case is for char *
// since that is usually a string.
if ((p->t->type == T_CHAR) && (p->t->is_pointer == 1)) {
fprintf(f_wrappers,"\t _arg%d = gh_scm2newstr(s_%d, &_len);\n",i,i);
} else {
// Have a generic pointer type here.
get_pointer(iname, i, p->t);
}
}
}
if ((tm = typemap_lookup("check","guile",p->t,p->name,source,target))) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n",tm);
}
if ((tm = typemap_lookup("freearg","guile",p->t,p->name,target,"scmresult"))) {
// Yep. Use it instead of the default
cleanup << tm << "\n";
}
p = l->get_next();
i++;
}
// Now write code to make the function call
fprintf(f_wrappers,"\t SCM_DEFER_INTS;\n");
emit_func_call(name,d,l,f_wrappers);
fprintf(f_wrappers,"\t SCM_ALLOW_INTS;\n");
// Now have return value, figure out what to do with it.
if ((d->type != T_VOID) || (d->is_pointer)) {
if ((tm = typemap_lookup("out","guile",d,name,"_result","scmresult"))) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n",tm);
} else {
if (!d->is_pointer) {
switch(d->type) {
case T_INT: case T_SINT:
case T_SHORT: case T_SSHORT:
case T_LONG: case T_SLONG:
case T_SCHAR:
fprintf(f_wrappers,"\t scmresult = gh_long2scm((long) _result);\n");
break;
case T_UINT:
case T_USHORT:
case T_ULONG:
case T_UCHAR:
fprintf(f_wrappers,"\t scmresult = gh_ulong2scm((unsigned long) _result);\n");
break;
case T_DOUBLE :
case T_FLOAT:
fprintf(f_wrappers,"\t scmresult = gh_double2scm((double) _result);\n");
break;
case T_CHAR :
fprintf(f_wrappers,"\t scmresult = gh_char2scm(_result);\n");
break;
default:
fprintf(stderr,"%s : Line %d: Unable to use return type %s in function %s.\n",
input_file, line_number, d->print_type(), name);
break;
}
} else {
// Is a pointer return type
if ((d->type == T_CHAR) && (d->is_pointer == 1)) {
fprintf(f_wrappers,"\t scmresult = gh_str02scm(_result);\n");
} else {
// Is an ordinary pointer type.
fprintf(f_wrappers,"\t SWIG_MakePtr(_ptemp, _result,\"%s\");\n",
d->print_mangle());
fprintf(f_wrappers,"\t scmresult = gh_str02scm(_ptemp);\n");
}
}
}
} else {
/* Some void type. Need to return something. I'll return 1 */
fprintf(f_wrappers,"\t scmresult = gh_int2scm(1);\n");
}
// Dump the argument cleanup code
fprintf(f_wrappers,"%s\n",cleanup.get());
// Look for any remaining cleanup
if (NewObject) {
if ((tm = typemap_lookup("newfree","guile",d,iname,"_result",""))) {
fprintf(f_wrappers,"%s\n",tm);
}
}
if ((tm = typemap_lookup("ret","guile",d,name,"_result",""))) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n",tm);
}
// Wrap things up (in a manner of speaking)
fprintf(f_wrappers,"\t return scmresult;\n");
fprintf(f_wrappers,"}\n");
// Now register the function
fprintf(f_init,"\t gh_new_procedure(\"%s\", _wrap_gscm_%s, %d, 0, 0);\n",
iname, wname, pcount);
// Make a documentation entry for this
if (doc_entry) {
static DocEntry *last_doc_entry = 0;
char *usage = 0;
usage_func(iname,d,l,&usage);
doc_entry->usage << usage;
if (last_doc_entry != doc_entry) {
doc_entry->cinfo << "returns " << d->print_type();
last_doc_entry = doc_entry;
}
delete usage;
}
}
// -----------------------------------------------------------------------
// GUILE::link_variable(char *name, char *iname, DataType *d)
//
// Create a link to a C variable.
// This creates a single function _wrap_gscm_var_varname().
// This function takes a single optional argument. If supplied, it means
// we are setting this variable to some value. If ommitted, it means we are
// simply evaluating this variable. Either way, we return the variables
// value.
// -----------------------------------------------------------------------
void GUILE::link_variable(char *name, char *iname, DataType *t)
{
char var_name[256];
char *tm;
char *tm2 = typemap_lookup("varout","guile",t,name,name,"scmresult");
// evaluation function names
sprintf(var_name,"_wrap_gscm_var_%s",iname);
if ((t->type != T_USER) || (t->is_pointer)) {
fprintf(f_wrappers,"SCM %s(SCM s_0) {\n", var_name);
if (!(Status & STAT_READONLY) && (t->is_pointer)) {
fprintf(f_wrappers,"\t char *_temp;\n");
fprintf(f_wrappers,"\t int _len;\n");
}
if (tm2) {
fprintf(f_wrappers,"\t char _ptemp[128];\n");
}
fprintf(f_wrappers,"\t SCM scmresult; /* fun2 */\n");
// Check for a setting of the variable value
fprintf(f_wrappers,"\t if (s_0 != GH_NOT_PASSED) {\n");
// Yup. Extract the type from s_0 and set variable value
if (Status & STAT_READONLY) {
// fprintf(f_wrappers,"\t\t gscm_error(\"Unable to set %s. Variable is read only.\", s_0);\n", iname);
} else {
if ((tm = typemap_lookup("varin","guile",t,name,"s_0",name))) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n",tm);
} else {
if (!t->is_pointer) {
switch(t->type) {
// Signed Integer
case T_INT: case T_SINT:
case T_SHORT: case T_SSHORT:
case T_LONG: case T_SLONG:
case T_SCHAR:
fprintf(f_wrappers,"\t\t %s = %s gh_scm2long(s_0);\n",name, t->print_cast());
break;
// Unsigned integer
case T_UINT:
case T_USHORT:
case T_ULONG:
case T_UCHAR:
fprintf(f_wrappers,"\t\t %s = %s gh_scm2ulong(s_0);\n",name, t->print_cast());
break;
// Floating point
case T_FLOAT:
case T_DOUBLE:
fprintf(f_wrappers,"\t\t %s = %s gh_scm2double(s_0);\n",name, t->print_cast());
break;
// Character value
case T_CHAR:
fprintf(f_wrappers,"\t\t %s = gh_scm2char(s_0);\n", name);
break;
// Unknown value
default:
fprintf(stderr,"Line %d. Error, unsupported data-type.\n", line_number);
break;
}
} else {
// Have some sort of pointer type here, Process it differently
if ((t->type == T_CHAR) && (t->is_pointer == 1)) {
fprintf(f_wrappers,"\t\t _temp = gh_scm2newstr(s_0, &_len);\n");
fprintf(f_wrappers,"\t\t if (%s) { free(%s);}\n", name,name);
fprintf(f_wrappers,"\t\t %s = (char *) malloc((_len+1)*sizeof(char));\n",name);
fprintf(f_wrappers,"\t\t strncpy(%s,_temp,_len);\n",name);
fprintf(f_wrappers,"\t\t %s[_len] = 0;\n", name);
} else {
// Set the value of a pointer
fprintf(f_wrappers,"\t\t _temp = gh_scm2newstr(s_0,&_len);\n");
fprintf(f_wrappers,"\t if (SWIG_GetPtr(_temp, (void **) &%s,",name);
if (t->type == T_VOID) fprintf(f_wrappers,"(char *) 0)) {\n");
else
fprintf(f_wrappers,"\"%s\")) {\n", t->print_mangle());
// Now emit code according to the level of strictness desired
switch(TypeStrict) {
case 0: // No type checking
fprintf(f_wrappers,"\t}\n");
break;
case 1: // Warning message only
fprintf(f_wrappers,
"\t fprintf(stderr,\"Warning : type mismatch in variable %s. Expected %s, received %%s\\n\", _temp);\n", name, t->print_mangle());
fprintf(f_wrappers,"\t }\n");
break;
case 2: // Super strict mode.
// fprintf(f_wrappers,"\t\t gscm_error(\"Type error in variable %s. Expected %s.\", s_0);\n", name,t->print_mangle());
fprintf(f_wrappers,"\t}\n");
break;
default :
fprintf(stderr,"Unknown strictness level\n");
break;
}
}
}
}
}
fprintf(f_wrappers,"\t}\n");
// Now return the value of the variable (regardless of evaluating or setting)
if (tm2) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n",tm);
} else {
if (!t->is_pointer) {
/* Return variable by value */
switch(t->type) {
// Signed Integer
case T_INT: case T_SINT:
case T_SHORT: case T_SSHORT:
case T_LONG: case T_SLONG:
case T_SCHAR:
fprintf(f_wrappers,"\t scmresult = gh_long2scm((long) %s);\n", name);
break;
// Unsigned integer
case T_UINT:
case T_USHORT:
case T_ULONG:
case T_UCHAR:
fprintf(f_wrappers,"\t scmresult = gh_ulong2scm((unsigned long) %s);\n",name);
break;
// Floats
case T_DOUBLE:
case T_FLOAT:
fprintf(f_wrappers,"\t scmresult = gh_double2scm((double) %s);\n", name);
break;
case T_CHAR:
fprintf(f_wrappers,"\t scmresult = gh_char2scm(%s);\n",name);
break;
default :
/* Unknown type */
break;
}
} else {
// Is a pointer return type
if ((t->type == T_CHAR) && (t->is_pointer == 1)) {
fprintf(f_wrappers,"\t scmresult = gh_str02scm(%s);\n",name);
} else {
// Is an ordinary pointer type.
fprintf(f_wrappers,"\t SWIG_MakePtr(_ptemp, %s,\"%s\");\n",name,
t->print_mangle());
fprintf(f_wrappers,"\t scmresult = gh_str02scm(_ptemp);\n");
}
}
}
fprintf(f_wrappers,"\t return scmresult;\n");
fprintf(f_wrappers,"}\n");
// Now add symbol to the Guile interpreter
fprintf(f_init,"\t gh_new_procedure(\"%s\", %s, 0, 1, 0);\n",iname, var_name);
} else {
fprintf(stderr,"%s : Line %d. ** Warning. Unable to link with type %s (ignored).\n",
input_file, line_number, t->print_type());
}
// Add a documentation entry
if (doc_entry) {
char *usage = 0;
usage_var(iname,t,&usage);
doc_entry->usage << usage;
doc_entry->cinfo << "Global : " << t->print_type() << " " << name;
delete usage;
}
}
// -----------------------------------------------------------------------
// GUILE::declare_const(char *name, char *iname, DataType *type, char *value)
//
// Makes a constant. Not sure how this is really supposed to work.
// I'm going to fake out SWIG and create a variable instead.
// ------------------------------------------------------------------------
void GUILE::declare_const(char *name, char *, DataType *type, char *value) {
int OldStatus = Status; // Save old status flags
char var_name[256];
Status = STAT_READONLY; // Enable readonly mode.
// Make a static variable;
sprintf(var_name,"_wrap_const_%s",name);
if ((type->type == T_USER) && (!type->is_pointer)) {
fprintf(stderr,"%s : Line %d. Unsupported constant value.\n", input_file, line_number);
return;
}
// Create variable and assign it a value
fprintf(f_header,"static %s %s = ", type->print_type(), var_name);
if ((type->type == T_CHAR) && (type->is_pointer <= 1)) {
fprintf(f_header,"\"%s\";\n", value);
} else {
fprintf(f_header,"%s;\n", value);
}
// Now create a variable declaration
link_variable(var_name, name, type);
Status = OldStatus;
if (doc_entry) {
char *usage = 0;
usage_const(name,type,value,&usage);
doc_entry->usage = "";
doc_entry->usage << usage;
doc_entry->cinfo = "";
doc_entry->cinfo << "Constant: " << type->print_type();
delete usage;
}
}
// ----------------------------------------------------------------------
// GUILE::usage_var(char *iname, DataType *t, char **s)
//
// Produces a usage string for a Guile variable.
// ----------------------------------------------------------------------
void GUILE::usage_var(char *iname, DataType *t, char **s) {
char temp[1024], *c;
sprintf(temp,"(%s)", iname);
c = temp + strlen(temp);
if (!((t->type != T_USER) || (t->is_pointer))) {
sprintf(c," - unsupported");
}
if (*s == 0)
*s = new char[strlen(temp)+1];
strcpy(*s,temp);
}
// ---------------------------------------------------------------------------
// GUILE::usage_func(char *iname, DataType *t, ParmList *l, char **s)
//
// Produces a usage string for a function in Guile
// ---------------------------------------------------------------------------
void GUILE::usage_func(char *iname, DataType *, ParmList *l,
char **s) {
char temp[1024];
char *c;
int i;
Parm *p;
sprintf(temp,"(%s ", iname);
c = temp + strlen(temp);
/* Now go through and print parameters */
p = l->get_first();
while (p != 0) {
/* If parameter has been named, use that. Otherwise, just print a type */
if ((p->t->type != T_VOID) || (p->t->is_pointer)) {
if (strlen(p->name) > 0) {
sprintf(c,"%s ",p->name);
c += strlen(p->name)+1;
}
else {
sprintf(c,"%s",p->t->name);
c += strlen(p->t->name);
if (p->t->is_pointer) {
for (i = 0; i < (p->t->is_pointer-p->t->implicit_ptr); i++) {
sprintf(c,"*");
c++;
}
}
}
}
p = l->get_next();
if (p != 0) {
sprintf(c," ");
c++;
}
}
sprintf(c,")");
if (*s == 0)
*s = new char[strlen(temp)+1];
strcpy(*s,temp);
}
// ----------------------------------------------------------------------
// GUILE::usage_const(char *iname, DataType *type, char *value, char **s)
//
// Produces a usage string for a Guile constant
// ----------------------------------------------------------------------
void GUILE::usage_const(char *iname, DataType *, char *value, char **s) {
char temp[1024];
sprintf(temp,"(%s %s)", iname, value);
if (*s == 0)
*s = new char[strlen(temp)+1];
strcpy(*s,temp);
}

View File

@@ -0,0 +1,57 @@
/*******************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
*******************************************************************************/
/**************************************************************************
* $Header$
*
* class GUILE
*
* Guile implementation
* (Caution : This is *somewhat* experimental)
*
* Seeking : highly motivated individual with plenty of spare time and
* a love of Guile. Must be willing to modify this code and
* make it better.
**************************************************************************/
class GUILE : public Language {
private:
char *guile_path;
char *module;
void get_pointer(char *iname, int parm, DataType *t);
void usage_var(char *, DataType *, char **);
void usage_func(char *, DataType *, ParmList *, char **);
void usage_const(char *, DataType *, char *, char **);
public :
GUILE() {
module = 0;
guile_path = "guile";
}
void parse_args(int, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *);
void declare_const(char *, char *, DataType *, char *);
void initialize();
void headers(void);
void close(void);
void set_module(char *, char **);
void set_init(char *);
void create_command(char *, char *) { };
};

View File

@@ -0,0 +1,79 @@
# Modified from automatic creation by Kevin Butler (butler@byu.edu)
# for Microsoft Visual C++ (11/22/96)
#
#######################################################################
# $Header$
# Simplified Wrapper and Interface Generator (SWIG)
#
# Makefile for version 1.0 Final
# Dave Beazley
# August 1, 1996
#
# This makefile is now mostly constructed by ./configure.
#
# $Log$
# Revision 1.1 2002/04/29 19:56:47 RD
# Since I have made several changes to SWIG over the years to accomodate
# special cases and other things in wxPython, and since I plan on making
# several more, I've decided to put the SWIG sources in wxPython's CVS
# instead of relying on maintaining patches. This effectivly becomes a
# fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
# doesn't have some things I rely on in 1.1, not to mention that my
# custom patches would all have to be redone, I felt that this is the
# easier road to take.
#
# Revision 1.2 1999/08/17 03:31:30 beazley
# Minor cleanup. Removed Perl4
#
# Revision 1.1.1.1 1999/02/28 02:00:50 beazley
# Swig1.1
#
# Revision 1.1 1996/08/12 01:55:02 dmb
# Initial revision
#
#######################################################################
#.KEEP_STATE:
rootdir = ..
!include <..\make_win.in>
########################################################################
# Normally, you shouldn't have to change anything below this point #
########################################################################
WRAPOBJS = swigmain.obj tcl.obj tcl8.obj perl5.obj python.obj pycpp.obj debug.obj guile.obj
WRAPSRCS = swigmain.cxx tcl.cxx tcl8.cxx perl5.cxx python.cxx pycpp.cxx debug.cxx guile.cxx
WRAPHEADERS = $(rootdir)/Include/swig.h swigtcl.h tcl8.h perl5.h python.h guile.h debug.h \
wrap.h
TARGET = $(rootdir)\wxswig.exe
LIBNAME = $(rootdir)\libswig.lib
LIBS = $(LIBNAME)
#
# Rules for creation of a .obj file from .cxx
.SUFFIXES: .cxx
.cxx.obj:
$(CC) $(INCFLAGS) $(CFLAGS) -c -o $*.obj $<
all: $(TARGET)
$(TARGET): $(WRAPOBJS) $(WRAPHEADERS) $(LIBNAME)
$(CC) -o $(TARGET) $(INCFLAGS) $(WRAPOBJS) $(LIBS)
swigmain.obj: swigmain.cxx
tcl.obj: tcl.cxx
perl5.obj: perl5.cxx
python.obj: python.cxx
pycpp.obj: pycpp.cxx
guile.obj: guile.cxx
clean::
del *.obj
del $(TARGET)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,105 @@
/****************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
****************************************************************************/
/**************************************************************************
* class PERL5
*
* A Perl 5 implementation
**************************************************************************/
class PERL5 : public Language {
private:
int export_all;
char *package;
char *module;
String cmodule;
String vinit;
FILE *f_pm;
String pm; // Package initialization code
String magic; // Magic variable wrappers
char *perl_path;
int is_static;
void get_pointer(char *iname, char *srcname, char *src, char *dest,
DataType *t, String &f, char *ret);
char *usage_var(char *, DataType *);
char *usage_func(char *, DataType *, ParmList *);
char *usage_const(char *, DataType *, char *);
char *alt_header;
// The following variables are used to manage Perl5 classes
int blessed; // Enable object oriented features
Hash classes; // A hash table for storing the classes we've seen so far
int have_constructor;
int have_destructor;
int have_data_members;
char *class_name; // Name of the class (what Perl thinks it is)
char *class_type; // Type of class "struct", "class", "union"
char *real_classname; // Real name of C/C++ class
String *base_class; // Base class (if using inheritance)
String *pcode; // Perl code associated with each class
String *blessedmembers; // Member data associated with each class
int member_func; // Set to 1 when wrapping a member function
char *realpackage; // Name of real module
String func_stubs; // Function stubs
String var_stubs; // Variable stubs
String *member_keys; // Keys for all member data
String exported; // Exported symbols
public :
PERL5() {
package = 0;
module = 0;
perl_path = "perl5";
is_static = 0;
blessed = 0;
alt_header = 0;
member_func = 0;
};
void parse_args(int, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *);
void declare_const(char *, char *, DataType *, char *);
void initialize(void);
void headers(void);
void close(void);
void set_module(char *, char **);
void set_init(char *);
void add_native(char *, char *);
void create_command(char *, char *);
char *type_mangle(DataType *);
// Support for blessed perl thingies....
void cpp_open_class(char *classname, char *rename, char *ctype, int strip);
void cpp_close_class();
void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
void cpp_static_func(char *name, char *iname, DataType *t, ParmList *l);
void cpp_variable(char *name, char *iname, DataType *t);
void cpp_constructor(char *name, char *iname, ParmList *l);
void cpp_destructor(char *name, char *newname);
void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
void cpp_class_decl(char *, char *, char *);
void add_typedef(DataType *t, char *name);
void pragma(char *, char *, char *);
void import(char *filename);
};

View File

@@ -0,0 +1,517 @@
/*******************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
*******************************************************************************/
/**********************************************************************
* $Header$
*
* pycpp.cxx
*
* This module contains code to generate Python shadow classes of C/C++
* objects.
**************************************************************************/
#include "swig.h"
#include "python.h"
static String *setattr;
static String *getattr;
static String *pyclass;
static String *construct;
static String *cinit;
static String *additional;
static int have_constructor;
static int have_destructor;
static int have_getattr;
static int have_setattr;
static int have_repr;
static char *class_name;
static char *class_type;
static char *real_classname;
static String *base_class;
static String base_getattr;
static String base_setattr;
static int class_renamed = 0;
// --------------------------------------------------------------------------
// PYTHON::cpp_open_class(char *classname, char *rname, char *ctype, int strip)
//
// Opens a new C++ class or structure.
// --------------------------------------------------------------------------
void PYTHON::cpp_open_class(char *classname, char *rname, char *ctype, int strip) {
char temp[256];
this->Language::cpp_open_class(classname, rname, ctype, strip);
if (shadow) {
/* Create new strings for building up a wrapper function */
setattr = new String();
getattr = new String();
pyclass = new String();
construct = new String();
cinit = new String();
additional= new String();
base_class = 0;
base_getattr = "";
base_setattr = "";
// *pyclass << "class " << rname << ":\n";
*setattr << tab4 << "def __setattr__(self,name,value):\n";
*getattr << tab4 << "def __getattr__(self,name):\n";
have_constructor = 0;
have_destructor = 0;
have_getattr = 0;
have_setattr = 0;
have_repr = 0;
if (rname) {
class_name = copy_string(rname);
class_renamed = 1;
} else {
class_name = copy_string(classname);
class_renamed = 0;
}
}
real_classname = copy_string(classname);
class_type = copy_string(ctype);
// Build up the hash table
hash.add(real_classname,copy_string(class_name));
sprintf(temp,"%s %s", class_type, real_classname);
hash.add(temp,copy_string(class_name));
}
// --------------------------------------------------------------------------
// PYTHON::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l)
//
// Creates a C++ member function
// --------------------------------------------------------------------------
void PYTHON::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l) {
Parm *p;
int i;
char *realname;
int oldshadow;
int pcount;
int numopt;
int have_optional;
String cname = "python:";
String translate = "";
// Create the default member function
oldshadow = shadow; // Disable shadowing when wrapping member functions
if (shadow) shadow = shadow | PYSHADOW_MEMBER;
this->Language::cpp_member_func(name,iname,t,l);
shadow = oldshadow;
if (shadow) {
if (!iname)
realname = name;
else
realname = iname;
// Check to see if we've already seen this
cname << class_name << "::" << realname;
if (add_symbol(cname.get(), 0,0)) {
return; // Forget it, already saw it
}
if (strcmp(realname,"__repr__") == 0)
have_repr = 1;
// Now add it to the class
*pyclass << tab4 << "def " << realname << "(self, *_args, **_kwargs):\n";
// Create a doc string
if (docstring && doc_entry) {
*pyclass << tab8 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n";
}
*pyclass << tab8 << "val = apply(" << module << "." << name_member(realname,class_name) << ",(self,) + _args, _kwargs)\n";
// Check to see if the return type is an object
if ((hash.lookup(t->name)) && (t->is_pointer <= 1)) {
if (!typemap_check("out",typemap_lang,t,name_member(realname,class_name))) {
if (!have_output) {
*pyclass << tab8 << "if val: val = " << (char *) hash.lookup(t->name) << "Ptr(val) ";
if (((hash.lookup(t->name)) && (t->is_pointer < 1)) ||
((hash.lookup(t->name)) && (t->is_pointer == 1) && NewObject))
*pyclass << "; val.thisown = 1\n";
else
*pyclass << "\n";
} else {
// Do nothing!
}
}
}
emitAddPragmas(*pyclass, realname, tab8);
*pyclass << tab8 << "return val\n";
// Change the usage string to reflect our shadow class
if (doc_entry) {
doc_entry->usage = "";
doc_entry->usage << usage_func(realname,t,l);
}
}
}
// -----------------------------------------------------------------------------
// void PYTHON::cpp_constructor(char *name, char *iname, ParmList *l)
//
// Make a constructor for our class
// -----------------------------------------------------------------------------
void PYTHON::cpp_constructor(char *name, char *iname, ParmList *l) {
char *realname;
Parm *p;
int i;
int oldshadow = shadow;
String cname = "python:constructor:";
String translate = "";
int pcount, numopt;
int have_optional;
if (shadow) shadow = shadow | PYSHADOW_MEMBER;
this->Language::cpp_constructor(name,iname,l);
shadow = oldshadow;
if (shadow) {
if (iname)
realname = iname;
else {
if (class_renamed) realname = class_name;
else realname = class_name;
}
// Check to see if we've already seen this
cname << class_name << "::" << realname;
if (add_symbol(cname.get(), 0,0)) {
return; // Forget it, already seen it
}
if (!have_constructor) {
// Create a new constructor
*construct << tab4 << "def __init__(self,*_args,**_kwargs):\n";
if (docstring && doc_entry)
*construct << tab8 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n";
*construct << tab8 << "self.this = apply(" << module << "." << name_construct(realname) << ",_args,_kwargs)\n";
*construct << tab8 << "self.thisown = 1\n";
emitAddPragmas(*construct,"__init__",tab8);
have_constructor = 1;
} else {
// Hmmm. We seem to be creating a different constructor. We're just going to create a
// function for it.
*additional << "def " << realname << "(*_args,**_kwargs):\n";
*additional << tab4 << "val = " << class_name << "Ptr(apply("
<< module << "." << name_construct(realname) << ",_args,_kwargs))\n"
<< tab4 << "val.thisown = 1\n";
emitAddPragmas(*additional, realname, tab4);
*additional << tab4 << "return val\n\n";
}
// Patch up the documentation entry
if (doc_entry) {
doc_entry->usage = "";
doc_entry->usage << usage_func(class_name,0,l);
}
}
}
// ------------------------------------------------------------------------------
// void PYTHON::cpp_destructor(char *name, char *newname)
//
// Creates a destructor for this object
// ------------------------------------------------------------------------------
void PYTHON::cpp_destructor(char *name, char *newname) {
char *realname;
int oldshadow = shadow;
if (shadow) shadow = shadow | PYSHADOW_MEMBER;
this->Language::cpp_destructor(name,newname);
shadow = oldshadow;
if (shadow) {
if (newname) realname = newname;
else {
if (class_renamed) realname = class_name;
else realname = name;
}
*pyclass << tab4 << "def __del__(self," << module << "=" << module << "):\n";
emitAddPragmas(*pyclass,"__del__",tab8);
*pyclass << tab8 << "if self.thisown == 1 :\n"
<< tab8 << tab4 << module << "." << name_destroy(realname) << "(self)\n";
have_destructor = 1;
if (doc_entry) {
doc_entry->usage = "";
doc_entry->usage << "del this";
}
}
}
// -------------------------------------------------------------------------------
// PYTHON::cpp_close_class()
//
// Closes a Python class and writes out a wrapper
// -------------------------------------------------------------------------------
void PYTHON::cpp_close_class() {
String ptrclass;
String repr;
if (shadow) {
if (!have_constructor) {
// Build a constructor that takes a pointer to this kind of object
*construct << tab4 << "def __init__(self,this):\n";
*construct << tab8 << "self.this = this\n";
}
// First, build the pointer base class
if (base_class) {
ptrclass << "class " << class_name << "Ptr(" << *base_class << "):\n";
} else {
ptrclass << "class " << class_name << "Ptr :\n";
}
// *getattr << tab8 << "return self.__dict__[name]\n";
*getattr << tab8 << "raise AttributeError,name\n";
*setattr << tab8 << "self.__dict__[name] = value\n";
ptrclass << *cinit
<< tab4 << "def __init__(self,this):\n"
<< tab8 << "self.this = this\n"
<< tab8 << "self.thisown = 0\n";
classes << ptrclass
<< *pyclass;
if (have_setattr)
classes << *setattr;
if (have_getattr)
classes << *getattr;
if (!have_repr) {
// Supply a repr method for this class
repr << tab4 << "def __repr__(self):\n"
<< tab8 << "return \"<C " << class_name <<" instance at %s>\" % (self.this,)\n";
classes << repr;
emitAddPragmas(classes,"__class__",tab4);
}
// Now build the real class with a normal constructor
classes << "class " << class_name << "(" << class_name << "Ptr):\n";
if (docstring && doc_entry) {
classes << tab4 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n";
}
classes << *construct << "\n\n"
<< "\n" << *additional << "\n";
delete pyclass;
delete setattr;
delete getattr;
delete additional;
}
}
void PYTHON::cpp_cleanup() { };
void PYTHON::cpp_inherit(char **baseclass,int) {
char *bc;
int i = 0, first_base = 0;
if (!shadow) {
this->Language::cpp_inherit(baseclass);
return;
}
// We'll inherit variables and constants, but not methods
this->Language::cpp_inherit(baseclass, INHERIT_VAR);
if (!baseclass) return;
base_class = new String;
// Now tell the Python module that we're inheriting from a base class
while (baseclass[i]) {
bc = (char *) hash.lookup(baseclass[i]);
if (bc) {
if (first_base) *base_class << ",";
*base_class << bc << "Ptr";
first_base = 1;
}
i++;
}
if (!first_base) {
delete base_class;
base_class = 0;
}
}
// --------------------------------------------------------------------------------
// PYTHON::cpp_variable(char *name, char *iname, DataType *t)
//
// Adds an instance member.
// --------------------------------------------------------------------------------
void PYTHON::cpp_variable(char *name, char *iname, DataType *t) {
char *realname;
int inhash = 0;
int oldshadow = shadow;
String cname = "python:";
if (shadow) shadow = shadow | PYSHADOW_MEMBER;
this->Language::cpp_variable(name,iname,t);
shadow = oldshadow;
if (shadow) {
have_getattr = 1;
have_setattr = 1;
if (!iname)
realname = name;
else
realname = iname;
// Check to see if we've already seen this
cname << class_name << "::" << realname;
if (add_symbol(cname.get(), 0,0)) {
return; // Forget it, already seen it
}
// Figure out if we've seen this datatype before
if ((hash.lookup(t->name)) && (t->is_pointer <= 1)) inhash = 1;
// Now write some code to set the variable
*setattr << tab8 << "if name == \"" << realname << "\" :\n";
if (inhash) {
*setattr << tab8 << tab4 << module << "." << name_set(name_member(realname,class_name)) << "(self,value.this)\n";
} else {
*setattr << tab8 << tab4 << module << "." << name_set(name_member(realname,class_name)) << "(self,value)\n";
}
*setattr << tab8 << tab4 << "return\n";
// Write some code to get the variable
*getattr << tab8 << "if name == \"" << realname << "\" : \n";
if (inhash) {
*getattr << tab8 << tab4 << "return " << (char *) hash.lookup(t->name) << "Ptr(" << module << "."
<< name_get(name_member(realname,class_name)) << "(self))\n";
} else {
*getattr << tab8 << tab4 << "return " << module << "." << name_get(name_member(realname,class_name)) << "(self)\n";
}
// Patch up ye old documentation entry
if (doc_entry) {
doc_entry->usage = "";
doc_entry->usage << "self." << realname;
}
}
}
// --------------------------------------------------------------------------------
// PYTHON::cpp_declare_const(char *name, char *iname, DataType *type, char *value)
//
// Add access to a C++ constant
// --------------------------------------------------------------------------------
void PYTHON::cpp_declare_const(char *name, char *iname, DataType *type, char *value) {
char *realname;
int oldshadow = shadow;
String cname = "python:";
if (shadow) shadow = shadow | PYSHADOW_MEMBER;
this->Language::cpp_declare_const(name,iname,type,value);
shadow = oldshadow;
if (shadow) {
if (!iname)
realname = name;
else
realname = iname;
// Check to see if we've already seen this
cname << class_name << "::" << realname;
if (add_symbol(cname.get(), 0,0)) {
return; // Forget it, already seen it
}
*cinit << tab4 << realname << " = " << module << "." << name_member(realname,class_name) << "\n";
if (doc_entry) {
doc_entry->usage = "";
doc_entry->usage << "self." << realname;
if (value) {
doc_entry->usage << " = " << value;
}
}
}
}
// --------------------------------------------------------------------------------
// PYTHON::add_typedef(DataType *t, char *name)
//
// This is called whenever a typedef is encountered. When shadow classes are
// used, this function lets us discovered hidden uses of a class. For example :
//
// struct FooBar {
// ...
// }
//
// typedef FooBar *FooBarPtr;
//
// --------------------------------------------------------------------------------
void PYTHON::add_typedef(DataType *t, char *name) {
if (!shadow) return;
// First check to see if there aren't too many pointers
if (t->is_pointer > 1) return;
if (hash.lookup(name)) return; // Already added
// Now look up the datatype in our shadow class hash table
if (hash.lookup(t->name)) {
// Yep. This datatype is in the hash
// Put this types 'new' name into the hash
hash.add(name,copy_string((char *) hash.lookup(t->name)));
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
/*******************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
*******************************************************************************/
/**************************************************************************
* $Header$
*
* python.h
*
* Header file for Python module. Warning ; this is work in progress.
**************************************************************************/
class PYTHON : public Language {
protected:
char *module; // Module name
char *path; // Pathname of where to look for library files
char *methods; // Method table name
char *global_name; // Name of global variables.
void get_pointer(char *iname, char *srcname, char *src, char *dest, DataType *t, String &f, char *ret);
int shadow;
int have_defarg;
int docstring;
int have_output;
int use_kw;
FILE *f_shadow;
struct Method { // Methods list. Needed to build methods
char *name; // Array at very end.
char *function;
Method *next;
};
Method *head;
Hash hash;
String classes;
String func;
String vars;
String modinit;
String modextern;
char *import_file;
void add_method(char *name, char *function);
void print_methods();
char *usage_var(char *, DataType *);
char *usage_func(char *, DataType *, ParmList *);
char *usage_const(char *, DataType *, char *);
char *add_docstring(DocEntry *de);
// Add for Python-COM support
virtual void initialize_cmodule();
virtual void close_cmodule();
virtual void emit_function_header(WrapperFunction &emit_to, char *wname);
virtual char *convert_self(WrapperFunction &f);
virtual char *make_funcname_wrapper(char *fnName);
void emitAddPragmas(String& output, char* name, char* spacing);
public :
PYTHON() {
module = (char *) 0;
path = "python"; // Set this to subdirectory where language
// Dependent library files will be stored
head = 0; // Head of method list
global_name = "cvar";
shadow = 0;
have_defarg = 0;
import_file = 0;
use_kw = 0;
};
// Don't change any of this
void parse_args(int, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *);
void declare_const(char *, char *, DataType *, char *);
void initialize(void);
void headers(void);
void close(void);
void set_module(char *, char **);
void set_init(char *);
void add_native(char *, char *);
void create_command(char *, char *);
void import(char *);
// C++ extensions---for creating shadow classes
void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
void cpp_constructor(char *name, char *iname, ParmList *l);
void cpp_destructor(char *name, char *newname);
void cpp_open_class(char *classname, char *rname, char *ctype, int strip);
void cpp_close_class();
void cpp_cleanup();
void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
void cpp_variable(char *name, char *iname, DataType *t);
void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
void cpp_class_decl(char *, char *,char *);
void pragma(char *, char *, char *);
void cpp_pragma(Pragma *);
void add_typedef(DataType *t, char *name);
};
#define PYSHADOW_MEMBER 0x2

View File

@@ -0,0 +1,168 @@
/*******************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* swigmain.cxx
*
* The main program.
*
***********************************************************************/
#include "wrap.h"
#include "swigtcl.h"
#include "tcl8.h"
#include "perl5.h"
#include "python.h"
// #include "pythoncom.h"
#include "guile.h"
#include "debug.h"
#include "ascii.h"
#include "latex.h"
#include "html.h"
#include "nodoc.h"
#include <ctype.h>
static char *usage = "\
swig <options> filename\n\n\
Target Language Options:\n\
-tcl - Generate Tcl wrappers.\n\
-tcl8 - Generate Tcl 8.0 wrappers.\n\
-python - Generate Python wrappers.\n\
-perl5 - Generate Perl5 wrappers.\n\
-guile - Generate Guile wrappers.\n\
-debug - Parser debugging module.\n";
#ifdef MACSWIG
static char *macmessage = "\
Copyright (c) 1995-1997\n\
University of Utah and the Regents of the University of California\n\n\
Enter SWIG processing options and filename below. For example :\n\
\n\
-tcl -c++ interface.i\n\
\n\
-help displays a list of all available options.\n\
\n\
Note : Macintosh filenames should be enclosed in quotes if they contain whitespace.\n\
\n";
#endif
//-----------------------------------------------------------------
// main()
//
// Main program. Initializes the files and starts the parser.
//-----------------------------------------------------------------
#ifndef MACSWIG
int main(int argc, char **argv) {
#else
int Mac_main(int argc, char **argv) {
#endif
int i;
Language *dl = new SWIG_LANG;
Documentation *dd = new SWIG_DOC;
extern int SWIG_main(int, char **, Language *, Documentation *);
init_args(argc,argv);
// Get options
for (i = 1; i < argc; i++) {
if (argv[i]) {
if(strcmp(argv[i],"-tcl") == 0) {
dl = new TCL;
mark_arg(i);
} else if (strcmp(argv[i],"-tcl8") == 0) {
dl = new TCL8;
mark_arg(i);
} else if (strcmp(argv[i],"-perl5") == 0) {
dl = new PERL5;
mark_arg(i);
} else if (strcmp(argv[i],"-python") == 0) {
dl = new PYTHON;
mark_arg(i);
} else if (strcmp(argv[i],"-debug") == 0) {
dl = new DEBUGLANG;
mark_arg(i);
} else if (strcmp(argv[i],"-guile") == 0) {
dl = new GUILE;
mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
mark_arg(i);
}
}
}
SWIG_main(argc,argv,dl,dd);
return 0;
}
#ifdef MACSWIG
int MacMainEntry(char *options) {
static char *_argv[256];
int i,argc;
char *c,*s,*t;
swig_log = fopen("swig_log","w");
fprintf(swig_log,"SWIG 1.1\n");
fprintf(swig_log,"Options : %s\n", options);
fprintf(swig_log,"-----------------------------------------------------\n");
// Tokenize the user input
_argv[0] = "swig";
i=1;
c = options;
while (*c) {
while(isspace(*c)) c++;
if (*c) {
s = c; // Starting character
while(isgraph(*c)) {
if (*c == '\"') {
c++;
while ((*c) && (*c != '\"'))
c++;
c++;
} else {
c++;
}
}
// Found some whitespace
if (*c) {
*c = 0;
c++;
}
_argv[i] = copy_string(s);
// Go through and remove quotes (if necessary)
t = _argv[i];
while(*s) {
if (*s != '\"')
*(t++) = *s;
s++;
}
*t = 0;
i++;
}
}
argc = i;
_argv[i] = 0;
return Mac_main(argc,_argv);
}
#endif

View File

@@ -0,0 +1,115 @@
/*******************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
*******************************************************************************/
/**************************************************************************
* class TCL
*
* A Simple TCL implementation.
**************************************************************************/
class TCL : public Language {
private:
char interp_name[256];
char *prefix; // Package prefix
char *module; // Name of the module
char *tcl_path;
char *init_name;
int Plugin;
int nspace;
char *safe_name;
void get_pointer(char *iname, char *srcname, char *src, char *dest, DataType *t,
String &f, char *ret);
char *char_result;
char *usage_string(char *, DataType *, ParmList *);
char *usage_func(char *, DataType *, ParmList *);
char *usage_var(char *, DataType *);
char *usage_const(char *, DataType *, char *);
// C++ handling
int have_constructor;
int have_destructor;
int have_methods;
int have_config;
int have_cget;
String config;
String cget;
String methods;
String options;
String config_options;
String methodnames;
String postinit;
int shadow;
char *class_name;
char *class_type;
char *real_classname;
char *base_class;
Hash hash;
Hash repeatcmd;
// C++ Code generation strings
String delcmd;
String methodcmd;
String objcmd;
public :
TCL() {
prefix = 0;
module = 0;
init_name = 0;
nspace = 0;
shadow = 1;
char_result = "TCL_VOLATILE";
tcl_path = "tcl";
sprintf(interp_name,"interp");
class_name = 0;
class_type = 0;
real_classname = 0;
base_class = 0;
};
void parse_args(int, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *);
void declare_const(char *, char *, DataType *, char *);
void initialize(void);
void headers(void);
void close(void);
void set_module(char *,char **);
void set_init(char *);
void add_native(char *, char *);
void pragma(char *,char *, char *);
void create_command(char *, char *);
// Stubs for processing C++ classes in Tcl
void cpp_open_class(char *classname, char *rename, char *ctype, int strip);
void cpp_close_class();
void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
void cpp_variable(char *name, char *iname, DataType *t);
void cpp_constructor(char *name, char *iname, ParmList *l);
void cpp_destructor(char *name, char *newname);
void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
void cpp_class_decl(char *, char *, char *);
void add_typedef(DataType *, char *);
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,115 @@
/*******************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
*******************************************************************************/
/**************************************************************************
* class TCL8
*
* A TCL implementation for Tcl 8.0. Basically the same as the other
* Tcl module, but with different code generation.
**************************************************************************/
class TCL8 : public Language {
private:
char interp_name[256];
char *prefix; // Package prefix
char *module; // Name of the module
char *tcl_path;
char *init_name;
int nspace;
void get_pointer(char *iname, char *srcname, char *src, char *dest, DataType *t,
String &f, char *ret);
char *char_result;
char *usage_func(char *, DataType *, ParmList *);
char *usage_string(char *, DataType *, ParmList *);
char *usage_var(char *, DataType *);
char *usage_const(char *, DataType *, char *);
// C++ handling
int have_constructor;
int have_destructor;
int have_methods;
int have_config;
int have_cget;
String config;
String cget;
String methods;
String options;
String config_options;
String methodnames;
String postinit;
int shadow;
char *class_name;
char *class_type;
char *real_classname;
char *base_class;
Hash hash;
Hash repeatcmd;
// Code generation options
String delcmd;
String methodcmd;
String objcmd;
public :
TCL8() {
prefix = 0;
module = 0;
init_name = 0;
nspace = 0;
shadow = 1;
char_result = "TCL_VOLATILE";
tcl_path = "tcl";
sprintf(interp_name,"interp");
class_name = 0;
class_type = 0;
real_classname = 0;
base_class = 0;
};
void parse_args(int, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *);
void declare_const(char *, char *, DataType *, char *);
void initialize(void);
void headers(void);
void close(void);
void set_module(char *,char **);
void set_init(char *);
void add_native(char *, char *);
void pragma(char *,char *, char *);
void create_command(char *, char *);
// Stubs for processing C++ classes in Tcl
void cpp_open_class(char *classname, char *rename, char *ctype, int strip);
void cpp_close_class();
void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
void cpp_variable(char *name, char *iname, DataType *t);
void cpp_constructor(char *name, char *iname, ParmList *l);
void cpp_destructor(char *name, char *newname);
void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
void add_typedef(DataType *, char *);
void cpp_class_decl(char *, char *, char *);
};

View File

@@ -0,0 +1,38 @@
/*******************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* wrap.h
***********************************************************************/
#include "swig.h"
#ifndef SWIG_LIB
#define SWIG_LIB getSwigLib() /*"./swig_lib"*/
#endif
#ifndef SWIG_LANG
#define SWIG_LANG PYTHON
#endif
#ifndef SWIG_DOC
#define SWIG_DOC ASCII
#endif