SWIG1.1 directory destroyed

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@956 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-12-18 02:51:11 +00:00
commit 6b28f547f3
10 changed files with 0 additions and 8115 deletions

View file

@ -1,73 +0,0 @@
#######################################################################
# $Header$
#######################################################################
srcdir = @srcdir@
VPATH = @srcdir@
SHELL = /bin/sh
CXX = @CXX@
CFLAGS = @CFLAGS@
YACC = @YACC@
AR = @AR@
RANLIB = @RANLIB@
TARGET = libswig11.a
OBJS = parser.o main.o scanner.o \
emit.o cplus.o lang.o
SRCS = main.cxx scanner.cxx \
emit.cxx cplus.cxx lang.cxx
PARSER = $(srcdir)/parser.yxx
INCLUDE = -I$(srcdir)/../Include \
-I$(srcdir)/. \
-I$(srcdir)/../Swig \
-I$(srcdir)/../Preprocessor \
-I$(srcdir)/../DOH/Include \
-I../Include \
-I.
# Rules for creation of a .o file from .cxx
.SUFFIXES: .cxx
.cxx.o:
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
swig: $(TARGET)
$(TARGET): $(OBJS)
$(AR) cr $(TARGET) $(OBJS)
$(RANLIB) $(TARGET)
parser.o: parser.cxx
$(CXX) $(INCLUDE) $(CFLAGS) $< -c -o parser.o
parser.cxx parser.h: $(PARSER)
$(YACC) @YFLAGS@ $(PARSER)
@cp y.tab.h parser.h
@cp y.tab.c parser.cxx
scanner.o: parser.h
parser::
@cp y.tab.c.bison parser.cxx
@cp y.tab.h.bison parser.h
@cp y.tab.h.bison y.tab.h
$(CXX) $(CFLAGS) parser.cxx -c -o parser.o
clean::
rm -f *.o $(TARGET) y.tab.c y.tab.h
nuke::
rm -f Makefile *~ #* core a.out

View file

@ -1,7 +0,0 @@
2/10/00
This is the old SWIG1.1 core written in C++. This is a real mess
and in the process of being deprecated. Please bear with us.
-- Dave

File diff suppressed because it is too large Load diff

View file

@ -1,257 +0,0 @@
/* -----------------------------------------------------------------------------
* emit.cxx
*
* Useful functions for emitting various pieces of code.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1998-2000. The University of Chicago
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
* University of California.
*
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
#include "internal.h"
extern "C" {
#include "swig.h"
}
static char cvsroot[] = "$Header$";
/* -----------------------------------------------------------------------------
* new_create_function()
*
* Create a new function
* ----------------------------------------------------------------------------- */
void new_create_function(char *name, char *iname, SwigType *type, ParmList *l) {
Hash *h;
h = NewHash();
Setattr(h,"name",name);
Setattr(h,"scriptname",iname);
Setattr(h,"type",type);
Setattr(h,"parms",l);
lang->function(h);
Delete(h);
}
/* -----------------------------------------------------------------------------
* emit_args()
*
* Creates a list of variable declarations for both the return value
* and function parameters.
*
* The return value is always called result and arguments arg0, arg1, arg2, etc...
* Returns the number of parameters associated with a function.
* ----------------------------------------------------------------------------- */
int emit_args(DOH *node, Wrapper *f) {
SwigType *rt;
ParmList *l;
Parm *p;
int i;
char *tm;
SwigType *pt;
DOHString *pvalue;
DOHString *pname;
DOHString *lname;
rt = Getattr(node,"type");
l = Getattr(node,"parms");
/* Emit function arguments */
Swig_cargs(f, l);
i = 0;
p = l;
while (p != 0) {
lname = Getlname(p);
pt = Gettype(p);
pname = Getname(p);
pvalue = Getvalue(p);
tm = Swig_typemap_lookup((char*)"arginit",pt,pname,(char*)"",lname,f);
if (tm) {
Printv(f,tm,"\n",0);
}
/* Check for ignore or default typemaps */
tm = Swig_typemap_lookup((char*)"default",pt,pname,(char*)"",lname,f);
if (tm) {
Printv(f,tm,"\n",0);
}
tm = Swig_typemap_lookup((char*)"ignore",pt,pname,(char*)"",lname,f);
if (tm) {
Printv(f,tm,"\n",0);
Setignore(p,1);
}
i++;
p = Getnext(p);
}
return(i);
}
/* -----------------------------------------------------------------------------
* int emit_func_call(char *decl, DataType *t, ParmList *l, Wrapper*f)
*
* Emits code for a function call (new version).
*
* Exception handling support :
*
* - This function checks to see if any sort of exception mechanism
* has been defined. If so, we emit the function call in an exception
* handling block.
* ----------------------------------------------------------------------------- */
static DOH *fcall = 0;
void emit_set_action(DOHString_or_char *decl) {
if (fcall) Delete (fcall);
fcall = NewString(decl);
}
void emit_func_call(DOH *node, Wrapper *f) {
char *decl;
SwigType *t;
ParmList *l;
char *tm;
decl = GetChar(node,"name");
t = Getattr(node,"type");
l = Getattr(node,"parms");
if ((tm = Swig_typemap_lookup((char*)"except",t,decl,(char*)"result",(char*)"",0))) {
Printv(f,tm,0);
Replace(f,"$name",decl,DOH_REPLACE_ANY);
} else if ((tm = Swig_except_lookup())) {
Printv(f,tm,0);
Replace(f,"$name",decl,DOH_REPLACE_ANY);
} else {
Printv(f,"$function",0);
}
if (!fcall) fcall = NewString(Swig_cfunction_call(decl,l));
if (CPlusPlus) {
Swig_cppresult(f, t, (char*)"result", Char(fcall));
} else {
Swig_cresult(f, t, (char*)"result", Char(fcall));
}
Delete(fcall);
fcall = 0;
}
/* -----------------------------------------------------------------------------
* void emit_set_get()
*
* Emits a pair of functions to set/get the value of a variable. This is
* only used in the event the target language can't provide variable linking
* on its own.
*
* double foo;
*
* Gets translated into the following :
*
* double foo_set(double x) {
* return foo = x;
* }
*
* double foo_get() {
* return foo;
* }
* ----------------------------------------------------------------------------- */
/* How to assign a C allocated string */
static char *c_str = (char *)"\
if ($target) free($target);\n\
$target = ($rtype) malloc(strlen($source)+1);\n\
strcpy((char *)$target,$source);\n\
return $ltype $target;\n";
/* How to assign a C allocated string */
static char *cpp_str = (char *)"\
if ($target) delete [] $target;\n\
$target = ($rtype) (new char[strlen($source)+1]);\n\
strcpy((char *)$target,$source);\n\
return ($ltype) $target;\n;";
void emit_set_get(DOH *node) {
char *name, *iname;
SwigType *t;
Wrapper *w;
DOHString *new_iname;
char *code = 0;
name = GetChar(node,"name");
iname = GetChar(node,"iname");
t = Getattr(node,"type");
/* First write a function to set the variable of the variable */
if (!(Status & STAT_READONLY)) {
if (SwigType_type(t) == T_STRING) {
if (CPlusPlus)
code = cpp_str;
else
code = c_str;
}
w = Swig_cvarset_wrapper(name, t, code);
Printf(f_header,"%s", w);
new_iname = Swig_name_set(iname);
DohIncref(new_iname);
new_create_function(GetChar(w,"name"), Char(new_iname), Gettype(w), Getparms(w));
Delete(new_iname);
Delete(w);
}
w = Swig_cvarget_wrapper(name,t,0);
Printf(f_header,"%s", w);
new_iname = Swig_name_get(iname);
DohIncref(new_iname);
new_create_function(GetChar(w,"name"), Char(new_iname), Gettype(w), Getparms(w));
Delete(new_iname);
Delete(w);
}
/* ------------------------------------------------------------------
* int check_numopt()
*
* Gets the number of optional arguments for a ParmList.
* ------------------------------------------------------------------ */
int check_numopt(ParmList *p) {
int n = 0;
int i = 0;
int state = 0;
for (;p; p = Getnext(p),i++) {
SwigType *pt = Gettype(p);
String *pn = Getname(p);
if (Getvalue(p)) {
n++;
state = 1;
} else if (Swig_typemap_search((char*)"default",pt,pn)) {
n++;
state = 1;
} else if (Swig_typemap_search((char*)"ignore",pt,pn)) {
n++;
} else {
if (state) {
Printf(stderr,"%s : Line %d. Argument %d must have a default value!\n", input_file,line_number,i+1);
}
}
}
return n;
}

View file

@ -1,64 +0,0 @@
/* -----------------------------------------------------------------------------
* internal.h
*
* Internal declarations used by the SWIG core
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1998-2000. The University of Chicago
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
* University of California.
*
* See the file LICENSE for information on usage and redistribution.
*
* $Header$
* ----------------------------------------------------------------------------- */
#include "swig11.h"
extern Language *lang;
extern int ForceExtern;
extern int WrapExtern;
extern void *CCode;
extern int GenerateDefault;
extern char *objc_construct;
extern char *objc_destruct;
// Structure for holding typemap parameters
struct TMParm {
Parm *p;
ParmList *args;
TMParm *next;
TMParm() {
next = 0;
}
};
/* Number of initialization names that can be used */
#define NI_NAMES 512
// Some functions for emitting some C++ helper code
extern void cplus_emit_member_func(char *classname, char *classtype, char *classrename,
char *mname, char *mrename, SwigType *type, ParmList *l,
int mode);
extern void cplus_emit_static_func(char *classname, char *classtype, char *classrename,
char *mname, char *mrename, SwigType *type, ParmList *l,
int mode);
extern void cplus_emit_destructor(char *classname, char *classtype, char *classrename,
char *name, char *iname, int mode);
extern void cplus_emit_constructor(char *classname, char *classtype, char *classrename,
char *name, char *iname, ParmList *l, int mode);
extern void cplus_emit_variable_get(char *classname, char *classtype, char *classrename,
char *name, char *iname, SwigType *type, int mode);
extern void cplus_emit_variable_set(char *classname, char *classtype, char *classrename,
char *name, char *iname, SwigType *type, int mode);
extern char *cplus_base_class(char *name);

