Added Java

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@64 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-01-12 17:33:21 +00:00
commit 99b646f6b3
28 changed files with 1664 additions and 1160 deletions

View file

@ -32,8 +32,8 @@ SWIG_LIB = $(prefix)/lib/swig1.3
# Normally, you shouldn't have to change anything below this point #
########################################################################
WRAPOBJS = swigmain.o tcl8.o perl5.o python.o pycpp.o guile.o debug.o
WRAPSRCS = swigmain.cxx tcl8.cxx perl5.cxx python.cxx pycpp.cxx guile.cxx debug.cxx
WRAPOBJS = swigmain.o tcl8.o perl5.o python.o pycpp.o guile.o java.o ascii.o html.o
WRAPSRCS = swigmain.cxx tcl8.cxx perl5.cxx python.cxx pycpp.cxx guile.cxx java.cxx ascii.cxx html.cxx
TARGET = ../swig
CFLAGS = @CFLAGS@ -DSWIG_LIB='"$(SWIG_LIB)"' -DSWIG_CC='"$(CC)"' @DEFS@

View file

@ -1,201 +0,0 @@
/*******************************************************************************
* 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.
*******************************************************************************/
static char cvsroot[] = "$Header$";
/**************************************************************************
* $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

@ -1,52 +0,0 @@
/*******************************************************************************
* 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

@ -39,17 +39,17 @@ public :
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 *) { };
virtual void parse_args(int, char *argv[]);
virtual void parse();
virtual void create_function(char *, char *, DataType *, ParmList *);
virtual void link_variable(char *, char *, DataType *);
virtual void declare_const(char *, char *, DataType *, char *);
virtual void initialize();
virtual void headers(void);
virtual void close(void);
virtual void set_module(char *, char **);
virtual void set_init(char *);
virtual void create_command(char *, char *) { };
};

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,89 @@
// ------------------------------------------------------------------------
// A Java SWIG Language module
//
// ------------------------------------------------------------------------
class JAVA : public Language {
private:
char *module; // Name of the module
char *java_path;
char *package; // Name of the package
char *c_pkgstr; // Name of the package
char *jni_pkgstr; // Name of the package
char *shadow_classname;
char *jimport;
char *method_modifiers;
FILE *f_java;
FILE *f_shadow;
int shadow;
Hash shadow_classes;
String shadow_classdef;
char *shadow_name;
char *shadow_baseclass;
int classdef_emitted;
int shadow_classdef_emitted;
int have_default_constructor;
int native_func; // Set to 1 when wrapping a native function
int member_func; // Set to 1 when wrapping a member function
int jnic; // 1: use c syntax jni; 0: use c++ syntax jni
int finalize; // generate finalize methods
int useRegisterNatives; // Set to 1 when doing stuff with register natives
String registerNativesList;
public :
JAVA() {
module = NULL;
package = NULL;
java_path = "java";
f_java = f_shadow = NULL;
native_func = shadow = member_func = 0;
jimport = shadow_name = shadow_baseclass = NULL;
method_modifiers = "public final static";
jnic = -1;
useRegisterNatives=0;
finalize=0;
};
// Virtual functions required by the SWIG parser
void parse_args(int, char *argv[]);
void parse();
void add_native(char *, char *, DataType *, ParmList *);
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 create_command(char *, char *);
void pragma(char *lang, char *code, char *value);
void add_typedef(DataType *t, char *name);
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_constructor(char *name, char *iname, ParmList *l);
void cpp_destructor(char *name, char *newname);
void cpp_class_decl(char *name, char *rename, char *type);
void cpp_inherit(char **baseclass, int);
void cpp_variable(char *name, char *iname, DataType *t);
void cpp_static_var(char *, char *, class DataType *);
void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
/* Java Module methods */
void emit_classdef();
void emit_shadow_classdef();
char *JNICALL(char *func);
char *JNICALL(String& func);
char *SwigTcToJniType(DataType *t, int ret);
char *SwigTcToJavaType(DataType *t, int ret, int inShadow);
char *SwigTcToJniScalarType(DataType *t);
char *JavaTypeFromTypemap(char *op, char *lang, DataType *t, char *pname);
char *makeValidJniName(char *name);
char *JavaMethodSignature(DataType *t, int ret, int inShadow);
void writeRegisterNatives();
};

View file

