mirror of https://github.com/swig/swig
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:
parent
d199dde9e2
commit
74a3aa015c
|
@ -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 *~
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -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,"&","&");
|
||||
Replaceall(o,"<","<");
|
||||
Replaceall(o,">",">");
|
||||
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,"&","&");
|
||||
Replaceall(o,"<","<");
|
||||
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,"<","<");
|
||||
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,"<","<");
|
||||
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,"<","<");
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -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;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
/*******************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
*
|
||||
* swigmain.cxx
|
||||
*
|
||||
* This file is the main entry point to SWIG. It collects the command
|
||||
* line options, registers built-in language modules, and instantiates
|
||||
* a module for code generation. If adding new language modules
|
||||
* to SWIG, you would modify this file.
|
||||
*
|
||||
* 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_swigmain_cxx[] = "$Header$";
|
||||
|
||||
#ifndef MACSWIG
|
||||
#include "swigconfig.h"
|
||||
#endif
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
/* Module factories. These functions are used to instantiate
|
||||
the built-in language modules. If adding a new language
|
||||
module to SWIG, place a similar function here. Make sure
|
||||
the function has "C" linkage. This is required so that modules
|
||||
can be dynamically loaded in future versions. */
|
||||
|
||||
extern "C" {
|
||||
Language *swig_tcl(void);
|
||||
Language *swig_python(void);
|
||||
Language *swig_perl5(void);
|
||||
Language *swig_ruby(void);
|
||||
Language *swig_guile(void);
|
||||
Language *swig_mzscheme(void);
|
||||
Language *swig_java(void);
|
||||
Language *swig_php(void);
|
||||
Language *swig_ocaml(void);
|
||||
Language *swig_pike(void);
|
||||
Language *swig_sexp(void);
|
||||
Language *swig_xml(void);
|
||||
}
|
||||
|
||||
struct swig_module {
|
||||
const char *name;
|
||||
ModuleFactory fac;
|
||||
const char *help;
|
||||
};
|
||||
|
||||
/* Association of command line options to language modules.
|
||||
Place an entry for new language modules here, keeping the
|
||||
list sorted alphabetically. */
|
||||
|
||||
swig_module modules[] = {
|
||||
{"-guile", swig_guile, "Guile"},
|
||||
{"-java", swig_java, "Java"},
|
||||
{"-mzscheme", swig_mzscheme, "Mzscheme"},
|
||||
{"-ocaml", swig_ocaml, "Ocaml"},
|
||||
{"-perl", swig_perl5, "Perl"},
|
||||
{"-perl5", swig_perl5, 0},
|
||||
{"-php", swig_php, "PHP"},
|
||||
{"-php4", swig_php, 0},
|
||||
{"-pike", swig_pike, "Pike"},
|
||||
{"-python", swig_python, "Python"},
|
||||
{"-ruby", swig_ruby, "Ruby"},
|
||||
{"-sexp", swig_sexp, "Lisp S-Expressions"},
|
||||
{"-tcl", swig_tcl, "Tcl"},
|
||||
{"-tcl8", swig_tcl, 0},
|
||||
{"-xml", swig_xml, "XML"},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
#ifdef MACSWIG
|
||||
#include <console.h>
|
||||
#include <SIOUX.h>
|
||||
#endif
|
||||
|
||||
#ifndef SWIG_LANG
|
||||
#define SWIG_LANG "-python"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// main()
|
||||
//
|
||||
// Main program. Initializes the files and starts the parser.
|
||||
//-----------------------------------------------------------------
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
Language *dl = 0;
|
||||
ModuleFactory fac = 0;
|
||||
|
||||
extern int SWIG_main(int, char **, Language *);
|
||||
|
||||
#ifdef MACSWIG
|
||||
SIOUXSettings.asktosaveonclose = false;
|
||||
argc = ccommand(&argv);
|
||||
#endif
|
||||
|
||||
/* Register built-in modules */
|
||||
for (i = 0; modules[i].name; i++) {
|
||||
Swig_register_module(modules[i].name, modules[i].fac);
|
||||
}
|
||||
|
||||
Swig_init_args(argc,argv);
|
||||
|
||||
/* Get options */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i]) {
|
||||
fac = Swig_find_module(argv[i]);
|
||||
if (fac) {
|
||||
dl = (fac)();
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-nolang") == 0) {
|
||||
dl = new Language;
|
||||
Swig_mark_arg(i);
|
||||
} else if ((strcmp(argv[i],"-dnone") == 0) ||
|
||||
(strcmp(argv[i],"-dhtml") == 0) ||
|
||||
(strcmp(argv[i],"-dlatex") == 0) ||
|
||||
(strcmp(argv[i],"-dascii") == 0) ||
|
||||
(strcmp(argv[i],"-stat") == 0))
|
||||
{
|
||||
Printf(stderr,"swig: Warning. %s option deprecated.\n",argv[i]);
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-help") == 0) {
|
||||
Printf(stderr,"Target Language Options:\n");
|
||||
for (int j = 0; modules[j].name; j++) {
|
||||
if (modules[j].help) {
|
||||
Printf(stderr," %-15s - Generate %s wrappers.\n", modules[j].name, modules[j].help);
|
||||
}
|
||||
}
|
||||
Swig_mark_arg(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!dl) {
|
||||
fac = Swig_find_module(SWIG_LANG);
|
||||
if (fac) {
|
||||
dl = (fac)();
|
||||
}
|
||||
}
|
||||
return SWIG_main(argc,argv,dl);
|
||||
}
|
||||
|
|
@ -0,0 +1,255 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* swigmod.h
|
||||
*
|
||||
* Main header file for SWIG modules
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1998-2000. The University of Chicago
|
||||
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
|
||||
* University of California.
|
||||
*
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
*
|
||||
* $Header$
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "swigver.h"
|
||||
|
||||
extern "C" {
|
||||
#include "swig.h"
|
||||
extern Hash *Preprocessor_define(const String_or_char *str, int swigmacro);
|
||||
}
|
||||
|
||||
#include "swigwarn.h"
|
||||
|
||||
#define NOT_VIRTUAL 0
|
||||
#define PLAIN_VIRTUAL 1
|
||||
#define PURE_VIRTUAL 2
|
||||
|
||||
extern char *input_file;
|
||||
extern int line_number;
|
||||
extern int start_line;
|
||||
extern int CPlusPlus; // C++ mode
|
||||
extern int Extend; // Extend mode
|
||||
extern int NoInclude; // NoInclude flag
|
||||
extern int Verbose;
|
||||
extern int IsVirtual;
|
||||
extern int ImportMode;
|
||||
extern int NoExcept; // -no_except option
|
||||
|
||||
/* Miscellaneous stuff */
|
||||
|
||||
#define tab2 " "
|
||||
#define tab4 " "
|
||||
#define tab8 " "
|
||||
|
||||
class Dispatcher {
|
||||
public:
|
||||
|
||||
virtual int emit_one(Node *n);
|
||||
virtual int emit_children(Node *n);
|
||||
virtual int defaultHandler(Node *n);
|
||||
|
||||
/* Top of the parse tree */
|
||||
virtual int top(Node *n) = 0;
|
||||
|
||||
/* SWIG directives */
|
||||
|
||||
virtual int applyDirective(Node *n);
|
||||
virtual int clearDirective(Node *n);
|
||||
virtual int constantDirective(Node *n);
|
||||
virtual int extendDirective(Node *n);
|
||||
virtual int fragmentDirective(Node *n);
|
||||
virtual int importDirective(Node *n);
|
||||
virtual int includeDirective(Node *n);
|
||||
virtual int insertDirective(Node *n);
|
||||
virtual int moduleDirective(Node *n);
|
||||
virtual int nativeDirective(Node *n);
|
||||
virtual int pragmaDirective(Node *n);
|
||||
virtual int typemapDirective(Node *n);
|
||||
virtual int typemapitemDirective(Node *n);
|
||||
virtual int typemapcopyDirective(Node *n);
|
||||
virtual int typesDirective(Node *n);
|
||||
|
||||
/* C/C++ parsing */
|
||||
|
||||
virtual int cDeclaration(Node *n);
|
||||
virtual int externDeclaration(Node *n);
|
||||
virtual int enumDeclaration(Node *n);
|
||||
virtual int enumvalueDeclaration(Node *n);
|
||||
virtual int classDeclaration(Node *n);
|
||||
virtual int classforwardDeclaration(Node *n);
|
||||
virtual int constructorDeclaration(Node *n);
|
||||
virtual int destructorDeclaration(Node *n);
|
||||
virtual int accessDeclaration(Node *n);
|
||||
virtual int usingDeclaration(Node *n);
|
||||
virtual int namespaceDeclaration(Node *n);
|
||||
virtual int templateDeclaration(Node *n);
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
* class language:
|
||||
*
|
||||
* This class defines the functions that need to be supported by the
|
||||
* scripting language being used. The translator calls these virtual
|
||||
* functions to output different types of code for different languages.
|
||||
*************************************************************************/
|
||||
|
||||
class Language : public Dispatcher {
|
||||
public:
|
||||
Language();
|
||||
virtual ~Language();
|
||||
virtual int emit_one(Node *n);
|
||||
|
||||
/* Parse command line options */
|
||||
|
||||
virtual void main(int argc, char *argv[]);
|
||||
|
||||
/* Top of the parse tree */
|
||||
|
||||
virtual int top(Node *n);
|
||||
|
||||
/* SWIG directives */
|
||||
|
||||
|
||||
virtual int applyDirective(Node *n);
|
||||
virtual int clearDirective(Node *n);
|
||||
virtual int constantDirective(Node *n);
|
||||
virtual int extendDirective(Node *n);
|
||||
virtual int fragmentDirective(Node *n);
|
||||
virtual int importDirective(Node *n);
|
||||
virtual int includeDirective(Node *n);
|
||||
virtual int insertDirective(Node *n);
|
||||
virtual int moduleDirective(Node *n);
|
||||
virtual int nativeDirective(Node *n);
|
||||
virtual int pragmaDirective(Node *n);
|
||||
virtual int typemapDirective(Node *n);
|
||||
virtual int typemapcopyDirective(Node *n);
|
||||
virtual int typesDirective(Node *n);
|
||||
|
||||
/* C/C++ parsing */
|
||||
|
||||
virtual int cDeclaration(Node *n);
|
||||
virtual int externDeclaration(Node *n);
|
||||
virtual int enumDeclaration(Node *n);
|
||||
virtual int enumvalueDeclaration(Node *n);
|
||||
virtual int classDeclaration(Node *n);
|
||||
virtual int classforwardDeclaration(Node *n);
|
||||
virtual int constructorDeclaration(Node *n);
|
||||
virtual int destructorDeclaration(Node *n);
|
||||
virtual int accessDeclaration(Node *n);
|
||||
virtual int namespaceDeclaration(Node *n);
|
||||
virtual int usingDeclaration(Node *n);
|
||||
|
||||
/* Function handlers */
|
||||
|
||||
virtual int functionHandler(Node *n);
|
||||
virtual int globalfunctionHandler(Node *n);
|
||||
virtual int memberfunctionHandler(Node *n);
|
||||
virtual int staticmemberfunctionHandler(Node *n);
|
||||
virtual int callbackfunctionHandler(Node *n);
|
||||
|
||||
/* Variable handlers */
|
||||
|
||||
virtual int variableHandler(Node *n);
|
||||
virtual int globalvariableHandler(Node *n);
|
||||
virtual int membervariableHandler(Node *n);
|
||||
virtual int staticmembervariableHandler(Node *n);
|
||||
|
||||
/* C++ handlers */
|
||||
|
||||
virtual int memberconstantHandler(Node *n);
|
||||
virtual int constructorHandler(Node *n);
|
||||
virtual int copyconstructorHandler(Node *n);
|
||||
virtual int destructorHandler(Node *n);
|
||||
virtual int classHandler(Node *n);
|
||||
|
||||
/* Miscellaneous */
|
||||
|
||||
virtual int typedefHandler(Node *n);
|
||||
|
||||
/* Low-level code generation */
|
||||
|
||||
virtual int constantWrapper(Node *n);
|
||||
virtual int variableWrapper(Node *n);
|
||||
virtual int functionWrapper(Node *n);
|
||||
virtual int nativeWrapper(Node *n);
|
||||
|
||||
/* Miscellaneous */
|
||||
|
||||
virtual int validIdentifier(String *s); /* valid identifier? */
|
||||
virtual int addSymbol(String *s, Node *n); /* Add symbol */
|
||||
virtual Node *symbolLookup(String *s); /* Symbol lookup */
|
||||
virtual Node *classLookup(SwigType *s); /* Class lookup */
|
||||
|
||||
protected:
|
||||
/* Patch C++ pass-by-value */
|
||||
static void patch_parms(Parm *p);
|
||||
|
||||
/* Allow overloaded functions */
|
||||
void allow_overloading(int val = 1);
|
||||
|
||||
/* Allow multiple-input typemaps */
|
||||
void allow_multiple_input(int val = 1);
|
||||
|
||||
/* Wrapping class query */
|
||||
int is_wrapping_class();
|
||||
|
||||
/* Return the node for the current class */
|
||||
Node *getCurrentClass() const;
|
||||
|
||||
/* Return the real name of the current class */
|
||||
String *getClassName() const;
|
||||
|
||||
/* Return the current class prefix */
|
||||
String *getClassPrefix() const;
|
||||
|
||||
/* Fully qualified type name to use */
|
||||
String *getClassType() const;
|
||||
|
||||
private:
|
||||
Hash *symbols;
|
||||
Hash *classtypes;
|
||||
int overloading;
|
||||
int multiinput;
|
||||
};
|
||||
|
||||
extern int SWIG_main(int, char **, Language *);
|
||||
extern void emit_args(SwigType *, ParmList *, Wrapper *f);
|
||||
extern void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */
|
||||
extern void SWIG_config_file(const String_or_char *);
|
||||
extern void SWIG_config_cppext(const char *ext);
|
||||
|
||||
extern "C" void SWIG_typemap_lang(const char *);
|
||||
extern void SWIG_library_directory(const char *);
|
||||
extern int emit_num_arguments(ParmList *);
|
||||
extern int emit_num_required(ParmList *);
|
||||
extern int emit_isvarargs(ParmList *);
|
||||
extern void emit_attach_parmmaps(ParmList *, Wrapper *f);
|
||||
extern void emit_action(Node *n, Wrapper *f);
|
||||
extern List *Swig_overload_rank(Node *n);
|
||||
extern String *Swig_overload_dispatch(Node *n, const String_or_char *fmt, int *);
|
||||
|
||||
|
||||
extern "C" {
|
||||
typedef Language *(*ModuleFactory)(void);
|
||||
}
|
||||
|
||||
extern void Swig_register_module(const char *name, ModuleFactory fac);
|
||||
extern ModuleFactory Swig_find_module(const char *name);
|
||||
|
||||
/* swig11.h ends here */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,832 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* tcl8.cxx
|
||||
*
|
||||
* Tcl8.0 wrapper module.
|
||||
*
|
||||
* 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_tcl8_cxx[] = "$Header$";
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
#ifndef MACSWIG
|
||||
#include "swigconfig.h"
|
||||
#endif
|
||||
|
||||
static const char *usage = (char*)"\
|
||||
Tcl 8 Options (available with -tcl)\n\
|
||||
-ldflags - Print runtime libraries to link with\n\
|
||||
-prefix name - Set a prefix to be appended to all names\n\
|
||||
-namespace - Build module into a Tcl 8 namespace. \n\
|
||||
-pkgversion - Set package version.\n\n";
|
||||
|
||||
static String *cmd_tab = 0; /* Table of command names */
|
||||
static String *var_tab = 0; /* Table of global variables */
|
||||
static String *const_tab = 0; /* Constant table */
|
||||
static String *methods_tab = 0; /* Methods table */
|
||||
static String *attr_tab = 0; /* Attribute table */
|
||||
static String *prefix = 0;
|
||||
static String *module = 0;
|
||||
static int nspace = 0;
|
||||
static String *init_name = 0;
|
||||
static String *ns_name = 0;
|
||||
static int have_constructor;
|
||||
static int have_destructor;
|
||||
static String *destructor_action = 0;
|
||||
static String *version = (String *) "0.0";
|
||||
static String *class_name = 0;
|
||||
|
||||
static File *f_header = 0;
|
||||
static File *f_wrappers = 0;
|
||||
static File *f_init = 0;
|
||||
static File *f_runtime = 0;
|
||||
|
||||
class TCL8 : public Language {
|
||||
public:
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* TCL8::main()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual void main(int argc, char *argv[]) {
|
||||
|
||||
SWIG_library_directory("tcl");
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (argv[i]) {
|
||||
if (strcmp(argv[i],"-prefix") == 0) {
|
||||
if (argv[i+1]) {
|
||||
prefix = NewString(argv[i+1]);
|
||||
Swig_mark_arg(i);
|
||||
Swig_mark_arg(i+1);
|
||||
i++;
|
||||
} else Swig_arg_error();
|
||||
} else if (strcmp(argv[i],"-pkgversion") == 0) {
|
||||
if (argv[i+1]) {
|
||||
version = NewString(argv[i+1]);
|
||||
Swig_mark_arg(i);
|
||||
Swig_mark_arg(i+1);
|
||||
i++;
|
||||
}
|
||||
} else if (strcmp(argv[i],"-namespace") == 0) {
|
||||
nspace = 1;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-help") == 0) {
|
||||
fputs(usage,stderr);
|
||||
} else if (strcmp (argv[i], "-ldflags") == 0) {
|
||||
printf("%s\n", SWIG_TCL_RUNTIME);
|
||||
SWIG_exit (EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
Preprocessor_define("SWIGTCL 1",0);
|
||||
Preprocessor_define("SWIGTCL8 1", 0);
|
||||
SWIG_typemap_lang("tcl8");
|
||||
SWIG_config_file("tcl8.swg");
|
||||
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);
|
||||
Swig_register_filebyname("init",f_init);
|
||||
|
||||
/* Initialize some variables for the object interface */
|
||||
|
||||
cmd_tab = NewString("");
|
||||
var_tab = NewString("");
|
||||
methods_tab = NewString("");
|
||||
const_tab = NewString("");
|
||||
|
||||
Swig_banner(f_runtime);
|
||||
|
||||
/* Include a Tcl configuration file */
|
||||
if (NoInclude) {
|
||||
Printf(f_runtime,"#define SWIG_NOINCLUDE\n");
|
||||
}
|
||||
|
||||
/* Set the module name, namespace, and prefix */
|
||||
|
||||
module = NewStringf("%(lower)s", Getattr(n,"name"));
|
||||
init_name = NewStringf("%(title)s_Init",module);
|
||||
|
||||
ns_name = prefix ? Copy(prefix) : Copy(module);
|
||||
if (prefix) Append(prefix,"_");
|
||||
|
||||
/* Generate some macros used throughout code generation */
|
||||
|
||||
Printf(f_header,"#define SWIG_init %s\n", init_name);
|
||||
Printf(f_header,"#define SWIG_name \"%s\"\n", module);
|
||||
if (nspace) {
|
||||
Printf(f_header,"#define SWIG_prefix \"%s::\"\n", ns_name);
|
||||
Printf(f_header,"#define SWIG_namespace \"%s\"\n\n", ns_name);
|
||||
} else {
|
||||
Printf(f_header,"#define SWIG_prefix \"%s\"\n", prefix);
|
||||
}
|
||||
Printf(f_header,"#define SWIG_version \"%s\"\n", version);
|
||||
|
||||
Printf(cmd_tab, "\nstatic swig_command_info swig_commands[] = {\n");
|
||||
Printf(var_tab, "\nstatic swig_var_info swig_variables[] = {\n");
|
||||
Printf(const_tab, "\nstatic swig_const_info swig_constants[] = {\n");
|
||||
|
||||
Printf(f_wrappers,"#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
|
||||
|
||||
/* Start emitting code */
|
||||
Language::top(n);
|
||||
|
||||
/* Done. Close up the module */
|
||||
Printv(cmd_tab, tab4, "{0, 0, 0}\n", "};\n",NIL);
|
||||
Printv(var_tab, tab4, "{0,0,0,0}\n", "};\n",NIL);
|
||||
Printv(const_tab, tab4, "{0,0,0,0,0,0}\n", "};\n", NIL);
|
||||
|
||||
Printv(f_wrappers, cmd_tab, var_tab, const_tab,NIL);
|
||||
|
||||
/* Dump the pointer equivalency table */
|
||||
SwigType_emit_type_table(f_runtime, f_wrappers);
|
||||
|
||||
Printf(f_wrappers,"#ifdef __cplusplus\n}\n#endif\n");
|
||||
|
||||
/* Close the init function and quit */
|
||||
Printf(f_init,"return TCL_OK;\n}\n");
|
||||
|
||||
/* Close all of the files */
|
||||
Printv(f_runtime, f_header, f_wrappers,NIL);
|
||||
Wrapper_pretty_print(f_init,f_runtime);
|
||||
Delete(f_header);
|
||||
Delete(f_wrappers);
|
||||
Delete(f_init);
|
||||
Close(f_runtime);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* functionWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int functionWrapper(Node *n) {
|
||||
String *name = Getattr(n,"name"); /* Like to get rid of this */
|
||||
String *iname = Getattr(n,"sym:name");
|
||||
SwigType *type = Getattr(n,"type");
|
||||
ParmList *parms = Getattr(n,"parms");
|
||||
String *overname = 0;
|
||||
|
||||
Parm *p;
|
||||
int i;
|
||||
String *tm;
|
||||
Wrapper *f;
|
||||
String *incode, *cleanup, *outarg, *argstr, *args;
|
||||
int num_arguments = 0;
|
||||
int num_required = 0;
|
||||
int varargs = 0;
|
||||
|
||||
char source[64];
|
||||
|
||||
if (Getattr(n,"sym:overloaded")) {
|
||||
overname = Getattr(n,"sym:overname");
|
||||
} else {
|
||||
if (!addSymbol(iname,n)) return SWIG_ERROR;
|
||||
}
|
||||
|
||||
incode = NewString("");
|
||||
cleanup = NewString("");
|
||||
outarg = NewString("");
|
||||
argstr = NewString("\"");
|
||||
args = NewString("");
|
||||
|
||||
f = NewWrapper();
|
||||
String *wname = Swig_name_wrapper(iname);
|
||||
if (overname) {
|
||||
Append(wname, overname);
|
||||
}
|
||||
Setattr(n,"wrap:name",wname);
|
||||
|
||||
Printv(f->def,
|
||||
"static int\n ", wname, "(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {",
|
||||
NIL);
|
||||
|
||||
/* Print out variables for storing arguments. */
|
||||
emit_args(type,parms, f);
|
||||
|
||||
/* Attach standard typemaps */
|
||||
emit_attach_parmmaps(parms,f);
|
||||
Setattr(n,"wrap:parms",parms);
|
||||
|
||||
/* Get number of require and total arguments */
|
||||
num_arguments = emit_num_arguments(parms);
|
||||
num_required = emit_num_required(parms);
|
||||
varargs = emit_isvarargs(parms);
|
||||
|
||||
/* Unmarshal parameters */
|
||||
|
||||
for (i = 0, p = parms; i < num_arguments; 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 string representations of the source and target arguments */
|
||||
sprintf(source,"objv[%d]",i+1);
|
||||
|
||||
if (i == num_required) Putc('|',argstr);
|
||||
if ((tm = Getattr(p,"tmap:in"))) {
|
||||
String *parse = Getattr(p,"tmap:in:parse");
|
||||
if (!parse) {
|
||||
Replaceall(tm,"$target",ln);
|
||||
Replaceall(tm,"$source",source);
|
||||
Replaceall(tm,"$input",source);
|
||||
Setattr(p,"emit:input",source);
|
||||
|
||||
if (Getattr(p,"wrap:disown") || (Getattr(p,"tmap:in:disown"))) {
|
||||
Replaceall(tm,"$disown","SWIG_POINTER_DISOWN");
|
||||
} else {
|
||||
Replaceall(tm,"$disown","0");
|
||||
}
|
||||
|
||||
Putc('o',argstr);
|
||||
Printf(args,",0");
|
||||
if (i >= num_required) {
|
||||
Printf(incode, "if (objc > %d) {\n", i+1);
|
||||
}
|
||||
Printf(incode,"%s\n", tm);
|
||||
if (i >= num_required) {
|
||||
Printf(incode, "}\n");
|
||||
}
|
||||
} else {
|
||||
Printf(argstr,"%s",parse);
|
||||
Printf(args,",&%s",ln);
|
||||
if (Strcmp(parse,"p") == 0) {
|
||||
SwigType *lt = SwigType_ltype(pt);
|
||||
SwigType_remember(pt);
|
||||
if (Cmp(lt,"p.void") == 0) {
|
||||
Printf(args,",0");
|
||||
} else {
|
||||
Printf(args,",SWIGTYPE%s", SwigType_manglestr(pt));
|
||||
}
|
||||
Delete(lt);
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
p = nextSibling(p);
|
||||
}
|
||||
|
||||
if (!varargs) {
|
||||
Putc(':',argstr);
|
||||
} else {
|
||||
Putc(';',argstr);
|
||||
/* If variable length arguments we need to emit the in typemap here */
|
||||
if (p && (tm = Getattr(p,"tmap:in"))) {
|
||||
sprintf(source,"objv[%d]", i+1);
|
||||
Printf(incode,"if (objc > %d) {\n", i);
|
||||
Replaceall(tm,"$input",source);
|
||||
Printv(incode,tm,"\n", NIL);
|
||||
Printf(incode,"}\n");
|
||||
}
|
||||
}
|
||||
|
||||
Printf(argstr,"%s\"",usage_string(Char(iname),type,parms));
|
||||
|
||||
Printv(f->code,
|
||||
"if (SWIG_GetArgs(interp, objc, objv,", argstr, args, ") == TCL_ERROR) SWIG_fail;\n",
|
||||
NIL);
|
||||
|
||||
Printv(f->code,incode,NIL);
|
||||
|
||||
/* Insert constraint checking code */
|
||||
for (p = parms; 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 */
|
||||
for (i = 0, p = parms; p; i++) {
|
||||
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 */
|
||||
for (i=0,p = parms; p;i++) {
|
||||
if ((tm = Getattr(p,"tmap:argout"))) {
|
||||
Replaceall(tm,"$source",Getattr(p,"lname"));
|
||||
Replaceall(tm,"$target","(Tcl_GetObjResult(interp))");
|
||||
Replaceall(tm,"$result","(Tcl_GetObjResult(interp))");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Now write code to make the function call */
|
||||
emit_action(n,f);
|
||||
|
||||
/* Need to redo all of this code (eventually) */
|
||||
|
||||
/* Return value if necessary */
|
||||
if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) {
|
||||
Replaceall(tm,"$source", "result");
|
||||
Replaceall(tm,"$target", "Tcl_GetObjResult(interp)");
|
||||
Replaceall(tm,"$result", "Tcl_GetObjResult(interp)");
|
||||
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(type,0), name);
|
||||
}
|
||||
|
||||
/* Dump output argument code */
|
||||
Printv(f->code,outarg,NIL);
|
||||
|
||||
/* Dump the argument cleanup code */
|
||||
Printv(f->code,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");
|
||||
Printf(f->code,"%s\n", tm);
|
||||
}
|
||||
}
|
||||
|
||||
if ((tm = Swig_typemap_lookup_new("ret",n,"result",0))) {
|
||||
Replaceall(tm,"$source","result");
|
||||
Printf(f->code,"%s\n", tm);
|
||||
}
|
||||
Printv(f->code, "return TCL_OK;\n", NIL);
|
||||
Printv(f->code, "fail:\n", cleanup, "return TCL_ERROR;\n", NIL);
|
||||
Printv(f->code,"}\n", NIL);
|
||||
|
||||
/* Substitute the cleanup code */
|
||||
Replaceall(f->code,"$cleanup",cleanup);
|
||||
Replaceall(f->code,"$symname", iname);
|
||||
|
||||
/* Dump out the function */
|
||||
Wrapper_print(f,f_wrappers);
|
||||
|
||||
if (!Getattr(n,"sym:overloaded")) {
|
||||
/* Register the function with Tcl */
|
||||
Printv(cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", Swig_name_wrapper(iname), ", NULL},\n", NIL);
|
||||
} else {
|
||||
if (!Getattr(n,"sym:nextSibling")) {
|
||||
/* Emit overloading dispatch function */
|
||||
|
||||
int maxargs;
|
||||
String *dispatch = Swig_overload_dispatch(n,"return %s(clientData, interp, objc, objv);",&maxargs);
|
||||
|
||||
/* Generate a dispatch wrapper for all overloaded functions */
|
||||
|
||||
Wrapper *df = NewWrapper();
|
||||
String *dname = Swig_name_wrapper(iname);
|
||||
|
||||
Printv(df->def,
|
||||
"static int\n", dname,
|
||||
"(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {",
|
||||
NIL);
|
||||
Printf(df->code,"Tcl_Obj *CONST *argv = objv+1;\n");
|
||||
Printf(df->code,"int argc = objc-1;\n");
|
||||
Printv(df->code,dispatch,"\n",NIL);
|
||||
Printf(df->code,"Tcl_SetResult(interp,(char *) \"No matching function for overloaded '%s'\", TCL_STATIC);\n", iname);
|
||||
Printf(df->code,"return TCL_ERROR;\n");
|
||||
Printv(df->code,"}\n",NIL);
|
||||
Wrapper_print(df,f_wrappers);
|
||||
Printv(cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", dname, ", NULL},\n", NIL);
|
||||
DelWrapper(df);
|
||||
Delete(dispatch);
|
||||
Delete(dname);
|
||||
}
|
||||
}
|
||||
|
||||
Delete(incode);
|
||||
Delete(cleanup);
|
||||
Delete(outarg);
|
||||
Delete(argstr);
|
||||
Delete(args);
|
||||
DelWrapper(f);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* variableWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int variableWrapper(Node *n) {
|
||||
|
||||
String *name = Getattr(n,"name");
|
||||
String *iname = Getattr(n,"sym:name");
|
||||
SwigType *t = Getattr(n,"type");
|
||||
|
||||
String *setname = 0;
|
||||
String *getname = 0;
|
||||
Wrapper *setf = 0, *getf = 0;
|
||||
int readonly = 0;
|
||||
String *tm;
|
||||
|
||||
if (!addSymbol(iname,n)) return SWIG_ERROR;
|
||||
|
||||
/* Create a function for getting a variable */
|
||||
getf = NewWrapper();
|
||||
getname = Swig_name_wrapper(Swig_name_get(iname));
|
||||
Printv(getf->def,"static char *",getname,"(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",NIL);
|
||||
Wrapper_add_local(getf,"value", "Tcl_Obj *value = 0");
|
||||
|
||||
if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) {
|
||||
Replaceall(tm,"$source", name);
|
||||
Replaceall(tm,"$target","value");
|
||||
Replaceall(tm,"$result", "value");
|
||||
Printf(getf->code, "%s\n",tm);
|
||||
Printf(getf->code, "if (value) {\n");
|
||||
Printf(getf->code, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n");
|
||||
Printf(getf->code, "Tcl_DecrRefCount(value);\n");
|
||||
Printf(getf->code, "}\n");
|
||||
Printf(getf->code, "return NULL;\n");
|
||||
Printf(getf->code,"}\n");
|
||||
Wrapper_print(getf,f_wrappers);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number,
|
||||
"Can't link to variable of type %s\n", SwigType_str(t,0));
|
||||
DelWrapper(getf);
|
||||
return SWIG_NOWRAP;
|
||||
}
|
||||
DelWrapper(getf);
|
||||
|
||||
/* Try to create a function setting a variable */
|
||||
if (!Getattr(n,"feature:immutable")) {
|
||||
setf = NewWrapper();
|
||||
setname = Swig_name_wrapper(Swig_name_set(iname));
|
||||
Printv(setf->def,"static char *",setname, "(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",NIL);
|
||||
Wrapper_add_local(setf,"value", "Tcl_Obj *value = 0");
|
||||
Wrapper_add_local(setf,"name1o", "Tcl_Obj *name1o = 0");
|
||||
|
||||
if ((tm = Swig_typemap_lookup_new("varin", n, name, 0))) {
|
||||
Replaceall(tm,"$source","value");
|
||||
Replaceall(tm,"$target",name);
|
||||
Replaceall(tm,"$input", "value");
|
||||
Printf(setf->code,"name1o = Tcl_NewStringObj(name1,-1);\n");
|
||||
Printf(setf->code,"value = Tcl_ObjGetVar2(interp, name1o, 0, flags);\n");
|
||||
Printf(setf->code,"Tcl_DecrRefCount(name1o);\n");
|
||||
Printf(setf->code,"if (!value) return NULL;\n");
|
||||
Printf(setf->code,"%s\n", tm);
|
||||
Printf(setf->code,"return NULL;\n");
|
||||
Printf(setf->code,"}\n");
|
||||
if (setf) Wrapper_print(setf,f_wrappers);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF,input_file, line_number,
|
||||
"Variable %s will be read-only without a varin typemap.\n", name);
|
||||
readonly = 1;
|
||||
}
|
||||
DelWrapper(setf);
|
||||
}
|
||||
|
||||
Printv(var_tab, tab4,"{ SWIG_prefix \"", iname, "\", 0, (swig_variable_func) ", getname, ",", NIL);
|
||||
if (readonly || Getattr(n,"feature:immutable")) {
|
||||
static int readonlywrap = 0;
|
||||
if (!readonlywrap) {
|
||||
Wrapper *ro = NewWrapper();
|
||||
Printf(ro->def, "static const char *swig_readonly(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {");
|
||||
Printv(ro->code, "return (char*) \"Variable is read-only\";\n", "}\n", NIL);
|
||||
Wrapper_print(ro,f_wrappers);
|
||||
readonlywrap = 1;
|
||||
DelWrapper(ro);
|
||||
}
|
||||
Printf(var_tab, "(swig_variable_func) swig_readonly},\n");
|
||||
} else {
|
||||
Printv(var_tab, "(swig_variable_func) ", setname, "},\n",NIL);
|
||||
}
|
||||
Delete(setname);
|
||||
Delete(getname);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* constantWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int constantWrapper(Node *n) {
|
||||
String *name = Getattr(n,"name");
|
||||
String *iname = Getattr(n,"sym:name");
|
||||
SwigType *type = Getattr(n,"type");
|
||||
String *value = Getattr(n,"value");
|
||||
String *tm;
|
||||
|
||||
if (!addSymbol(iname,n)) return SWIG_ERROR;
|
||||
|
||||
/* Special hook for member pointer */
|
||||
if (SwigType_type(type) == T_MPOINTER) {
|
||||
String *wname = Swig_name_wrapper(iname);
|
||||
Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type,wname), value);
|
||||
value = Char(wname);
|
||||
}
|
||||
if ((tm = Swig_typemap_lookup_new("consttab",n,name,0))) {
|
||||
Replaceall(tm,"$source",value);
|
||||
Replaceall(tm,"$target",name);
|
||||
Replaceall(tm,"$value",value);
|
||||
Printf(const_tab,"%s,\n", tm);
|
||||
} else if ((tm = Swig_typemap_lookup_new("constcode", n, name, 0))) {
|
||||
Replaceall(tm,"$source", value);
|
||||
Replaceall(tm,"$target", name);
|
||||
Replaceall(tm,"$value",value);
|
||||
Printf(f_init, "%s\n", tm);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_CONST_UNDEF,
|
||||
input_file, line_number, "Unsupported constant value.\n");
|
||||
return SWIG_NOWRAP;
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* nativeWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int nativeWrapper(Node *n) {
|
||||
String *name = Getattr(n,"sym:name");
|
||||
String *funcname = Getattr(n,"wrap:name");
|
||||
if (!addSymbol(funcname,n)) return SWIG_ERROR;
|
||||
|
||||
Printf(f_init,"\t Tcl_CreateObjCommand(interp, SWIG_prefix \"%s\", (swig_wrapper_func) %s, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);\n",name, funcname);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* classHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int classHandler(Node *n) {
|
||||
|
||||
String *mangled_classname = 0;
|
||||
String *real_classname = 0;
|
||||
|
||||
have_constructor = 0;
|
||||
have_destructor = 0;
|
||||
destructor_action = 0;
|
||||
|
||||
class_name = Getattr(n,"sym:name");
|
||||
if (!addSymbol(class_name,n)) return SWIG_ERROR;
|
||||
|
||||
real_classname = Getattr(n,"name");
|
||||
mangled_classname = Swig_name_mangle(real_classname);
|
||||
|
||||
attr_tab = NewString("");
|
||||
Printf(attr_tab, "static swig_attribute swig_");
|
||||
Printv(attr_tab, mangled_classname, "_attributes[] = {\n", NIL);
|
||||
|
||||
methods_tab = NewStringf("");
|
||||
Printf(methods_tab,"static swig_method swig_");
|
||||
Printv(methods_tab, mangled_classname, "_methods[] = {\n", NIL);
|
||||
|
||||
/* Generate normal wrappers */
|
||||
Language::classHandler(n);
|
||||
|
||||
SwigType *t = Copy(Getattr(n,"name"));
|
||||
SwigType_add_pointer(t);
|
||||
|
||||
// Catch all: eg. a class with only static functions and/or variables will not have 'remembered'
|
||||
// SwigType_remember(t);
|
||||
String *wrap_class = NewStringf("&_wrap_class_%s", mangled_classname);
|
||||
SwigType_remember_clientdata(t,wrap_class);
|
||||
|
||||
// t = Copy(Getattr(n,"classtype"));
|
||||
// SwigType_add_pointer(t);
|
||||
|
||||
String *rt = Copy(Getattr(n,"classtype"));
|
||||
SwigType_add_pointer(rt);
|
||||
|
||||
// Register the class structure with the type checker
|
||||
/* Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_classname); */
|
||||
if (have_destructor) {
|
||||
Printv(f_wrappers, "static void swig_delete_", class_name, "(void *obj) {\n", NIL);
|
||||
if (destructor_action) {
|
||||
Printv(f_wrappers, SwigType_str(rt,"arg1"), " = (", SwigType_str(rt,0), ") obj;\n", NIL);
|
||||
Printv(f_wrappers, destructor_action, NIL);
|
||||
} else {
|
||||
if (CPlusPlus) {
|
||||
Printv(f_wrappers," delete (", SwigType_str(rt,0), ") obj;\n",NIL);
|
||||
} else {
|
||||
Printv(f_wrappers," free((char *) obj);\n",NIL);
|
||||
}
|
||||
}
|
||||
Printf(f_wrappers,"}\n");
|
||||
}
|
||||
|
||||
Printf(methods_tab, " {0,0}\n};\n");
|
||||
Printv(f_wrappers,methods_tab,NIL);
|
||||
|
||||
Printf(attr_tab, " {0,0,0}\n};\n");
|
||||
Printv(f_wrappers,attr_tab,NIL);
|
||||
|
||||
/* Handle inheritance */
|
||||
|
||||
String *base_class = NewString("");
|
||||
List *baselist = Getattr(n,"bases");
|
||||
if (baselist && Len(baselist)) {
|
||||
Node *base = Firstitem(baselist);
|
||||
while (base) {
|
||||
String *bname = Getattr(base, "name");
|
||||
if ((!bname) || Getattr(base,"feature:ignore") || (!Getattr(base,"module"))) {
|
||||
base = Nextitem(baselist);
|
||||
continue;
|
||||
}
|
||||
String *bmangle = Swig_name_mangle(bname);
|
||||
Printv(f_wrappers,"extern swig_class _wrap_class_", bmangle, ";\n", NIL);
|
||||
Printf(base_class,"&_wrap_class_%s",bmangle);
|
||||
base = Nextitem(baselist);
|
||||
Putc(',',base_class);
|
||||
Delete(bmangle);
|
||||
}
|
||||
}
|
||||
|
||||
Printv(f_wrappers,"static swig_class *swig_",mangled_classname,"_bases[] = {", base_class,"0};\n", NIL);
|
||||
Delete(base_class);
|
||||
|
||||
Printv(f_wrappers, "swig_class _wrap_class_", mangled_classname, " = { \"", class_name,
|
||||
"\", &SWIGTYPE", SwigType_manglestr(t), ",",NIL);
|
||||
|
||||
if (have_constructor) {
|
||||
Printf(f_wrappers,"%s", Swig_name_wrapper(Swig_name_construct(class_name)));
|
||||
} else {
|
||||
Printf(f_wrappers,"0");
|
||||
}
|
||||
if (have_destructor) {
|
||||
Printv(f_wrappers, ", swig_delete_", class_name,NIL);
|
||||
} else {
|
||||
Printf(f_wrappers,",0");
|
||||
}
|
||||
Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname,"_bases };\n", NIL);
|
||||
Printv(cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, &_wrap_class_", mangled_classname, "},\n", NIL);
|
||||
Delete(t);
|
||||
Delete(mangled_classname);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* memberfunctionHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int memberfunctionHandler(Node *n) {
|
||||
String *name = Getattr(n,"name");
|
||||
String *iname = GetChar(n,"sym:name");
|
||||
|
||||
String *realname, *rname;
|
||||
|
||||
Language::memberfunctionHandler(n);
|
||||
|
||||
realname = iname ? iname : name;
|
||||
rname = Swig_name_wrapper(Swig_name_member(class_name, realname));
|
||||
if (!Getattr(n,"sym:nextSibling")) {
|
||||
Printv(methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL);
|
||||
}
|
||||
Delete(rname);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* membervariableHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int membervariableHandler(Node *n) {
|
||||
String *symname = Getattr(n,"sym:name");
|
||||
String *rname;
|
||||
|
||||
Language::membervariableHandler(n);
|
||||
Printv(attr_tab, tab4, "{ \"-", symname, "\",", NIL);
|
||||
rname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name,symname)));
|
||||
Printv(attr_tab, rname, ", ", NIL);
|
||||
Delete(rname);
|
||||
if (!Getattr(n,"feature:immutable")) {
|
||||
rname = Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name,symname)));
|
||||
Printv(attr_tab, rname, "},\n",NIL);
|
||||
Delete(rname);
|
||||
} else {
|
||||
Printf(attr_tab, "0 },\n");
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* constructorHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int constructorHandler(Node *n) {
|
||||
Language::constructorHandler(n);
|
||||
have_constructor = 1;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* destructorHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int destructorHandler(Node *n) {
|
||||
Language::destructorHandler(n);
|
||||
have_destructor = 1;
|
||||
destructor_action = Getattr(n,"wrap:action");
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* validIdentifier()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int validIdentifier(String *s) {
|
||||
if (Strchr(s,' ')) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* usage_string()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
char *
|
||||
usage_string(char *iname, SwigType *, ParmList *l) {
|
||||
static String *temp = 0;
|
||||
Parm *p;
|
||||
int i, numopt,pcount;
|
||||
|
||||
if (!temp) temp = NewString("");
|
||||
Clear(temp);
|
||||
if (nspace) {
|
||||
Printf(temp,"%s::%s", ns_name,iname);
|
||||
} else {
|
||||
Printf(temp,"%s ", iname);
|
||||
}
|
||||
/* Now go through and print parameters */
|
||||
i = 0;
|
||||
pcount = ParmList_len(l);
|
||||
numopt = 0; /*check_numopt(l); */
|
||||
for (p = l; p; p = nextSibling(p)) {
|
||||
|
||||
SwigType *pt = Getattr(p,"type");
|
||||
String *pn = Getattr(p,"name");
|
||||
/* Only print an argument if not ignored */
|
||||
if (!checkAttribute(p,"tmap:in:numinputs","0")) {
|
||||
if (i >= (pcount-numopt))
|
||||
Putc('?',temp);
|
||||
if (Len(pn) > 0) {
|
||||
Printf(temp, "%s",pn);
|
||||
} else {
|
||||
Printf(temp,"%s", SwigType_str(pt,0));
|
||||
}
|
||||
if (i >= (pcount-numopt)) Putc('?',temp);
|
||||
Putc(' ',temp);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return Char(temp);
|
||||
}
|
||||
};
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* swig_tcl() - Instantiate module
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
extern "C" Language *
|
||||
swig_tcl(void) {
|
||||
return new TCL8();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,966 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* typepass.cxx
|
||||
*
|
||||
* This module builds all of the internal type information by collecting
|
||||
* typedef declarations as well as registering classes, structures, and unions.
|
||||
* This information is needed to correctly handle shadow classes and other
|
||||
* advanced features. This phase of compilation is also used to perform
|
||||
* type-expansion. All types are fully qualified with namespace prefixes
|
||||
* and other information needed for compilation.
|
||||
*
|
||||
* This module also handles the %varargs directive by looking for
|
||||
* "feature:varargs" and substituting ... with an alternative set of
|
||||
* arguments.
|
||||
*
|
||||
* 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_typepass_cxx[] = "$Header$";
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
struct normal_node {
|
||||
Symtab *symtab;
|
||||
Hash *typescope;
|
||||
List *normallist;
|
||||
normal_node *next;
|
||||
};
|
||||
|
||||
static normal_node *patch_list = 0;
|
||||
|
||||
class TypePass : public Dispatcher {
|
||||
Node *inclass;
|
||||
Node *module;
|
||||
int importmode;
|
||||
String *nsname;
|
||||
Hash *classhash;
|
||||
List *normalize;
|
||||
|
||||
/* Normalize a type. Replaces type with fully qualified version */
|
||||
|
||||
void normalize_type(SwigType *ty) {
|
||||
SwigType *qty;
|
||||
/*qty = Swig_symbol_type_qualify(ty,0);*/
|
||||
/* if (SwigType_istemplate(ty)) {
|
||||
qty = Swig_symbol_type_qualify(ty,0);
|
||||
Clear(ty);
|
||||
Append(ty,qty);
|
||||
}
|
||||
*/
|
||||
|
||||
if (CPlusPlus) {
|
||||
Replaceall(ty,"struct ","");
|
||||
Replaceall(ty,"union ","");
|
||||
Replaceall(ty,"class ","");
|
||||
}
|
||||
|
||||
qty = SwigType_typedef_qualified(ty);
|
||||
/* Printf(stdout,"%s --> %s\n", ty, qty);*/
|
||||
Clear(ty);
|
||||
Append(ty,qty);
|
||||
Delete(qty);
|
||||
}
|
||||
|
||||
/* Normalize a parameter list */
|
||||
|
||||
void normalize_parms(ParmList *p) {
|
||||
while (p) {
|
||||
SwigType *ty = Getattr(p,"type");
|
||||
normalize_type(ty);
|
||||
String *value = Getattr(p,"value");
|
||||
if (value) {
|
||||
Node *n = Swig_symbol_clookup(value,0);
|
||||
if (n) {
|
||||
String *q = Swig_symbol_qualified(n);
|
||||
if (q && Len(q)) {
|
||||
String *vb = Swig_scopename_last(value);
|
||||
Clear(value);
|
||||
Printf(value,"%s::%s", SwigType_namestr(q), vb);
|
||||
Delete(q);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value && SwigType_istemplate(value)) {
|
||||
String *nv = SwigType_namestr(value);
|
||||
Setattr(p,"value",nv);
|
||||
}
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
void normalize_later(ParmList *p) {
|
||||
while (p) {
|
||||
SwigType *ty = Getattr(p,"type");
|
||||
Append(normalize,ty);
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Walk through entries in normalize list and patch them up */
|
||||
void normalize_list() {
|
||||
Hash *currentsym = Swig_symbol_current();
|
||||
|
||||
normal_node *nn = patch_list;
|
||||
normal_node *np;
|
||||
while (nn) {
|
||||
Swig_symbol_setscope(nn->symtab);
|
||||
SwigType_set_scope(nn->typescope);
|
||||
SwigType *t;
|
||||
for (t = Firstitem(nn->normallist); t; t = Nextitem(nn->normallist)) {
|
||||
normalize_type(t);
|
||||
}
|
||||
Delete(nn->normallist);
|
||||
np = nn->next;
|
||||
delete(nn);
|
||||
nn = np;
|
||||
}
|
||||
Swig_symbol_setscope(currentsym);
|
||||
}
|
||||
|
||||
/* generate C++ inheritance type-relationships */
|
||||
void cplus_inherit_types(Node *first, Node *cls, String *clsname, String *cast = 0) {
|
||||
|
||||
if (first == cls) return; /* The Marcelo check */
|
||||
if (!cls) cls = first;
|
||||
|
||||
List *ilist = Getattr(cls,"bases");
|
||||
if (!ilist) {
|
||||
List *nlist = Getattr(cls,"baselist");
|
||||
if (nlist) {
|
||||
int len = Len(nlist);
|
||||
int i;
|
||||
for (i = 0; i < len; i++) {
|
||||
Node *bcls = 0;
|
||||
int clsforward = 0;
|
||||
String *bname = Getitem(nlist,i);
|
||||
String *sname = bname;
|
||||
String *tname = 0;
|
||||
|
||||
/* Try to locate the base class. We look in the symbol table and we chase
|
||||
typedef declarations to get to the base class if necessary */
|
||||
Symtab *st = Getattr(cls,"sym:symtab");
|
||||
|
||||
if (SwigType_istemplate(bname)) {
|
||||
tname = SwigType_typedef_resolve_all(bname);
|
||||
sname = tname;
|
||||
}
|
||||
while (1) {
|
||||
String *qsname = SwigType_typedef_qualified(sname);
|
||||
bcls = Swig_symbol_clookup(qsname,st);
|
||||
Delete(qsname);
|
||||
if (bcls) {
|
||||
if (Strcmp(nodeType(bcls),"class") != 0) {
|
||||
/* Not a class. The symbol could be a typedef. */
|
||||
if (checkAttribute(bcls,"storage","typedef")) {
|
||||
SwigType *decl = Getattr(bcls,"decl");
|
||||
if (!decl || !(Len(decl))) {
|
||||
sname = Getattr(bcls,"type");
|
||||
st = Getattr(bcls,"sym:symtab");
|
||||
if (SwigType_istemplate(sname)) {
|
||||
if (tname) Delete(tname);
|
||||
tname = SwigType_typedef_resolve_all(sname);
|
||||
sname = tname;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (Strcmp(nodeType(bcls),"classforward") != 0) {
|
||||
Swig_error(Getfile(bname),Getline(bname),"'%s' is not a class. \n",bname);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPE_INCOMPLETE,Getfile(bname),Getline(bname),"Base class '%s' is incomplete.\n", bname);
|
||||
clsforward = 1;
|
||||
}
|
||||
bcls = 0;
|
||||
} else {
|
||||
if (Getattr(bcls,"typepass:visit")) {
|
||||
if (!ilist) ilist = NewList();
|
||||
Append(ilist,bcls);
|
||||
} else {
|
||||
Swig_error(Getfile(bcls),Getline(bcls),"class '%s' must be defined before it is used as a base class.\n", bname);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (tname) Delete(tname);
|
||||
if (!bcls) {
|
||||
if (!clsforward) {
|
||||
if (!Getmeta(bname,"already_warned")) {
|
||||
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname),Getline(bname),"Nothing known about class '%s'. Ignored.\n", SwigType_namestr(bname));
|
||||
if (Strchr(bname,'<')) {
|
||||
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Maybe you forgot to instantiate '%s' using %%template.\n", SwigType_namestr(bname));
|
||||
}
|
||||
Setmeta(bname,"already_warned","1");
|
||||
}
|
||||
}
|
||||
SwigType_inherit(clsname,bname, cast);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ilist) {
|
||||
Setattr(cls,"bases",ilist);
|
||||
}
|
||||
}
|
||||
if (!ilist) return;
|
||||
int len = Len(ilist);
|
||||
int i;
|
||||
for (i = 0; i < len; i++) {
|
||||
Node *n = Getitem(ilist,i);
|
||||
String *bname = Getattr(n,"name");
|
||||
Node *bclass = n; /* Getattr(n,"class"); */
|
||||
Hash *scopes = Getattr(bclass,"typescope");
|
||||
SwigType_inherit(clsname,bname, cast);
|
||||
if (!importmode) {
|
||||
String *btype = Copy(bname);
|
||||
SwigType_add_pointer(btype);
|
||||
SwigType_remember(btype);
|
||||
Delete(btype);
|
||||
}
|
||||
if (scopes) {
|
||||
SwigType_inherit_scope(scopes);
|
||||
}
|
||||
/* Set up inheritance in the symbol table */
|
||||
Symtab *s = Swig_symbol_current();
|
||||
Symtab *st = Getattr(cls,"symtab");
|
||||
Swig_symbol_setscope(st);
|
||||
Swig_symbol_inherit(Getattr(bclass,"symtab"));
|
||||
Swig_symbol_setscope(s);
|
||||
|
||||
/* Recursively hit base classes */
|
||||
String *newcast = NewStringf("(%s *)%s", SwigType_namestr(Getattr(bclass,"name")), cast);
|
||||
cplus_inherit_types(first,bclass,clsname, newcast);
|
||||
Delete(newcast);
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean overloaded list. Removes templates, friends, ignored, and errors */
|
||||
|
||||
void clean_overloaded(Node *n) {
|
||||
Node *nn = Getattr(n,"sym:overloaded");
|
||||
Node *first = 0;
|
||||
int cnt = 0;
|
||||
while (nn) {
|
||||
if ((Strcmp(nodeType(nn),"template") == 0) ||
|
||||
(Getattr(nn,"feature:ignore")) ||
|
||||
(Getattr(nn,"error")) ||
|
||||
((Strcmp(nodeType(nn),"using") == 0) && !firstChild(nn)) ||
|
||||
(checkAttribute(nn,"storage","friend"))) {
|
||||
/* Remove from overloaded list */
|
||||
Node *ps = Getattr(nn,"sym:previousSibling");
|
||||
Node *ns = Getattr(nn,"sym:nextSibling");
|
||||
if (ps) {
|
||||
Setattr(ps,"sym:nextSibling",ns);
|
||||
}
|
||||
if (ns) {
|
||||
Setattr(ns,"sym:previousSibling",ps);
|
||||
}
|
||||
Delattr(nn,"sym:previousSibling");
|
||||
Delattr(nn,"sym:nextSibling");
|
||||
Delattr(nn,"sym:overloaded");
|
||||
nn = ns;
|
||||
continue;
|
||||
} else if ((Strcmp(nodeType(nn),"using") == 0)) {
|
||||
/* A possibly dangerous parse tree hack. We're going to
|
||||
cut the parse tree node out and stick in the resolved
|
||||
using declarations */
|
||||
|
||||
Node *ps = Getattr(nn,"sym:previousSibling");
|
||||
Node *ns = Getattr(nn,"sym:nextSibling");
|
||||
Node *un = firstChild(nn);
|
||||
Node *pn = un;
|
||||
|
||||
if (!first) {
|
||||
first = un;
|
||||
}
|
||||
while (pn) {
|
||||
Node *ppn = Getattr(pn,"sym:nextSibling");
|
||||
Setattr(pn,"sym:overloaded",first);
|
||||
Setattr(pn,"sym:overname", NewStringf("%s_%d", Getattr(nn,"sym:overname"), cnt++));
|
||||
if (ppn) pn = ppn;
|
||||
else break;
|
||||
}
|
||||
if (ps) {
|
||||
Setattr(ps,"sym:nextSibling",un);
|
||||
Setattr(un,"sym:previousSibling",ps);
|
||||
}
|
||||
if (ns) {
|
||||
Setattr(ns,"sym:previousSibling", pn);
|
||||
Setattr(pn,"sym:nextSibling",ns);
|
||||
}
|
||||
if (!first) {
|
||||
first = un;
|
||||
Setattr(nn,"sym:overloaded",first);
|
||||
}
|
||||
} else {
|
||||
if (!first) first = nn;
|
||||
Setattr(nn,"sym:overloaded",first);
|
||||
}
|
||||
nn = Getattr(nn,"sym:nextSibling");
|
||||
}
|
||||
if (!first || (first && !Getattr(first,"sym:nextSibling"))) {
|
||||
Delattr(n,"sym:overloaded");
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* top()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int top(Node *n) {
|
||||
importmode = 0;
|
||||
module = Getattr(n,"module");
|
||||
inclass = 0;
|
||||
normalize = 0;
|
||||
nsname = 0;
|
||||
classhash = Getattr(n,"classes");
|
||||
emit_children(n);
|
||||
normalize_list();
|
||||
SwigType_set_scope(0);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* moduleDirective()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int moduleDirective(Node *n) {
|
||||
if (!module) {
|
||||
module = n;
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* importDirective()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int importDirective(Node *n) {
|
||||
String *oldmodule = module;
|
||||
int oldimport = importmode;
|
||||
importmode = 1;
|
||||
module = 0;
|
||||
emit_children(n);
|
||||
importmode = oldimport;
|
||||
module = oldmodule;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* includeDirective()
|
||||
* externDirective()
|
||||
* extendDirective()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int includeDirective(Node *n) { return emit_children(n); }
|
||||
virtual int externDeclaration(Node *n) { return emit_children(n); }
|
||||
virtual int extendDirective(Node *n) { return emit_children(n); }
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* classDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int classDeclaration(Node *n) {
|
||||
String *name = Getattr(n,"name");
|
||||
String *tdname = Getattr(n,"tdname");
|
||||
String *unnamed = Getattr(n,"unnamed");
|
||||
String *storage = Getattr(n,"storage");
|
||||
String *kind = Getattr(n,"kind");
|
||||
Node *oldinclass = inclass;
|
||||
List *olist = normalize;
|
||||
Symtab *symtab;
|
||||
String *nname = 0;
|
||||
String *fname = 0;
|
||||
String *scopename = 0;
|
||||
|
||||
normalize = NewList();
|
||||
|
||||
if (name) {
|
||||
|
||||
if (SwigType_istemplate(name)) {
|
||||
// We need to fully resolve the name to make templates work correctly */
|
||||
Node *cn;
|
||||
fname = SwigType_typedef_resolve_all(name);
|
||||
if (Strcmp(fname,name) != 0) {
|
||||
cn = Swig_symbol_clookup_local(fname,0);
|
||||
if ((!cn) || (Strcmp(nodeType(cn),"template") == 0)) {
|
||||
Swig_symbol_cadd(fname,n);
|
||||
SwigType_typedef_class(fname);
|
||||
scopename = Copy(fname);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPE_REDEFINED,Getfile(n),Getline(n),"Template '%s' was already wrapped as '%s' at %s:%d.\n",
|
||||
SwigType_namestr(name), SwigType_namestr(Getattr(cn,"name")), Getfile(cn), Getline(cn));
|
||||
scopename = 0;
|
||||
}
|
||||
} else {
|
||||
Swig_symbol_cadd(fname,n);
|
||||
SwigType_typedef_class(fname);
|
||||
scopename = Copy(fname);
|
||||
}
|
||||
} else {
|
||||
if ((CPlusPlus) || (unnamed)) {
|
||||
SwigType_typedef_class(name);
|
||||
} else {
|
||||
SwigType_typedef_class(NewStringf("%s %s", kind, name));
|
||||
}
|
||||
scopename = Copy(name);
|
||||
}
|
||||
} else {
|
||||
scopename = 0;
|
||||
}
|
||||
|
||||
Setattr(n,"typepass:visit","1");
|
||||
|
||||
/* Need to set up a typedef if unnamed */
|
||||
if (unnamed && tdname && (Cmp(storage,"typedef") == 0)) {
|
||||
SwigType_typedef(unnamed,tdname);
|
||||
}
|
||||
|
||||
if (nsname) {
|
||||
nname = NewStringf("%s::%s", nsname, name);
|
||||
}
|
||||
SwigType_new_scope(scopename);
|
||||
SwigType_attach_symtab(Getattr(n,"symtab"));
|
||||
|
||||
/* Inherit type definitions into the class */
|
||||
if (name) {
|
||||
cplus_inherit_types(n, 0, nname ? nname : (fname ? fname : name));
|
||||
}
|
||||
|
||||
inclass = n;
|
||||
symtab = Swig_symbol_setscope(Getattr(n,"symtab"));
|
||||
emit_children(n);
|
||||
Swig_symbol_setscope(symtab);
|
||||
|
||||
Hash *ts = SwigType_pop_scope();
|
||||
Setattr(n,"typescope",ts);
|
||||
Setattr(n,"module",module);
|
||||
|
||||
/* Normalize deferred types */
|
||||
{
|
||||
normal_node *nn = new normal_node();
|
||||
nn->normallist = normalize;
|
||||
nn->symtab = Getattr(n,"symtab");
|
||||
nn->next = patch_list;
|
||||
nn->typescope = Getattr(n,"typescope");
|
||||
patch_list = nn;
|
||||
}
|
||||
|
||||
normalize = olist;
|
||||
|
||||
inclass = oldinclass;
|
||||
|
||||
/* If in a namespace, patch the class name */
|
||||
if (nname) {
|
||||
Setattr(n,"name",nname);
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* namespaceDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int templateDeclaration(Node *n) {
|
||||
String *name = Getattr(n,"name");
|
||||
String *ttype = Getattr(n,"templatetype");
|
||||
if (Strcmp(ttype,"class") == 0) {
|
||||
String *rname = SwigType_typedef_resolve_all(name);
|
||||
SwigType_typedef_class(rname);
|
||||
Delete(rname);
|
||||
} else if (Strcmp(ttype,"classforward") == 0) {
|
||||
String *rname = SwigType_typedef_resolve_all(name);
|
||||
SwigType_typedef_class(rname);
|
||||
Delete(rname);
|
||||
/* SwigType_typedef_class(name);*/
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* classforwardDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int classforwardDeclaration(Node *n) {
|
||||
|
||||
/* Temporary hack. Can't do inside a class because it breaks
|
||||
C nested structure wrapping */
|
||||
|
||||
if ((!inclass) || (CPlusPlus)) {
|
||||
String *name = Getattr(n,"name");
|
||||
String *nname;
|
||||
SwigType_typedef_class(name);
|
||||
if (nsname) {
|
||||
nname = NewStringf("%s::%s", nsname, name);
|
||||
Setattr(n,"name",nname);
|
||||
}
|
||||
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* namespaceDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int namespaceDeclaration(Node *n) {
|
||||
Symtab *symtab;
|
||||
String *name = Getattr(n,"name");
|
||||
String *alias = Getattr(n,"alias");
|
||||
List *olist = normalize;
|
||||
normalize = NewList();
|
||||
if (alias) {
|
||||
Typetab *ts = Getattr(n,"typescope");
|
||||
if (!ts) {
|
||||
Node *ns;
|
||||
/* Create a empty scope for the alias */
|
||||
ns = Getattr(n,"namespace");
|
||||
if (ns) {
|
||||
SwigType_scope_alias(name, Getattr(ns,"typescope"));
|
||||
}
|
||||
ts = Getattr(ns,"typescope");
|
||||
Setattr(n,"typescope",ts);
|
||||
}
|
||||
/* Namespace alias */
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (name) {
|
||||
Node *nn = Swig_symbol_clookup(name,n);
|
||||
Hash *ts = Getattr(nn,"typescope");
|
||||
if (!ts) {
|
||||
SwigType_new_scope(name);
|
||||
SwigType_attach_symtab(Getattr(n,"symtab"));
|
||||
} else {
|
||||
SwigType_set_scope(ts);
|
||||
}
|
||||
}
|
||||
String *oldnsname = nsname;
|
||||
nsname = Swig_symbol_qualified(Getattr(n,"symtab"));
|
||||
symtab = Swig_symbol_setscope(Getattr(n,"symtab"));
|
||||
emit_children(n);
|
||||
Swig_symbol_setscope(symtab);
|
||||
|
||||
if (name) {
|
||||
Hash *ts = SwigType_pop_scope();
|
||||
Setattr(n,"typescope",ts);
|
||||
}
|
||||
|
||||
/* Normalize deferred types */
|
||||
{
|
||||
normal_node *nn = new normal_node();
|
||||
nn->normallist = normalize;
|
||||
nn->symtab = Getattr(n,"symtab");
|
||||
nn->next = patch_list;
|
||||
nn->typescope = Getattr(n,"typescope");
|
||||
patch_list = nn;
|
||||
}
|
||||
normalize = olist;
|
||||
|
||||
Delete(nsname);
|
||||
nsname = oldnsname;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* cDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int cDeclaration(Node *n) {
|
||||
|
||||
if (NoExcept) {
|
||||
Delattr(n,"throws");
|
||||
}
|
||||
|
||||
/* Search for var args */
|
||||
if (Getattr(n,"feature:varargs")) {
|
||||
ParmList *v = Getattr(n,"feature:varargs");
|
||||
Parm *p = Getattr(n,"parms");
|
||||
Parm *pp = 0;
|
||||
while (p) {
|
||||
SwigType *t = Getattr(p,"type");
|
||||
if (Strcmp(t,"v(...)") == 0) {
|
||||
if (pp) {
|
||||
set_nextSibling(pp,Copy(v));
|
||||
} else {
|
||||
Setattr(n,"parms", Copy(v));
|
||||
}
|
||||
break;
|
||||
}
|
||||
pp = p;
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Normalize types. */
|
||||
SwigType *ty = Getattr(n,"type");
|
||||
normalize_type(ty);
|
||||
SwigType *decl = Getattr(n,"decl");
|
||||
if (decl) {
|
||||
normalize_type(decl);
|
||||
}
|
||||
normalize_parms(Getattr(n,"parms"));
|
||||
normalize_parms(Getattr(n,"throws"));
|
||||
|
||||
if (checkAttribute(n,"storage","typedef")) {
|
||||
String *name = Getattr(n,"name");
|
||||
ty = Getattr(n,"type");
|
||||
decl = Getattr(n,"decl");
|
||||
SwigType *t = Copy(ty);
|
||||
{
|
||||
/* If the typename is qualified, make sure the scopename is fully qualified when making a typedef */
|
||||
if (Swig_scopename_check(t)) {
|
||||
String *base, *prefix, *qprefix;
|
||||
base = Swig_scopename_last(t);
|
||||
prefix = Swig_scopename_prefix(t);
|
||||
qprefix = SwigType_typedef_qualified(prefix);
|
||||
Delete(t);
|
||||
t = NewStringf("%s::%s", qprefix,base);
|
||||
Delete(base);
|
||||
Delete(prefix);
|
||||
Delete(qprefix);
|
||||
}
|
||||
}
|
||||
SwigType_push(t,decl);
|
||||
if (CPlusPlus) {
|
||||
Replaceall(t,"struct ","");
|
||||
Replaceall(t,"union ","");
|
||||
Replaceall(t,"class ","");
|
||||
}
|
||||
SwigType_typedef(t,name);
|
||||
}
|
||||
/* If namespaces are active. We need to patch the name with a namespace prefix */
|
||||
if (nsname && !inclass) {
|
||||
String *name = Getattr(n,"name");
|
||||
if (name) {
|
||||
String *nname = NewStringf("%s::%s", nsname, name);
|
||||
Setattr(n,"name", nname);
|
||||
Delete(nname);
|
||||
}
|
||||
}
|
||||
clean_overloaded(n);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* constructorDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int constructorDeclaration(Node *n) {
|
||||
if (NoExcept) {
|
||||
Delattr(n,"throws");
|
||||
}
|
||||
|
||||
/* Search for var args */
|
||||
if (Getattr(n,"feature:varargs")) {
|
||||
ParmList *v = Getattr(n,"feature:varargs");
|
||||
Parm *p = Getattr(n,"parms");
|
||||
Parm *pp = 0;
|
||||
while (p) {
|
||||
SwigType *t = Getattr(p,"type");
|
||||
if (Strcmp(t,"v(...)") == 0) {
|
||||
if (pp) {
|
||||
set_nextSibling(pp,Copy(v));
|
||||
} else {
|
||||
Setattr(n,"parms", Copy(v));
|
||||
}
|
||||
break;
|
||||
}
|
||||
pp = p;
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
normalize_parms(Getattr(n,"parms"));
|
||||
normalize_parms(Getattr(n,"throws"));
|
||||
|
||||
/* If in a namespace, patch the class name */
|
||||
if (nsname) {
|
||||
String *nname = NewStringf("%s::%s", nsname, Getattr(n,"name"));
|
||||
Setattr(n,"name",nname);
|
||||
}
|
||||
clean_overloaded(n);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* destructorDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int destructorDeclaration(Node *n) {
|
||||
/* If in a namespace, patch the class name */
|
||||
if (nsname) {
|
||||
String *nname = NewStringf("%s::%s", nsname, Getattr(n,"name"));
|
||||
Setattr(n,"name",nname);
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* constantDirective()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int constantDirective(Node *n) {
|
||||
SwigType *ty = Getattr(n,"type");
|
||||
if (ty) {
|
||||
Setattr(n,"type",SwigType_typedef_qualified(ty));
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* enumDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int enumDeclaration(Node *n) {
|
||||
String *name = Getattr(n,"name");
|
||||
if (name) {
|
||||
SwigType *t = NewStringf("enum %s", name);
|
||||
SwigType_typedef(t,name);
|
||||
Delete(t);
|
||||
}
|
||||
emit_children(n);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* enumvalueDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int enumvalueDeclaration(Node *n) {
|
||||
String *name = Getattr(n,"name");
|
||||
String *value = Getattr(n,"value");
|
||||
if (!value) value = name;
|
||||
if (Strcmp(value,name) == 0) {
|
||||
String *new_value;
|
||||
if ((nsname) || (inclass)) {
|
||||
new_value = NewStringf("%s::%s", SwigType_namestr(Swig_symbol_qualified(n)), value);
|
||||
} else {
|
||||
new_value = NewString(value);
|
||||
}
|
||||
Setattr(n,"value",new_value);
|
||||
Delete(new_value);
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* usingDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int usingDeclaration(Node *n) {
|
||||
if (Getattr(n,"namespace")) {
|
||||
/* using namespace id */
|
||||
|
||||
/* For a namespace import. We set up inheritance in the type system */
|
||||
Node *ns = Getattr(n,"node");
|
||||
if (ns) {
|
||||
Typetab *ts = Getattr(ns,"typescope");
|
||||
if (ts) {
|
||||
SwigType_using_scope(ts);
|
||||
}
|
||||
}
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
Node *ns;
|
||||
/* using id */
|
||||
|
||||
if (Getattr(n,"sym:symtab")) {
|
||||
ns = Swig_symbol_clookup(Getattr(n,"uname"), Getattr(n,"sym:symtab"));
|
||||
} else {
|
||||
ns = 0;
|
||||
}
|
||||
if (!ns) {
|
||||
if (!Getattr(n,"access") || ((Strcmp(Getattr(n,"access"),"public") == 0))) {
|
||||
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(n), Getline(n), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(n,"uname")));
|
||||
}
|
||||
} else {
|
||||
|
||||
/* Only a single symbol is being used. There are only a few symbols that
|
||||
we actually care about. These are typedef, class declarations, and enum */
|
||||
|
||||
String *ntype = nodeType(ns);
|
||||
if (Strcmp(ntype,"cdecl") == 0) {
|
||||
if (checkAttribute(ns,"storage","typedef")) {
|
||||
/* A typedef declaration */
|
||||
String *uname = Getattr(n,"uname");
|
||||
SwigType_typedef_using(uname);
|
||||
} else {
|
||||
/* A normal C declaration. */
|
||||
if ((inclass) && (!Getattr(n,"feature:ignore")) && (Getattr(n,"sym:name"))) {
|
||||
Node *c = ns;
|
||||
Node *unodes = 0, *last_unodes = 0;
|
||||
int ccount = 0;
|
||||
String *symname = Getattr(n,"sym:name");
|
||||
while (c) {
|
||||
if (Strcmp(nodeType(c),"cdecl") == 0) {
|
||||
if (!(checkAttribute(c,"storage","static")
|
||||
|| checkAttribute(c,"storage","typedef")
|
||||
|| checkAttribute(c,"storage","friend")
|
||||
|| (Getattr(c,"feature:extend") && !Getattr(c,"code"))
|
||||
|| Getattr(c,"feature:ignore"))) {
|
||||
|
||||
String *csymname = Getattr(c,"sym:name");
|
||||
if (!csymname || (Strcmp(csymname,symname) == 0)) {
|
||||
/* Check for existence in overload list already */
|
||||
{
|
||||
String *decl = Getattr(c,"decl");
|
||||
Node *over = Getattr(n,"sym:overloaded");
|
||||
int match = 0;
|
||||
while (over) {
|
||||
String *odecl = Getattr(over,"decl");
|
||||
if (Cmp(decl, odecl) == 0) {
|
||||
match = 1;
|
||||
break;
|
||||
}
|
||||
over = Getattr(over,"sym:nextSibling");
|
||||
}
|
||||
if (match) {
|
||||
c = Getattr(c,"csym:nextSibling");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Node *nn = copyNode(c);
|
||||
if (!Getattr(nn,"sym:name")) Setattr(nn,"sym:name", symname);
|
||||
|
||||
if (!Getattr(nn,"feature:ignore")) {
|
||||
Setattr(nn,"parms",CopyParmList(Getattr(c,"parms")));
|
||||
ccount++;
|
||||
if (!last_unodes) {
|
||||
last_unodes = nn;
|
||||
unodes = nn;
|
||||
} else {
|
||||
Setattr(nn,"previousSibling",last_unodes);
|
||||
Setattr(last_unodes,"nextSibling", nn);
|
||||
Setattr(nn,"sym:previousSibling", last_unodes);
|
||||
Setattr(last_unodes,"sym:nextSibling", nn);
|
||||
Setattr(nn,"sym:overloaded", unodes);
|
||||
Setattr(unodes,"sym:overloaded", unodes);
|
||||
last_unodes = nn;
|
||||
}
|
||||
} else {
|
||||
Delete(nn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
c = Getattr(c,"csym:nextSibling");
|
||||
}
|
||||
if (unodes) {
|
||||
set_firstChild(n,unodes);
|
||||
if (ccount > 1) {
|
||||
if (!Getattr(n,"sym:overloaded")) {
|
||||
Setattr(n,"sym:overloaded",n);
|
||||
Setattr(n,"sym:overname","_SWIG_0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ((Strcmp(ntype,"class") == 0) || ((Strcmp(ntype,"classforward") == 0))) {
|
||||
/* We install the using class name as kind of a typedef back to the original class */
|
||||
String *uname = Getattr(n,"uname");
|
||||
/* Import into current type scope */
|
||||
SwigType_typedef_using(uname);
|
||||
} else if (Strcmp(ntype,"enum") == 0) {
|
||||
SwigType_typedef_using(Getattr(n,"uname"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* typemapDirective()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int typemapDirective(Node *n) {
|
||||
if (inclass || nsname) {
|
||||
Node *items = firstChild(n);
|
||||
while (items) {
|
||||
Parm *pattern = Getattr(items,"pattern");
|
||||
Parm *parms = Getattr(items,"parms");
|
||||
normalize_later(pattern);
|
||||
normalize_later(parms);
|
||||
items = nextSibling(items);
|
||||
}
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* typemapcopyDirective()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int typemapcopyDirective(Node *n) {
|
||||
if (inclass || nsname) {
|
||||
Node *items = firstChild(n);
|
||||
ParmList *pattern = Getattr(n,"pattern");
|
||||
normalize_later(pattern);
|
||||
while (items) {
|
||||
ParmList *npattern = Getattr(items,"pattern");
|
||||
normalize_later(npattern);
|
||||
items = nextSibling(items);
|
||||
}
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* applyDirective()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int applyDirective(Node *n) {
|
||||
if (inclass || nsname) {
|
||||
ParmList *pattern = Getattr(n,"pattern");
|
||||
normalize_later(pattern);
|
||||
Node *items = firstChild(n);
|
||||
while (items) {
|
||||
Parm *apattern = Getattr(items,"pattern");
|
||||
normalize_later(apattern);
|
||||
items = nextSibling(items);
|
||||
}
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* clearDirective()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int clearDirective(Node *n) {
|
||||
if (inclass || nsname) {
|
||||
Node *p;
|
||||
for (p = firstChild(n); p; p = nextSibling(p)) {
|
||||
ParmList *pattern = Getattr(p,"pattern");
|
||||
normalize_later(pattern);
|
||||
}
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
};
|
||||
|
||||
void Swig_process_types(Node *n) {
|
||||
if (!n) return;
|
||||
TypePass *t = new TypePass;
|
||||
t->top(n);
|
||||
delete t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,318 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* Xml.cxx
|
||||
*
|
||||
* A web-base parse tree Xml 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_xml_cxx[] = "$Header$";
|
||||
static const char *usage = "\
|
||||
XML Options (available with -xml)\n\
|
||||
-xml output.xml - Use output.xml as output file (extension .xml mandatory)\n\
|
||||
-xmllang lang - Typedef language.\n\n";
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
//static Node *view_top = 0;
|
||||
static File *out = 0;
|
||||
|
||||
class XML
|
||||
: public Language
|
||||
{
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
int indent_level;
|
||||
long id;
|
||||
XML()
|
||||
: indent_level( 0 )
|
||||
, id( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~XML()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void main(int argc, char *argv[])
|
||||
{
|
||||
SWIG_typemap_lang("xml");
|
||||
for( int iX = 0; iX < argc; iX++ )
|
||||
{
|
||||
if( strcmp( argv[iX], "-xml" ) == 0 )
|
||||
{
|
||||
char * extension = argv[iX+1]+strlen(argv[iX+1])-4;
|
||||
if( strcmp( extension, ".xml" ) )
|
||||
continue;
|
||||
iX++;
|
||||
Swig_mark_arg (iX);
|
||||
String * outfile = NewString( argv[iX] );
|
||||
out = NewFile(outfile,"w");
|
||||
if (!out)
|
||||
{
|
||||
Printf(stderr,"*** Can't open '%s'\n", outfile);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if( strcmp( argv[iX], "-xmllang" ) == 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Top of the parse tree */
|
||||
|
||||
virtual int top(Node *n)
|
||||
{
|
||||
if( out == 0 )
|
||||
{
|
||||
String *outfile = Getattr(n,"outfile");
|
||||
Replaceall(outfile,"_wrap.cxx", ".xml");
|
||||
out = NewFile(outfile,"w");
|
||||
if (!out)
|
||||
{
|
||||
Printf(stderr,"*** Can't open '%s'\n", outfile);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
Printf( out, "<?xml version=\"1.0\" ?> \n" );
|
||||
Xml_print_tree(n);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void print_indent(int l)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < indent_level; i++)
|
||||
{
|
||||
Printf(out, " ");
|
||||
}
|
||||
if (l)
|
||||
{
|
||||
Printf(out, " ");
|
||||
}
|
||||
}
|
||||
|
||||
void Xml_print_tree(DOH *obj)
|
||||
{
|
||||
while (obj)
|
||||
{
|
||||
Xml_print_node(obj);
|
||||
obj = nextSibling(obj);
|
||||
}
|
||||
}
|
||||
|
||||
void Xml_print_attributes(Node * obj)
|
||||
{
|
||||
String *k;
|
||||
indent_level += 4;
|
||||
print_indent(0);
|
||||
Printf( out, "<attributelist id=\"%ld\" addr=\"%x\" >\n", ++id, obj );
|
||||
indent_level += 4;
|
||||
|
||||
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,"module") == 0)
|
||||
{
|
||||
Xml_print_module( Getattr(obj,k) );
|
||||
}
|
||||
else if (Cmp(k,"baselist") == 0)
|
||||
{
|
||||
Xml_print_baselist( Getattr(obj,k) );
|
||||
}
|
||||
else if (Cmp(k,"typescope") == 0)
|
||||
{
|
||||
Xml_print_typescope( Getattr(obj,k) );
|
||||
}
|
||||
else if (Cmp(k,"typetab") == 0)
|
||||
{
|
||||
Xml_print_typetab( Getattr(obj,k) );
|
||||
}
|
||||
else if (Cmp(k,"kwargs") == 0)
|
||||
{
|
||||
Xml_print_kwargs( Getattr(obj,k) );
|
||||
}
|
||||
else if (Cmp(k,"parms") == 0 || Cmp(k, "pattern") == 0 )
|
||||
{
|
||||
Xml_print_parmlist( Getattr(obj,k) );
|
||||
}
|
||||
else
|
||||
{
|
||||
DOH *o;
|
||||
print_indent(0);
|
||||
if (DohIsString(Getattr(obj,k)))
|
||||
{
|
||||
o = Str(Getattr(obj,k));
|
||||
Replaceall( k, ":", "_" );
|
||||
Replaceall( o, "<", "<" );
|
||||
Replaceall( o, "&", "&" );
|
||||
Replaceall( o, "\"", """ );
|
||||
Replaceall( o, "\\", "\\\\" );
|
||||
Printf(out,"<attribute name=\"%s\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", k, o, ++id, o );
|
||||
Delete(o);
|
||||
}
|
||||
else
|
||||
{
|
||||
o = Getattr(obj,k);
|
||||
Replaceall( k, ":", "_" );
|
||||
Printf(out,"<attribute name=\"%s\" value=\"%x\" id=\"%ld\" addr=\"%x\" />\n", k, o, ++id, o );
|
||||
}
|
||||
}
|
||||
k = Nextkey(obj);
|
||||
}
|
||||
indent_level -= 4;
|
||||
print_indent(0);
|
||||
Printf( out, "</attributelist >\n" );
|
||||
indent_level -= 4;
|
||||
}
|
||||
|
||||
void Xml_print_node(Node *obj)
|
||||
{
|
||||
Node *cobj;
|
||||
|
||||
print_indent(0);
|
||||
Printf(out,"<%s id=\"%ld\" addr=\"%x\" >\n", nodeType(obj), ++id, obj);
|
||||
Xml_print_attributes( obj );
|
||||
cobj = firstChild(obj);
|
||||
if (cobj)
|
||||
{
|
||||
indent_level += 4;
|
||||
Printf(out,"\n");
|
||||
Xml_print_tree(cobj);
|
||||
indent_level -= 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
print_indent(1);
|
||||
Printf(out,"\n");
|
||||
}
|
||||
print_indent(0);
|
||||
Printf(out,"</%s >\n", nodeType(obj));
|
||||
}
|
||||
|
||||
|
||||
void Xml_print_parmlist(ParmList *p)
|
||||
{
|
||||
|
||||
print_indent(0);
|
||||
Printf( out, "<parmlist id=\"%ld\" addr=\"%x\" >\n", ++id, p );
|
||||
indent_level += 4;
|
||||
while(p)
|
||||
{
|
||||
print_indent(0);
|
||||
Printf( out, "<parm id=\"%ld\">\n", ++id );
|
||||
Xml_print_attributes( p );
|
||||
print_indent(0);
|
||||
Printf( out, "</parm >\n" );
|
||||
p = nextSibling(p);
|
||||
}
|
||||
indent_level -= 4;
|
||||
print_indent(0);
|
||||
Printf( out, "</parmlist >\n" );
|
||||
}
|
||||
|
||||
void Xml_print_baselist(List *p)
|
||||
{
|
||||
|
||||
print_indent(0);
|
||||
Printf( out, "<baselist id=\"%ld\" addr=\"%x\" >\n", ++id, p );
|
||||
indent_level += 4;
|
||||
String *s;
|
||||
for (s = Firstitem(p); s; s = Nextitem(p))
|
||||
{
|
||||
print_indent(0);
|
||||
Printf( out, "<base name=\"%s\" id=\"%ld\" addr=\"%x\" />\n", s, ++id, s );
|
||||
}
|
||||
indent_level -= 4;
|
||||
print_indent(0);
|
||||
Printf( out, "</baselist >\n" );
|
||||
}
|
||||
|
||||
void Xml_print_module(Node *p)
|
||||
{
|
||||
|
||||
print_indent(0);
|
||||
Printf( out, "<attribute name=\"module\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", Getattr( p, "name"), ++id, p );
|
||||
}
|
||||
|
||||
void Xml_print_kwargs(Hash *p)
|
||||
{
|
||||
Xml_print_hash( p, "kwargs" );
|
||||
}
|
||||
|
||||
void Xml_print_typescope(Hash *p)
|
||||
{
|
||||
|
||||
Xml_print_hash( p, "typescope" );
|
||||
}
|
||||
|
||||
void Xml_print_typetab(Hash *p)
|
||||
{
|
||||
|
||||
Xml_print_hash( p, "typetab" );
|
||||
}
|
||||
|
||||
|
||||
void Xml_print_hash(Hash *p, const char * markup)
|
||||
{
|
||||
|
||||
print_indent(0);
|
||||
Printf( out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p );
|
||||
Xml_print_attributes( p );
|
||||
indent_level += 4;
|
||||
Node * n = Firstitem( p );
|
||||
while(n)
|
||||
{
|
||||
print_indent(0);
|
||||
Printf( out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n );
|
||||
Xml_print_attributes( n );
|
||||
Printf( out, "</%ssitem >\n", markup );
|
||||
print_indent(0);
|
||||
Printf( out, " />\n" );
|
||||
n = Nextkey(p);
|
||||
}
|
||||
indent_level -= 4;
|
||||
print_indent(0);
|
||||
Printf( out, "</%s >\n", markup );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
Language * swig_xml( void )
|
||||
{
|
||||
return new XML();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue