File move

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4150 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2002-12-03 20:33:35 +00:00
commit 74a3aa015c
25 changed files with 19427 additions and 0 deletions

View file

@ -0,0 +1,41 @@
#######################################################################
# $Header$
#######################################################################
srcdir = @srcdir@
VPATH = @srcdir@
SHELL = /bin/sh
CXX = @CXX@
CFLAGS = @CFLAGS@ @SWILL@
YACC = @YACC@
AR = @AR@
RANLIB = @RANLIB@
TARGET = libmodules.a
OBJS = main.@OBJEXT@ module.@OBJEXT@ emit.@OBJEXT@ overload.@OBJEXT@ lang.@OBJEXT@ typepass.@OBJEXT@ allocate.@OBJEXT@ browser.@OBJEXT@ contract.@OBJEXT@ swigmain.@OBJEXT@ tcl8.@OBJEXT@ python.@OBJEXT@ perl5.@OBJEXT@ guile.@OBJEXT@ ruby.@OBJEXT@ mzscheme.@OBJEXT@ java.@OBJEXT@ php4.@OBJEXT@ ocaml.@OBJEXT@ xml.@OBJEXT@ pike.@OBJEXT@ s-exp.@OBJEXT@
SRCS = main.cxx module.cxx emit.cxx overload.cxx lang.cxx typepass.cxx allocate.cxx browser.cxx contract.cxx swigmain.cxx tcl8.cxx python.cxx perl5.cxx guile.cxx ruby.cxx mzscheme.cxx java.cxx php4.cxx ocaml.cxx xml.cxx pike.cxx s-exp.cxx
INCLUDES = -I$(srcdir)/../Include \
-I$(srcdir)/../DOH/Include \
-I$(srcdir)/../Preprocessor \
-I$(srcdir)/../Swig \
-I../Include
# Rules for creation of a .@OBJEXT@ file from .cxx
.SUFFIXES: .cxx
.cxx.@OBJEXT@:
$(CXX) $(INCLUDES) $(CFLAGS) -c -o $*.@OBJEXT@ $<
swig: $(TARGET)
$(TARGET): $(OBJS)
$(AR) cr $(TARGET) $(OBJS)
$(RANLIB) $(TARGET)
clean::
rm -f *.@OBJEXT@ *~ $(TARGET)
nuke::
rm -f Makefile *~

9
Source/Modules/README Normal file
View file

@ -0,0 +1,9 @@
06/25/2002
This directory contains all of the SWIG language modules. Many of these
modules contain code that dates back to SWIG1.0. The module API has changed
a lot in the development releases so this is fairly messy. We're working on
cleaning it up, but you'll have to bear with us until it's done.
-- Dave

453
Source/Modules/allocate.cxx Normal file
View file

@ -0,0 +1,453 @@
/* -----------------------------------------------------------------------------
* allocate.cxx
*
* This module tries to figure out which classes and structures support
* default constructors and destructors in C++. There are several rules that
* define this behavior including pure abstract methods, private sections,
* and non-default constructors in base classes. See the ARM or
* Doc/Manual/SWIGPlus.html for details.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1998-2002. 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.
* ----------------------------------------------------------------------------- */
char cvsroot_allocate_cxx[] = "$Header$";
#include "swigmod.h"
class Allocate : public Dispatcher {
Node *inclass;
enum AccessMode { PUBLIC, PRIVATE, PROTECTED };
AccessMode cplus_mode;
int extendmode;
/* Checks to see if a class is abstract through inheritance */
int is_abstract_inherit(Node *n, Node *base = 0, int first = 0) {
if (!first && (base == n)) return 0;
if (!base) {
/* Root node */
Symtab *stab = Getattr(n,"symtab"); /* Get symbol table for node */
Symtab *oldtab = Swig_symbol_setscope(stab);
int ret = is_abstract_inherit(n,n,1);
Swig_symbol_setscope(oldtab);
return ret;
}
List *abstract = Getattr(base,"abstract");
if (abstract) {
for (int i = 0; i < Len(abstract); i++) {
Node *nn = Getitem(abstract,i);
String *name = Getattr(nn,"name");
String *base_decl = Getattr(nn,"decl");
if (Strstr(name,"~")) continue; /* Don't care about destructors */
int implemented = 0;
Node *dn = Swig_symbol_clookup(name,0);
if (!dn) {
Printf(stdout,"node: %x '%s'. base: %x '%s'. member '%s'\n", n, Getattr(n,"name"), base, Getattr(base,"name"), name);
}
assert(dn); // Assertion of doom
while (dn && !implemented) {
String *local_decl = Getattr(dn,"decl");
if (local_decl && !Strcmp(local_decl, base_decl)) {
if (Getattr(dn,"abstract")) return 1;
implemented++;
}
dn = Getattr(dn,"csym:nextSibling");
}
if (!implemented && (Getattr(nn,"abstract"))) {
return 1;
}
/*
if (dn && (Getattr(dn,"abstract"))) {
return 1;
}
*/
}
}
List *bases = Getattr(base,"bases");
if (!bases) return 0;
for (int i = 0; i < Len(bases); i++) {
if (is_abstract_inherit(n,Getitem(bases,i))) {
return 1;
}
}
return 0;
}
/* Grab methods used by smart pointers */
List *smart_pointer_methods(Node *cls, List *methods) {
if (!methods) {
methods = NewList();
}
Node *c = firstChild(cls);
String *kind = Getattr(cls,"kind");
int mode;
if (Strcmp(kind,"class") == 0) mode = PRIVATE;
else mode = PUBLIC;
while (c) {
if (Getattr(c,"error") || Getattr(c,"feature:ignore")) {
c = nextSibling(c);
continue;
}
if (Strcmp(nodeType(c),"cdecl") == 0) {
if (!Getattr(c,"feature:ignore")) {
String *storage = Getattr(c,"storage");
if (!((Cmp(storage,"static") == 0) || (Cmp(storage,"typedef") == 0))) {
String *name = Getattr(c,"name");
String *symname = Getattr(c,"sym:name");
Node *e = Swig_symbol_clookup_local(name,0);
if (e && !Getattr(e,"feature:ignore") && (Cmp(symname, Getattr(e,"sym:name")) == 0)) {
Swig_warning(WARN_LANG_DEREF_SHADOW,Getfile(e),Getline(e),"Declaration of '%s' shadows declaration accessible via operator->() at %s:%d\n",
name, Getfile(c),Getline(c));
} else {
/* Make sure node with same name doesn't already exist */
int k;
int match = 0;
for (k = 0; k < Len(methods); k++) {
e = Getitem(methods,k);
if (Cmp(symname,Getattr(e,"sym:name")) == 0) {
match = 1;
break;
}
if ((!symname || (!Getattr(e,"sym:name"))) && (Cmp(name,Getattr(e,"name")) == 0)) {
match = 1;
break;
}
}
if (!match) {
Node *cc = c;
while (cc) {
Append(methods,cc);
cc = Getattr(cc,"sym:nextSibling");
}
}
}
}
}
}
if (Strcmp(nodeType(c),"access") == 0) {
kind = Getattr(c,"kind");
if (Strcmp(kind,"public") == 0) mode = PUBLIC;
else mode = PRIVATE;
}
c = nextSibling(c);
}
/* Look for methods in base classes */
{
Node *bases = Getattr(cls,"bases");
int k;
for (k = 0; k < Len(bases); k++) {
smart_pointer_methods(Getitem(bases,k),methods);
}
}
/* Remove protected/private members */
{
for (int i = 0; i < Len(methods); ) {
Node *n = Getitem(methods,i);
if (checkAttribute(n,"access","protected") || checkAttribute(n,"access","private")) {
Delitem(methods,i);
continue;
}
i++;
}
}
return methods;
}
void mark_exception_classes(ParmList *p) {
while(p) {
SwigType *ty = Getattr(p,"type");
SwigType *t = SwigType_typedef_resolve_all(ty);
Node *c = Swig_symbol_clookup(t,0);
if (c) {
Setattr(c,"cplus:exceptionclass","1");
}
p = nextSibling(p);
}
}
public:
virtual int top(Node *n) {
cplus_mode = PUBLIC;
inclass = 0;
extendmode = 0;
emit_children(n);
return SWIG_OK;
}
virtual int importDirective(Node *n) { return emit_children(n); }
virtual int includeDirective(Node *n) { return emit_children(n); }
virtual int externDeclaration(Node *n) { return emit_children(n); }
virtual int namespaceDeclaration(Node *n) { return emit_children(n); }
virtual int extendDirective(Node *n) {
extendmode = 1;
emit_children(n);
extendmode = 0;
return SWIG_OK;
}
virtual int classDeclaration(Node *n) {
Symtab *symtab = Swig_symbol_current();
Swig_symbol_setscope(Getattr(n,"symtab"));
if (!CPlusPlus) {
/* Always have default constructors/destructors in C */
Setattr(n,"allocate:default_constructor","1");
Setattr(n,"allocate:default_destructor","1");
}
if (Getattr(n,"allocate:visit")) return SWIG_OK;
Setattr(n,"allocate:visit","1");
/* Always visit base classes first */
{
List *bases = Getattr(n,"bases");
if (bases) {
for (int i = 0; i < Len(bases); i++) {
Node *b = Getitem(bases,i);
classDeclaration(b);
}
}
}
inclass = n;
String *kind = Getattr(n,"kind");
if (Strcmp(kind,"class") == 0) {
cplus_mode = PRIVATE;
} else {
cplus_mode = PUBLIC;
}
emit_children(n);
/* Check if the class is abstract via inheritance. This might occur if a class didn't have
any pure virtual methods of its own, but it didn't implement all of the pure methods in
a base class */
if (is_abstract_inherit(n)) {
if ((!Getattr(n,"abstract")) && ((Getattr(n,"allocate:public_constructor") || (!Getattr(n,"feature:nodefault") && !Getattr(n,"allocate:has_constructor"))))) {
if (!Getattr(n,"feature:notabstract")) {
Swig_warning(WARN_TYPE_ABSTRACT,Getfile(n),Getline(n),"Class '%s' might be abstract. No constructors generated. \n", SwigType_namestr(Getattr(n,"name")));
Setattr(n,"abstract",NewList());
}
}
}
if (!Getattr(n,"allocate:has_constructor")) {
/* No constructor is defined. We need to check a few things */
/* If class is abstract. No default constructor. Sorry */
if (Getattr(n,"abstract")) {
Delattr(n,"allocate:default_constructor");
}
if (!Getattr(n,"allocate:default_constructor")) {
/* Check base classes */
List *bases = Getattr(n,"bases");
int allows_default = 1;
for (int i = 0; i < Len(bases); i++) {
Node *n = Getitem(bases,i);
/* If base class does not allow default constructor, we don't allow it either */
if (!Getattr(n,"allocate:default_constructor") && (!Getattr(n,"allocate:default_base_constructor"))) {
allows_default = 0;
}
}
if (allows_default) {
Setattr(n,"allocate:default_constructor","1");
}
}
}
if (!Getattr(n,"allocate:has_destructor")) {
/* No destructor was defined. We need to check a few things here too */
List *bases = Getattr(n,"bases");
int allows_destruct = 1;
for (int i = 0; i < Len(bases); i++) {
Node *n = Getitem(bases,i);
/* If base class does not allow default destructor, we don't allow it either */
if (!Getattr(n,"allocate:default_destructor") && (!Getattr(n,"allocate:default_base_destructor"))) {
allows_destruct = 0;
}
}
if (allows_destruct) {
Setattr(n,"allocate:default_destructor","1");
}
}
/* Check if base classes allow smart pointers, but might be hidden */
if (!Getattr(n,"allocate:smartpointer")) {
Node *sp = Swig_symbol_clookup((char*)"operator ->",0);
if (sp) {
/* Look for parent */
Node *p = parentNode(sp);
if (Strcmp(nodeType(p),"extend") == 0) {
p = parentNode(p);
}
if (Strcmp(nodeType(p),"class") == 0) {
if (Getattr(p,"feature:ignore")) {
Setattr(n,"allocate:smartpointer",Getattr(p,"allocate:smartpointer"));
}
}
}
}
/* Only care about default behavior. Remove temporary values */
Setattr(n,"allocate:visit","1");
inclass = 0;
Swig_symbol_setscope(symtab);
return SWIG_OK;
}
virtual int accessDeclaration(Node *n) {
String *kind = Getattr(n,"kind");
if (Cmp(kind,"public") == 0) {
cplus_mode = PUBLIC;
} else if (Cmp(kind,"private") == 0) {
cplus_mode = PRIVATE;
} else if (Cmp(kind,"protected") == 0) {
cplus_mode = PROTECTED;
}
return SWIG_OK;
}
virtual int cDeclaration(Node *n) {
mark_exception_classes(Getattr(n,"throws"));
if (inclass) {
String *name = Getattr(n,"name");
if (cplus_mode != PUBLIC) {
/* Look for a private assignment operator */
if (Strcmp(name,"operator =") == 0) {
Setattr(inclass,"allocate:noassign","1");
}
} else {
/* Look for smart pointer operator */
if ((Strcmp(name,"operator ->") == 0) && (!Getattr(n,"feature:ignore"))) {
/* Look for version with no parameters */
Node *sn = n;
while (sn) {
if (!Getattr(sn,"parms")) {
SwigType *type = SwigType_typedef_resolve_all(Getattr(sn,"type"));
SwigType_push(type,Getattr(sn,"decl"));
Delete(SwigType_pop_function(type));
SwigType *base = SwigType_base(type);
Node *sc = Swig_symbol_clookup(base, 0);
if ((sc) && (Strcmp(nodeType(sc),"class") == 0)) {
if (SwigType_check_decl(type,"p.")) {
List *methods = smart_pointer_methods(sc,0);
Setattr(inclass,"allocate:smartpointer",methods);
break;
} else {
/* Hmmm. The return value is not a pointer. If the type is a value
or reference. We're going to chase it to see if another operator->()
can be found */
if ((SwigType_check_decl(type,"")) || (SwigType_check_decl(type,"r."))) {
Node *nn = Swig_symbol_clookup((char*)"operator ->", Getattr(sc,"symtab"));
if (nn) {
sn = nn;
continue;
} else {
break;
}
} else {
break;
}
}
} else {
break;
}
} else {
break;
}
}
}
}
}
return SWIG_OK;
}
virtual int constructorDeclaration(Node *n) {
if (!inclass) return SWIG_OK;
Parm *parms = Getattr(n,"parms");
mark_exception_classes(Getattr(n,"throws"));
if (!extendmode) {
if (!ParmList_numrequired(parms)) {
/* Class does define a default constructor */
/* However, we had better see where it is defined */
if (cplus_mode == PUBLIC) {
Setattr(inclass,"allocate:default_constructor","1");
} else if (cplus_mode == PROTECTED) {
Setattr(inclass,"allocate:default_base_constructor","1");
}
}
/* Class defines some kind of constructor. May or may not be public */
Setattr(inclass,"allocate:has_constructor","1");
if (cplus_mode == PUBLIC) {
Setattr(inclass,"allocate:public_constructor","1");
}
}
/* See if this is a copy constructor */
if (parms && (ParmList_numrequired(parms) == 1)) {
/* Look for a few cases. X(const X &), X(X &), X(X *) */
String *cc = NewStringf("r.q(const).%s", Getattr(inclass,"name"));
if (Strcmp(cc,Getattr(parms,"type")) == 0) {
Setattr(n,"copy_constructor","1");
}
Delete(cc);
cc = NewStringf("r.%s", Getattr(inclass,"name"));
if (Strcmp(cc,Getattr(parms,"type")) == 0) {
Setattr(n,"copy_constructor","1");
}
Delete(cc);
cc = NewStringf("p.%s", Getattr(inclass,"name"));
String *ty = SwigType_strip_qualifiers(Getattr(parms,"type"));
if (Strcmp(cc,ty) == 0) {
Setattr(n,"copy_constructor","1");
}
Delete(cc);
Delete(ty);
}
return SWIG_OK;
}
virtual int destructorDeclaration(Node *n) {
if (!inclass) return SWIG_OK;
if (!extendmode) {
Setattr(inclass,"allocate:has_destructor","1");
if (cplus_mode == PUBLIC) {
Setattr(inclass,"allocate:default_destructor","1");
} else if (cplus_mode == PROTECTED) {
Setattr(inclass,"allocate:default_base_destructor","1");
}
}
return SWIG_OK;
}
};
void Swig_default_allocators(Node *n) {
if (!n) return;
Allocate *a = new Allocate;
a->top(n);
delete a;
}