@ -127,11 +127,11 @@ PERL5::parse_args(int argc, char *argv[]) {
if (argv[i+1]) {
package = new char[strlen(argv[i+1])+1];
strcpy(package, argv[i+1]);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-module") == 0) {
if (argv[i+1]) {
@ -139,21 +139,21 @@ PERL5::parse_args(int argc, char *argv[]) {
strcpy(module, argv[i+1]);
cmodule = module;
cmodule.replace(":","_");
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-exportall") == 0) {
export_all = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-static") == 0) {
is_static = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-shadow") == 0) {
blessed = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-hide") == 0) {
if (argv[i+1]) {
hide = new char[strlen(argv[i+1])+1];
@ -161,24 +161,24 @@ PERL5::parse_args(int argc, char *argv[]) {
chide = hide;
chide.replace(":","_");
hidden = 1;
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-alt-header") == 0) {
if (argv[i+1]) {
alt_header = copy_string(argv[i+1]);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-compat") == 0) {
compat = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
}
@ -1574,12 +1574,12 @@ char *PERL5::usage_const(char *iname, DataType *, char *value) {
}
// -----------------------------------------------------------------------
// PERL5::add_native(char *name, char *funcname)
// PERL5::add_native(char *name, char *funcname, DataType *, ParmList *)
//
// Add a native module name to Perl5.
// -----------------------------------------------------------------------
void PERL5::add_native(char *name, char *funcname) {
void PERL5::add_native(char *name, char *funcname, DataType *, ParmList *) {
fprintf(f_init,"\t newXS(\"%s::%s\", %s, file);\n", package,name, funcname);
if (export_all)
exported << name << " ";

View file

@ -74,35 +74,35 @@ public :
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 *);
virtual void parse_args(int, char *argv[]);
virtual void parse();
virtual void create_function(char *, char *, DataType *, ParmList *);
virtual void link_variable(char *, char *, DataType *);
virtual void declare_const(char *, char *, DataType *, char *);
virtual void initialize(void);
virtual void headers(void);
virtual void close(void);
virtual void set_module(char *, char **);
virtual void set_init(char *);
virtual void add_native(char *, char *, DataType *, ParmList *);
virtual void create_command(char *, char *);
virtual 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);
virtual void cpp_open_class(char *classname, char *rename, char *ctype, int strip);
virtual void cpp_close_class();
virtual void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
virtual void cpp_static_func(char *name, char *iname, DataType *t, ParmList *l);
virtual void cpp_variable(char *name, char *iname, DataType *t);
virtual void cpp_constructor(char *name, char *iname, ParmList *l);
virtual void cpp_destructor(char *name, char *newname);
virtual void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
virtual void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
virtual void cpp_class_decl(char *, char *, char *);
virtual void add_typedef(DataType *t, char *name);
virtual void pragma(char *, char *, char *);
virtual void import(char *filename);
};

View file

@ -68,31 +68,31 @@ void PYTHON::parse_args(int argc, char *argv[]) {
if (argv[i+1]) {
module = new char[strlen(argv[i+1])+2];
strcpy(module, argv[i+1]);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i+=1;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-globals") == 0) {
if (argv[i+1]) {
global_name = new char[strlen(argv[i+1])+1];
strcpy(global_name, argv[i+1]);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-shadow") == 0) {
shadow = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-docstring") == 0) {
docstring = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-keyword") == 0) {
use_kw = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
}
@ -1496,12 +1496,12 @@ char *PYTHON::usage_const(char *iname, DataType *, char *value) {
}
// -----------------------------------------------------------------------
// PYTHON::add_native(char *name, char *funcname)
// PYTHON::add_native(char *name, char *funcname, DataType *, ParmList *)
//
// Add a native module name to the methods list.
// -----------------------------------------------------------------------
void PYTHON::add_native(char *name, char *funcname) {
void PYTHON::add_native(char *name, char *funcname, DataType *, ParmList *) {
add_method(name, funcname);
if (shadow) {
func << name << " = " << module << "." << name << "\n\n";

View file

@ -76,35 +76,35 @@ public :
};
// 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 *);
virtual void parse_args(int, char *argv[]);
virtual void parse();
virtual void create_function(char *, char *, DataType *, ParmList *);
virtual void link_variable(char *, char *, DataType *);
virtual void declare_const(char *, char *, DataType *, char *);
virtual void initialize(void);
virtual void headers(void);
virtual void close(void);
virtual void set_module(char *, char **);
virtual void set_init(char *);
virtual void add_native(char *, char *, DataType *, ParmList *);
virtual void create_command(char *, char *);
virtual 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);
virtual void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
virtual void cpp_constructor(char *name, char *iname, ParmList *l);
virtual void cpp_destructor(char *name, char *newname);
virtual void cpp_open_class(char *classname, char *rname, char *ctype, int strip);
virtual void cpp_close_class();
virtual void cpp_cleanup();
virtual void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
virtual void cpp_variable(char *name, char *iname, DataType *t);
virtual void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
virtual void cpp_class_decl(char *, char *,char *);
virtual void pragma(char *, char *, char *);
virtual void cpp_pragma(Pragma *);
virtual void add_typedef(DataType *t, char *name);
};
#define PYSHADOW_MEMBER 0x2

View file

@ -27,9 +27,9 @@ static char cvsroot[] = "$Header$";
#include "wrap.h"
#include "tcl8.h"
#include "perl5.h"
#include "java.h"
#include "python.h"
#include "guile.h"
#include "debug.h"
#include "ascii.h"
#include "html.h"
#include "nodoc.h"
@ -41,8 +41,12 @@ Target Language Options:\n\
-tcl - Generate Tcl wrappers.\n\
-python - Generate Python wrappers.\n\
-perl5 - Generate Perl5 wrappers.\n\
-guile - Generate Guile wrappers.\n\
-debug - Parser debugging module.\n";
-java - Generate Java wrappers.\n\
-guile - Generate Guile wrappers.\n\n\
Documentation Options\n\
-dascii - ASCII documentation.\n\
-dhtml - HTML documentation.\n\
-dnone - No documentation.\n";
#ifdef MACSWIG
static char *macmessage = "\
@ -77,7 +81,7 @@ int Mac_main(int argc, char **argv) {
Documentation *dd = new SWIG_DOC;
extern int SWIG_main(int, char **, Language *, Documentation *);
init_args(argc,argv);
SWIG_init_args(argc,argv);
// Get options
for (i = 1; i < argc; i++) {
@ -85,28 +89,39 @@ int Mac_main(int argc, char **argv) {
if(strcmp(argv[i],"-tcl") == 0) {
fprintf(stderr,"swig: -tcl option now implies -tcl8\n");
dl = new TCL8;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-tcl8") == 0) {
dl = new TCL8;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-perl5") == 0) {
dl = new PERL5;
mark_arg(i);
SWIG_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);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-guile") == 0) {
dl = new GUILE;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-java") == 0) {
dl = new JAVA;
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-dascii") == 0) {
dd = new ASCII;
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-dnone") == 0) {
dd = new NODOC;
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-dhtml") == 0) {
dd = new HTML;
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
mark_arg(i);
SWIG_mark_arg(i);
}
}
}
if (!dd) dd = new ASCII;
SWIG_main(argc,argv,dl,dd);
return 0;
}

View file

@ -62,30 +62,30 @@ void TCL8::parse_args(int argc, char *argv[]) {
if (argv[i+1]) {
prefix = new char[strlen(argv[i+1])+2];
strcpy(prefix, argv[i+1]);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-module") == 0) {
if (argv[i+1]) {
set_module(argv[i+1],0);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-namespace") == 0) {
nspace = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-old") == 0) {
shadow = 0;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-noobject") == 0) {
shadow = 0;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
}
@ -1271,14 +1271,14 @@ char *TCL8::usage_const(char *name, DataType *, char *value) {
}
// -------------------------------------------------------------------
// TCL8::add_native(char *name, char *funcname)
// TCL8::add_native(char *name, char *funcname, DataType *t, ParmList *l)
//
// This adds an already written Tcl wrapper function to our
// initialization function.
// -------------------------------------------------------------------
void TCL8::add_native(char *name, char *funcname) {
void TCL8::add_native(char *name, char *funcname, DataType *, ParmList *) {
fprintf(f_init,"\t Tcl_CreateCommand(%s, SWIG_prefix \"%s\", %s, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);\n",interp_name, name, funcname);

View file

@ -66,32 +66,32 @@ public :
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 *);
virtual void parse_args(int, char *argv[]);
virtual void parse();
virtual void create_function(char *, char *, DataType *, ParmList *);
virtual void link_variable(char *, char *, DataType *);
virtual void declare_const(char *, char *, DataType *, char *);
virtual void initialize(void);
virtual void headers(void);
virtual void close(void);
virtual void set_module(char *,char **);
virtual void set_init(char *);
virtual void add_native(char *, char *, DataType *, ParmList *);
virtual void pragma(char *,char *, char *);
virtual 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 *);
virtual void cpp_open_class(char *classname, char *rename, char *ctype, int strip);
virtual void cpp_close_class();
virtual void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
virtual void cpp_variable(char *name, char *iname, DataType *t);
virtual void cpp_constructor(char *name, char *iname, ParmList *l);
virtual void cpp_destructor(char *name, char *newname);
virtual void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
virtual void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
virtual void add_typedef(DataType *, char *);
virtual void cpp_class_decl(char *, char *, char *);
};

View file

@ -1,29 +1,5 @@
#######################################################################
# $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.2 2000/01/12 04:56:27 beazley
# Removed latex
#
# Revision 1.1 2000/01/11 20:08:16 beazley
# First checkin
#
# Revision 1.2 1999/11/14 02:42:56 beazley
# Initial 1.3 checkin
#
# Revision 1.1.1.1 1999/02/28 02:00:51 beazley
# Swig1.1
#
# Revision 1.1 1996/08/12 01:55:02 dmb
# Initial revision
#
#######################################################################
#.KEEP_STATE:
@ -63,13 +39,13 @@ AR = @AR@
# Normally, you shouldn't have to change anything below this point #
########################################################################
LIBOBJS = main.o scanner.o symbol.o include.o types.o parms.o emit.o newdoc.o ascii.o \
html.o cplus.o lang.o hash.o sstring.o wrapfunc.o getopt.o comment.o \
LIBOBJS = main.o scanner.o symbol.o types.o include.o parms.o emit.o newdoc.o \
cplus.o lang.o hash.o sstring.o wrapfunc.o comment.o \
typemap.o naming.o
LIBSRCS = main.cxx scanner.cxx symbol.cxx include.cxx types.cxx parms.cxx emit.cxx \
newdoc.cxx ascii.cxx html.cxx cplus.cxx lang.cxx hash.cxx \
sstring.cxx wrapfunc.cxx getopt.cxx comment.cxx typemap.cxx naming.cxx
newdoc.cxx cplus.cxx lang.cxx hash.cxx \
sstring.cxx wrapfunc.cxx comment.cxx typemap.cxx naming.cxx
PARSER = parser.y
INCLUDE = -I../Include -I. -I../Core -I../Preprocessor -I../DOH/Include

View file

@ -583,61 +583,61 @@ void CommentHandler::parse_args(int argc, char **argv) {
if (argv[i]) {
if (strcmp(argv[i],"-Sbefore") == 0) {
this->style("before",0);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-Safter") == 0) {
this->style("after",0);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-Schop_top") == 0) {
if (argv[i+1]) {
this->style("chop_top",argv[i+1]);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-Schop_bottom") == 0) {
if (argv[i+1]) {
this->style("chop_bottom",argv[i+1]);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-Schop_left") == 0) {
if (argv[i+1]) {
this->style("chop_left",argv[i+1]);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-Schop_right") == 0) {
if (argv[i+1]) {
this->style("chop_right",argv[i+1]);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-Sskip") == 0) {
if (argv[i+1]) {
this->style("skip",argv[i+1]);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-Suntabify") == 0) {
this->style("untabify",0);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-Stabify") == 0) {
this->style("tabify",0);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-Signore") == 0) {
this->style("ignore",0);
} else if (strcmp(argv[i],"-help") == 0) {

View file

@ -1,143 +0,0 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "internal.h"
static char cvsroot[] = "$Header$";
/*******************************************************************************
* $Header$
*
* File : getopt.cxx
*
* This file defines a few functions for handling command line arguments.
* C++ makes this really funky---especially since each language module
* may want to extract it's own command line arguments.
*
* My own special version of getopt. This is a bit weird, because we
* don't know what the options are in advance (they could be determined
* by a language module).
*******************************************************************************/
static char **args;
static int numargs;
static int *marked;
// -----------------------------------------------------------------------------
// void init_args(int argc, char **argv)
//
// Initializes the argument list.
//
// Inputs :
// argc = Argument count
// argv = Argument array
//
// Output : None
//
// Side Effects : Saves local copy of argc and argv
// -----------------------------------------------------------------------------
void
init_args(int argc, char **argv)
{
int i;
numargs = argc;
args = argv;
marked = new int[numargs];
for (i = 0; i < argc; i++) {
marked[i] = 0;
}
marked[0] = 1;
}
// -----------------------------------------------------------------------------
// void mark_arg(int n)
//
// Marks an argument as being parsed. All modules should do this whenever they
// parse a command line option.
//
// Inputs : n = Argument number
//
// Output : None
//
// Side Effects : Sets a status bit internally
// -----------------------------------------------------------------------------
void
mark_arg(int n) {
if (marked)
marked[n] = 1;
}
// -----------------------------------------------------------------------------
// void check_options()
//
// Checks for unparsed command line options. If so, issues an error and exits.
//
// Inputs : None
//
// Output : None
//
// Side Effects : exits if there are unparsed options
// -----------------------------------------------------------------------------
void check_options() {
int error = 0;
int i;
if (!marked) {
fprintf(stderr,"Must specify an input file. Use -help for available options.\n");
SWIG_exit(1);
}
for (i = 1; i < numargs-1; i++) {
if (!marked[i]) {
fprintf(stderr,"swig error : Unrecognized option %s\n", args[i]);
error=1;
}
}
if (error) {
fprintf(stderr,"Use 'swig -help' for available options.\n");
SWIG_exit(1);
}
if (marked[numargs-1]) {
fprintf(stderr,"Must specify an input file. Use -help for available options.\n");
SWIG_exit(1);
}
}
// -----------------------------------------------------------------------------
// void arg_error()
//
// Generates a generic error message and exits.
//
// Inputs : None
//
// Output : None
//
// Side Effects : Exits
// -----------------------------------------------------------------------------
void arg_error() {
fprintf(stderr,"SWIG : Unable to parse command line options.\n");
fprintf(stderr,"Use 'swig -help' for available options.\n");
SWIG_exit(1);
}

View file

@ -20,6 +20,8 @@ static char cvsroot[] = "$Header$";
#include <stdio.h>
#include <ctype.h>
extern "C" FILE *SWIG_open(void *);
/*******************************************************************************
* $Header$
*
@ -28,87 +30,6 @@ static char cvsroot[] = "$Header$";
* Code for including files into a wrapper file.
*******************************************************************************/
/* Delimeter used in accessing files and directories */
#ifdef MACSWIG
#define DELIMETER ':'
#else
#define DELIMETER '/'
#endif
/* Linked list containing search directories */
struct Dnode {
char *dirname;
Dnode *next;
};
Dnode ihead, iz;
int include_init = 0;
/* Linked list containing included files */
struct Inode {
char *name;
Inode *next;
};
Inode *include_list = 0;
// -----------------------------------------------------------------------------
// void add_directory(char *dirname)
//
// Adds a directory to the SWIG search path.
// -----------------------------------------------------------------------------
void add_directory(char *dirname) {
Dnode *d;
if (!include_init) {
ihead.next = &iz;
iz.next = &iz;
iz.dirname = new char[2];
iz.dirname[0] = 0;
include_init = 1;
}
d = new Dnode;
d->dirname = new char[strlen(dirname)+1];
strcpy(d->dirname,dirname);
d->next = ihead.next;
ihead.next = d;
}
// -----------------------------------------------------------------------------
// int add_iname(char *name)
//
// Adds an include file to the list of processed files. If already present,
// returns 1.
// -----------------------------------------------------------------------------
int add_iname(char *name) {
Inode *newi, *i;
// if (WrapExtern) return 0; // Still thinking about this patch.
if (include_list) {
/* Search list */
i = include_list;
while (i) {
if (strcmp(i->name, name) == 0) return 1;
i = i->next;
}
}
newi = new Inode;
newi->name = new char[strlen(name)+1];
strcpy(newi->name, name);
newi->next = include_list;
include_list = newi;
return 0;
}
// -----------------------------------------------------------------------------
// void check_suffix(char *name)
//
@ -146,73 +67,6 @@ void check_suffix(char *name) {
ForceExtern = 0;
}
}
// -----------------------------------------------------------------------------
// int include_file(char *name)
//
// Includes a new SWIG wrapper file. Returns -1 if file not found.
// -----------------------------------------------------------------------------
int include_file(char *name) {
FILE *f;
char filename[256];
int found = 0;
Dnode *d;
extern void scanner_file(FILE *);
if (!include_init) return -1; // Not initialized yet
if (add_iname(name)) {
if (Verbose) fprintf(stderr,"file %s already included.\n", name);
return -1; // Already included this file
}
if (Verbose) {
fprintf(stderr,"Wrapping %s...\n", name);
fprintf(stderr,"Looking for ./%s\n", name);
}
if ((f = fopen(name,"r")) != NULL) {
input_file = new char[strlen(name)+1];
strcpy(input_file,name);
scanner_file(f);
check_suffix(name);
return 0;
}
// Now start searching libraries
d = ihead.next; // Start of search list
while (d != &iz) {
// Look for the wrap file in language directory
sprintf(filename,"%s%c%s%c%s", d->dirname,DELIMETER,LibDir,DELIMETER,name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if((f = fopen(filename,"r")) != NULL) {
found = 1;
} else {
sprintf(filename,"%s%c%s", d->dirname, DELIMETER,name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if ((f = fopen(filename,"r")) != NULL) {
found = 1;
}
}
if (found) {
// Found it, open it up for input
input_file = new char[strlen(filename)+1];
strcpy(input_file,filename);
scanner_file(f);
check_suffix(name);
return 0;
}
d = d->next;
}
if (!found) fprintf(stderr,"%s : Line %d. Unable to find include file %s (ignored).\n",input_file, line_number, name);
return -1;
}
static char buffer[1024];
// -----------------------------------------------------------------------------
// void copy_data(FILE *f1, FILE *f2)
@ -220,6 +74,8 @@ static char buffer[1024];
// Copies data from file f1 to file f2.
// -----------------------------------------------------------------------------
static char buffer[1024];
void copy_data(FILE *f1, FILE *f2) {
while (fgets(buffer,1023,f1)) {
@ -247,50 +103,13 @@ void copy_data(FILE *f1, String &s2) {
//
// Looks for a file and inserts into file f.
// -----------------------------------------------------------------------------
int insert_file(char *name, FILE *f_out) {
FILE *f;
char filename[256];
int found = 0;
Dnode *d;
if (!include_init) return -1; // Not initialized yet
if (add_iname(name)) {
if (Verbose) fprintf(stderr,"file %s already included.\n", name);
return -1; // Already included this file
}
if (Verbose) fprintf(stderr,"Looking for ./%s\n", name);
if ((f = fopen(name,"r")) != NULL) {
f = SWIG_open((void *) name);
if (f) {
copy_data(f,f_out);
return 0;
}
// Now start searching libraries
d = ihead.next; // Start of search list
while (d != &iz) {
// Look for the wrap file in language directory
sprintf(filename,"%s%c%s%c%s", d->dirname,DELIMETER,LibDir,DELIMETER,name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if((f = fopen(filename,"r")) != NULL) {
found = 1;
} else {
sprintf(filename,"%s%c%s", d->dirname, DELIMETER, name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if ((f = fopen(filename,"r")) != NULL) {
found = 1;
}
}
if (found) {
copy_data(f,f_out);
return 0;
}
d = d->next;
}
if ((!found) && (Verbose)) fprintf(stderr,"unable to find %s. (Ignored)\n",name);
return -1;
}
@ -301,192 +120,34 @@ int insert_file(char *name, FILE *f_out) {
// -----------------------------------------------------------------------------
void swig_append(char *filename, FILE *f) {
FILE *in_file;
if ((in_file = fopen(filename,"r")) == NULL) {
fprintf(stderr,"** SWIG ERROR ** file %s not found.\n",filename);
FatalError();
return;
}
while (fgets(buffer,1023,in_file)) {
fputs(buffer, f);
}
fclose(in_file);
copy_data(in_file, f);
}
// -----------------------------------------------------------------------------
// int get_file(char *name, String &str)
//
// Looks for a file and converts it into a String.
// -----------------------------------------------------------------------------
int get_file(char *name, String &str) {
FILE *f;
char filename[256];
int found = 0;
Dnode *d;
if (!include_init) return -1; // Not initialized yet
if (Verbose) fprintf(stderr,"Looking for %s\n", name);
if ((f = fopen(name,"r")) != NULL) {
copy_data(f,str);
return 0;
}
// Now start searching libraries
d = ihead.next; // Start of search list
while (d != &iz) {
// Look for the wrap file in language directory
sprintf(filename,"%s%c%s%c%s", d->dirname,DELIMETER,LibDir,DELIMETER,name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if((f = fopen(filename,"r")) != NULL) {
found = 1;
} else {
sprintf(filename,"%s%c%s", d->dirname, DELIMETER, name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if ((f = fopen(filename,"r")) != NULL) {
found = 1;
}
}
if (found) {
copy_data(f,str);
return 0;
}
d = d->next;
}
if ((!found)) fprintf(stderr,"SWIG Error. Unable to find %s. Possible installation problem.\n",name);
FatalError();
return -1;
}
static char *libs[1000];
static int nlibs = 0;
// -----------------------------------------------------------------------------
// void library_add(char *name)
//
// Adds a filename to the list of libraries. This is usually only called by
// the SWIG main program.
// -----------------------------------------------------------------------------
void library_add(char *name) {
int i;
// Check to make sure it's not already added
if (!(*name)) return;
for (i = 0; i < nlibs; i++) {
if (strcmp(libs[i],name) == 0) return;
}
libs[nlibs] = copy_string(name);
nlibs++;
}
// -----------------------------------------------------------------------------
// void library_insert()
//
// Starts parsing all of the SWIG library files.
// -----------------------------------------------------------------------------
void library_insert() {
int i;
i = nlibs-1;
while (i >= 0) {
include_file(libs[i]);
i--;
}
}
// -----------------------------------------------------------------------------
// int checkout(char *filename,char *dest)
//
// Tries to check a file out of the SWIG library. If found, it will save it in
// the current directory. This is a useful mechanism for using SWIG as a code
// manager and for extracting library files.
// -----------------------------------------------------------------------------
int checkout_file(char *filename,char *dest) {
FILE *f1;
char tempn[256];
// First check to see if the file already exists in current directory
f1 = fopen(dest,"r");
if (f1) {
if (Verbose)
fprintf(stderr,"Warning. Unable to check-out %s. File already exists.\n", filename);
fclose(f1);
return -1;
}
while (!f1) {
sprintf(tempn,"%s%d",dest,rand());
f1 = fopen(tempn,"r");
if (f1) {
fclose(f1);
f1 = 0;
} else {
f1 = fopen(tempn,"w");
if (!f1) {
fprintf(stderr,"Unable to open %s for writing\n", tempn);
return -1;
}
}
}
// Now try to insert the library file into the destination file
if ((insert_file(filename,f1)) == -1) {
fprintf(stderr,"Unable to check-out '%s'. File does not exist in SWIG library.\n",filename);
fclose(f1);
remove(tempn); // Unsuccessful, remove file we created
f = SWIG_open((void *) name);
if (!f) {
fprintf(stderr,"SWIG Error. Unable to find %s. Possible installation problem.\n",name);
FatalError();
return -1;
}
fclose(f1);
// Now move the file
rename(tempn,dest);
copy_data(f,str);
return 0;
}
// -----------------------------------------------------------------------------
// int checkin_file(char *dir, char *lang, char *source,char *dest)
//
// Attempts to check a file into the SWIG library.
// Output : 0 on success
// -1 on failure.
// -----------------------------------------------------------------------------
int checkin_file(char *dir, char *lang, char *source, char *dest) {
FILE *f1;
char tempn[256];
String s;
// First check to see if the file exists
f1 = fopen(source,"r");
if (!f1) return -1;
copy_data(f1,s);
// Now try to open the destination file
sprintf(tempn,"%s/%s/%s", dir,lang,dest);
f1 = fopen(tempn,"w");
if (!f1) return -1;
fprintf(f1,"%s",s.get());
fclose(f1);
return 0;
}

View file

@ -51,16 +51,15 @@ void Language::create_command(char *, char *) {
}
// -----------------------------------------------------------------
// void Language::add_native(char *targetlang, char *funcname)
// void Language::add_native(char *name, char *iname, DataType *t, ParmList *l)
//
// Method for adding a native function
// -----------------------------------------------------------------
// Method for adding a native function with full argument info
// default is to call the old-style add_native method
// -----------------------------------------------------------------
void
Language::add_native(char *, char *funcname) {
fprintf(stderr,"%s : Line %d. Adding native function %s not supported (ignored).\n", input_file, line_number, funcname);
Language::add_native(char *, char *iname, DataType *, ParmList *) {
fprintf(stderr,"%s : Line %d. Adding native function %s not supported (ignored).\n", input_file, line_number, iname);
}
static char *ClassName = 0; // This is the real name of the current class

View file

@ -26,9 +26,6 @@ static char cvsroot[] = "$Header$";
#define WRAP
#include "internal.h"
#include "ascii.h"
#include "html.h"
#include "nodoc.h"
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
@ -39,14 +36,9 @@ static char cvsroot[] = "$Header$";
class SwigException {};
static char *usage = "\
\nDocumentation Options\n\
-dascii - ASCII documentation.\n\
-dhtml - HTML documentation.\n\
-dnone - No documentation.\n\n\
General Options\n\
\nGeneral Options\n\
-c - Produce raw wrapper code (omit support code)\n\
-c++ - Enable C++ processing\n\
-ci - Check a file into the SWIG library\n\
-co - Check a file out of the SWIG library\n\
-d docfile - Set name of the documentation file.\n\
-Dsymbol - Define a symbol (for conditional compilation)\n\
@ -56,10 +48,8 @@ General Options\n\
-nocomment - Ignore all comments (for documentation).\n\
-o outfile - Set name of the output file.\n\
-objc - Enable Objective C processing\n\
-stat - Print statistics\n\
-strict n - Set pointer type-checking strictness\n\
-swiglib - Report location of SWIG library and exit\n\
-t typemap_file - Use a typemap file.\n\
-v - Run in verbose mode\n\
-version - Print SWIG version number\n\
-help - This output.\n\n";
@ -90,7 +80,6 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
int i;
char *c;
extern FILE *LEX_in;
extern void add_directory(char *);
extern char *get_time();
char temp[512];
char infile[512];
@ -100,13 +89,13 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
int help = 0;
int ignorecomments = 0;
int checkout = 0;
int checkin = 0;
int cpp_only = 0;
char *typemap_file = 0;
char *includefiles[256];
int includecount = 0;
extern void check_suffix(char *);
extern void scanner_file(FILE *);
DOH *libfiles = 0;
#ifdef MACSWIG
try {
@ -153,10 +142,7 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
add_directory(":swig_lib");
#else
sprintf(temp,"%s/config", LibDir);
add_directory(temp);
add_directory("./swig_lib/config");
add_directory(LibDir);
add_directory("./swig_lib");
SWIG_add_directory((DOH *) temp);
SWIG_add_directory((DOH *) "./swig_lib/config");
SWIG_add_directory((DOH *) LibDir);
@ -166,6 +152,8 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
sprintf(InitName,"init_wrap");
libfiles = NewList();
// Initialize the preprocessor
SWIG_cpp_init();
@ -175,85 +163,64 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
if (strncmp(argv[i],"-I",2) == 0) {
// Add a new directory search path
includefiles[includecount++] = copy_string(argv[i]+2);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strncmp(argv[i],"-D",2) == 0) {
DOH *d = NewString(argv[i]+2);
String_replace(d,"="," ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
SWIG_cpp_define(d,0);
// Create a symbol
add_symbol(argv[i]+2, (DataType *) 0, (char *) 0);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-strict") == 0) {
if (argv[i+1]) {
TypeStrict = atoi(argv[i+1]);
mark_arg(i);
mark_arg(i+1);
SWIG_mark_arg(i);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-E") == 0) {
cpp_only = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if ((strcmp(argv[i],"-verbose") == 0) || (strcmp(argv[i],"-v") == 0)) {
Verbose = 1;
mark_arg(i);
} else if (strcmp(argv[i],"-dascii") == 0) {
doc = new ASCII;
mark_arg(i);
} else if (strcmp(argv[i],"-dnone") == 0) {
doc = new NODOC;
mark_arg(i);
} else if (strcmp(argv[i],"-dhtml") == 0) {
doc = new HTML;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-nocomment") == 0) {
ignorecomments = 1;
mark_arg(i);
} else if (strcmp(argv[i],"-stat") == 0) {
Stats=1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-c++") == 0) {
CPlusPlus=1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-objc") == 0) {
ObjC = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-c") == 0) {
NoInclude=1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-make_default") == 0) {
GenerateDefault = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-swiglib") == 0) {
printf("%s\n", LibDir);
SWIG_exit(0);
} else if (strcmp(argv[i],"-o") == 0) {
mark_arg(i);
SWIG_mark_arg(i);
if (argv[i+1]) {
outfile_name = copy_string(argv[i+1]);
mark_arg(i+1);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-d") == 0) {
mark_arg(i);
SWIG_mark_arg(i);
if (argv[i+1]) {
doc_file = copy_string(argv[i+1]);
mark_arg(i+1);
SWIG_mark_arg(i+1);
i++;
} else {
arg_error();
}
} else if (strcmp(argv[i],"-t") == 0) {
mark_arg(i);
if (argv[i+1]) {
typemap_file = copy_string(argv[i+1]);
mark_arg(i+1);
i++;
} else {
arg_error();
SWIG_arg_error();
}
} else if (strcmp(argv[i],"-version") == 0) {
fprintf(stderr,"\nSWIG Version %d.%d %s\n", SWIG_MAJOR_VERSION,
@ -264,17 +231,14 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
SWIG_exit(0);
} else if (strncmp(argv[i],"-l",2) == 0) {
// Add a new directory search path
library_add(argv[i]+2);
mark_arg(i);
Append(libfiles,argv[i]+2);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-co") == 0) {
checkout = 1;
mark_arg(i);
} else if (strcmp(argv[i],"-ci") == 0) {
checkin = 1;
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
mark_arg(i);
SWIG_mark_arg(i);
help = 1;
}
}
@ -282,13 +246,8 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
while (includecount > 0) {
SWIG_add_directory((DOH *) includefiles[includecount]);
add_directory(includefiles[--includecount]);
}
// Create a new documentation handler
if (doc == 0) doc = new ASCII;
// Open up a comment handler
comment_handler = new CommentHandler();
@ -313,7 +272,9 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
// Check all of the options to make sure we're cool.
check_options();
SWIG_check_options();
SWIG_set_library(LibDir);
// If we made it this far, looks good. go for it....
@ -326,34 +287,30 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
// If the user has requested to check out a file, handle that
if (checkout) {
int stat;
DOH *s;
char *outfile = input_file;
if (outfile_name)
outfile = outfile_name;
stat = checkout_file(input_file,outfile);
if (!stat) {
fprintf(stderr,"%s checked out from the SWIG library\n",input_file);
s = SWIG_include(input_file);
if (!s) {
fprintf(stderr,"Unable to locate '%s' in the SWIG library.\n", input_file);
} else {
FILE * f = fopen(input_file,"r");
FILE *f = fopen(outfile,"r");
if (f) {
fprintf(stderr,"Unable to check-out %s. File already exists.\n", input_file);
fclose(f);
fprintf(stderr,"File '%s' already exists. Checkout aborted.\n", outfile);
} else {
fprintf(stderr,"Unable to check-out %s\n", input_file);
f = fopen(outfile,"w");
if (!f) {
fprintf(stderr,"Unable to create file '%s'\n", outfile);
} else {
fprintf(stderr,"'%s' checked out from the SWIG library.\n", input_file);
fputs(Char(s),f);
fclose(f);
}
}
}
} else if (checkin) {
// Try to check-in a file to the SWIG library
int stat;
char *outname = input_file;
if (outfile_name)
outname = outfile_name;
stat = checkin_file(SwigLib, LibDir, input_file, outname);
if (!stat) {
fprintf(stderr,"%s checked-in to %s/%s/%s\n", input_file, SwigLib, LibDir, outname);
} else {
fprintf(stderr,"Unable to check-in %s to %s/%s\n", input_file, SwigLib, LibDir);
}
} else {
doctitle->file = copy_string(input_file);
doctitle->line_number = -1000;
@ -434,7 +391,12 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
{
DOH *cpps;
FILE *f;
int i;
DOH *ds = SWIG_include(input_file);
Seek(ds,0,SEEK_END);
for (i = 0; i < Len(libfiles); i++) {
Printf(ds,"\n%%include \"%s\"\n", Getitem(libfiles,i));
}
Seek(ds,0,SEEK_SET);
cpps = SWIG_cpp_parse(ds);
if (cpp_only) {
@ -451,9 +413,6 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
SWIG_exit(0);
}
// Add to the include list
add_iname(infilename);
// Initialize the scanner
LEX_in = f_input;
scanner_file(LEX_in);
@ -506,16 +465,6 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
if (CPlusPlus)
add_symbol("__cplusplus",0,0);
// Load up the typemap file if given
if (typemap_file) {
if (include_file(typemap_file) == -1) {
fprintf(stderr,"Unable to locate typemap file %s. Aborting.\n", typemap_file);
SWIG_exit(1);
}
}
// If in Objective-C mode. Load in a configuration file
if (ObjC) {
@ -569,13 +518,6 @@ int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
if (Verbose)
type_undefined_check();
if (Stats) {
fprintf(stderr,"Wrapped %d functions\n", Stat_func);
fprintf(stderr,"Wrapped %d variables\n", Stat_var);
fprintf(stderr,"Wrapped %d constants\n", Stat_const);
type_undefined_check();
}
if (checkout) {
// File was checked out from the SWIG library. Remove it now
remove(input_file);

View file

@ -269,22 +269,22 @@ void DocEntry::parse_args(int argc, char **argv) {
if (argv[i]) {
if (strcmp(argv[i],"-Ssort") == 0) {
this->style("sort",0);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-Snosort") == 0) {
this->style("nosort",0);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-Sinfo") == 0) {
this->style("info",0);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-Snoinfo") == 0) {
this->style("noinfo",0);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-Spre") == 0) {
this->style("pre",0);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-Sformat") == 0) {
this->style("format",0);
mark_arg(i);
SWIG_mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(doc_usage,stderr);
}

View file

@ -159,9 +159,6 @@ static void init_language() {
int oldignore = IgnoreDoc;
IgnoreDoc = 1;
if (ConfigFile) {
include_file(ConfigFile);
}
IgnoreDoc = oldignore;
}
lang_init = 1;
@ -482,12 +479,11 @@ static void dump_nested(char *parent) {
%token LPAREN RPAREN COMMA SEMI EXTERN INIT LBRACE RBRACE DEFINE PERIOD
%token CONST STRUCT UNION EQUAL SIZEOF MODULE LBRACKET RBRACKET
%token ILLEGAL CONSTANT
%token READONLY READWRITE NAME RENAME CHECKOUT ADDMETHODS PRAGMA
%token READONLY READWRITE NAME RENAME ADDMETHODS PRAGMA
%token CVALUE COUT
%token ENUM ENDDEF MACRO
%token CLASS PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND OPERATOR THROW TEMPLATE
%token NATIVE INLINE
%token IFDEF IFNDEF ENDIF ELSE UNDEF IF DEFINED ELIF
%token RAW_MODE ALPHA_MODE TEXT DOC_DISABLE DOC_ENABLE STYLE LOCALSTYLE
%token TYPEMAP EXCEPT ECHO NEW APPLY CLEAR DOCONLY
%token <ivalue> TITLE SECTION SUBSECTION SUBSUBSECTION
@ -511,7 +507,7 @@ static void dump_nested(char *parent) {
%type <pl> parms ptail;
%type <p> parm parm_type;
%type <tmparm> typemap_parm tm_list tm_tail;
%type <id> pname cpptype base_specifier access_specifier typemap_name tm_method idstring;
%type <id> pname cpptype base_specifier access_specifier typemap_name tm_method;
%type <type> type opt_signed opt_unsigned strict_type;
%type <decl> declaration nested_decl;
%type <ivalue> stars;
@ -608,15 +604,6 @@ statement : INCLUDE STRING LBRACE {
line_number = $1.line;
}
/* %checkout directive. Like %include, but simply copies the file into the
current directory */
| CHECKOUT idstring {
if ((checkout_file($2,$2)) == 0) {
fprintf(stderr,"%s checked out from the SWIG library.\n",$2);
}
}
/* An unknown C preprocessor statement. Just throw it away */
| POUND {
@ -823,7 +810,7 @@ statement : INCLUDE STRING LBRACE {
input_file, line_number, $3);
} else {
doc_entry = new DocDecl($3,doc_stack[doc_stack_top]);
lang->add_native($3,$6);
lang->add_native($3,$6,0,0);
}
}
}
@ -839,7 +826,7 @@ statement : INCLUDE STRING LBRACE {
emit_extern_func($7.id, $6, $9, $5, f_header);
}
doc_entry = new DocDecl($3,doc_stack[doc_stack_top]);
lang->add_native($3,$7.id);
lang->add_native($3,$7.id,$6,$9);
}
}
delete $6;
@ -3818,11 +3805,6 @@ typemap_args : LPAREN parms RPAREN {
}
;
idstring : ID {$$ = $1;}
| STRING { $$ = $1;}
;
/* User defined directive */
user_directive : USERDIRECTIVE LPAREN parms RPAREN uservalue { }

View file

@ -132,7 +132,6 @@ void scanner_file(FILE *f) {
void scanner_close() {
InFile *p;
static int lib_insert = 0;
fclose(LEX_in);
if (!in_head) return;
p = in_head->prev;
@ -148,15 +147,6 @@ void scanner_close() {
}
delete in_head;
in_head = p;
// if LEX_in is NULL it means we're done with the interface file. We're now
// going to grab all of the library files.
if ((!LEX_in) && (!lib_insert)) {
library_insert();
lib_insert = 1;
}
}
/**************************************************************
@ -810,61 +800,14 @@ int yylook(void) {
break;
case 3: /* a CPP directive */
if (( c= nextchar()) == 0) return 0;
if (c == '\n') {
retract(1);
yytext[yylen] = 0;
yylval.id = yytext;
return(POUND);
} else if ((c == ' ') || (c == '\t')) { // Ignore white space after # symbol
yytext[yylen] = 0;
yylen--;
state = 3;
} else {
yytext[yylen] = 0;
state = 31;
}
break;
case 31:
if ((c = nextchar()) == 0) return 0;
if ((c == ' ') || (c == '\t') || (c=='\n')) {
retract(1);
yytext[yylen] = 0;
if (strcmp(yytext,"#define") == 0) {
in_define = 1;
define_first_id = 1;
return(DEFINE);
} else if (strcmp(yytext,"#ifdef") == 0) {
return(IFDEF);
} else if (strcmp(yytext,"#ifndef") == 0) {
return(IFNDEF);
} else if (strcmp(yytext,"#else") == 0) {
return(ELSE);
} else if (strcmp(yytext,"#endif") == 0) {
return(ENDIF);
} else if (strcmp(yytext,"#undef") == 0) {
return(UNDEF);
} else if (strcmp(yytext,"#if") == 0) {
return(IF);
} else if (strcmp(yytext,"#elif") == 0) {
return(ELIF);
} else {
/* Some kind of "unknown CPP directive. Skip to end of the line */
state = 32;
}
}
break;
case 32:
if ((c = nextchar()) == 0) return 0;
if (c == '\n') {
retract(1);
yytext[yylen] = 0;
yylval.id = yytext;
return(POUND);
}
state = 32;
break;
case 4: /* A wrapper generator directive (maybe) */
if (( c= nextchar()) == 0) return 0;
@ -1281,7 +1224,6 @@ extern "C" int yylex(void) {
if (strcmp(yytext,"union") == 0) return(UNION);
if (strcmp(yytext,"enum") == 0) return(ENUM);
if (strcmp(yytext,"sizeof") == 0) return(SIZEOF);
if (strcmp(yytext,"defined") == 0) return(DEFINED);
// Ignored keywords
@ -1296,9 +1238,8 @@ extern "C" int yylex(void) {
if (strcmp(yytext,"%readwrite") == 0) return(READWRITE);
if (strcmp(yytext,"%name") == 0) return(NAME);
if (strcmp(yytext,"%rename") == 0) return(RENAME);
if (strcmp(yytext,"%include") == 0) return(INCLUDE);
if (strcmp(yytext,"%extern") == 0) return(WEXTERN);
if (strcmp(yytext,"%checkout") == 0) return(CHECKOUT);
if (strcmp(yytext,"%includefile") == 0) return(INCLUDE);
if (strcmp(yytext,"%externfile") == 0) return(WEXTERN);
if (strcmp(yytext,"%val") == 0) return(CVALUE);
if (strcmp(yytext,"%out") == 0) return(COUT);
if (strcmp(yytext,"%constant") == 0) return(CONSTANT);
@ -1336,18 +1277,12 @@ extern "C" int yylex(void) {
if (strcmp(yytext,"%native") == 0) return(NATIVE);
if (strcmp(yytext,"%disabledoc") == 0) return(DOC_DISABLE);
if (strcmp(yytext,"%enabledoc") == 0) return(DOC_ENABLE);
if (strcmp(yytext,"%ifdef") == 0) return(IFDEF);
if (strcmp(yytext,"%else") == 0) return(ELSE);
if (strcmp(yytext,"%ifndef") == 0) return(IFNDEF);
if (strcmp(yytext,"%endif") == 0) return(ENDIF);
if (strcmp(yytext,"%if") == 0) return(IF);
if (strcmp(yytext,"%elif") == 0) return(ELIF);
if (strcmp(yytext,"%pragma") == 0) return(PRAGMA);
if (strcmp(yytext,"%addmethods") == 0) return(ADDMETHODS);
if (strcmp(yytext,"%inline") == 0) return(INLINE);
if (strcmp(yytext,"%typemap") == 0) return(TYPEMAP);
if (strcmp(yytext,"%except") == 0) return(EXCEPT);
if (strcmp(yytext,"%import") == 0) return(IMPORT);
if (strcmp(yytext,"%importfile") == 0) return(IMPORT);
if (strcmp(yytext,"%echo") == 0) return(ECHO);
if (strcmp(yytext,"%new") == 0) return(NEW);
if (strcmp(yytext,"%apply") == 0) return(APPLY);

View file

@ -395,7 +395,7 @@ public:
virtual void close(void) = 0;
virtual void set_module(char *mod_name,char **mod_list) = 0;
virtual void set_init(char *init_name);
virtual void add_native(char *, char *);
virtual void add_native(char *name, char *iname, DataType *t, ParmList *l);
virtual char *type_mangle(DataType *t) {
return t->print_mangle_default();
}
@ -557,22 +557,19 @@ extern void cplus_support_doc(String &f);
/* Function for building search directories */
extern void add_directory(char *dirname);
extern int insert_file(char *, FILE *);
extern int get_file(char *filename, String &str);
extern int checkout_file(char *filename, char *dest);
extern int checkin_file(char *dir, char *lang, char *source, char *dest);
extern int include_file(char *filename);
extern void swig_append(char *filename, FILE *);
/* Miscellaneous */
/* These are in the new core */
extern void check_options();
extern void init_args(int argc, char **);
extern void mark_arg(int n);
extern void arg_error();
extern void library_add(char *name);
extern void library_insert();
extern "C" {
/* Option processing */
extern void SWIG_init_args(int argc, char **);
extern void SWIG_mark_arg(int n);
extern void SWIG_check_options();
extern void SWIG_arg_error();
}
// -----------------------------------------------------------------------
// Class for Creating Wrapper Functions