View file

@ -1,418 +0,0 @@
/* -----------------------------------------------------------------------------
* lang.cxx
*
* Language base class functions. Default C++ handling is also implemented here.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1998-2000. The University of Chicago
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
* University of California.
*
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
#include "internal.h"
#include <ctype.h>
extern "C" {
#include "swig.h"
}
extern int add_symbol(char *name);
/* -----------------------------------------------------------------
* Language::create_command()
* ----------------------------------------------------------------- */
void Language::create_command(char *, char *) {
Printf(stderr,"SWIG Warning. No command creation procedure defined.\n");
Printf(stderr,"C++ inheritance may not work correctly.\n");
}
/* -----------------------------------------------------------------
* Language::nativefunction()
* ----------------------------------------------------------------- */
void
Language::nativefunction(DOH *node) {
Printf(stderr,"%s : Line %d. Adding native function %s not supported (ignored).\n", input_file, line_number, Getattr(node,"scriptname"));
}
static String *ClassName = 0; /* This is the real name of the current class */
static String *ClassRename = 0; /* This is non-NULL if the class has been renamed */
static String *ClassType = 0; /* Type of class (ie. union, struct, class) */
static String *ClassFullname = 0; /* Full name of the class */
static String *ClassPrefix = 0; /* Prefix used on wrappers */
/* -----------------------------------------------------------------------------
* Language::cpp_open_class()
* ----------------------------------------------------------------------------- */
void Language::cpp_open_class(char *classname, char *classrename, char *ctype, int strip) {
/* Copy the class name */
if (ClassName) Delete(ClassName);
ClassName = NewString(classname);
/* Copy the class renaming */
if (ClassRename) Delete(ClassRename);
if (classrename) {
ClassRename = NewString(classrename);
} else {
ClassRename = 0; /* No renaming */
}
/* Make the class type*/
if (ClassType) Delete(ClassType);
if (strip) ClassType = NewString("");
else ClassType = NewStringf("%s ", ctype);
if (ClassFullname) Delete(ClassFullname);
ClassFullname = NewStringf("%s%s", ClassType, ClassName);
if (ClassRename) {
ClassPrefix = ClassRename;
} else {
ClassPrefix = ClassName;
}
}
/* -----------------------------------------------------------------------------
* Language::cpp_close_class()
* ----------------------------------------------------------------------------- */
void Language::cpp_close_class() {
/* Doesn't really do anything */
}
/* -----------------------------------------------------------------------------
* Language::cpp_memberfunction()
* ----------------------------------------------------------------------------- */
void Language::cpp_memberfunction(DOH *node) {
String *name;
String *iname;
String *ccode;
String *script_name;
SwigType *type;
ParmList *parms;
Wrapper *w;
name = Getattr(node,"name");
iname = Getattr(node,"scriptname");
type = Getattr(node,"type");
parms = Getattr(node,"parms");
ccode = Getattr(node,"ccode");
/* Generate the C wrapper function name and interpreter name of this function*/
/* Create the actual function name */
script_name = Swig_name_member(ClassPrefix, iname ? iname : name);
/* Now do a symbol table lookup on it : */
if (add_symbol(Char(script_name))) {
Printf(stderr,"%s : Line %d. Function %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, iname, name);
return;
}
/* Create the C wrapper function for this */
w = Swig_cmethod_wrapper(ClassFullname, name, type, parms, ccode);
if (AddMethods && ccode) {
/* Dump the C wrappers */
Printf(f_wrappers,"%s",w);
} else if (!AddMethods) {
/* Just create a string that does what we want */
emit_set_action(Swig_cmethod_call(name, Getparms(w)));
}
Setattr(w,"scriptname",script_name);
lang->function(w);
Delete(w);
}
/* -----------------------------------------------------------------------------
* Language::cpp_constructor()
* ----------------------------------------------------------------------------- */
void Language::cpp_constructor(DOH *node) {
char *name, *iname;
ParmList *l;
char *cname;
name = GetChar(node,"name");
iname = GetChar(node,"scriptname");
l = Getattr(node,"parms");
if ((strcmp(name,Char(ClassName))) && (!ObjCClass)) {
Printf(stderr,"%s : Line %d. Function %s must have a return type.\n",
input_file, line_number, name);
return;
}
cname = Char(Swig_name_construct(iname ? iname : ClassPrefix));
/* Add this function to the SWIG symbol table */
if (add_symbol(cname)) {
Printf(stderr,"%s : Line %d. Constructor %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname);
return;
}
/* Call our default method */
cplus_emit_constructor(Char(ClassName), Char(ClassType), Char(ClassRename), name, iname, l, AddMethods);
}
/* -----------------------------------------------------------------------------
* Language::cpp_destructor()
* ----------------------------------------------------------------------------- */
void Language::cpp_destructor(DOH *node) {
char *name, *iname;
char *cname;
name = GetChar(node,"name");
iname = GetChar(node,"scriptname");
cname = Char(Swig_name_destroy(ClassRename ? ClassRename : ClassName));
/* Add this function to the SWIG symbol table */
if (add_symbol(cname)) {
Printf(stderr,"%s : Line %d. Destructor %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname);
return;
}
/* Call our default method */
cplus_emit_destructor(Char(ClassName), Char(ClassType), Char(ClassRename), name, iname, AddMethods);
}
/* -----------------------------------------------------------------------------
* Language::cleanup()
* ----------------------------------------------------------------------------- */
void Language::cpp_cleanup() {
/* This doesn't do anything (well, not be default) */
}
/* -----------------------------------------------------------------------------
* Language::cpp_inherit()
* ----------------------------------------------------------------------------- */
void Language::cpp_inherit(char **baseclass, int mode) {
extern void cplus_inherit_members(char *, int);
int i = 0;
if (!baseclass) return;
while (baseclass[i]) {
cplus_inherit_members(baseclass[i],mode);
i++;
}
}
/* -----------------------------------------------------------------------------
* Language::cpp_variable()
* ----------------------------------------------------------------------------- */
void Language::cpp_variable(DOH *node) {
char *name, *iname;
SwigType *t;
char *cname;
name = GetChar(node,"name");
iname = GetChar(node,"scriptname");
t = Getattr(node,"type");
/* Set the class prefix */
cname = Char(Swig_name_get(Swig_name_member(ClassPrefix, iname ? iname : name)));
/* Check the symbol table */
if (add_symbol(cname)) {
Printf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n", input_file, line_number, cname);
return;
}
/* Create a function to set the value of the variable */
if (!(Status & STAT_READONLY)) {
cplus_emit_variable_set(Char(ClassName), Char(ClassType), Char(ClassRename), name, iname, t, AddMethods);
}
/* Create a function to get the value of a variable */
cplus_emit_variable_get(Char(ClassName),Char(ClassType), Char(ClassRename), name, iname, t, AddMethods);
}
/* -----------------------------------------------------------------------------
* Language::cpp_static_func()
* ----------------------------------------------------------------------------- */
void Language::cpp_staticfunction(DOH *node) {
char *name, *iname;
SwigType *t;
ParmList *l;
char *cname;
name = GetChar(node,"name");
iname = GetChar(node,"scriptname");
t = Getattr(node,"type");
l = Getattr(node,"parms");
/* Set the member function name */
cname = Char(Swig_name_member(ClassPrefix,iname ? iname : name));
/* Now do a symbol table lookup on it : */
if (add_symbol(cname)) {
if (ObjCClass)
Printf(stderr,"%s : Line %d. class function %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname);
else
Printf(stderr,"%s : Line %d. static function %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname);
return;
}
cplus_emit_static_func(Char(ClassName),Char(ClassType), Char(ClassRename), name, iname, t, l, AddMethods);
}
/* -----------------------------------------------------------------------------
* Language::cpp_constant()
* ----------------------------------------------------------------------------- */
void Language::cpp_constant(DOH *node)
{
char *name, *iname, *value;
SwigType *type;
char *cname;
char mname[256];
String *new_value;
name = GetChar(node,"name");
iname = GetChar(node,"scriptname");
value = GetChar(node,"value");
type = Getattr(node,"type");
/* Set the constant name */
cname = Char(Swig_name_member(ClassPrefix, iname ? iname : name));
/* Now do a symbol table lookup on it : */
if (add_symbol(cname)) {
Printf(stderr,"%s : Line %d. Constant %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, cname, name);
return;
}
/* Form correct C++ name */
sprintf(mname,"%s::%s",ClassName,name);
/* Declare a constant */
if (!value) {
new_value = NewStringf("%s::%s", ClassName, name);
} else {
new_value = NewString(value);
}
Hash *n;
n = NewHash();
Setattr(n,"name",cname);
Setattr(n,"scriptname",cname);
Setattr(n,"type",type);
Setattr(n,"value",new_value);
lang->constant(n);
Delete(n);
Delete(new_value);
}
/* -----------------------------------------------------------------------------
* Language::cpp_staticvariable()
* ----------------------------------------------------------------------------- */
void Language::cpp_staticvariable(DOH *node) {
char *name, *iname;
SwigType *t;
char *cname;
char mname[256];
name = GetChar(node,"name");
iname = GetChar(node,"scriptname");
t = Getattr(node,"type");
/* Create the variable name */
cname = Char(Swig_name_member(ClassPrefix, iname ? iname : name));
/* Now do a symbol table lookup on it : */
if (add_symbol(cname)) {
Printf(stderr,"%s : Line %d. Variable %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, cname, name);
return;
}
/* Form correct C++ name */
sprintf(mname,"%s::%s",Char(ClassName),name);
/* Link with this variable */
Hash *n = NewHash();
Setattr(n,"name",mname);
Setattr(n,"scriptname", cname);
Setattr(n,"type",t);
lang->variable(n);
Delete(n);
}
/* -----------------------------------------------------------------------------
* Language::cpp_class_decl()
* ----------------------------------------------------------------------------- */
void Language::cpp_class_decl(char *, char *, char *) {
/* Does nothing by default */
}
/* -----------------------------------------------------------------------------
* Language::cpp_pragma()
* ----------------------------------------------------------------------------- */
void Language::cpp_pragma(Pragma *) {
/* Does nothing by default */
}
/* -----------------------------------------------------------------------------
* Language::add_typedef()
* ----------------------------------------------------------------------------- */
void Language::add_typedef(SwigType *, char *) {
/* Does nothing by default */
}
/* -----------------------------------------------------------------------------
* Language::pragma()
* ----------------------------------------------------------------------------- */
void Language::pragma(char *, char *, char *) {
/* Does nothing by default */
}
/* -----------------------------------------------------------------------------
* Language::import()
* ----------------------------------------------------------------------------- */
void Language::import(char *) {
/* Does nothing by default */
}

View file

@ -1,534 +0,0 @@
/* -----------------------------------------------------------------------------
* main.cxx
*
* Main entry point to the SWIG core.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1998-2000. The University of Chicago
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
* University of California.
*
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
#include "internal.h"
#ifndef MACSWIG
#include "swigconfig.h"
#endif
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
extern "C" {
#include "preprocessor.h"
}
#ifndef SWIG_LIB
#define SWIG_LIB "/usr/local/lib/swig1.3"
#endif
#ifndef SWIG_CC
#define SWIG_CC "CC"
#endif
// Global variables
FILE *f_runtime;
DOH *f_header; // Some commonly used
DOH *f_wrappers; // FILE pointers
DOH *f_init;
FILE *f_input;
char LibDir[512]; // Library directory
int Status;
Language *lang; // Language method
int CPlusPlus = 0;
int ObjC = 0;
int ObjCClass = 0;
int AddMethods = 0; // AddMethods flag
int NewObject = 0; // NewObject flag
int Inline = 0; // Inline mode
int ForceExtern = 0; // Force extern mode
int WrapExtern = 0;
int GenerateDefault = 0; // Generate default constructors
char *Config = 0;
int NoInclude = 0;
int error_count = 0; // Error count
int Verbose = 0;
class SwigException {};
static char *usage = (char*)"\
\nGeneral Options\n\
-c - Produce raw wrapper code (omit support code)\n\
-c++ - Enable C++ processing\n\
-co - Check a file out of the SWIG library\n\
-Dsymbol - Define a symbol (for conditional compilation)\n\
-I<dir> - Look for SWIG files in <dir>\n\
-includeall - Follow all #include statements\n\
-l<ifile> - Include SWIG library file.\n\
-make_default - Create default constructors/destructors\n\
-o outfile - Set name of the output file.\n\
-objc - Enable Objective C processing\n\
-swiglib - Report location of SWIG library and exit\n\
-v - Run in verbose mode\n\
-version - Print SWIG version number\n\
-help - This output.\n\n";
// -----------------------------------------------------------------------------
// check_suffix(char *name)
//
// Checks the suffix of a file to see if we should emit extern declarations.
// -----------------------------------------------------------------------------
int
check_suffix(char *name) {
char *c;
if (!name) return 0;
if (strlen(name) == 0) return 0;
c = name+strlen(name)-1;
while (c != name) {
if (*c == '.') break;
c--;
}
if (c == name) return 0;
if ((strcmp(c,".c") == 0) ||
(strcmp(c,".C") == 0) ||
(strcmp(c,".cc") == 0) ||
(strcmp(c,".cxx") == 0) ||
(strcmp(c,".c++") == 0) ||
(strcmp(c,".cpp") == 0)) {
return 1;
}
return 0;
}
//-----------------------------------------------------------------
// main()
//
// Main program. Initializes the files and starts the parser.
//-----------------------------------------------------------------
char infilename[256];
char filename[256];
char output_dir[512];
char fn_runtime[256];
#ifdef MACSWIG
FILE *swig_log;
#endif
char *SwigLib;
static int freeze = 0;
static String *lang_config = 0;
/* This function sets the name of the configuration file */
void SWIG_config_file(const String_or_char *filename) {
lang_config = NewString(filename);
}
int SWIG_main(int argc, char *argv[], Language *l) {
int i;
char *c;
char temp[512];
char infile[512];
char *outfile_name = 0;
int help = 0;
int checkout = 0;
int cpp_only = 0;
int tm_debug = 0;
char *includefiles[256];
int includecount = 0;
extern int check_suffix(char *);
extern void scanner_file(DOHFile *);
extern void parser_init(void);
DOH *libfiles = 0;
/* Initialize the SWIG core */
Swig_init();
#ifdef MACSWIG
try {
#endif
// Initialize the preprocessor
Preprocessor_init();
f_wrappers = 0;
f_init = 0;
f_header = 0;
lang = l;
Status = 0;
// Set up some default symbols (available in both SWIG interface files
// and C files)
Preprocessor_define((DOH *) "SWIG 1", 0);
Preprocessor_define((DOH *) "__STDC__", 0);
#ifdef MACSWIG
Preprocessor_define((DOH *) "SWIGMAC 1", 0);
#endif
#ifdef SWIGWIN32
Preprocessor_define((DOH *) "SWIGWIN32 1", 0);
#endif
// Check for SWIG_LIB environment variable
if ((c = getenv("SWIG_LIB")) == (char *) 0) {
sprintf(LibDir,"%s",SWIG_LIB); // Build up search paths
} else {
strcpy(LibDir,c);
}
SwigLib = Swig_copy_string(LibDir); // Make a copy of the real library location
#ifdef MACSWIG
sprintf(temp,"%s:config", LibDir);
Swig_add_directory((DOH *) ":swig_lib:config");
Swig_add_directory((DOH *) ":swig_lib");
#else
sprintf(temp,"%s/config", LibDir);
Swig_add_directory((DOH *) "./swig_lib/config");
Swig_add_directory((DOH *) "./swig_lib");
#endif
Swig_add_directory((DOH *) temp);
Swig_add_directory((DOH *) LibDir);
libfiles = NewList();
// Get options
for (i = 1; i < argc; i++) {
if (argv[i]) {
if (strncmp(argv[i],"-I",2) == 0) {
// Add a new directory search path
includefiles[includecount++] = Swig_copy_string(argv[i]+2);
Swig_mark_arg(i);
} else if (strncmp(argv[i],"-D",2) == 0) {
DOH *d = NewString(argv[i]+2);
Replace(d,(char*)"=",(char*)" ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Preprocessor_define((DOH *) d,0);
// Create a symbol
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-E") == 0) {
cpp_only = 1;
Swig_mark_arg(i);
} else if ((strcmp(argv[i],"-verbose") == 0) ||
(strcmp(argv[i],"-v") == 0)) {
Verbose = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-c++") == 0) {
CPlusPlus=1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-objc") == 0) {
ObjC = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-c") == 0) {
NoInclude=1;
Preprocessor_define((DOH *) "SWIG_NOINCLUDE 1", 0);
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-make_default") == 0) {
GenerateDefault = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-swiglib") == 0) {
printf("%s\n", LibDir);
SWIG_exit (EXIT_SUCCESS);
} else if (strcmp(argv[i],"-o") == 0) {
Swig_mark_arg(i);
if (argv[i+1]) {
outfile_name = Swig_copy_string(argv[i+1]);
Swig_mark_arg(i+1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i],"-version") == 0) {
fprintf(stderr,"\nSWIG Version %s %s\n",
SWIG_VERSION, SWIG_SPIN);
fprintf(stderr,"Copyright (c) 1995-98\n");
fprintf(stderr,"University of Utah and the Regents of the University of California\n");
fprintf(stderr,"\nCompiled with %s\n", SWIG_CC);
SWIG_exit (EXIT_SUCCESS);
} else if (strncmp(argv[i],"-l",2) == 0) {
// Add a new directory search path
Append(libfiles,argv[i]+2);
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-co") == 0) {
checkout = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-freeze") == 0) {
freeze = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-includeall") == 0) {
Preprocessor_include_all(1);
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-tm_debug") == 0) {
tm_debug = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
Swig_mark_arg(i);
help = 1;
}
}
}
if (Verbose)
printf ("LibDir: %s\n", LibDir);
while (includecount > 0) {
Swig_add_directory((DOH *) includefiles[--includecount]);
}
// Parse language dependent options
lang->parse_args(argc,argv);
if (help) SWIG_exit (EXIT_SUCCESS); // Exit if we're in help mode
// Check all of the options to make sure we're cool.
Swig_check_options();
// Add language dependent directory to the search path
{
DOH *rl = NewString("");
#ifdef MACSWIG
Printf(r1,"%s:%s", SwigLib,LibDir);
#else
Printf(rl,"%s/%s", SwigLib,LibDir);
#endif
Swig_add_directory(rl);
}
// If we made it this far, looks good. go for it....
// Create names of temporary files that are created
sprintf(infilename,"%s", argv[argc-1]);
input_file = new char[strlen(infilename)+1];
strcpy(input_file, infilename);
// If the user has requested to check out a file, handle that
if (checkout) {
DOH *s;
char *outfile = input_file;
if (outfile_name)
outfile = outfile_name;
if (Verbose)
printf ("Handling checkout...\n");
s = Swig_include(input_file);
if (!s) {
fprintf(stderr,"Unable to locate '%s' in the SWIG library.\n", input_file);
} else {
FILE *f = fopen(outfile,"r");
if (f) {
fclose(f);
fprintf(stderr,"File '%s' already exists. Checkout aborted.\n", outfile);
} else {
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 {
// Check the suffix for a .c file. If so, we're going to
// declare everything we see as "extern"
ForceExtern = check_suffix(infilename);
// Strip off suffix
c = infilename + strlen(infilename);
while (c != infilename) {
if (*c == '.') {
*c = 0;
break;
} else {
c--;
}
}
if (!outfile_name) {
char *cc = infilename + strlen(infilename);
while (cc != infilename) {
if (*cc == '/') {
cc++;
break;
}
cc--;
}
sprintf(fn_runtime,"%s_wrap.c",infilename);
strcpy(infile,infilename);
outfile_name = fn_runtime;
} else {
sprintf(fn_runtime,"%s",outfile_name);
}
{
// Try to identify the output directory
char *cc = outfile_name;
char *lastc = outfile_name;
while (*cc) {
if (*cc == '/') lastc = cc+1;
cc++;
}
cc = outfile_name;
char *dd = output_dir;
while (cc != lastc) {
*dd = *cc;
dd++;
cc++;
}
*dd = 0;
// Patch up the input filename
cc = infilename + strlen(infilename);
while (cc != infilename) {
if (*cc == '/') {
cc++;
break;
}
cc--;
}
strcpy(infile,cc);
}
// Define the __cplusplus symbol
if (CPlusPlus)
Preprocessor_define((DOH *) "__cplusplus 1", 0);
// Run the preprocessor
if (Verbose)
printf ("Preprocessing...\n");
{
DOH *cpps;
int i;
String *fs = NewString("");
String *ds = Swig_include(input_file);
if (!ds) {
Printf(stderr,"Unable to find '%s'\n", input_file);
SWIG_exit (EXIT_FAILURE);
}
if (lang_config) {
Printf(fs,"\n%%include \"%s\"\n", lang_config);
}
Printf(fs,"\n%%file(\"include\") \"%s\" {\n", Swig_last_file());
Append(fs, ds);
Append(fs,"\n}\n");
Delete(ds);
for (i = 0; i < Len(libfiles); i++) {
Printf(fs,"\n%%include \"%s\"\n", Getitem(libfiles,i));
}
Seek(fs,0,SEEK_SET);
cpps = Preprocessor_parse(fs);
if (cpp_only) {
Printf(stdout,"%s", cpps);
while (freeze);
SWIG_exit (EXIT_SUCCESS);
}
// Initialize the scanner
Seek(cpps, 0, SEEK_SET);
scanner_file(cpps);
}
if ((f_runtime = fopen(fn_runtime,"w")) == 0) {
fprintf(stderr,"Unable to open %s\n", fn_runtime);
exit(0);
}
f_header = NewString("");
f_wrappers = NewString("");
f_init = NewString("");
// Set up the typemap for handling new return strings
{
if (CPlusPlus)
Swig_typemap_register((char*)"newfree",(char*)"p.char",(char*)"",(char*)"delete [] $source;\n",0);
else
Swig_typemap_register((char*)"newfree",(char*)"p.char",(char*)"",(char*)"free($source);\n",0);
}
// If in Objective-C mode. Load in a configuration file
if (ObjC) {
// Add the 'id' object type as a void *
/* DataType *t = new DataType(T_VOID);
t->is_pointer = 1;
t->implicit_ptr = 0;
t->typedef_add("id");
delete t;
*/
}
// Pass control over to the specific language interpreter
if (Verbose) {
fprintf (stdout, "Starting language-specific parse...\n");
fflush (stdout);
}
parser_init();
lang->parse();
if (Verbose) {
fprintf (stdout, "Finished language-specific parse.\n");
fflush (stdout);
}
Dump(f_header,f_runtime);
Dump(f_wrappers, f_runtime);
Wrapper_pretty_print(f_init,f_runtime);
fclose(f_runtime);
if (checkout) {
// File was checked out from the SWIG library. Remove it now
remove(input_file);
}
}
if (tm_debug) Swig_typemap_debug();
while (freeze);
return error_count;
}
// --------------------------------------------------------------------------
// SWIG_exit(int exit_code)
//
// Cleanup and either freeze or exit
// --------------------------------------------------------------------------
void SWIG_exit(int exit_code) {
if (f_runtime) {
fclose(f_runtime);
remove(fn_runtime);
}
while (freeze);
exit (exit_code);
}
// --------------------------------------------------------------------------
// swig_pragma(char *name, char *value)
//
// Handle pragma directives. Not many supported right now
// --------------------------------------------------------------------------
void swig_pragma(char *name, char *value) {
if (strcmp(name,"make_default") == 0) {
GenerateDefault = 1;
}
if (strcmp(name,"no_default") == 0) {
GenerateDefault = 0;
}
if (strcmp(name,"objc_new") == 0) {
objc_construct = Swig_copy_string(value);
}
if (strcmp(name,"objc_delete") == 0) {
objc_destruct = Swig_copy_string(value);
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,171 +0,0 @@
/* -----------------------------------------------------------------------------
* swig11.h
*
* Main header file for the SWIG1.1 core.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1998-2000. The University of Chicago
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
* University of California.
*
* See the file LICENSE for information on usage and redistribution.
*
* $Header$
* ----------------------------------------------------------------------------- */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "swigver.h"
extern "C" {
#include "swig.h"
}
/* Global variables. Needs to be cleaned up */
#ifdef MACSWIG
#define Status Swig_Status
#endif
#define PLAIN_VIRTUAL 1
#define PURE_VIRTUAL 2
#define SUPER_VIRTUAL 3
extern FILE *f_runtime; // Runtime code
extern DOH *f_header; // Headers
extern DOH *f_wrappers; // Wrappers
extern DOH *f_init; // Initialization code
extern FILE *f_input;
extern char LibDir[512]; // Library directory
extern int Status; // Variable creation status
extern int yyparse();
extern int line_number;
extern int start_line;
extern char *input_file; // Current input file
extern int CPlusPlus; // C++ mode
extern int ObjC; // Objective-C mode
extern int ObjCClass; // Objective-C style class
extern int AddMethods; // AddMethods mode
extern int NewObject; // NewObject mode
extern int Inline; // Inline mode
extern int NoInclude; // NoInclude flag
extern char *typemap_lang; // Current language name
extern int error_count;
extern char output_dir[512]; // Output directory
extern int Verbose;
extern int IsVirtual;
#define FatalError() if ((error_count++) > 20) { fprintf(stderr,"Confused by earlier errors. Bailing out\n"); SWIG_exit (EXIT_FAILURE); }
/* Miscellaneous stuff */
#define STAT_READONLY 1
#define MAXSCOPE 16
#define tab2 " "
#define tab4 " "
#define tab8 " "
// Modes for different types of inheritance
#define INHERIT_FUNC 0x1
#define INHERIT_VAR 0x2
#define INHERIT_CONST 0x4
#define INHERIT_ALL (INHERIT_FUNC | INHERIT_VAR | INHERIT_CONST)
struct Pragma {
void *filename;
int lineno;
void *lang;
void *name;
void *value;
Pragma *next;
};
/* Language Class */
class Language {
public:
virtual void parse_args(int argc, char *argv[]) = 0;
virtual void parse() = 0;
/* NEW API */
virtual void function(DOH *node) = 0;
virtual void variable(DOH *node) = 0;
virtual void constant(DOH *node) = 0;
virtual void nativefunction(DOH *node);
/* C++ handling */
virtual void cpp_memberfunction(DOH *node);
virtual void cpp_constructor(DOH *node);
virtual void cpp_destructor(DOH *node);
virtual void cpp_variable(DOH *node);
virtual void cpp_staticfunction(DOH *node);
virtual void cpp_constant(DOH *node);
virtual void cpp_staticvariable(DOH *node);
/* OLD API */
virtual void initialize(void) = 0;
virtual void close(void) = 0;
virtual void set_module(char *mod_name) = 0;
virtual void add_typedef(SwigType *t, char *name);
virtual void create_command(char *cname, char *iname);
virtual void cpp_open_class(char *name, char *rename, 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_pragma(Pragma *plist);
virtual void pragma(char *, char *, char *);
// Declaration of a class, but not a full definition
virtual void cpp_class_decl(char *, char *, char *);
// Import directive
virtual void import(char *filename);
};
/* Emit functions */
extern void new_create_function(char *, char *, SwigType *, ParmList *);
extern void emit_set_get(DOH *node);
extern void emit_set_action(DOHString_or_char *decl);
extern int SWIG_main(int, char **, Language *);
/* These are in the new core */
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();
extern void *Preprocessor_define(void *, int);
extern int Swig_insert_file(const void *filename, void *outfile);
extern FILE *Swig_open(const void *filename);
extern char *Swig_copy_string(const char *s);
}
// Misc
extern int emit_args(DOH *node, Wrapper *f);
extern void emit_func_call(DOH *node, Wrapper *f);
extern void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */
extern int check_numopt(ParmList *);
extern void SWIG_config_file(const String_or_char *);
/* swig11.h ends here */