415
Source/Modules/browser.cxx Normal file
View file

@ -0,0 +1,415 @@
/* -----------------------------------------------------------------------------
* browser.cxx
*
* A web-base parse tree browser using SWILL. This is an optional
* feature that's normally disabled.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 2002. The University of Chicago
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
char cvsroot_browser_cxx[] = "$Header$";
#include "swigmod.h"
#ifdef SWIG_SWILL
extern "C" {
#include "swill.h"
}
static FILE *out = 0;
static Node *view_top = 0;
class Browser : public Dispatcher {
void show_checkbox(Node *t, Node *n) {
int v = 0;
if (Getmeta(n,"visible")) {
v = 1;
}
if (v) {
Printf(out,"<a name=\"n%x\"></a>[<a href=\"hide.html?node=0x%x&hn=0x%x#n%x\">-</a>] ", n, t, n,n);
} else {
Printf(out,"<a name=\"n%x\"></a>[<a href=\"show.html?node=0x%x&hn=0x%x#n%x\">+</a>] ", n, t, n,n);
}
}
void show_attributes(Node *obj) {
if (!Getmeta(obj,"visible")) return;
String *os = NewString("");
String *k;
k = Firstkey(obj);
while (k) {
if ((Cmp(k,"nodeType") == 0) || (Cmp(k,"firstChild") == 0) || (Cmp(k,"lastChild") == 0) ||
(Cmp(k,"parentNode") == 0) || (Cmp(k,"nextSibling") == 0) ||
(Cmp(k,"previousSibling") == 0) || (*(Char(k)) == '$')) {
/* Do nothing */
} else if (Cmp(k,"parms") == 0) {
String *o = NewString("");
Printf(o,"%s", ParmList_protostr(Getattr(obj,k)));
Replaceall(o,"&","&amp;");
Replaceall(o,"<","&lt;");
Replaceall(o,">","&gt;");
Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - %s\n", Getattr(obj,k), k, o);
Delete(o);
} else {
DOH *o;
char *trunc = "";
if (DohIsString(Getattr(obj,k))) {
o = Str(Getattr(obj,k));
if (Len(o) > 70) {
trunc = "...";
}
Replaceall(o,"&","&amp;");
Replaceall(o,"<","&lt;");
Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc);
Delete(o);
} else {
Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k));
}
}
k = Nextkey(obj);
}
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Delete(os);
}
public:
virtual int emit_one(Node *n) {
char *tag = Char(nodeType(n));
char *file = Char(Getfile(n));
int line = Getline(n);
char *name = GetChar(n,"name");
show_checkbox(view_top, n);
Printf(out,"<b><a href=\"index.html?node=0x%x\">%s</a></b>", n, tag);
if (name) {
Printf(out," (%s)", name);
}
Printf(out,". %s:%d\n", file, line);
Printf(out,"<br>");
Dispatcher::emit_one(n);
return SWIG_OK;
}
virtual int emit_children(Node *n) {
if (Getmeta(n,"visible")) {
Printf(out,"<blockquote>\n");
Dispatcher::emit_children(n);
Printf(out,"</blockquote>\n");
}
return SWIG_OK;
}
virtual int defaultHandler(Node *n) {
show_attributes(n);
return SWIG_OK;
}
virtual int top(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
virtual int includeDirective(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
virtual int importDirective(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
virtual int extendDirective(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
virtual int classDeclaration(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
virtual int templateDeclaration(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
virtual int enumDeclaration(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
virtual int typemapDirective(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
virtual int namespaceDeclaration(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
virtual int usingDeclaration(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
};
static int browser_exit = 0;
static Node *tree_top = 0;
static Browser *browse = 0;
/* ----------------------------------------------------------------------
* exit_handler() - Force the browser to exit
* ---------------------------------------------------------------------- */
void exit_handler(FILE *f) {
browser_exit = 1;
Printf(f,"Terminated.\n");
}
/* ----------------------------------------------------------------------
* node_handler() - Generate information about a specific node
* ---------------------------------------------------------------------- */
static void display(FILE *f, Node *n) {
/* Print standard HTML header */
Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", SWIG_VERSION);
Printf(f,"<b>SWIG-%s</b><br>\n", SWIG_VERSION);
Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
if (n != tree_top) {
Printf(f," [ <a href=\"index.html?node=0x%x\">Up</a> ]", parentNode(n));
}
Printf(f," [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f,"<br><hr><p>\n");
out = f;
browse->emit_one(n);
/* Print standard footer */
Printf(f,"<br><hr></BODY></HTML>\n");
}
void node_handler(FILE *f) {
Node *n = 0;
if (!swill_getargs("p(node)", &n)) {
n = tree_top;
}
view_top = n;
display(f,n);
}
/* ----------------------------------------------------------------------
* hide_handler() - Hide a node
* ---------------------------------------------------------------------- */
void hide_handler(FILE *f) {
Node *n = 0;
if (!swill_getargs("p(hn)", &n)) {
n = 0;
}
if (n) {
Delmeta(n,"visible");
}
node_handler(f);
}
void show_handler(FILE *f) {
Node *n = 0;
if (!swill_getargs("p(hn)", &n)) {
n = 0;
}
if (n) {
Setmeta(n,"visible","1");
}
node_handler(f);
}
void raw_data(FILE *out, Node *obj) {
if (!obj) return;
if (DohIsMapping(obj)) {
String *k;
String *os = NewString("");
Printf(os,"Hash {\n");
k = Firstkey(obj);
while (k) {
DOH *o;
const char *trunc = "";
if (DohIsString(Getattr(obj,k))) {
o = Str(Getattr(obj,k));
if (Len(o) > 70) {
trunc = "...";
}
Replaceall(o,"<","&lt;");
Printf(os," <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc);
Delete(o);
} else {
Printf(os," <a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k));
}
k = Nextkey(obj);
}
Printf(os,"}\n");
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Delete(os);
} else if (DohIsString(obj)) {
String *o = Str(obj);
Replaceall(o,"<","&lt;");
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(o));
Delete(o);
} else if (DohIsSequence(obj)) {
int i;
String *os = NewString("");
Printf(os,"List [\n");
for (i = 0; i < Len(obj); i++) {
DOH *o = Getitem(obj,i);
const char *trunc = "";
if (DohIsString(o)) {
String *s = Str(o);
if (Len(s) > 70) {
trunc = "...";
}
Replaceall(o,"<","&lt;");
Printf(os," <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o,i,s, trunc);
Delete(s);
} else {
Printf(os," <a href=\"data.html?n=0x%x\">?</a> [%d] - 0x%x\n", o, i, o);
}
}
Printf(os,"\n]\n");
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Delete(os);
}
}
void data_handler(FILE *f) {
DOH *n = 0;
if (!swill_getargs("p(n)", &n)) {
n = 0;
}
Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", SWIG_VERSION);
Printf(f,"<b>SWIG-%s</b><br>\n", SWIG_VERSION);
Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f,"<br><hr><p>\n");
if (n) {
raw_data(f,n);
}
/* Print standard footer */
Printf(f,"<br><hr></BODY></HTML>\n");
}
void symbol_handler(FILE *f) {
Symtab *sym;
char *name = 0;
Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", SWIG_VERSION);
Printf(f,"<b>SWIG-%s</b><br>\n", SWIG_VERSION);
Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f," [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f,"<br><hr><p>\n");
if (!swill_getargs("p(sym)|s(name)", &sym, &name)) {
sym = Swig_symbol_getscope("");
name = 0;
}
if (!sym) {
Printf(f,"No symbol table specified!\n");
return;
}
{
String *q = Swig_symbol_qualifiedscopename(sym);
if (!Len(q)) {
Printf(f,"<b>Symbol table: :: (global)</b><br>\n");
} else {
Printf(f,"<b>Symbol table: %s</b><br>\n", q);
}
Delete(q);
}
fprintf(f,"<p><form action=\"symbol.html\" method=GET>\n");
fprintf(f,"Symbol lookup: <input type=text name=name size=40></input><br>\n");
fprintf(f,"<input type=hidden name=sym value=\"0x%x\">\n", sym);
fprintf(f,"Submit : <input type=submit></input>\n");
fprintf(f,"</form>");
if (name) {
Node *n = Swig_symbol_clookup(name,sym);
Printf(f,"Symbol '%s':\n", name);
Printf(f,"<blockquote>\n");
if (!n) {
Printf(f,"Not defined!\n");
} else {
raw_data(f,n);
}
Printf(f,"</blockquote>\n");
}
Printf(f,"<p><b>Nested scopes</b><br>\n");
Printf(f,"<blockquote><pre>\n");
{
Hash *h;
h = firstChild(sym);
while (h) {
Printf(f,"<a href=\"symbol.html?sym=0x%x\">%s</a>\n", h, Getattr(h,"name"));
h = nextSibling(h);
}
}
Printf(f,"</pre></blockquote>\n");
Printf(f,"<p><b>Symbol table contents</b></br>\n");
raw_data(f,Getattr(sym,"symtab"));
Printf(f,"<br><hr></BODY></HTML>\n");
}
#endif
void
Swig_browser(Node *top, int port) {
#ifdef SWIG_SWILL
int sport;
browser_exit = 0;
/* Initialize the server */
sport = swill_init(port);
if (sport < 0) {
Printf(stderr,"Couldn't open socket on port %d. Sorry.\n", port);
return;
}
browse = new Browser();
Setmeta(top,"visible","1");
tree_top = top;
Printf(stderr,"SWIG: Tree browser listening on port %d\n", sport);
swill_handle("exit.html", exit_handler,0);
swill_handle("index.html", node_handler, 0);
swill_handle("hide.html", hide_handler,0);
swill_handle("show.html", show_handler,0);
swill_handle("data.html", data_handler,0);
swill_handle("symbol.html", symbol_handler, 0);
swill_netscape("index.html");
while (!browser_exit) {
swill_serve();
}
Printf(stderr,"Browser terminated.\n");
swill_close();
delete browse;
return;
#endif
}

118
Source/Modules/contract.cxx Normal file
View file

@ -0,0 +1,118 @@
/* -----------------------------------------------------------------------------
* contract.cxx
*
* Experimental support for contracts
*
* Author(s) : Aquinas Hobor (aahobor@cs.uchicago.edu)
*
* Copyright (C) 1999-2000. The University of Chicago
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
char cvsroot_contract_cxx[] = "$Header$";
#include "swigmod.h"
class Contracts : public Dispatcher {
public:
virtual int top(Node *n) {
emit_children(n);
return SWIG_OK;
}
virtual int importDirective(Node *n) { return emit_children(n); }
virtual int includeDirective(Node *n) { return emit_children(n); } // ?
virtual int externDeclaration(Node *n) { return emit_children(n); }
String * strParms(ParmList *l) {
int comma = 0;
int i = 0;
Parm *p = l;
SwigType *pt;
String * returns = NewString("");
while(p) {
String *pname;
pt = Getattr(p,"type");
if ((SwigType_type(pt) != T_VOID)) {
if (comma) Printf(returns,",");
pname = Swig_cparm_name(p,i);
Printf(returns,"%s",SwigType_rcaststr(pt,pname));
comma = 1;
i++;
}
p = nextSibling(p);
}
return returns;
}
virtual int cDeclaration(Node *n) {
String *name = Getattr(n,"name");
String *k = Getattr(n,"feature:contract");
if(k)
{
/* make the names */
ParmList *l = Getmeta(k,"parms");
String *params = ParmList_str(l);
String *transformed = strParms(l);
if(DohStrcmp(params,"")==0) {
DohDelete(params);
params = DohNewString("void");
}
String *contractName = DohNewStringf("__SWIG_precontract_%s",name);
/* make the contract */
String *contract = DohNewStringf("int %s(%s,int rt[2])\n{\n",contractName,params);
SwigScanner * ss = NewSwigScanner();
SwigScanner_clear(ss);
SwigScanner_push(ss,Copy(k));
SwigScanner_token(ss); // Get rid of the '{' at the begining
/* loop over the clauses */
int clauseNum = 1;
int token = -1;
while(1) {
String *clause = DohNewString(""); /*BUG -- should free*/
while((token=SwigScanner_token(ss))) {
if ((token==SWIG_TOKEN_SEMI)||(token==SWIG_TOKEN_RBRACE))
break;
// if (token != SWIG_TOKEN_ENDLINE)
Printf(clause,"%s",SwigScanner_text(ss));
}
if (DohStrcmp(clause,"\n") != 0) {
Printf(contract,"if (!(%s",clause);
Printf(contract,")) {\nrt[0]=__LINE__;\nrt[1]=%i;\nreturn 1;\n}\n",clauseNum);
}
if(token==SWIG_TOKEN_RBRACE) break;
clauseNum++;
}
/* finish it off and attach it to the main tree */
Printf(contract,"return 0;\n}\n");
Setattr(n,"wrap:code",contract); /*BUG -- WHAT IF SOMETHING IS ALREADY THERE*/
/* Generate the calling code */
String * calling = DohNewString("{\nint cfail[2];\nchar message[255];\n");
Printf(calling,"if (%s(%s,cfail)) {\n",contractName,transformed);
Printf(calling,"sprintf(message,\"Contract %s failed on clause %%i (line %%i)!\",cfail[1],cfail[0]);\n",contractName);
Printf(calling,"PyErr_SetString(PyExc_Exception,message);return NULL;\n}\n");
Printf(calling,"}\n");
/* Setattr(n,"feature:preassert",calling); */
}
/*There are two attributes "feature:preassert" and "feature:postassert".*/
return SWIG_OK;
}
};
void Swig_contracts(Node *n) {
Printf(stdout,"Applying contracts (experimental v0.09)\n");
Contracts *a = new Contracts;
a->top(n);
delete a;
}

452
Source/Modules/emit.cxx Normal file
View file

@ -0,0 +1,452 @@
/* -----------------------------------------------------------------------------
* 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 "swigmod.h"
char cvsroot_emit_cxx[] = "$Header$";
extern SwigType *cplus_value_type(SwigType *t);
/* -----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------- */
void emit_args(SwigType *rt, ParmList *l, Wrapper *f) {
Parm *p;
String *tm;
/* Emit function arguments */
Swig_cargs(f, l);
/* Handle return type */
if (rt && (SwigType_type(rt) != T_VOID)) {
if (!CPlusPlus || (CPlusPlus && !SwigType_isclass(rt))) {
Wrapper_add_local(f,"result", SwigType_lstr(rt,"result"));
} else {
SwigType *vt = 0;
vt = cplus_value_type(rt);
if (!vt) {
Wrapper_add_local(f,"result", SwigType_lstr(rt,"result"));
} else {
Wrapper_add_local(f,"result", SwigType_lstr(vt,"result"));
Delete(vt);
}
}
}
/* Attach typemaps to parameters */
/* Swig_typemap_attach_parms("ignore",l,f); */
Swig_typemap_attach_parms("default",l,f);
Swig_typemap_attach_parms("arginit",l,f);
/* Apply the arginit and default */
p = l;
while (p) {
tm = Getattr(p,"tmap:arginit");
if (tm) {
Replace(tm,"$target", Getattr(p,"lname"), DOH_REPLACE_ANY);
Printv(f->code,tm,"\n",NIL);
p = Getattr(p,"tmap:arginit:next");
} else {
p = nextSibling(p);
}
}
/* Apply the default typemap */
p = l;
while (p) {
tm = Getattr(p,"tmap:default");
if (tm) {
Replace(tm,"$target", Getattr(p,"lname"), DOH_REPLACE_ANY);
Printv(f->code,tm,"\n",NIL);
p = Getattr(p,"tmap:default:next");
} else {
p = nextSibling(p);
}
}
#ifdef DEPRECATED
/* Apply the ignore typemap */
p = l;
while (p) {
tm = Getattr(p,"tmap:ignore");
if (tm) {
Parm *np;
Replace(tm,"$target", Getattr(p,"lname"), DOH_REPLACE_ANY);
Printv(f->code,tm,"\n",NIL);
np = Getattr(p,"tmap:ignore:next");
/* Deprecate this part later */
while (p && (p != np)) {
Setattr(p,"ignore","1");
p = nextSibling(p);
}
/* -- end deprecate */
} else {
p = nextSibling(p);
}
}
#endif
return;
}
/* -----------------------------------------------------------------------------
* emit_attach_parmmaps()
*
* Attach the standard parameter related typemaps.
* ----------------------------------------------------------------------------- */
void emit_attach_parmmaps(ParmList *l, Wrapper *f) {
Swig_typemap_attach_parms("in",l,f);
Swig_typemap_attach_parms("typecheck",l,0);
Swig_typemap_attach_parms("argout",l,f);
Swig_typemap_attach_parms("check",l,f);
Swig_typemap_attach_parms("freearg",l,f);
{
/* This is compatibility code to deal with the deprecated "ignore" typemap */
Parm *p = l;
Parm *np;
String *tm;
while (p) {
tm = Getattr(p,"tmap:in");
if (tm && checkAttribute(p,"tmap:in:numinputs","0")) {
Replaceall(tm,"$target", Getattr(p,"lname"));
Printv(f->code,tm,"\n",NIL);
np = Getattr(p,"tmap:in:next");
while (p && (p != np)) {
Setattr(p,"ignore","1");
p = nextSibling(p);
}
} else if (tm) {
p = Getattr(p,"tmap:in:next");
} else {
p = nextSibling(p);
}
}
}
/* Perform a sanity check on "in" and "freearg" typemaps. These
must exactly match to avoid chaos. If a mismatch occurs, we
nuke the freearg typemap */
{
Parm *p = l;
Parm *npin, *npfreearg;
while (p) {
npin = Getattr(p,"tmap:in:next");
/*
if (Getattr(p,"tmap:ignore")) {
npin = Getattr(p,"tmap:ignore:next");
} else if (Getattr(p,"tmap:in")) {
npin = Getattr(p,"tmap:in:next");
}
*/
if (Getattr(p,"tmap:freearg")) {
npfreearg = Getattr(p,"tmap:freearg:next");
if (npin != npfreearg) {
while (p != npin) {
Delattr(p,"tmap:freearg");
Delattr(p,"tmap:freearg:next");
p = nextSibling(p);
}
}
}
p = npin;
}
}
/* Check for variable length arguments with no input typemap.
If no input is defined, we set this to ignore and print a
message.
*/
{
Parm *p = l;
Parm *lp = 0;
while (p) {
if (!checkAttribute(p,"tmap:in:numinputs","0")) {
lp = p;
p = Getattr(p,"tmap:in:next");
continue;
}
if (SwigType_isvarargs(Getattr(p,"type"))) {
Swig_warning(WARN_LANG_VARARGS,input_file,line_number,"Variable length arguments discarded.\n");
Setattr(p,"tmap:in","");
}
lp = 0;
p = nextSibling(p);
}
/* Check if last input argument is variable length argument */
if (lp) {
p = lp;
while (p) {
if (SwigType_isvarargs(Getattr(p,"type"))) {
Setattr(l,"emit:varargs",lp);
break;
}
p = nextSibling(p);
}
}
}
}
/* -----------------------------------------------------------------------------
* emit_num_arguments() ** new in 1.3.10
*
* Calculate the total number of arguments. This function is safe for use
* with multi-valued typemaps which may change the number of arguments in
* strange ways.
* ----------------------------------------------------------------------------- */
int emit_num_arguments(ParmList *parms) {
Parm *p = parms;
int nargs = 0;
while (p) {
if (Getattr(p,"tmap:in")) {
nargs += GetInt(p,"tmap:in:numinputs");
p = Getattr(p,"tmap:in:next");
} else {
p = nextSibling(p);
}
}
#ifdef DEPRECATED
while (p) {
/* Ignored arguments */
if (Getattr(p,"tmap:ignore")) {
p = Getattr(p,"tmap:ignore:next");
} else {
/* Marshalled arguments */
nargs++;
if (Getattr(p,"tmap:in")) {
p = Getattr(p,"tmap:in:next");
} else {
p = nextSibling(p);
}
}
}
#endif
if (parms && (p = Getattr(parms,"emit:varargs"))) {
if (!nextSibling(p)) {
nargs--;
}
}
return nargs;
}
/* -----------------------------------------------------------------------------
* emit_num_required() ** new in 1.3.10
*
* Computes the number of required arguments. This is function is safe for
* use with multi-valued typemaps and knows how to skip over everything
* properly.
* ----------------------------------------------------------------------------- */
int emit_num_required(ParmList *parms) {
Parm *p = parms;
int nargs = 0;
while (p) {
if (Getattr(p,"tmap:in") && checkAttribute(p,"tmap:in:numinputs","0")) {
p = Getattr(p,"tmap:in:next");
} else {
if (Getattr(p,"value")) break;
if (Getattr(p,"tmap:default")) break;
nargs+= GetInt(p,"tmap:in:numinputs");
if (Getattr(p,"tmap:in")) {
p = Getattr(p,"tmap:in:next");
} else {
p = nextSibling(p);
}
}
}
/* Print message for non-default arguments */
while (p) {
if (Getattr(p,"tmap:in") && checkAttribute(p,"tmap:in:numinputs","0")) {
p = Getattr(p,"tmap:in:next");
} else {
if (!Getattr(p,"value") && (!Getattr(p,"tmap:default"))) {
Swig_error(Getfile(p),Getline(p),"Error. Non-optional argument '%s' follows an optional argument.\n",Getattr(p,"name"));
}
if (Getattr(p,"tmap:in")) {
p = Getattr(p,"tmap:in:next");
} else {
p = nextSibling(p);
}
}
}
if (parms && (p = Getattr(parms,"emit:varargs"))) {
if (!nextSibling(p)) {
nargs--;
}
}
return nargs;
}
/* -----------------------------------------------------------------------------
* emit_isvarargs()
*
* Checks if a function is a varargs function
* ----------------------------------------------------------------------------- */
int
emit_isvarargs(ParmList *p) {
if (!p) return 0;
if (Getattr(p,"emit:varargs")) return 1;
return 0;
}
/* -----------------------------------------------------------------------------
* replace_args()
* ----------------------------------------------------------------------------- */
static
void replace_args(Parm *p, String *s) {
while (p) {
String *n = Getattr(p,"name");
if (n) {
Replace(s,n,Getattr(p,"lname"), DOH_REPLACE_ID);
}
p = nextSibling(p);
}
}
/* -----------------------------------------------------------------------------
* int emit_action()
*
* Emits action code for a wrapper and checks for exception handling
* ----------------------------------------------------------------------------- */
void emit_action(Node *n, Wrapper *f) {
String *tm;
String *action;
String *wrap;
Parm *p;
SwigType *rt;
ParmList *throws = Getattr(n,"throws");
/* Look for fragments */
{
String *f;
f = Getattr(n,"feature:fragment");
if (f) {
char *c, *tok;
String *t = Copy(f);
c = Char(t);
tok = strtok(c,",");
while (tok) {
Swig_fragment_emit(tok);
tok = strtok(NULL,",");
}
Delete(t);
}
}
/* Emit wrapper code (if any) */
wrap = Getattr(n,"wrap:code");
if (wrap && Swig_filebyname("header")!=Getattr(n,"wrap:code:done") ) {
File *f_code = Swig_filebyname("header");
if (f_code) {
Printv(f_code,wrap,NIL);
}
Setattr(n,"wrap:code:done",f_code);
}
action = Getattr(n,"feature:action");
if (!action)
action = Getattr(n,"wrap:action");
assert(action);
/* Get the return type */
rt = Getattr(n,"type");
/* Preassert -- EXPERIMENTAL */
tm = Getattr(n,"feature:preassert");
if (tm) {
p = Getattr(n,"parms");
replace_args(p,tm);
Printv(f->code,tm,"\n",NIL);
}
/* Exception handling code */
/* If we are in C++ mode and there is a throw specifier. We're going to
enclose the block in a try block */
if (throws) {
Printf(f->code,"try {\n");
}
/* Look for except typemap (Deprecated) */
tm = Swig_typemap_lookup_new("except",n,"result",0);
/* Look for except feature */
if (!tm) {
tm = Getattr(n,"feature:except");
if (tm) tm = Copy(tm);
}
if ((tm) && Len(tm) && (Strcmp(tm,"1") != 0)) {
Replaceall(tm,"$name",Getattr(n,"name"));
Replaceall(tm,"$symname", Getattr(n,"sym:name"));
Replaceall(tm,"$function", action);
Replaceall(tm,"$action", action);
Printv(f->code,tm,"\n", NIL);
Delete(tm);
} else {
Printv(f->code, action, "\n",NIL);
}
if (throws) {
Printf(f->code,"}\n");
for (Parm *ep = throws; ep; ep = nextSibling(ep)) {
String *em = Swig_typemap_lookup_new("throws",ep,"_e",0);
if (em) {
Printf(f->code,"catch(%s) {\n", SwigType_str(Getattr(ep,"type"),"&_e"));
Printv(f->code,em,"\n",NIL);
Printf(f->code,"}\n");
} else {
Swig_warning(WARN_TYPEMAP_THROW, Getfile(n), Getline(n),
"No 'throw' typemap defined for exception type '%s'\n", SwigType_str(Getattr(ep,"type"),0));
}
}
Printf(f->code,"catch(...) { throw; }\n");
}
/* Postassert - EXPERIMENTAL */
tm = Getattr(n,"feature:postassert");
if (tm) {
p = Getattr(n,"parms");
replace_args(p,tm);
Printv(f->code,tm,"\n",NIL);
}
}

1208
Source/Modules/guile.cxx Normal file

File diff suppressed because it is too large Load diff

1900
Source/Modules/java.cxx Normal file

File diff suppressed because it is too large Load diff

1853
Source/Modules/lang.cxx Normal file

File diff suppressed because it is too large Load diff

622
Source/Modules/main.cxx Normal file
View file

@ -0,0 +1,622 @@
/* -----------------------------------------------------------------------------
* 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.
* ----------------------------------------------------------------------------- */
char cvsroot_main_cxx[] = "$Header$";
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include "swigmod.h"
#ifndef MACSWIG
#include "swigconfig.h"
#endif
#include "swigwarn.h"
extern "C" {
#include "preprocessor.h"
}
#include <ctype.h>
#ifndef SWIG_LIB
#define SWIG_LIB "/usr/local/lib/swig1.3"
#endif
#ifndef SWIG_CC
#define SWIG_CC "CC"
#endif
// Global variables
char LibDir[512]; // Library directory
Language *lang; // Language method
int CPlusPlus = 0;
int Extend = 0; // Extend flag
int ForceExtern = 0; // Force extern mode
int GenerateDefault = 1; // Generate default constructors
char *Config = 0;
int NoInclude = 0;
int Verbose = 0;
int NoExtern = 0;
int NoExcept = 0;
extern "C" {
extern String *ModuleName;
}
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\
-importall - Follow all #include statements as imports\n\
-ignoremissing - Ignore missing include files.\n\
-l<ifile> - Include SWIG library file.\n\
-M - List all dependencies. \n\
-MM - List dependencies, but omit files in SWIG library.\n\
-makedefault - Create default constructors/destructors (the default)\n\
-module - Set module name\n\
-nodefault - Do not generate constructors/destructors\n\
-noexcept - Do not wrap exception specifiers.\n\
-noextern - Do not generate extern declarations.\n\
-o outfile - Set name of the output file.\n\
-swiglib - Report location of SWIG library and exit\n\
-v - Run in verbose mode\n\
-version - Print SWIG version number\n\
-Wall - Enable all warning messages\n\
-wn - Suppress warning number n\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;
c = Swig_file_suffix(name);
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;
}
// -----------------------------------------------------------------------------
// install_opts(int argc, char *argv[])
// Install all command line options as preprocessor symbols
// -----------------------------------------------------------------------------
static void
install_opts(int argc, char *argv[]) {
int i;
int noopt = 0;
char *c;
for (i = 1; i < (argc-1); i++) {
if (argv[i]) {
if ((*argv[i] == '-') && (!isupper(*(argv[i]+1)))) {
String *opt = NewStringf("SWIGOPT%(upper)s", argv[i]);
Replaceall(opt,"-","_");
c = Char(opt);
noopt = 0;
while (*c) {
if (!(isalnum(*c) || (*c == '_'))) {
noopt = 1;
break;
}
c++;
}
if (((i+1) < (argc-1)) && (argv[i+1]) && (*argv[i+1] != '-')) {
Printf(opt," %s", argv[i+1]);
i++;
} else {
Printf(opt," 1");
}
if (!noopt) {
/* Printf(stdout,"%s\n", opt); */
Preprocessor_define(opt, 0);
}
}
}
}
}
//-----------------------------------------------------------------
// main()
//
// Main program. Initializes the files and starts the parser.
//-----------------------------------------------------------------
char *SwigLib;
static int freeze = 0;
static String *lang_config = 0;
static char *cpp_extension = (char *) "cxx";
/* This function sets the name of the configuration file */
void SWIG_config_file(const String_or_char *filename) {
lang_config = NewString(filename);
}
void SWIG_library_directory(const char *filename) {
strcpy(LibDir,filename);
}
void SWIG_config_cppext(const char *ext) {
cpp_extension = (char *) ext;
}
extern "C" Node *Swig_cparse(File *);
extern "C" void Swig_cparse_cplusplus(int);
extern "C" void Swig_cparse_debug_templates(int);
int SWIG_main(int argc, char *argv[], Language *l) {
int i;
char *c;
char temp[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 *);
int dump_tags = 0;
int dump_tree = 0;
int contracts = 0;
int browse = 0;
int dump_typedef = 0;
int dump_classes = 0;
int werror = 0;
int depend = 0;
DOH *libfiles = 0;
DOH *cpps = 0 ;
extern void Swig_contracts(Node *n);
extern void Swig_browser(Node *n, int);
extern void Swig_default_allocators(Node *n);
extern void Swig_process_types(Node *n);
/* Initialize the SWIG core */
Swig_init();
/* Suppress warning messages for private inheritance, preprocessor evaluation,
might be abstract, and overloaded const */
Swig_warnfilter("202,309,403,512",1);
// Initialize the preprocessor
Preprocessor_init();
lang = l;
// 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
// Set the SWIG version value
String *vers;
vers = NewStringf("SWIG_VERSION 0x%02d%02d%02d", SWIG_MAJOR_VERSION, SWIG_MINOR_VERSION, SWIG_SPIN);
Preprocessor_define(vers,0);
// Check for SWIG_LIB environment variable
if ((c = getenv("SWIG_LIB")) == (char *) 0) {
#if defined(_WIN32)
char buf[MAX_PATH];
char *p;
if (GetModuleFileName(0, buf, MAX_PATH) == 0
|| (p = strrchr(buf, '\\')) == 0) {
Printf(stderr, "Warning: Could not determine SWIG library location. Assuming " SWIG_LIB "\n");
sprintf(LibDir,"%s",SWIG_LIB); // Build up search paths
} else {
strcpy(p+1, "Lib");
strcpy(LibDir, buf);
}
#else
sprintf(LibDir,"%s",SWIG_LIB); // Build up search paths
#endif
} else {
strcpy(LibDir,c);
}
SwigLib = Swig_copy_string(LibDir); // Make a copy of the real library location
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;
Preprocessor_define((DOH *) "__cplusplus 1", 0);
Swig_cparse_cplusplus(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) || (strcmp(argv[i],"-makedefault") == 0)) {
GenerateDefault = 1;
Swig_mark_arg(i);
} else if ((strcmp(argv[i],"-no_default") == 0) || (strcmp(argv[i],"-nodefault") == 0)) {
GenerateDefault = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-noexcept") == 0) {
NoExcept = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-noextern") == 0) {
NoExtern = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-show_templates") == 0) {
Swig_cparse_debug_templates(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\n",
SWIG_VERSION);
fprintf(stderr,"Copyright (c) 1995-1998\n");
fprintf(stderr,"University of Utah and the Regents of the University of California\n");
fprintf(stderr,"Copyright (c) 1998-2002\n");
fprintf(stderr,"University of Chicago\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],"-importall") == 0) {
Preprocessor_import_all(1);
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-ignoremissing") == 0) {
Preprocessor_ignore_missing(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],"-module") == 0) {
Swig_mark_arg(i);
if (argv[i+1]) {
ModuleName = NewString(argv[i+1]);
Swig_mark_arg(i+1);
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i],"-M") == 0) {
depend = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-MM") == 0) {
depend = 2;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-Wall") == 0) {
Swig_mark_arg(i);
Swig_warnall();
} else if (strcmp(argv[i],"-Werror") == 0) {
werror = 1;
Swig_mark_arg(i);
} else if (strncmp(argv[i],"-w",2) == 0) {
Swig_mark_arg(i);
Swig_warnfilter(argv[i]+2,1);
} else if (strcmp(argv[i],"-dump_tags") == 0) {
dump_tags = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-dump_tree") == 0) {
dump_tree = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-contracts") == 0) {
Swig_mark_arg(i);
contracts = 1;
} else if (strcmp(argv[i],"-browse") == 0) {
browse = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-dump_typedef") == 0) {
dump_typedef = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-dump_classes") == 0) {
dump_classes = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
Swig_mark_arg(i);
help = 1;
}
}
}
for (i = 0; i < includecount; i++) {
Swig_add_directory((DOH *) includefiles[i]);
}
// Define the __cplusplus symbol
if (CPlusPlus)
Preprocessor_define((DOH *) "__cplusplus 1", 0);
// Parse language dependent options
lang->main(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();
install_opts(argc, argv);
// Add language dependent directory to the search path
{
DOH *rl = NewString("");
Printf(rl,"%s%s%s", SwigLib, SWIG_FILE_DELIMETER, LibDir);
Swig_add_directory(rl);
rl = NewString("");
Printf(rl,".%sswig_lib%s%s", SWIG_FILE_DELIMETER, SWIG_FILE_DELIMETER, LibDir);
Swig_add_directory(rl);
}
sprintf(temp,"%s%sconfig", SwigLib, SWIG_FILE_DELIMETER);
Swig_add_directory((DOH *) temp);
Swig_add_directory((DOH *) "." SWIG_FILE_DELIMETER "swig_lib" SWIG_FILE_DELIMETER "config");
Swig_add_directory((DOH *) SwigLib);
Swig_add_directory((DOH *) "." SWIG_FILE_DELIMETER "swig_lib");
if (Verbose) {
printf ("LibDir: %s\n", LibDir);
List *sp = Swig_search_path();
String *s;
for (s = Firstitem(sp); s; s = Nextitem(sp)) {
Printf(stdout," %s\n", s);
}
}
// If we made it this far, looks good. go for it....
input_file = argv[argc-1];
// 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(input_file);
// Run the preprocessor
if (Verbose)
printf ("Preprocessing...\n");
{
int i;
String *fs = NewString("");
FILE *df = Swig_open(input_file);
if (!df) {
Printf(stderr,"Unable to find '%s'\n", input_file);
SWIG_exit (EXIT_FAILURE);
}
fclose(df);
Printf(fs,"%%include \"swig.swg\"\n");
if (lang_config) {
Printf(fs,"\n%%include \"%s\"\n", lang_config);
}
Printf(fs,"%%include \"%s\"\n", Swig_last_file());
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 (Swig_error_count()) {
SWIG_exit(EXIT_FAILURE);
}
if (cpp_only) {
Printf(stdout,"%s", cpps);
while (freeze);
SWIG_exit (EXIT_SUCCESS);
}
if (depend) {
String *outfile;
if (!outfile_name) {
if (CPlusPlus) {
outfile = NewStringf("%s_wrap.%s", Swig_file_basename(input_file),cpp_extension);
} else {
outfile = NewStringf("%s_wrap.c", Swig_file_basename(input_file));
}
} else {
outfile = NewString(outfile_name);
}
Printf(stdout,"%s: ", outfile);
List *files = Preprocessor_depend();
for (int i = 0; i < Len(files); i++) {
if ((depend != 2) || ((depend == 2) && (Strncmp(Getitem(files,i),SwigLib, Len(SwigLib)) != 0))) {
Printf(stdout,"\\\n %s ", Getitem(files,i));
}
}
Printf(stdout,"\n");
SWIG_exit(EXIT_SUCCESS);
}
Seek(cpps, 0, SEEK_SET);
}
/* Register a null file with the file handler */
Swig_register_filebyname("null", NewString(""));
// Pass control over to the specific language interpreter
if (Verbose) {
fprintf (stdout, "Starting language-specific parse...\n");
fflush (stdout);
}
Node *top = Swig_cparse(cpps);
if (Verbose) {
Printf(stdout,"Processing types...\n");
}
Swig_process_types(top);
if (Verbose) {
Printf(stdout,"C++ analysis...\n");
}
Swig_default_allocators(top);
if (Verbose) {
Printf(stdout,"Generating wrappers...\n");
}
if (dump_classes) {
Hash *classes = Getattr(top,"classes");
if (classes) {
Printf(stdout,"Classes\n");
Printf(stdout,"------------\n");
String *key;
for (key = Firstkey(classes); key; key = Nextkey(classes)) {
Printf(stdout,"%s\n", key);
}
}
}
if (dump_typedef) {
SwigType_print_scope(0);
}
if (dump_tags) {
Swig_print_tags(top,0);
}
if (dump_tree) {
Swig_print_tree(top);
}
if (top) {
if (!Getattr(top,"name")) {
Printf(stderr,"*** No module name specified using %%module or -module.\n");
SWIG_exit(EXIT_FAILURE);
} else {
/* Set some filename information on the object */
Setattr(top,"infile", input_file);
if (!outfile_name) {
if (CPlusPlus) {
Setattr(top,"outfile", NewStringf("%s_wrap.%s", Swig_file_basename(input_file),cpp_extension));
} else {
Setattr(top,"outfile", NewStringf("%s_wrap.c", Swig_file_basename(input_file)));
}
} else {
Setattr(top,"outfile", outfile_name);
}
if (contracts) {
Swig_contracts(top);
}
lang->top(top);
if (browse) {
Swig_browser(top,0);
}
}
}
}
if (tm_debug) Swig_typemap_debug();
while (freeze);
if ((werror) && (Swig_warn_count())) {
return Swig_warn_count();
}
return Swig_error_count();
}
// --------------------------------------------------------------------------
// SWIG_exit(int exit_code)
//
// Cleanup and either freeze or exit
// --------------------------------------------------------------------------
void SWIG_exit(int exit_code) {
while (freeze);
exit (exit_code);
}

57
Source/Modules/module.cxx Normal file
View file

@ -0,0 +1,57 @@
/* -----------------------------------------------------------------------------
* module.cxx
*
* This file is responsible for the module system.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1999-2000. The University of Chicago
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
char cvsroot_module_cxx[] = "$Header$";
#include "swigmod.h"
struct Module {
ModuleFactory fac;
char *name;
Module *next;
Module(const char *n, ModuleFactory f) {
fac = f;
name = new char[strlen(n)+1];
strcpy(name, n);
next = 0;
}
};
static Module *modules = 0;
/* -----------------------------------------------------------------------------
* void Swig_register_module()
*
* Register a module.
* ----------------------------------------------------------------------------- */
void Swig_register_module(const char *n, ModuleFactory f) {
Module *m = new Module(n,f);
m->next = modules;
modules = m;
}
/* -----------------------------------------------------------------------------
* Language *Swig_find_module()
*
* Given a command line option, locates the factory function.
* ----------------------------------------------------------------------------- */
ModuleFactory Swig_find_module(const char *name) {
Module *m = modules;
while (m) {
if (strcmp(m->name,name) == 0) {
return m->fac;
}
m = m->next;
}
return 0;
}

668
Source/Modules/mzscheme.cxx Normal file
View file

@ -0,0 +1,668 @@
/******************************************************************************
* 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.
*****************************************************************************/
char cvsroot_mzscheme_cxx[] = "$Header$";
/***********************************************************************
* $Header$
*
* mzscheme.cxx
*
* Definitions for adding functions to Mzscheme 101
***********************************************************************/
#include "swigmod.h"
#include <ctype.h>
static const char *mzscheme_usage = (char*)"\
\n\
Mzscheme Options (available with -mzscheme)\n\
-help - Print this help\n\
-prefix name - Set a prefix to be appended to all names\n\
-declaremodule - Create extension that declares a module\n\
\n"
;
static char *prefix=0;
static bool declaremodule = false;
static String *module=0;
static char *mzscheme_path=(char*)"mzscheme";
static String *init_func_def = 0;
static File *f_runtime = 0;
static File *f_header = 0;
static File *f_wrappers = 0;
static File *f_init = 0;
class MZSCHEME : public Language {
public:
/* ------------------------------------------------------------
* main()
* ------------------------------------------------------------ */
virtual void main (int argc, char *argv[]) {
int i;
SWIG_library_directory(mzscheme_path);
// Look for certain command line options
for (i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp (argv[i], "-help") == 0) {
fputs (mzscheme_usage, stderr);
SWIG_exit (0);
}
else if (strcmp (argv[i], "-prefix") == 0) {
if (argv[i + 1]) {
prefix = new char[strlen(argv[i + 1]) + 2];
strcpy(prefix, argv[i + 1]);
Swig_mark_arg (i);
Swig_mark_arg (i + 1);
i++;
} else {
Swig_arg_error();
}
}
else if (strcmp (argv[i], "-declaremodule") == 0) {
declaremodule = true;
Swig_mark_arg (i);
}
}
}
// If a prefix has been specified make sure it ends in a '_'
if (prefix) {
if (prefix[strlen (prefix)] != '_') {
prefix[strlen (prefix) + 1] = 0;
prefix[strlen (prefix)] = '_';
}
} else
prefix = (char*)"swig_";
// Add a symbol for this module
Preprocessor_define ("SWIGMZSCHEME 1",0);
// Set name of typemaps
SWIG_typemap_lang("mzscheme");
// Read in default typemaps */
SWIG_config_file("mzscheme.i");
allow_overloading();
}
/* ------------------------------------------------------------
* top()
* ------------------------------------------------------------ */
virtual int top(Node *n) {
/* Initialize all of the output files */
String *outfile = Getattr(n,"outfile");
f_runtime = NewFile(outfile,"w");
if (!f_runtime) {
Printf(stderr,"*** Can't open '%s'\n", outfile);
SWIG_exit(EXIT_FAILURE);
}
f_init = NewString("");
f_header = NewString("");
f_wrappers = NewString("");
/* Register file targets with the SWIG file handler */
Swig_register_filebyname("header",f_header);
Swig_register_filebyname("wrapper",f_wrappers);
Swig_register_filebyname("runtime",f_runtime);
init_func_def = NewString("");
Swig_register_filebyname("init",init_func_def);
Printf(f_runtime, "/* -*- buffer-read-only: t -*- vi: set ro: */\n");
Swig_banner (f_runtime);
if (NoInclude) {
Printf(f_runtime, "#define SWIG_NOINCLUDE\n");
}
module = Getattr(n,"name");
Language::top(n);
SwigType_emit_type_table (f_runtime, f_wrappers);
Printf(f_init, "Scheme_Object *scheme_reload(Scheme_Env *env) {\n");
Printf(f_init, "\tScheme_Env *menv = env;\n");
if (declaremodule) {
Printf(f_init, "\tmenv = scheme_primitive_module(scheme_intern_symbol(\"%s\"), env);\n", module);
}
Printf (f_init, "\tSWIG_RegisterTypes(swig_types, swig_types_initial);\n");
Printf(f_init, "%s\n", Char(init_func_def));
if (declaremodule) {
Printf(f_init, "\tscheme_finish_primitive_module(menv);\n");
}
Printf (f_init, "\treturn scheme_void;\n}\n");
Printf(f_init, "Scheme_Object *scheme_initialize(Scheme_Env *env) {\n");
Printf(f_init, "\treturn scheme_reload(env);\n");
Printf (f_init, "}\n");
Printf(f_init,"Scheme_Object *scheme_module_name(void) {\n");
if (declaremodule) {
Printf(f_init, " return scheme_intern_symbol((char*)\"%s\");\n", module);
}
else {
Printf(f_init," return scheme_make_symbol((char*)\"%s\");\n", module);
}
Printf(f_init,"}\n");
/* Close all of the files */
Dump(f_header,f_runtime);
Dump(f_wrappers,f_runtime);
Wrapper_pretty_print(f_init,f_runtime);
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_runtime);
Delete(f_runtime);
return SWIG_OK;
}
/* ------------------------------------------------------------
* functionWrapper()
* Create a function declaration and register it with the interpreter.
* ------------------------------------------------------------ */
void throw_unhandled_mzscheme_type_error (SwigType *d)
{
Swig_warning(WARN_TYPEMAP_UNDEF, input_file, line_number,
"Unable to handle type %s.\n", SwigType_str(d,0));
}
/* Return true iff T is a pointer type */
int
is_a_pointer (SwigType *t)
{
return SwigType_ispointer(SwigType_typedef_resolve_all(t));
}
virtual int functionWrapper(Node *n) {
char *iname = GetChar(n,"sym:name");
SwigType *d = Getattr(n,"type");
ParmList *l = Getattr(n,"parms");
Parm *p;
Wrapper *f = NewWrapper();
String *proc_name = NewString("");
String *source = NewString("");
String *target = NewString("");
String *arg = NewString("");
String *cleanup = NewString("");
String *outarg = NewString("");
String *build = NewString("");
String *tm;
int argout_set = 0;
int i = 0;
int numargs;
int numreq;
String *overname = 0;
// Make a wrapper name for this
String *wname = Swig_name_wrapper(iname);
if (Getattr(n,"sym:overloaded")) {
overname = Getattr(n,"sym:overname");
} else {
if (!addSymbol(iname,n)) return SWIG_ERROR;
}
if (overname) {
Append(wname, overname);
}
Setattr(n,"wrap:name",wname);
// Build the name for Scheme.
Printv(proc_name, iname,NIL);
Replaceall(proc_name, "_", "-");
// writing the function wrapper function
Printv(f->def, "static Scheme_Object *", wname, " (", NIL);
Printv(f->def, "int argc, Scheme_Object **argv", NIL);
Printv(f->def, ")\n{", NIL);
/* Define the scheme name in C. This define is used by several
macros. */
Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL);
// Declare return variable and arguments
// number of parameters
// they are called arg0, arg1, ...
// the return value is called result
emit_args(d, l, f);
/* Attach the standard typemaps */
emit_attach_parmmaps(l,f);
Setattr(n,"wrap:parms",l);
numargs = emit_num_arguments(l);
numreq = emit_num_required(l);
// adds local variables
Wrapper_add_local(f, "_len", "int _len");
Wrapper_add_local(f, "lenv", "int lenv = 1");
Wrapper_add_local(f, "values", "Scheme_Object *values[MAXVALUES]");
// Now write code to extract the parameters (this is super ugly)
for (i = 0, p = l; i < numargs; i++) {
/* Skip ignored arguments */
while (checkAttribute(p,"tmap:in:numinputs","0")) {
p = Getattr(p,"tmap:in:next");
}
SwigType *pt = Getattr(p,"type");
String *ln = Getattr(p,"lname");
// Produce names of source and target
Clear(source);
Clear(target);
Clear(arg);
Printf(source, "argv[%d]", i);
Printf(target, "%s",ln);
Printv(arg, Getattr(p,"name"),NIL);
if (i >= numreq) {
Printf(f->code,"if (argc > %d) {\n",i);
}
// Handle parameter types.
if ((tm = Getattr(p,"tmap:in"))) {
Replaceall(tm,"$source",source);
Replaceall(tm,"$target",target);
Replaceall(tm,"$input",source);
Setattr(p,"emit:input",source);
Printv(f->code, tm, "\n", NIL);
p = Getattr(p,"tmap:in:next");
} else {
// no typemap found
// check if typedef and resolve
throw_unhandled_mzscheme_type_error (pt);
p = nextSibling(p);
}
if (i >= numreq) {
Printf(f->code,"}\n");
}
}
/* Insert constraint checking code */
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:check"))) {
Replaceall(tm,"$target",Getattr(p,"lname"));
Printv(f->code,tm,"\n",NIL);
p = Getattr(p,"tmap:check:next");
} else {
p = nextSibling(p);
}
}
// Pass output arguments back to the caller.
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:argout"))) {
Replaceall(tm,"$source",Getattr(p,"emit:input")); /* Deprecated */
Replaceall(tm,"$target",Getattr(p,"lname")); /* Deprecated */
Replaceall(tm,"$arg",Getattr(p,"emit:input"));
Replaceall(tm,"$input",Getattr(p,"emit:input"));
Printv(outarg,tm,"\n",NIL);
p = Getattr(p,"tmap:argout:next");
argout_set = 1;
} else {
p = nextSibling(p);
}
}
// Free up any memory allocated for the arguments.
/* Insert cleanup code */
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:freearg"))) {
Replaceall(tm,"$target",Getattr(p,"lname"));
Printv(cleanup,tm,"\n",NIL);
p = Getattr(p,"tmap:freearg:next");
} else {
p = nextSibling(p);
}
}
// Now write code to make the function call
emit_action(n,f);
// Now have return value, figure out what to do with it.
if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) {
Replaceall(tm,"$source","result");
Replaceall(tm,"$target","values[0]");
Replaceall(tm,"$result","values[0]");
Printv(f->code, tm, "\n",NIL);
} else {
throw_unhandled_mzscheme_type_error (d);
}
// Dump the argument output code
Printv(f->code, Char(outarg),NIL);
// Dump the argument cleanup code
Printv(f->code, Char(cleanup),NIL);
// Look for any remaining cleanup
if (Getattr(n,"feature:new")) {
if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) {
Replaceall(tm,"$source","result");
Printv(f->code, tm, "\n",NIL);
}
}
// Free any memory allocated by the function being wrapped..
if ((tm = Swig_typemap_lookup_new("ret",n,"result",0))) {
Replaceall(tm,"$source","result");
Printv(f->code, tm, "\n",NIL);
}
// Wrap things up (in a manner of speaking)
Printv(f->code, tab4, "return swig_package_values(lenv, values);\n", NIL);
Printf(f->code, "#undef FUNC_NAME\n");
Printv(f->code, "}\n",NIL);
Wrapper_print(f, f_wrappers);
if (!Getattr(n,"sym:overloaded")) {
// Now register the function
char temp[256];
sprintf(temp, "%d", numargs);
Printf(init_func_def, "scheme_add_global(\"%s\", scheme_make_prim_w_arity(%s,\"%s\",%d,%d),menv);\n",
proc_name, wname, proc_name, numreq, numargs);
} else {
if (!Getattr(n,"sym:nextSibling")) {
/* Emit overloading dispatch function */
int maxargs;
String *dispatch = Swig_overload_dispatch(n,"return %s(argc,argv);",&maxargs);
/* Generate a dispatch wrapper for all overloaded functions */
Wrapper *df = NewWrapper();
String *dname = Swig_name_wrapper(iname);
Printv(df->def,
"static Scheme_Object *\n", dname,
"(int argc, Scheme_Object **argv) {",
NIL);
Printv(df->code,dispatch,"\n",NIL);
Printf(df->code,"scheme_signal_error(\"No matching function for overloaded '%s'\");\n", iname);
Printv(df->code,"}\n",NIL);
Wrapper_print(df,f_wrappers);
Printf(init_func_def, "scheme_add_global(\"%s\", scheme_make_prim_w_arity(%s,\"%s\",%d,%d),menv);\n",
proc_name, dname, proc_name, 0, maxargs);
DelWrapper(df);
Delete(dispatch);
Delete(dname);
}
}
Delete(proc_name);
Delete(source);
Delete(target);
Delete(arg);
Delete(outarg);
Delete(cleanup);
Delete(build);
DelWrapper(f);
return SWIG_OK;
}
/* ------------------------------------------------------------
* variableWrapper()
*
* Create a link to a C variable.
* This creates a single function _wrap_swig_var_varname().
* This function takes a single optional argument. If supplied, it means
* we are setting this variable to some value. If omitted, it means we are
* simply evaluating this variable. Either way, we return the variables
* value.
* ------------------------------------------------------------ */
virtual int variableWrapper(Node *n) {
char *name = GetChar(n,"name");
char *iname = GetChar(n,"sym:name");
SwigType *t = Getattr(n,"type");
String *proc_name = NewString("");
char var_name[256];
String *tm;
String *tm2 = NewString("");;
String *argnum = NewString("0");
String *arg = NewString("argv[0]");
Wrapper *f;
if (!addSymbol(iname,n)) return SWIG_ERROR;
f = NewWrapper();
// evaluation function names
strcpy(var_name, Char(Swig_name_wrapper(iname)));
// Build the name for scheme.
Printv(proc_name, iname,NIL);
Replaceall(proc_name, "_", "-");
if ((SwigType_type(t) != T_USER) || (is_a_pointer(t))) {
Printf (f->def, "static Scheme_Object *%s(int argc, Scheme_Object** argv) {\n", var_name);
Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL);
Wrapper_add_local (f, "swig_result", "Scheme_Object *swig_result");
if (!Getattr(n,"feature:immutable")) {
/* Check for a setting of the variable value */
Printf (f->code, "if (argc) {\n");
if ((tm = Swig_typemap_lookup_new("varin",n,name,0))) {
Replaceall(tm,"$source","argv[0]");
Replaceall(tm,"$target",name);
Replaceall(tm,"$input","argv[0]");
Printv(f->code, tm, "\n",NIL);
}
else {
throw_unhandled_mzscheme_type_error (t);
}
Printf (f->code, "}\n");
}
// Now return the value of the variable (regardless
// of evaluating or setting)
if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) {
Replaceall(tm,"$source",name);
Replaceall(tm,"$target","swig_result");
Replaceall(tm,"$result","swig_result");
Printf (f->code, "%s\n", tm);
}
else {
throw_unhandled_mzscheme_type_error (t);
}
Printf (f->code, "\nreturn swig_result;\n");
Printf (f->code, "#undef FUNC_NAME\n");
Printf (f->code, "}\n");
Wrapper_print (f, f_wrappers);
// Now add symbol to the MzScheme interpreter
Printv(init_func_def,
"scheme_add_global(\"",
proc_name,
"\", scheme_make_prim_w_arity(",
var_name,
", \"",
proc_name,
"\", ",
"0",
", ",
"1",
"), menv);\n",NIL);
} else {
Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number,
"Unsupported variable type %s (ignored).\n", SwigType_str(t,0));
}
Delete(proc_name);
Delete(argnum);
Delete(arg);
Delete(tm2);
DelWrapper(f);
return SWIG_OK;
}
/* ------------------------------------------------------------
* constantWrapper()
* ------------------------------------------------------------ */
virtual int constantWrapper(Node *n) {
char *name = GetChar(n,"name");
char *iname = GetChar(n,"sym:name");
SwigType *type = Getattr(n,"type");
String *value = Getattr(n,"value");
String *var_name = NewString("");
String *proc_name = NewString("");
String *rvalue = NewString("");
String *temp = NewString("");
String *tm;
// Make a static variable;
Printf (var_name, "_wrap_const_%s", Swig_name_mangle(iname));
// Build the name for scheme.
Printv(proc_name, iname,NIL);
Replaceall(proc_name, "_", "-");
if ((SwigType_type(type) == T_USER) && (!is_a_pointer(type))) {
Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number,
"Unsupported constant value.\n");
return SWIG_NOWRAP;
}
// See if there's a typemap
Printv(rvalue, value,NIL);
if ((SwigType_type(type) == T_CHAR) && (is_a_pointer(type) == 1)) {
temp = Copy(rvalue);
Clear(rvalue);
Printv(rvalue, "\"", temp, "\"",NIL);
}
if ((SwigType_type(type) == T_CHAR) && (is_a_pointer(type) == 0)) {
Delete(temp);
temp = Copy(rvalue);
Clear(rvalue);
Printv(rvalue, "'", temp, "'",NIL);
}
if ((tm = Swig_typemap_lookup_new("constant",n,name,0))) {
Replaceall(tm,"$source",rvalue);
Replaceall(tm,"$value",rvalue);
Replaceall(tm,"$target",name);
Printf (f_init, "%s\n", tm);
} else {
// Create variable and assign it a value
Printf (f_header, "static %s = ", SwigType_lstr(type,var_name));
if ((SwigType_type(type) == T_STRING)) {
Printf (f_header, "\"%s\";\n", value);
} else if (SwigType_type(type) == T_CHAR) {
Printf (f_header, "\'%s\';\n", value);
} else {
Printf (f_header, "%s;\n", value);
}
// Now create a variable declaration
{
/* Hack alert: will cleanup later -- Dave */
Node *n = NewHash();
Setattr(n,"name",var_name);
Setattr(n,"sym:name",iname);
Setattr(n,"type", type);
variableWrapper(n);
Delete(n);
}
}
Delete(proc_name);
Delete(rvalue);
Delete(temp);
return SWIG_OK;
}
/* ------------------------------------------------------------
* validIdentifer()
* ------------------------------------------------------------ */
virtual int validIdentifier(String *s) {
char *c = Char(s);
/* Check whether we have an R5RS identifier.*/
/* <identifier> --> <initial> <subsequent>* | <peculiar identifier> */
/* <initial> --> <letter> | <special initial> */
if (!(isalpha(*c) || (*c == '!') || (*c == '$') || (*c == '%')
|| (*c == '&') || (*c == '*') || (*c == '/') || (*c == ':')
|| (*c == '<') || (*c == '=') || (*c == '>') || (*c == '?')
|| (*c == '^') || (*c == '_') || (*c == '~'))) {
/* <peculiar identifier> --> + | - | ... */
if ((strcmp(c, "+") == 0)
|| strcmp(c, "-") == 0
|| strcmp(c, "...") == 0) return 1;
else return 0;
}
/* <subsequent> --> <initial> | <digit> | <special subsequent> */
while (*c) {
if (!(isalnum(*c) || (*c == '!') || (*c == '$') || (*c == '%')
|| (*c == '&') || (*c == '*') || (*c == '/') || (*c == ':')
|| (*c == '<') || (*c == '=') || (*c == '>') || (*c == '?')
|| (*c == '^') || (*c == '_') || (*c == '~') || (*c == '+')
|| (*c == '-') || (*c == '.') || (*c == '@'))) return 0;
c++;
}
return 1;
}
};
/* -----------------------------------------------------------------------------
* swig_mzscheme() - Instantiate module
* ----------------------------------------------------------------------------- */
extern "C" Language *
swig_mzscheme(void) {
return new MZSCHEME();
}

1072
Source/Modules/ocaml.cxx Executable file

File diff suppressed because it is too large Load diff

338
Source/Modules/overload.cxx Normal file
View file

@ -0,0 +1,338 @@
/* -----------------------------------------------------------------------------
* overload.cxx
*
* This file is used to analyze overloaded functions and methods.
* It looks at signatures and tries to gather information for
* building a dispatch function.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1999-2000. The University of Chicago
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
char cvsroot_overload_cxx[] = "$Header$";
#include "swigmod.h"
#define MAX_OVERLOAD 256
extern int emit_num_required(ParmList *);
/* -----------------------------------------------------------------------------
* Swig_overload_rank()
*
* This function takes an overloaded declaration and creates a list that ranks
* all overloaded methods in an order that can be used to generate a dispatch
* function.
* ----------------------------------------------------------------------------- */
struct Overloaded {
Node *n; /* Node */
int argc; /* Argument count */
ParmList *parms; /* Parameters used for overload check */
int error; /* Ambiguity error */
};
List *
Swig_overload_rank(Node *n) {
Overloaded nodes[MAX_OVERLOAD];
int nnodes = 0;
Node *o = Getattr(n,"sym:overloaded");
Node *c;
if (!o) return 0;
c = o;
while (c) {
if (!Getattr(c,"error")) {
if (Getattr(c,"wrap:name")) {
nodes[nnodes].n = c;
nodes[nnodes].parms = Getattr(c,"wrap:parms");
nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms);
nodes[nnodes].error = 0;
nnodes++;
}
}
c = Getattr(c,"sym:nextSibling");
}
/* Sort the declarations by required argument count */
{
int i,j;
for (i = 0; i < nnodes; i++) {
for (j = i+1; j < nnodes; j++) {
if (nodes[i].argc > nodes[j].argc) {
Overloaded t = nodes[i];
nodes[i] = nodes[j];
nodes[j] = t;
}
}
}
}
/* Sort the declarations by argument types */
{
int i,j;
for (i = 0; i < nnodes-1; i++) {
if (nodes[i].argc == nodes[i+1].argc) {
for (j = i+1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) {
Parm *p1 = nodes[i].parms;
Parm *p2 = nodes[j].parms;
int differ = 0;
int num_checked = 0;
while (p1 && p2 && (num_checked < nodes[i].argc)) {
// Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type"));
if (checkAttribute(p1,"tmap:in:numinputs","0")) {
p1 = Getattr(p1,"tmap:in:next");
continue;
}
if (checkAttribute(p2,"tmap:in:numinputs","0")) {
p2 = Getattr(p2,"tmap:in:next");
continue;
}
String *t1 = Getattr(p1,"tmap:typecheck:precedence");
String *t2 = Getattr(p2,"tmap:typecheck:precedence");
if ((!t1) && (!nodes[i].error)) {
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n),
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
Getattr(nodes[i].n,"name"),ParmList_str(Getattr(nodes[i].n,"parms")),
SwigType_str(Getattr(p1,"type"),0));
nodes[i].error = 1;
} else if ((!t2) && (!nodes[j].error)) {
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
Getattr(nodes[j].n,"name"),ParmList_str(Getattr(nodes[j].n,"parms")),
SwigType_str(Getattr(p2,"type"),0));
nodes[j].error = 1;
}
if (t1 && t2) {
int t1v, t2v;
t1v = atoi(Char(t1));
t2v = atoi(Char(t2));
differ = t1v-t2v;
}
else if (!t1 && t2) differ = 1;
else if (t2 && !t1) differ = -1;
else if (!t1 && !t2) differ = -1;
num_checked++;
if (differ > 0) {
Overloaded t = nodes[i];
nodes[i] = nodes[j];
nodes[j] = t;
break;
} else if ((differ == 0) && (Strcmp(t1,"0") == 0)) {
t1 = Getattr(p1,"ltype");
if (!t1) {
t1 = SwigType_ltype(Getattr(p1,"type"));
if (Getattr(p1,"tmap:typecheck:SWIGTYPE")) {
SwigType_add_pointer(t1);
}
Setattr(p1,"ltype",t1);
}
t2 = Getattr(p2,"ltype");
if (!t2) {
t2 = SwigType_ltype(Getattr(p2,"type"));
if (Getattr(p2,"tmap:typecheck:SWIGTYPE")) {
SwigType_add_pointer(t2);
}
Setattr(p2,"ltype",t2);
}
/* Need subtype check here. If t2 is a subtype of t1, then we need to change the
order */
if (SwigType_issubtype(t2,t1)) {
Overloaded t = nodes[i];
nodes[i] = nodes[j];
nodes[j] = t;
}
if (Strcmp(t1,t2) != 0) {
differ = 1;
break;
}
} else if (differ) {
break;
}
if (Getattr(p1,"tmap:in:next")) {
p1 = Getattr(p1,"tmap:in:next");
} else {
p1 = nextSibling(p1);
}
if (Getattr(p2,"tmap:in:next")) {
p2 = Getattr(p2,"tmap:in:next");
} else {
p2 = nextSibling(p2);
}
}
if (!differ) {
/* See if declarations differ by const only */
String *d1 = Getattr(nodes[i].n,"decl");
String *d2 = Getattr(nodes[j].n,"decl");
if (d1 && d2) {
String *dq1 = Copy(d1);
String *dq2 = Copy(d2);
if (SwigType_isconst(d1)) {
SwigType_pop(dq1);
}
if (SwigType_isconst(d2)) {
SwigType_pop(dq2);
}
if (Strcmp(dq1,dq2) == 0) {
if (SwigType_isconst(d1) && !SwigType_isconst(d2)) {
Overloaded t = nodes[i];
nodes[i] = nodes[j];
nodes[j] = t;
differ = 1;
if (!nodes[j].error) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
Getfile(nodes[i].n), Getline(nodes[i].n));
}
nodes[j].error = 1;
} else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) {
differ = 1;
if (!nodes[j].error) {
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
Getfile(nodes[i].n), Getline(nodes[i].n));
}
nodes[j].error = 1;
}
}
Delete(dq1);
Delete(dq2);
}
}
if (!differ) {
if (!nodes[j].error) {
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
"Overloaded %s(%s) is shadowed by %s(%s) at %s:%d.\n",
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms),
Getfile(nodes[i].n),Getline(nodes[i].n));
nodes[j].error = 1;
}
}
}
}
}
}
List *result = NewList();
{
int i;
for (i = 0; i < nnodes; i++) {
Append(result,nodes[i].n);
// Printf(stdout,"[ %d ] %s\n", i, ParmList_protostr(nodes[i].parms));
// Swig_print_node(nodes[i].n);
}
}
return result;
}
/* -----------------------------------------------------------------------------
* Swig_overload_dispatch()
*
* Generate a dispatch function. argc is assumed to hold the argument count.
* argv is the argument vector.
*
* Note that for C++ class member functions, Swig_overload_dispatch() assumes
* that argc includes the "self" argument and that the first element of argv[]
* is the "self" argument. So for a member function:
*
* Foo::bar(int x, int y, int z);
*
* the argc should be 4 (not 3!) and the first element of argv[] would be
* the appropriate scripting language reference to "self". For regular
* functions (and static class functions) the argc and argv only include
* the regular function arguments.
* ----------------------------------------------------------------------------- */
static bool print_typecheck(String *f, int j, Parm *pj)
{
char tmp[256];
sprintf(tmp,"argv[%d]",j);
String *tm = Getattr(pj,"tmap:typecheck");
if (tm) {
Replaceid(tm,Getattr(pj,"lname"),"_v");
Replaceall(tm,"$input", tmp);
Printv(f,tm,"\n",NIL);
return true;
}
else
return false;
}
String *
Swig_overload_dispatch(Node *n, const String_or_char *fmt, int *maxargs) {
int i,j;
*maxargs = 1;
String *f = NewString("");
/* Get a list of methods ranked by precedence values and argument count */
List *dispatch = Swig_overload_rank(n);
int nfunc = Len(dispatch);
/* Loop over the functions */
for (i = 0; i < nfunc; i++) {
Node *ni = Getitem(dispatch,i);
Parm *pi = Getattr(ni,"wrap:parms");
int num_required = emit_num_required(pi);
int num_arguments = emit_num_arguments(pi);
if (num_arguments > *maxargs) *maxargs = num_arguments;
int varargs = emit_isvarargs(pi);
if (!varargs) {
if (num_required == num_arguments) {
Printf(f,"if (argc == %d) {\n", num_required);
} else {
Printf(f,"if ((argc >= %d) && (argc <= %d)) {\n", num_required, num_arguments);
}
} else {
Printf(f,"if (argc >= %d) {\n", num_required);
}
if (num_arguments) {
Printf(f,"int _v;\n");
}
int num_braces = 0;
j = 0;
Parm *pj = pi;
while (pj) {
if (checkAttribute(pj,"tmap:in:numinputs","0")) {
pj = Getattr(pj,"tmap:in:next");
continue;
}
if (j >= num_required) {
Printf(f, "if (argc <= %d) {\n", j);
Printf(f, Char(fmt),Getattr(ni,"wrap:name"));
Printf(f, "}\n");
}
if (print_typecheck(f, j, pj)) {
Printf(f, "if (_v) {\n");
num_braces++;
}
Parm *pk = Getattr(pj,"tmap:in:next");
if (pk) pj = pk;
else pj = nextSibling(pj);
j++;
}
Printf(f, Char(fmt),Getattr(ni,"wrap:name"));
/* close braces */
for (/* empty */; num_braces > 0; num_braces--)
Printf(f, "}\n");
Printf(f,"}\n"); /* braces closes "if" for this method */
}
Delete(dispatch);
return f;
}

1594
Source/Modules/perl5.cxx Normal file

File diff suppressed because it is too large Load diff

2113
Source/Modules/php4.cxx Normal file

File diff suppressed because it is too large Load diff

881
Source/Modules/pike.cxx Normal file
View file

@ -0,0 +1,881 @@
/***********************************************************************
* Pike language module for SWIG
***********************************************************************/
char cvsroot_pike_cxx[] = "$Header$";
#include "swigmod.h"
#ifndef MACSWIG
#include "swigconfig.h"
#endif
class PIKE : public Language {
private:
File *f_runtime;
File *f_header;
File *f_wrappers;
File *f_init;
String *PrefixPlusUnderscore;
int current;
// Wrap modes
enum {
NO_CPP,
MEMBER_FUNC,
CONSTRUCTOR,
DESTRUCTOR,
MEMBER_VAR,
CLASS_CONST,
STATIC_FUNC,
STATIC_VAR
};
public:
/* ---------------------------------------------------------------------
* PIKE()
*
* Initialize member data
* --------------------------------------------------------------------- */
PIKE() {
f_runtime = 0;
f_header = 0;
f_wrappers = 0;
f_init = 0;
PrefixPlusUnderscore = 0;
current = NO_CPP;
}
/* ---------------------------------------------------------------------
* main()
*
* Parse command line options and initializes variables.
* --------------------------------------------------------------------- */
virtual void main(int argc, char *argv[]) {
/* Set location of SWIG library */
SWIG_library_directory("pike");
/* Look for certain command line options */
for (int i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp (argv[i], "-ldflags") == 0) {
printf("%s\n", SWIG_PIKE_RUNTIME);
SWIG_exit(EXIT_SUCCESS);
}
}
}
/* Add a symbol to the parser for conditional compilation */
Preprocessor_define("SWIGPIKE 1", 0);
/* Set language-specific configuration file */
SWIG_config_file("pike.swg");
/* Set typemap language */
SWIG_typemap_lang("pike");
/* Enable overloaded methods support */
allow_overloading();
}
/* ---------------------------------------------------------------------
* top()
* --------------------------------------------------------------------- */
virtual int top(Node *n) {
/* Get the module name */
String *module = Getattr(n, "name");
/* Get the output file name */
String *outfile = Getattr(n, "outfile");
/* Open the output file */
f_runtime = NewFile(outfile, "w");
if (!f_runtime) {
Printf(stderr, "*** Can't open '%s'\n", outfile);
SWIG_exit(EXIT_FAILURE);
}
f_init = NewString("");
f_header = NewString("");
f_wrappers = NewString("");
/* Register file targets with the SWIG file handler */
Swig_register_filebyname("header", f_header);
Swig_register_filebyname("wrapper", f_wrappers);
Swig_register_filebyname("runtime", f_runtime);
Swig_register_filebyname("init", f_init);
/* Standard stuff for the SWIG runtime section */
Swig_banner(f_runtime);
if (NoInclude) {
Printf(f_runtime, "#define SWIG_NOINCLUDE\n");
}
Printf(f_header, "#define SWIG_init pike_module_init\n");
Printf(f_header, "#define SWIG_name \"%s\"\n\n", module);
/* Change naming scheme for constructors and destructors */
Swig_name_register("construct","%c_create");
Swig_name_register("destroy","%c_destroy");
/* Current wrap type */
current = NO_CPP;
/* Emit code for children */
Language::top(n);
/* Close the initialization function */
Printf(f_init, "}\n");
SwigType_emit_type_table(f_runtime, f_wrappers);
/* Close all of the files */
Dump(f_header, f_runtime);
Dump(f_wrappers, f_runtime);
Wrapper_pretty_print(f_init, f_runtime);
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_runtime);
Delete(f_runtime);
/* Done */
return SWIG_OK;
}
/* ------------------------------------------------------------
* importDirective()
* ------------------------------------------------------------ */
virtual int importDirective(Node *n) {
String *modname = Getattr(n,"module");
if (modname) {
Printf(f_init,"pike_require(\"%s\");\n", modname);
}
return Language::importDirective(n);
}
/* ------------------------------------------------------------
* strip()
*
* For names that begin with the current class prefix plus an
* underscore (e.g. "Foo_enum_test"), return the base function
* name (i.e. "enum_test").
* ------------------------------------------------------------ */
String *strip(const DOHString_or_char *name) {
String *s = Copy(name);
if (Strncmp(name, PrefixPlusUnderscore, Len(PrefixPlusUnderscore)) != 0) {
return s;
}
Replaceall(s, PrefixPlusUnderscore, "");
return s;
}
/* ------------------------------------------------------------
* add_method()
* ------------------------------------------------------------ */
void add_method(Node *n, const DOHString_or_char *name, const DOHString_or_char *function, const DOHString_or_char *description) {
String *rename;
if (current != NO_CPP) {
rename = strip(name);
} else {
rename = NewString(name);
}
Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
Delete(rename);
}
/* ---------------------------------------------------------------------
* functionWrapper()
*
* Create a function declaration and register it with the interpreter.
* --------------------------------------------------------------------- */
virtual int functionWrapper(Node *n) {
String *name = Getattr(n,"name");
String *iname = Getattr(n,"sym:name");
SwigType *d = Getattr(n,"type");
ParmList *l = Getattr(n,"parms");
Parm *p;
String *tm;
int i;
String *overname = 0;
if (Getattr(n,"sym:overloaded")) {
overname = Getattr(n,"sym:overname");
} else {
if (!addSymbol(iname,n)) return SWIG_ERROR;
}
Wrapper *f = NewWrapper();
/* Write code to extract function parameters. */
emit_args(d, l, f);
/* Attach the standard typemaps */
emit_attach_parmmaps(l,f);
Setattr(n,"wrap:parms",l);
/* Get number of required and total arguments */
int num_arguments = emit_num_arguments(l);
int varargs = emit_isvarargs(l);
/* Which input argument to start with? */
int start = (current == MEMBER_FUNC || current == MEMBER_VAR || current == DESTRUCTOR) ? 1 : 0;
/* Offset to skip over the attribute name */
// int offset = (current == MEMBER_VAR) ? 1 : 0;
int offset = 0;
String *wname = Swig_name_wrapper(iname);
if (overname) {
Append(wname,overname);
}
Printv(f->def, "static void ", wname, "(INT32 args) {", NIL);
/* Generate code for argument marshalling */
String *description = NewString("");
char source[64];
for (i = 0, p = l; i < num_arguments; i++) {
while (checkAttribute(p,"tmap:in:numinputs","0")) {
p = Getattr(p,"tmap:in:next");
}
SwigType *pt = Getattr(p,"type");
String *ln = Getattr(p,"lname");
if (i < start) {
String *lstr = SwigType_lstr(pt,0);
Printf(f->code, "%s = (%s) THIS;\n", ln, lstr);
Delete(lstr);
} else {
/* Look for an input typemap */
sprintf(source, "sp[%d-args]", i-start+offset);
if ((tm = Getattr(p,"tmap:in"))) {
Replaceall(tm, "$source", source);
Replaceall(tm, "$target", ln);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source);
Printf(f->code, "%s\n", tm);
String *pikedesc = Getattr(p, "tmap:in:pikedesc");
if (pikedesc) {
Printv(description, pikedesc, " ", NIL);
}
p = Getattr(p,"tmap:in:next");
continue;
} else {
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number,
"Unable to use type %s as a function argument.\n",SwigType_str(pt,0));
break;
}
}
p = nextSibling(p);
}
/* Check for trailing varargs */
if (varargs) {
if (p && (tm = Getattr(p,"tmap:in"))) {
Replaceall(tm,"$input", "varargs");
Printv(f->code,tm,"\n",NIL);
}
}
/* Insert constraint checking code */
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:check"))) {
Replaceall(tm,"$target",Getattr(p,"lname"));
Printv(f->code,tm,"\n",NIL);
p = Getattr(p,"tmap:check:next");
} else {
p = nextSibling(p);
}
}
/* Insert cleanup code */
String *cleanup = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:freearg"))) {
Replaceall(tm,"$source",Getattr(p,"lname"));
Printv(cleanup,tm,"\n",NIL);
p = Getattr(p,"tmap:freearg:next");
} else {
p = nextSibling(p);
}
}
/* Insert argument output code */
String *outarg = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:argout"))) {
Replaceall(tm,"$source",Getattr(p,"lname"));
Replaceall(tm,"$target","resultobj");
Replaceall(tm,"$arg",Getattr(p,"emit:input"));
Replaceall(tm,"$input",Getattr(p,"emit:input"));
Printv(outarg,tm,"\n",NIL);
p = Getattr(p,"tmap:argout:next");
} else {
p = nextSibling(p);
}
}
/* Emit the function call */
emit_action(n,f);
/* Clear the return stack */
Printf(f->code, "pop_n_elems(args);\n");
/* Return the function value */
if (current == CONSTRUCTOR) {
Printv(f->code, "THIS = (void *) result;\n", NIL);
Printv(description, ", tVoid", NIL);
} else if (current == DESTRUCTOR) {
Printv(description, ", tVoid", NIL);
} else {
Wrapper_add_local(f, "resultobj", "struct object *resultobj");
Printv(description, ", ", NIL);
if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) {
Replaceall(tm,"$source", "result");
Replaceall(tm,"$target", "resultobj");
Replaceall(tm,"$result", "resultobj");
if (Getattr(n,"feature:new")) {
Replaceall(tm,"$owner","1");
} else {
Replaceall(tm,"$owner","0");
}
String *pikedesc = Getattr(n, "tmap:out:pikedesc");
if (pikedesc) {
Printv(description, pikedesc, NIL);
}
Printf(f->code,"%s\n", tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number,
"Unable to use return type %s in function %s.\n", SwigType_str(d,0), name);
}
}
/* Output argument output code */
Printv(f->code,outarg,NIL);
/* Output cleanup code */
Printv(f->code,cleanup,NIL);
/* Look to see if there is any newfree cleanup code */
if (Getattr(n,"feature:new")) {
if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) {
Replaceall(tm,"$source","result");
Printf(f->code,"%s\n",tm);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) {
Replaceall(tm,"$source","result");
Printf(f->code,"%s\n",tm);
}
/* Close the function */
Printf(f->code, "}\n");
/* Substitute the cleanup code */
Replaceall(f->code,"$cleanup",cleanup);
/* Substitute the function name */
Replaceall(f->code,"$symname",iname);
Replaceall(f->code,"$result","resultobj");
/* Dump the function out */
Wrapper_print(f,f_wrappers);
/* Now register the function with the interpreter. */
if (!Getattr(n,"sym:overloaded")) {
add_method(n, iname, wname, description);
} else {
Setattr(n,"wrap:name", wname);
if (!Getattr(n,"sym:nextSibling")) {
dispatchFunction(n);
}
}
Delete(cleanup);
Delete(outarg);
Delete(description);
Delete(wname);
DelWrapper(f);
return SWIG_OK;
}
/* ------------------------------------------------------------
* dispatchFunction()
*
* Emit overloading dispatch function
* ------------------------------------------------------------ */
void dispatchFunction(Node *n) {
/* Last node in overloaded chain */
int maxargs;
String *tmp = NewString("");
String *dispatch = Swig_overload_dispatch(n,"return %s(self,args);",&maxargs);
/* Generate a dispatch wrapper for all overloaded functions */
Wrapper *f = NewWrapper();
String *symname = Getattr(n,"sym:name");
String *wname = Swig_name_wrapper(symname);
Printv(f->def,
"struct object *", wname,
"(struct object *self, struct object *args) {",
NULL);
Wrapper_add_local(f,"argc","INT32 argc");
Printf(tmp,"struct object *argv[%d]", maxargs+1);
Wrapper_add_local(f,"argv",tmp);
Wrapper_add_local(f,"ii","INT32 ii");
Printf(f->code,"argc = sizeof(args);\n");
Printf(f->code,"for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n",maxargs);
Printf(f->code,"argv[ii] = array_index(args,&argv[ii],ii);\n");
Printf(f->code,"}\n");
Replaceall(dispatch,"$args","self,args");
Printv(f->code,dispatch,"\n",NIL);
Printf(f->code,"No matching function for overloaded '%s'\n", symname);
Printf(f->code,"return NULL;\n");
Printv(f->code,"}\n",NIL);
Wrapper_print(f,f_wrappers);
add_method(n,symname,wname,0);
DelWrapper(f);
Delete(dispatch);
Delete(tmp);
Delete(wname);
}
/* ------------------------------------------------------------
* variableWrapper()
* ------------------------------------------------------------ */
virtual int variableWrapper(Node *n) {
// return Language::variableWrapper(n);
String *name = Getattr(n,"name");
String *iname = Getattr(n,"sym:name");
SwigType *t = Getattr(n,"type");
String *wname;
// static int have_globals = 0;
String *tm;
Wrapper *getf, *setf;
if (!addSymbol(iname,n)) return SWIG_ERROR;
getf = NewWrapper();
setf = NewWrapper();
wname = Swig_name_wrapper(iname);
/* Create a function for setting the value of the variable */
Printf(setf->def,"static int %s_set(object *_val) {", wname);
if (!Getattr(n,"feature:immutable")) {
if ((tm = Swig_typemap_lookup_new("varin",n,name,0))) {
Replaceall(tm,"$source","_val");
Replaceall(tm,"$target",name);
Replaceall(tm,"$input","_val");
Printf(setf->code,"%s\n",tm);
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number,
"Unable to set variable of type %s.\n", SwigType_str(t,0));
}
Printf(setf->code," return 0;\n");
} else {
/* Is a readonly variable. Issue an error */
Printv(setf->code,
tab4, "Variable $iname is read-only.\n",
tab4, "return 1;\n",
NIL);
}
Printf(setf->code,"}\n");
Wrapper_print(setf,f_wrappers);
/* Create a function for getting the value of a variable */
Printf(getf->def,"static object *%s_get() {", wname);
Wrapper_add_local(getf,"pikeobj", "object *pyobj");
if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) {
Replaceall(tm,"$source",name);
Replaceall(tm,"$target","pikeobj");
Replaceall(tm,"$result","pikeobj");
Printf(getf->code,"%s\n", tm);
} else {
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number,
"Unable to link with type %s\n", SwigType_str(t,0));
}
Printf(getf->code," return pikeobj;\n}\n");
Wrapper_print(getf,f_wrappers);
/* Now add this to the variable linking mechanism */
Printf(f_init,"\t SWIG_addvarlink(SWIG_globals,(char*)\"%s\",%s_get, %s_set);\n", iname, wname, wname);
DelWrapper(setf);
DelWrapper(getf);
return SWIG_OK;
}
/* ------------------------------------------------------------
* constantWrapper()
* ------------------------------------------------------------ */
virtual int constantWrapper(Node *n) {
Swig_require(&n, "*sym:name", "type", "value", NIL);
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
String *value = Getattr(n, "value");
/* Special hook for member pointer */
if (SwigType_type(type) == T_MPOINTER) {
String *wname = Swig_name_wrapper(symname);
Printf(f_header, "static %s = %s;\n", SwigType_str(type, wname), value);
value = wname;
}
/* Perform constant typemap substitution */
String *tm = Swig_typemap_lookup_new("constant", n, value, 0);
if (tm) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", symname);
Replaceall(tm, "$symname", symname);
Replaceall(tm, "$value", value);
Printf(f_init, "%s\n", tm);
} else {
Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number,
"Unsupported constant value %s = %s\n", SwigType_str(type, 0), value);
}
Swig_restore(&n);
return SWIG_OK;
}
/* ------------------------------------------------------------
* nativeWrapper()
* ------------------------------------------------------------ */
virtual int nativeWrapper(Node *n) {
// return Language::nativeWrapper(n);
String *name = Getattr(n,"sym:name");
String *wrapname = Getattr(n,"wrap:name");
if (!addSymbol(wrapname,n)) return SWIG_ERROR;
add_method(n, name, wrapname,0);
return SWIG_OK;
}
/* ------------------------------------------------------------
* enumDeclaration()
* ------------------------------------------------------------ */
virtual int enumDeclaration(Node *n) {
return Language::enumDeclaration(n);
}
/* ------------------------------------------------------------
* enumvalueDeclaration()
* ------------------------------------------------------------ */
virtual int enumvalueDeclaration(Node *n) {
return Language::enumvalueDeclaration(n);
}
/* ------------------------------------------------------------
* classDeclaration()
* ------------------------------------------------------------ */
virtual int classDeclaration(Node *n) {
return Language::classDeclaration(n);
}
/* ------------------------------------------------------------
* classHandler()
* ------------------------------------------------------------ */
virtual int classHandler(Node *n) {
String *symname = Getattr(n, "sym:name");
if (!addSymbol(symname, n))
return SWIG_ERROR;
PrefixPlusUnderscore = NewStringf("%s_", getClassPrefix());
Printf(f_init, "start_new_program();\n");
/* Handle inheritance */
List *baselist = Getattr(n,"bases");
if (baselist && Len(baselist) > 0) {
Node *base = Firstitem(baselist);
while (base) {
char *basename = Char(Getattr(base,"name"));
if (SwigType_istemplate(basename)) {
basename = Char(SwigType_namestr(basename));
}
SwigType *basetype = NewString(basename);
SwigType_add_pointer(basetype);
SwigType_remember(basetype);
String *basemangle = SwigType_manglestr(basetype);
Printf(f_init, "low_inherit((struct program *) SWIGTYPE%s->clientdata, 0, 0, 0, 0, 0);\n", basemangle);
Delete(basemangle);
Delete(basetype);
base = Nextitem(baselist);
}
} else {
Printf(f_init, "ADD_STORAGE(swig_object_wrapper);\n");
}
Language::classHandler(n);
/* Accessors for member variables */
/*
List *membervariables = Getattr(n,"membervariables");
if (membervariables && Len(membervariables) > 0) {
membervariableAccessors(membervariables);
}
*/
/* Done, close the class */
Printf(f_init, "add_program_constant(\"%s\", pr = end_program(), 0);\n", symname);
SwigType *tt = NewString(symname);
SwigType_add_pointer(tt);
SwigType_remember(tt);
String *tm = SwigType_manglestr(tt);
Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) pr);\n", tm);
Delete(tm);
Delete(tt);
Delete(PrefixPlusUnderscore); PrefixPlusUnderscore = 0;
return SWIG_OK;
}
/* ------------------------------------------------------------
* memberfunctionHandler()
*
* Method for adding C++ member function
* ------------------------------------------------------------ */
virtual int memberfunctionHandler(Node *n) {
current = MEMBER_FUNC;
Language::memberfunctionHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* constructorHandler()
*
* Method for adding C++ member constructor
* ------------------------------------------------------------ */
virtual int constructorHandler(Node *n) {
current = CONSTRUCTOR;
Language::constructorHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* destructorHandler()
* ------------------------------------------------------------ */
virtual int destructorHandler(Node *n) {
current = DESTRUCTOR;
Language::destructorHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* membervariableAccessors()
* ------------------------------------------------------------ */
void membervariableAccessors(List *membervariables) {
String *name;
Node *n;
bool need_setter;
String *funcname;
/* If at least one of them is mutable, we need a setter */
need_setter = false;
n = Firstitem(membervariables);
while (n) {
if (!Getattr(n, "feature:immutable")) {
need_setter = true;
break;
}
n = Nextitem(membervariables);
}
/* Create a function to set the values of the (mutable) variables */
if (need_setter) {
Wrapper *wrapper = NewWrapper();
String *setter = Swig_name_member(getClassPrefix(), (char *) "`->=");
String *wname = Swig_name_wrapper(setter);
Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL);
Printf(wrapper->locals, "char *name = (char *) STR0(sp[0-args].u.string);\n");
n = Firstitem(membervariables);
while (n) {
if (!Getattr(n, "feature:immutable")) {
name = Getattr(n, "name");
funcname = Swig_name_wrapper(Swig_name_set(Swig_name_member(getClassPrefix(), name)));
Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name);
Printf(wrapper->code, "%s(args);\n", funcname);
Printf(wrapper->code, "return;\n");
Printf(wrapper->code, "}\n");
Delete(funcname);
}
n = Nextitem(membervariables);
}
/* Close the function */
Printf(wrapper->code, "pop_n_elems(args);\n");
Printf(wrapper->code, "}\n");
/* Dump wrapper code to the output file */
Wrapper_print(wrapper, f_wrappers);
/* Register it with Pike */
String *description = NewString("tStr tFloat, tVoid");
add_method(Firstitem(membervariables), "`->=", wname, description);
Delete(description);
/* Clean up */
Delete(wname);
Delete(setter);
DelWrapper(wrapper);
}
/* Create a function to get the values of the (mutable) variables */
Wrapper *wrapper = NewWrapper();
String *getter = Swig_name_member(getClassPrefix(), (char *) "`->");
String *wname = Swig_name_wrapper(getter);
Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL);
Printf(wrapper->locals, "char *name = (char *) STR0(sp[0-args].u.string);\n");
n = Firstitem(membervariables);
while (n) {
name = Getattr(n, "name");
funcname = Swig_name_wrapper(Swig_name_get(Swig_name_member(getClassPrefix(), name)));
Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name);
Printf(wrapper->code, "%s(args);\n", funcname);
Printf(wrapper->code, "return;\n");
Printf(wrapper->code, "}\n");
Delete(funcname);
n = Nextitem(membervariables);
}
/* Close the function */
Printf(wrapper->code, "pop_n_elems(args);\n");
Printf(wrapper->code, "}\n");
/* Dump wrapper code to the output file */
Wrapper_print(wrapper, f_wrappers);
/* Register it with Pike */
String *description = NewString("tStr, tMix");
add_method(Firstitem(membervariables), "`->", wname, description);
Delete(description);
/* Clean up */
Delete(wname);
Delete(getter);
DelWrapper(wrapper);
}
/* ------------------------------------------------------------
* membervariableHandler()
* ------------------------------------------------------------ */
virtual int membervariableHandler(Node *n) {
List *membervariables = Getattr(getCurrentClass(),"membervariables");
if (!membervariables) {
membervariables = NewList();
Setattr(getCurrentClass(),"membervariables",membervariables);
}
Append(membervariables,n);
current = MEMBER_VAR;
Language::membervariableHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* -----------------------------------------------------------------------
* staticmemberfunctionHandler()
*
* Wrap a static C++ function
* ---------------------------------------------------------------------- */
virtual int staticmemberfunctionHandler(Node *n) {
current = STATIC_FUNC;
Language::staticmemberfunctionHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* memberconstantHandler()
*
* Create a C++ constant
* ------------------------------------------------------------ */
virtual int memberconstantHandler(Node *n) {
current = CLASS_CONST;
constantWrapper(n);
current = NO_CPP;
return SWIG_OK;
}
/* ---------------------------------------------------------------------
* staticmembervariableHandler()
* --------------------------------------------------------------------- */
virtual int staticmembervariableHandler(Node *n) {
current = STATIC_VAR;
Language::staticmembervariableHandler(n);
current = NO_CPP;
return SWIG_OK;
}
};
/* -----------------------------------------------------------------------------
* swig_pike() - Instantiate module
* ----------------------------------------------------------------------------- */
extern "C" Language *
swig_pike(void) {
return new PIKE();
}

1268
Source/Modules/python.cxx Normal file

File diff suppressed because it is too large Load diff

1440
Source/Modules/ruby.cxx Normal file

File diff suppressed because it is too large Load diff

401
Source/Modules/s-exp.cxx Normal file
View file

@ -0,0 +1,401 @@
/* -----------------------------------------------------------------------------
* s-exp.cxx
*
* A parse tree represented as Lisp s-expressions.
*
* Author(s) : Matthias Koeppe (mkoeppe@mail.math.uni-magdeburg.de)
*
* Copyright (C) 2002. The University of Chicago
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
/* Derived from xml.cxx 1.1.2.2 */
char cvsroot_s_exp_cxx[] = "$Header$";
static const char *usage = "\
S-Exp Options (available with -sexp)\n\
-typemaplang lang - Typemap language.\n\n";
#include "swigmod.h"
//static Node *view_top = 0;
static File *out = 0;
class Sexp : public Language {
public:
int indent_level;
Sexp() : indent_level( 0 ) {}
virtual ~Sexp() {}
virtual void main(int argc, char *argv[]) {
SWIG_typemap_lang("sexp");
for( int iX = 0; iX < argc; iX++ )
{
if( strcmp( argv[iX], "-typemaplang" ) == 0 )
{
Swig_mark_arg (iX);
iX++;
SWIG_typemap_lang(argv[iX]);
Swig_mark_arg (iX);
continue;
}
if( strcmp( argv[iX], "-help" ) == 0 )
{
fputs( usage, stderr );
}
}
}
DOHHash *print_circle_hash;
int print_circle_count;
int hanging_parens;
bool need_whitespace;
bool need_newline;
/* Top of the parse tree */
virtual int top(Node *n)
{
if( out == 0 )
{
String *outfile = Getattr(n,"outfile");
Replaceall(outfile,"_wrap.cxx", ".lisp");
out = NewFile(outfile,"w");
if (!out)
{
Printf(stderr,"*** Can't open '%s'\n", outfile);
SWIG_exit(EXIT_FAILURE);
}
}
Language::top(n);
Printf( out, ";;; Lisp parse tree produced by SWIG\n" );
print_circle_hash = DohNewHash();
print_circle_count = 0;
hanging_parens = 0;
need_whitespace = 0;
need_newline = 0;
Sexp_print_node(n);
flush_parens();
return SWIG_OK;
}
void print_indent()
{
int i;
for (i = 0; i < indent_level; i++)
{
Printf(out, " ");
}
}
void open_paren(const String *oper)
{
flush_parens();
Printf(out, "(");
if (oper) Printf(out, "%s ", oper);
indent_level += 2;
}
void close_paren(bool need_newline = false)
{
hanging_parens++;
if (need_newline)
print_lazy_whitespace();
indent_level -= 2;
}
void flush_parens()
{
int i;
if (hanging_parens) {
for (i = 0; i<hanging_parens; i++)
Printf(out, ")");
hanging_parens = 0;
need_newline = true;
need_whitespace = true;
}
if (need_newline) {
Printf(out, "\n");
print_indent();
need_newline = false;
need_whitespace = false;
}
else if (need_whitespace) {
Printf(out, " ");
need_whitespace = false;
}
}
void print_lazy_whitespace()
{
need_whitespace = 1;
}
void print_lazy_newline()
{
need_newline = 1;
}
bool internal_key_p(DOH *key)
{
return ((Cmp(key,"nodeType") == 0)
|| (Cmp(key,"firstChild") == 0)
|| (Cmp(key,"lastChild") == 0)
|| (Cmp(key,"parentNode") == 0)
|| (Cmp(key,"nextSibling") == 0)
|| (Cmp(key,"previousSibling") == 0)
|| (Cmp(key,"csym:nextSibling") == 0)
|| (Cmp(key,"csym:previousSibling") == 0)
|| (Cmp(key,"typepass:visit") == 0)
|| (Cmp(key,"allocate:visit") == 0)
|| (*(Char(key)) == '$'));
}
bool boolean_key_p(DOH *key)
{
return ((Cmp(key,"allocate:default_constructor") == 0)
|| (Cmp(key,"allocate:default_destructor") == 0)
|| (Cmp(key,"allows_typedef") == 0)
|| (Cmp(key,"feature:immutable") == 0));
}
bool list_key_p(DOH *key)
{
return ((Cmp(key, "parms") == 0)
|| (Cmp(key, "baselist") == 0));
}
bool plist_key_p(DOH *key)
// true if KEY is the name of data that is a mapping from keys to
// values, which should be printed as a plist.
{
return ((Cmp(key, "typescope") == 0));
}
bool maybe_plist_key_p(DOH *key)
{
return (Strncmp(key, "tmap:", 5) == 0);
}
bool print_circle(DOH *obj, bool list_p)
// We have a complex object, which might be referenced several
// times, or even recursively. Use Lisp's reader notation for
// circular structures (#n#, #n=).
//
// An object can be printed in list-mode or object-mode; LIST_P toggles.
// return TRUE if OBJ still needs to be printed
{
flush_parens();
// Following is a silly hack. It works around the limitation of
// DOH's hash tables that only work with string keys!
char address[16];
sprintf(address, "%x%c", (unsigned int)obj, list_p ? 'L' : 'O');
DOH *placeholder = Getattr(print_circle_hash, address);
if (placeholder) {
Printv(out, placeholder, NIL);
return false;
}
else {
String *placeholder = NewStringf("#%d#", ++print_circle_count);
Setattr(print_circle_hash, address, placeholder);
Printf(out, "#%d=", print_circle_count);
return true;
}
}
void Sexp_print_value_of_key(DOH *value, DOH *key)
{
if ((Cmp(key, "parms") == 0) || (Cmp(key, "wrap:parms") == 0)
|| (Cmp(key, "kwargs") == 0) || (Cmp(key, "pattern") == 0))
Sexp_print_parms(value);
else if (plist_key_p(key))
Sexp_print_plist(value);
else if (maybe_plist_key_p(key)) {
if (DohIsMapping(value))
Sexp_print_plist(value);
else
Sexp_print_doh(value);
}
else if (list_key_p(key))
Sexp_print_list(value);
else if (boolean_key_p(key))
Sexp_print_boolean(value);
else
Sexp_print_doh(value);
}
void Sexp_print_boolean(DOH *obj)
{
flush_parens();
/* See DOH/Doh/base.c, DohGetInt() */
if (DohIsString(obj)) {
if (atoi(Char(obj)) != 0)
Printf(out, "t");
else Printf(out, "nil");
}
else Printf(out, "nil");
}
void Sexp_print_list(DOH *obj)
{
if (print_circle(obj, true)) {
open_paren(NIL);
for (; obj; obj = nextSibling(obj)) {
Sexp_print_doh(obj);
print_lazy_whitespace();
}
close_paren(true);
}
}
void Sexp_print_parms(DOH *obj)
// print it as a list of plists
{
if (print_circle(obj, true)) {
open_paren(NIL);
for (; obj; obj = nextSibling(obj)) {
if (DohIsMapping(obj)) {
DOH *k;
open_paren(NIL);
for (k = Firstkey(obj); k; k = Nextkey(obj)) {
if (!internal_key_p(k)) {
DOH *value = Getattr(obj, k);
Sexp_print_as_keyword(k);
Sexp_print_value_of_key(value, k);
print_lazy_whitespace();
}
}
close_paren(true);
}
else Sexp_print_doh(obj);
print_lazy_whitespace();
}
close_paren(true);
}
}
void Sexp_print_doh(DOH *obj)
{
flush_parens();
if (DohIsString(obj)) {
String *o = Str(obj);
Replaceall( o, "\\", "\\\\" );
Replaceall( o, "\"", "\\\"" );
Printf(out,"\"%s\"", o);
Delete(o);
}
else {
if (print_circle(obj, false)) {
// Dispatch type
if (nodeType(obj)) {
Sexp_print_node(obj);
}
else if (DohIsMapping(obj)) {
DOH *k;
open_paren(NIL);
for (k = Firstkey(obj); k; k = Nextkey(obj)) {
if (!internal_key_p(k)) {
DOH *value = Getattr(obj, k);
flush_parens();
open_paren(NIL);
Sexp_print_doh(k);
Printf(out, " . ");
Sexp_print_value_of_key(value, k);
close_paren();
}
}
close_paren();
}
else {
// What is it?
Printf(out,"#<DOH %x>", obj);
}
}
}
}
void Sexp_print_as_keyword(const DOH *k)
{
/* Print key, replacing ":" with "-" because : is CL's package prefix */
flush_parens();
String *key = NewString(k);
Replaceall(key, ":", "-");
Replaceall(key, "_", "-");
Printf(out,":%s ", key);
Delete(key);
}
void Sexp_print_plist_noparens(DOH *obj)
{
/* attributes map names to objects */
String *k;
bool first;
for (k = Firstkey(obj), first = true; k; k = Nextkey(obj), first=false) {
if (!internal_key_p(k)) {
DOH *value = Getattr(obj, k);
flush_parens();
if (!first) {
Printf(out, " ");
}
Sexp_print_as_keyword(k);
/* Print value */
Sexp_print_value_of_key(value, k);
}
}
}
void Sexp_print_plist(DOH *obj)
{
flush_parens();
if (print_circle(obj, true)) {
open_paren(NIL);
Sexp_print_plist_noparens(obj);
close_paren();
}
}
void Sexp_print_attributes(Node * obj)
{
Sexp_print_plist_noparens(obj);
}
void Sexp_print_node(Node *obj)
{
Node *cobj;
open_paren(nodeType(obj));
/* A node has an attribute list... */
Sexp_print_attributes(obj);
/* ... and child nodes. */
cobj = firstChild(obj);
if (cobj) {
print_lazy_newline();
flush_parens();
Sexp_print_as_keyword("children");
open_paren(NIL);
for (; cobj; cobj = nextSibling(cobj)) {
Sexp_print_node(cobj);
}
close_paren();
}
close_paren();
}
virtual int functionWrapper(Node *n)
{
ParmList *l = Getattr(n,"parms");
Wrapper *f = NewWrapper();
emit_attach_parmmaps(l,f);
Setattr(n,"wrap:parms",l);
return SWIG_OK;
}
};
extern "C"
{
Language * swig_sexp( void )
{
return new Sexp();
}
}

Some files were not shown because too many files have changed in this diff Show more