The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6fcc22a1f8
commit
516036631c
1508 changed files with 125983 additions and 44037 deletions
9
SWIG/Source/CParse/.cvsignore
Normal file
9
SWIG/Source/CParse/.cvsignore
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Makefile
|
||||
.deps
|
||||
parser.c
|
||||
parser.h
|
||||
libcparse.a
|
||||
cscanner.o
|
||||
parser.o
|
||||
y.tab.c
|
||||
y.tab.h
|
||||
69
SWIG/Source/CParse/Makefile.in
Normal file
69
SWIG/Source/CParse/Makefile.in
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#######################################################################
|
||||
# $Header$
|
||||
#######################################################################
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
SHELL = /bin/sh
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@
|
||||
YACC = @YACC@
|
||||
AR = @AR@
|
||||
RANLIB = @RANLIB@
|
||||
|
||||
TARGET = libcparse.a
|
||||
|
||||
OBJS = parser.@OBJEXT@ cscanner.@OBJEXT@ templ.@OBJEXT@ util.@OBJEXT@
|
||||
|
||||
SRCS = cscanner.c templ.c util.c
|
||||
|
||||
PARSER = $(srcdir)/parser.y
|
||||
INCLUDES = -I$(srcdir)/../Include \
|
||||
-I$(srcdir)/. \
|
||||
-I$(srcdir)/../Swig \
|
||||
-I$(srcdir)/../Preprocessor \
|
||||
-I$(srcdir)/../DOH/Include \
|
||||
-I../Include \
|
||||
-I.
|
||||
|
||||
.c.@OBJEXT@:
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c -o $*.@OBJEXT@ $<
|
||||
|
||||
cparse: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
$(AR) cr $(TARGET) $(OBJS)
|
||||
$(RANLIB) $(TARGET)
|
||||
|
||||
parser.@OBJEXT@: parser.c
|
||||
$(CC) $(INCLUDES) $(CFLAGS) $< -c -o parser.@OBJEXT@
|
||||
|
||||
parser.c parser.h: $(PARSER)
|
||||
$(YACC) @YFLAGS@ $(PARSER)
|
||||
@cp y.tab.h parser.h
|
||||
@cp y.tab.c parser.c
|
||||
|
||||
scanner.@OBJEXT@: parser.h
|
||||
|
||||
parser::
|
||||
@cp y.tab.c.bison parser.c
|
||||
@cp y.tab.h.bison parser.h
|
||||
@cp y.tab.h.bison y.tab.h
|
||||
$(CC) $(CFLAGS) parser.c -c -o parser.@OBJEXT@
|
||||
|
||||
clean::
|
||||
rm -f *.@OBJEXT@ $(TARGET) y.tab.c y.tab.h
|
||||
|
||||
nuke::
|
||||
rm -f Makefile *~
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
12
SWIG/Source/CParse/cparse.h
Normal file
12
SWIG/Source/CParse/cparse.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include "swig.h"
|
||||
#include "swigwarn.h"
|
||||
#include "swigver.h"
|
||||
|
||||
extern char *cparse_file;
|
||||
extern int cparse_line;
|
||||
extern int cparse_cplusplus;
|
||||
extern int cparse_start_line;
|
||||
extern void Swig_cparse_replace_descriptor(String *s);
|
||||
extern void Swig_cparse_cplusplus(int);
|
||||
extern void Swig_cparse_debug_templates(int);
|
||||
|
||||
1290
SWIG/Source/CParse/cscanner.c
Normal file
1290
SWIG/Source/CParse/cscanner.c
Normal file
File diff suppressed because it is too large
Load diff
4568
SWIG/Source/CParse/parser.y
Normal file
4568
SWIG/Source/CParse/parser.y
Normal file
File diff suppressed because it is too large
Load diff
495
SWIG/Source/CParse/templ.c
Normal file
495
SWIG/Source/CParse/templ.c
Normal file
|
|
@ -0,0 +1,495 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* templ.c
|
||||
*
|
||||
* Expands a template into a specialized version.
|
||||
*
|
||||
* 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_templ_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
#include "cparse.h"
|
||||
|
||||
static int template_debug = 0;
|
||||
|
||||
static void add_parms(ParmList *p, List *patchlist, List *typelist) {
|
||||
while (p) {
|
||||
SwigType *ty = Getattr(p,"type");
|
||||
SwigType *val = Getattr(p,"value");
|
||||
Append(typelist,ty);
|
||||
Append(patchlist,val);
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
void Swig_cparse_debug_templates(int x) {
|
||||
template_debug = x;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_cparse_template_expand()
|
||||
*
|
||||
* Expands a template node into a specialized version. This is done by
|
||||
* patching typenames and other aspects of the node according to a list of
|
||||
* template parameters
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
cparse_template_expand(Node *n, String *tname, String *rname, String *templateargs, List *patchlist, List *typelist, List *cpatchlist) {
|
||||
static int expanded = 0;
|
||||
int ret;
|
||||
|
||||
if (!n) return 0;
|
||||
if (Getattr(n,"error")) return 0;
|
||||
|
||||
if (Strcmp(nodeType(n),"template") == 0) {
|
||||
/* Change the node type back to normal */
|
||||
if (!expanded) {
|
||||
expanded = 1;
|
||||
set_nodeType(n,Getattr(n,"templatetype"));
|
||||
ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist);
|
||||
expanded = 0;
|
||||
return ret;
|
||||
} else {
|
||||
/* Called when template appears inside another template */
|
||||
/* Member templates */
|
||||
|
||||
set_nodeType(n,Getattr(n,"templatetype"));
|
||||
ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist);
|
||||
set_nodeType(n,"template");
|
||||
return ret;
|
||||
}
|
||||
} else if (Strcmp(nodeType(n),"cdecl") == 0) {
|
||||
/* A simple C declaration */
|
||||
SwigType *t, *v, *d;
|
||||
String *code;
|
||||
t = Getattr(n,"type");
|
||||
v = Getattr(n,"value");
|
||||
d = Getattr(n,"decl");
|
||||
|
||||
code = Getattr(n,"code");
|
||||
|
||||
Append(typelist,t);
|
||||
Append(typelist,d);
|
||||
Append(patchlist,v);
|
||||
Append(cpatchlist,code);
|
||||
|
||||
if (Getattr(n,"conversion_operator")) {
|
||||
Append(cpatchlist, Getattr(n,"name"));
|
||||
if (Getattr(n,"sym:name")) {
|
||||
Append(cpatchlist, Getattr(n,"sym:name"));
|
||||
}
|
||||
}
|
||||
|
||||
add_parms(Getattr(n,"parms"), cpatchlist, typelist);
|
||||
add_parms(Getattr(n,"throws"), cpatchlist, typelist);
|
||||
|
||||
} else if (Strcmp(nodeType(n),"class") == 0) {
|
||||
/* Patch base classes */
|
||||
{
|
||||
List *bases = Getattr(n,"baselist");
|
||||
if (bases) {
|
||||
int i;
|
||||
for (i = 0; i < Len(bases); i++) {
|
||||
String *name = Copy(Getitem(bases,i));
|
||||
Setitem(bases,i,name);
|
||||
Append(typelist,name);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Patch children */
|
||||
{
|
||||
Node *cn = firstChild(n);
|
||||
while (cn) {
|
||||
cparse_template_expand(cn,tname, rname, templateargs, patchlist,typelist,cpatchlist);
|
||||
cn = nextSibling(cn);
|
||||
}
|
||||
}
|
||||
} else if (Strcmp(nodeType(n),"constructor") == 0) {
|
||||
String *name = Getattr(n,"name");
|
||||
if (!(Getattr(n,"templatetype"))) {
|
||||
String *symname;
|
||||
String *stripped_name = SwigType_templateprefix(name);
|
||||
if (Strstr(tname,stripped_name)) {
|
||||
Replaceid(name,stripped_name,tname);
|
||||
}
|
||||
Delete(stripped_name);
|
||||
symname = Getattr(n,"sym:name");
|
||||
if (symname) {
|
||||
stripped_name = SwigType_templateprefix(symname);
|
||||
if (Strstr(tname,stripped_name)) {
|
||||
Replaceid(symname,stripped_name,tname);
|
||||
}
|
||||
Delete(stripped_name);
|
||||
}
|
||||
if (Strstr(name,"<")) {
|
||||
Append(patchlist,Getattr(n,"name"));
|
||||
} else {
|
||||
Append(name,templateargs);
|
||||
}
|
||||
name = Getattr(n,"sym:name");
|
||||
if (name && (Strstr(name,"<"))) {
|
||||
Clear(name);
|
||||
Append(name,rname);
|
||||
} else {
|
||||
Replace(name,tname,rname, DOH_REPLACE_ANY);
|
||||
}
|
||||
Setattr(n,"sym:name",name);
|
||||
}
|
||||
Append(cpatchlist,Getattr(n,"code"));
|
||||
Append(typelist, Getattr(n,"decl"));
|
||||
add_parms(Getattr(n,"parms"), cpatchlist, typelist);
|
||||
add_parms(Getattr(n,"throws"), cpatchlist, typelist);
|
||||
} else if (Strcmp(nodeType(n),"destructor") == 0) {
|
||||
String *name = Getattr(n,"name");
|
||||
if (Strstr(name,"<")) {
|
||||
Append(patchlist,Getattr(n,"name"));
|
||||
} else {
|
||||
Append(name,templateargs);
|
||||
}
|
||||
name = Getattr(n,"sym:name");
|
||||
if (name && Strstr(name,"<")) {
|
||||
Setattr(n,"sym:name", Copy(tname));
|
||||
} else {
|
||||
Replace(name,tname,rname, DOH_REPLACE_ANY);
|
||||
}
|
||||
Setattr(n,"sym:name",name);
|
||||
Append(cpatchlist,Getattr(n,"code"));
|
||||
} else if (Strcmp(nodeType(n),"using") == 0) {
|
||||
String *uname = Getattr(n,"uname");
|
||||
if (uname) {
|
||||
if (Strstr(uname,"<")) {
|
||||
Append(patchlist, uname);
|
||||
}
|
||||
}
|
||||
if (Getattr(n,"namespace")) {
|
||||
/* Namespace link. This is nasty. Is other namespace defined? */
|
||||
|
||||
}
|
||||
} else {
|
||||
/* Look for obvious parameters */
|
||||
Node *cn;
|
||||
Append(cpatchlist,Getattr(n,"code"));
|
||||
Append(typelist, Getattr(n,"type"));
|
||||
Append(typelist, Getattr(n,"decl"));
|
||||
add_parms(Getattr(n,"parms"), cpatchlist, typelist);
|
||||
add_parms(Getattr(n,"pattern"), cpatchlist, typelist);
|
||||
add_parms(Getattr(n,"throws"), cpatchlist, typelist);
|
||||
cn = firstChild(n);
|
||||
while (cn) {
|
||||
cparse_template_expand(cn,tname, rname, templateargs, patchlist, typelist, cpatchlist);
|
||||
cn = nextSibling(cn);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms) {
|
||||
List *patchlist, *cpatchlist, *typelist;
|
||||
String *templateargs;
|
||||
String *tname;
|
||||
String *iname;
|
||||
String *tbase;
|
||||
patchlist = NewList();
|
||||
cpatchlist = NewList();
|
||||
typelist = NewList();
|
||||
|
||||
{
|
||||
String *tmp = NewString("");
|
||||
if (tparms) {
|
||||
SwigType_add_template(tmp,tparms);
|
||||
}
|
||||
templateargs = Copy(tmp);
|
||||
Delete(tmp);
|
||||
}
|
||||
|
||||
tname = Copy(Getattr(n,"name"));
|
||||
tbase = Swig_scopename_last(tname);
|
||||
|
||||
if (0) {
|
||||
Parm *p = tparms;
|
||||
while (p) {
|
||||
Printf(stdout,"tparm: '%s' '%s'\n", Getattr(p,"name"), Getattr(p,"value"));
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
cparse_template_expand(n,tname, rname, templateargs, patchlist, typelist, cpatchlist);
|
||||
|
||||
/* Set the name */
|
||||
{
|
||||
String *name = Getattr(n,"name");
|
||||
if (name) {
|
||||
Append(name,templateargs);
|
||||
}
|
||||
iname = name;
|
||||
}
|
||||
|
||||
/* Patch all of the types */
|
||||
{
|
||||
Parm *tp = Getattr(n,"templateparms");
|
||||
Parm *p = tparms;
|
||||
|
||||
if (tp) {
|
||||
while (p && tp) {
|
||||
String *name, *value, *valuestr, *tydef, *tmp, *tmpr;
|
||||
int sz, i;
|
||||
|
||||
name = Getattr(tp,"name");
|
||||
value = Getattr(p,"value");
|
||||
tydef = Getattr(p,"typedef");
|
||||
if (name) {
|
||||
if (!value) {
|
||||
value = Getattr(p,"type");
|
||||
valuestr = SwigType_str(value,0);
|
||||
} else {
|
||||
valuestr = SwigType_namestr(value);
|
||||
}
|
||||
assert(value);
|
||||
/* Need to patch default arguments */
|
||||
{
|
||||
Parm *rp = nextSibling(p);
|
||||
while (rp) {
|
||||
String *rvalue = Getattr(rp,"value");
|
||||
if (rvalue) {
|
||||
Replace(rvalue,name,value, DOH_REPLACE_ID);
|
||||
}
|
||||
rp = nextSibling(rp);
|
||||
}
|
||||
}
|
||||
sz = Len(patchlist);
|
||||
for (i = 0; i < sz; i++) {
|
||||
String *s = Getitem(patchlist,i);
|
||||
Replace(s,name,value, DOH_REPLACE_ID);
|
||||
}
|
||||
sz = Len(typelist);
|
||||
for (i = 0; i < sz; i++) {
|
||||
String *s = Getitem(typelist,i);
|
||||
Replace(s,name,value, DOH_REPLACE_ID);
|
||||
SwigType_typename_replace(s,tbase,iname);
|
||||
}
|
||||
|
||||
if (!tydef) {
|
||||
tydef = value;
|
||||
}
|
||||
tmp = NewStringf("#%s",name);
|
||||
tmpr = NewStringf("\"%s\"", value);
|
||||
|
||||
sz = Len(cpatchlist);
|
||||
for (i = 0; i < sz; i++) {
|
||||
String *s = Getitem(cpatchlist,i);
|
||||
Replace(s,tmp,tmpr, DOH_REPLACE_ID);
|
||||
/* Replace(s,name,tydef, DOH_REPLACE_ID); */
|
||||
Replace(s,name,valuestr, DOH_REPLACE_ID);
|
||||
}
|
||||
Delete(tmp);
|
||||
Delete(tmpr);
|
||||
Delete(valuestr);
|
||||
}
|
||||
p = nextSibling(p);
|
||||
tp = nextSibling(tp);
|
||||
if (!p) p = tp;
|
||||
}
|
||||
} else {
|
||||
/* No template parameters at all. This could be a specialization */
|
||||
int i, sz;
|
||||
sz = Len(typelist);
|
||||
for (i = 0; i < sz; i++) {
|
||||
String *s = Getitem(typelist,i);
|
||||
SwigType_typename_replace(s,tbase,iname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Patch bases */
|
||||
{
|
||||
List *bases = Getattr(n,"baselist");
|
||||
if (bases) {
|
||||
String *b;
|
||||
for (b = Firstitem(bases); b; b = Nextitem(bases)) {
|
||||
String *qn = Swig_symbol_type_qualify(b,0);
|
||||
Clear(b);
|
||||
Append(b,qn);
|
||||
}
|
||||
}
|
||||
}
|
||||
Delete(patchlist);
|
||||
Delete(cpatchlist);
|
||||
Delete(typelist);
|
||||
Delete(tbase);
|
||||
|
||||
/* set_nodeType(n,"template");*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* cparse_template_locate()
|
||||
*
|
||||
* Search for a template that matches name with given parameters.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
Node *
|
||||
Swig_cparse_template_locate(String *name, Parm *tparms) {
|
||||
Node *n;
|
||||
String *tname, *rname = 0;
|
||||
Node *templ;
|
||||
List *mpartials = 0;
|
||||
Parm *p;
|
||||
Parm *parms;
|
||||
|
||||
tname = NewString(name);
|
||||
parms = CopyParmList(tparms);
|
||||
|
||||
p = parms;
|
||||
while (p) {
|
||||
SwigType *ty = Getattr(p,"type");
|
||||
if (ty) {
|
||||
SwigType *nt = Swig_symbol_typedef_reduce(ty,0);
|
||||
nt = Swig_symbol_type_qualify(nt,0);
|
||||
Setattr(p,"type",nt);
|
||||
}
|
||||
p = nextSibling(p);
|
||||
}
|
||||
|
||||
SwigType_add_template(tname,parms);
|
||||
|
||||
if (template_debug) {
|
||||
Printf(stdout,"\n%s:%d: template_debug: Searching for %s\n", cparse_file, cparse_line, tname);
|
||||
}
|
||||
|
||||
/* Search for an exact specialization.
|
||||
Example: template<> class name<int> { ... } */
|
||||
{
|
||||
if (template_debug) {
|
||||
Printf(stdout," searching: '%s' (exact specialization)\n", tname);
|
||||
}
|
||||
n = Swig_symbol_clookup_local(tname,0);
|
||||
if (n) {
|
||||
Node *tn;
|
||||
if (Strcmp(nodeType(n),"template") == 0) goto success;
|
||||
tn = Getattr(n,"template");
|
||||
if (tn) {
|
||||
n = tn;
|
||||
goto success; /* Previously wrapped by a template return that */
|
||||
}
|
||||
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType(n));
|
||||
Delete(tname);
|
||||
Delete(parms);
|
||||
return 0; /* Found a match, but it's not a template of any kind. */
|
||||
}
|
||||
}
|
||||
|
||||
/* Search for generic template */
|
||||
templ = Swig_symbol_clookup_local(name,0);
|
||||
|
||||
/* Search for partial specialization.
|
||||
Example: template<typename T> class name<T *> { ... } */
|
||||
|
||||
/* Generate reduced template name (stripped of extraneous pointers, etc.) */
|
||||
|
||||
rname = NewStringf("%s<(",name);
|
||||
p = parms;
|
||||
while (p) {
|
||||
String *t;
|
||||
t = Getattr(p,"type");
|
||||
if (t) {
|
||||
String *tbase = SwigType_base(t);
|
||||
t = SwigType_default(t);
|
||||
Replaceid(t,"SWIGTYPE",tbase);
|
||||
Replaceid(t,"SWIGENUM",tbase);
|
||||
Printf(rname,"%s",t);
|
||||
Delete(t);
|
||||
} else {
|
||||
String *v = Getattr(p,"value");
|
||||
Printf(rname,"%s",v);
|
||||
}
|
||||
p = nextSibling(p);
|
||||
if (p) {
|
||||
Printf(rname,",");
|
||||
}
|
||||
}
|
||||
Printf(rname,")>");
|
||||
|
||||
mpartials = NewList();
|
||||
if (templ) {
|
||||
/* First, we search using an exact type prototype */
|
||||
Parm *p;
|
||||
char tmp[32];
|
||||
int i;
|
||||
List *partials;
|
||||
String *s, *ss;
|
||||
|
||||
partials = Getattr(templ,"partials");
|
||||
if (partials) {
|
||||
for (s = Firstitem(partials); s; s= Nextitem(partials)) {
|
||||
ss = Copy(s);
|
||||
p = parms;
|
||||
i = 1;
|
||||
while (p) {
|
||||
String *t,*tn;
|
||||
sprintf(tmp,"$%d",i);
|
||||
t = Getattr(p,"type");
|
||||
if (t) {
|
||||
tn = SwigType_base(t);
|
||||
Replaceid(ss,tmp,tn);
|
||||
Delete(tn);
|
||||
} else {
|
||||
String *v = Getattr(p,"value");
|
||||
Replaceid(ss,tmp,v);
|
||||
}
|
||||
i++;
|
||||
p = nextSibling(p);
|
||||
}
|
||||
if (template_debug) {
|
||||
Printf(stdout," searching: '%s' (partial specialization - %s)\n", ss, s);
|
||||
}
|
||||
if ((Strcmp(ss,tname) == 0) || (Strcmp(ss,rname) == 0)) {
|
||||
Append(mpartials,s);
|
||||
}
|
||||
Delete(ss);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (template_debug) {
|
||||
Printf(stdout," Matched partials: %s\n", mpartials);
|
||||
}
|
||||
|
||||
if (Len(mpartials)) {
|
||||
String *s = Getitem(mpartials,0);
|
||||
n = Swig_symbol_clookup_local(s,0);
|
||||
if (Len(mpartials) > 1) {
|
||||
if (n) {
|
||||
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG,cparse_file,cparse_line,"Instantiation of template %s is ambiguous. Using %s at %s:%d\n",
|
||||
SwigType_namestr(tname), SwigType_namestr(Getattr(n,"name")), Getfile(n),Getline(n));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!n) {
|
||||
n = templ;
|
||||
}
|
||||
if (!n) {
|
||||
Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name);
|
||||
} else if (n && (Strcmp(nodeType(n),"template") != 0)) {
|
||||
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType(n));
|
||||
n = 0;
|
||||
}
|
||||
success:
|
||||
Delete(tname);
|
||||
Delete(rname);
|
||||
Delete(mpartials);
|
||||
if ((template_debug) && (n)) {
|
||||
Printf(stdout,"Node: %x\n", n);
|
||||
Swig_print_node(n);
|
||||
}
|
||||
Delete(parms);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
71
SWIG/Source/CParse/util.c
Normal file
71
SWIG/Source/CParse/util.c
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* util.c
|
||||
*
|
||||
* Parsing utilities
|
||||
*
|
||||
* 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_util_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
extern SwigType *Swig_cparse_type(String *);
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_cparse_replace_descriptor()
|
||||
*
|
||||
* Replaces type descriptor string $descriptor() with the SWIG type descriptor
|
||||
* string.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_cparse_replace_descriptor(String *s) {
|
||||
char tmp[512];
|
||||
String *arg = 0;
|
||||
SwigType *t;
|
||||
|
||||
while (Strstr(s,"$descriptor(")) {
|
||||
char *d = tmp;
|
||||
int level = 0;
|
||||
char *c = Strstr(s,"$descriptor(");
|
||||
while (*c) {
|
||||
if (*c == '(') level++;
|
||||
if (*c == ')') {
|
||||
level--;
|
||||
if (level == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*d = *c;
|
||||
d++;
|
||||
c++;
|
||||
}
|
||||
*d = 0;
|
||||
arg = NewString(tmp+12);
|
||||
t = Swig_cparse_type(arg);
|
||||
Delete(arg);
|
||||
arg = 0;
|
||||
|
||||
if (t) {
|
||||
String *mangle;
|
||||
String *descriptor;
|
||||
|
||||
mangle = SwigType_manglestr(t);
|
||||
descriptor = NewStringf("SWIGTYPE%s",mangle);
|
||||
SwigType_remember(t);
|
||||
*d = ')';
|
||||
d++;
|
||||
*d = 0;
|
||||
Replace(s,tmp,descriptor,DOH_REPLACE_ANY);
|
||||
Delete(mangle);
|
||||
Delete(descriptor);
|
||||
} else {
|
||||
Swig_error(Getfile(s),Getline(s),"Bad $descriptor() macro.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2,3 +2,4 @@ Makefile
|
|||
config.*
|
||||
*.tar.gz
|
||||
configure
|
||||
autom4te.cache
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
# Generated automatically from Makefile.in by configure.
|
||||
#######################################################################
|
||||
# $Header$
|
||||
# DOH
|
||||
#######################################################################
|
||||
|
||||
#.KEEP_STATE:
|
||||
|
||||
# Set your C++ compiler here. g++ works on most machines,
|
||||
# but you might have to change it depending on your installation.
|
||||
#
|
||||
CC = cc
|
||||
prefix = /r0/beazley/Projects
|
||||
|
||||
# Comment out the following line if you're on an SGI or don't have ranlib!
|
||||
RANLIB = ranlib
|
||||
AR = ar
|
||||
|
||||
########################################################################
|
||||
# Normally, you shouldn't have to change anything below this point #
|
||||
########################################################################
|
||||
|
||||
LIBOBJS = callable.o void.o fio.o memory.o base.o file.o list.o hash.o string.o
|
||||
|
||||
LIBSRCS = callable.c void.c fio.c memory.c base.c file.c list.c hash.c string.c
|
||||
|
||||
LIBHEADERS = ../Include/doh.h
|
||||
LIB = ../libdoh.a
|
||||
INCLUDE = -I../Include
|
||||
CFLAGS = -DDOH_STRING_UPDATE_LINES
|
||||
SHELL = /bin/sh
|
||||
|
||||
#
|
||||
# Rules for creation of a .o file from .cxx
|
||||
.SUFFIXES: .c
|
||||
.c.o:
|
||||
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
$(LIB): $(LIBOBJS)
|
||||
@echo "Building library"
|
||||
$(AR) cr $(LIB) $(LIBOBJS)
|
||||
$(RANLIB) $(LIB)
|
||||
|
||||
clean::
|
||||
rm -f *.o ../libdoh.a
|
||||
nuke::
|
||||
rm -f Makefile *~ #* core a.out
|
||||
|
||||
|
|
@ -24,21 +24,21 @@ DOHOPT =
|
|||
# Normally, you shouldn't have to change anything below this point #
|
||||
########################################################################
|
||||
|
||||
LIBOBJS = void.o fio.o memory.o base.o file.o list.o hash.o string.o
|
||||
LIBOBJS = void.@OBJEXT@ fio.@OBJEXT@ memory.@OBJEXT@ base.@OBJEXT@ file.@OBJEXT@ list.@OBJEXT@ hash.@OBJEXT@ string.@OBJEXT@
|
||||
|
||||
LIBSRCS = void.c fio.c memory.c base.c file.c list.c hash.c string.c
|
||||
|
||||
LIBHEADERS = $(srcdir)/../Include/doh.h
|
||||
LIB = libdoh.a
|
||||
INCLUDE = -I$(srcdir)/../Include
|
||||
INCLUDES = -I$(srcdir)/../Include
|
||||
CFLAGS = @CFLAGS@
|
||||
SHELL = /bin/sh
|
||||
|
||||
#
|
||||
# Rules for creation of a .o file from .c
|
||||
# Rules for creation of a .@OBJEXT@ file from .c
|
||||
.SUFFIXES: .c
|
||||
.c.o:
|
||||
$(CC) $(DOHOPT) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
.c.@OBJEXT@:
|
||||
$(CC) $(DOHOPT) $(INCLUDES) $(CFLAGS) -c -o $*.@OBJEXT@ $<
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
|
|
@ -49,6 +49,6 @@ $(LIB): $(LIBOBJS)
|
|||
cp -f $(LIB) ..
|
||||
|
||||
clean::
|
||||
rm -f *.o $(LIB) ../$(LIB)
|
||||
rm -f *.@OBJEXT@ $(LIB) ../$(LIB)
|
||||
nuke::
|
||||
rm -f Makefile *~ #* core a.out
|
||||
rm -f Makefile *~
|
||||
|
|
|
|||
|
|
@ -10,21 +10,10 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_base_c[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
static DohObjInfo *dohtypes[MAX_DOHTYPE];
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohRegisterType()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
DohRegisterType(int type, DohObjInfo *objinfo) {
|
||||
dohtypes[type] = objinfo;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohDelete()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -43,7 +32,7 @@ DohDelete(DOH *obj) {
|
|||
assert(b->refcount > 0);
|
||||
b->refcount--;
|
||||
if (b->refcount <= 0) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_del) {
|
||||
(objinfo->doh_del)(b);
|
||||
} else {
|
||||
|
|
@ -63,9 +52,14 @@ DohCopy(const DOH *obj) {
|
|||
DohObjInfo *objinfo;
|
||||
|
||||
if (!obj) return 0;
|
||||
objinfo = dohtypes[b->type];
|
||||
if (objinfo->doh_copy)
|
||||
return (objinfo->doh_copy)(b);
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_copy) {
|
||||
DohBase *bc = (DohBase *) (objinfo->doh_copy)(b);
|
||||
if ((bc) && b->meta) {
|
||||
bc->meta = Copy(b->meta);
|
||||
}
|
||||
return (DOH *) bc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +75,7 @@ DohIncref(DOH *obj) {
|
|||
void
|
||||
DohClear(DOH *obj) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_clear)
|
||||
(objinfo->doh_clear)(b);
|
||||
}
|
||||
|
|
@ -96,11 +90,11 @@ DohStr(const DOH *obj) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (DohCheck(b)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_str) {
|
||||
return (objinfo->doh_str)(b);
|
||||
}
|
||||
sprintf(buffer,"<Object '%s' at %x>", objinfo->objname, b);
|
||||
sprintf(buffer,"<Object '%s' at %x>", objinfo->objname, (unsigned int)b);
|
||||
return NewString(buffer);
|
||||
} else {
|
||||
return NewString(obj);
|
||||
|
|
@ -114,7 +108,7 @@ DohStr(const DOH *obj) {
|
|||
int
|
||||
DohDump(const DOH *obj, DOH *out) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_dump) {
|
||||
return (objinfo->doh_dump)(b,out);
|
||||
}
|
||||
|
|
@ -130,7 +124,7 @@ DohLen(const DOH *obj) {
|
|||
DohObjInfo *objinfo;
|
||||
if (!b) return 0;
|
||||
if (DohCheck(b)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_len) {
|
||||
return (objinfo->doh_len)(b);
|
||||
}
|
||||
|
|
@ -149,7 +143,7 @@ DohHashval(const DOH *obj) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (DohCheck(b)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_hashval) {
|
||||
return (objinfo->doh_hashval)(b);
|
||||
}
|
||||
|
|
@ -166,7 +160,7 @@ DohData(const DOH *obj) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (DohCheck(obj)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_data) {
|
||||
return (objinfo->doh_data)(b);
|
||||
}
|
||||
|
|
@ -191,8 +185,8 @@ DohCmp(const DOH *obj1, const DOH *obj2) {
|
|||
if (!b1 && b2) return -1;
|
||||
return strcmp((char *) DohData(b1),(char *) DohData(b2));
|
||||
}
|
||||
b1info = dohtypes[b1->type];
|
||||
b2info = dohtypes[b2->type];
|
||||
b1info = b1->type;
|
||||
b2info = b2->type;
|
||||
if ((b1info == b2info) && (b1info->doh_cmp))
|
||||
return (b1info->doh_cmp)(b1,b2);
|
||||
return 1;
|
||||
|
|
@ -206,7 +200,7 @@ DohIsMapping(const DOH *obj) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (!DohCheck(b)) return 0;
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_hash) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
|
@ -218,7 +212,7 @@ DohIsMapping(const DOH *obj) {
|
|||
DOH *
|
||||
DohGetattr(DOH *obj, const DOH *name) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_hash && objinfo->doh_hash->doh_getattr) {
|
||||
return (objinfo->doh_hash->doh_getattr)(b,(DOH *) name);
|
||||
}
|
||||
|
|
@ -232,7 +226,7 @@ DohGetattr(DOH *obj, const DOH *name) {
|
|||
int
|
||||
DohSetattr(DOH *obj, const DOH *name, const DOH *value) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_hash && objinfo->doh_hash->doh_setattr) {
|
||||
return (objinfo->doh_hash->doh_setattr)(b,(DOH *) name,(DOH *) value);
|
||||
}
|
||||
|
|
@ -243,13 +237,14 @@ DohSetattr(DOH *obj, const DOH *name, const DOH *value) {
|
|||
* DohDelattr()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
int
|
||||
DohDelattr(DOH *obj, const DOH *name) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_hash && objinfo->doh_hash->doh_delattr) {
|
||||
(objinfo->doh_hash->doh_delattr)(b,(DOH *) name);
|
||||
return (objinfo->doh_hash->doh_delattr)(b,(DOH *) name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -259,7 +254,7 @@ DohDelattr(DOH *obj, const DOH *name) {
|
|||
DOH *
|
||||
DohFirstkey(DOH *obj) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_hash && objinfo->doh_hash->doh_firstkey) {
|
||||
return (objinfo->doh_hash->doh_firstkey)(b);
|
||||
}
|
||||
|
|
@ -273,13 +268,27 @@ DohFirstkey(DOH *obj) {
|
|||
DOH *
|
||||
DohNextkey(DOH *obj) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo && objinfo->doh_hash->doh_nextkey) {
|
||||
return (objinfo->doh_hash->doh_nextkey)(b);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohNextkey()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
DohKeys(DOH *obj) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo && objinfo->doh_hash->doh_keys) {
|
||||
return (objinfo->doh_hash->doh_keys)(b);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohGetInt()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -388,7 +397,7 @@ DohIsSequence(const DOH *obj) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (!DohCheck(b)) return 0;
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_list) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
|
@ -400,7 +409,7 @@ DohIsSequence(const DOH *obj) {
|
|||
DOH *
|
||||
DohGetitem(DOH *obj, int index) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_list && objinfo->doh_list->doh_getitem) {
|
||||
return (objinfo->doh_list->doh_getitem)(b,index);
|
||||
}
|
||||
|
|
@ -414,7 +423,7 @@ DohGetitem(DOH *obj, int index) {
|
|||
int
|
||||
DohSetitem(DOH *obj, int index, const DOH *value) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_list && objinfo->doh_list->doh_setitem) {
|
||||
return (objinfo->doh_list->doh_setitem)(b,index,(DOH *) value);
|
||||
}
|
||||
|
|
@ -428,7 +437,7 @@ DohSetitem(DOH *obj, int index, const DOH *value) {
|
|||
int
|
||||
DohDelitem(DOH *obj, int index) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_list && objinfo->doh_list->doh_delitem) {
|
||||
return (objinfo->doh_list->doh_delitem)(b,index);
|
||||
}
|
||||
|
|
@ -442,7 +451,7 @@ DohDelitem(DOH *obj, int index) {
|
|||
int
|
||||
DohInsertitem(DOH *obj, int index, const DOH *value) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_list && objinfo->doh_list->doh_insitem) {
|
||||
return (objinfo->doh_list->doh_insitem)(b,index,(DOH *) value);
|
||||
}
|
||||
|
|
@ -456,7 +465,7 @@ DohInsertitem(DOH *obj, int index, const DOH *value) {
|
|||
DOH *
|
||||
DohFirstitem(DOH *obj) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_list && objinfo->doh_list->doh_firstitem) {
|
||||
return (objinfo->doh_list->doh_firstitem)(b);
|
||||
}
|
||||
|
|
@ -470,7 +479,7 @@ DohFirstitem(DOH *obj) {
|
|||
DOH *
|
||||
DohNextitem(DOH *obj) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo = dohtypes[b->type];
|
||||
DohObjInfo *objinfo = b->type;
|
||||
if (objinfo->doh_list && objinfo->doh_list->doh_nextitem) {
|
||||
return (objinfo->doh_list->doh_nextitem)(b);
|
||||
}
|
||||
|
|
@ -486,7 +495,7 @@ DohIsFile(const DOH *obj) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (!DohCheck(b)) return 0;
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_file) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
|
@ -500,7 +509,7 @@ DohRead(DOH *obj, void *buffer, int length) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (DohCheck(obj)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if ((objinfo->doh_file) && (objinfo->doh_file->doh_read)) {
|
||||
return (objinfo->doh_file->doh_read)(b,buffer,length);
|
||||
}
|
||||
|
|
@ -519,7 +528,7 @@ DohWrite(DOH *obj, void *buffer, int length) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (DohCheck(obj)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if ((objinfo->doh_file) && (objinfo->doh_file->doh_write)) {
|
||||
return (objinfo->doh_file->doh_write)(b,buffer,length);
|
||||
}
|
||||
|
|
@ -538,7 +547,7 @@ DohSeek(DOH *obj, long offset, int whence) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (DohCheck(obj)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if ((objinfo->doh_file) && (objinfo->doh_file->doh_seek)) {
|
||||
return (objinfo->doh_file->doh_seek)(b,offset,whence);
|
||||
}
|
||||
|
|
@ -556,7 +565,7 @@ DohTell(DOH *obj) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (DohCheck(obj)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if ((objinfo->doh_file) && (objinfo->doh_file->doh_tell)) {
|
||||
return (objinfo->doh_file->doh_tell)(b);
|
||||
}
|
||||
|
|
@ -575,11 +584,11 @@ DohGetc(DOH *obj) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (obj == lastdoh) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
return (objinfo->doh_file->doh_getc)(b);
|
||||
}
|
||||
if (DohCheck(obj)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_file->doh_getc) {
|
||||
lastdoh = obj;
|
||||
return (objinfo->doh_file->doh_getc)(b);
|
||||
|
|
@ -600,11 +609,11 @@ DohPutc(int ch, DOH *obj) {
|
|||
DohObjInfo *objinfo;
|
||||
|
||||
if (obj == lastdoh) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
return (objinfo->doh_file->doh_putc)(b,ch);
|
||||
}
|
||||
if (DohCheck(obj)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_file->doh_putc) {
|
||||
lastdoh = obj;
|
||||
return (objinfo->doh_file->doh_putc)(b,ch);
|
||||
|
|
@ -623,7 +632,7 @@ DohUngetc(int ch, DOH *obj) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (DohCheck(obj)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_file->doh_ungetc) {
|
||||
return (objinfo->doh_file->doh_ungetc)(b,ch);
|
||||
}
|
||||
|
|
@ -641,7 +650,7 @@ DohClose(DOH *obj) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (DohCheck(obj)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_file->doh_close) {
|
||||
return (objinfo->doh_file->doh_close)(b);
|
||||
}
|
||||
|
|
@ -659,7 +668,7 @@ DohIsString(const DOH *obj) {
|
|||
DohBase *b = (DohBase *) obj;
|
||||
DohObjInfo *objinfo;
|
||||
if (!DohCheck(b)) return 0;
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_string) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
|
@ -672,8 +681,10 @@ int
|
|||
DohReplace(DOH *src, const DOH *token, const DOH *rep, int flags) {
|
||||
DohBase *b = (DohBase *) src;
|
||||
DohObjInfo *objinfo;
|
||||
if (!token) return 0;
|
||||
if (!rep) rep = "";
|
||||
if (DohIsString(src)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_string->doh_replace) {
|
||||
return (objinfo->doh_string->doh_replace)(b,(DOH *) token, (DOH *) rep,flags);
|
||||
}
|
||||
|
|
@ -690,7 +701,7 @@ DohChop(DOH *src) {
|
|||
DohBase *b = (DohBase *) src;
|
||||
DohObjInfo *objinfo;
|
||||
if (DohIsString(src)) {
|
||||
objinfo = dohtypes[b->type];
|
||||
objinfo = b->type;
|
||||
if (objinfo->doh_string->doh_chop) {
|
||||
(objinfo->doh_string->doh_chop)(b);
|
||||
}
|
||||
|
|
@ -705,7 +716,7 @@ DohSetfile(DOH *ho, DOH *file) {
|
|||
DohBase *h = (DohBase *) ho;
|
||||
DohObjInfo *objinfo;
|
||||
if (!h) return;
|
||||
objinfo = dohtypes[h->type];
|
||||
objinfo = h->type;
|
||||
if (objinfo->doh_setfile)
|
||||
(objinfo->doh_setfile)(h,file);
|
||||
}
|
||||
|
|
@ -718,7 +729,7 @@ DohGetfile(DOH *ho) {
|
|||
DohBase *h = (DohBase *) ho;
|
||||
DohObjInfo *objinfo;
|
||||
if (!h) return 0;
|
||||
objinfo = dohtypes[h->type];
|
||||
objinfo = h->type;
|
||||
if (objinfo->doh_getfile)
|
||||
return (objinfo->doh_getfile)(h);
|
||||
return 0;
|
||||
|
|
@ -732,7 +743,7 @@ DohSetline(DOH *ho, int l) {
|
|||
DohBase *h = (DohBase *) ho;
|
||||
DohObjInfo *objinfo;
|
||||
if (!h) return;
|
||||
objinfo = dohtypes[h->type];
|
||||
objinfo = h->type;
|
||||
if (objinfo->doh_setline)
|
||||
(objinfo->doh_setline)(h,l);
|
||||
}
|
||||
|
|
@ -745,12 +756,60 @@ DohGetline(DOH *ho) {
|
|||
DohBase *h = (DohBase *) ho;
|
||||
DohObjInfo *objinfo;
|
||||
if (!h) return 0;
|
||||
objinfo = dohtypes[h->type];
|
||||
objinfo = h->type;
|
||||
if (objinfo->doh_getline)
|
||||
return (objinfo->doh_getline)(h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohGetmeta()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
DohGetmeta(DOH *ho, const DOH *name) {
|
||||
DohBase *h = (DohBase *) ho;
|
||||
if (!DohCheck(ho)) return 0;
|
||||
if (!h->meta) return 0;
|
||||
return DohGetattr(h->meta,name);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohGetmeta()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
DohSetmeta(DOH *ho, const DOH *name, const DOH *value) {
|
||||
DohBase *h = (DohBase *) ho;
|
||||
if (!DohCheck(ho)) return 0;
|
||||
if (!h->meta) h->meta = NewHash();
|
||||
return DohSetattr(h->meta, name, value);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohDelmeta()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
DohDelmeta(DOH *ho, const DOH *name) {
|
||||
DohBase *h = (DohBase *) ho;
|
||||
if (!DohCheck(ho)) return 0;
|
||||
if (!h->meta) return 0;
|
||||
return DohDelattr(h->meta, name);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohSetmark()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
DohSetmark(DOH *ho, int x) {
|
||||
DohBase *h = (DohBase *) ho;
|
||||
h->flag_usermark = x;
|
||||
}
|
||||
|
||||
int
|
||||
DohGetmark(DOH *ho) {
|
||||
DohBase *h = (DohBase *) ho;
|
||||
return h->flag_usermark;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_file_c[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
|
|
@ -41,6 +41,7 @@ DelFile(DOH *fo) {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
DohFree(f);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -118,12 +119,12 @@ File_tell(DOH *fo) {
|
|||
|
||||
static int
|
||||
File_putc(DOH *fo, int ch) {
|
||||
char c;
|
||||
DohFile *f = (DohFile *) ObjData(fo);
|
||||
if (f->filep) {
|
||||
return fputc(ch,f->filep);
|
||||
} else if (f->fd) {
|
||||
#ifdef DOH_INTFILE
|
||||
char c;
|
||||
c = (char) ch;
|
||||
return write(f->fd,&c,1);
|
||||
#endif
|
||||
|
|
@ -137,12 +138,12 @@ File_putc(DOH *fo, int ch) {
|
|||
|
||||
static int
|
||||
File_getc(DOH *fo) {
|
||||
char c;
|
||||
DohFile *f = (DohFile *) ObjData(fo);
|
||||
if (f->filep) {
|
||||
return fgetc(f->filep);
|
||||
} else if (f->fd) {
|
||||
#ifdef DOH_INTFILE
|
||||
char c;
|
||||
if (read(f->fd,&c,1) < 0) return EOF;
|
||||
return c;
|
||||
#endif
|
||||
|
|
@ -169,6 +170,28 @@ File_ungetc(DOH *fo, int ch) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* File_close()
|
||||
*
|
||||
* Close the file
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
File_close(DOH *fo) {
|
||||
int ret = 0;
|
||||
DohFile *f = (DohFile *) ObjData(fo);
|
||||
if (f->filep) {
|
||||
ret = fclose(f->filep);
|
||||
f->filep = 0;
|
||||
} else if (f->fd) {
|
||||
#ifdef DOH_INTFILE
|
||||
ret = close(f->fd);
|
||||
f->fd = 0;
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static DohFileMethods FileFileMethods = {
|
||||
File_read,
|
||||
File_write,
|
||||
|
|
@ -177,7 +200,7 @@ static DohFileMethods FileFileMethods = {
|
|||
File_ungetc,
|
||||
File_seek,
|
||||
File_tell,
|
||||
0, /* close */
|
||||
File_close, /* close */
|
||||
};
|
||||
|
||||
static DohObjInfo DohFileType = {
|
||||
|
|
@ -209,20 +232,13 @@ static DohObjInfo DohFileType = {
|
|||
* Create a new file from a given filename and mode.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int init = 0;
|
||||
|
||||
DOH *
|
||||
NewFile(DOH *fn, char *mode)
|
||||
DohNewFile(DOH *fn, const char *mode)
|
||||
{
|
||||
DohFile *f;
|
||||
FILE *file;
|
||||
char *filename;
|
||||
|
||||
if (!init) {
|
||||
DohRegisterType(DOHTYPE_FILE, &DohFileType);
|
||||
init = 1;
|
||||
}
|
||||
|
||||
filename = Char(fn);
|
||||
file = fopen(filename,mode);
|
||||
if (!file) return 0;
|
||||
|
|
@ -235,7 +251,7 @@ NewFile(DOH *fn, char *mode)
|
|||
f->filep = file;
|
||||
f->fd = 0;
|
||||
f->closeondel = 1;
|
||||
return DohObjMalloc(DOHTYPE_FILE,f);
|
||||
return DohObjMalloc(&DohFileType,f);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -245,20 +261,15 @@ NewFile(DOH *fn, char *mode)
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
NewFileFromFile(FILE *file)
|
||||
DohNewFileFromFile(FILE *file)
|
||||
{
|
||||
DohFile *f;
|
||||
|
||||
if (!init) {
|
||||
DohRegisterType(DOHTYPE_FILE, &DohFileType);
|
||||
init = 1;
|
||||
}
|
||||
f = (DohFile *) DohMalloc(sizeof(DohFile));
|
||||
if (!f) return 0;
|
||||
f->filep = file;
|
||||
f->fd = 0;
|
||||
f->closeondel = 0;
|
||||
return DohObjMalloc(DOHTYPE_FILE,f);
|
||||
return DohObjMalloc(&DohFileType,f);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -268,17 +279,13 @@ NewFileFromFile(FILE *file)
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
NewFileFromFd(int fd)
|
||||
DohNewFileFromFd(int fd)
|
||||
{
|
||||
DohFile *f;
|
||||
if (!init) {
|
||||
DohRegisterType(DOHTYPE_FILE, &DohFileType);
|
||||
init = 1;
|
||||
}
|
||||
f = (DohFile *) DohMalloc(sizeof(DohFile));
|
||||
if (!f) return 0;
|
||||
f->filep = 0;
|
||||
f->fd = fd;
|
||||
f->closeondel = 0;
|
||||
return DohObjMalloc(DOHTYPE_FILE,f);
|
||||
return DohObjMalloc(&DohFileType,f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_fio_c[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
|
|
@ -265,7 +265,7 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
|
|||
doh = va_arg(ap, DOH *);
|
||||
if (DohCheck(doh)) {
|
||||
/* Is a DOH object. */
|
||||
if (DohIsString(doh) && (ObjType(doh) == DOHTYPE_STRING)) {
|
||||
if (DohIsString(doh)) {
|
||||
Sval = doh;
|
||||
} else {
|
||||
Sval = Str(doh);
|
||||
|
|
@ -411,7 +411,7 @@ int DohPrintv(DOHFile *f, ...) {
|
|||
va_start(ap,f);
|
||||
while(1) {
|
||||
obj = va_arg(ap,void *);
|
||||
if (!obj) break;
|
||||
if ((!obj) || (obj == DohNone)) break;
|
||||
if (DohCheck(obj)) {
|
||||
ret += DohDump(obj,f);
|
||||
} else {
|
||||
|
|
@ -459,12 +459,12 @@ DohCopyto(DOH *in, DOH *out) {
|
|||
/* -----------------------------------------------------------------------------
|
||||
* DohSplit()
|
||||
*
|
||||
* Split an input stream into a list of strings delimeted by characters in a
|
||||
* string. Optionally accepts a maximum number of splits to perform.
|
||||
* Split an input stream into a list of strings delimited by the specified
|
||||
* character. Optionally accepts a maximum number of splits to perform.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
DohSplit(DOH *in, char *chs, int nsplits) {
|
||||
DohSplit(DOH *in, char ch, int nsplits) {
|
||||
DOH *list;
|
||||
DOH *str;
|
||||
int c;
|
||||
|
|
@ -479,17 +479,18 @@ DohSplit(DOH *in, char *chs, int nsplits) {
|
|||
str = NewString("");
|
||||
do {
|
||||
c = Getc(in);
|
||||
} while ((c != EOF) && (c == *chs));
|
||||
} while ((c != EOF) && (c == ch));
|
||||
if (c != EOF) {
|
||||
Putc(c,str);
|
||||
while (1) {
|
||||
c = Getc(in);
|
||||
if ((c == EOF) || ((c == *chs) && (nsplits != 0))) break;
|
||||
if ((c == EOF) || ((c == ch) && (nsplits != 0))) break;
|
||||
Putc(c,str);
|
||||
}
|
||||
nsplits--;
|
||||
}
|
||||
Append(list,str);
|
||||
Delete(str);
|
||||
if (c == EOF) break;
|
||||
}
|
||||
return list;
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_hash_c[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
extern DohObjInfo DohHashType;
|
||||
|
||||
/* Hash node */
|
||||
typedef struct HashNode {
|
||||
DOH *key;
|
||||
|
|
@ -46,6 +48,9 @@ static DOH *find_key (DOH *doh_c) {
|
|||
char *c = (char *) doh_c;
|
||||
KeyValue *r, *s;
|
||||
int d = 0;
|
||||
/* OK, sure, we use a binary tree for maintaining interned
|
||||
symbols. Then we use their hash values for accessing secondary
|
||||
hash tables. */
|
||||
r = root;
|
||||
s = 0;
|
||||
while (r) {
|
||||
|
|
@ -199,8 +204,10 @@ Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
|
|||
int hv;
|
||||
HashNode *n, *prev;
|
||||
Hash *h = (Hash *) ObjData(ho);
|
||||
|
||||
if (!obj) return 0;
|
||||
|
||||
if (!obj) {
|
||||
return DohDelattr(ho,k);
|
||||
}
|
||||
if (!DohCheck(k)) k = find_key(k);
|
||||
if (!DohCheck(obj)) {
|
||||
obj = NewString((char *) obj);
|
||||
|
|
@ -211,16 +218,15 @@ Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
|
|||
prev = 0;
|
||||
while (n) {
|
||||
if (Cmp(n->key,k) == 0) {
|
||||
HashNode *nn;
|
||||
if (prev) {
|
||||
prev->next = n->next;
|
||||
} else {
|
||||
h->hashtable[hv] = n->next;
|
||||
/* Node already exists. Just replace its contents */
|
||||
if (n->object == obj) {
|
||||
/* Whoa. Same object. Do nothing */
|
||||
return 1;
|
||||
}
|
||||
nn = n->next;
|
||||
DelNode(n);
|
||||
h->nitems--;
|
||||
n = nn;
|
||||
Delete(n->object);
|
||||
n->object = obj;
|
||||
Incref(obj);
|
||||
return 1; /* Return 1 to indicate a replacement */
|
||||
} else {
|
||||
prev = n;
|
||||
n = n->next;
|
||||
|
|
@ -276,11 +282,17 @@ Hash_delattr(DOH *ho, DOH *k) {
|
|||
while (n) {
|
||||
if (Cmp(n->key, k) == 0) {
|
||||
/* Found it, kill it */
|
||||
|
||||
if (prev) {
|
||||
prev->next = n->next;
|
||||
} else {
|
||||
h->hashtable[hv] = n->next;
|
||||
}
|
||||
/* Need to check for iterator location */
|
||||
if (n == h->current) {
|
||||
h->current = prev; /* Move back to previous node. When next is called, will move to next node */
|
||||
if (!h->current) h->currentindex--; /* No previous node. Move back one slot */
|
||||
}
|
||||
DelNode(n);
|
||||
h->nitems--;
|
||||
return 1;
|
||||
|
|
@ -307,10 +319,12 @@ hash_first(DOH *ho) {
|
|||
static HashNode *
|
||||
hash_next(DOH *ho) {
|
||||
Hash *h = (Hash *) ObjData(ho);
|
||||
if (h->currentindex < 0) return hash_first(h);
|
||||
if (h->currentindex < 0) return hash_first(ho);
|
||||
|
||||
/* Try to move to the next entry */
|
||||
h->current = h->current->next;
|
||||
if (h->current) {
|
||||
h->current = h->current->next;
|
||||
}
|
||||
if (h->current) {
|
||||
return h->current;
|
||||
}
|
||||
|
|
@ -348,6 +362,26 @@ Hash_nextkey(DOH *ho) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Hash_keys(DOH *)
|
||||
*
|
||||
* Return a list of keys
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
Hash_keys(DOH *so) {
|
||||
DOH *keys;
|
||||
DOH *k;
|
||||
|
||||
keys = NewList();
|
||||
k = Firstkey(so);
|
||||
while (k) {
|
||||
Append(keys,k);
|
||||
k = Nextkey(so);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Hash_str()
|
||||
*
|
||||
|
|
@ -397,26 +431,6 @@ Hash_len(DOH *ho) {
|
|||
return h->nitems;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Hash_keys(DOH *)
|
||||
*
|
||||
* Return a list of keys
|
||||
* ----------------------------------------------------------------------------- */
|
||||
DOH *
|
||||
Hash_keys(DOH *so) {
|
||||
DOH *keys;
|
||||
DOH *k;
|
||||
|
||||
keys = NewList();
|
||||
k = Firstkey(so);
|
||||
while (k) {
|
||||
Append(keys,k);
|
||||
k = Nextkey(so);
|
||||
}
|
||||
/* List_sort(keys); */
|
||||
return keys;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* CopyHash()
|
||||
*
|
||||
|
|
@ -444,7 +458,7 @@ CopyHash(DOH *ho) {
|
|||
nh->file = h->file;
|
||||
if (nh->file) Incref(nh->file);
|
||||
|
||||
nho = DohObjMalloc(DOHTYPE_HASH, nh);
|
||||
nho = DohObjMalloc(&DohHashType, nh);
|
||||
for (i = 0; i < h->hashsize; i++) {
|
||||
if ((n = h->hashtable[i])) {
|
||||
while (n) {
|
||||
|
|
@ -458,7 +472,8 @@ CopyHash(DOH *ho) {
|
|||
|
||||
|
||||
|
||||
void Hash_setfile(DOH *ho, DOH *file) {
|
||||
static void
|
||||
Hash_setfile(DOH *ho, DOH *file) {
|
||||
DOH *fo;
|
||||
Hash *h = (Hash *) ObjData(ho);
|
||||
|
||||
|
|
@ -471,17 +486,20 @@ void Hash_setfile(DOH *ho, DOH *file) {
|
|||
h->file = fo;
|
||||
}
|
||||
|
||||
DOH *Hash_getfile(DOH *ho) {
|
||||
static DOH *
|
||||
Hash_getfile(DOH *ho) {
|
||||
Hash *h = (Hash *) ObjData(ho);
|
||||
return h->file;
|
||||
}
|
||||
|
||||
void Hash_setline(DOH *ho, int line) {
|
||||
static void
|
||||
Hash_setline(DOH *ho, int line) {
|
||||
Hash *h = (Hash *) ObjData(ho);
|
||||
h->line = line;
|
||||
}
|
||||
|
||||
int Hash_getline(DOH *ho) {
|
||||
static int
|
||||
Hash_getline(DOH *ho) {
|
||||
Hash *h = (Hash *) ObjData(ho);
|
||||
return h->line;
|
||||
}
|
||||
|
|
@ -496,9 +514,10 @@ static DohHashMethods HashHashMethods = {
|
|||
Hash_delattr,
|
||||
Hash_firstkey,
|
||||
Hash_nextkey,
|
||||
Hash_keys,
|
||||
};
|
||||
|
||||
static DohObjInfo HashType = {
|
||||
DohObjInfo DohHashType = {
|
||||
"Hash", /* objname */
|
||||
DelHash, /* doh_del */
|
||||
CopyHash, /* doh_copy */
|
||||
|
|
@ -528,14 +547,9 @@ static DohObjInfo HashType = {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
NewHash() {
|
||||
DohNewHash() {
|
||||
Hash *h;
|
||||
int i;
|
||||
static int init = 0;
|
||||
if (!init) {
|
||||
DohRegisterType(DOHTYPE_HASH, &HashType);
|
||||
init = 1;
|
||||
}
|
||||
h = (Hash *) DohMalloc(sizeof(Hash));
|
||||
h->hashsize = HASH_INIT_SIZE;
|
||||
h->hashtable = (HashNode **) DohMalloc(h->hashsize*sizeof(HashNode *));
|
||||
|
|
@ -547,6 +561,5 @@ NewHash() {
|
|||
h->nitems = 0;
|
||||
h->file = 0;
|
||||
h->line = 0;
|
||||
return DohObjMalloc(DOHTYPE_HASH,h);
|
||||
return DohObjMalloc(&DohHashType,h);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_list_c[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
|
|
@ -22,6 +22,8 @@ typedef struct List {
|
|||
DOH **items;
|
||||
} List;
|
||||
|
||||
extern DohObjInfo DohListType;
|
||||
|
||||
/* Doubles amount of memory in a list */
|
||||
static
|
||||
void more(List *l) {
|
||||
|
|
@ -52,7 +54,7 @@ CopyList(DOH *lo) {
|
|||
nl->file = l->file;
|
||||
if (nl->file) Incref(nl->file);
|
||||
nl->line = l->line;
|
||||
return DohObjMalloc(DOHTYPE_LIST, nl);
|
||||
return DohObjMalloc(&DohListType, nl);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -261,27 +263,8 @@ List_dump(DOH *lo, DOH *out) {
|
|||
return nsent;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* List_sort()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
static int objcmp(const void *s1, const void *s2) {
|
||||
DOH **so1, **so2;
|
||||
so1 = (DOH **) s1;
|
||||
so2 = (DOH **) s2;
|
||||
return Cmp(*so1,*so2);
|
||||
}
|
||||
|
||||
void
|
||||
List_sort(DOH *lo, int opt) {
|
||||
List *l = (List *) ObjData(lo);
|
||||
qsort(l->items,l->nitems,sizeof(DOH *),objcmp);
|
||||
}
|
||||
|
||||
|
||||
void List_setfile(DOH *lo, DOH *file) {
|
||||
static void
|
||||
List_setfile(DOH *lo, DOH *file) {
|
||||
DOH *fo;
|
||||
List *l = (List *) ObjData(lo);
|
||||
|
||||
|
|
@ -294,17 +277,19 @@ void List_setfile(DOH *lo, DOH *file) {
|
|||
l->file = fo;
|
||||
}
|
||||
|
||||
DOH *List_getfile(DOH *lo) {
|
||||
static DOH *
|
||||
List_getfile(DOH *lo) {
|
||||
List *l = (List *) ObjData(lo);
|
||||
return l->file;
|
||||
}
|
||||
|
||||
void List_setline(DOH *lo, int line) {
|
||||
static void
|
||||
List_setline(DOH *lo, int line) {
|
||||
List *l = (List *) ObjData(lo);
|
||||
l->line = line;
|
||||
}
|
||||
|
||||
int List_getline(DOH *lo) {
|
||||
static int List_getline(DOH *lo) {
|
||||
List *l = (List *) ObjData(lo);
|
||||
return l->line;
|
||||
}
|
||||
|
|
@ -316,10 +301,9 @@ static DohListMethods ListListMethods = {
|
|||
List_insert,
|
||||
List_first,
|
||||
List_next,
|
||||
List_sort
|
||||
};
|
||||
|
||||
static DohObjInfo ListType = {
|
||||
DohObjInfo DohListType = {
|
||||
"List", /* objname */
|
||||
DelList, /* doh_del */
|
||||
CopyList, /* doh_copy */
|
||||
|
|
@ -351,14 +335,9 @@ static DohObjInfo ListType = {
|
|||
#define MAXLISTITEMS 8
|
||||
|
||||
DOH *
|
||||
NewList() {
|
||||
DohNewList() {
|
||||
List *l;
|
||||
int i;
|
||||
static int init = 0;
|
||||
if (!init) {
|
||||
DohRegisterType(DOHTYPE_LIST, &ListType);
|
||||
init = 1;
|
||||
}
|
||||
l = (List *) DohMalloc(sizeof(List));
|
||||
l->nitems = 0;
|
||||
l->maxitems = MAXLISTITEMS;
|
||||
|
|
@ -369,5 +348,6 @@ NewList() {
|
|||
l->iter = 0;
|
||||
l->file = 0;
|
||||
l->line = 0;
|
||||
return DohObjMalloc(DOHTYPE_LIST,l);
|
||||
return DohObjMalloc(&DohListType,l);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_memory_c[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
|
|
@ -30,8 +30,7 @@ typedef struct pool {
|
|||
struct pool *next; /* Next pool */
|
||||
} Pool;
|
||||
|
||||
DohBase *FreeList = 0; /* List of free objects */
|
||||
|
||||
static DohBase *FreeList = 0; /* List of free objects */
|
||||
static Pool *Pools = 0;
|
||||
static int pools_initialized = 0;
|
||||
|
||||
|
|
@ -105,7 +104,7 @@ DohIntern(DOH *obj) {
|
|||
* ---------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
DohObjMalloc(int type, void *data) {
|
||||
DohObjMalloc(DohObjInfo *type, void *data) {
|
||||
DohBase *obj;
|
||||
if (!pools_initialized) InitPools();
|
||||
if (FreeList) {
|
||||
|
|
@ -121,9 +120,12 @@ DohObjMalloc(int type, void *data) {
|
|||
}
|
||||
obj->type = type;
|
||||
obj->data = data;
|
||||
obj->meta = 0;
|
||||
obj->refcount = 1;
|
||||
obj->flag_intern = 0;
|
||||
obj->flag_marked = 0;
|
||||
obj->flag_user = 0;
|
||||
obj->flag_usermark = 0;
|
||||
return (DOH *) obj;
|
||||
}
|
||||
|
||||
|
|
@ -137,6 +139,10 @@ DohObjFree(DOH *ptr) {
|
|||
b = (DohBase *) ptr;
|
||||
if (b->flag_intern) return;
|
||||
b->data = (void *) FreeList;
|
||||
if (b->meta) {
|
||||
Delete(b->meta);
|
||||
b->meta = 0;
|
||||
}
|
||||
b->type = 0;
|
||||
FreeList = b;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,13 +10,11 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_string_c[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
#ifndef DOH_STRING_UPDATE_LINES
|
||||
#define DOH_STRING_UPDATE_LINES
|
||||
#endif
|
||||
extern DohObjInfo DohStringType;
|
||||
|
||||
typedef struct String {
|
||||
DOH *file;
|
||||
|
|
@ -31,7 +29,9 @@ typedef struct String {
|
|||
/* -----------------------------------------------------------------------------
|
||||
* void *String_data() - Return as a 'void *'
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void *String_data(DOH *so) {
|
||||
|
||||
static void *
|
||||
String_data(DOH *so) {
|
||||
String *s = (String *) ObjData(so);
|
||||
s->str[s->len] = 0;
|
||||
return (void *) s->str;
|
||||
|
|
@ -41,7 +41,8 @@ void *String_data(DOH *so) {
|
|||
* int String_dump() - Serialize a string onto out
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int String_dump(DOH *so, DOH *out) {
|
||||
static int
|
||||
String_dump(DOH *so, DOH *out) {
|
||||
int nsent;
|
||||
int ret;
|
||||
String *s = (String *) ObjData(so);
|
||||
|
|
@ -57,32 +58,37 @@ int String_dump(DOH *so, DOH *out) {
|
|||
/* -----------------------------------------------------------------------------
|
||||
* CopyString() - Copy a string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
DOH *
|
||||
|
||||
static DOH *
|
||||
CopyString(DOH *so) {
|
||||
String *s = (String *) ObjData(so);
|
||||
int max;
|
||||
String *str;
|
||||
String *s = (String *) ObjData(so);
|
||||
str = (String *) DohMalloc(sizeof(String));
|
||||
str->hashkey = -1;
|
||||
str->sp = 0;
|
||||
str->sp = s->sp;
|
||||
str->line = s->line;
|
||||
str->file = s->file;
|
||||
if (str->file) Incref(str->file);
|
||||
max = s->maxsize;
|
||||
str->str = (char *) DohMalloc(max);
|
||||
str->str = (char *) DohMalloc(max+1);
|
||||
memmove(str->str, s->str, max);
|
||||
str->maxsize= max;
|
||||
str->len = s->len;
|
||||
str->str[str->len] = 0;
|
||||
return DohObjMalloc(DOHTYPE_STRING,str);
|
||||
|
||||
return DohObjMalloc(&DohStringType,str);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DelString() - Delete a string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
|
||||
static void
|
||||
DelString(DOH *so) {
|
||||
String *s = (String *) ObjData(so);
|
||||
s->hashkey = -1;
|
||||
s->str = 0;
|
||||
DohFree(s->str);
|
||||
DohFree(s);
|
||||
}
|
||||
|
|
@ -91,7 +97,7 @@ DelString(DOH *so) {
|
|||
* String_len() - Length of a string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
static int
|
||||
String_len(DOH *so) {
|
||||
String *s = (String *) ObjData(so);
|
||||
return s->len;
|
||||
|
|
@ -102,7 +108,7 @@ String_len(DOH *so) {
|
|||
* int String_cmp() - Compare two strings
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
static int
|
||||
String_cmp(DOH *so1, DOH *so2)
|
||||
{
|
||||
String *s1, *s2;
|
||||
|
|
@ -130,7 +136,8 @@ String_cmp(DOH *so1, DOH *so2)
|
|||
* int String_hash() - Compute string hash value
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int String_hash(DOH *so) {
|
||||
static int
|
||||
String_hash(DOH *so) {
|
||||
String *s = (String *) ObjData(so);
|
||||
char *c;
|
||||
int i, h = 0, len;
|
||||
|
|
@ -179,43 +186,11 @@ add(String *s, const char *newstr) {
|
|||
s->len += l;
|
||||
}
|
||||
|
||||
/* Add a single character to s */
|
||||
void
|
||||
String_addchar(String *s, char c) {
|
||||
register char *tc;
|
||||
register int len = s->len;
|
||||
register int maxsize = s->maxsize;
|
||||
s->hashkey = -1;
|
||||
if (len > (maxsize-2)) {
|
||||
s->str = (char *) DohRealloc(s->str,2*maxsize);
|
||||
assert(s->str);
|
||||
s->maxsize = 2*maxsize;
|
||||
}
|
||||
tc = s->str;
|
||||
tc[len] = c;
|
||||
if (s->sp >= len) {
|
||||
s->sp = len+1;
|
||||
tc[len+1] = 0;
|
||||
if (c == '\n') s->line++;
|
||||
}
|
||||
s->len++;
|
||||
}
|
||||
|
||||
/* Expand a string to accomodate a write */
|
||||
void
|
||||
String_expand(String *s, int width) {
|
||||
if ((s->len + width) > (s->maxsize-1)) {
|
||||
s->str = (char *) DohRealloc(s->str,(s->len + width)+1);
|
||||
assert(s->str);
|
||||
s->maxsize = s->len + width + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void String_clear() - Clear a string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
static void
|
||||
String_clear(DOH *so)
|
||||
{
|
||||
String *s = (String *) ObjData(so);
|
||||
|
|
@ -230,7 +205,9 @@ String_clear(DOH *so)
|
|||
* void String_insert() - Insert a string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int String_insert(DOH *so, int pos, DOH *str) {
|
||||
static int
|
||||
String_insert(DOH *so, int pos, DOH *str)
|
||||
{
|
||||
String *s = (String *) ObjData(so);
|
||||
char *nstr;
|
||||
int len;
|
||||
|
|
@ -274,7 +251,8 @@ int String_insert(DOH *so, int pos, DOH *str) {
|
|||
* int String_delitem() - Delete a character
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int String_delitem(DOH *so, int pos)
|
||||
static int
|
||||
String_delitem(DOH *so, int pos)
|
||||
{
|
||||
String *s = (String *) ObjData(so);
|
||||
s->hashkey = -1;
|
||||
|
|
@ -297,8 +275,9 @@ int String_delitem(DOH *so, int pos)
|
|||
* DOH *String_str() - Returns a string (used by printing commands)
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
String_str(DOH *so) {
|
||||
static DOH *
|
||||
String_str(DOH *so)
|
||||
{
|
||||
String *s = (String *) ObjData(so);
|
||||
s->str[s->len] = 0;
|
||||
return NewString(s->str);
|
||||
|
|
@ -307,8 +286,10 @@ String_str(DOH *so) {
|
|||
/* -----------------------------------------------------------------------------
|
||||
* int String_read() - Read data from a string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
int
|
||||
String_read(DOH *so, void *buffer, int len) {
|
||||
|
||||
static int
|
||||
String_read(DOH *so, void *buffer, int len)
|
||||
{
|
||||
int reallen, retlen;
|
||||
char *cb;
|
||||
String *s = (String *) ObjData(so);
|
||||
|
|
@ -328,8 +309,9 @@ String_read(DOH *so, void *buffer, int len) {
|
|||
/* -----------------------------------------------------------------------------
|
||||
* int String_write() - Write data to a string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
int
|
||||
String_write(DOH *so, void *buffer, int len) {
|
||||
static int
|
||||
String_write(DOH *so, void *buffer, int len)
|
||||
{
|
||||
int newlen;
|
||||
String *s = (String *) ObjData(so);
|
||||
s->hashkey = -1;
|
||||
|
|
@ -351,8 +333,10 @@ String_write(DOH *so, void *buffer, int len) {
|
|||
/* -----------------------------------------------------------------------------
|
||||
* int String_seek() - Seek to a new position
|
||||
* ----------------------------------------------------------------------------- */
|
||||
int
|
||||
String_seek(DOH *so, long offset, int whence) {
|
||||
|
||||
static int
|
||||
String_seek(DOH *so, long offset, int whence)
|
||||
{
|
||||
int pos, nsp, inc;
|
||||
int prev;
|
||||
String *s = (String *) ObjData(so);
|
||||
|
|
@ -391,8 +375,10 @@ String_seek(DOH *so, long offset, int whence) {
|
|||
/* -----------------------------------------------------------------------------
|
||||
* long String_tell() - Return current position
|
||||
* ----------------------------------------------------------------------------- */
|
||||
long
|
||||
String_tell(DOH *so) {
|
||||
|
||||
static long
|
||||
String_tell(DOH *so)
|
||||
{
|
||||
String *s = (String *) ObjData(so);
|
||||
return (long) (s->sp);
|
||||
}
|
||||
|
|
@ -401,8 +387,9 @@ String_tell(DOH *so) {
|
|||
* int String_putc()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
String_putc(DOH *so, int ch) {
|
||||
static int
|
||||
String_putc(DOH *so, int ch)
|
||||
{
|
||||
register int len, maxsize, sp;
|
||||
String *s = (String *) ObjData(so);
|
||||
s->hashkey = -1;
|
||||
|
|
@ -435,7 +422,9 @@ String_putc(DOH *so, int ch) {
|
|||
* int String_getc()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int String_getc(DOH *so) {
|
||||
static int
|
||||
String_getc(DOH *so)
|
||||
{
|
||||
int c;
|
||||
String *s = (String *) ObjData(so);
|
||||
if (s->sp >= s->len)
|
||||
|
|
@ -450,7 +439,9 @@ int String_getc(DOH *so) {
|
|||
* int String_ungetc()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int String_ungetc(DOH *so, int ch) {
|
||||
static int
|
||||
String_ungetc(DOH *so, int ch)
|
||||
{
|
||||
String *s = (String *) ObjData(so);
|
||||
if (ch == EOF) return ch;
|
||||
if (s->sp <= 0) return EOF;
|
||||
|
|
@ -466,7 +457,9 @@ int String_ungetc(DOH *so, int ch) {
|
|||
* Replaces count non-overlapping occurrences of token with rep in a string.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char *end_quote(char *s) {
|
||||
static char *
|
||||
end_quote(char *s)
|
||||
{
|
||||
char qc;
|
||||
char *q;
|
||||
qc = *s;
|
||||
|
|
@ -478,11 +471,15 @@ static char *end_quote(char *s) {
|
|||
}
|
||||
}
|
||||
|
||||
static char *match_simple(char *base, char *s, char *token, int tokenlen) {
|
||||
static char *
|
||||
match_simple(char *base, char *s, char *token, int tokenlen)
|
||||
{
|
||||
return strstr(s,token);
|
||||
}
|
||||
|
||||
static char *match_identifier(char *base, char *s, char *token, int tokenlen) {
|
||||
static char *
|
||||
match_identifier(char *base, char *s, char *token, int tokenlen)
|
||||
{
|
||||
while (s) {
|
||||
s = strstr(s,token);
|
||||
if (!s) return 0;
|
||||
|
|
@ -499,8 +496,8 @@ static char *match_identifier(char *base, char *s, char *token, int tokenlen) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int replace_simple(String *str, char *token, char *rep, int flags, int count, char *(*match)(char *, char *, char *, int))
|
||||
static int
|
||||
replace_simple(String *str, char *token, char *rep, int flags, int count, char *(*match)(char *, char *, char *, int))
|
||||
{
|
||||
int tokenlen; /* Length of the token */
|
||||
int replen; /* Length of the replacement */
|
||||
|
|
@ -513,7 +510,10 @@ int replace_simple(String *str, char *token, char *rep, int flags, int count, ch
|
|||
register char *base;
|
||||
int i;
|
||||
|
||||
str->hashkey = -1;
|
||||
|
||||
/* Figure out if anything gets replaced */
|
||||
if (!strlen(token)) return 0;
|
||||
|
||||
base = str->str;
|
||||
tokenlen = strlen(token);
|
||||
|
|
@ -706,11 +706,12 @@ int replace_simple(String *str, char *token, char *rep, int flags, int count, ch
|
|||
* int String_replace()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
static int
|
||||
String_replace(DOH *stro, DOH *token, DOH *rep, int flags)
|
||||
{
|
||||
int count = -1;
|
||||
String *str = (String *) ObjData(stro);
|
||||
|
||||
if (flags & DOH_REPLACE_FIRST) count = 1;
|
||||
|
||||
if (flags & DOH_REPLACE_ID) {
|
||||
|
|
@ -724,8 +725,9 @@ String_replace(DOH *stro, DOH *token, DOH *rep, int flags)
|
|||
* void String_chop(DOH *str)
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
String_chop(DOH *so) {
|
||||
static void
|
||||
String_chop(DOH *so)
|
||||
{
|
||||
char *c;
|
||||
String *str = (String *) ObjData(so);
|
||||
/* Replace trailing whitespace */
|
||||
|
|
@ -743,7 +745,9 @@ String_chop(DOH *so) {
|
|||
str->hashkey = -1;
|
||||
}
|
||||
|
||||
void String_setfile(DOH *so, DOH *file) {
|
||||
static void
|
||||
String_setfile(DOH *so, DOH *file)
|
||||
{
|
||||
DOH *fo;
|
||||
String *str = (String *) ObjData(so);
|
||||
|
||||
|
|
@ -756,17 +760,23 @@ void String_setfile(DOH *so, DOH *file) {
|
|||
str->file = fo;
|
||||
}
|
||||
|
||||
DOH *String_getfile(DOH *so) {
|
||||
static DOH *
|
||||
String_getfile(DOH *so)
|
||||
{
|
||||
String *str = (String *) ObjData(so);
|
||||
return str->file;
|
||||
}
|
||||
|
||||
void String_setline(DOH *so, int line) {
|
||||
static void
|
||||
String_setline(DOH *so, int line)
|
||||
{
|
||||
String *str = (String *) ObjData(so);
|
||||
str->line = line;
|
||||
}
|
||||
|
||||
int String_getline(DOH *so) {
|
||||
static int
|
||||
String_getline(DOH *so)
|
||||
{
|
||||
String *str = (String *) ObjData(so);
|
||||
return str->line;
|
||||
}
|
||||
|
|
@ -778,7 +788,6 @@ static DohListMethods StringListMethods = {
|
|||
String_insert, /* doh_insitem */
|
||||
0, /* doh_first */
|
||||
0, /* doh_next */
|
||||
0, /* doh_sort */
|
||||
};
|
||||
|
||||
static DohFileMethods StringFileMethods = {
|
||||
|
|
@ -797,7 +806,7 @@ static DohStringMethods StringStringMethods = {
|
|||
String_chop,
|
||||
};
|
||||
|
||||
static DohObjInfo StringType = {
|
||||
DohObjInfo DohStringType = {
|
||||
"String", /* objname */
|
||||
DelString, /* doh_del */
|
||||
CopyString, /* doh_copy */
|
||||
|
|
@ -823,21 +832,16 @@ static DohObjInfo StringType = {
|
|||
|
||||
#define INIT_MAXSIZE 16
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewString(const char *c) - Create a new string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOHString *
|
||||
NewString(const DOH *so)
|
||||
DohNewString(const DOH *so)
|
||||
{
|
||||
int l = 0, max;
|
||||
String *str;
|
||||
char *s;
|
||||
static int init = 0;
|
||||
if (!init) {
|
||||
DohRegisterType(DOHTYPE_STRING, &StringType);
|
||||
init = 1;
|
||||
}
|
||||
if (DohCheck(so)) s = Char(so);
|
||||
else s = (char *) so;
|
||||
str = (String *) DohMalloc(sizeof(String));
|
||||
|
|
@ -860,7 +864,7 @@ NewString(const DOH *so)
|
|||
str->str[0] = 0;
|
||||
str->len = 0;
|
||||
}
|
||||
return DohObjMalloc(DOHTYPE_STRING,str);
|
||||
return DohObjMalloc(&DohStringType,str);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -870,7 +874,7 @@ NewString(const DOH *so)
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOHString *
|
||||
NewStringf(const DOH *fmt, ...)
|
||||
DohNewStringf(const DOH *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
DOH *r;
|
||||
|
|
@ -880,3 +884,28 @@ NewStringf(const DOH *fmt, ...)
|
|||
va_end(ap);
|
||||
return (DOHString *) r;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Strcmp()
|
||||
* Strncmp()
|
||||
* Strstr()
|
||||
* Strchr()
|
||||
*
|
||||
* Some utility functions.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2) {
|
||||
return strcmp(Char(s1),Char(s2));
|
||||
}
|
||||
|
||||
int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n) {
|
||||
return strncmp(Char(s1),Char(s2),n);
|
||||
}
|
||||
|
||||
char *DohStrstr(const DOHString_or_char *s1, const DOHString_or_char *s2) {
|
||||
return strstr(Char(s1),Char(s2));
|
||||
}
|
||||
|
||||
char *DohStrchr(const DOHString_or_char *s1, int ch) {
|
||||
return strchr(Char(s1),ch);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_void_c[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
|
|
@ -88,15 +88,10 @@ static DohObjInfo DohVoidType = {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
NewVoid(void *obj, void (*del)(void *)) {
|
||||
static int init = 0;
|
||||
DohNewVoid(void *obj, void (*del)(void *)) {
|
||||
VoidObj *v;
|
||||
if (!init) {
|
||||
DohRegisterType(DOHTYPE_VOID, &DohVoidType);
|
||||
init = 1;
|
||||
}
|
||||
v = (VoidObj *) DohMalloc(sizeof(VoidObj));
|
||||
v->ptr = obj;
|
||||
v->del = del;
|
||||
return DohObjMalloc(DOHTYPE_VOID,v);
|
||||
return DohObjMalloc(&DohVoidType,v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,105 @@
|
|||
#ifndef _DOH_H
|
||||
#define _DOH_H
|
||||
|
||||
/* Set the namespace prefix for DOH API functions. This can be used to control
|
||||
visibility of the functions in libraries */
|
||||
|
||||
/* Set this macro if you want to change DOH linkage. You would do this if you
|
||||
wanted to hide DOH in a library using a different set of names. Note: simply
|
||||
change "Doh" to a new name. */
|
||||
|
||||
/*
|
||||
#define DOH_NAMESPACE(x) Doh ## x
|
||||
*/
|
||||
|
||||
#ifdef DOH_NAMESPACE
|
||||
|
||||
/* Namespace control. These macros define all of the public API names in DOH */
|
||||
|
||||
#define DohCheck DOH_NAMESPACE(Check)
|
||||
#define DohIntern DOH_NAMESPACE(Intern)
|
||||
#define DohDelete DOH_NAMESPACE(Delete)
|
||||
#define DohCopy DOH_NAMESPACE(Copy)
|
||||
#define DohClear DOH_NAMESPACE(Clear)
|
||||
#define DohStr DOH_NAMESPACE(Str)
|
||||
#define DohData DOH_NAMESPACE(Data)
|
||||
#define DohDump DOH_NAMESPACE(Dump)
|
||||
#define DohLen DOH_NAMESPACE(Len)
|
||||
#define DohHashval DOH_NAMESPACE(Hashval)
|
||||
#define DohCmp DOH_NAMESPACE(Cmp)
|
||||
#define DohIncref DOH_NAMESPACE(Incref)
|
||||
#define DohGetattr DOH_NAMESPACE(Getattr)
|
||||
#define DohSetattr DOH_NAMESPACE(Setattr)
|
||||
#define DohDelattr DOH_NAMESPACE(Delattr)
|
||||
#define DohFirstkey DOH_NAMESPACE(Firstkey)
|
||||
#define DohNextkey DOH_NAMESPACE(Nextkey)
|
||||
#define DohKeys DOH_NAMESPACE(Keys)
|
||||
#define DohGetInt DOH_NAMESPACE(GetInt)
|
||||
#define DohGetDouble DOH_NAMESPACE(GetDouble)
|
||||
#define DohGetChar DOH_NAMESPACE(GetChar)
|
||||
#define DohSetChar DOH_NAMESPACE(SetChar)
|
||||
#define DohSetInt DOH_NAMESPACE(SetInt)
|
||||
#define DohSetDouble DOH_NAMESPACE(SetDouble)
|
||||
#define DohSetVoid DOH_NAMESPACE(SetVoid)
|
||||
#define DohGetVoid DOH_NAMESPACE(GetVoid)
|
||||
#define DohGetitem DOH_NAMESPACE(Getitem)
|
||||
#define DohSetitem DOH_NAMESPACE(Setitem)
|
||||
#define DohDelitem DOH_NAMESPACE(Delitem)
|
||||
#define DohInsertitem DOH_NAMESPACE(Insertitem)
|
||||
#define DohFirstitem DOH_NAMESPACE(Firstitem)
|
||||
#define DohNextitem DOH_NAMESPACE(Nextitem)
|
||||
#define DohWrite DOH_NAMESPACE(Write)
|
||||
#define DohRead DOH_NAMESPACE(Read)
|
||||
#define DohSeek DOH_NAMESPACE(Seek)
|
||||
#define DohTell DOH_NAMESPACE(Tell)
|
||||
#define DohGetc DOH_NAMESPACE(Getc)
|
||||
#define DohPutc DOH_NAMESPACE(Putc)
|
||||
#define DohUngetc DOH_NAMESPACE(Ungetc)
|
||||
#define DohGetline DOH_NAMESPACE(Getline)
|
||||
#define DohSetline DOH_NAMESPACE(Setline)
|
||||
#define DohGetfile DOH_NAMESPACE(Getfile)
|
||||
#define DohSetfile DOH_NAMESPACE(Setfile)
|
||||
#define DohReplace DOH_NAMESPACE(Replace)
|
||||
#define DohChop DOH_NAMESPACE(Chop)
|
||||
#define DohGetmeta DOH_NAMESPACE(Getmeta)
|
||||
#define DohSetmeta DOH_NAMESPACE(Setmeta)
|
||||
#define DohDelmeta DOH_NAMESPACE(Delmeta)
|
||||
#define DohEncoding DOH_NAMESPACE(Encoding)
|
||||
#define DohPrintf DOH_NAMESPACE(Printf)
|
||||
#define DohvPrintf DOH_NAMESPACE(vPrintf)
|
||||
#define DohPrintv DOH_NAMESPACE(Printv)
|
||||
#define DohReadline DOH_NAMESPACE(Readline)
|
||||
#define DohIsMapping DOH_NAMESPACE(IsMapping)
|
||||
#define DohIsSequence DOH_NAMESPACE(IsSequence)
|
||||
#define DohIsString DOH_NAMESPACE(IsString)
|
||||
#define DohIsFile DOH_NAMESPACE(IsFile)
|
||||
#define DohNewString DOH_NAMESPACE(NewString)
|
||||
#define DohNewStringf DOH_NAMESPACE(NewStringf)
|
||||
#define DohStrcmp DOH_NAMESPACE(Strcmp)
|
||||
#define DohStrncmp DOH_NAMESPACE(Strncmp)
|
||||
#define DohStrstr DOH_NAMESPACE(Strstr)
|
||||
#define DohStrchr DOH_NAMESPACE(Strchr)
|
||||
#define DohNewFile DOH_NAMESPACE(NewFile)
|
||||
#define DohNewFileFromFile DOH_NAMESPACE(NewFileFromFile)
|
||||
#define DohNewFileFromFd DOH_NAMESPACE(NewFileFromFd)
|
||||
#define DohClose DOH_NAMESPACE(Close)
|
||||
#define DohCopyto DOH_NAMESPACE(Copyto)
|
||||
#define DohNewList DOH_NAMESPACE(NewList)
|
||||
#define DohNewHash DOH_NAMESPACE(NewHash)
|
||||
#define DohNewVoid DOH_NAMESPACE(NewVoid)
|
||||
#define DohSplit DOH_NAMESPACE(Split)
|
||||
#define DohNone DOH_NAMESPACE(None)
|
||||
|
||||
#define DohObjMalloc DOH_NAMESPACE(ObjMalloc)
|
||||
#define DohObjFree DOH_NAMESPACE(ObjFree)
|
||||
#define DohStringType DOH_NAMESPACE(StringType)
|
||||
#define DohListType DOH_NAMESPACE(ListType)
|
||||
#define DohHashType DOH_NAMESPACE(HashType)
|
||||
#define DohFileType DOH_NAMESPACE(FileType)
|
||||
#define DohVoidType DOH_NAMESPACE(VoidType)
|
||||
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
|
@ -53,8 +152,8 @@ typedef void DOH;
|
|||
#define DohFree free
|
||||
#endif
|
||||
|
||||
extern int DohCheck(const DOH *ptr); /* Check if a DOH object */
|
||||
extern void DohIntern(DOH *); /* Intern an object */
|
||||
extern int DohCheck(const DOH *ptr); /* Check if a DOH object */
|
||||
extern void DohIntern(DOH *); /* Intern an object */
|
||||
|
||||
/* Basic object methods. Common to most objects */
|
||||
|
||||
|
|
@ -71,64 +170,126 @@ extern void DohIncref(DOH *obj);
|
|||
|
||||
/* Mapping methods */
|
||||
|
||||
extern DOH *DohGetattr(DOH *obj, const DOHString_or_char *name);
|
||||
extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_char *value);
|
||||
extern void DohDelattr(DOH *obj, const DOHString_or_char *name);
|
||||
extern DOH *DohFirstkey(DOH *obj);
|
||||
extern DOH *DohNextkey(DOH *obj);
|
||||
extern int DohGetInt(DOH *obj, const DOHString_or_char *name);
|
||||
extern double DohGetDouble(DOH *obj, const DOHString_or_char *name);
|
||||
extern char *DohGetChar(DOH *obj, const DOHString_or_char *name);
|
||||
extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int);
|
||||
extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double);
|
||||
extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name);
|
||||
extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value);
|
||||
extern DOH *DohGetattr(DOH *obj, const DOHString_or_char *name);
|
||||
extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_char *value);
|
||||
extern int DohDelattr(DOH *obj, const DOHString_or_char *name);
|
||||
extern DOH *DohFirstkey(DOH *obj);
|
||||
extern DOH *DohNextkey(DOH *obj);
|
||||
extern DOH *DohKeys(DOH *obj);
|
||||
extern int DohGetInt(DOH *obj, const DOHString_or_char *name);
|
||||
extern double DohGetDouble(DOH *obj, const DOHString_or_char *name);
|
||||
extern char *DohGetChar(DOH *obj, const DOHString_or_char *name);
|
||||
extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int);
|
||||
extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double);
|
||||
extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name);
|
||||
extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value);
|
||||
|
||||
/* Sequence methods */
|
||||
|
||||
extern DOH *DohGetitem(DOH *obj, int index);
|
||||
extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char *value);
|
||||
extern int DohDelitem(DOH *obj, int index);
|
||||
extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char *value);
|
||||
extern DOH *DohFirstitem(DOH *obj);
|
||||
extern DOH *DohNextitem(DOH *obj);
|
||||
extern DOH *DohGetitem(DOH *obj, int index);
|
||||
extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char *value);
|
||||
extern int DohDelitem(DOH *obj, int index);
|
||||
extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char *value);
|
||||
extern DOH *DohFirstitem(DOH *obj);
|
||||
extern DOH *DohNextitem(DOH *obj);
|
||||
|
||||
/* File methods */
|
||||
|
||||
extern int DohWrite(DOHFile *obj, void *buffer, int length);
|
||||
extern int DohRead(DOHFile *obj, void *buffer, int length);
|
||||
extern int DohSeek(DOHFile *obj, long offset, int whence);
|
||||
extern long DohTell(DOHFile *obj);
|
||||
extern int DohGetc(DOHFile *obj);
|
||||
extern int DohPutc(int ch, DOHFile *obj);
|
||||
extern int DohUngetc(int ch, DOHFile *obj);
|
||||
extern int DohWrite(DOHFile *obj, void *buffer, int length);
|
||||
extern int DohRead(DOHFile *obj, void *buffer, int length);
|
||||
extern int DohSeek(DOHFile *obj, long offset, int whence);
|
||||
extern long DohTell(DOHFile *obj);
|
||||
extern int DohGetc(DOHFile *obj);
|
||||
extern int DohPutc(int ch, DOHFile *obj);
|
||||
extern int DohUngetc(int ch, DOHFile *obj);
|
||||
|
||||
/* Positional */
|
||||
|
||||
extern int DohGetline(DOH *obj);
|
||||
extern void DohSetline(DOH *obj, int line);
|
||||
extern DOH *DohGetfile(DOH *obj);
|
||||
extern void DohSetfile(DOH *obj, DOH *file);
|
||||
extern int DohGetline(DOH *obj);
|
||||
extern void DohSetline(DOH *obj, int line);
|
||||
extern DOH *DohGetfile(DOH *obj);
|
||||
extern void DohSetfile(DOH *obj, DOH *file);
|
||||
|
||||
/* String Methods */
|
||||
|
||||
extern int DohReplace(DOHString *src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags);
|
||||
extern void DohChop(DOHString *src);
|
||||
extern int DohReplace(DOHString *src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags);
|
||||
extern void DohChop(DOHString *src);
|
||||
|
||||
/* Meta-variables */
|
||||
extern DOH *DohGetmeta(DOH *, const DOH *);
|
||||
extern int DohSetmeta(DOH *, const DOH *, const DOH *value);
|
||||
extern int DohDelmeta(DOH *, const DOH *);
|
||||
|
||||
/* Utility functions */
|
||||
|
||||
extern void DohEncoding(char *name, DOH *(*fn)(DOH *s));
|
||||
extern int DohPrintf(DOHFile *obj, const char *format, ...);
|
||||
extern int DohvPrintf(DOHFile *obj, const char *format, va_list ap);
|
||||
extern int DohPrintv(DOHFile *obj, ...);
|
||||
extern DOH *DohReadline(DOHFile *in);
|
||||
extern void DohEncoding(char *name, DOH *(*fn)(DOH *s));
|
||||
extern int DohPrintf(DOHFile *obj, const char *format, ...);
|
||||
extern int DohvPrintf(DOHFile *obj, const char *format, va_list ap);
|
||||
extern int DohPrintv(DOHFile *obj, ...);
|
||||
extern DOH *DohReadline(DOHFile *in);
|
||||
|
||||
/* Miscellaneous */
|
||||
|
||||
extern int DohIsMapping(const DOH *obj);
|
||||
extern int DohIsSequence(const DOH *obj);
|
||||
extern int DohIsString(const DOH *obj);
|
||||
extern int DohIsFile(const DOH *obj);
|
||||
extern int DohIsMapping(const DOH *obj);
|
||||
extern int DohIsSequence(const DOH *obj);
|
||||
extern int DohIsString(const DOH *obj);
|
||||
extern int DohIsFile(const DOH *obj);
|
||||
|
||||
extern void DohSetmark(DOH *obj, int x);
|
||||
extern int DohGetmark(DOH *obj);
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Strings.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOHString *DohNewString(const DOH *c);
|
||||
extern DOHString *DohNewStringf(const DOH *fmt, ...);
|
||||
|
||||
extern int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2);
|
||||
extern int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n);
|
||||
extern char *DohStrstr(const DOHString_or_char *s1, const DOHString_or_char *s2);
|
||||
extern char *DohStrchr(const DOHString_or_char *s1, int ch);
|
||||
|
||||
/* String replacement flags */
|
||||
|
||||
#define DOH_REPLACE_ANY 0x01
|
||||
#define DOH_REPLACE_NOQUOTE 0x02
|
||||
#define DOH_REPLACE_ID 0x04
|
||||
#define DOH_REPLACE_FIRST 0x08
|
||||
|
||||
#define Replaceall(s,t,r) DohReplace(s,t,r,DOH_REPLACE_ANY)
|
||||
#define Replaceid(s,t,r) DohReplace(s,t,r,DOH_REPLACE_ID)
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Files
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOHFile *DohNewFile(DOH *file, const char *mode);
|
||||
extern DOHFile *DohNewFileFromFile(FILE *f);
|
||||
extern DOHFile *DohNewFileFromFd(int fd);
|
||||
extern int DohClose(DOH *file);
|
||||
extern int DohCopyto(DOHFile *input, DOHFile *output);
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* List
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOHList *DohNewList();
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Hash
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOHHash *DohNewHash();
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Void
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOHVoid *DohNewVoid(void *ptr, void (*del)(void *));
|
||||
extern DOHList *DohSplit(DOHFile *input, char ch, int nsplits);
|
||||
extern DOH *DohNone;
|
||||
|
||||
#ifndef DOH_LONG_NAMES
|
||||
/* Macros to invoke the above functions. Includes the location of
|
||||
|
|
@ -168,6 +329,7 @@ extern int DohIsFile(const DOH *obj);
|
|||
#define Getc DohGetc
|
||||
#define Putc DohPutc
|
||||
#define Ungetc DohUngetc
|
||||
#define Close DohClose
|
||||
#define vPrintf DohvPrintf
|
||||
#define GetInt DohGetInt
|
||||
#define GetDouble DohGetDouble
|
||||
|
|
@ -182,57 +344,36 @@ extern int DohIsFile(const DOH *obj);
|
|||
#define Readline DohReadline
|
||||
#define Replace DohReplace
|
||||
#define Chop DohChop
|
||||
#define Getmeta DohGetmeta
|
||||
#define Setmeta DohSetmeta
|
||||
#define Delmeta DohDelmeta
|
||||
#define NewString DohNewString
|
||||
#define NewStringf DohNewStringf
|
||||
#define NewHash DohNewHash
|
||||
#define NewList DohNewList
|
||||
#define NewFile DohNewFile
|
||||
#define NewFileFromFile DohNewFileFromFile
|
||||
#define NewFileFromFd DohNewFileFromFd
|
||||
#define Close DohClose
|
||||
#define NewVoid DohNewVoid
|
||||
#define Keys DohKeys
|
||||
#define Strcmp DohStrcmp
|
||||
#define Strncmp DohStrncmp
|
||||
#define Strstr DohStrstr
|
||||
#define Strchr DohStrchr
|
||||
#define Copyto DohCopyto
|
||||
#define Split DohSplit
|
||||
#define Setmark DohSetmark
|
||||
#define Getmark DohGetmark
|
||||
#define None DohNone
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Strings.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
#ifdef NIL
|
||||
#undef NIL
|
||||
#endif
|
||||
|
||||
extern DOHString *NewString(const DOH *c);
|
||||
extern DOHString *NewStringf(const DOH *fmt, ...);
|
||||
#define NIL (char *) NULL
|
||||
|
||||
/* String replacement flags */
|
||||
|
||||
#define DOH_REPLACE_ANY 0x01
|
||||
#define DOH_REPLACE_NOQUOTE 0x02
|
||||
#define DOH_REPLACE_ID 0x04
|
||||
#define DOH_REPLACE_FIRST 0x08
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Files
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOHFile *NewFile(DOH *file, char *mode);
|
||||
extern DOHFile *NewFileFromFile(FILE *f);
|
||||
extern DOHFile *NewFileFromFd(int fd);
|
||||
|
||||
extern int DohCopyto(DOHFile *input, DOHFile *output);
|
||||
|
||||
#define Copyto DohCopyto
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* List
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOHList *NewList();
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Hash
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOHHash *NewHash();
|
||||
extern DOHList *Hash_keys(DOHHash *);
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Void
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOHVoid *NewVoid(void *ptr, void (*del)(void *));
|
||||
|
||||
extern DOHList *DohSplit(DOHFile *input, char *chs, int nsplits);
|
||||
#define Split DohSplit
|
||||
|
||||
extern DOH *DohNone;
|
||||
|
||||
#endif /* DOH_H */
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ typedef struct {
|
|||
int (*doh_delattr)(DOH *obj, DOH *name); /* Del attribute */
|
||||
DOH *(*doh_firstkey)(DOH *obj); /* First key */
|
||||
DOH *(*doh_nextkey)(DOH *obj); /* Next key */
|
||||
DOH *(*doh_keys)(DOH *obj); /* All keys as a list */
|
||||
} DohHashMethods;
|
||||
|
||||
/* List objects */
|
||||
|
|
@ -33,7 +34,6 @@ typedef struct {
|
|||
int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */
|
||||
DOH *(*doh_firstitem)(DOH *obj); /* Iterators */
|
||||
DOH *(*doh_nextitem)(DOH *obj);
|
||||
void (*doh_sort)(DOH *obj, int opt); /* Sort */
|
||||
} DohListMethods;
|
||||
|
||||
/* File methods */
|
||||
|
|
@ -93,37 +93,29 @@ typedef struct DohObjInfo {
|
|||
} DohObjInfo;
|
||||
|
||||
typedef struct {
|
||||
void *data; /* Data pointer */
|
||||
unsigned int type : 4; /* Object type (max 16 -- deal with it) */
|
||||
void *data; /* Data pointer */
|
||||
DohObjInfo *type;
|
||||
void *meta; /* Meta data */
|
||||
int flag_intern : 1; /* Interned object */
|
||||
int flag_marked : 1; /* Mark flag. Used to avoid recursive loops in places */
|
||||
int flag_user : 1; /* User flag */
|
||||
int flag_reserved : 1; /* Reserved flag */
|
||||
int refcount : 24; /* Reference count (max 16 million) */
|
||||
int flag_usermark : 1; /* User marked */
|
||||
int refcount : 28; /* Reference count (max 16 million) */
|
||||
} DohBase;
|
||||
|
||||
/* Macros for decrefing and increfing (safe for null objects). */
|
||||
#define Decref(a) if (a) ((DohBase *) a)->refcount--
|
||||
#define Incref(a) if (a) ((DohBase *) a)->refcount++
|
||||
#define Refcount(a) ((DohBase *) a)->refcount
|
||||
#define Decref(a) if (a) ((DohBase *) a)->refcount--
|
||||
#define Incref(a) if (a) ((DohBase *) a)->refcount++
|
||||
#define Refcount(a) ((DohBase *) a)->refcount
|
||||
|
||||
/* Macros for manipulating objects in a safe manner */
|
||||
#define ObjData(a) ((DohBase *)a)->data
|
||||
#define ObjSetMark(a,x) ((DohBase *)a)->flag_marked = x
|
||||
#define ObjGetMark(a) ((DohBase *)a)->flag_marked
|
||||
#define ObjType(a) ((DohBase *)a)->type
|
||||
#define ObjData(a) ((DohBase *)a)->data
|
||||
#define ObjSetMark(a,x) ((DohBase *)a)->flag_marked = x
|
||||
#define ObjGetMark(a) ((DohBase *)a)->flag_marked
|
||||
#define ObjType(a) ((DohBase *)a)->type
|
||||
|
||||
extern DOH *DohObjMalloc(int type, void *data); /* Allocate a DOH object */
|
||||
extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */
|
||||
extern void DohObjFree(DOH *ptr); /* Free a DOH object */
|
||||
extern void DohRegisterType(int type, DohObjInfo *objinfo);
|
||||
|
||||
#define MAX_DOHTYPE 16
|
||||
|
||||
#define DOHTYPE_STRING 1
|
||||
#define DOHTYPE_LIST 2
|
||||
#define DOHTYPE_HASH 3
|
||||
#define DOHTYPE_VOID 4
|
||||
#define DOHTYPE_FILE 5
|
||||
|
||||
#endif /* DOHOBJ_H */
|
||||
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ exec_prefix= @exec_prefix@
|
|||
INCLUDE_DIR = $(prefix)/include
|
||||
LIB_DIR = $(exec_prefix)/lib
|
||||
|
||||
DOHOPT =
|
||||
|
||||
# Installer
|
||||
|
||||
INSTALL = ./install-sh -c
|
||||
|
|
@ -19,7 +17,7 @@ INSTALL_DATA = ${INSTALL} -m 644
|
|||
INSTALL_PROGRAM= ${INSTALL} -m 755
|
||||
|
||||
all:
|
||||
cd Doh; $(MAKE) DOHOPT='$(DOHOPT)'
|
||||
cd Doh; $(MAKE)
|
||||
|
||||
install:
|
||||
@echo "Installing $(LIB_DIR)/libdoh.a..."
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_INIT(Include/doh.h)
|
||||
AC_PREREQ(2.0)
|
||||
AC_PREREQ(2.53)
|
||||
|
||||
# Set name for machine-dependent library files
|
||||
AC_SUBST(MACHDEP)
|
||||
|
|
@ -41,4 +41,4 @@ dnl Checks for header files.
|
|||
AC_HEADER_STDC
|
||||
dnl Checks for library functions.
|
||||
|
||||
AC_OUTPUT(Makefile Doh/Makefile )
|
||||
AC_OUTPUT(Makefile Doh/Makefile)
|
||||
|
|
|
|||
3
SWIG/Source/Include/.cvsignore
Normal file
3
SWIG/Source/Include/.cvsignore
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
swigconfig.h
|
||||
swigver.h
|
||||
|
||||
|
|
@ -1,6 +1,19 @@
|
|||
/* This file contains SWIG specific configuration data for those modules
|
||||
/* This -*-c-*- file contains SWIG specific configuration data for those modules
|
||||
that care */
|
||||
|
||||
#define SWIG_LIB "@prefix@/lib/swig1.3"
|
||||
#define SWIG_LANG TCL8
|
||||
/* Directory where to find the machine-independent SWIG files */
|
||||
|
||||
#define SWIG_LIB "@-swig_lib-@"
|
||||
|
||||
/* Default language */
|
||||
|
||||
#define SWIG_LANG "-tcl"
|
||||
|
||||
/* Values returned by swig when invoked with the -ldflags option */
|
||||
|
||||
#define SWIG_PERL_RUNTIME "-L@-exec_prefix-@/lib -lswigpl@-release_suffix-@"
|
||||
#define SWIG_PYTHON_RUNTIME "-L@-exec_prefix-@/lib -lswigpy@-release_suffix-@"
|
||||
#define SWIG_TCL_RUNTIME "-L@-exec_prefix-@/lib -lswigtcl@-release_suffix-@"
|
||||
#define SWIG_RUBY_RUNTIME "-L@-exec_prefix-@/lib -lswigrb@-release_suffix-@"
|
||||
#define SWIG_GUILE_RUNTIME "-L@-exec_prefix-@/lib -lswigguile@-release_suffix-@"
|
||||
#define SWIG_PIKE_RUNTIME "-L@-exec_prefix-@/lib -lswigpike@-release_suffix-@"
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
/* SWIG version information */
|
||||
|
||||
#ifndef SWIG_VERSION
|
||||
#define SWIG_VERSION "1.3u-20001219-1815"
|
||||
#endif
|
||||
|
||||
#ifndef SWIG_SPIN
|
||||
#define SWIG_SPIN "(Alpha 6)"
|
||||
#endif
|
||||
|
|
@ -5,6 +5,14 @@
|
|||
#define SWIG_VERSION "@SWIG_VERSION@"
|
||||
#endif
|
||||
|
||||
#ifndef SWIG_SPIN
|
||||
#define SWIG_SPIN "@SWIG_SPIN@"
|
||||
#ifndef SWIG_MAJOR_VERSION
|
||||
#define SWIG_MAJOR_VERSION @SWIG_MAJOR_VERSION@
|
||||
#endif
|
||||
|
||||
#ifndef SWIG_MINOR_VERSION
|
||||
#define SWIG_MINOR_VERSION @SWIG_MINOR_VERSION@
|
||||
#endif
|
||||
|
||||
#ifndef SWIG_SPIN
|
||||
#define SWIG_SPIN @SWIG_SPIN@
|
||||
#endif
|
||||
|
|
|
|||
186
SWIG/Source/Include/swigwarn.h
Normal file
186
SWIG/Source/Include/swigwarn.h
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
/* SWIG warning message numbers
|
||||
|
||||
This file serves as the main registry of warning message numbers. Some of these
|
||||
numbers are used internally in the C/C++ source code of SWIG. However, some
|
||||
of the numbers are used in SWIG configuration files (swig.swg and others).
|
||||
|
||||
The numbers are roughly organized into a few different classes by functionality.
|
||||
|
||||
Even though symbolic constants are used in the SWIG source, this is
|
||||
not always the case in SWIG interface files. Do not change the
|
||||
numbers in this file.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef _SWIGWARN_H
|
||||
#define _SWIGWARN_H 1
|
||||
|
||||
#define WARN_NONE 0
|
||||
|
||||
/* -- Deprecated features -- */
|
||||
|
||||
#define WARN_DEPRECATED_EXTERN 101
|
||||
#define WARN_DEPRECATED_VAL 102
|
||||
#define WARN_DEPRECATED_OUT 103
|
||||
#define WARN_DEPRECATED_DISABLEDOC 104
|
||||
#define WARN_DEPRECATED_ENABLEDOC 105
|
||||
#define WARN_DEPRECATED_DOCONLY 106
|
||||
#define WARN_DEPRECATED_STYLE 107
|
||||
#define WARN_DEPRECATED_LOCALSTYLE 108
|
||||
#define WARN_DEPRECATED_TITLE 109
|
||||
#define WARN_DEPRECATED_SECTION 110
|
||||
#define WARN_DEPRECATED_SUBSECTION 111
|
||||
#define WARN_DEPRECATED_SUBSUBSECTION 112
|
||||
#define WARN_DEPRECATED_ADDMETHODS 113
|
||||
#define WARN_DEPRECATED_READONLY 114
|
||||
#define WARN_DEPRECATED_READWRITE 115
|
||||
#define WARN_DEPRECATED_EXCEPT 116
|
||||
#define WARN_DEPRECATED_NEW 117
|
||||
#define WARN_DEPRECATED_EXCEPT_TM 118
|
||||
#define WARN_DEPRECATED_IGNORE_TM 119
|
||||
|
||||
/* -- Preprocessor -- */
|
||||
|
||||
#define WARN_PP_MISSING_FILE 201
|
||||
#define WARN_PP_EVALUATION 202
|
||||
|
||||
/* -- C/C++ Parser -- */
|
||||
|
||||
#define WARN_PARSE_CLASS_KEYWORD 301
|
||||
#define WARN_PARSE_REDEFINED 302
|
||||
#define WARN_PARSE_EXTEND_UNDEF 303
|
||||
#define WARN_PARSE_UNSUPPORTED_VALUE 304
|
||||
#define WARN_PARSE_BAD_VALUE 305
|
||||
#define WARN_PARSE_PRIVATE 306
|
||||
#define WARN_PARSE_BAD_DEFAULT 307
|
||||
#define WARN_PARSE_NAMESPACE_ALIAS 308
|
||||
#define WARN_PARSE_PRIVATE_INHERIT 309
|
||||
#define WARN_PARSE_TEMPLATE_REPEAT 310
|
||||
#define WARN_PARSE_TEMPLATE_PARTIAL 311
|
||||
#define WARN_PARSE_NESTED_CLASS 312
|
||||
#define WARN_PARSE_UNDEFINED_EXTERN 313
|
||||
#define WARN_PARSE_KEYWORD 314
|
||||
#define WARN_PARSE_USING_UNDEF 315
|
||||
#define WARN_PARSE_MODULE_REPEAT 316
|
||||
#define WARN_PARSE_TEMPLATE_SP_UNDEF 317
|
||||
#define WARN_PARSE_TEMPLATE_AMBIG 318
|
||||
#define WARN_PARSE_NO_ACCESS 319
|
||||
|
||||
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
|
||||
#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */
|
||||
#define WARN_IGNORE_OPERATOR_PLUS 352 /* + */
|
||||
#define WARN_IGNORE_OPERATOR_MINUS 353 /* - */
|
||||
#define WARN_IGNORE_OPERATOR_MUL 354 /* * */
|
||||
#define WARN_IGNORE_OPERATOR_DIV 355 /* / */
|
||||
#define WARN_IGNORE_OPERATOR_MOD 356 /* % */
|
||||
#define WARN_IGNORE_OPERATOR_XOR 357 /* ^ */
|
||||
#define WARN_IGNORE_OPERATOR_AND 358 /* & */
|
||||
#define WARN_IGNORE_OPERATOR_OR 359 /* | */
|
||||
#define WARN_IGNORE_OPERATOR_NOT 360 /* ~ */
|
||||
#define WARN_IGNORE_OPERATOR_LNOT 361 /* ! */
|
||||
#define WARN_IGNORE_OPERATOR_EQ 362 /* = */
|
||||
#define WARN_IGNORE_OPERATOR_LT 363 /* < */
|
||||
#define WARN_IGNORE_OPERATOR_GT 364 /* > */
|
||||
#define WARN_IGNORE_OPERATOR_PLUSEQ 365 /* += */
|
||||
#define WARN_IGNORE_OPERATOR_MINUSEQ 366 /* -= */
|
||||
#define WARN_IGNORE_OPERATOR_MULEQ 367 /* *= */
|
||||
#define WARN_IGNORE_OPERATOR_DIVEQ 368 /* /= */
|
||||
#define WARN_IGNORE_OPERATOR_MODEQ 369 /* %= */
|
||||
#define WARN_IGNORE_OPERATOR_XOREQ 370 /* ^= */
|
||||
#define WARN_IGNORE_OPERATOR_ANDEQ 371 /* &= */
|
||||
#define WARN_IGNORE_OPERATOR_OREQ 372 /* |= */
|
||||
#define WARN_IGNORE_OPERATOR_LSHIFT 373 /* << */
|
||||
#define WARN_IGNORE_OPERATOR_RSHIFT 374 /* >> */
|
||||
#define WARN_IGNORE_OPERATOR_LSHIFTEQ 375 /* <<= */
|
||||
#define WARN_IGNORE_OPERATOR_RSHIFTEQ 376 /* >>= */
|
||||
#define WARN_IGNORE_OPERATOR_EQUALTO 377 /* == */
|
||||
#define WARN_IGNORE_OPERATOR_NOTEQUAL 378 /* != */
|
||||
#define WARN_IGNORE_OPERATOR_LTEQUAL 379 /* <= */
|
||||
#define WARN_IGNORE_OPERATOR_GTEQUAL 380 /* >= */
|
||||
#define WARN_IGNORE_OPERATOR_LAND 381 /* && */
|
||||
#define WARN_IGNORE_OPERATOR_LOR 382 /* || */
|
||||
#define WARN_IGNORE_OPERATOR_PLUSPLUS 383 /* ++ */
|
||||
#define WARN_IGNORE_OPERATOR_MINUSMINUS 384 /* -- */
|
||||
#define WARN_IGNORE_OPERATOR_COMMA 385 /* , */
|
||||
#define WARN_IGNORE_OPERATOR_ARROWSTAR 386 /* ->* */
|
||||
#define WARN_IGNORE_OPERATOR_ARROW 387 /* -> */
|
||||
#define WARN_IGNORE_OPERATOR_CALL 388 /* () */
|
||||
#define WARN_IGNORE_OPERATOR_INDEX 389 /* [] */
|
||||
#define WARN_IGNORE_OPERATOR_UPLUS 390 /* + */
|
||||
#define WARN_IGNORE_OPERATOR_UMINUS 391 /* - */
|
||||
#define WARN_IGNORE_OPERATOR_UMUL 392 /* * */
|
||||
#define WARN_IGNORE_OPERATOR_UAND 393 /* & */
|
||||
#define WARN_IGNORE_OPERATOR_NEWARR 394 /* new [] */
|
||||
#define WARN_IGNORE_OEPRATOR_DELARR 395 /* delete [] */
|
||||
|
||||
/* 394-399 are reserved */
|
||||
|
||||
/* -- Type system and typemaps -- */
|
||||
|
||||
#define WARN_TYPE_UNDEFINED_CLASS 401
|
||||
#define WARN_TYPE_INCOMPLETE 402
|
||||
#define WARN_TYPE_ABSTRACT 403
|
||||
#define WARN_TYPE_REDEFINED 404
|
||||
|
||||
#define WARN_TYPEMAP_SOURCETARGET 450
|
||||
#define WARN_TYPEMAP_CHARLEAK 451
|
||||
#define WARN_TYPEMAP_SWIGTYPE 452
|
||||
#define WARN_TYPEMAP_APPLY_UNDEF 453
|
||||
|
||||
#define WARN_TYPEMAP_IN_UNDEF 460
|
||||
#define WARN_TYPEMAP_OUT_UNDEF 461
|
||||
#define WARN_TYPEMAP_VARIN_UNDEF 462
|
||||
#define WARN_TYPEMAP_VAROUT_UNDEF 463
|
||||
#define WARN_TYPEMAP_CONST_UNDEF 464
|
||||
#define WARN_TYPEMAP_UNDEF 465
|
||||
#define WARN_TYPEMAP_VAR_UNDEF 466
|
||||
#define WARN_TYPEMAP_TYPECHECK 467
|
||||
#define WARN_TYPEMAP_THROW 468
|
||||
|
||||
/* -- General code generation -- */
|
||||
|
||||
#define WARN_LANG_OVERLOAD_DECL 501
|
||||
#define WARN_LANG_OVERLOAD_CONSTRUCT 502
|
||||
#define WARN_LANG_IDENTIFIER 503
|
||||
#define WARN_LANG_RETURN_TYPE 504
|
||||
#define WARN_LANG_VARARGS 505
|
||||
#define WARN_LANG_VARARGS_KEYWORD 506
|
||||
#define WARN_LANG_NATIVE_UNIMPL 507
|
||||
#define WARN_LANG_DEREF_SHADOW 508
|
||||
#define WARN_LANG_OVERLOAD_SHADOW 509
|
||||
#define WARN_LANG_FRIEND_IGNORE 510
|
||||
#define WARN_LANG_OVERLOAD_KEYWORD 511
|
||||
#define WARN_LANG_OVERLOAD_CONST 512
|
||||
#define WARN_LANG_CLASS_UNNAMED 513
|
||||
|
||||
/* -- Reserved (600-799) -- */
|
||||
|
||||
/* -- Language module specific warnings (800 - 999) -- */
|
||||
|
||||
#define WARN_RUBY_WRONG_NAME 801
|
||||
#define WARN_RUBY_MULTIPLE_INHERITANCE 802
|
||||
|
||||
#define WARN_JAVA_TYPEMAP_JNI_UNDEF 810
|
||||
#define WARN_JAVA_TYPEMAP_JTYPE_UNDEF 811
|
||||
#define WARN_JAVA_TYPEMAP_JSTYPE_UNDEF 812
|
||||
#define WARN_JAVA_MULTIPLE_INHERITANCE 813
|
||||
#define WARN_JAVA_TYPEMAP_GETCPTR_UNDEF 814
|
||||
#define WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF 815
|
||||
#define WARN_JAVA_TYPEMAP_PTRCONSTMOD_UNDEF 816
|
||||
#define WARN_JAVA_TYPEMAP_JAVAOUT_UNDEF 817
|
||||
#define WARN_JAVA_TYPEMAP_JAVAIN_UNDEF 818
|
||||
|
||||
/* please leave 810-830 free for Java */
|
||||
|
||||
|
||||
|
||||
/* Feel free to claim any number in this space that's not currently being used. Just make sure you
|
||||
add an entry here */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
@ -7,32 +7,25 @@ VPATH = @srcdir@
|
|||
|
||||
SHELL = /bin/sh
|
||||
CXX = @CXX@
|
||||
CFLAGS = @CFLAGS@
|
||||
CFLAGS = @CFLAGS@ @SWILL@
|
||||
YACC = @YACC@
|
||||
AR = @AR@
|
||||
RANLIB = @RANLIB@
|
||||
|
||||
TARGET = libmodules11.a
|
||||
COREOBJS = main.o emit.o lang.o generate.o
|
||||
CORESRCS = main.cxx emit.cxx lang.cxx generate.cxx
|
||||
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
|
||||
|
||||
LANGOBJS = tcl8.o python.o perl5.o guile.o ruby.o mzscheme.o #java.o
|
||||
LANGSRCS = tcl8.cxx python.cxx perl5.cxx guile.cxx ruby.cxx mzscheme.cxx #java.cxx
|
||||
|
||||
OBJS = $(COREOBJS) $(LANGOBJS) xml.o
|
||||
SRCS = $(CORESRCS) $(LANGSRCS) xml.cxx
|
||||
|
||||
INCLUDE = -I$(srcdir)/../Include \
|
||||
-I$(srcdir)/../Preprocessor \
|
||||
-I$(srcdir)/../LParse \
|
||||
INCLUDES = -I$(srcdir)/../Include \
|
||||
-I$(srcdir)/../DOH/Include \
|
||||
-I$(srcdir)/../Preprocessor \
|
||||
-I$(srcdir)/../Swig \
|
||||
-I../Include
|
||||
|
||||
# Rules for creation of a .o file from .cxx
|
||||
# Rules for creation of a .@OBJEXT@ file from .cxx
|
||||
.SUFFIXES: .cxx
|
||||
.cxx.o:
|
||||
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
.cxx.@OBJEXT@:
|
||||
$(CXX) $(INCLUDES) $(CFLAGS) -c -o $*.@OBJEXT@ $<
|
||||
|
||||
|
||||
swig: $(TARGET)
|
||||
|
|
@ -42,7 +35,7 @@ $(TARGET): $(OBJS)
|
|||
$(RANLIB) $(TARGET)
|
||||
|
||||
clean::
|
||||
rm -f *.o *~ $(TARGET)
|
||||
rm -f *.@OBJEXT@ *~ $(TARGET)
|
||||
|
||||
nuke::
|
||||
rm -f Makefile *~ #* core a.out
|
||||
rm -f Makefile *~
|
||||
|
|
|
|||
9
SWIG/Source/Modules1.1/README
Normal file
9
SWIG/Source/Modules1.1/README
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
06/25/2002
|
||||
|
||||
This directory contains all of the SWIG language modules. Many of these
|
||||
modules contain code that dates back to SWIG1.0. The module API has changed
|
||||
a lot in the development releases so this is fairly messy. We're working on
|
||||
cleaning it up, but you'll have to bear with us until it's done.
|
||||
|
||||
-- Dave
|
||||
|
||||
453
SWIG/Source/Modules1.1/allocate.cxx
Normal file
453
SWIG/Source/Modules1.1/allocate.cxx
Normal file
|
|
@ -0,0 +1,453 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* allocate.cxx
|
||||
*
|
||||
* This module tries to figure out which classes and structures support
|
||||
* default constructors and destructors in C++. There are several rules that
|
||||
* define this behavior including pure abstract methods, private sections,
|
||||
* and non-default constructors in base classes. See the ARM or
|
||||
* Doc/Manual/SWIGPlus.html for details.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1998-2002. The University of Chicago
|
||||
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
|
||||
* University of California.
|
||||
*
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char cvsroot_allocate_cxx[] = "$Header$";
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
class Allocate : public Dispatcher {
|
||||
Node *inclass;
|
||||
enum AccessMode { PUBLIC, PRIVATE, PROTECTED };
|
||||
AccessMode cplus_mode;
|
||||
int extendmode;
|
||||
|
||||
/* Checks to see if a class is abstract through inheritance */
|
||||
int is_abstract_inherit(Node *n, Node *base = 0, int first = 0) {
|
||||
if (!first && (base == n)) return 0;
|
||||
if (!base) {
|
||||
/* Root node */
|
||||
Symtab *stab = Getattr(n,"symtab"); /* Get symbol table for node */
|
||||
Symtab *oldtab = Swig_symbol_setscope(stab);
|
||||
int ret = is_abstract_inherit(n,n,1);
|
||||
Swig_symbol_setscope(oldtab);
|
||||
return ret;
|
||||
}
|
||||
List *abstract = Getattr(base,"abstract");
|
||||
if (abstract) {
|
||||
for (int i = 0; i < Len(abstract); i++) {
|
||||
Node *nn = Getitem(abstract,i);
|
||||
String *name = Getattr(nn,"name");
|
||||
String *base_decl = Getattr(nn,"decl");
|
||||
if (Strstr(name,"~")) continue; /* Don't care about destructors */
|
||||
int implemented = 0;
|
||||
Node *dn = Swig_symbol_clookup(name,0);
|
||||
if (!dn) {
|
||||
Printf(stdout,"node: %x '%s'. base: %x '%s'. member '%s'\n", n, Getattr(n,"name"), base, Getattr(base,"name"), name);
|
||||
}
|
||||
assert(dn); // Assertion of doom
|
||||
while (dn && !implemented) {
|
||||
String *local_decl = Getattr(dn,"decl");
|
||||
if (local_decl && !Strcmp(local_decl, base_decl)) {
|
||||
if (Getattr(dn,"abstract")) return 1;
|
||||
implemented++;
|
||||
}
|
||||
dn = Getattr(dn,"csym:nextSibling");
|
||||
}
|
||||
if (!implemented && (Getattr(nn,"abstract"))) {
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
if (dn && (Getattr(dn,"abstract"))) {
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
List *bases = Getattr(base,"bases");
|
||||
if (!bases) return 0;
|
||||
for (int i = 0; i < Len(bases); i++) {
|
||||
if (is_abstract_inherit(n,Getitem(bases,i))) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Grab methods used by smart pointers */
|
||||
|
||||
List *smart_pointer_methods(Node *cls, List *methods) {
|
||||
if (!methods) {
|
||||
methods = NewList();
|
||||
}
|
||||
|
||||
Node *c = firstChild(cls);
|
||||
String *kind = Getattr(cls,"kind");
|
||||
int mode;
|
||||
if (Strcmp(kind,"class") == 0) mode = PRIVATE;
|
||||
else mode = PUBLIC;
|
||||
|
||||
while (c) {
|
||||
if (Getattr(c,"error") || Getattr(c,"feature:ignore")) {
|
||||
c = nextSibling(c);
|
||||
continue;
|
||||
}
|
||||
if (Strcmp(nodeType(c),"cdecl") == 0) {
|
||||
if (!Getattr(c,"feature:ignore")) {
|
||||
String *storage = Getattr(c,"storage");
|
||||
if (!((Cmp(storage,"static") == 0) || (Cmp(storage,"typedef") == 0))) {
|
||||
String *name = Getattr(c,"name");
|
||||
String *symname = Getattr(c,"sym:name");
|
||||
Node *e = Swig_symbol_clookup_local(name,0);
|
||||
if (e && !Getattr(e,"feature:ignore") && (Cmp(symname, Getattr(e,"sym:name")) == 0)) {
|
||||
Swig_warning(WARN_LANG_DEREF_SHADOW,Getfile(e),Getline(e),"Declaration of '%s' shadows declaration accessible via operator->() at %s:%d\n",
|
||||
name, Getfile(c),Getline(c));
|
||||
} else {
|
||||
/* Make sure node with same name doesn't already exist */
|
||||
int k;
|
||||
int match = 0;
|
||||
for (k = 0; k < Len(methods); k++) {
|
||||
e = Getitem(methods,k);
|
||||
if (Cmp(symname,Getattr(e,"sym:name")) == 0) {
|
||||
match = 1;
|
||||
break;
|
||||
}
|
||||
if ((!symname || (!Getattr(e,"sym:name"))) && (Cmp(name,Getattr(e,"name")) == 0)) {
|
||||
match = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!match) {
|
||||
Node *cc = c;
|
||||
while (cc) {
|
||||
Append(methods,cc);
|
||||
cc = Getattr(cc,"sym:nextSibling");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Strcmp(nodeType(c),"access") == 0) {
|
||||
kind = Getattr(c,"kind");
|
||||
if (Strcmp(kind,"public") == 0) mode = PUBLIC;
|
||||
else mode = PRIVATE;
|
||||
}
|
||||
c = nextSibling(c);
|
||||
}
|
||||
/* Look for methods in base classes */
|
||||
{
|
||||
Node *bases = Getattr(cls,"bases");
|
||||
int k;
|
||||
for (k = 0; k < Len(bases); k++) {
|
||||
smart_pointer_methods(Getitem(bases,k),methods);
|
||||
}
|
||||
}
|
||||
/* Remove protected/private members */
|
||||
{
|
||||
for (int i = 0; i < Len(methods); ) {
|
||||
Node *n = Getitem(methods,i);
|
||||
if (checkAttribute(n,"access","protected") || checkAttribute(n,"access","private")) {
|
||||
Delitem(methods,i);
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return methods;
|
||||
}
|
||||
|
||||
void mark_exception_classes(ParmList *p) {
|
||||
while(p) {
|
||||
SwigType *ty = Getattr(p,"type");
|
||||
SwigType *t = SwigType_typedef_resolve_all(ty);
|
||||
Node *c = Swig_symbol_clookup(t,0);
|
||||
if (c) {
|
||||
Setattr(c,"cplus:exceptionclass","1");
|
||||
}
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
virtual int top(Node *n) {
|
||||
cplus_mode = PUBLIC;
|
||||
inclass = 0;
|
||||
extendmode = 0;
|
||||
emit_children(n);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
virtual int importDirective(Node *n) { return emit_children(n); }
|
||||
virtual int includeDirective(Node *n) { return emit_children(n); }
|
||||
virtual int externDeclaration(Node *n) { return emit_children(n); }
|
||||
virtual int namespaceDeclaration(Node *n) { return emit_children(n); }
|
||||
virtual int extendDirective(Node *n) {
|
||||
extendmode = 1;
|
||||
emit_children(n);
|
||||
extendmode = 0;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
virtual int classDeclaration(Node *n) {
|
||||
Symtab *symtab = Swig_symbol_current();
|
||||
Swig_symbol_setscope(Getattr(n,"symtab"));
|
||||
|
||||
if (!CPlusPlus) {
|
||||
/* Always have default constructors/destructors in C */
|
||||
Setattr(n,"allocate:default_constructor","1");
|
||||
Setattr(n,"allocate:default_destructor","1");
|
||||
}
|
||||
|
||||
if (Getattr(n,"allocate:visit")) return SWIG_OK;
|
||||
Setattr(n,"allocate:visit","1");
|
||||
|
||||
/* Always visit base classes first */
|
||||
{
|
||||
List *bases = Getattr(n,"bases");
|
||||
if (bases) {
|
||||
for (int i = 0; i < Len(bases); i++) {
|
||||
Node *b = Getitem(bases,i);
|
||||
classDeclaration(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inclass = n;
|
||||
String *kind = Getattr(n,"kind");
|
||||
if (Strcmp(kind,"class") == 0) {
|
||||
cplus_mode = PRIVATE;
|
||||
} else {
|
||||
cplus_mode = PUBLIC;
|
||||
}
|
||||
|
||||
emit_children(n);
|
||||
|
||||
/* Check if the class is abstract via inheritance. This might occur if a class didn't have
|
||||
any pure virtual methods of its own, but it didn't implement all of the pure methods in
|
||||
a base class */
|
||||
|
||||
if (is_abstract_inherit(n)) {
|
||||
if ((!Getattr(n,"abstract")) && ((Getattr(n,"allocate:public_constructor") || (!Getattr(n,"feature:nodefault") && !Getattr(n,"allocate:has_constructor"))))) {
|
||||
if (!Getattr(n,"feature:notabstract")) {
|
||||
Swig_warning(WARN_TYPE_ABSTRACT,Getfile(n),Getline(n),"Class '%s' might be abstract. No constructors generated. \n", SwigType_namestr(Getattr(n,"name")));
|
||||
Setattr(n,"abstract",NewList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Getattr(n,"allocate:has_constructor")) {
|
||||
/* No constructor is defined. We need to check a few things */
|
||||
/* If class is abstract. No default constructor. Sorry */
|
||||
if (Getattr(n,"abstract")) {
|
||||
Delattr(n,"allocate:default_constructor");
|
||||
}
|
||||
if (!Getattr(n,"allocate:default_constructor")) {
|
||||
/* Check base classes */
|
||||
List *bases = Getattr(n,"bases");
|
||||
int allows_default = 1;
|
||||
|
||||
for (int i = 0; i < Len(bases); i++) {
|
||||
Node *n = Getitem(bases,i);
|
||||
/* If base class does not allow default constructor, we don't allow it either */
|
||||
if (!Getattr(n,"allocate:default_constructor") && (!Getattr(n,"allocate:default_base_constructor"))) {
|
||||
allows_default = 0;
|
||||
}
|
||||
}
|
||||
if (allows_default) {
|
||||
Setattr(n,"allocate:default_constructor","1");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Getattr(n,"allocate:has_destructor")) {
|
||||
/* No destructor was defined. We need to check a few things here too */
|
||||
List *bases = Getattr(n,"bases");
|
||||
int allows_destruct = 1;
|
||||
|
||||
for (int i = 0; i < Len(bases); i++) {
|
||||
Node *n = Getitem(bases,i);
|
||||
/* If base class does not allow default destructor, we don't allow it either */
|
||||
if (!Getattr(n,"allocate:default_destructor") && (!Getattr(n,"allocate:default_base_destructor"))) {
|
||||
allows_destruct = 0;
|
||||
}
|
||||
}
|
||||
if (allows_destruct) {
|
||||
Setattr(n,"allocate:default_destructor","1");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Check if base classes allow smart pointers, but might be hidden */
|
||||
if (!Getattr(n,"allocate:smartpointer")) {
|
||||
Node *sp = Swig_symbol_clookup((char*)"operator ->",0);
|
||||
if (sp) {
|
||||
/* Look for parent */
|
||||
Node *p = parentNode(sp);
|
||||
if (Strcmp(nodeType(p),"extend") == 0) {
|
||||
p = parentNode(p);
|
||||
}
|
||||
if (Strcmp(nodeType(p),"class") == 0) {
|
||||
if (Getattr(p,"feature:ignore")) {
|
||||
Setattr(n,"allocate:smartpointer",Getattr(p,"allocate:smartpointer"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Only care about default behavior. Remove temporary values */
|
||||
Setattr(n,"allocate:visit","1");
|
||||
inclass = 0;
|
||||
Swig_symbol_setscope(symtab);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
virtual int accessDeclaration(Node *n) {
|
||||
String *kind = Getattr(n,"kind");
|
||||
if (Cmp(kind,"public") == 0) {
|
||||
cplus_mode = PUBLIC;
|
||||
} else if (Cmp(kind,"private") == 0) {
|
||||
cplus_mode = PRIVATE;
|
||||
} else if (Cmp(kind,"protected") == 0) {
|
||||
cplus_mode = PROTECTED;
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
virtual int cDeclaration(Node *n) {
|
||||
|
||||
mark_exception_classes(Getattr(n,"throws"));
|
||||
|
||||
if (inclass) {
|
||||
String *name = Getattr(n,"name");
|
||||
if (cplus_mode != PUBLIC) {
|
||||
/* Look for a private assignment operator */
|
||||
if (Strcmp(name,"operator =") == 0) {
|
||||
Setattr(inclass,"allocate:noassign","1");
|
||||
}
|
||||
} else {
|
||||
/* Look for smart pointer operator */
|
||||
if ((Strcmp(name,"operator ->") == 0) && (!Getattr(n,"feature:ignore"))) {
|
||||
/* Look for version with no parameters */
|
||||
Node *sn = n;
|
||||
while (sn) {
|
||||
if (!Getattr(sn,"parms")) {
|
||||
SwigType *type = SwigType_typedef_resolve_all(Getattr(sn,"type"));
|
||||
SwigType_push(type,Getattr(sn,"decl"));
|
||||
Delete(SwigType_pop_function(type));
|
||||
SwigType *base = SwigType_base(type);
|
||||
Node *sc = Swig_symbol_clookup(base, 0);
|
||||
if ((sc) && (Strcmp(nodeType(sc),"class") == 0)) {
|
||||
if (SwigType_check_decl(type,"p.")) {
|
||||
List *methods = smart_pointer_methods(sc,0);
|
||||
Setattr(inclass,"allocate:smartpointer",methods);
|
||||
break;
|
||||
} else {
|
||||
/* Hmmm. The return value is not a pointer. If the type is a value
|
||||
or reference. We're going to chase it to see if another operator->()
|
||||
can be found */
|
||||
|
||||
if ((SwigType_check_decl(type,"")) || (SwigType_check_decl(type,"r."))) {
|
||||
Node *nn = Swig_symbol_clookup((char*)"operator ->", Getattr(sc,"symtab"));
|
||||
if (nn) {
|
||||
sn = nn;
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
virtual int constructorDeclaration(Node *n) {
|
||||
if (!inclass) return SWIG_OK;
|
||||
Parm *parms = Getattr(n,"parms");
|
||||
|
||||
mark_exception_classes(Getattr(n,"throws"));
|
||||
if (!extendmode) {
|
||||
if (!ParmList_numrequired(parms)) {
|
||||
/* Class does define a default constructor */
|
||||
/* However, we had better see where it is defined */
|
||||
if (cplus_mode == PUBLIC) {
|
||||
Setattr(inclass,"allocate:default_constructor","1");
|
||||
} else if (cplus_mode == PROTECTED) {
|
||||
Setattr(inclass,"allocate:default_base_constructor","1");
|
||||
}
|
||||
}
|
||||
/* Class defines some kind of constructor. May or may not be public */
|
||||
Setattr(inclass,"allocate:has_constructor","1");
|
||||
if (cplus_mode == PUBLIC) {
|
||||
Setattr(inclass,"allocate:public_constructor","1");
|
||||
}
|
||||
}
|
||||
|
||||
/* See if this is a copy constructor */
|
||||
if (parms && (ParmList_numrequired(parms) == 1)) {
|
||||
/* Look for a few cases. X(const X &), X(X &), X(X *) */
|
||||
|
||||
String *cc = NewStringf("r.q(const).%s", Getattr(inclass,"name"));
|
||||
if (Strcmp(cc,Getattr(parms,"type")) == 0) {
|
||||
Setattr(n,"copy_constructor","1");
|
||||
}
|
||||
Delete(cc);
|
||||
cc = NewStringf("r.%s", Getattr(inclass,"name"));
|
||||
if (Strcmp(cc,Getattr(parms,"type")) == 0) {
|
||||
Setattr(n,"copy_constructor","1");
|
||||
}
|
||||
Delete(cc);
|
||||
cc = NewStringf("p.%s", Getattr(inclass,"name"));
|
||||
String *ty = SwigType_strip_qualifiers(Getattr(parms,"type"));
|
||||
if (Strcmp(cc,ty) == 0) {
|
||||
Setattr(n,"copy_constructor","1");
|
||||
}
|
||||
Delete(cc);
|
||||
Delete(ty);
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
virtual int destructorDeclaration(Node *n) {
|
||||
if (!inclass) return SWIG_OK;
|
||||
if (!extendmode) {
|
||||
Setattr(inclass,"allocate:has_destructor","1");
|
||||
if (cplus_mode == PUBLIC) {
|
||||
Setattr(inclass,"allocate:default_destructor","1");
|
||||
} else if (cplus_mode == PROTECTED) {
|
||||
Setattr(inclass,"allocate:default_base_destructor","1");
|
||||
}
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
};
|
||||
|
||||
void Swig_default_allocators(Node *n) {
|
||||
if (!n) return;
|
||||
Allocate *a = new Allocate;
|
||||
a->top(n);
|
||||
delete a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
415
SWIG/Source/Modules1.1/browser.cxx
Normal file
415
SWIG/Source/Modules1.1/browser.cxx
Normal file
|
|
@ -0,0 +1,415 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* browser.cxx
|
||||
*
|
||||
* A web-base parse tree browser using SWILL. This is an optional
|
||||
* feature that's normally disabled.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 2002. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char cvsroot_browser_cxx[] = "$Header$";
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
#ifdef SWIG_SWILL
|
||||
extern "C" {
|
||||
#include "swill.h"
|
||||
}
|
||||
|
||||
static FILE *out = 0;
|
||||
static Node *view_top = 0;
|
||||
|
||||
class Browser : public Dispatcher {
|
||||
void show_checkbox(Node *t, Node *n) {
|
||||
int v = 0;
|
||||
if (Getmeta(n,"visible")) {
|
||||
v = 1;
|
||||
}
|
||||
if (v) {
|
||||
Printf(out,"<a name=\"n%x\"></a>[<a href=\"hide.html?node=0x%x&hn=0x%x#n%x\">-</a>] ", n, t, n,n);
|
||||
} else {
|
||||
Printf(out,"<a name=\"n%x\"></a>[<a href=\"show.html?node=0x%x&hn=0x%x#n%x\">+</a>] ", n, t, n,n);
|
||||
}
|
||||
}
|
||||
void show_attributes(Node *obj) {
|
||||
if (!Getmeta(obj,"visible")) return;
|
||||
String *os = NewString("");
|
||||
String *k;
|
||||
k = Firstkey(obj);
|
||||
while (k) {
|
||||
if ((Cmp(k,"nodeType") == 0) || (Cmp(k,"firstChild") == 0) || (Cmp(k,"lastChild") == 0) ||
|
||||
(Cmp(k,"parentNode") == 0) || (Cmp(k,"nextSibling") == 0) ||
|
||||
(Cmp(k,"previousSibling") == 0) || (*(Char(k)) == '$')) {
|
||||
/* Do nothing */
|
||||
} else if (Cmp(k,"parms") == 0) {
|
||||
String *o = NewString("");
|
||||
Printf(o,"%s", ParmList_protostr(Getattr(obj,k)));
|
||||
Replaceall(o,"&","&");
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
118
SWIG/Source/Modules1.1/contract.cxx
Normal file
118
SWIG/Source/Modules1.1/contract.cxx
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* contract.cxx
|
||||
*
|
||||
* Experimental support for contracts
|
||||
*
|
||||
* Author(s) : Aquinas Hobor (aahobor@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char cvsroot_contract_cxx[] = "$Header$";
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
class Contracts : public Dispatcher {
|
||||
|
||||
public:
|
||||
virtual int top(Node *n) {
|
||||
emit_children(n);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
virtual int importDirective(Node *n) { return emit_children(n); }
|
||||
virtual int includeDirective(Node *n) { return emit_children(n); } // ?
|
||||
virtual int externDeclaration(Node *n) { return emit_children(n); }
|
||||
|
||||
String * strParms(ParmList *l) {
|
||||
int comma = 0;
|
||||
int i = 0;
|
||||
Parm *p = l;
|
||||
SwigType *pt;
|
||||
String * returns = NewString("");
|
||||
while(p) {
|
||||
String *pname;
|
||||
pt = Getattr(p,"type");
|
||||
if ((SwigType_type(pt) != T_VOID)) {
|
||||
if (comma) Printf(returns,",");
|
||||
pname = Swig_cparm_name(p,i);
|
||||
Printf(returns,"%s",SwigType_rcaststr(pt,pname));
|
||||
comma = 1;
|
||||
i++;
|
||||
}
|
||||
p = nextSibling(p);
|
||||
}
|
||||
return returns;
|
||||
}
|
||||
|
||||
virtual int cDeclaration(Node *n) {
|
||||
String *name = Getattr(n,"name");
|
||||
String *k = Getattr(n,"feature:contract");
|
||||
|
||||
if(k)
|
||||
{
|
||||
/* make the names */
|
||||
ParmList *l = Getmeta(k,"parms");
|
||||
String *params = ParmList_str(l);
|
||||
String *transformed = strParms(l);
|
||||
if(DohStrcmp(params,"")==0) {
|
||||
DohDelete(params);
|
||||
params = DohNewString("void");
|
||||
}
|
||||
String *contractName = DohNewStringf("__SWIG_precontract_%s",name);
|
||||
|
||||
/* make the contract */
|
||||
String *contract = DohNewStringf("int %s(%s,int rt[2])\n{\n",contractName,params);
|
||||
SwigScanner * ss = NewSwigScanner();
|
||||
SwigScanner_clear(ss);
|
||||
SwigScanner_push(ss,Copy(k));
|
||||
SwigScanner_token(ss); // Get rid of the '{' at the begining
|
||||
|
||||
/* loop over the clauses */
|
||||
int clauseNum = 1;
|
||||
int token = -1;
|
||||
while(1) {
|
||||
String *clause = DohNewString(""); /*BUG -- should free*/
|
||||
while((token=SwigScanner_token(ss))) {
|
||||
if ((token==SWIG_TOKEN_SEMI)||(token==SWIG_TOKEN_RBRACE))
|
||||
break;
|
||||
// if (token != SWIG_TOKEN_ENDLINE)
|
||||
Printf(clause,"%s",SwigScanner_text(ss));
|
||||
}
|
||||
if (DohStrcmp(clause,"\n") != 0) {
|
||||
Printf(contract,"if (!(%s",clause);
|
||||
Printf(contract,")) {\nrt[0]=__LINE__;\nrt[1]=%i;\nreturn 1;\n}\n",clauseNum);
|
||||
}
|
||||
if(token==SWIG_TOKEN_RBRACE) break;
|
||||
clauseNum++;
|
||||
}
|
||||
|
||||
/* finish it off and attach it to the main tree */
|
||||
Printf(contract,"return 0;\n}\n");
|
||||
Setattr(n,"wrap:code",contract); /*BUG -- WHAT IF SOMETHING IS ALREADY THERE*/
|
||||
|
||||
/* Generate the calling code */
|
||||
String * calling = DohNewString("{\nint cfail[2];\nchar message[255];\n");
|
||||
Printf(calling,"if (%s(%s,cfail)) {\n",contractName,transformed);
|
||||
Printf(calling,"sprintf(message,\"Contract %s failed on clause %%i (line %%i)!\",cfail[1],cfail[0]);\n",contractName);
|
||||
Printf(calling,"PyErr_SetString(PyExc_Exception,message);return NULL;\n}\n");
|
||||
Printf(calling,"}\n");
|
||||
/* Setattr(n,"feature:preassert",calling); */
|
||||
}
|
||||
/*There are two attributes "feature:preassert" and "feature:postassert".*/
|
||||
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void Swig_contracts(Node *n) {
|
||||
Printf(stdout,"Applying contracts (experimental v0.09)\n");
|
||||
|
||||
Contracts *a = new Contracts;
|
||||
a->top(n);
|
||||
delete a;
|
||||
|
||||
}
|
||||
|
|
@ -12,26 +12,11 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#include "swig11.h"
|
||||
#include "swigmod.h"
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_emit_cxx[] = "$Header$";
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* new_create_function()
|
||||
*
|
||||
* Create a new function
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void new_create_function(char *name, char *iname, SwigType *type, ParmList *l) {
|
||||
Hash *h;
|
||||
h = NewHash();
|
||||
Setattr(h,"name",name);
|
||||
Setattr(h,"scriptname",iname);
|
||||
Setattr(h,"type",type);
|
||||
Setattr(h,"parms",l);
|
||||
lang->function(h);
|
||||
Delete(h);
|
||||
}
|
||||
extern SwigType *cplus_value_type(SwigType *t);
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* emit_args()
|
||||
|
|
@ -43,210 +28,425 @@ void new_create_function(char *name, char *iname, SwigType *type, ParmList *l) {
|
|||
* Returns the number of parameters associated with a function.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int emit_args(DOH *node, Wrapper *f) {
|
||||
void emit_args(SwigType *rt, ParmList *l, Wrapper *f) {
|
||||
|
||||
SwigType *rt;
|
||||
ParmList *l;
|
||||
Parm *p;
|
||||
int i;
|
||||
char *tm;
|
||||
SwigType *pt;
|
||||
DOHString *pvalue;
|
||||
DOHString *pname;
|
||||
DOHString *lname;
|
||||
|
||||
rt = Getattr(node,"type");
|
||||
l = Getattr(node,"parms");
|
||||
String *tm;
|
||||
|
||||
/* Emit function arguments */
|
||||
Swig_cargs(f, l);
|
||||
|
||||
i = 0;
|
||||
p = l;
|
||||
while (p != 0) {
|
||||
lname = Getlname(p);
|
||||
pt = Gettype(p);
|
||||
pname = Getname(p);
|
||||
pvalue = Getvalue(p);
|
||||
|
||||
tm = Swig_typemap_lookup((char*)"arginit",pt,pname,(char*)"",lname,f);
|
||||
if (tm) {
|
||||
Printv(f,tm,"\n",0);
|
||||
}
|
||||
/* Check for ignore or default typemaps */
|
||||
tm = Swig_typemap_lookup((char*)"default",pt,pname,(char*)"",lname,f);
|
||||
if (tm) {
|
||||
Printv(f,tm,"\n",0);
|
||||
}
|
||||
tm = Swig_typemap_lookup((char*)"ignore",pt,pname,(char*)"",lname,f);
|
||||
if (tm) {
|
||||
Printv(f,tm,"\n",0);
|
||||
Setignore(p,1);
|
||||
}
|
||||
i++;
|
||||
p = Getnext(p);
|
||||
}
|
||||
return(i);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int emit_func_call(char *decl, DataType *t, ParmList *l, Wrapper*f)
|
||||
*
|
||||
* Emits code for a function call (new version).
|
||||
*
|
||||
* Exception handling support :
|
||||
*
|
||||
* - This function checks to see if any sort of exception mechanism
|
||||
* has been defined. If so, we emit the function call in an exception
|
||||
* handling block.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *fcall = 0;
|
||||
|
||||
void emit_set_action(DOHString_or_char *decl) {
|
||||
if (fcall) Delete (fcall);
|
||||
fcall = NewString(decl);
|
||||
}
|
||||
|
||||
void emit_func_call(DOH *node, Wrapper *f) {
|
||||
char *decl;
|
||||
SwigType *t;
|
||||
ParmList *l;
|
||||
char *tm;
|
||||
|
||||
decl = GetChar(node,"name");
|
||||
t = Getattr(node,"type");
|
||||
l = Getattr(node,"parms");
|
||||
|
||||
if ((tm = Swig_typemap_lookup((char*)"except",t,decl,(char*)"result",(char*)"",0))) {
|
||||
Printv(f,tm,0);
|
||||
Replace(f,"$name",decl,DOH_REPLACE_ANY);
|
||||
} else if ((tm = Swig_except_lookup())) {
|
||||
Printv(f,tm,0);
|
||||
Replace(f,"$name",decl,DOH_REPLACE_ANY);
|
||||
} else {
|
||||
Printv(f,"$function",0);
|
||||
}
|
||||
|
||||
if (!fcall) fcall = NewString(Swig_cfunction_call(decl,l));
|
||||
|
||||
if (CPlusPlus) {
|
||||
Swig_cppresult(f, t, (char*)"result", Char(fcall));
|
||||
} else {
|
||||
Swig_cresult(f, t, (char*)"result", Char(fcall));
|
||||
}
|
||||
Delete(fcall);
|
||||
fcall = 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void emit_set_get()
|
||||
*
|
||||
* Emits a pair of functions to set/get the value of a variable. This is
|
||||
* only used in the event the target language can't provide variable linking
|
||||
* on its own.
|
||||
*
|
||||
* double foo;
|
||||
*
|
||||
* Gets translated into the following :
|
||||
*
|
||||
* double foo_set(double x) {
|
||||
* return foo = x;
|
||||
* }
|
||||
*
|
||||
* double foo_get() {
|
||||
* return foo;
|
||||
* }
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* How to assign a C allocated string */
|
||||
|
||||
static char *c_str = (char *)"\
|
||||
if ($target) free($target);\n\
|
||||
$target = ($rtype) malloc(strlen($source)+1);\n\
|
||||
strcpy((char *)$target,$source);\n\
|
||||
return $ltype $target;\n";
|
||||
|
||||
/* How to assign a C allocated string */
|
||||
|
||||
static char *cpp_str = (char *)"\
|
||||
if ($target) delete [] $target;\n\
|
||||
$target = ($rtype) (new char[strlen($source)+1]);\n\
|
||||
strcpy((char *)$target,$source);\n\
|
||||
return ($ltype) $target;\n;";
|
||||
|
||||
|
||||
void emit_set_get(DOH *node) {
|
||||
char *name, *iname;
|
||||
SwigType *t;
|
||||
Wrapper *w;
|
||||
DOHString *new_iname;
|
||||
char *code = 0;
|
||||
|
||||
name = GetChar(node,"name");
|
||||
iname = GetChar(node,"iname");
|
||||
t = Getattr(node,"type");
|
||||
|
||||
/* First write a function to set the variable of the variable */
|
||||
if (!ReadOnly) {
|
||||
|
||||
if (SwigType_type(t) == T_STRING) {
|
||||
if (CPlusPlus)
|
||||
code = cpp_str;
|
||||
else
|
||||
code = c_str;
|
||||
}
|
||||
w = Swig_cvarset_wrapper(name, t, code);
|
||||
Printf(f_header,"%s", w);
|
||||
new_iname = Swig_name_set(iname);
|
||||
DohIncref(new_iname);
|
||||
new_create_function(GetChar(w,"name"), Char(new_iname), Gettype(w), Getparms(w));
|
||||
Delete(new_iname);
|
||||
Delete(w);
|
||||
}
|
||||
|
||||
w = Swig_cvarget_wrapper(name,t,0);
|
||||
Printf(f_header,"%s", w);
|
||||
new_iname = Swig_name_get(iname);
|
||||
DohIncref(new_iname);
|
||||
new_create_function(GetChar(w,"name"), Char(new_iname), Gettype(w), Getparms(w));
|
||||
Delete(new_iname);
|
||||
Delete(w);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* int check_numopt()
|
||||
*
|
||||
* Gets the number of optional arguments for a ParmList.
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
int check_numopt(ParmList *p) {
|
||||
int n = 0;
|
||||
int i = 0;
|
||||
int state = 0;
|
||||
|
||||
for (;p; p = Getnext(p),i++) {
|
||||
SwigType *pt = Gettype(p);
|
||||
String *pn = Getname(p);
|
||||
if (Getvalue(p)) {
|
||||
n++;
|
||||
state = 1;
|
||||
} else if (Swig_typemap_search((char*)"default",pt,pn)) {
|
||||
n++;
|
||||
state = 1;
|
||||
} else if (Swig_typemap_search((char*)"ignore",pt,pn)) {
|
||||
n++;
|
||||
/* 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 {
|
||||
if (state) {
|
||||
Printf(stderr,"%s:%d. Argument %d must have a default value!\n", Getfile(p), Getline(p),i+1);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
return n;
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,909 +0,0 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* generate.cxx
|
||||
*
|
||||
* This file manages the code generation process and serves as a bridge between
|
||||
* the new SWIG parser and the old set of C++-based language modules.
|
||||
*
|
||||
* 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.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#include "swig11.h"
|
||||
|
||||
static char cvstag[] = "$Header$";
|
||||
|
||||
int ReadOnly = 0;
|
||||
int WrapExtern = 0;
|
||||
|
||||
/* Access permissions: public, private, protected */
|
||||
enum { PUBLIC, PRIVATE, PROTECTED };
|
||||
int Access = PUBLIC;
|
||||
|
||||
/* Miscellaneous modes */
|
||||
int Native = 0;
|
||||
|
||||
/* This function tries to locate the module name within the parse tree */
|
||||
static String *find_module(DOH *node) {
|
||||
DOH *n;
|
||||
|
||||
if (!node) return 0;
|
||||
n = node;
|
||||
while (n) {
|
||||
if (Swig_tag_check(n,"module")) {
|
||||
return Getname(n);
|
||||
}
|
||||
if (Swig_tag_check(n,"file")) {
|
||||
String *ty;
|
||||
ty = Getattr(n,"type");
|
||||
if (Cmp(ty,"include") == 0) {
|
||||
DOH *m;
|
||||
/* Might be in an include file */
|
||||
m = find_module(Getchild(n));
|
||||
if (m) return m;
|
||||
}
|
||||
}
|
||||
n = Getnext(n);
|
||||
}
|
||||
return find_module(Getchild(node));
|
||||
}
|
||||
|
||||
/* This helper function emits external function declarations */
|
||||
static
|
||||
void emit_extern_func(DOH *node, File *f) {
|
||||
Parm *p;
|
||||
SwigType *tc;
|
||||
char *c;
|
||||
String *storage;
|
||||
storage = Getattr(node,"storage");
|
||||
if (!storage) return;
|
||||
c = Char(storage);
|
||||
if (strncmp(c,"extern",6) == 0) {
|
||||
List *tl = NewList();
|
||||
p = Getparms(node);
|
||||
while (p) {
|
||||
Append(tl,Gettype(p));
|
||||
p = Getnext(p);
|
||||
}
|
||||
tc = Copy(Gettype(node));
|
||||
SwigType_add_function(tc,tl);
|
||||
Printf(f,"%s %s;\n", storage, SwigType_str(tc,Getname(node)));
|
||||
Delete(tc);
|
||||
Delete(tl);
|
||||
}
|
||||
}
|
||||
|
||||
/* Test if static */
|
||||
static int
|
||||
check_static(DOH *node) {
|
||||
String *storage = Getattr(node,"storage");
|
||||
if (!storage) return 0;
|
||||
if (Cmp(storage,"static") == 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Test if extern */
|
||||
static int
|
||||
check_extern(DOH *node) {
|
||||
String *storage = Getattr(node,"storage");
|
||||
if (!storage) return 0;
|
||||
if (strncmp(Char(storage),"extern",6) == 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static String *new_name = 0;
|
||||
|
||||
/* Handle renaming */
|
||||
static
|
||||
void set_scriptname(DOH *node) {
|
||||
if (new_name) {
|
||||
Setattr(node,"scriptname",new_name);
|
||||
} else {
|
||||
String *aname = Getattr(node,"altname");
|
||||
if (aname) {
|
||||
Setattr(node,"scriptname",aname);
|
||||
} else {
|
||||
Setattr(node,"scriptname", Getname(node));
|
||||
}
|
||||
}
|
||||
new_name = 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* C++ Support
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *class_hash = 0; /* Hash table of classes that have been seen so far */
|
||||
static DOH *current_class = 0; /* Set when wrapping a class */
|
||||
static DOH *class_name = 0; /* Real name of current class */
|
||||
static DOH *class_types = 0; /* Types defined within this class */
|
||||
static String *construct_name = 0; /* Expected name of a constructor */
|
||||
int AddMethods = 0; /* Set when in addmethods mode */
|
||||
int Abstract = 0; /* Set when the class is determined to be abstract */
|
||||
static int have_destructor = 0;
|
||||
static int have_constructor = 0;
|
||||
|
||||
/* Check for abstract classes */
|
||||
|
||||
int cplus_check_abstract(DOH *node) {
|
||||
while (node) {
|
||||
if (Getattr(node,"abstract")) return 1;
|
||||
node = Getnext(node);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Given a class object, this function builds an internal symbol table */
|
||||
void cplus_build_symbols(DOH *node) {
|
||||
Hash *sym;
|
||||
DOH *c;
|
||||
sym = Getattr(node,"symbols");
|
||||
if (!sym) {
|
||||
sym = NewHash();
|
||||
Setattr(node,"symbols",sym);
|
||||
}
|
||||
c = Getchild(node);
|
||||
while (c) {
|
||||
String *name = Getname(c);
|
||||
String *tag = Gettag(c);
|
||||
if (Cmp(tag,"c:destructor") == 0) {
|
||||
name = NewStringf("~%s",name);
|
||||
}
|
||||
if (name) {
|
||||
DOH *pnode = Getattr(sym,name);
|
||||
if (pnode) {
|
||||
Printf(stderr,"%s:%d. '%s' redefined. Previous definition at %s:%d.\n",
|
||||
Getfile(c),Getline(c), name, Getfile(pnode), Getline(pnode));
|
||||
} else {
|
||||
Setattr(sym,name,c);
|
||||
}
|
||||
}
|
||||
c = Getnext(c);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Inherit certain types of declarations from another class */
|
||||
|
||||
|
||||
|
||||
/* Add a class type */
|
||||
static void
|
||||
class_addtype(String *name, String *cname) {
|
||||
String *s;
|
||||
if (!cname)
|
||||
s = NewStringf("%s::%s", class_name, name);
|
||||
else
|
||||
s = NewStringf("%s::%s", cname, name);
|
||||
|
||||
if (!class_types) class_types = NewHash();
|
||||
Setattr(class_types,name,s);
|
||||
}
|
||||
|
||||
/* Updates a type with a fully qualified version */
|
||||
static void
|
||||
class_update_type(String *type) {
|
||||
String *base, *rep;
|
||||
if (!type) return;
|
||||
base = SwigType_base(type);
|
||||
if (!class_types) return;
|
||||
rep = Getattr(class_types,base);
|
||||
if (rep) {
|
||||
SwigType_setbase(type,rep);
|
||||
/* Printf(stdout,"updated type = '%s'\n", type); */
|
||||
}
|
||||
}
|
||||
|
||||
/* Updates a list of parms with fully qualified names */
|
||||
static void
|
||||
class_update_parms(ParmList *p) {
|
||||
while (p) {
|
||||
class_update_type(Gettype(p));
|
||||
p = Getnext(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Traverse the inheritance hierarchy of a class */
|
||||
void
|
||||
cplus_walk_inherit(DOH *cls, void (*action)(DOH *base, void *clientdata), void *clientdata) {
|
||||
DOH *base;
|
||||
List *bases;
|
||||
int i, nbase;
|
||||
|
||||
bases = Getattr(cls,"bases");
|
||||
if (bases) {
|
||||
nbase = Len(bases);
|
||||
for (i = 0; i < nbase; i++) {
|
||||
base = Getattr(class_hash, Getitem(bases,i));
|
||||
if (base) {
|
||||
(*action)(base,clientdata);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Action for inheriting type definitions */
|
||||
static void inherit_types(DOH *cls, void *clientdata) {
|
||||
DOH *ty;
|
||||
ty = Getattr(cls,"types");
|
||||
if (ty) {
|
||||
String *key;
|
||||
SwigType_merge_scope(ty,0);
|
||||
for (key = Firstkey(ty); key; key = Nextkey(ty)) {
|
||||
class_addtype(key, Getname(cls));
|
||||
}
|
||||
}
|
||||
cplus_walk_inherit(cls,inherit_types,clientdata);
|
||||
}
|
||||
|
||||
/* Action for inheriting typemaps */
|
||||
static void inherit_typemaps(DOH *cls, void *clientdata) {
|
||||
DOH *ty;
|
||||
|
||||
cplus_walk_inherit(cls,inherit_typemaps,clientdata);
|
||||
ty = Getattr(cls,"typemaps");
|
||||
if (ty) {
|
||||
if (!clientdata)
|
||||
Swig_typemap_new_scope(ty);
|
||||
else
|
||||
Swig_typemap_pop_scope();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
int swig11_unknown(DOH *node, void *clientdata) {
|
||||
Printf(stdout,"::: Unknown tag - '%s'\n", Getattr(node,"tag"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int swig11_nil(DOH *node, void *clientdata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_file()
|
||||
*
|
||||
* File inclusion directives. %include, %extern, and %import.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_file(DOH *node, void *clientdata) {
|
||||
DOH *c;
|
||||
String *type;
|
||||
int old_we = WrapExtern;
|
||||
|
||||
type = Getattr(node,"type");
|
||||
if ((Cmp(type, "extern") == 0) || (Cmp(type,"import") == 0)) {
|
||||
WrapExtern = 1;
|
||||
}
|
||||
c = Getchild(node);
|
||||
if (Cmp(type,"import") == 0) {
|
||||
/* If importing a module, we try to find the module name and pass it to
|
||||
the language modules */
|
||||
String *modname;
|
||||
modname = find_module(c);
|
||||
if (modname) {
|
||||
lang->import(modname);
|
||||
}
|
||||
}
|
||||
Swig_emit_all(c,clientdata);
|
||||
WrapExtern = old_we;
|
||||
return 0;
|
||||
}
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_scope()
|
||||
*
|
||||
* Handle the %scope directive. This is a new feature not present in SWIG1.1.
|
||||
* Creates a new typemap scope and has other side effects.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_scope(DOH *node, void *clientdata) {
|
||||
DOH *c;
|
||||
String *name;
|
||||
|
||||
c = Getchild(node);
|
||||
name = Getname(node);
|
||||
|
||||
Swig_typemap_new_scope(0);
|
||||
if (name) {
|
||||
if (Cmp(name,"native") == 0) {
|
||||
int oldnative = Native;
|
||||
Native = 1;
|
||||
Swig_emit_all(c,clientdata);
|
||||
Native = oldnative;
|
||||
} else if (Cmp(name,"readonly") == 0) {
|
||||
int oldro = ReadOnly;
|
||||
ReadOnly = 1;
|
||||
Swig_emit_all(c,clientdata);
|
||||
ReadOnly = oldro;
|
||||
} else {
|
||||
Swig_emit_all(c,clientdata);
|
||||
}
|
||||
}
|
||||
Hash *scp = Swig_typemap_pop_scope();
|
||||
Setattr(node,"typemaps", scp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_insert()
|
||||
*
|
||||
* Code insertion with various %{ %} directives.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_insert(DOH *node, void *clientdata) {
|
||||
String *section;
|
||||
String *filename;
|
||||
String *code;
|
||||
File *out;
|
||||
|
||||
if (WrapExtern) return 0;
|
||||
|
||||
section = Getattr(node,"section");
|
||||
if (!section) {
|
||||
section = (void *) "header";
|
||||
}
|
||||
out = Swig_filebyname(section);
|
||||
if (!out) {
|
||||
Printf(stderr,"%s:%d. Can't insert code into unknown section '%s'\n", Getfile(node), Getline(node), section);
|
||||
return 0;
|
||||
}
|
||||
filename = Getattr(node,"filename");
|
||||
if (filename) {
|
||||
/* The user is inserting the contents of a file */
|
||||
if (Swig_insert_file(filename,out) < 0) {
|
||||
Printf(stderr,"%s:%d. File '%s' not found.\n", Getfile(node), Getline(node), filename);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
code = Getattr(node,"code");
|
||||
if (code) {
|
||||
Printf(out,"%s",code);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_pragma()
|
||||
*
|
||||
* %pragma directive.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_pragma(DOH *node, void *clientdata) {
|
||||
String *name;
|
||||
String *value;
|
||||
|
||||
if (WrapExtern) return 0;
|
||||
|
||||
name = Getname(node);
|
||||
value = Getvalue(node);
|
||||
|
||||
if (Cmp(name,"readonly") == 0) {
|
||||
ReadOnly = 1;
|
||||
} else if (Cmp(name,"readwrite") == 0) {
|
||||
ReadOnly = 0;
|
||||
} else if (Cmp(name,"name") == 0) {
|
||||
new_name = value;
|
||||
}
|
||||
lang->pragma(node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_typemap()
|
||||
*
|
||||
* Handle the %typemap directive.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_typemap(DOH *node, void *clientdata) {
|
||||
String *name;
|
||||
SwigType *type;
|
||||
String *code;
|
||||
DOH *parms;
|
||||
String *method;
|
||||
|
||||
if (WrapExtern) return 0;
|
||||
method = Getattr(node,"method");
|
||||
name = Getname(node);
|
||||
type = Gettype(node);
|
||||
code = Getattr(node,"code");
|
||||
parms = Getparms(node);
|
||||
|
||||
if (current_class) {
|
||||
class_update_type(type);
|
||||
class_update_type(parms);
|
||||
}
|
||||
|
||||
if (code) {
|
||||
Swig_typemap_register(method,type,name,code,parms);
|
||||
} else {
|
||||
String *srcname;
|
||||
String *srctype;
|
||||
srcname = Getattr(node,"srcname");
|
||||
srctype = Getattr(node,"srctype");
|
||||
if (srcname && srctype) {
|
||||
Swig_typemap_copy(method,srctype,srcname,type,name);
|
||||
} else {
|
||||
Swig_typemap_clear(method,type,name);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_apply()
|
||||
*
|
||||
* The %apply directive.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_apply(DOH *node, void *clientdata) {
|
||||
DOH *parms;
|
||||
String *name;
|
||||
SwigType *type;
|
||||
|
||||
if (WrapExtern) return 0;
|
||||
|
||||
name = Getname(node);
|
||||
type = Gettype(node);
|
||||
parms = Getparms(node);
|
||||
|
||||
while (parms) {
|
||||
Swig_typemap_apply(type,name,Gettype(parms),Getname(parms));
|
||||
parms = Getnext(parms);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_exception()
|
||||
*
|
||||
* The %except directive.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_exception(DOH *node, void *clientdata) {
|
||||
String *code = Getattr(node,"code");
|
||||
if (WrapExtern) return 0;
|
||||
if (code) {
|
||||
Swig_except_register(code);
|
||||
} else {
|
||||
Swig_except_clear();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_clear()
|
||||
*
|
||||
* The %clear directive.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_clear(DOH *node, void *clientdata) {
|
||||
DOH *parms = Getattr(node,"parms");
|
||||
if (WrapExtern) return 0;
|
||||
while (parms) {
|
||||
Swig_typemap_clear_apply(Gettype(parms),Getname(parms));
|
||||
parms = Getnext(parms);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_constant
|
||||
*
|
||||
* The %constant directive
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_constant(DOH *node, void *clientdata) {
|
||||
if (WrapExtern) return 0;
|
||||
if (Access != PUBLIC) return 0;
|
||||
|
||||
set_scriptname(node);
|
||||
lang->constant(node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_function()
|
||||
*
|
||||
* Emit a wrapper function.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_function(DOH *node, void *clientdata) {
|
||||
int is_static;
|
||||
if (WrapExtern) return 0;
|
||||
if (Access != PUBLIC) return 0;
|
||||
|
||||
is_static = check_static(node);
|
||||
set_scriptname(node);
|
||||
|
||||
/* Will need some kind of class check in here */
|
||||
|
||||
if (current_class) {
|
||||
/* Function has been declared inside a class definition. */
|
||||
class_update_parms(Getparms(node));
|
||||
class_update_type(Gettype(node));
|
||||
String *name = Getname(node);
|
||||
if (Cmp(name,construct_name) == 0) {
|
||||
have_constructor =1;
|
||||
if (!Abstract) {
|
||||
lang->cpp_constructor(node);
|
||||
}
|
||||
} else {
|
||||
if (is_static) lang->cpp_staticfunction(node);
|
||||
else lang->cpp_memberfunction(node);
|
||||
}
|
||||
} else {
|
||||
|
||||
/* Can't wrap a static function. Oh well. */
|
||||
if (is_static) return 0;
|
||||
emit_extern_func(node,f_header);
|
||||
|
||||
if (Native) {
|
||||
lang->nativefunction(node);
|
||||
} else {
|
||||
lang->function(node);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_variable()
|
||||
*
|
||||
* Wrap a variable.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_variable(DOH *node, void *clientdata) {
|
||||
int is_static;
|
||||
SwigType *type;
|
||||
|
||||
if (WrapExtern) return 0;
|
||||
if (Access != PUBLIC) return 0;
|
||||
|
||||
if (Native) {
|
||||
Printf(stderr,"%s:%d. Can't wrap variables in %%native mode (ignored).\n", Getfile(node),Getline(node));
|
||||
return 0;
|
||||
}
|
||||
|
||||
type = Gettype(node);
|
||||
|
||||
is_static = check_static(node);
|
||||
set_scriptname(node);
|
||||
|
||||
if (current_class) {
|
||||
/* Inside a class definition */
|
||||
if (is_static) {
|
||||
lang->cpp_staticvariable(node);
|
||||
} else {
|
||||
lang->cpp_variable(node);
|
||||
}
|
||||
} else {
|
||||
if (check_extern(node)) {
|
||||
Printf(f_header,"extern %s;\n", SwigType_str(type, Getname(node)));
|
||||
}
|
||||
if (is_static) return 0;
|
||||
|
||||
if (SwigType_isconst(type)) {
|
||||
swig11_constant(node,clientdata);
|
||||
} else {
|
||||
lang->variable(node);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_typedef()
|
||||
*
|
||||
* Handle a typedef declaration.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_typedef(DOH *node, void *clientdata) {
|
||||
String *name;
|
||||
SwigType *type;
|
||||
|
||||
type = Gettype(node);
|
||||
name = Getname(node);
|
||||
SwigType_typedef(type,name);
|
||||
|
||||
if (current_class) {
|
||||
class_addtype(name,0);
|
||||
}
|
||||
lang->add_typedef(type, Char(name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_enum()
|
||||
*
|
||||
* Support for enumerations.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_enum(DOH *node, void *clientdata) {
|
||||
DOH *c;
|
||||
String *name;
|
||||
if (WrapExtern) return 0;
|
||||
if (Access != PUBLIC) return 0;
|
||||
|
||||
name = Getname(node);
|
||||
if (name && CPlusPlus) {
|
||||
/* Add a typedef */
|
||||
String *t = NewStringf("enum %s", name);
|
||||
SwigType_typedef(t,name);
|
||||
class_addtype(name,0);
|
||||
Delete(t);
|
||||
}
|
||||
c = Getchild(node);
|
||||
Swig_emit_all(c,clientdata);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_enumvalue()
|
||||
*
|
||||
* Create a constant corresponding to an enum value.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
int swig11_enumvalue(DOH *node, void *clientdata) {
|
||||
set_scriptname(node);
|
||||
Setattr(node,"type","int"); /* Enums wrapped as ints */
|
||||
if (!Getvalue(node)) { /* If no value, use the name itself */
|
||||
if (class_name) {
|
||||
Setvalue(node,NewStringf("%s::%s",class_name, Getname(node)));
|
||||
} else {
|
||||
Setvalue(node,Getname(node));
|
||||
}
|
||||
}
|
||||
if (current_class) {
|
||||
lang->cpp_constant(node);
|
||||
} else {
|
||||
swig11_constant(node,clientdata);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_class()
|
||||
*
|
||||
* Wrapping of C++ classes
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_class(DOH *node, void *clientdata) {
|
||||
DOH *c;
|
||||
List *bases;
|
||||
|
||||
/* Save the class */
|
||||
String *name = Getname(node);
|
||||
Setattr(class_hash,name,node);
|
||||
if (WrapExtern) return 0;
|
||||
|
||||
if (Native) {
|
||||
Printf(stderr,"%s:%d. Can't wrap structures or classes in %%native mode (ignored).\n", Getfile(node),Getline(node));
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_scriptname(node);
|
||||
class_name = name;
|
||||
class_types = 0;
|
||||
|
||||
have_destructor = 0;
|
||||
have_constructor = 0;
|
||||
|
||||
/* Need to merge in data from other scopes. For typemaps, can include scopes
|
||||
for each base class one after the other. For types, need to merge type information */
|
||||
|
||||
SwigType_new_scope();
|
||||
if (name) {
|
||||
SwigType_set_scope_name(name);
|
||||
}
|
||||
|
||||
cplus_walk_inherit(node, inherit_types, 0);
|
||||
|
||||
/* Merge in typemaps */
|
||||
cplus_walk_inherit(node, inherit_typemaps, 0);
|
||||
|
||||
/* Create a typemap scope for this class */
|
||||
Swig_typemap_new_scope(0);
|
||||
|
||||
cplus_build_symbols(node);
|
||||
lang->cpp_open_class(node);
|
||||
current_class = node;
|
||||
|
||||
construct_name = Getname(node);
|
||||
if (!CPlusPlus) {
|
||||
String *altname = Getattr(node,"altname");
|
||||
if (altname) construct_name = altname;
|
||||
}
|
||||
|
||||
c = Getchild(node);
|
||||
Abstract = cplus_check_abstract(c);
|
||||
|
||||
Swig_emit_all(c,clientdata);
|
||||
|
||||
bases = Getattr(node,"bases");
|
||||
if (bases) {
|
||||
String *b;
|
||||
lang->cpp_inherit(bases);
|
||||
b = Firstitem(bases);
|
||||
while (b) {
|
||||
SwigType_inherit(Getname(current_class),b);
|
||||
b = Nextitem(bases);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for constructors and destructors */
|
||||
|
||||
if (CPlusPlus) {
|
||||
if (!have_constructor && !Abstract) {
|
||||
DOH *cn = NewHash();
|
||||
Setname(cn, Getname(current_class));
|
||||
Setattr(cn,"scriptname", Getname(current_class));
|
||||
lang->cpp_constructor(cn);
|
||||
}
|
||||
if (!have_destructor) {
|
||||
DOH *dn = NewHash();
|
||||
Setname(dn, Getname(current_class));
|
||||
Setattr(dn,"scriptname", Getname(current_class));
|
||||
lang->cpp_destructor(dn);
|
||||
}
|
||||
}
|
||||
|
||||
lang->cpp_close_class();
|
||||
|
||||
/* Pop the type scope and save with the class */
|
||||
|
||||
Hash *scp = SwigType_pop_scope();
|
||||
Setattr(node,"types",scp);
|
||||
|
||||
scp = Swig_typemap_pop_scope();
|
||||
Setattr(node,"typemaps",scp);
|
||||
Setattr(node,"classtypes",class_types);
|
||||
|
||||
/* Pop off all of the typemap scopes we added */
|
||||
cplus_walk_inherit(node,inherit_typemaps, (void *) 1);
|
||||
|
||||
current_class = 0;
|
||||
construct_name = 0;
|
||||
class_name = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_classdecl()
|
||||
*
|
||||
* Empty class declaration. Used to register classes with language modules.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_classdecl(DOH *node, void *clientdata) {
|
||||
if (WrapExtern) return 0;
|
||||
set_scriptname(node);
|
||||
|
||||
lang->cpp_class_decl(node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int swig11_addmethods(DOH *node, void *clientdata) {
|
||||
DOH *c;
|
||||
int oldaddmethods = AddMethods;
|
||||
if (WrapExtern) return 0;
|
||||
if (!current_class) {
|
||||
Printf(stderr,"%s:%d. %%addmethods ignored (does not appear inside a class).\n", Getfile(node),Getline(node));
|
||||
return 0;
|
||||
}
|
||||
AddMethods = 1;
|
||||
c = Getchild(node);
|
||||
Swig_emit_all(c,clientdata);
|
||||
AddMethods = oldaddmethods;;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_destructor()
|
||||
*
|
||||
* C++ Destructor
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_destructor(DOH *node, void *clientdata) {
|
||||
if (WrapExtern) return 0;
|
||||
if (Access != PUBLIC) return 0;
|
||||
if (!current_class) return 0;
|
||||
|
||||
set_scriptname(node);
|
||||
lang->cpp_destructor(node);
|
||||
have_destructor = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_access()
|
||||
*
|
||||
* Handle an access specifier (public, private, protected)
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_access(DOH *node, void *clientdata) {
|
||||
String *name = Getname(node);
|
||||
if (Cmp(name,"public") == 0) Access = PUBLIC;
|
||||
else if (Cmp(name,"private") == 0) Access = PRIVATE;
|
||||
else if (Cmp(name,"protected") == 0) Access = PROTECTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig11_types()
|
||||
*
|
||||
* Handle the types directive.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int swig11_types(DOH *node, void *clientdata) {
|
||||
Parm *p;
|
||||
p = Getparms(node);
|
||||
while (p) {
|
||||
SwigType *t = Gettype(p);
|
||||
SwigType_remember(t);
|
||||
p = Getnext(p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SwigRule rules[] = {
|
||||
{ "file", swig11_file},
|
||||
{ "scope", swig11_scope},
|
||||
{ "insert", swig11_insert},
|
||||
{ "pragma", swig11_pragma},
|
||||
{ "typemap", swig11_typemap},
|
||||
{ "apply", swig11_apply},
|
||||
{ "exception", swig11_exception},
|
||||
{ "clear", swig11_clear},
|
||||
{ "addmethods", swig11_addmethods},
|
||||
{ "constant", swig11_constant},
|
||||
{ "function", swig11_function},
|
||||
{ "variable", swig11_variable},
|
||||
{ "typedef", swig11_typedef},
|
||||
{ "enum", swig11_enum},
|
||||
{ "enumvalue", swig11_enumvalue},
|
||||
{ "class", swig11_class},
|
||||
{ "classdecl", swig11_classdecl},
|
||||
{ "destructor", swig11_destructor},
|
||||
{ "access", swig11_access},
|
||||
{ "types", swig11_types},
|
||||
{ "module", swig11_nil},
|
||||
{ "*", swig11_unknown},
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* generate()
|
||||
*
|
||||
* Called by the SWIG1.1 system to emit code
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void generate(DOH *node) {
|
||||
DOH *c;
|
||||
extern String *swig_module;
|
||||
|
||||
/* Initialize globals */
|
||||
class_hash = NewHash();
|
||||
|
||||
Swig_add_rules(rules);
|
||||
c = Getattr(node,"child");
|
||||
|
||||
/* Find the module name */
|
||||
if (!swig_module) {
|
||||
swig_module = find_module(c);
|
||||
}
|
||||
if (!swig_module) {
|
||||
Printf(stderr,"SWIG: No module name specified! Please use %%module or -module.\n");
|
||||
Swig_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
lang->initialize(swig_module);
|
||||
Swig_emit_all(c,0);
|
||||
lang->close();
|
||||
|
||||
/* Swig_dump_tags(node,0); */
|
||||
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,55 +0,0 @@
|
|||
/*****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
*****************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* $Header$
|
||||
*
|
||||
* class GUILE
|
||||
*
|
||||
* Guile implementation
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
class GUILE : public Language
|
||||
{
|
||||
private:
|
||||
char *prefix;
|
||||
char *module;
|
||||
char *package;
|
||||
enum {
|
||||
GUILE_LSTYLE_SIMPLE, // call `SWIG_init()'
|
||||
GUILE_LSTYLE_LTDLMOD, // "native" guile?
|
||||
GUILE_LSTYLE_HOBBIT // use (hobbit4d link)
|
||||
} linkage;
|
||||
File *procdoc;
|
||||
int emit_setters;
|
||||
int struct_member;
|
||||
void emit_linkage(char *module_name);
|
||||
|
||||
public :
|
||||
GUILE ();
|
||||
void parse_args (int, char *argv[]);
|
||||
void initialize(String *module);
|
||||
void function (DOH *node);
|
||||
void variable (DOH *node);
|
||||
void constant (DOH *node);
|
||||
void close (void);
|
||||
void create_command (String *, String *) { };
|
||||
void cpp_variable(DOH *node);
|
||||
};
|
||||
|
||||
/* guile.h ends here */
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,49 +0,0 @@
|
|||
|
||||
// ------------------------------------------------------------------------
|
||||
// A Java SWIG Language module
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
class JAVA : public Language {
|
||||
public :
|
||||
|
||||
// Virtual functions required by the SWIG parser
|
||||
|
||||
void parse_args(int, char *argv[]);
|
||||
void parse();
|
||||
void add_native(char *, char *, SwigType *, ParmList *);
|
||||
void create_function(char *, char *, SwigType *, ParmList *);
|
||||
void link_variable(char *, char *, SwigType *);
|
||||
void declare_const(char *, char *, SwigType *, char *);
|
||||
void initialize(void);
|
||||
void headers(void);
|
||||
void close(void);
|
||||
void set_module(char *,char **);
|
||||
void create_command(char *, char *);
|
||||
|
||||
void pragma(char *lang, char *code, char *value);
|
||||
void add_typedef(SwigType *t, char *name);
|
||||
void cpp_open_class(char *classname, char *rename, char *ctype, int strip);
|
||||
void cpp_close_class();
|
||||
void cpp_member_func(char *name, char *iname, SwigType *t, ParmList *l);
|
||||
void cpp_static_func(char *name, char *iname, SwigType *t, ParmList *l);
|
||||
void cpp_constructor(char *name, char *iname, ParmList *l);
|
||||
void cpp_destructor(char *name, char *newname);
|
||||
void cpp_class_decl(char *name, char *rename, char *type);
|
||||
void cpp_inherit(char **baseclass, int);
|
||||
void cpp_variable(char *name, char *iname, SwigType *t);
|
||||
void cpp_static_var(char *, char *, SwigType *);
|
||||
void cpp_declare_const(char *name, char *iname, SwigType *type, char *value);
|
||||
|
||||
/* Java Module methods */
|
||||
void emit_classdef();
|
||||
void emit_shadow_classdef();
|
||||
char *JNICALL(DOHString_or_char *func);
|
||||
char *SwigTcToJniType(SwigType *t, int ret);
|
||||
char *SwigTcToJavaType(SwigType *t, int ret, int inShadow);
|
||||
char *SwigTcToJniScalarType(SwigType *t);
|
||||
char *JavaTypeFromTypemap(char *op, char *lang, SwigType *t, char *pname);
|
||||
char *makeValidJniName(char *name);
|
||||
char *JavaMethodSignature(SwigType *t, int ret, int inShadow);
|
||||
void writeRegisterNatives();
|
||||
};
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -12,54 +12,77 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_main_cxx[] = "$Header$";
|
||||
|
||||
#include "swig11.h"
|
||||
#if defined(_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "swigmod.h"
|
||||
#ifndef MACSWIG
|
||||
#include "swigconfig.h"
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "swigwarn.h"
|
||||
|
||||
extern "C" {
|
||||
#include "preprocessor.h"
|
||||
}
|
||||
|
||||
#ifndef SWIG_LANG
|
||||
#define SWIG_LANG PYTHON
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef SWIG_LIB
|
||||
#define SWIG_LIB "/usr/local/lib/swig1.3"
|
||||
#endif
|
||||
|
||||
#include "tcl8.h"
|
||||
#include "python.h"
|
||||
#include "perl5.h"
|
||||
#include "guile.h"
|
||||
#ifdef OLD
|
||||
#include "java.h"
|
||||
#ifndef SWIG_CC
|
||||
#define SWIG_CC "CC"
|
||||
#endif
|
||||
#include "mzscheme.h"
|
||||
#include "ruby.h"
|
||||
#include "xml.h"
|
||||
|
||||
// Global variables
|
||||
|
||||
FILE *f_runtime = 0;
|
||||
DOH *f_header = 0; // Some commonly used
|
||||
DOH *f_wrappers = 0; // FILE pointers
|
||||
DOH *f_init = 0;
|
||||
char LibDir[512]; // Library directory
|
||||
Language *lang; // Language method
|
||||
int CPlusPlus = 0;
|
||||
int NewObject = 0; // NewObject flag
|
||||
int Extend = 0; // Extend flag
|
||||
int ForceExtern = 0; // Force extern mode
|
||||
int GenerateDefault = 0; // Generate default constructors
|
||||
int GenerateDefault = 1; // Generate default constructors
|
||||
char *Config = 0;
|
||||
int NoInclude = 0;
|
||||
int Verbose = 0;
|
||||
String *swig_module = 0;
|
||||
int NoExtern = 0;
|
||||
int NoExcept = 0;
|
||||
|
||||
extern "C" {
|
||||
extern String *ModuleName;
|
||||
}
|
||||
|
||||
static char *usage = (char*)"\
|
||||
\nSWIG1.1 Options\n\
|
||||
";
|
||||
\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)
|
||||
|
|
@ -67,18 +90,11 @@ static char *usage = (char*)"\
|
|||
// Checks the suffix of a file to see if we should emit extern declarations.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static
|
||||
int
|
||||
check_suffix(char *name) {
|
||||
char *c;
|
||||
if (!name) return 0;
|
||||
if (strlen(name) == 0) return 0;
|
||||
c = name+strlen(name)-1;
|
||||
while (c != name) {
|
||||
if (*c == '.') break;
|
||||
c--;
|
||||
}
|
||||
if (c == name) return 0;
|
||||
c = Swig_file_suffix(name);
|
||||
if ((strcmp(c,".c") == 0) ||
|
||||
(strcmp(c,".C") == 0) ||
|
||||
(strcmp(c,".cc") == 0) ||
|
||||
|
|
@ -90,208 +106,517 @@ check_suffix(char *name) {
|
|||
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 infilename[256];
|
||||
char filename[256];
|
||||
char output_dir[512];
|
||||
char fn_runtime[256];
|
||||
static char *outfile_name = 0;
|
||||
|
||||
char *SwigLib;
|
||||
static int freeze = 0;
|
||||
static String *lang_config = 0;
|
||||
static char *cpp_extension = (char *) "cxx";
|
||||
|
||||
extern "C"
|
||||
int swig11_init(int argc, char *argv[]) {
|
||||
/* 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 infile[512];
|
||||
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;
|
||||
|
||||
lang = new SWIG_LANG;
|
||||
f_wrappers = 0;
|
||||
f_init = 0;
|
||||
f_header = 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(strcmp(argv[i],"-tcl") == 0) {
|
||||
fprintf(stderr,"swig: -tcl option now implies -tcl8\n");
|
||||
lang = new TCL8;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-tcl8") == 0) {
|
||||
lang = new TCL8;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-python") == 0) {
|
||||
lang = new PYTHON;
|
||||
Swig_mark_arg(i);
|
||||
|
||||
} else if (strcmp(argv[i],"-perl5") == 0) {
|
||||
lang = new PERL5;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-guile") == 0) {
|
||||
lang = new GUILE;
|
||||
Swig_mark_arg(i);
|
||||
#ifdef OLD
|
||||
} else if (strcmp(argv[i],"-java") == 0) {
|
||||
lang = new JAVA;
|
||||
Swig_mark_arg(i);
|
||||
#endif
|
||||
} else if (strcmp(argv[i],"-mzscheme") == 0) {
|
||||
lang = new MZSCHEME;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-ruby") == 0) {
|
||||
lang = new RUBY;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-help") == 0) {
|
||||
fputs(usage,stderr);
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-c++") == 0) {
|
||||
CPlusPlus=1;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-c") == 0) {
|
||||
NoInclude=1;
|
||||
Preprocessor_define((void *) "SWIG_NOINCLUDE 1", 0);
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-make_default") == 0) {
|
||||
GenerateDefault = 1;
|
||||
Swig_mark_arg(i);
|
||||
} else if(strcmp(argv[i],"-module") == 0) {
|
||||
if (argv[i+1]) {
|
||||
swig_module = NewString(argv[i+1]);
|
||||
Swig_mark_arg(i);
|
||||
Swig_mark_arg(i+1);
|
||||
i++;
|
||||
} else {
|
||||
Swig_arg_error();
|
||||
}
|
||||
} else if (strcmp(argv[i],"-o") == 0) {
|
||||
if (argv[i+1]) {
|
||||
outfile_name = argv[i+1];
|
||||
Swig_mark_arg(i);
|
||||
Swig_mark_arg(i+1);
|
||||
i++;
|
||||
}
|
||||
} else if (strcmp(argv[i],"-help") == 0) {
|
||||
fputs(usage,stderr);
|
||||
Swig_mark_arg(i);
|
||||
help = 1;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Parse language dependent options
|
||||
lang->parse_args(argc,argv);
|
||||
|
||||
if (help) return 0;
|
||||
|
||||
// Create names of temporary files that are created
|
||||
sprintf(infilename,"%s", argv[argc-1]);
|
||||
|
||||
// Check the suffix for a .c file. If so, we're going to
|
||||
// declare everything we see as "extern"
|
||||
|
||||
ForceExtern = check_suffix(infilename);
|
||||
// Strip off suffix
|
||||
|
||||
c = infilename + strlen(infilename);
|
||||
while (c != infilename) {
|
||||
if (*c == '.') {
|
||||
*c = 0;
|
||||
break;
|
||||
} else {
|
||||
c--;
|
||||
}
|
||||
for (i = 0; i < includecount; i++) {
|
||||
Swig_add_directory((DOH *) includefiles[i]);
|
||||
}
|
||||
if (!outfile_name) {
|
||||
char *cc = infilename + strlen(infilename);
|
||||
while (cc != infilename) {
|
||||
if (*cc == '/') {
|
||||
cc++;
|
||||
break;
|
||||
}
|
||||
cc--;
|
||||
}
|
||||
sprintf(fn_runtime,"%s_wrap.c",infilename);
|
||||
strcpy(infile,infilename);
|
||||
outfile_name = fn_runtime;
|
||||
} else {
|
||||
sprintf(fn_runtime,"%s",outfile_name);
|
||||
}
|
||||
{
|
||||
// Try to identify the output directory
|
||||
char *cc = outfile_name;
|
||||
char *lastc = outfile_name;
|
||||
while (*cc) {
|
||||
if (*cc == '/') lastc = cc+1;
|
||||
cc++;
|
||||
}
|
||||
cc = outfile_name;
|
||||
char *dd = output_dir;
|
||||
while (cc != lastc) {
|
||||
*dd = *cc;
|
||||
dd++;
|
||||
cc++;
|
||||
}
|
||||
*dd = 0;
|
||||
// Patch up the input filename
|
||||
cc = infilename + strlen(infilename);
|
||||
while (cc != infilename) {
|
||||
if (*cc == '/') {
|
||||
cc++;
|
||||
break;
|
||||
}
|
||||
cc--;
|
||||
}
|
||||
strcpy(infile,cc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
extern void generate(DOH *top);
|
||||
|
||||
extern "C"
|
||||
DOH *swig11_run(DOH *node) {
|
||||
if ((f_runtime = fopen(fn_runtime,"w")) == 0) {
|
||||
fprintf(stderr,"Unable to open %s\n", fn_runtime);
|
||||
Swig_exit(1);
|
||||
}
|
||||
f_header = NewString("");
|
||||
f_wrappers = NewString("");
|
||||
f_init = NewString("");
|
||||
|
||||
Swig_register_filebyname("header",f_header);
|
||||
Swig_register_filebyname("runtime", f_runtime);
|
||||
Swig_register_filebyname("wrapper", f_wrappers);
|
||||
Swig_register_filebyname("init", f_init);
|
||||
|
||||
// Set up the typemap for handling new return strings
|
||||
// Define the __cplusplus symbol
|
||||
if (CPlusPlus)
|
||||
Swig_typemap_register((char*)"newfree",(char*)"p.char",(char*)"",(char*)"delete [] $source;\n",0);
|
||||
else
|
||||
Swig_typemap_register((char*)"newfree",(char*)"p.char",(char*)"",(char*)"free($source);\n",0);
|
||||
Preprocessor_define((DOH *) "__cplusplus 1", 0);
|
||||
|
||||
generate(node);
|
||||
// Parse language dependent options
|
||||
lang->main(argc,argv);
|
||||
|
||||
Dump(f_header,f_runtime);
|
||||
Dump(f_wrappers, f_runtime);
|
||||
Wrapper_pretty_print(f_init,f_runtime);
|
||||
fclose(f_runtime);
|
||||
return node;
|
||||
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();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void swig11module() {
|
||||
Swig_register_module("tcl8","swig:top", swig11_init, swig11_run);
|
||||
Swig_register_module("python","swig:top", swig11_init, swig11_run);
|
||||
Swig_register_module("perl5","swig:top", swig11_init, swig11_run);
|
||||
Swig_register_module("ruby","swig:top", swig11_init, swig11_run);
|
||||
Swig_register_module("guile","swig:top", swig11_init, swig11_run);
|
||||
Swig_register_module("mzscheme","swig:top", swig11_init, swig11_run);
|
||||
Swig_register_module("swig11","swig:top", swig11_init, swig11_run);
|
||||
Swig_register_module("xml","swig:top", xml_init, xml_run);
|
||||
// --------------------------------------------------------------------------
|
||||
// SWIG_exit(int exit_code)
|
||||
//
|
||||
// Cleanup and either freeze or exit
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void SWIG_exit(int exit_code) {
|
||||
while (freeze);
|
||||
exit (exit_code);
|
||||
}
|
||||
|
||||
|
|
|
|||
57
SWIG/Source/Modules1.1/module.cxx
Normal file
57
SWIG/Source/Modules1.1/module.cxx
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* module.cxx
|
||||
*
|
||||
* This file is responsible for the module system.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char cvsroot_module_cxx[] = "$Header$";
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
struct Module {
|
||||
ModuleFactory fac;
|
||||
char *name;
|
||||
Module *next;
|
||||
Module(const char *n, ModuleFactory f) {
|
||||
fac = f;
|
||||
name = new char[strlen(n)+1];
|
||||
strcpy(name, n);
|
||||
next = 0;
|
||||
}
|
||||
};
|
||||
|
||||
static Module *modules = 0;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void Swig_register_module()
|
||||
*
|
||||
* Register a module.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_register_module(const char *n, ModuleFactory f) {
|
||||
Module *m = new Module(n,f);
|
||||
m->next = modules;
|
||||
modules = m;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Language *Swig_find_module()
|
||||
*
|
||||
* Given a command line option, locates the factory function.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
ModuleFactory Swig_find_module(const char *name) {
|
||||
Module *m = modules;
|
||||
while (m) {
|
||||
if (strcmp(m->name,name) == 0) {
|
||||
return m->fac;
|
||||
}
|
||||
m = m->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,43 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
*******************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* $Header$
|
||||
*
|
||||
* class MZSCHEME
|
||||
*
|
||||
* Mzscheme implementation
|
||||
* (Caution : This is *somewhat* experimental)
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
class MZSCHEME : public Language
|
||||
{
|
||||
private:
|
||||
void get_pointer(DOHString_or_char *name, int parm, SwigType *t, Wrapper *f);
|
||||
void usage_var(char *, SwigType *, DOHString *usage);
|
||||
void usage_func(char *, SwigType *, ParmList *, DOHString *usage);
|
||||
void usage_returns(char *, SwigType *, ParmList *, DOHString *usage);
|
||||
void usage_const(char *, SwigType *, char *, DOHString *usage);
|
||||
|
||||
public :
|
||||
void parse_args (int, char *argv[]);
|
||||
void initialize(String *module);
|
||||
void function (DOH *node);
|
||||
void variable (DOH *node);
|
||||
void constant (DOH *node);
|
||||
void close (void);
|
||||
void create_command (String *, String *) { };
|
||||
};
|
||||
1072
SWIG/Source/Modules1.1/ocaml.cxx
Executable file
1072
SWIG/Source/Modules1.1/ocaml.cxx
Executable file
File diff suppressed because it is too large
Load diff
338
SWIG/Source/Modules1.1/overload.cxx
Normal file
338
SWIG/Source/Modules1.1/overload.cxx
Normal file
|
|
@ -0,0 +1,338 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* overload.cxx
|
||||
*
|
||||
* This file is used to analyze overloaded functions and methods.
|
||||
* It looks at signatures and tries to gather information for
|
||||
* building a dispatch function.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char cvsroot_overload_cxx[] = "$Header$";
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
#define MAX_OVERLOAD 256
|
||||
|
||||
extern int emit_num_required(ParmList *);
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_overload_rank()
|
||||
*
|
||||
* This function takes an overloaded declaration and creates a list that ranks
|
||||
* all overloaded methods in an order that can be used to generate a dispatch
|
||||
* function.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
struct Overloaded {
|
||||
Node *n; /* Node */
|
||||
int argc; /* Argument count */
|
||||
ParmList *parms; /* Parameters used for overload check */
|
||||
int error; /* Ambiguity error */
|
||||
};
|
||||
|
||||
List *
|
||||
Swig_overload_rank(Node *n) {
|
||||
Overloaded nodes[MAX_OVERLOAD];
|
||||
int nnodes = 0;
|
||||
Node *o = Getattr(n,"sym:overloaded");
|
||||
Node *c;
|
||||
|
||||
if (!o) return 0;
|
||||
|
||||
c = o;
|
||||
while (c) {
|
||||
if (!Getattr(c,"error")) {
|
||||
if (Getattr(c,"wrap:name")) {
|
||||
nodes[nnodes].n = c;
|
||||
nodes[nnodes].parms = Getattr(c,"wrap:parms");
|
||||
nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms);
|
||||
nodes[nnodes].error = 0;
|
||||
nnodes++;
|
||||
}
|
||||
}
|
||||
c = Getattr(c,"sym:nextSibling");
|
||||
}
|
||||
|
||||
/* Sort the declarations by required argument count */
|
||||
{
|
||||
int i,j;
|
||||
for (i = 0; i < nnodes; i++) {
|
||||
for (j = i+1; j < nnodes; j++) {
|
||||
if (nodes[i].argc > nodes[j].argc) {
|
||||
Overloaded t = nodes[i];
|
||||
nodes[i] = nodes[j];
|
||||
nodes[j] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Sort the declarations by argument types */
|
||||
{
|
||||
int i,j;
|
||||
for (i = 0; i < nnodes-1; i++) {
|
||||
if (nodes[i].argc == nodes[i+1].argc) {
|
||||
for (j = i+1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) {
|
||||
Parm *p1 = nodes[i].parms;
|
||||
Parm *p2 = nodes[j].parms;
|
||||
int differ = 0;
|
||||
int num_checked = 0;
|
||||
while (p1 && p2 && (num_checked < nodes[i].argc)) {
|
||||
// Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type"));
|
||||
if (checkAttribute(p1,"tmap:in:numinputs","0")) {
|
||||
p1 = Getattr(p1,"tmap:in:next");
|
||||
continue;
|
||||
}
|
||||
if (checkAttribute(p2,"tmap:in:numinputs","0")) {
|
||||
p2 = Getattr(p2,"tmap:in:next");
|
||||
continue;
|
||||
}
|
||||
String *t1 = Getattr(p1,"tmap:typecheck:precedence");
|
||||
String *t2 = Getattr(p2,"tmap:typecheck:precedence");
|
||||
if ((!t1) && (!nodes[i].error)) {
|
||||
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n),
|
||||
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
|
||||
Getattr(nodes[i].n,"name"),ParmList_str(Getattr(nodes[i].n,"parms")),
|
||||
SwigType_str(Getattr(p1,"type"),0));
|
||||
nodes[i].error = 1;
|
||||
} else if ((!t2) && (!nodes[j].error)) {
|
||||
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n),
|
||||
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
|
||||
Getattr(nodes[j].n,"name"),ParmList_str(Getattr(nodes[j].n,"parms")),
|
||||
SwigType_str(Getattr(p2,"type"),0));
|
||||
nodes[j].error = 1;
|
||||
}
|
||||
if (t1 && t2) {
|
||||
int t1v, t2v;
|
||||
t1v = atoi(Char(t1));
|
||||
t2v = atoi(Char(t2));
|
||||
differ = t1v-t2v;
|
||||
}
|
||||
else if (!t1 && t2) differ = 1;
|
||||
else if (t2 && !t1) differ = -1;
|
||||
else if (!t1 && !t2) differ = -1;
|
||||
num_checked++;
|
||||
if (differ > 0) {
|
||||
Overloaded t = nodes[i];
|
||||
nodes[i] = nodes[j];
|
||||
nodes[j] = t;
|
||||
break;
|
||||
} else if ((differ == 0) && (Strcmp(t1,"0") == 0)) {
|
||||
t1 = Getattr(p1,"ltype");
|
||||
if (!t1) {
|
||||
t1 = SwigType_ltype(Getattr(p1,"type"));
|
||||
if (Getattr(p1,"tmap:typecheck:SWIGTYPE")) {
|
||||
SwigType_add_pointer(t1);
|
||||
}
|
||||
Setattr(p1,"ltype",t1);
|
||||
}
|
||||
t2 = Getattr(p2,"ltype");
|
||||
if (!t2) {
|
||||
t2 = SwigType_ltype(Getattr(p2,"type"));
|
||||
if (Getattr(p2,"tmap:typecheck:SWIGTYPE")) {
|
||||
SwigType_add_pointer(t2);
|
||||
}
|
||||
Setattr(p2,"ltype",t2);
|
||||
}
|
||||
|
||||
/* Need subtype check here. If t2 is a subtype of t1, then we need to change the
|
||||
order */
|
||||
|
||||
if (SwigType_issubtype(t2,t1)) {
|
||||
Overloaded t = nodes[i];
|
||||
nodes[i] = nodes[j];
|
||||
nodes[j] = t;
|
||||
}
|
||||
|
||||
if (Strcmp(t1,t2) != 0) {
|
||||
differ = 1;
|
||||
break;
|
||||
}
|
||||
} else if (differ) {
|
||||
break;
|
||||
}
|
||||
if (Getattr(p1,"tmap:in:next")) {
|
||||
p1 = Getattr(p1,"tmap:in:next");
|
||||
} else {
|
||||
p1 = nextSibling(p1);
|
||||
}
|
||||
if (Getattr(p2,"tmap:in:next")) {
|
||||
p2 = Getattr(p2,"tmap:in:next");
|
||||
} else {
|
||||
p2 = nextSibling(p2);
|
||||
}
|
||||
}
|
||||
if (!differ) {
|
||||
/* See if declarations differ by const only */
|
||||
String *d1 = Getattr(nodes[i].n,"decl");
|
||||
String *d2 = Getattr(nodes[j].n,"decl");
|
||||
if (d1 && d2) {
|
||||
String *dq1 = Copy(d1);
|
||||
String *dq2 = Copy(d2);
|
||||
if (SwigType_isconst(d1)) {
|
||||
SwigType_pop(dq1);
|
||||
}
|
||||
if (SwigType_isconst(d2)) {
|
||||
SwigType_pop(dq2);
|
||||
}
|
||||
if (Strcmp(dq1,dq2) == 0) {
|
||||
|
||||
if (SwigType_isconst(d1) && !SwigType_isconst(d2)) {
|
||||
Overloaded t = nodes[i];
|
||||
nodes[i] = nodes[j];
|
||||
nodes[j] = t;
|
||||
differ = 1;
|
||||
if (!nodes[j].error) {
|
||||
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
|
||||
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
|
||||
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
|
||||
Getfile(nodes[i].n), Getline(nodes[i].n));
|
||||
}
|
||||
nodes[j].error = 1;
|
||||
} else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) {
|
||||
differ = 1;
|
||||
if (!nodes[j].error) {
|
||||
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
|
||||
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
|
||||
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
|
||||
Getfile(nodes[i].n), Getline(nodes[i].n));
|
||||
}
|
||||
nodes[j].error = 1;
|
||||
}
|
||||
}
|
||||
Delete(dq1);
|
||||
Delete(dq2);
|
||||
}
|
||||
}
|
||||
if (!differ) {
|
||||
if (!nodes[j].error) {
|
||||
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
|
||||
"Overloaded %s(%s) is shadowed by %s(%s) at %s:%d.\n",
|
||||
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
|
||||
Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms),
|
||||
Getfile(nodes[i].n),Getline(nodes[i].n));
|
||||
nodes[j].error = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
List *result = NewList();
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < nnodes; i++) {
|
||||
Append(result,nodes[i].n);
|
||||
// Printf(stdout,"[ %d ] %s\n", i, ParmList_protostr(nodes[i].parms));
|
||||
// Swig_print_node(nodes[i].n);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_overload_dispatch()
|
||||
*
|
||||
* Generate a dispatch function. argc is assumed to hold the argument count.
|
||||
* argv is the argument vector.
|
||||
*
|
||||
* Note that for C++ class member functions, Swig_overload_dispatch() assumes
|
||||
* that argc includes the "self" argument and that the first element of argv[]
|
||||
* is the "self" argument. So for a member function:
|
||||
*
|
||||
* Foo::bar(int x, int y, int z);
|
||||
*
|
||||
* the argc should be 4 (not 3!) and the first element of argv[] would be
|
||||
* the appropriate scripting language reference to "self". For regular
|
||||
* functions (and static class functions) the argc and argv only include
|
||||
* the regular function arguments.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static bool print_typecheck(String *f, int j, Parm *pj)
|
||||
{
|
||||
char tmp[256];
|
||||
sprintf(tmp,"argv[%d]",j);
|
||||
String *tm = Getattr(pj,"tmap:typecheck");
|
||||
if (tm) {
|
||||
Replaceid(tm,Getattr(pj,"lname"),"_v");
|
||||
Replaceall(tm,"$input", tmp);
|
||||
Printv(f,tm,"\n",NIL);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
String *
|
||||
Swig_overload_dispatch(Node *n, const String_or_char *fmt, int *maxargs) {
|
||||
int i,j;
|
||||
|
||||
*maxargs = 1;
|
||||
|
||||
String *f = NewString("");
|
||||
|
||||
/* Get a list of methods ranked by precedence values and argument count */
|
||||
List *dispatch = Swig_overload_rank(n);
|
||||
int nfunc = Len(dispatch);
|
||||
|
||||
/* Loop over the functions */
|
||||
|
||||
for (i = 0; i < nfunc; i++) {
|
||||
Node *ni = Getitem(dispatch,i);
|
||||
Parm *pi = Getattr(ni,"wrap:parms");
|
||||
int num_required = emit_num_required(pi);
|
||||
int num_arguments = emit_num_arguments(pi);
|
||||
if (num_arguments > *maxargs) *maxargs = num_arguments;
|
||||
int varargs = emit_isvarargs(pi);
|
||||
|
||||
if (!varargs) {
|
||||
if (num_required == num_arguments) {
|
||||
Printf(f,"if (argc == %d) {\n", num_required);
|
||||
} else {
|
||||
Printf(f,"if ((argc >= %d) && (argc <= %d)) {\n", num_required, num_arguments);
|
||||
}
|
||||
} else {
|
||||
Printf(f,"if (argc >= %d) {\n", num_required);
|
||||
}
|
||||
|
||||
if (num_arguments) {
|
||||
Printf(f,"int _v;\n");
|
||||
}
|
||||
|
||||
int num_braces = 0;
|
||||
j = 0;
|
||||
Parm *pj = pi;
|
||||
while (pj) {
|
||||
if (checkAttribute(pj,"tmap:in:numinputs","0")) {
|
||||
pj = Getattr(pj,"tmap:in:next");
|
||||
continue;
|
||||
}
|
||||
if (j >= num_required) {
|
||||
Printf(f, "if (argc <= %d) {\n", j);
|
||||
Printf(f, Char(fmt),Getattr(ni,"wrap:name"));
|
||||
Printf(f, "}\n");
|
||||
}
|
||||
if (print_typecheck(f, j, pj)) {
|
||||
Printf(f, "if (_v) {\n");
|
||||
num_braces++;
|
||||
}
|
||||
Parm *pk = Getattr(pj,"tmap:in:next");
|
||||
if (pk) pj = pk;
|
||||
else pj = nextSibling(pj);
|
||||
j++;
|
||||
}
|
||||
Printf(f, Char(fmt),Getattr(ni,"wrap:name"));
|
||||
/* close braces */
|
||||
for (/* empty */; num_braces > 0; num_braces--)
|
||||
Printf(f, "}\n");
|
||||
Printf(f,"}\n"); /* braces closes "if" for this method */
|
||||
}
|
||||
Delete(dispatch);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,53 +0,0 @@
|
|||
/****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* class PERL5
|
||||
*
|
||||
* A Perl 5 implementation
|
||||
**************************************************************************/
|
||||
|
||||
class PERL5 : public Language {
|
||||
private:
|
||||
char *usage_func(char *, SwigType *, ParmList *);
|
||||
public :
|
||||
virtual void parse_args(int, char *argv[]);
|
||||
virtual void initialize(String *modname);
|
||||
virtual void function(DOH *node);
|
||||
virtual void variable(DOH *node);
|
||||
virtual void constant(DOH *node);
|
||||
virtual void close(void);
|
||||
virtual void nativefunction(DOH *);
|
||||
virtual void create_command(String *, String *);
|
||||
|
||||
// Support for blessed perl thingies....
|
||||
|
||||
virtual void cpp_open_class(DOH *);
|
||||
virtual void cpp_close_class();
|
||||
virtual void cpp_memberfunction(DOH *);
|
||||
virtual void cpp_staticfunction(DOH *);
|
||||
virtual void cpp_variable(DOH *);
|
||||
virtual void cpp_constructor(DOH *);
|
||||
virtual void cpp_destructor(DOH *);
|
||||
virtual void cpp_inherit(List *bases);
|
||||
virtual void cpp_constant(DOH *);
|
||||
virtual void cpp_class_decl(DOH *);
|
||||
virtual void add_typedef(SwigType *t, String *name);
|
||||
virtual void pragma(DOH *node);
|
||||
virtual void import(String *filename);
|
||||
};
|
||||
|
||||
|
||||
|
||||
2113
SWIG/Source/Modules1.1/php4.cxx
Normal file
2113
SWIG/Source/Modules1.1/php4.cxx
Normal file
File diff suppressed because it is too large
Load diff
881
SWIG/Source/Modules1.1/pike.cxx
Normal file
881
SWIG/Source/Modules1.1/pike.cxx
Normal file
|
|
@ -0,0 +1,881 @@
|
|||
/***********************************************************************
|
||||
* Pike language module for SWIG
|
||||
***********************************************************************/
|
||||
|
||||
char cvsroot_pike_cxx[] = "$Header$";
|
||||
|
||||
#include "swigmod.h"
|
||||
#ifndef MACSWIG
|
||||
#include "swigconfig.h"
|
||||
#endif
|
||||
|
||||
class PIKE : public Language {
|
||||
private:
|
||||
|
||||
File *f_runtime;
|
||||
File *f_header;
|
||||
File *f_wrappers;
|
||||
File *f_init;
|
||||
String *PrefixPlusUnderscore;
|
||||
int current;
|
||||
|
||||
// Wrap modes
|
||||
enum {
|
||||
NO_CPP,
|
||||
MEMBER_FUNC,
|
||||
CONSTRUCTOR,
|
||||
DESTRUCTOR,
|
||||
MEMBER_VAR,
|
||||
CLASS_CONST,
|
||||
STATIC_FUNC,
|
||||
STATIC_VAR
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* PIKE()
|
||||
*
|
||||
* Initialize member data
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
PIKE() {
|
||||
f_runtime = 0;
|
||||
f_header = 0;
|
||||
f_wrappers = 0;
|
||||
f_init = 0;
|
||||
PrefixPlusUnderscore = 0;
|
||||
current = NO_CPP;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* main()
|
||||
*
|
||||
* Parse command line options and initializes variables.
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual void main(int argc, char *argv[]) {
|
||||
|
||||
/* Set location of SWIG library */
|
||||
SWIG_library_directory("pike");
|
||||
|
||||
/* Look for certain command line options */
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (argv[i]) {
|
||||
if (strcmp (argv[i], "-ldflags") == 0) {
|
||||
printf("%s\n", SWIG_PIKE_RUNTIME);
|
||||
SWIG_exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Add a symbol to the parser for conditional compilation */
|
||||
Preprocessor_define("SWIGPIKE 1", 0);
|
||||
|
||||
/* Set language-specific configuration file */
|
||||
SWIG_config_file("pike.swg");
|
||||
|
||||
/* Set typemap language */
|
||||
SWIG_typemap_lang("pike");
|
||||
|
||||
/* Enable overloaded methods support */
|
||||
allow_overloading();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* top()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int top(Node *n) {
|
||||
/* Get the module name */
|
||||
String *module = Getattr(n, "name");
|
||||
|
||||
/* Get the output file name */
|
||||
String *outfile = Getattr(n, "outfile");
|
||||
|
||||
/* Open the output file */
|
||||
f_runtime = NewFile(outfile, "w");
|
||||
if (!f_runtime) {
|
||||
Printf(stderr, "*** Can't open '%s'\n", outfile);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
f_init = NewString("");
|
||||
f_header = NewString("");
|
||||
f_wrappers = NewString("");
|
||||
|
||||
/* Register file targets with the SWIG file handler */
|
||||
Swig_register_filebyname("header", f_header);
|
||||
Swig_register_filebyname("wrapper", f_wrappers);
|
||||
Swig_register_filebyname("runtime", f_runtime);
|
||||
Swig_register_filebyname("init", f_init);
|
||||
|
||||
/* Standard stuff for the SWIG runtime section */
|
||||
Swig_banner(f_runtime);
|
||||
if (NoInclude) {
|
||||
Printf(f_runtime, "#define SWIG_NOINCLUDE\n");
|
||||
}
|
||||
|
||||
Printf(f_header, "#define SWIG_init pike_module_init\n");
|
||||
Printf(f_header, "#define SWIG_name \"%s\"\n\n", module);
|
||||
|
||||
/* Change naming scheme for constructors and destructors */
|
||||
Swig_name_register("construct","%c_create");
|
||||
Swig_name_register("destroy","%c_destroy");
|
||||
|
||||
/* Current wrap type */
|
||||
current = NO_CPP;
|
||||
|
||||
/* Emit code for children */
|
||||
Language::top(n);
|
||||
|
||||
/* Close the initialization function */
|
||||
Printf(f_init, "}\n");
|
||||
SwigType_emit_type_table(f_runtime, f_wrappers);
|
||||
|
||||
/* Close all of the files */
|
||||
Dump(f_header, f_runtime);
|
||||
Dump(f_wrappers, f_runtime);
|
||||
Wrapper_pretty_print(f_init, f_runtime);
|
||||
Delete(f_header);
|
||||
Delete(f_wrappers);
|
||||
Delete(f_init);
|
||||
Close(f_runtime);
|
||||
Delete(f_runtime);
|
||||
|
||||
/* Done */
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* importDirective()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int importDirective(Node *n) {
|
||||
String *modname = Getattr(n,"module");
|
||||
if (modname) {
|
||||
Printf(f_init,"pike_require(\"%s\");\n", modname);
|
||||
}
|
||||
return Language::importDirective(n);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* strip()
|
||||
*
|
||||
* For names that begin with the current class prefix plus an
|
||||
* underscore (e.g. "Foo_enum_test"), return the base function
|
||||
* name (i.e. "enum_test").
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
String *strip(const DOHString_or_char *name) {
|
||||
String *s = Copy(name);
|
||||
if (Strncmp(name, PrefixPlusUnderscore, Len(PrefixPlusUnderscore)) != 0) {
|
||||
return s;
|
||||
}
|
||||
Replaceall(s, PrefixPlusUnderscore, "");
|
||||
return s;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* add_method()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
void add_method(Node *n, const DOHString_or_char *name, const DOHString_or_char *function, const DOHString_or_char *description) {
|
||||
String *rename;
|
||||
if (current != NO_CPP) {
|
||||
rename = strip(name);
|
||||
} else {
|
||||
rename = NewString(name);
|
||||
}
|
||||
Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
|
||||
Delete(rename);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* functionWrapper()
|
||||
*
|
||||
* Create a function declaration and register it with the interpreter.
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int functionWrapper(Node *n) {
|
||||
|
||||
String *name = Getattr(n,"name");
|
||||
String *iname = Getattr(n,"sym:name");
|
||||
SwigType *d = Getattr(n,"type");
|
||||
ParmList *l = Getattr(n,"parms");
|
||||
|
||||
Parm *p;
|
||||
String *tm;
|
||||
int i;
|
||||
|
||||
String *overname = 0;
|
||||
if (Getattr(n,"sym:overloaded")) {
|
||||
overname = Getattr(n,"sym:overname");
|
||||
} else {
|
||||
if (!addSymbol(iname,n)) return SWIG_ERROR;
|
||||
}
|
||||
|
||||
Wrapper *f = NewWrapper();
|
||||
|
||||
/* Write code to extract function parameters. */
|
||||
emit_args(d, l, f);
|
||||
|
||||
/* Attach the standard typemaps */
|
||||
emit_attach_parmmaps(l,f);
|
||||
Setattr(n,"wrap:parms",l);
|
||||
|
||||
/* Get number of required and total arguments */
|
||||
int num_arguments = emit_num_arguments(l);
|
||||
int varargs = emit_isvarargs(l);
|
||||
|
||||
/* Which input argument to start with? */
|
||||
int start = (current == MEMBER_FUNC || current == MEMBER_VAR || current == DESTRUCTOR) ? 1 : 0;
|
||||
|
||||
/* Offset to skip over the attribute name */
|
||||
// int offset = (current == MEMBER_VAR) ? 1 : 0;
|
||||
int offset = 0;
|
||||
|
||||
String *wname = Swig_name_wrapper(iname);
|
||||
if (overname) {
|
||||
Append(wname,overname);
|
||||
}
|
||||
|
||||
Printv(f->def, "static void ", wname, "(INT32 args) {", NIL);
|
||||
|
||||
/* Generate code for argument marshalling */
|
||||
String *description = NewString("");
|
||||
char source[64];
|
||||
for (i = 0, p = l; i < num_arguments; i++) {
|
||||
|
||||
while (checkAttribute(p,"tmap:in:numinputs","0")) {
|
||||
p = Getattr(p,"tmap:in:next");
|
||||
}
|
||||
|
||||
SwigType *pt = Getattr(p,"type");
|
||||
String *ln = Getattr(p,"lname");
|
||||
|
||||
if (i < start) {
|
||||
String *lstr = SwigType_lstr(pt,0);
|
||||
Printf(f->code, "%s = (%s) THIS;\n", ln, lstr);
|
||||
Delete(lstr);
|
||||
} else {
|
||||
/* Look for an input typemap */
|
||||
sprintf(source, "sp[%d-args]", i-start+offset);
|
||||
if ((tm = Getattr(p,"tmap:in"))) {
|
||||
Replaceall(tm, "$source", source);
|
||||
Replaceall(tm, "$target", ln);
|
||||
Replaceall(tm, "$input", source);
|
||||
Setattr(p, "emit:input", source);
|
||||
Printf(f->code, "%s\n", tm);
|
||||
String *pikedesc = Getattr(p, "tmap:in:pikedesc");
|
||||
if (pikedesc) {
|
||||
Printv(description, pikedesc, " ", NIL);
|
||||
}
|
||||
p = Getattr(p,"tmap:in:next");
|
||||
continue;
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number,
|
||||
"Unable to use type %s as a function argument.\n",SwigType_str(pt,0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
p = nextSibling(p);
|
||||
}
|
||||
|
||||
/* Check for trailing varargs */
|
||||
if (varargs) {
|
||||
if (p && (tm = Getattr(p,"tmap:in"))) {
|
||||
Replaceall(tm,"$input", "varargs");
|
||||
Printv(f->code,tm,"\n",NIL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert constraint checking code */
|
||||
for (p = l; p;) {
|
||||
if ((tm = Getattr(p,"tmap:check"))) {
|
||||
Replaceall(tm,"$target",Getattr(p,"lname"));
|
||||
Printv(f->code,tm,"\n",NIL);
|
||||
p = Getattr(p,"tmap:check:next");
|
||||
} else {
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert cleanup code */
|
||||
String *cleanup = NewString("");
|
||||
for (p = l; p;) {
|
||||
if ((tm = Getattr(p,"tmap:freearg"))) {
|
||||
Replaceall(tm,"$source",Getattr(p,"lname"));
|
||||
Printv(cleanup,tm,"\n",NIL);
|
||||
p = Getattr(p,"tmap:freearg:next");
|
||||
} else {
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert argument output code */
|
||||
String *outarg = NewString("");
|
||||
for (p = l; p;) {
|
||||
if ((tm = Getattr(p,"tmap:argout"))) {
|
||||
Replaceall(tm,"$source",Getattr(p,"lname"));
|
||||
Replaceall(tm,"$target","resultobj");
|
||||
Replaceall(tm,"$arg",Getattr(p,"emit:input"));
|
||||
Replaceall(tm,"$input",Getattr(p,"emit:input"));
|
||||
Printv(outarg,tm,"\n",NIL);
|
||||
p = Getattr(p,"tmap:argout:next");
|
||||
} else {
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Emit the function call */
|
||||
emit_action(n,f);
|
||||
|
||||
/* Clear the return stack */
|
||||
Printf(f->code, "pop_n_elems(args);\n");
|
||||
|
||||
/* Return the function value */
|
||||
if (current == CONSTRUCTOR) {
|
||||
Printv(f->code, "THIS = (void *) result;\n", NIL);
|
||||
Printv(description, ", tVoid", NIL);
|
||||
} else if (current == DESTRUCTOR) {
|
||||
Printv(description, ", tVoid", NIL);
|
||||
} else {
|
||||
Wrapper_add_local(f, "resultobj", "struct object *resultobj");
|
||||
Printv(description, ", ", NIL);
|
||||
if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) {
|
||||
Replaceall(tm,"$source", "result");
|
||||
Replaceall(tm,"$target", "resultobj");
|
||||
Replaceall(tm,"$result", "resultobj");
|
||||
if (Getattr(n,"feature:new")) {
|
||||
Replaceall(tm,"$owner","1");
|
||||
} else {
|
||||
Replaceall(tm,"$owner","0");
|
||||
}
|
||||
String *pikedesc = Getattr(n, "tmap:out:pikedesc");
|
||||
if (pikedesc) {
|
||||
Printv(description, pikedesc, NIL);
|
||||
}
|
||||
Printf(f->code,"%s\n", tm);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number,
|
||||
"Unable to use return type %s in function %s.\n", SwigType_str(d,0), name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Output argument output code */
|
||||
Printv(f->code,outarg,NIL);
|
||||
|
||||
/* Output cleanup code */
|
||||
Printv(f->code,cleanup,NIL);
|
||||
|
||||
/* Look to see if there is any newfree cleanup code */
|
||||
if (Getattr(n,"feature:new")) {
|
||||
if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) {
|
||||
Replaceall(tm,"$source","result");
|
||||
Printf(f->code,"%s\n",tm);
|
||||
}
|
||||
}
|
||||
|
||||
/* See if there is any return cleanup code */
|
||||
if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) {
|
||||
Replaceall(tm,"$source","result");
|
||||
Printf(f->code,"%s\n",tm);
|
||||
}
|
||||
|
||||
/* Close the function */
|
||||
Printf(f->code, "}\n");
|
||||
|
||||
/* Substitute the cleanup code */
|
||||
Replaceall(f->code,"$cleanup",cleanup);
|
||||
|
||||
/* Substitute the function name */
|
||||
Replaceall(f->code,"$symname",iname);
|
||||
Replaceall(f->code,"$result","resultobj");
|
||||
|
||||
/* Dump the function out */
|
||||
Wrapper_print(f,f_wrappers);
|
||||
|
||||
/* Now register the function with the interpreter. */
|
||||
if (!Getattr(n,"sym:overloaded")) {
|
||||
add_method(n, iname, wname, description);
|
||||
} else {
|
||||
Setattr(n,"wrap:name", wname);
|
||||
if (!Getattr(n,"sym:nextSibling")) {
|
||||
dispatchFunction(n);
|
||||
}
|
||||
}
|
||||
|
||||
Delete(cleanup);
|
||||
Delete(outarg);
|
||||
Delete(description);
|
||||
Delete(wname);
|
||||
DelWrapper(f);
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* dispatchFunction()
|
||||
*
|
||||
* Emit overloading dispatch function
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
void dispatchFunction(Node *n) {
|
||||
/* Last node in overloaded chain */
|
||||
|
||||
int maxargs;
|
||||
String *tmp = NewString("");
|
||||
String *dispatch = Swig_overload_dispatch(n,"return %s(self,args);",&maxargs);
|
||||
|
||||
/* Generate a dispatch wrapper for all overloaded functions */
|
||||
|
||||
Wrapper *f = NewWrapper();
|
||||
String *symname = Getattr(n,"sym:name");
|
||||
String *wname = Swig_name_wrapper(symname);
|
||||
|
||||
Printv(f->def,
|
||||
"struct object *", wname,
|
||||
"(struct object *self, struct object *args) {",
|
||||
NULL);
|
||||
|
||||
|
||||
Wrapper_add_local(f,"argc","INT32 argc");
|
||||
Printf(tmp,"struct object *argv[%d]", maxargs+1);
|
||||
Wrapper_add_local(f,"argv",tmp);
|
||||
Wrapper_add_local(f,"ii","INT32 ii");
|
||||
Printf(f->code,"argc = sizeof(args);\n");
|
||||
Printf(f->code,"for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n",maxargs);
|
||||
Printf(f->code,"argv[ii] = array_index(args,&argv[ii],ii);\n");
|
||||
Printf(f->code,"}\n");
|
||||
|
||||
Replaceall(dispatch,"$args","self,args");
|
||||
Printv(f->code,dispatch,"\n",NIL);
|
||||
Printf(f->code,"No matching function for overloaded '%s'\n", symname);
|
||||
Printf(f->code,"return NULL;\n");
|
||||
Printv(f->code,"}\n",NIL);
|
||||
Wrapper_print(f,f_wrappers);
|
||||
add_method(n,symname,wname,0);
|
||||
|
||||
DelWrapper(f);
|
||||
Delete(dispatch);
|
||||
Delete(tmp);
|
||||
Delete(wname);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* variableWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int variableWrapper(Node *n) {
|
||||
// return Language::variableWrapper(n);
|
||||
|
||||
String *name = Getattr(n,"name");
|
||||
String *iname = Getattr(n,"sym:name");
|
||||
SwigType *t = Getattr(n,"type");
|
||||
|
||||
String *wname;
|
||||
// static int have_globals = 0;
|
||||
String *tm;
|
||||
Wrapper *getf, *setf;
|
||||
|
||||
if (!addSymbol(iname,n)) return SWIG_ERROR;
|
||||
|
||||
getf = NewWrapper();
|
||||
setf = NewWrapper();
|
||||
|
||||
wname = Swig_name_wrapper(iname);
|
||||
|
||||
/* Create a function for setting the value of the variable */
|
||||
|
||||
Printf(setf->def,"static int %s_set(object *_val) {", wname);
|
||||
if (!Getattr(n,"feature:immutable")) {
|
||||
if ((tm = Swig_typemap_lookup_new("varin",n,name,0))) {
|
||||
Replaceall(tm,"$source","_val");
|
||||
Replaceall(tm,"$target",name);
|
||||
Replaceall(tm,"$input","_val");
|
||||
Printf(setf->code,"%s\n",tm);
|
||||
Delete(tm);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number,
|
||||
"Unable to set variable of type %s.\n", SwigType_str(t,0));
|
||||
}
|
||||
Printf(setf->code," return 0;\n");
|
||||
} else {
|
||||
/* Is a readonly variable. Issue an error */
|
||||
|
||||
Printv(setf->code,
|
||||
tab4, "Variable $iname is read-only.\n",
|
||||
tab4, "return 1;\n",
|
||||
NIL);
|
||||
|
||||
}
|
||||
|
||||
Printf(setf->code,"}\n");
|
||||
Wrapper_print(setf,f_wrappers);
|
||||
|
||||
/* Create a function for getting the value of a variable */
|
||||
Printf(getf->def,"static object *%s_get() {", wname);
|
||||
Wrapper_add_local(getf,"pikeobj", "object *pyobj");
|
||||
if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) {
|
||||
Replaceall(tm,"$source",name);
|
||||
Replaceall(tm,"$target","pikeobj");
|
||||
Replaceall(tm,"$result","pikeobj");
|
||||
Printf(getf->code,"%s\n", tm);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number,
|
||||
"Unable to link with type %s\n", SwigType_str(t,0));
|
||||
}
|
||||
|
||||
Printf(getf->code," return pikeobj;\n}\n");
|
||||
Wrapper_print(getf,f_wrappers);
|
||||
|
||||
/* Now add this to the variable linking mechanism */
|
||||
Printf(f_init,"\t SWIG_addvarlink(SWIG_globals,(char*)\"%s\",%s_get, %s_set);\n", iname, wname, wname);
|
||||
|
||||
DelWrapper(setf);
|
||||
DelWrapper(getf);
|
||||
return SWIG_OK;
|
||||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* constantWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int constantWrapper(Node *n) {
|
||||
|
||||
Swig_require(&n, "*sym:name", "type", "value", NIL);
|
||||
|
||||
String *symname = Getattr(n, "sym:name");
|
||||
SwigType *type = Getattr(n, "type");
|
||||
String *value = Getattr(n, "value");
|
||||
|
||||
/* Special hook for member pointer */
|
||||
if (SwigType_type(type) == T_MPOINTER) {
|
||||
String *wname = Swig_name_wrapper(symname);
|
||||
Printf(f_header, "static %s = %s;\n", SwigType_str(type, wname), value);
|
||||
value = wname;
|
||||
}
|
||||
|
||||
/* Perform constant typemap substitution */
|
||||
String *tm = Swig_typemap_lookup_new("constant", n, value, 0);
|
||||
if (tm) {
|
||||
Replaceall(tm, "$source", value);
|
||||
Replaceall(tm, "$target", symname);
|
||||
Replaceall(tm, "$symname", symname);
|
||||
Replaceall(tm, "$value", value);
|
||||
Printf(f_init, "%s\n", tm);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number,
|
||||
"Unsupported constant value %s = %s\n", SwigType_str(type, 0), value);
|
||||
}
|
||||
|
||||
Swig_restore(&n);
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* nativeWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int nativeWrapper(Node *n) {
|
||||
// return Language::nativeWrapper(n);
|
||||
String *name = Getattr(n,"sym:name");
|
||||
String *wrapname = Getattr(n,"wrap:name");
|
||||
|
||||
if (!addSymbol(wrapname,n)) return SWIG_ERROR;
|
||||
|
||||
add_method(n, name, wrapname,0);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* enumDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int enumDeclaration(Node *n) {
|
||||
return Language::enumDeclaration(n);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* enumvalueDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int enumvalueDeclaration(Node *n) {
|
||||
return Language::enumvalueDeclaration(n);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* classDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int classDeclaration(Node *n) {
|
||||
return Language::classDeclaration(n);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* classHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int classHandler(Node *n) {
|
||||
|
||||
String *symname = Getattr(n, "sym:name");
|
||||
if (!addSymbol(symname, n))
|
||||
return SWIG_ERROR;
|
||||
|
||||
PrefixPlusUnderscore = NewStringf("%s_", getClassPrefix());
|
||||
|
||||
Printf(f_init, "start_new_program();\n");
|
||||
|
||||
/* Handle inheritance */
|
||||
List *baselist = Getattr(n,"bases");
|
||||
if (baselist && Len(baselist) > 0) {
|
||||
Node *base = Firstitem(baselist);
|
||||
while (base) {
|
||||
char *basename = Char(Getattr(base,"name"));
|
||||
if (SwigType_istemplate(basename)) {
|
||||
basename = Char(SwigType_namestr(basename));
|
||||
}
|
||||
SwigType *basetype = NewString(basename);
|
||||
SwigType_add_pointer(basetype);
|
||||
SwigType_remember(basetype);
|
||||
String *basemangle = SwigType_manglestr(basetype);
|
||||
Printf(f_init, "low_inherit((struct program *) SWIGTYPE%s->clientdata, 0, 0, 0, 0, 0);\n", basemangle);
|
||||
Delete(basemangle);
|
||||
Delete(basetype);
|
||||
base = Nextitem(baselist);
|
||||
}
|
||||
} else {
|
||||
Printf(f_init, "ADD_STORAGE(swig_object_wrapper);\n");
|
||||
}
|
||||
|
||||
Language::classHandler(n);
|
||||
|
||||
/* Accessors for member variables */
|
||||
/*
|
||||
List *membervariables = Getattr(n,"membervariables");
|
||||
if (membervariables && Len(membervariables) > 0) {
|
||||
membervariableAccessors(membervariables);
|
||||
}
|
||||
*/
|
||||
|
||||
/* Done, close the class */
|
||||
Printf(f_init, "add_program_constant(\"%s\", pr = end_program(), 0);\n", symname);
|
||||
|
||||
SwigType *tt = NewString(symname);
|
||||
SwigType_add_pointer(tt);
|
||||
SwigType_remember(tt);
|
||||
String *tm = SwigType_manglestr(tt);
|
||||
Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) pr);\n", tm);
|
||||
Delete(tm);
|
||||
Delete(tt);
|
||||
|
||||
Delete(PrefixPlusUnderscore); PrefixPlusUnderscore = 0;
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* memberfunctionHandler()
|
||||
*
|
||||
* Method for adding C++ member function
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int memberfunctionHandler(Node *n) {
|
||||
current = MEMBER_FUNC;
|
||||
Language::memberfunctionHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* constructorHandler()
|
||||
*
|
||||
* Method for adding C++ member constructor
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int constructorHandler(Node *n) {
|
||||
current = CONSTRUCTOR;
|
||||
Language::constructorHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* destructorHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int destructorHandler(Node *n) {
|
||||
current = DESTRUCTOR;
|
||||
Language::destructorHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* membervariableAccessors()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
void membervariableAccessors(List *membervariables) {
|
||||
String *name;
|
||||
Node *n;
|
||||
bool need_setter;
|
||||
String *funcname;
|
||||
|
||||
/* If at least one of them is mutable, we need a setter */
|
||||
need_setter = false;
|
||||
n = Firstitem(membervariables);
|
||||
while (n) {
|
||||
if (!Getattr(n, "feature:immutable")) {
|
||||
need_setter = true;
|
||||
break;
|
||||
}
|
||||
n = Nextitem(membervariables);
|
||||
}
|
||||
|
||||
/* Create a function to set the values of the (mutable) variables */
|
||||
if (need_setter) {
|
||||
Wrapper *wrapper = NewWrapper();
|
||||
String *setter = Swig_name_member(getClassPrefix(), (char *) "`->=");
|
||||
String *wname = Swig_name_wrapper(setter);
|
||||
Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL);
|
||||
Printf(wrapper->locals, "char *name = (char *) STR0(sp[0-args].u.string);\n");
|
||||
|
||||
n = Firstitem(membervariables);
|
||||
while (n) {
|
||||
if (!Getattr(n, "feature:immutable")) {
|
||||
name = Getattr(n, "name");
|
||||
funcname = Swig_name_wrapper(Swig_name_set(Swig_name_member(getClassPrefix(), name)));
|
||||
Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name);
|
||||
Printf(wrapper->code, "%s(args);\n", funcname);
|
||||
Printf(wrapper->code, "return;\n");
|
||||
Printf(wrapper->code, "}\n");
|
||||
Delete(funcname);
|
||||
}
|
||||
n = Nextitem(membervariables);
|
||||
}
|
||||
|
||||
/* Close the function */
|
||||
Printf(wrapper->code, "pop_n_elems(args);\n");
|
||||
Printf(wrapper->code, "}\n");
|
||||
|
||||
/* Dump wrapper code to the output file */
|
||||
Wrapper_print(wrapper, f_wrappers);
|
||||
|
||||
/* Register it with Pike */
|
||||
String *description = NewString("tStr tFloat, tVoid");
|
||||
add_method(Firstitem(membervariables), "`->=", wname, description);
|
||||
Delete(description);
|
||||
|
||||
/* Clean up */
|
||||
Delete(wname);
|
||||
Delete(setter);
|
||||
DelWrapper(wrapper);
|
||||
}
|
||||
|
||||
/* Create a function to get the values of the (mutable) variables */
|
||||
Wrapper *wrapper = NewWrapper();
|
||||
String *getter = Swig_name_member(getClassPrefix(), (char *) "`->");
|
||||
String *wname = Swig_name_wrapper(getter);
|
||||
Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL);
|
||||
Printf(wrapper->locals, "char *name = (char *) STR0(sp[0-args].u.string);\n");
|
||||
|
||||
n = Firstitem(membervariables);
|
||||
while (n) {
|
||||
name = Getattr(n, "name");
|
||||
funcname = Swig_name_wrapper(Swig_name_get(Swig_name_member(getClassPrefix(), name)));
|
||||
Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name);
|
||||
Printf(wrapper->code, "%s(args);\n", funcname);
|
||||
Printf(wrapper->code, "return;\n");
|
||||
Printf(wrapper->code, "}\n");
|
||||
Delete(funcname);
|
||||
n = Nextitem(membervariables);
|
||||
}
|
||||
|
||||
/* Close the function */
|
||||
Printf(wrapper->code, "pop_n_elems(args);\n");
|
||||
Printf(wrapper->code, "}\n");
|
||||
|
||||
/* Dump wrapper code to the output file */
|
||||
Wrapper_print(wrapper, f_wrappers);
|
||||
|
||||
/* Register it with Pike */
|
||||
String *description = NewString("tStr, tMix");
|
||||
add_method(Firstitem(membervariables), "`->", wname, description);
|
||||
Delete(description);
|
||||
|
||||
/* Clean up */
|
||||
Delete(wname);
|
||||
Delete(getter);
|
||||
DelWrapper(wrapper);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* membervariableHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int membervariableHandler(Node *n) {
|
||||
List *membervariables = Getattr(getCurrentClass(),"membervariables");
|
||||
if (!membervariables) {
|
||||
membervariables = NewList();
|
||||
Setattr(getCurrentClass(),"membervariables",membervariables);
|
||||
}
|
||||
Append(membervariables,n);
|
||||
current = MEMBER_VAR;
|
||||
Language::membervariableHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
* staticmemberfunctionHandler()
|
||||
*
|
||||
* Wrap a static C++ function
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
virtual int staticmemberfunctionHandler(Node *n) {
|
||||
current = STATIC_FUNC;
|
||||
Language::staticmemberfunctionHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* memberconstantHandler()
|
||||
*
|
||||
* Create a C++ constant
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int memberconstantHandler(Node *n) {
|
||||
current = CLASS_CONST;
|
||||
constantWrapper(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* staticmembervariableHandler()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int staticmembervariableHandler(Node *n) {
|
||||
current = STATIC_VAR;
|
||||
Language::staticmembervariableHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig_pike() - Instantiate module
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern "C" Language *
|
||||
swig_pike(void) {
|
||||
return new PIKE();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,62 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
*******************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* $Header$
|
||||
*
|
||||
* python.h
|
||||
*
|
||||
* Header file for Python module. Warning ; this is work in progress.
|
||||
**************************************************************************/
|
||||
|
||||
class PYTHON : public Language {
|
||||
protected:
|
||||
void get_pointer(char *src, char *dest, SwigType *t, String *f, char *ret);
|
||||
void add_method(String *name, String *function, int kw);
|
||||
char *usage_func(char *, SwigType *, ParmList *);
|
||||
|
||||
public :
|
||||
|
||||
// Don't change any of this
|
||||
virtual void parse_args(int, char *argv[]);
|
||||
virtual void initialize(String *);
|
||||
virtual void function(DOH *node);
|
||||
virtual void variable(DOH *node);
|
||||
virtual void constant(DOH *node);
|
||||
virtual void nativefunction(DOH *);
|
||||
virtual void close(void);
|
||||
virtual void create_command(String *, String *);
|
||||
virtual void import(String *modname);
|
||||
|
||||
// C++ extensions---for creating shadow classes
|
||||
|
||||
virtual void cpp_memberfunction(DOH *);
|
||||
virtual void cpp_constructor(DOH *);
|
||||
virtual void cpp_destructor(DOH *);
|
||||
virtual void cpp_open_class(DOH *);
|
||||
virtual void cpp_close_class();
|
||||
virtual void cpp_inherit(List *bases);
|
||||
virtual void cpp_variable(DOH *);
|
||||
virtual void cpp_constant(DOH *);
|
||||
virtual void cpp_class_decl(DOH *);
|
||||
virtual void pragma(DOH *node);
|
||||
virtual void add_typedef(SwigType *t, String *name);
|
||||
};
|
||||
|
||||
#define PYSHADOW_MEMBER 0x2
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,55 +0,0 @@
|
|||
/********************************************************************
|
||||
* Ruby module for SWIG
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
* Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
||||
* Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
||||
*
|
||||
* Masaki Fukushima
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
class RUBY : public Language {
|
||||
protected:
|
||||
virtual String *make_wrapper_name(char *cname);
|
||||
virtual char *validate_const_name(char *name);
|
||||
virtual char *ruby_typemap_lookup(char *, SwigType *, String_or_char *, char *, char *, Wrapper * = 0);
|
||||
virtual int to_VALUE(SwigType *, char *, DOHString *, int = 0);
|
||||
virtual int from_VALUE(SwigType *, char *, char *, DOHString *);
|
||||
public:
|
||||
/* Virtual functions required by the SWIG parser */
|
||||
virtual void parse_args(int, char *argv[]);
|
||||
virtual void initialize(String *module);
|
||||
virtual void function(DOH *node);
|
||||
virtual void variable(DOH *node);
|
||||
virtual void constant(DOH *node);
|
||||
virtual void close(void);
|
||||
virtual void nativefunction(DOH *);
|
||||
virtual void create_command(String *, String *);
|
||||
virtual void import(String *);
|
||||
|
||||
/* C++ language extensions. */
|
||||
virtual void cpp_memberfunction(DOH *);
|
||||
virtual void cpp_constructor(DOH *);
|
||||
virtual void cpp_destructor(DOH *);
|
||||
virtual void cpp_open_class(DOH *);
|
||||
virtual void cpp_close_class();
|
||||
virtual void cpp_inherit(List *bases);
|
||||
virtual void cpp_variable(DOH *);
|
||||
virtual void cpp_staticfunction(DOH *);
|
||||
virtual void cpp_constant(DOH *);
|
||||
virtual void cpp_staticvariable(DOH *);
|
||||
|
||||
/* Declaration of a class, but not a full definition */
|
||||
virtual void cpp_class_decl(DOH *);
|
||||
|
||||
/* Pragma directive */
|
||||
virtual void pragma(DOH *node);
|
||||
};
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* c-basic-offset: 2
|
||||
* End:
|
||||
*/
|
||||
401
SWIG/Source/Modules1.1/s-exp.cxx
Normal file
401
SWIG/Source/Modules1.1/s-exp.cxx
Normal file
|
|
@ -0,0 +1,401 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* s-exp.cxx
|
||||
*
|
||||
* A parse tree represented as Lisp s-expressions.
|
||||
*
|
||||
* Author(s) : Matthias Koeppe (mkoeppe@mail.math.uni-magdeburg.de)
|
||||
*
|
||||
* Copyright (C) 2002. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* Derived from xml.cxx 1.1.2.2 */
|
||||
|
||||
char cvsroot_s_exp_cxx[] = "$Header$";
|
||||
static const char *usage = "\
|
||||
S-Exp Options (available with -sexp)\n\
|
||||
-typemaplang lang - Typemap language.\n\n";
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
//static Node *view_top = 0;
|
||||
static File *out = 0;
|
||||
|
||||
class Sexp : public Language {
|
||||
public:
|
||||
int indent_level;
|
||||
Sexp() : indent_level( 0 ) {}
|
||||
virtual ~Sexp() {}
|
||||
virtual void main(int argc, char *argv[]) {
|
||||
SWIG_typemap_lang("sexp");
|
||||
for( int iX = 0; iX < argc; iX++ )
|
||||
{
|
||||
if( strcmp( argv[iX], "-typemaplang" ) == 0 )
|
||||
{
|
||||
Swig_mark_arg (iX);
|
||||
iX++;
|
||||
SWIG_typemap_lang(argv[iX]);
|
||||
Swig_mark_arg (iX);
|
||||
continue;
|
||||
}
|
||||
if( strcmp( argv[iX], "-help" ) == 0 )
|
||||
{
|
||||
fputs( usage, stderr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DOHHash *print_circle_hash;
|
||||
int print_circle_count;
|
||||
int hanging_parens;
|
||||
bool need_whitespace;
|
||||
bool need_newline;
|
||||
|
||||
/* Top of the parse tree */
|
||||
virtual int top(Node *n)
|
||||
{
|
||||
if( out == 0 )
|
||||
{
|
||||
String *outfile = Getattr(n,"outfile");
|
||||
Replaceall(outfile,"_wrap.cxx", ".lisp");
|
||||
out = NewFile(outfile,"w");
|
||||
if (!out)
|
||||
{
|
||||
Printf(stderr,"*** Can't open '%s'\n", outfile);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
Language::top(n);
|
||||
Printf( out, ";;; Lisp parse tree produced by SWIG\n" );
|
||||
print_circle_hash = DohNewHash();
|
||||
print_circle_count = 0;
|
||||
hanging_parens = 0;
|
||||
need_whitespace = 0;
|
||||
need_newline = 0;
|
||||
Sexp_print_node(n);
|
||||
flush_parens();
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
void print_indent()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < indent_level; i++)
|
||||
{
|
||||
Printf(out, " ");
|
||||
}
|
||||
}
|
||||
|
||||
void open_paren(const String *oper)
|
||||
{
|
||||
flush_parens();
|
||||
Printf(out, "(");
|
||||
if (oper) Printf(out, "%s ", oper);
|
||||
indent_level += 2;
|
||||
}
|
||||
|
||||
void close_paren(bool need_newline = false)
|
||||
{
|
||||
hanging_parens++;
|
||||
if (need_newline)
|
||||
print_lazy_whitespace();
|
||||
indent_level -= 2;
|
||||
}
|
||||
|
||||
void flush_parens()
|
||||
{
|
||||
int i;
|
||||
if (hanging_parens) {
|
||||
for (i = 0; i<hanging_parens; i++)
|
||||
Printf(out, ")");
|
||||
hanging_parens = 0;
|
||||
need_newline = true;
|
||||
need_whitespace = true;
|
||||
}
|
||||
if (need_newline) {
|
||||
Printf(out, "\n");
|
||||
print_indent();
|
||||
need_newline = false;
|
||||
need_whitespace = false;
|
||||
}
|
||||
else if (need_whitespace) {
|
||||
Printf(out, " ");
|
||||
need_whitespace = false;
|
||||
}
|
||||
}
|
||||
|
||||
void print_lazy_whitespace()
|
||||
{
|
||||
need_whitespace = 1;
|
||||
}
|
||||
|
||||
void print_lazy_newline()
|
||||
{
|
||||
need_newline = 1;
|
||||
}
|
||||
|
||||
bool internal_key_p(DOH *key)
|
||||
{
|
||||
return ((Cmp(key,"nodeType") == 0)
|
||||
|| (Cmp(key,"firstChild") == 0)
|
||||
|| (Cmp(key,"lastChild") == 0)
|
||||
|| (Cmp(key,"parentNode") == 0)
|
||||
|| (Cmp(key,"nextSibling") == 0)
|
||||
|| (Cmp(key,"previousSibling") == 0)
|
||||
|| (Cmp(key,"csym:nextSibling") == 0)
|
||||
|| (Cmp(key,"csym:previousSibling") == 0)
|
||||
|| (Cmp(key,"typepass:visit") == 0)
|
||||
|| (Cmp(key,"allocate:visit") == 0)
|
||||
|| (*(Char(key)) == '$'));
|
||||
}
|
||||
|
||||
bool boolean_key_p(DOH *key)
|
||||
{
|
||||
return ((Cmp(key,"allocate:default_constructor") == 0)
|
||||
|| (Cmp(key,"allocate:default_destructor") == 0)
|
||||
|| (Cmp(key,"allows_typedef") == 0)
|
||||
|| (Cmp(key,"feature:immutable") == 0));
|
||||
}
|
||||
|
||||
bool list_key_p(DOH *key)
|
||||
{
|
||||
return ((Cmp(key, "parms") == 0)
|
||||
|| (Cmp(key, "baselist") == 0));
|
||||
}
|
||||
|
||||
bool plist_key_p(DOH *key)
|
||||
// true if KEY is the name of data that is a mapping from keys to
|
||||
// values, which should be printed as a plist.
|
||||
{
|
||||
return ((Cmp(key, "typescope") == 0));
|
||||
}
|
||||
|
||||
bool maybe_plist_key_p(DOH *key)
|
||||
{
|
||||
return (Strncmp(key, "tmap:", 5) == 0);
|
||||
}
|
||||
|
||||
bool print_circle(DOH *obj, bool list_p)
|
||||
// We have a complex object, which might be referenced several
|
||||
// times, or even recursively. Use Lisp's reader notation for
|
||||
// circular structures (#n#, #n=).
|
||||
//
|
||||
// An object can be printed in list-mode or object-mode; LIST_P toggles.
|
||||
// return TRUE if OBJ still needs to be printed
|
||||
{
|
||||
flush_parens();
|
||||
// Following is a silly hack. It works around the limitation of
|
||||
// DOH's hash tables that only work with string keys!
|
||||
char address[16];
|
||||
sprintf(address, "%x%c", (unsigned int)obj, list_p ? 'L' : 'O');
|
||||
DOH *placeholder = Getattr(print_circle_hash, address);
|
||||
if (placeholder) {
|
||||
Printv(out, placeholder, NIL);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
String *placeholder = NewStringf("#%d#", ++print_circle_count);
|
||||
Setattr(print_circle_hash, address, placeholder);
|
||||
Printf(out, "#%d=", print_circle_count);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void Sexp_print_value_of_key(DOH *value, DOH *key)
|
||||
{
|
||||
if ((Cmp(key, "parms") == 0) || (Cmp(key, "wrap:parms") == 0)
|
||||
|| (Cmp(key, "kwargs") == 0) || (Cmp(key, "pattern") == 0))
|
||||
Sexp_print_parms(value);
|
||||
else if (plist_key_p(key))
|
||||
Sexp_print_plist(value);
|
||||
else if (maybe_plist_key_p(key)) {
|
||||
if (DohIsMapping(value))
|
||||
Sexp_print_plist(value);
|
||||
else
|
||||
Sexp_print_doh(value);
|
||||
}
|
||||
else if (list_key_p(key))
|
||||
Sexp_print_list(value);
|
||||
else if (boolean_key_p(key))
|
||||
Sexp_print_boolean(value);
|
||||
else
|
||||
Sexp_print_doh(value);
|
||||
}
|
||||
|
||||
void Sexp_print_boolean(DOH *obj)
|
||||
{
|
||||
flush_parens();
|
||||
/* See DOH/Doh/base.c, DohGetInt() */
|
||||
if (DohIsString(obj)) {
|
||||
if (atoi(Char(obj)) != 0)
|
||||
Printf(out, "t");
|
||||
else Printf(out, "nil");
|
||||
}
|
||||
else Printf(out, "nil");
|
||||
}
|
||||
|
||||
void Sexp_print_list(DOH *obj)
|
||||
{
|
||||
if (print_circle(obj, true)) {
|
||||
open_paren(NIL);
|
||||
for (; obj; obj = nextSibling(obj)) {
|
||||
Sexp_print_doh(obj);
|
||||
print_lazy_whitespace();
|
||||
}
|
||||
close_paren(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Sexp_print_parms(DOH *obj)
|
||||
// print it as a list of plists
|
||||
{
|
||||
if (print_circle(obj, true)) {
|
||||
open_paren(NIL);
|
||||
for (; obj; obj = nextSibling(obj)) {
|
||||
if (DohIsMapping(obj)) {
|
||||
DOH *k;
|
||||
open_paren(NIL);
|
||||
for (k = Firstkey(obj); k; k = Nextkey(obj)) {
|
||||
if (!internal_key_p(k)) {
|
||||
DOH *value = Getattr(obj, k);
|
||||
Sexp_print_as_keyword(k);
|
||||
Sexp_print_value_of_key(value, k);
|
||||
print_lazy_whitespace();
|
||||
}
|
||||
}
|
||||
close_paren(true);
|
||||
}
|
||||
else Sexp_print_doh(obj);
|
||||
print_lazy_whitespace();
|
||||
}
|
||||
close_paren(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Sexp_print_doh(DOH *obj)
|
||||
{
|
||||
flush_parens();
|
||||
if (DohIsString(obj)) {
|
||||
String *o = Str(obj);
|
||||
Replaceall( o, "\\", "\\\\" );
|
||||
Replaceall( o, "\"", "\\\"" );
|
||||
Printf(out,"\"%s\"", o);
|
||||
Delete(o);
|
||||
}
|
||||
else {
|
||||
if (print_circle(obj, false)) {
|
||||
// Dispatch type
|
||||
if (nodeType(obj)) {
|
||||
Sexp_print_node(obj);
|
||||
}
|
||||
|
||||
else if (DohIsMapping(obj)) {
|
||||
DOH *k;
|
||||
open_paren(NIL);
|
||||
for (k = Firstkey(obj); k; k = Nextkey(obj)) {
|
||||
if (!internal_key_p(k)) {
|
||||
DOH *value = Getattr(obj, k);
|
||||
flush_parens();
|
||||
open_paren(NIL);
|
||||
Sexp_print_doh(k);
|
||||
Printf(out, " . ");
|
||||
Sexp_print_value_of_key(value, k);
|
||||
close_paren();
|
||||
}
|
||||
}
|
||||
close_paren();
|
||||
}
|
||||
else {
|
||||
// What is it?
|
||||
Printf(out,"#<DOH %x>", obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sexp_print_as_keyword(const DOH *k)
|
||||
{
|
||||
/* Print key, replacing ":" with "-" because : is CL's package prefix */
|
||||
flush_parens();
|
||||
String *key = NewString(k);
|
||||
Replaceall(key, ":", "-");
|
||||
Replaceall(key, "_", "-");
|
||||
Printf(out,":%s ", key);
|
||||
Delete(key);
|
||||
}
|
||||
|
||||
void Sexp_print_plist_noparens(DOH *obj)
|
||||
{
|
||||
/* attributes map names to objects */
|
||||
String *k;
|
||||
bool first;
|
||||
for (k = Firstkey(obj), first = true; k; k = Nextkey(obj), first=false) {
|
||||
if (!internal_key_p(k)) {
|
||||
DOH *value = Getattr(obj, k);
|
||||
flush_parens();
|
||||
if (!first) {
|
||||
Printf(out, " ");
|
||||
}
|
||||
Sexp_print_as_keyword(k);
|
||||
/* Print value */
|
||||
Sexp_print_value_of_key(value, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sexp_print_plist(DOH *obj)
|
||||
{
|
||||
flush_parens();
|
||||
if (print_circle(obj, true)) {
|
||||
open_paren(NIL);
|
||||
Sexp_print_plist_noparens(obj);
|
||||
close_paren();
|
||||
}
|
||||
}
|
||||
|
||||
void Sexp_print_attributes(Node * obj)
|
||||
{
|
||||
Sexp_print_plist_noparens(obj);
|
||||
}
|
||||
|
||||
void Sexp_print_node(Node *obj)
|
||||
{
|
||||
Node *cobj;
|
||||
open_paren(nodeType(obj));
|
||||
/* A node has an attribute list... */
|
||||
Sexp_print_attributes(obj);
|
||||
/* ... and child nodes. */
|
||||
cobj = firstChild(obj);
|
||||
if (cobj) {
|
||||
print_lazy_newline();
|
||||
flush_parens();
|
||||
Sexp_print_as_keyword("children");
|
||||
open_paren(NIL);
|
||||
for (; cobj; cobj = nextSibling(cobj)) {
|
||||
Sexp_print_node(cobj);
|
||||
}
|
||||
close_paren();
|
||||
}
|
||||
close_paren();
|
||||
}
|
||||
|
||||
|
||||
virtual int functionWrapper(Node *n)
|
||||
{
|
||||
ParmList *l = Getattr(n,"parms");
|
||||
Wrapper *f = NewWrapper();
|
||||
emit_attach_parmmaps(l,f);
|
||||
Setattr(n,"wrap:parms",l);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
Language * swig_sexp( void )
|
||||
{
|
||||
return new Sexp();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* swig11.h
|
||||
*
|
||||
* Main header file for the SWIG1.1 core.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1998-2000. The University of Chicago
|
||||
* Copyright (C) 1995-1998. The University of Utah and The Regents of the
|
||||
* University of California.
|
||||
*
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
*
|
||||
* $Header$
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "swigver.h"
|
||||
|
||||
extern "C" {
|
||||
#include "swig.h"
|
||||
}
|
||||
|
||||
/* Global variables. */
|
||||
|
||||
extern FILE *f_runtime; // Runtime code
|
||||
extern DOH *f_header; // Headers
|
||||
extern DOH *f_wrappers; // Wrappers
|
||||
extern DOH *f_init; // Initialization code
|
||||
extern FILE *f_input;
|
||||
extern int CPlusPlus; // C++ mode
|
||||
extern int AddMethods; // AddMethods mode
|
||||
extern int NewObject; // NewObject mode
|
||||
extern int NoInclude; // NoInclude flag
|
||||
extern char output_dir[512]; // Output directory
|
||||
extern int Verbose;
|
||||
extern int ReadOnly; // Read only mode
|
||||
extern int Native; // Native mode
|
||||
|
||||
/* Miscellaneous stuff */
|
||||
|
||||
#define tab4 " "
|
||||
#define tab8 " "
|
||||
|
||||
// Modes for different types of inheritance
|
||||
|
||||
#define INHERIT_FUNC 0x1
|
||||
#define INHERIT_VAR 0x2
|
||||
#define INHERIT_CONST 0x4
|
||||
#define INHERIT_ALL (INHERIT_FUNC | INHERIT_VAR | INHERIT_CONST)
|
||||
|
||||
/* Language Class */
|
||||
class Language {
|
||||
public:
|
||||
virtual void parse_args(int argc, char *argv[]) = 0;
|
||||
virtual void initialize(String *modname) = 0;
|
||||
virtual void close(void) = 0;
|
||||
virtual void import(String *modname);
|
||||
|
||||
/* Basic function, variable, constant API (required) */
|
||||
virtual void function(DOH *node) = 0;
|
||||
virtual void variable(DOH *node) = 0;
|
||||
virtual void constant(DOH *node) = 0;
|
||||
virtual void nativefunction(DOH *node);
|
||||
virtual void create_command(String *cname, String *iname);
|
||||
|
||||
/* Optional C++ handling */
|
||||
virtual void cpp_open_class(DOH *node);
|
||||
virtual void cpp_memberfunction(DOH *node);
|
||||
virtual void cpp_constructor(DOH *node);
|
||||
virtual void cpp_destructor(DOH *node);
|
||||
virtual void cpp_variable(DOH *node);
|
||||
virtual void cpp_staticfunction(DOH *node);
|
||||
virtual void cpp_constant(DOH *node);
|
||||
virtual void cpp_staticvariable(DOH *node);
|
||||
virtual void cpp_close_class();
|
||||
|
||||
virtual void cpp_class_decl(DOH *node);
|
||||
virtual void cpp_inherit(List *bases);
|
||||
|
||||
/* Miscellaneous features */
|
||||
|
||||
virtual void add_typedef(SwigType *t, String *name);
|
||||
virtual void pragma(DOH *node);
|
||||
|
||||
};
|
||||
|
||||
/* Emit functions */
|
||||
|
||||
extern void new_create_function(char *, char *, SwigType *, ParmList *);
|
||||
extern void emit_set_get(DOH *node);
|
||||
extern void emit_set_action(DOHString_or_char *decl);
|
||||
|
||||
/* These are in the new core */
|
||||
extern "C" void *Preprocessor_define(void *, int);
|
||||
|
||||
// Misc
|
||||
|
||||
extern int emit_args(DOH *node, Wrapper *f);
|
||||
extern void emit_func_call(DOH *node, Wrapper *f);
|
||||
extern int check_numopt(ParmList *);
|
||||
extern void SWIG_config_file(const String_or_char *);
|
||||
|
||||
/* C++ utility functions */
|
||||
extern int cplus_check_abstract(DOH *node);
|
||||
extern void cplus_walk_inherit(DOH *cls, void (*action)(DOH *base, void *clientdata), void *clientdata);
|
||||
|
||||
extern Language *lang;
|
||||
|
||||
/* swig11.h ends here */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
255
SWIG/Source/Modules1.1/swigmod.h
Normal file
255
SWIG/Source/Modules1.1/swigmod.h
Normal file
|
|
@ -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 */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,53 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
*******************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* class TCL8
|
||||
*
|
||||
* A TCL implementation for Tcl 8.0. Basically the same as the other
|
||||
* Tcl module, but with different code generation.
|
||||
**************************************************************************/
|
||||
|
||||
class TCL8 : public Language {
|
||||
private:
|
||||
char *usage_string(char *, SwigType *, ParmList *);
|
||||
|
||||
public :
|
||||
virtual void parse_args(int, char *argv[]);
|
||||
virtual void initialize(String *);
|
||||
virtual void function(DOH *node);
|
||||
virtual void variable(DOH *node);
|
||||
virtual void constant(DOH *node);
|
||||
virtual void close(void);
|
||||
virtual void nativefunction(DOH *);
|
||||
virtual void create_command(String *, String *);
|
||||
|
||||
// Stubs for processing C++ classes in Tcl
|
||||
|
||||
virtual void cpp_open_class(DOH *node);
|
||||
virtual void cpp_close_class();
|
||||
virtual void cpp_memberfunction(DOH *);
|
||||
virtual void cpp_variable(DOH *);
|
||||
virtual void cpp_constructor(DOH *);
|
||||
virtual void cpp_destructor(DOH *);
|
||||
virtual void cpp_inherit(List *bases);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
966
SWIG/Source/Modules1.1/typepass.cxx
Normal file
966
SWIG/Source/Modules1.1/typepass.cxx
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,304 +1,318 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* xml.cxx
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Xml.cxx
|
||||
*
|
||||
* Generate XML representation
|
||||
* 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)
|
||||
*
|
||||
* Author(s) : SWIG core: David Beazley (beazley@cs.uchicago.edu)
|
||||
* XML module: Klaus Wiederaenders (kwconsulting@compuserve.com)
|
||||
* Copyright (C) 1999-2001. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* Copyright (C) 2002. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* DB: I had to take some features related to package naming out of this to
|
||||
get the new type system to work. These need to be put back in at some
|
||||
point. */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include <time.h>
|
||||
#include "swig11.h"
|
||||
#include "xml.h"
|
||||
#include "dohobj.h"
|
||||
|
||||
static char *usage = (char*)"\
|
||||
char cvsroot_xml_cxx[] = "$Header$";
|
||||
static const char *usage = "\
|
||||
XML Options (available with -xml)\n\
|
||||
-o filename - Output file\n\
|
||||
-dtd filename - Stylsheet file\n\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 );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
static String *dtdfile = 0;
|
||||
static String *xmlfile = 0;
|
||||
static int indent = 0;
|
||||
static const int indentsize = 2;
|
||||
static const char * indentchar = " ";
|
||||
FILE *f_xml = 0;
|
||||
extern "C"
|
||||
{
|
||||
|
||||
static String * emit_indent( int indent )
|
||||
{
|
||||
String *out;
|
||||
out = NewString("");
|
||||
for(int iX = 0; iX < indent; iX ++ )
|
||||
Append( out, indentchar );
|
||||
return Swig_temp_result(out);
|
||||
}
|
||||
|
||||
void xml(DOH *node)
|
||||
{
|
||||
if (ObjGetMark(node))
|
||||
{
|
||||
Printf( f_xml, "%s<swigxml:node ident=\"ID%0X\" />\n",
|
||||
emit_indent( indent ), node);
|
||||
return;
|
||||
}
|
||||
indent += indentsize;
|
||||
ObjSetMark(node, 1);
|
||||
while (node)
|
||||
{
|
||||
DohBase * base = (DohBase *) node;
|
||||
if( !base )
|
||||
return;
|
||||
switch( base->type )
|
||||
{
|
||||
case 1:
|
||||
Replace( node, "<", "<", DOH_REPLACE_ANY );
|
||||
Replace( node, "&", "&", DOH_REPLACE_ANY );
|
||||
Printf( f_xml, "%s", node );
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
indent += indentsize;
|
||||
DOH *item;
|
||||
|
||||
item = Firstitem(node);
|
||||
while (item)
|
||||
{
|
||||
DohBase * itembase = (DohBase *) item;
|
||||
if( itembase && itembase->type == DOHTYPE_STRING )
|
||||
{
|
||||
Printf( f_xml,
|
||||
"%s<swigxml:item name=\"%s\" ident=\"ID%0X\" />\n",
|
||||
emit_indent( indent ), Char( item ), item );
|
||||
}
|
||||
else
|
||||
{
|
||||
Printf( f_xml, "%s<swigxml:item ident=\"ID%0X\">\n",
|
||||
emit_indent( indent ), item );
|
||||
xml( item );
|
||||
Printf( f_xml, "%s</swigxml:item>\n",
|
||||
emit_indent( indent ) );
|
||||
|
||||
}
|
||||
item = Nextitem(node);
|
||||
}
|
||||
indent -= indentsize;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
String * none = NewString("swigxml:none");
|
||||
DOH * tag = Getattr( node, "tag" );
|
||||
if( !tag )
|
||||
{
|
||||
/*
|
||||
ObjSetMark(node, 0);
|
||||
Printf( f_xml, "------- %s\n", Char( Str( node )));
|
||||
ObjSetMark(node, 1);
|
||||
*/
|
||||
tag = none;
|
||||
}
|
||||
DOH * name = Getattr( node, "name" );
|
||||
char * ttt = Char( tag );
|
||||
|
||||
if( tag && ::strchr( Char(tag), ':' ) == 0 )
|
||||
Insert( tag, 0, "swigxml:" );
|
||||
// check for simple node
|
||||
int length = Len( node );
|
||||
if( Getattr( node, "tag" ) )
|
||||
--length;
|
||||
if( Getattr( node, "prev" ) )
|
||||
--length;
|
||||
if( Getattr( node, "next" ) )
|
||||
--length;
|
||||
if( Getattr( node, "parent" ) )
|
||||
--length;
|
||||
if( Getattr( node, "last" ) )
|
||||
--length;
|
||||
if( length == 1 && name )
|
||||
{ // Yes, it's simple
|
||||
if( Len( name) )
|
||||
Printf( f_xml, "%s<%s name=\"%s\" ident=\"ID%0X\" />\n",
|
||||
emit_indent( indent ), Char( tag ), Char( name ),
|
||||
node );
|
||||
else
|
||||
Printf( f_xml, "%s<%s ident=\"ID%0X\" />\n",
|
||||
emit_indent( indent ), Char( tag ), node );
|
||||
Delete( none );
|
||||
break;
|
||||
}
|
||||
if( Len( name) )
|
||||
Printf( f_xml, "%s<%s name=\"%s\" ident=\"ID%0X\">\n",
|
||||
emit_indent( indent ), Char( tag ), Char( name ), node );
|
||||
else
|
||||
Printf( f_xml, "%s<%s ident=\"ID%0X\">\n",
|
||||
emit_indent( indent ), Char( tag ), node );
|
||||
indent += indentsize;
|
||||
|
||||
DOH * key = Firstkey(node);
|
||||
while (key)
|
||||
{
|
||||
char * kkkk = Char( key );
|
||||
DOH * attr = Getattr( node, key );
|
||||
char * aaaa = Char( Getattr( node, key ) );
|
||||
DohBase * attrbase = (DohBase *) attr;
|
||||
if( ::strcmp( Char( key ), "tag")
|
||||
&& ::strcmp( Char( key ), "code")
|
||||
&& ::strcmp( Char( key ), "name")
|
||||
&& attrbase && attrbase->type == DOHTYPE_STRING)
|
||||
{
|
||||
Replace( attr, "\"", """, DOH_REPLACE_ANY );
|
||||
Printf( f_xml,
|
||||
"%s<swigxml:%s string=\"%s\" ident=\"ID%0X\" />\n",
|
||||
emit_indent( indent ), Char( key ), Char( attr ),
|
||||
attr );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ::strcmp( Char( key ), "prev" )
|
||||
&& ::strcmp( Char( key ), "next" )
|
||||
&& ::strcmp( Char( key ), "parent" )
|
||||
&& ::strcmp( Char( key ), "tag" )
|
||||
&& ::strcmp( Char( key ), "name" )
|
||||
&& ::strcmp( Char( key ), "last" ) )
|
||||
{
|
||||
Printf( f_xml, "%s<swigxml:%s ident=\"ID%0X\">\n",
|
||||
emit_indent( indent ), Char( key ), key );
|
||||
xml( attr );
|
||||
Printf( f_xml, "%s</swigxml:%s>\n",
|
||||
emit_indent( indent ), Char( key ) );
|
||||
}
|
||||
|
||||
}
|
||||
key = Nextkey(node);
|
||||
}
|
||||
indent -= indentsize;
|
||||
Printf( f_xml, "%s</%s>\n", emit_indent( indent ), Char( tag ) );
|
||||
Delete( none );
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
Printf( f_xml, "%s ", "DOHTYPE_VOID" );
|
||||
break;
|
||||
case 5:
|
||||
Printf( f_xml, "%s ", "DOHTYPE_FILE" );
|
||||
break;
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
Printf( f_xml, "%d ", base->type );
|
||||
;
|
||||
}
|
||||
ObjSetMark(node, 0);
|
||||
node = Swig_next(node);
|
||||
}
|
||||
indent -= indentsize;
|
||||
|
||||
}
|
||||
|
||||
int xml_init(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int help = 0;
|
||||
|
||||
// Get options
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (argv[i])
|
||||
{
|
||||
if(strcmp(argv[i],"-xml") == 0)
|
||||
{
|
||||
if (argv[i+1])
|
||||
{
|
||||
xmlfile = NewString(argv[i+1]);
|
||||
// don't do this: Swig_mark_arg(i);
|
||||
Swig_mark_arg(i+1);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Swig_arg_error();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(strcmp(argv[i],"-dtd") == 0)
|
||||
{
|
||||
if (argv[i+1])
|
||||
{
|
||||
dtdfile = NewString(argv[i+1]);
|
||||
Swig_mark_arg(i);
|
||||
Swig_mark_arg(i+1);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Swig_arg_error();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (strcmp(argv[i],"-help") == 0)
|
||||
{
|
||||
fputs(usage,stderr);
|
||||
Swig_mark_arg(i);
|
||||
help = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (help) return 0;
|
||||
Preprocessor_define((void *) "SWIGXML 1", 0);
|
||||
if( ! Swig_swiglib_get() )
|
||||
Swig_swiglib_set("xml");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DOH *xml_run(DOH *node)
|
||||
{
|
||||
time_t now;
|
||||
time( &now );
|
||||
char buffer[32];
|
||||
::strcpy( buffer, ctime(&now));
|
||||
buffer[24] = '\0';
|
||||
char * filename = Char(xmlfile);
|
||||
if ((f_xml = fopen( filename,"w")) == 0) {
|
||||
fprintf(stderr,"Unable to open %s\n", filename);
|
||||
Swig_exit(1);
|
||||
}
|
||||
Printf( f_xml, "<!-- Generated by Swig XML at %s -->\n", buffer );
|
||||
|
||||
if( dtdfile )
|
||||
{
|
||||
Printf( f_xml, "<!DOCTYPE swigxml:swig SYSTEM \"%s\">\n", dtdfile);
|
||||
}
|
||||
|
||||
Printf( f_xml, "<swigxml:swig"
|
||||
" name=\"namespaces\""
|
||||
" xmlns:swigxml=\"http://jniplusplus.sourceforge.net\""
|
||||
" xmlns:swig=\"http://swig.sourceforge.net\""
|
||||
" xmlns:c=\"http://www.ansi.org\""
|
||||
" ident=\"ID000000\">\n" );
|
||||
xml(node);
|
||||
Printf( f_xml, "</swigxml:swig>\n" );
|
||||
|
||||
fclose(f_xml);
|
||||
return node;
|
||||
}
|
||||
|
||||
Language * swig_xml( void )
|
||||
{
|
||||
return new XML();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,119 +0,0 @@
|
|||
<!ELEMENT swig:top (swigxml:child)>
|
||||
<!ATTLIST swig:top name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swig:pragma (swigxml:value,swigxml:lang?)>
|
||||
<!ATTLIST swig:pragma name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swig:file ((swigxml:type|swigxml:child)+)>
|
||||
<!ATTLIST swig:file name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swig:module EMPTY>
|
||||
<!ATTLIST swig:module name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swig:insert (swigxml:code,swigxml:section?,swigxml:method?,swigxml:type?)>
|
||||
<!ATTLIST swig:insert name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swig:types (swigxml:parms)>
|
||||
<!ATTLIST swig:types name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swig:typemap (swigxml:parms?,(swigxml:srctype|swigxml:code),swigxml:method,swigxml:type,swigxml:lang?,swigxml:srcname?)>
|
||||
<!ATTLIST swig:typemap name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swig:constant (swigxml:value,swigxml:type?)>
|
||||
<!ATTLIST swig:constant name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swig:apply (swigxml:parms?,swigxml:type)>
|
||||
<!ATTLIST swig:apply name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swig:addmethods (swigxml:child)>
|
||||
<!ATTLIST swig:addmethods name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT c:class ((swigxml:child|swigxml:classtype|swigxml:namespace|swigxml:bases|swigxml:scriptname|swigxml:symbols|swigxml:altname)+)>
|
||||
<!ATTLIST c:class name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT c:destructor (swigxml:code?,swigxml:storage?)>
|
||||
<!ATTLIST c:destructor name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT c:function (swigxml:abstract?,swigxml:parms?,swigxml:code?,swigxml:storage?,swigxml:type)>
|
||||
<!ATTLIST c:function name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT c:variable (swigxml:storage?,swigxml:value?,swigxml:type)>
|
||||
<!ATTLIST c:variable name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT c:access EMPTY>
|
||||
<!ATTLIST c:access name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT c:typedef (swigxml:type)>
|
||||
<!ATTLIST c:typedef name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT c:enum (swigxml:child)>
|
||||
<!ATTLIST c:enum name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT c:enumvalue (swigxml:value?)>
|
||||
<!ATTLIST c:enumvalue name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:child ((swig:addmethods|swig:apply|swig:constant|swig:types|swig:insert|swig:file|swig:module|swig:typemap|swig:pragma|c:class|c:destructor|c:function|c:access|c:variable|c:typedef|c:enum|c:enumvalue)+)>
|
||||
<!ATTLIST swigxml:child name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:swig (swig:top)>
|
||||
<!ATTLIST swigxml:swig name CDATA #REQUIRED xmlns:swigxml CDATA #REQUIRED xmlns:swig CDATA #REQUIRED xmlns:c CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:type EMPTY>
|
||||
<!ATTLIST swigxml:type name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:code (#PCDATA)>
|
||||
<!ATTLIST swigxml:code name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:method EMPTY>
|
||||
<!ATTLIST swigxml:method name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:value EMPTY>
|
||||
<!ATTLIST swigxml:value name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:lang EMPTY>
|
||||
<!ATTLIST swigxml:lang name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:parms (swigxml:parm+|swigxml:none+)>
|
||||
<!ATTLIST swigxml:parms name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:parm (swigxml:value?,swigxml:type)>
|
||||
<!ATTLIST swigxml:parm name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:storage EMPTY>
|
||||
<!ATTLIST swigxml:storage name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:classtype EMPTY>
|
||||
<!ATTLIST swigxml:classtype name CDATA #IMPLIED string (struct|class|union) #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:namespace EMPTY>
|
||||
<!ATTLIST swigxml:namespace name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:bases (swigxml:item+)>
|
||||
<!ATTLIST swigxml:bases name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:item EMPTY>
|
||||
<!ATTLIST swigxml:item name CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:node EMPTY>
|
||||
<!ATTLIST swigxml:node ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:scriptname EMPTY>
|
||||
<!ATTLIST swigxml:scriptname name CDATA #REQUIRED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:abstract EMPTY>
|
||||
<!ATTLIST swigxml:abstract name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:section EMPTY>
|
||||
<!ATTLIST swigxml:section name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:srctype EMPTY>
|
||||
<!ATTLIST swigxml:srctype name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:srcname EMPTY>
|
||||
<!ATTLIST swigxml:srcname name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:none (swigxml:type)>
|
||||
<!ATTLIST swigxml:none name CDATA #IMPLIED ident CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT swigxml:altname EMPTY>
|
||||
<!ATTLIST swigxml:altname name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
/****************************************************************************
|
||||
* Simplified Wrapper and Interface Generator (SWIG)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
|
||||
extern "C" DOH *xml_run(DOH *node);
|
||||
extern "C" int xml_init(int argc, char *argv[]);
|
||||
|
||||
|
|
@ -6,7 +6,7 @@ srcdir = @srcdir@
|
|||
VPATH = @srcdir@
|
||||
|
||||
SRCS = expr.c cpp.c
|
||||
OBJS = expr.o cpp.o
|
||||
OBJS = expr.@OBJEXT@ cpp.@OBJEXT@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
|
@ -15,11 +15,11 @@ CC = @CC@
|
|||
AR = @AR@
|
||||
RANLIB = @RANLIB@
|
||||
CFLAGS = @CFLAGS@
|
||||
INCLUDE = -I$(srcdir)/. -I$(srcdir)/../Swig -I$(srcdir)/../DOH/Include
|
||||
INCLUDES = -I$(srcdir)/. -I$(srcdir)/../Swig -I$(srcdir)/../DOH/Include -I$(srcdir)/../Include
|
||||
TARGET = libcpp.a
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(INCLUDE) -c -o $*.o $<
|
||||
.c.@OBJEXT@:
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c -o $*.@OBJEXT@ $<
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
|
|
@ -28,4 +28,4 @@ $(TARGET): $(OBJS)
|
|||
$(RANLIB) $(TARGET)
|
||||
|
||||
clean:
|
||||
rm -f *.o *~ core *.so *.a *_wrap.*
|
||||
rm -f *.@OBJEXT@ *~ core *.so *.a *_wrap.*
|
||||
|
|
|
|||
|
|
@ -15,49 +15,36 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_cpp_c[] = "$Header$";
|
||||
|
||||
#include "preprocessor.h"
|
||||
#include <ctype.h>
|
||||
|
||||
static DOHHash *cpp = 0; /* C preprocessor data */
|
||||
static Hash *cpp = 0; /* C preprocessor data */
|
||||
static int include_all = 0; /* Follow all includes */
|
||||
static int ignore_missing = 0;
|
||||
static int import_all = 0; /* Follow all includes, but as %import statements */
|
||||
static int single_include = 1; /* Only include each file once */
|
||||
static int silent_errors = 0;
|
||||
static DOHHash *included_files = 0;
|
||||
|
||||
/* Handle an error */
|
||||
|
||||
static void cpp_error(DOHString *file, int line, char *fmt, ...) {
|
||||
va_list ap;
|
||||
if (silent_errors) return;
|
||||
va_start(ap,fmt);
|
||||
if (line > 0) {
|
||||
Printf(stderr,"%s:%d ", file, line);
|
||||
} else {
|
||||
Printf(stderr,"%s:EOF ",file);
|
||||
}
|
||||
vPrintf(stderr,fmt,ap);
|
||||
va_end(ap);
|
||||
}
|
||||
static Hash *included_files = 0;
|
||||
static List *dependencies = 0;
|
||||
|
||||
/* Test a character to see if it starts an identifier */
|
||||
static int
|
||||
isidentifier(char c) {
|
||||
isidentifier(int c) {
|
||||
if ((isalpha(c)) || (c == '_') || (c == '$')) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
/* Test a character to see if it valid in an identifier (after the first letter) */
|
||||
static int
|
||||
isidchar(char c) {
|
||||
isidchar(int c) {
|
||||
if ((isalnum(c)) || (c == '_') || (c == '$')) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
/* Skip whitespace */
|
||||
static void
|
||||
skip_whitespace(DOH *s, DOH *out) {
|
||||
skip_whitespace(File *s, File *out) {
|
||||
int c;
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
if (!isspace(c)) {
|
||||
|
|
@ -69,7 +56,7 @@ skip_whitespace(DOH *s, DOH *out) {
|
|||
|
||||
/* Skip to a specified character taking line breaks into account */
|
||||
static int
|
||||
skip_tochar(DOHFile *s, int ch, DOHFile *out) {
|
||||
skip_tochar(File *s, int ch, File *out) {
|
||||
int c;
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
if (out) Putc(c,out);
|
||||
|
|
@ -89,8 +76,8 @@ copy_location(DOH *s1, DOH *s2) {
|
|||
Setline(s2,Getline(s1));
|
||||
}
|
||||
|
||||
static DOHString *cpp_include(DOHString_or_char *fn) {
|
||||
DOHString *s;
|
||||
static String *cpp_include(String_or_char *fn) {
|
||||
String *s;
|
||||
if (single_include) {
|
||||
if (Getattr(included_files,fn)) return 0;
|
||||
Setattr(included_files,fn,fn);
|
||||
|
|
@ -98,18 +85,31 @@ static DOHString *cpp_include(DOHString_or_char *fn) {
|
|||
s = Swig_include(fn);
|
||||
if (!s) {
|
||||
Seek(fn,0,SEEK_SET);
|
||||
cpp_error(Getfile(fn),Getline(fn),"Unable to find '%s'\n", fn);
|
||||
if (ignore_missing) {
|
||||
Swig_warning(WARN_PP_MISSING_FILE,Getfile(fn),Getline(fn),"Unable to find '%s'\n", fn);
|
||||
} else {
|
||||
Swig_error(Getfile(fn),Getline(fn),"Unable to find '%s'\n", fn);
|
||||
}
|
||||
} else {
|
||||
Seek(s,0,SEEK_SET);
|
||||
if (!dependencies) {
|
||||
dependencies = NewList();
|
||||
}
|
||||
Append(dependencies, Copy(Swig_last_file()));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
List *Preprocessor_depend(void) {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void Preprocessor_cpp_init() - Initialize the preprocessor
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void Preprocessor_init() {
|
||||
DOHHash *s;
|
||||
extern void Preprocessor_expr_init(void);
|
||||
Hash *s;
|
||||
cpp = NewHash();
|
||||
s = NewHash();
|
||||
Setattr(cpp,"symbols",s);
|
||||
|
|
@ -123,6 +123,15 @@ void Preprocessor_include_all(int a) {
|
|||
include_all = a;
|
||||
}
|
||||
|
||||
void Preprocessor_import_all(int a) {
|
||||
import_all = a;
|
||||
}
|
||||
|
||||
void Preprocessor_ignore_missing(int a) {
|
||||
ignore_missing = a;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Preprocessor_define()
|
||||
*
|
||||
|
|
@ -130,30 +139,30 @@ void Preprocessor_include_all(int a) {
|
|||
* SWIG macro semantics.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
|
||||
Hash *Preprocessor_define(const String_or_char *_str, int swigmacro)
|
||||
{
|
||||
DOHString *macroname = 0, *argstr = 0, *macrovalue = 0, *file = 0, *s = 0;
|
||||
DOHHash *macro = 0, *symbols = 0, *m1;
|
||||
DOHList *arglist = 0;
|
||||
String *macroname = 0, *argstr = 0, *macrovalue = 0, *file = 0, *s = 0;
|
||||
Hash *macro = 0, *symbols = 0, *m1;
|
||||
List *arglist = 0;
|
||||
int c, line;
|
||||
int varargs = 0;
|
||||
String_or_char *str = (String_or_char *) _str;
|
||||
|
||||
assert(cpp);
|
||||
assert(str);
|
||||
|
||||
/* First make sure that string is actually a string */
|
||||
if (DohCheck(str)) {
|
||||
s = Copy(str);
|
||||
s = NewString(str);
|
||||
copy_location(str,s);
|
||||
str = s;
|
||||
} else {
|
||||
str = NewString((char *) str);
|
||||
Seek(str,0,SEEK_SET);
|
||||
}
|
||||
Seek(str,0,SEEK_SET);
|
||||
line = Getline(str);
|
||||
file = Getfile(str);
|
||||
|
||||
/* Printf(stdout,"%s:%d '%s'\n", file,line,str); */
|
||||
|
||||
/* Skip over any leading whitespace */
|
||||
skip_whitespace(str,0);
|
||||
|
||||
|
|
@ -169,7 +178,7 @@ DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
|
|||
else Putc(c,argstr);
|
||||
}
|
||||
if (c != ')') {
|
||||
cpp_error(Getfile(str),Getline(str), "Missing \')\' in macro parameters\n");
|
||||
Swig_error(Getfile(str),Getline(str), "Missing \')\' in macro parameters\n");
|
||||
goto macro_error;
|
||||
}
|
||||
break;
|
||||
|
|
@ -178,7 +187,7 @@ DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
|
|||
} else if (isspace(c)) {
|
||||
break;
|
||||
} else {
|
||||
cpp_error(Getfile(str),Getline(str),"Illegal character in macro name\n");
|
||||
Swig_error(Getfile(str),Getline(str),"Illegal character in macro name\n");
|
||||
goto macro_error;
|
||||
}
|
||||
}
|
||||
|
|
@ -197,18 +206,38 @@ DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
|
|||
argname = NewString("");
|
||||
while ((c = Getc(argstr)) != EOF) {
|
||||
if (c == ',') {
|
||||
Append(arglist,argname);
|
||||
/* Check for varargs */
|
||||
if (Strstr(argname,".")) {
|
||||
if (Strcmp(argname,"...") != 0) {
|
||||
Swig_error(Getfile(str),Getline(str),"Illegal macro argument name '%s'\n", argname);
|
||||
} else {
|
||||
Append(arglist,"__VA_ARGS__");
|
||||
varargs = 1;
|
||||
}
|
||||
} else {
|
||||
Append(arglist,argname);
|
||||
}
|
||||
Delete(argname);
|
||||
argname = NewString("");
|
||||
} else if (isidchar(c)) {
|
||||
} else if (isidchar(c) || (c == '.')) {
|
||||
Putc(c,argname);
|
||||
} else if (!isspace(c)) {
|
||||
cpp_error(Getfile(str),Getline(str),"Illegal character in macro name\n");
|
||||
} else if (!(isspace(c) || (c == '\\'))) {
|
||||
Swig_error(Getfile(str),Getline(str),"Illegal character in macro argument name\n");
|
||||
goto macro_error;
|
||||
}
|
||||
}
|
||||
if (Len(argname)) {
|
||||
Append(arglist,argname);
|
||||
/* Check for varargs */
|
||||
if (Strstr(argname,".")) {
|
||||
if (Strcmp(argname,"...") != 0) {
|
||||
Swig_error(Getfile(str),Getline(str),"Illegal macro argument name '%s'\n", argname);
|
||||
} else {
|
||||
Append(arglist,"__VA_ARGS__");
|
||||
varargs = 1;
|
||||
}
|
||||
} else {
|
||||
Append(arglist,argname);
|
||||
}
|
||||
Delete(argname);
|
||||
}
|
||||
}
|
||||
|
|
@ -216,16 +245,70 @@ DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
|
|||
if (!swigmacro) {
|
||||
Replace(macrovalue,"\\\n"," ", DOH_REPLACE_NOQUOTE);
|
||||
}
|
||||
|
||||
/* Look for special # substitutions. We only consider # that appears
|
||||
outside of quotes and comments */
|
||||
|
||||
{
|
||||
int state = 0;
|
||||
char *cc = Char(macrovalue);
|
||||
while (*cc) {
|
||||
switch(state) {
|
||||
case 0:
|
||||
if (*cc == '#') *cc = '\001';
|
||||
else if (*cc == '/') state = 10;
|
||||
else if (*cc == '\'') state = 20;
|
||||
else if (*cc == '\"') state = 30;
|
||||
break;
|
||||
case 10:
|
||||
if (*cc == '*') state = 11;
|
||||
else if (*cc == '/') state = 15;
|
||||
else {
|
||||
state = 0;
|
||||
cc--;
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
if (*cc == '*') state = 12;
|
||||
break;
|
||||
case 12:
|
||||
if (*cc == '/') state = 0;
|
||||
else if (*cc != '*') state = 11;
|
||||
break;
|
||||
case 15:
|
||||
if (*cc == '\n') state = 0;
|
||||
break;
|
||||
case 20:
|
||||
if (*cc == '\'') state = 0;
|
||||
if (*cc == '\\') state = 21;
|
||||
break;
|
||||
case 21:
|
||||
state = 20;
|
||||
break;
|
||||
case 30:
|
||||
if (*cc == '\"') state = 0;
|
||||
if (*cc == '\\') state = 31;
|
||||
break;
|
||||
case 31:
|
||||
state = 30;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
cc++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get rid of whitespace surrounding # */
|
||||
Replace(macrovalue,"#","\001",DOH_REPLACE_NOQUOTE);
|
||||
/* Replace(macrovalue,"#","\001",DOH_REPLACE_NOQUOTE); */
|
||||
while(strstr(Char(macrovalue),"\001 ")) {
|
||||
Replace(macrovalue,"\001 ","\001", DOH_REPLACE_NOQUOTE);
|
||||
Replace(macrovalue,"\001 ","\001", DOH_REPLACE_ANY);
|
||||
}
|
||||
while(strstr(Char(macrovalue)," \001")) {
|
||||
Replace(macrovalue," \001","\001", DOH_REPLACE_NOQUOTE);
|
||||
Replace(macrovalue," \001","\001", DOH_REPLACE_ANY);
|
||||
}
|
||||
/* Replace '##' with a special token */
|
||||
Replace(macrovalue,"\001\001","\002", DOH_REPLACE_NOQUOTE);
|
||||
Replace(macrovalue,"\001\001","\002", DOH_REPLACE_ANY);
|
||||
|
||||
/* Go create the macro */
|
||||
macro = NewHash();
|
||||
|
|
@ -234,6 +317,9 @@ DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
|
|||
if (arglist) {
|
||||
Setattr(macro,"args",arglist);
|
||||
Delete(arglist);
|
||||
if (varargs) {
|
||||
Setattr(macro,"varargs","1");
|
||||
}
|
||||
}
|
||||
Setattr(macro,"value",macrovalue);
|
||||
Delete(macrovalue);
|
||||
|
|
@ -245,7 +331,7 @@ DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
|
|||
symbols = Getattr(cpp,"symbols");
|
||||
if ((m1 = Getattr(symbols,macroname))) {
|
||||
if (Cmp(Getattr(m1,"value"),macrovalue))
|
||||
cpp_error(Getfile(str),Getline(str),"Macro '%s' redefined. Previous definition in \'%s\', Line %d\n", macroname, Getfile(m1), Getline(m1));
|
||||
Swig_error(Getfile(str),Getline(str),"Macro '%s' redefined. Previous definition in \'%s\', Line %d\n", macroname, Getfile(m1), Getline(m1));
|
||||
}
|
||||
Setattr(symbols,macroname,macro);
|
||||
Delete(str);
|
||||
|
|
@ -263,9 +349,9 @@ DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
|
|||
*
|
||||
* Undefines a macro.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void Preprocessor_undef(DOHString_or_char *str)
|
||||
void Preprocessor_undef(String_or_char *str)
|
||||
{
|
||||
DOH *symbols;
|
||||
Hash *symbols;
|
||||
assert(cpp);
|
||||
symbols = Getattr(cpp,"symbols");
|
||||
Delattr(symbols,str);
|
||||
|
|
@ -277,11 +363,11 @@ void Preprocessor_undef(DOHString_or_char *str)
|
|||
* Isolates macro arguments and returns them in a list. For each argument,
|
||||
* leading and trailing whitespace is stripped (ala K&R, pg. 230).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
static DOHList *
|
||||
find_args(DOHString *s)
|
||||
static List *
|
||||
find_args(String *s)
|
||||
{
|
||||
DOHList *args;
|
||||
DOHString *str;
|
||||
List *args;
|
||||
String *str;
|
||||
int c, level;
|
||||
long pos;
|
||||
|
||||
|
|
@ -344,7 +430,7 @@ find_args(DOHString *s)
|
|||
c = Getc(s);
|
||||
}
|
||||
unterm:
|
||||
cpp_error(Getfile(args),Getline(args),"Unterminated macro call.\n");
|
||||
Swig_error(Getfile(args),Getline(args),"Unterminated macro call.\n");
|
||||
return args;
|
||||
}
|
||||
|
||||
|
|
@ -355,9 +441,9 @@ find_args(DOHString *s)
|
|||
* or bare.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOHString *
|
||||
get_filename(DOHString *str) {
|
||||
DOHString *fn;
|
||||
static String *
|
||||
get_filename(String *str) {
|
||||
String *fn;
|
||||
int c;
|
||||
|
||||
skip_whitespace(str,0);
|
||||
|
|
@ -377,6 +463,31 @@ get_filename(DOHString *str) {
|
|||
return fn;
|
||||
}
|
||||
|
||||
static String *
|
||||
get_options(String *str) {
|
||||
|
||||
int c;
|
||||
skip_whitespace(str,0);
|
||||
c = Getc(str);
|
||||
if (c == '(') {
|
||||
String *opt;
|
||||
int level = 1;
|
||||
opt = NewString("(");
|
||||
while (((c = Getc(str)) != EOF)) {
|
||||
Putc(c,opt);
|
||||
if (c == ')') {
|
||||
level--;
|
||||
if (!level) return opt;
|
||||
}
|
||||
if (c == '(') level++;
|
||||
}
|
||||
Delete(opt);
|
||||
return 0;
|
||||
} else {
|
||||
Ungetc(c,str);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* -----------------------------------------------------------------------------
|
||||
* expand_macro()
|
||||
*
|
||||
|
|
@ -386,12 +497,13 @@ get_filename(DOHString *str) {
|
|||
|
||||
DOH *expanded_value = 0;
|
||||
|
||||
static DOHString *
|
||||
expand_macro(DOHString_or_char *name, DOHList *args)
|
||||
static String *
|
||||
expand_macro(String_or_char *name, List *args)
|
||||
{
|
||||
DOH *symbols, *ns, *macro, *margs, *mvalue, *temp, *tempa, *e;
|
||||
DOH *Preprocessor_replace(DOH *);
|
||||
int i, l;
|
||||
int isvarargs = 0;
|
||||
|
||||
symbols = Getattr(cpp,"symbols");
|
||||
if (!symbols) return 0;
|
||||
|
|
@ -420,14 +532,37 @@ expand_macro(DOHString_or_char *name, DOHList *args)
|
|||
assert(mvalue);
|
||||
margs = Getattr(macro,"args");
|
||||
|
||||
if (Getattr(macro,"varargs")) {
|
||||
isvarargs = 1;
|
||||
/* Variable length argument macro. We need to collect all of the extra arguments into a single argument */
|
||||
if (Len(args) >= (Len(margs)-1)) {
|
||||
int i;
|
||||
int vi, na;
|
||||
String *vararg = NewString("");
|
||||
vi = Len(margs)-1;
|
||||
na = Len(args);
|
||||
for (i = vi; i < na; i++) {
|
||||
Append(vararg,Getitem(args,i));
|
||||
if ((i+1) < na) {
|
||||
Append(vararg,",");
|
||||
}
|
||||
}
|
||||
/* Remove arguments */
|
||||
for (i = vi; i < na; i++) {
|
||||
Delitem(args,vi);
|
||||
}
|
||||
Append(args,vararg);
|
||||
Delete(vararg);
|
||||
}
|
||||
}
|
||||
/* If there are arguments, see if they match what we were given */
|
||||
if ((margs) && (Len(margs) != Len(args))) {
|
||||
if (Len(margs) > 1)
|
||||
cpp_error(Getfile(args),Getline(args),"Macro '%s' expects %d arguments\n", name, Len(margs));
|
||||
else if (Len(margs) == 1)
|
||||
cpp_error(Getfile(args),Getline(args),"Macro '%s' expects 1 argument\n", name);
|
||||
if (Len(margs) > (1+isvarargs))
|
||||
Swig_error(Getfile(args),Getline(args),"Macro '%s' expects %d arguments\n", name, Len(margs)-isvarargs);
|
||||
else if (Len(margs) == (1+isvarargs))
|
||||
Swig_error(Getfile(args),Getline(args),"Macro '%s' expects 1 argument\n", name);
|
||||
else
|
||||
cpp_error(Getfile(args),Getline(args),"Macro '%s' expects no arguments\n", name);
|
||||
Swig_error(Getfile(args),Getline(args),"Macro '%s' expects no arguments\n", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -480,27 +615,49 @@ expand_macro(DOHString_or_char *name, DOHList *args)
|
|||
}
|
||||
Replace(ns,temp,rep, DOH_REPLACE_ANY);
|
||||
}
|
||||
if (isvarargs) {
|
||||
if ((Strcmp(aname,"__VA_ARGS__") == 0) && (Len(arg) == 0)) {
|
||||
/* Zero length __VA_ARGS__ macro argument. We search for commas that might appear before and nuke them */
|
||||
char *a, *s, *t;
|
||||
s = Char(ns);
|
||||
a = strstr(s,"__VA_ARGS__");
|
||||
while (a) {
|
||||
t = a-1;
|
||||
if (*t == '\002') {
|
||||
t--;
|
||||
while (t >= s) {
|
||||
if (isspace((int) *t)) t--;
|
||||
else if (*t == ',') {
|
||||
*t = ' ';
|
||||
} else break;
|
||||
}
|
||||
}
|
||||
a = strstr(a+11,"__VA_ARGS__");
|
||||
}
|
||||
}
|
||||
}
|
||||
Replace(ns, aname, arg, DOH_REPLACE_ID);
|
||||
}
|
||||
}
|
||||
Replace(ns,"\002","",DOH_REPLACE_ANY); /* Get rid of concatenation tokens */
|
||||
Replace(ns,"\001","#",DOH_REPLACE_ANY); /* Put # back (non-standard C) */
|
||||
|
||||
|
||||
/* Expand this macro even further */
|
||||
e = Preprocessor_replace(ns);
|
||||
|
||||
Delete(ns);
|
||||
Delattr(macro,"*expanded*");
|
||||
if (Getattr(macro,"swigmacro")) {
|
||||
DOHString *g;
|
||||
DOHString *f = NewString("");
|
||||
Printf(f,"%%macro %s, \"%s\", %d {\n", name, Getfile(macro), Getline(macro));
|
||||
String *g;
|
||||
String *f = NewString("");
|
||||
Seek(e,0,SEEK_SET);
|
||||
copy_location(macro,e);
|
||||
g = Preprocessor_parse(e);
|
||||
Printf(f,"%s\n", g);
|
||||
Printf(f,"}\n");
|
||||
|
||||
/* Drop the macro in place, but with a marker around it */
|
||||
Printf(f,"/*@%s,%d,%s@*/%s/*@@*/", Getfile(macro), Getline(macro), name, g);
|
||||
|
||||
/* Printf(f," }\n"); */
|
||||
Delete(g);
|
||||
Delete(e);
|
||||
e = f;
|
||||
|
|
@ -510,6 +667,24 @@ expand_macro(DOHString_or_char *name, DOHList *args)
|
|||
return e;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* evaluate_args()
|
||||
*
|
||||
* Evaluate the arguments of a macro
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
List *evaluate_args(List *x) {
|
||||
String *a;
|
||||
String *Preprocessor_replace(String *);
|
||||
|
||||
List *nl = NewList();
|
||||
|
||||
for (a = Firstitem(x); a; a = Nextitem(x)) {
|
||||
Append(nl,Preprocessor_replace(a));
|
||||
}
|
||||
return nl;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *Preprocessor_replace(DOH *s)
|
||||
*
|
||||
|
|
@ -575,6 +750,7 @@ Preprocessor_replace(DOH *s)
|
|||
DOH *arg = 0;
|
||||
args = NewList();
|
||||
arg = NewString("");
|
||||
if (isidchar(c)) Putc(c,arg);
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
if (!isidchar(c)) {
|
||||
Seek(s,-1,SEEK_CUR);
|
||||
|
|
@ -585,8 +761,8 @@ Preprocessor_replace(DOH *s)
|
|||
Append(args,arg);
|
||||
Delete(arg);
|
||||
}
|
||||
if (!args) {
|
||||
cpp_error(Getfile(id),Getline(id),"No arguments given to defined()\n");
|
||||
if ((!args) || (!Len(args))) {
|
||||
Swig_error(Getfile(id),Getline(id),"No arguments given to defined()\n");
|
||||
state = 0;
|
||||
break;
|
||||
}
|
||||
|
|
@ -608,7 +784,10 @@ Preprocessor_replace(DOH *s)
|
|||
break;
|
||||
}
|
||||
if (Cmp(id,"__FILE__") == 0) {
|
||||
Printf(ns,"\"%s\"",Getfile(s));
|
||||
String *fn = Copy(Getfile(s));
|
||||
Replaceall(fn,"\\","\\\\");
|
||||
Printf(ns,"\"%s\"",fn);
|
||||
Delete(fn);
|
||||
state = 0;
|
||||
break;
|
||||
}
|
||||
|
|
@ -623,6 +802,12 @@ Preprocessor_replace(DOH *s)
|
|||
} else {
|
||||
args = 0;
|
||||
}
|
||||
if (args) {
|
||||
List *nargs = evaluate_args(args);
|
||||
Delete(args);
|
||||
args = nargs;
|
||||
}
|
||||
|
||||
e = expand_macro(id,args);
|
||||
if (e) {
|
||||
Printf(ns,"%s",e);
|
||||
|
|
@ -668,13 +853,13 @@ Preprocessor_replace(DOH *s)
|
|||
if (state == 1) {
|
||||
/* See if this is the special "defined" macro */
|
||||
if (Cmp(id,"defined") == 0) {
|
||||
cpp_error(Getfile(id),Getline(id),"No arguments given to defined()\n");
|
||||
Swig_error(Getfile(id),Getline(id),"No arguments given to defined()\n");
|
||||
} else if ((m = Getattr(symbols,id))) {
|
||||
DOH *e;
|
||||
/* Yes. There is a macro here */
|
||||
/* See if the macro expects arguments */
|
||||
if (Getattr(m,"args")) {
|
||||
cpp_error(Getfile(id),Getline(id),"Macro arguments expected.\n");
|
||||
Swig_error(Getfile(id),Getline(id),"Macro arguments expected.\n");
|
||||
}
|
||||
e = expand_macro(id,0);
|
||||
Printf(ns,"%s",e);
|
||||
|
|
@ -698,52 +883,24 @@ Preprocessor_replace(DOH *s)
|
|||
static int
|
||||
check_id(DOH *s)
|
||||
{
|
||||
int c, state = 0;
|
||||
int hasvalue = 0;
|
||||
Seek(s,0,SEEK_SET);
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
switch(state) {
|
||||
static SwigScanner *scan = 0;
|
||||
int c;
|
||||
|
||||
case 0:
|
||||
if (isdigit(c)) {
|
||||
hasvalue =1;
|
||||
state = 1;
|
||||
}
|
||||
else if (isidentifier(c)) return 1;
|
||||
else if (c == '\"') {
|
||||
skip_tochar(s,'\"',0);
|
||||
hasvalue = 1;
|
||||
} else if (c == '\'') {
|
||||
skip_tochar(s,'\'',0);
|
||||
hasvalue = 1;
|
||||
} else if (c == '/') state = 3;
|
||||
break;
|
||||
case 1:
|
||||
if (isspace(c)) state = 0;
|
||||
hasvalue = 1;
|
||||
break;
|
||||
case 3:
|
||||
if (c == '*') state = 10;
|
||||
else if (c == '/') state = 20;
|
||||
else {
|
||||
Ungetc(c,s);
|
||||
state = 0;
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
if (c == '*') state = 11;
|
||||
break;
|
||||
case 11:
|
||||
if (c == '/') state = 0;
|
||||
else if (c != '*') state = 10;
|
||||
break;
|
||||
case 20:
|
||||
if (c == '\n') state = 0;
|
||||
break;
|
||||
}
|
||||
Seek(s,0,SEEK_SET);
|
||||
|
||||
if (!scan) {
|
||||
scan = NewSwigScanner();
|
||||
}
|
||||
|
||||
SwigScanner_clear(scan);
|
||||
s = Copy(s);
|
||||
Seek(s,SEEK_SET,0);
|
||||
SwigScanner_push(scan,s);
|
||||
while ((c = SwigScanner_token(scan))) {
|
||||
if ((c == SWIG_TOKEN_ID) || (c == SWIG_TOKEN_LBRACE) || (c == SWIG_TOKEN_RBRACE)) return 1;
|
||||
}
|
||||
if (!hasvalue) return 1;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/* addline(). Utility function for adding lines to a chunk */
|
||||
|
|
@ -775,7 +932,7 @@ static void add_chunk(DOH *ns, DOH *chunk, int allow) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DOH *Preprocessor_parse(DOH *s)
|
||||
* Preprocessor_parse()
|
||||
*
|
||||
* Parses the string s. Returns a new string containing the preprocessed version.
|
||||
*
|
||||
|
|
@ -787,12 +944,13 @@ static void add_chunk(DOH *ns, DOH *chunk, int allow) {
|
|||
* included inline (with all preprocessor directives included).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
Preprocessor_parse(DOH *s)
|
||||
String *
|
||||
Preprocessor_parse(String *s)
|
||||
{
|
||||
DOH *ns; /* New string containing the preprocessed text */
|
||||
DOH *chunk, *symbols, *sval, *decl;
|
||||
DOH *id = 0, *value = 0, *comment = 0;
|
||||
String *ns; /* New string containing the preprocessed text */
|
||||
String *chunk, *sval, *decl;
|
||||
Hash *symbols;
|
||||
String *id = 0, *value = 0, *comment = 0;
|
||||
int i, state, val, e, c;
|
||||
int start_line = 0;
|
||||
int allow = 1;
|
||||
|
|
@ -802,6 +960,9 @@ Preprocessor_parse(DOH *s)
|
|||
int cpp_lines = 0;
|
||||
int cond_lines[256];
|
||||
|
||||
/* Blow away all carriage returns */
|
||||
Replace(s,"\015","",DOH_REPLACE_ANY);
|
||||
|
||||
ns = NewString(""); /* Return result */
|
||||
|
||||
decl = NewString("");
|
||||
|
|
@ -842,12 +1003,12 @@ Preprocessor_parse(DOH *s)
|
|||
else if (c == '\"') {
|
||||
start_line = Getline(s);
|
||||
if (skip_tochar(s,'\"',chunk) < 0) {
|
||||
cpp_error(Getfile(s),-1,"Unterminated string constant starting at line %d\n",start_line);
|
||||
Swig_error(Getfile(s),-1,"Unterminated string constant starting at line %d\n",start_line);
|
||||
}
|
||||
} else if (c == '\'') {
|
||||
start_line = Getline(s);
|
||||
if (skip_tochar(s,'\'',chunk) < 0) {
|
||||
cpp_error(Getfile(s),-1,"Unterminated character constant starting at line %d\n",start_line);
|
||||
Swig_error(Getfile(s),-1,"Unterminated character constant starting at line %d\n",start_line);
|
||||
}
|
||||
}
|
||||
else if (c == '/') state = 30; /* Comment */
|
||||
|
|
@ -896,8 +1057,13 @@ Preprocessor_parse(DOH *s)
|
|||
if (c == '\n') {
|
||||
Ungetc(c,s);
|
||||
state = 50;
|
||||
} else {
|
||||
state = 42;
|
||||
if (!isspace(c)) {
|
||||
Ungetc(c,s);
|
||||
}
|
||||
}
|
||||
else state = 42;
|
||||
|
||||
copy_location(s,value);
|
||||
break;
|
||||
}
|
||||
|
|
@ -922,6 +1088,12 @@ Preprocessor_parse(DOH *s)
|
|||
state = 50;
|
||||
} else if (c == '/') {
|
||||
state = 45;
|
||||
} else if (c == '\"') {
|
||||
Putc(c,value);
|
||||
skip_tochar(s,'\"',value);
|
||||
} else if (c == '\'') {
|
||||
Putc(c,value);
|
||||
skip_tochar(s,'\'',value);
|
||||
} else {
|
||||
Putc(c,value);
|
||||
if (c == '\\') state = 44;
|
||||
|
|
@ -982,9 +1154,9 @@ Preprocessor_parse(DOH *s)
|
|||
if ((m) && !(Getattr(m,"args"))) {
|
||||
v = Copy(Getattr(m,"value"));
|
||||
if (Len(v)) {
|
||||
silent_errors = 1;
|
||||
Swig_error_silent(1);
|
||||
v1 = Preprocessor_replace(v);
|
||||
silent_errors = 0;
|
||||
Swig_error_silent(0);
|
||||
/* Printf(stdout,"checking '%s'\n", v1); */
|
||||
if (!check_id(v1)) {
|
||||
if (Len(comment) == 0)
|
||||
|
|
@ -1021,20 +1193,20 @@ Preprocessor_parse(DOH *s)
|
|||
}
|
||||
} else if (Cmp(id,"else") == 0) {
|
||||
if (level <= 0) {
|
||||
cpp_error(Getfile(s),Getline(id),"Misplaced #else.\n");
|
||||
Swig_error(Getfile(s),Getline(id),"Misplaced #else.\n");
|
||||
} else {
|
||||
cond_lines[level-1] = Getline(id);
|
||||
if (allow) {
|
||||
allow = 0;
|
||||
mask = 0;
|
||||
} else if (level == start_level) {
|
||||
allow = 1;
|
||||
allow = 1*mask;
|
||||
}
|
||||
}
|
||||
} else if (Cmp(id,"endif") == 0) {
|
||||
level--;
|
||||
if (level < 0) {
|
||||
cpp_error(Getfile(id),Getline(id),"Extraneous #endif ignored.\n");
|
||||
Swig_error(Getfile(id),Getline(id),"Extraneous #endif.\n");
|
||||
level = 0;
|
||||
} else {
|
||||
if (level < start_level) {
|
||||
|
|
@ -1053,7 +1225,7 @@ Preprocessor_parse(DOH *s)
|
|||
val = Preprocessor_expr(sval,&e);
|
||||
if (e) {
|
||||
Seek(value,0,SEEK_SET);
|
||||
/* cpp_error(Getfile(value),Getline(value),"Could not evaluate '%s'\n", value); */
|
||||
Swig_warning(WARN_PP_EVALUATION,Getfile(value),Getline(value),"Could not evaluate '%s'\n", value);
|
||||
allow = 0;
|
||||
} else {
|
||||
if (val == 0)
|
||||
|
|
@ -1063,7 +1235,7 @@ Preprocessor_parse(DOH *s)
|
|||
}
|
||||
} else if (Cmp(id,"elif") == 0) {
|
||||
if (level == 0) {
|
||||
cpp_error(Getfile(s),Getline(id),"Misplaced #elif.\n");
|
||||
Swig_error(Getfile(s),Getline(id),"Misplaced #elif.\n");
|
||||
} else {
|
||||
cond_lines[level-1] = Getline(id);
|
||||
if (allow) {
|
||||
|
|
@ -1075,7 +1247,7 @@ Preprocessor_parse(DOH *s)
|
|||
val = Preprocessor_expr(sval,&e);
|
||||
if (e) {
|
||||
Seek(value,0,SEEK_SET);
|
||||
/* cpp_error(Getfile(value),Getline(value),"Could not evaluate '%s'\n", value); */
|
||||
Swig_warning(WARN_PP_EVALUATION,Getfile(value),Getline(value),"Could not evaluate '%s'\n", value);
|
||||
allow = 0;
|
||||
} else {
|
||||
if (val)
|
||||
|
|
@ -1087,24 +1259,36 @@ Preprocessor_parse(DOH *s)
|
|||
}
|
||||
} else if (Cmp(id,"line") == 0) {
|
||||
} else if (Cmp(id,"include") == 0) {
|
||||
if ((include_all) && (allow)) {
|
||||
if (((include_all) || (import_all)) && (allow)) {
|
||||
DOH *s1, *s2, *fn;
|
||||
Seek(value,0,SEEK_SET);
|
||||
fn = get_filename(value);
|
||||
s1 = cpp_include(fn);
|
||||
if (s1) {
|
||||
Printf(ns,"%%file(\"include\") \"%s\" {\n", Swig_last_file());
|
||||
if (include_all)
|
||||
Printf(ns,"%%includefile \"%s\" [\n", Swig_last_file());
|
||||
else if (import_all)
|
||||
Printf(ns,"%%importfile \"%s\" [\n", Swig_last_file());
|
||||
s2 = Preprocessor_parse(s1);
|
||||
addline(ns,s2,allow);
|
||||
Printf(ns,"\n}\n");
|
||||
Printf(ns,"\n]\n");
|
||||
Delete(s2);
|
||||
}
|
||||
Delete(s1);
|
||||
Delete(fn);
|
||||
}
|
||||
} else if (Cmp(id,"pragma") == 0) {
|
||||
if (Strncmp(value,"SWIG ",5) == 0) {
|
||||
char *c = Char(value)+5;
|
||||
while (*c && (isspace((int)*c))) c++;
|
||||
if (*c) {
|
||||
if (Strncmp(c,"nowarn=",7) == 0) {
|
||||
Swig_warnfilter(c+7,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (Cmp(id,"level") == 0) {
|
||||
cpp_error(Getfile(s),Getline(id),"cpp debug: level = %d, startlevel = %d\n", level, start_level);
|
||||
Swig_error(Getfile(s),Getline(id),"cpp debug: level = %d, startlevel = %d\n", level, start_level);
|
||||
}
|
||||
for (i = 0; i < cpp_lines; i++)
|
||||
Putc('\n',ns);
|
||||
|
|
@ -1124,8 +1308,9 @@ Preprocessor_parse(DOH *s)
|
|||
}
|
||||
/* %#cpp - an embedded C preprocessor directive (we strip off the %) */
|
||||
else if (c == '#') {
|
||||
add_chunk(ns,chunk,allow);
|
||||
Putc(c,chunk);
|
||||
state = 0;
|
||||
state = 107;
|
||||
} else if (isidentifier(c)) {
|
||||
Clear(decl);
|
||||
Putc('%',decl);
|
||||
|
|
@ -1155,6 +1340,22 @@ Preprocessor_parse(DOH *s)
|
|||
state = 105;
|
||||
}
|
||||
break;
|
||||
|
||||
case 107:
|
||||
Putc(c,chunk);
|
||||
if (c == '\n') {
|
||||
addline(ns,chunk,allow);
|
||||
Clear(chunk);
|
||||
state = 0;
|
||||
} else if (c == '\\') {
|
||||
state = 108;
|
||||
}
|
||||
break;
|
||||
|
||||
case 108:
|
||||
Putc(c,chunk);
|
||||
state = 107;
|
||||
break;
|
||||
|
||||
case 110:
|
||||
if (!isidchar(c)) {
|
||||
|
|
@ -1163,22 +1364,31 @@ Preprocessor_parse(DOH *s)
|
|||
if ((Cmp(decl,"%include") == 0) || (Cmp(decl,"%import") == 0) || (Cmp(decl,"%extern") == 0)) {
|
||||
/* Got some kind of file inclusion directive */
|
||||
if (allow) {
|
||||
DOH *s1, *s2, *fn;
|
||||
DOH *s1, *s2, *fn, *opt;
|
||||
|
||||
if (Cmp(decl,"%extern") == 0) {
|
||||
Swig_warning(WARN_DEPRECATED_EXTERN, Getfile(s),Getline(s),"%%extern is deprecated. Use %%import instead.\n");
|
||||
Clear(decl);
|
||||
Printf(decl,"%%import");
|
||||
}
|
||||
opt = get_options(s);
|
||||
fn = get_filename(s);
|
||||
s1 = cpp_include(fn);
|
||||
if (s1) {
|
||||
add_chunk(ns,chunk,allow);
|
||||
copy_location(s,chunk);
|
||||
Printf(ns,"%%file(\"%s\") \"%s\" {\n", Char(decl)+1, Swig_last_file());
|
||||
Printf(ns,"%sfile%s \"%s\" [\n", decl, opt, Swig_last_file());
|
||||
if ((Cmp(decl,"%import") == 0) || (Cmp(decl,"%extern") == 0)) {
|
||||
Preprocessor_define("WRAPEXTERN 1", 0);
|
||||
Preprocessor_define("SWIGIMPORT 1", 0);
|
||||
}
|
||||
s2 = Preprocessor_parse(s1);
|
||||
if ((Cmp(decl,"%import") == 0) || (Cmp(decl,"%extern") == 0)) {
|
||||
Preprocessor_undef("SWIGIMPORT");
|
||||
Preprocessor_undef("WRAPEXTERN");
|
||||
}
|
||||
addline(ns,s2,allow);
|
||||
Printf(ns,"\n}\n");
|
||||
Printf(ns,"\n]\n");
|
||||
Delete(s2);
|
||||
Delete(s1);
|
||||
}
|
||||
|
|
@ -1209,15 +1419,17 @@ Preprocessor_parse(DOH *s)
|
|||
Putc(c,value);
|
||||
if (c == '%') {
|
||||
int i = 0;
|
||||
char *d = "enddef\n";
|
||||
for (i = 0; i < 7; i++) {
|
||||
char *d = "enddef";
|
||||
for (i = 0; i < 6; i++) {
|
||||
c = Getc(s);
|
||||
Putc(c,value);
|
||||
if (c != d[i]) break;
|
||||
}
|
||||
if (i == 7) {
|
||||
c = Getc(s);
|
||||
Ungetc(c,s);
|
||||
if ((i == 6) && (isspace(c))) {
|
||||
/* Got the macro */
|
||||
for (i = 0; i < 8; i++) {
|
||||
for (i = 0; i < 7; i++) {
|
||||
Delitem(value,DOH_END);
|
||||
}
|
||||
if (allow) {
|
||||
|
|
@ -1237,18 +1449,18 @@ Preprocessor_parse(DOH *s)
|
|||
}
|
||||
}
|
||||
while (level > 0) {
|
||||
cpp_error(Getfile(s),-1,"Missing #endif for conditional starting on line %d\n", cond_lines[level-1]);
|
||||
Swig_error(Getfile(s),-1,"Missing #endif for conditional starting on line %d\n", cond_lines[level-1]);
|
||||
level--;
|
||||
}
|
||||
if (state == 150) {
|
||||
Seek(value,0,SEEK_SET);
|
||||
cpp_error(Getfile(s),-1,"Missing %%enddef for macro starting on line %d\n",Getline(value));
|
||||
Swig_error(Getfile(s),-1,"Missing %%enddef for macro starting on line %d\n",Getline(value));
|
||||
}
|
||||
if ((state >= 105) && (state < 107)) {
|
||||
cpp_error(Getfile(s),-1,"Unterminated %%{ ... %%} block starting on line %d\n", start_line);
|
||||
Swig_error(Getfile(s),-1,"Unterminated %%{ ... %%} block starting on line %d\n", start_line);
|
||||
}
|
||||
if ((state >= 30) && (state < 40)) {
|
||||
cpp_error(Getfile(s),-1,"Unterminated comment starting on line %d\n", start_line);
|
||||
Swig_error(Getfile(s),-1,"Unterminated comment starting on line %d\n", start_line);
|
||||
}
|
||||
add_chunk(ns,chunk,allow);
|
||||
copy_location(s,chunk);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_expr_c[] = "$Header$";
|
||||
|
||||
#include "preprocessor.h"
|
||||
|
||||
|
|
@ -19,6 +19,7 @@ static SwigScanner *scan = 0;
|
|||
typedef struct {
|
||||
int op;
|
||||
long value;
|
||||
String *svalue;
|
||||
} exprval;
|
||||
|
||||
#define EXPR_TOP 1
|
||||
|
|
@ -66,95 +67,122 @@ static void reduce_op() {
|
|||
sp = 0;
|
||||
return;
|
||||
}
|
||||
switch(stack[sp-1].value) {
|
||||
case SWIG_TOKEN_STAR:
|
||||
stack[sp-2].value = stack[sp-2].value * stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_EQUALTO:
|
||||
stack[sp-2].value = stack[sp-2].value == stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_NOTEQUAL:
|
||||
stack[sp-2].value = stack[sp-2].value != stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_PLUS:
|
||||
stack[sp-2].value = stack[sp-2].value + stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_MINUS:
|
||||
stack[sp-2].value = stack[sp-2].value - stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_AND:
|
||||
stack[sp-2].value = stack[sp-2].value & stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_LAND:
|
||||
stack[sp-2].value = stack[sp-2].value && stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_OR:
|
||||
stack[sp-2].value = stack[sp-2].value | stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_LOR:
|
||||
stack[sp-2].value = stack[sp-2].value || stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_XOR:
|
||||
stack[sp-2].value = stack[sp-2].value ^ stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_LESSTHAN:
|
||||
stack[sp-2].value = stack[sp-2].value < stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_GREATERTHAN:
|
||||
stack[sp-2].value = stack[sp-2].value > stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_LTEQUAL:
|
||||
stack[sp-2].value = stack[sp-2].value <= stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_GTEQUAL:
|
||||
stack[sp-2].value = stack[sp-2].value >= stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_NOT:
|
||||
stack[sp-1].value = ~stack[sp].value;
|
||||
sp--;
|
||||
break;
|
||||
case SWIG_TOKEN_LNOT:
|
||||
stack[sp-1].value = !stack[sp].value;
|
||||
sp--;
|
||||
break;
|
||||
case EXPR_UMINUS:
|
||||
stack[sp-1].value = -stack[sp].value;
|
||||
sp--;
|
||||
break;
|
||||
case SWIG_TOKEN_SLASH:
|
||||
stack[sp-2].value = stack[sp-2].value / stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_PERCENT:
|
||||
stack[sp-2].value = stack[sp-2].value % stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_LSHIFT:
|
||||
stack[sp-2].value = stack[sp-2].value << stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_RSHIFT:
|
||||
stack[sp-2].value = stack[sp-2].value >> stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
default:
|
||||
errmsg = "Syntax error";
|
||||
sp = 0;
|
||||
break;
|
||||
if (stack[sp-2].svalue || stack[sp].svalue) {
|
||||
/* A string expression */
|
||||
if (!(stack[sp-2].svalue && stack[sp].svalue)) {
|
||||
errmsg = "Can't mix strings and integers in expression";
|
||||
sp = 0;
|
||||
return;
|
||||
}
|
||||
switch(stack[sp-1].value) {
|
||||
case SWIG_TOKEN_EQUALTO:
|
||||
stack[sp-2].value = (Strcmp(stack[sp-2].svalue,stack[sp].svalue) == 0);
|
||||
Delete(stack[sp-2].svalue);
|
||||
Delete(stack[sp].svalue);
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_NOTEQUAL:
|
||||
stack[sp-2].value = (Strcmp(stack[sp-2].svalue,stack[sp].svalue) != 0);
|
||||
Delete(stack[sp-2].svalue);
|
||||
Delete(stack[sp].svalue);
|
||||
sp -= 2;
|
||||
break;
|
||||
default:
|
||||
errmsg = "Syntax error";
|
||||
sp = 0;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch(stack[sp-1].value) {
|
||||
case SWIG_TOKEN_STAR:
|
||||
stack[sp-2].value = stack[sp-2].value * stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_EQUALTO:
|
||||
stack[sp-2].value = stack[sp-2].value == stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_NOTEQUAL:
|
||||
stack[sp-2].value = stack[sp-2].value != stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_PLUS:
|
||||
stack[sp-2].value = stack[sp-2].value + stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_MINUS:
|
||||
stack[sp-2].value = stack[sp-2].value - stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_AND:
|
||||
stack[sp-2].value = stack[sp-2].value & stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_LAND:
|
||||
stack[sp-2].value = stack[sp-2].value && stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_OR:
|
||||
stack[sp-2].value = stack[sp-2].value | stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_LOR:
|
||||
stack[sp-2].value = stack[sp-2].value || stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_XOR:
|
||||
stack[sp-2].value = stack[sp-2].value ^ stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_LESSTHAN:
|
||||
stack[sp-2].value = stack[sp-2].value < stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_GREATERTHAN:
|
||||
stack[sp-2].value = stack[sp-2].value > stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_LTEQUAL:
|
||||
stack[sp-2].value = stack[sp-2].value <= stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_GTEQUAL:
|
||||
stack[sp-2].value = stack[sp-2].value >= stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_NOT:
|
||||
stack[sp-1].value = ~stack[sp].value;
|
||||
sp--;
|
||||
break;
|
||||
case SWIG_TOKEN_LNOT:
|
||||
stack[sp-1].value = !stack[sp].value;
|
||||
sp--;
|
||||
break;
|
||||
case EXPR_UMINUS:
|
||||
stack[sp-1].value = -stack[sp].value;
|
||||
sp--;
|
||||
break;
|
||||
case SWIG_TOKEN_SLASH:
|
||||
stack[sp-2].value = stack[sp-2].value / stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_PERCENT:
|
||||
stack[sp-2].value = stack[sp-2].value % stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_LSHIFT:
|
||||
stack[sp-2].value = stack[sp-2].value << stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
case SWIG_TOKEN_RSHIFT:
|
||||
stack[sp-2].value = stack[sp-2].value >> stack[sp].value;
|
||||
sp -= 2;
|
||||
break;
|
||||
default:
|
||||
errmsg = "Syntax error";
|
||||
sp = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
stack[sp].op = EXPR_VALUE;
|
||||
}
|
||||
|
|
@ -187,6 +215,7 @@ Preprocessor_expr(DOH *s, int *error) {
|
|||
assert(scan);
|
||||
|
||||
Seek(s,0,SEEK_SET);
|
||||
/* Printf(stdout,"evaluating : '%s'\n", s); */
|
||||
*error = 0;
|
||||
SwigScanner_clear(scan);
|
||||
SwigScanner_push(scan,s);
|
||||
|
|
@ -208,7 +237,10 @@ Preprocessor_expr(DOH *s, int *error) {
|
|||
}
|
||||
if ((token == SWIG_TOKEN_INT) || (token == SWIG_TOKEN_UINT) || (token == SWIG_TOKEN_LONG) || (token == SWIG_TOKEN_ULONG)) {
|
||||
/* A number. Reduce EXPR_TOP to an EXPR_VALUE */
|
||||
stack[sp].value = (long) atol(Char(SwigScanner_text(scan)));
|
||||
char *c = Char(SwigScanner_text(scan));
|
||||
stack[sp].value = (long) strtol(c,0,0);
|
||||
stack[sp].svalue = 0;
|
||||
/* stack[sp].value = (long) atol(Char(SwigScanner_text(scan))); */
|
||||
stack[sp].op = EXPR_VALUE;
|
||||
} else if (token == SWIG_TOKEN_PLUS) { }
|
||||
else if ((token == SWIG_TOKEN_MINUS) || (token == SWIG_TOKEN_LNOT) || (token==SWIG_TOKEN_NOT)) {
|
||||
|
|
@ -216,12 +248,21 @@ Preprocessor_expr(DOH *s, int *error) {
|
|||
stack[sp].value = token;
|
||||
stack[sp++].op = EXPR_OP;
|
||||
stack[sp].op = EXPR_TOP;
|
||||
stack[sp].svalue = 0;
|
||||
} else if ((token == SWIG_TOKEN_LPAREN)) {
|
||||
stack[sp++].op = EXPR_GROUP;
|
||||
stack[sp].op = EXPR_TOP;
|
||||
stack[sp].value = 0;
|
||||
} else if (token == SWIG_TOKEN_ENDLINE) { }
|
||||
else goto syntax_error;
|
||||
stack[sp].svalue = 0;
|
||||
} else if (token == SWIG_TOKEN_ENDLINE) {
|
||||
} else if ((token == SWIG_TOKEN_STRING)) {
|
||||
stack[sp].svalue = NewString(SwigScanner_text(scan));
|
||||
stack[sp].op = EXPR_VALUE;
|
||||
} else if ((token == SWIG_TOKEN_ID)) {
|
||||
stack[sp].value = 0;
|
||||
stack[sp].svalue = 0;
|
||||
stack[sp].op = EXPR_VALUE;
|
||||
} else goto syntax_error;
|
||||
break;
|
||||
case EXPR_VALUE:
|
||||
/* A value is on the stack. We may reduce or evaluate depending on what the next token is */
|
||||
|
|
@ -302,6 +343,7 @@ Preprocessor_expr(DOH *s, int *error) {
|
|||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr,"Internal error in expression evaluator.\n");
|
||||
abort();
|
||||
|
|
|
|||
|
|
@ -15,19 +15,21 @@
|
|||
#define _PREPROCESSOR_H
|
||||
|
||||
#include "swig.h"
|
||||
#include "swigwarn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void Preprocessor_expr_init(void);
|
||||
extern int Preprocessor_expr(DOHString *s, int *error);
|
||||
extern char *Preprocessor_expr_error(void);
|
||||
extern DOH *Preprocessor_define(DOHString_or_char *str, int swigmacro);
|
||||
extern void Preprocessor_undef(DOHString_or_char *name);
|
||||
extern void Preprocessor_init();
|
||||
extern DOH *Preprocessor_parse(DOH *s);
|
||||
extern void Preprocessor_include_all(int);
|
||||
extern int Preprocessor_expr(String *s, int *error);
|
||||
extern char *Preprocessor_expr_error(void);
|
||||
extern Hash *Preprocessor_define(const String_or_char *str, int swigmacro);
|
||||
extern void Preprocessor_undef(String_or_char *name);
|
||||
extern void Preprocessor_init();
|
||||
extern String *Preprocessor_parse(String *s);
|
||||
extern void Preprocessor_include_all(int);
|
||||
extern void Preprocessor_import_all(int);
|
||||
extern void Preprocessor_ignore_missing(int);
|
||||
extern List *Preprocessor_depend(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
32
SWIG/Source/README
Normal file
32
SWIG/Source/README
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
SWIG Source directory
|
||||
|
||||
This directory currently contains a mix of legacy SWIG1.1 code and
|
||||
recent development work. As a result, it's still a little messy.
|
||||
Here is a rough breakdown of the directories:
|
||||
|
||||
Source/DOH - A core set of basic datatypes including
|
||||
strings, lists, hashes, and files. Used
|
||||
extensively by the rest of SWIG.
|
||||
|
||||
Source/Swig - Swig core. Type-system, utility functions.
|
||||
|
||||
Source/Preprocessor - SWIG C Preprocessor
|
||||
|
||||
Source/CParse - SWIG C Parser (still messy)
|
||||
|
||||
Source/Modules1.1 - Old SWIG1.1 derived language modules.
|
||||
Remaining legacy code.
|
||||
|
||||
|
||||
The following directories may be in CVS, but are largely deprecated:
|
||||
|
||||
Source/Modules - Some experimental module work. New
|
||||
modules may be added here eventually.
|
||||
|
||||
Source/LParse - Experimental parser. Officially dead
|
||||
as CParse is more capable.
|
||||
|
||||
Source/SWIG1.1 - Old SWIG1.1 core. Completely empty now.
|
||||
|
||||
|
||||
|
||||
|
|
@ -5,10 +5,10 @@
|
|||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
SRCS = map.c wrapfunc.c naming.c tree.c stype.c scanner.c include.c getopt.c misc.c \
|
||||
parms.c cwrap.c typemap.c module.c main.c
|
||||
OBJS = map.o wrapfunc.o naming.o tree.o stype.o scanner.o include.o getopt.o misc.o \
|
||||
parms.o cwrap.o typemap.o module.o main.o
|
||||
SRCS = wrapfunc.c naming.c tree.c stype.c typesys.c scanner.c include.c getopt.c misc.c \
|
||||
parms.c cwrap.c typemap.c warn.c symbol.c error.c fragment.c
|
||||
OBJS = wrapfunc.@OBJEXT@ naming.@OBJEXT@ tree.@OBJEXT@ stype.@OBJEXT@ typesys.@OBJEXT@ scanner.@OBJEXT@ include.@OBJEXT@ getopt.@OBJEXT@ misc.@OBJEXT@ \
|
||||
parms.@OBJEXT@ cwrap.@OBJEXT@ typemap.@OBJEXT@ warn.@OBJEXT@ symbol.@OBJEXT@ error.@OBJEXT@ fragment.@OBJEXT@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
|
@ -17,11 +17,11 @@ CC = @CC@
|
|||
AR = @AR@
|
||||
RANLIB = @RANLIB@
|
||||
CFLAGS = @CFLAGS@
|
||||
INCLUDE = -I$(srcdir)/. -I$(srcdir)/../DOH/Include -I$(srcdir)/../Include
|
||||
INCLUDES = -I$(srcdir)/. -I$(srcdir)/../DOH/Include -I$(srcdir)/../Include
|
||||
TARGET = libswig.a
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(INCLUDE) -c -o $*.o $<
|
||||
.c.@OBJEXT@:
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c -o $*.@OBJEXT@ $<
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
|
|
@ -30,4 +30,4 @@ $(TARGET): $(OBJS)
|
|||
$(RANLIB) $(TARGET)
|
||||
|
||||
clean:
|
||||
rm -f *.o *~ core *.so *.a *_wrap.*
|
||||
rm -f *.@OBJEXT@ *~ core *.so *.a *_wrap.*
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
198
SWIG/Source/Swig/error.c
Normal file
198
SWIG/Source/Swig/error.c
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* error.c
|
||||
*
|
||||
* Error handling functions. These are used to issue warnings and
|
||||
* error messages.
|
||||
*
|
||||
* 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.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#include "swig.h"
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char cvsroot_error_c[] = "$Header$";
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Commentary on the warning filter.
|
||||
*
|
||||
* The warning filter is a string of numbers prefaced by (-) or (+) to
|
||||
* indicate whether or not a warning message is displayed. For example:
|
||||
*
|
||||
* "-304-201-140+210+201"
|
||||
*
|
||||
* The filter string is scanned left to right and the first occurrence
|
||||
* of a warning number is used to determine printing behavior.
|
||||
*
|
||||
* The same number may appear more than once in the string. For example, in the
|
||||
* above string, "201" appears twice. This simply means that warning 201
|
||||
* was disabled after it was previously enabled. This may only be temporary
|
||||
* setting--the first number may be removed later in which case the warning
|
||||
* is reenabled.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int silence = 0; /* Silent operation */
|
||||
static String *filter = 0; /* Warning filter */
|
||||
static int warnall = 0;
|
||||
static int nwarning = 0;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_warning()
|
||||
*
|
||||
* Issue a warning message
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt, ...) {
|
||||
String *out;
|
||||
char *msg;
|
||||
int wrn = 1;
|
||||
va_list ap;
|
||||
if (silence) return;
|
||||
|
||||
va_start(ap,fmt);
|
||||
|
||||
out = NewString("");
|
||||
vPrintf(out,fmt,ap);
|
||||
{
|
||||
char temp[64], *t;
|
||||
t = temp;
|
||||
msg = Char(out);
|
||||
while (isdigit(*msg)) {
|
||||
*(t++) = *(msg++);
|
||||
}
|
||||
if (t != temp) {
|
||||
msg++;
|
||||
wnum = atoi(temp);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check in the warning filter */
|
||||
if (filter) {
|
||||
char temp[32];
|
||||
char *c;
|
||||
sprintf(temp,"%d",wnum);
|
||||
c = Strstr(filter,temp);
|
||||
if (c) {
|
||||
if (*(c-1) == '-') wrn = 0; /* Warning disabled */
|
||||
if (*(c-1) == '+') wrn = 1; /* Warning enabled */
|
||||
}
|
||||
}
|
||||
if (warnall || wrn) {
|
||||
if (wnum) {
|
||||
Printf(stderr,"%s:%d: Warning(%d): ", filename, line, wnum);
|
||||
} else {
|
||||
Printf(stderr,"%s:%d: Warning: ", filename, line, wnum);
|
||||
}
|
||||
Printf(stderr,"%s",msg);
|
||||
nwarning++;
|
||||
}
|
||||
Delete(out);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_error()
|
||||
*
|
||||
* Issue an error message
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int nerrors = 0;
|
||||
|
||||
void
|
||||
Swig_error(const String_or_char *filename, int line, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
if (silence) return;
|
||||
|
||||
va_start(ap,fmt);
|
||||
if (line > 0) {
|
||||
Printf(stderr,"%s:%d: ", filename, line);
|
||||
} else {
|
||||
Printf(stderr,"%s:EOF: ", filename);
|
||||
}
|
||||
vPrintf(stderr,fmt,ap);
|
||||
va_end(ap);
|
||||
nerrors++;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_error_count()
|
||||
*
|
||||
* Returns number of errors received.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
Swig_error_count(void) {
|
||||
return nerrors;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_error_silent()
|
||||
*
|
||||
* Set silent flag
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_error_silent(int s) {
|
||||
silence = s;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_warnfilter()
|
||||
*
|
||||
* Takes a comma separate list of warning numbers and puts in the filter.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_warnfilter(const String_or_char *wlist, int add) {
|
||||
char *c;
|
||||
String *s;
|
||||
|
||||
if (!filter) filter = NewString("");
|
||||
s = NewString(wlist);
|
||||
c = Char(s);
|
||||
c = strtok(c,", ");
|
||||
while (c) {
|
||||
if (isdigit(*c) || (*c == '+') || (*c == '-')) {
|
||||
if (add) {
|
||||
Insert(filter,0,c);
|
||||
if (isdigit(*c)) {
|
||||
Insert(filter,0,"-");
|
||||
}
|
||||
} else {
|
||||
char temp[32];
|
||||
if (isdigit(*c)) {
|
||||
sprintf(temp,"-%s",c);
|
||||
} else {
|
||||
strcpy(temp,c);
|
||||
}
|
||||
Replace(filter,temp,"", DOH_REPLACE_FIRST);
|
||||
}
|
||||
}
|
||||
c = strtok(NULL,", ");
|
||||
}
|
||||
Delete(s);
|
||||
}
|
||||
|
||||
void
|
||||
Swig_warnall(void) {
|
||||
warnall = 1;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_warn_count()
|
||||
*
|
||||
* Return the number of warnings
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
Swig_warn_count(void) {
|
||||
return nwarning;
|
||||
}
|
||||
|
||||
64
SWIG/Source/Swig/fragment.c
Normal file
64
SWIG/Source/Swig/fragment.c
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* fragment.c
|
||||
*
|
||||
* This file manages named code fragments. Code fragments are typically
|
||||
* used to hold helper-code that may or may not be included in the wrapper
|
||||
* file (depending on what features are actually used in the interface).
|
||||
*
|
||||
* By using fragments, it's possible to greatly reduce the amount of
|
||||
* wrapper code and to generate cleaner wrapper files.
|
||||
*
|
||||
* 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_fragment_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
static Hash *fragments = 0;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_fragment_register()
|
||||
*
|
||||
* Add a fragment.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_fragment_register(String *name, String *section, String *code) {
|
||||
String *ccode;
|
||||
if (!fragments) {
|
||||
fragments = NewHash();
|
||||
}
|
||||
ccode = Copy(code);
|
||||
Setmeta(ccode,"section",Copy(section));
|
||||
Setattr(fragments,Copy(name),ccode);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_fragment_emit()
|
||||
*
|
||||
* Emit a fragment
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_fragment_emit(String *name) {
|
||||
String *code;
|
||||
if (!fragments) return;
|
||||
|
||||
code = Getattr(fragments,name);
|
||||
if (code) {
|
||||
String *section = Getmeta(code,"section");
|
||||
if (section) {
|
||||
File *f = Swig_filebyname(section);
|
||||
if (!f) {
|
||||
Swig_error(Getfile(code),Getline(code),"Bad section '%s' for code fragment '%s'\n", section,name);
|
||||
} else {
|
||||
Printf(f,"%s\n",code);
|
||||
}
|
||||
}
|
||||
Delattr(fragments,name);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
* Should have cleaner error handling in general.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_getopt_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_include_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
|
|
@ -19,7 +19,6 @@ static char cvsroot[] = "$Header$";
|
|||
|
||||
static List *directories = 0; /* List of include directories */
|
||||
static String *lastpath = 0; /* Last file that was included */
|
||||
static int bytes_read = 0; /* Bytes read */
|
||||
static String *swiglib = 0; /* Location of SWIG library */
|
||||
static String *lang_config = 0; /* Language configuration file */
|
||||
|
||||
|
|
@ -178,7 +177,6 @@ Swig_read_file(FILE *f) {
|
|||
* Opens a file and returns it as a string.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int readbytes = 0;
|
||||
String *
|
||||
Swig_include(const String_or_char *name) {
|
||||
FILE *f;
|
||||
|
|
@ -187,20 +185,13 @@ Swig_include(const String_or_char *name) {
|
|||
f = Swig_open(name);
|
||||
if (!f) return 0;
|
||||
str = Swig_read_file(f);
|
||||
bytes_read = bytes_read + Len(str);
|
||||
fclose(f);
|
||||
Seek(str,0,SEEK_SET);
|
||||
Setfile(str,lastpath);
|
||||
Setline(str,1);
|
||||
readbytes += Len(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
int
|
||||
Swig_bytes_read() {
|
||||
return readbytes;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_insert_file()
|
||||
*
|
||||
|
|
@ -249,4 +240,82 @@ Swig_filebyname(const String_or_char *filename) {
|
|||
return Getattr(named_files,filename);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_file_suffix()
|
||||
*
|
||||
* Returns the suffix of a file
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
Swig_file_suffix(const String_or_char *filename) {
|
||||
char *d;
|
||||
char *c = Char(filename);
|
||||
if (strlen(c)) {
|
||||
d = c + Len(filename) - 1;
|
||||
while (d != c) {
|
||||
if (*d == '.') return d;
|
||||
d--;
|
||||
}
|
||||
return c+Len(filename);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_file_basename()
|
||||
*
|
||||
* Returns the filename with no suffix attached.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
Swig_file_basename(const String_or_char *filename)
|
||||
{
|
||||
static char tmp[1024];
|
||||
char *c;
|
||||
strcpy(tmp,Char(filename));
|
||||
c = Swig_file_suffix(tmp);
|
||||
*c = 0;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_file_filename()
|
||||
*
|
||||
* Return the file with any leading path stripped off
|
||||
* ----------------------------------------------------------------------------- */
|
||||
char *
|
||||
Swig_file_filename(const String_or_char *filename)
|
||||
{
|
||||
static char tmp[1024];
|
||||
const char *delim = SWIG_FILE_DELIMETER;
|
||||
char *c;
|
||||
|
||||
strcpy(tmp,Char(filename));
|
||||
if ((c=strrchr(tmp,*delim))) return c+1;
|
||||
else return tmp;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_file_dirname()
|
||||
*
|
||||
* Return the name of the directory associated with a file
|
||||
* ----------------------------------------------------------------------------- */
|
||||
char *
|
||||
Swig_file_dirname(const String_or_char *filename)
|
||||
{
|
||||
static char tmp[1024];
|
||||
const char *delim = SWIG_FILE_DELIMETER;
|
||||
char *c;
|
||||
strcpy(tmp,Char(filename));
|
||||
if (!strstr(tmp,delim)) {
|
||||
return "";
|
||||
}
|
||||
c = tmp + strlen(tmp) -1;
|
||||
while (*c != *delim) c--;
|
||||
*(++c) = 0;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,103 +0,0 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* main.c
|
||||
*
|
||||
* SWIG main program.
|
||||
*
|
||||
* 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.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#include "swigconfig.h"
|
||||
#include "swigver.h"
|
||||
#include "swig.h"
|
||||
|
||||
static char *usage = (char*)"\
|
||||
\nGeneral Options\n\
|
||||
-version - Print SWIG version number\n\
|
||||
-help - This output.\n\n";
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_main()
|
||||
*
|
||||
* Entry point to SWIG. This should only be called after all of the available
|
||||
* modules have been registered (presumably by the real main function).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int Swig_main(int argc, char **argv, char **modules) {
|
||||
int i;
|
||||
int help = 0;
|
||||
int freeze = 0;
|
||||
Hash *top = 0;
|
||||
|
||||
/* Initialize the SWIG core */
|
||||
Swig_init();
|
||||
Swig_init_args(argc,argv);
|
||||
|
||||
/* Look for command line options */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i]) {
|
||||
if (strcmp(argv[i],"-freeze") == 0) {
|
||||
freeze= 1;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i],"-version") == 0) {
|
||||
fprintf(stderr,"\nSWIG Version %s %s\n",
|
||||
SWIG_VERSION, SWIG_SPIN);
|
||||
fprintf(stderr,"Copyright (c) 1995-1998, University of Utah and the Regents of the University of California\n");
|
||||
fprintf(stderr,"Copyright (c) 1998-2000, University of Chicago\n");
|
||||
Swig_exit (EXIT_SUCCESS);
|
||||
} else if (strcmp(argv[i],"-help") == 0) {
|
||||
Printf(stderr,"%s",usage);
|
||||
Swig_mark_arg(i);
|
||||
help = 1;
|
||||
} else {
|
||||
if (!Swig_check_marked(i)) {
|
||||
Module *m;
|
||||
m = Swig_load_module(argv[i]+1);
|
||||
if (m) {
|
||||
Swig_mark_arg(i);
|
||||
Swig_init_module(m, argc, argv);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Load the default modules (always enabled) */
|
||||
if (modules) {
|
||||
int i = 0;
|
||||
while (modules[i]) {
|
||||
Module *m;
|
||||
m = Swig_load_module(modules[i]);
|
||||
if (m) {
|
||||
Swig_init_module(m,argc,argv);
|
||||
} else {
|
||||
Printf(stderr,"Swig: default module '%s' not found!\n", modules[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (help) Swig_exit(EXIT_SUCCESS);
|
||||
/* Check the arguments */
|
||||
Swig_check_options();
|
||||
|
||||
/* Get the input file name and create a starting node */
|
||||
top = NewHash();
|
||||
Settag(top,"swig:initial");
|
||||
Setname(top,argv[argc-1]);
|
||||
|
||||
/* Run the modules */
|
||||
Swig_run_modules(top);
|
||||
|
||||
while(freeze);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Swig_exit(int n) {
|
||||
exit(n);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,352 +0,0 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* map.c
|
||||
*
|
||||
* This file provides support for defining %map rules that match lists of
|
||||
* parameters to objects defining code generation rules.
|
||||
*
|
||||
* 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.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Synopsis
|
||||
*
|
||||
* One of the problems in creating wrappers is that of defining rules for
|
||||
* managing various datatypes and function parameters. In SWIG1.1,
|
||||
* this sort of customization was managed using a mechanism known as
|
||||
* "typemaps". This module generalizes the idea even further and provides
|
||||
* generic set of functions that can be used to define and match rules
|
||||
* that are associated with lists of datatypes.
|
||||
*
|
||||
* The functions in this file are intended to be rather generic. They are only
|
||||
* responsible for the storage and matching of rules. Other parts of the
|
||||
* code can use these to implement typemaps, argmaps, or anything else.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_map_add_parmrule()
|
||||
*
|
||||
* Adds a new mapping rule for a list of parameters. The parms input to this
|
||||
* function should be a properly constructed parameter list with associated
|
||||
* attributes (type and name). The 'obj' attribute can be any DOH object.
|
||||
*
|
||||
* The structure of how data might be stored is as follows:
|
||||
*
|
||||
* ruleset (hash)
|
||||
* --------------
|
||||
* parm1 ---------> rule (hash)
|
||||
* -------------
|
||||
* parm2 -----------> rule (hash)
|
||||
* *obj* --> obj ------------
|
||||
* parm3
|
||||
* *obj* -->obj
|
||||
*
|
||||
* For multiple arguments, we end up building a large tree of hash tables.
|
||||
* The object will be stored in the *obj* attribute of the last hash table.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_map_add_parmrule(Hash *ruleset, Hash *parms, DOH *obj)
|
||||
{
|
||||
Hash *p, *n;
|
||||
|
||||
/* Walk down the parms list and create a series of hash tables */
|
||||
p = parms;
|
||||
n = ruleset;
|
||||
|
||||
while (p) {
|
||||
String *ty, *name, *key;
|
||||
Hash *nn;
|
||||
ty = Getattr(p,"type");
|
||||
name = Getattr(p,"name");
|
||||
|
||||
/* Create a hash table key */
|
||||
|
||||
key = NewStringf("*map:%s-%s",name,ty);
|
||||
|
||||
/* See if there is already a entry with this type in the table */
|
||||
nn = Getattr(n,key);
|
||||
if (!nn) {
|
||||
/* No. Go ahead and create it */
|
||||
nn = NewHash();
|
||||
Setattr(n,key,nn);
|
||||
}
|
||||
Delete(key);
|
||||
n = nn;
|
||||
p = Swig_next(p);
|
||||
}
|
||||
|
||||
/* No more parameters. At this point, n points to the very last hash table in our search.
|
||||
We'll stick our object there */
|
||||
|
||||
Setattr(n,"*obj*",obj);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_map_add_typerule()
|
||||
*
|
||||
* Adds a rule for a single type and name.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_map_add_typerule(Hash *ruleset, DOH *type, String_or_char *name, DOH *obj) {
|
||||
Hash *p;
|
||||
|
||||
p = NewHash();
|
||||
Setattr(p,"type",type);
|
||||
if (name)
|
||||
Setattr(p,"name", name);
|
||||
|
||||
Swig_map_add_parmrule(ruleset,p,obj);
|
||||
Delete(p);
|
||||
}
|
||||
|
||||
typedef struct MatchObject {
|
||||
Hash *ruleset; /* Hash table of rules */
|
||||
Hash *p; /* Parameter on which checking starts */
|
||||
int depth; /* Depth of the match */
|
||||
struct MatchObject *next; /* Next match object */
|
||||
} MatchObject;
|
||||
|
||||
|
||||
static MatchObject *matchstack = 0;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_map_match_parms()
|
||||
*
|
||||
* Perform a longest map match for a list of parameters and a set of mapping rules.
|
||||
* Returns the corresponding rule object and the number of parameters that were
|
||||
* matched.
|
||||
*
|
||||
* Note: If the ruleset has a 'parent' attribute, this function will walk its
|
||||
* way up and try to find a match. This can be used to implement scoped
|
||||
* mappings.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
Swig_map_match_parms(Hash *ruleset, Hash *parms, int *nmatch)
|
||||
{
|
||||
MatchObject *mo;
|
||||
|
||||
DOH *bestobj = 0;
|
||||
int bestdepth = -1;
|
||||
|
||||
*nmatch = 0;
|
||||
|
||||
mo = (MatchObject *) malloc(sizeof(MatchObject));
|
||||
mo->ruleset = ruleset;
|
||||
mo->depth = 0;
|
||||
mo->p = parms;
|
||||
mo->next = 0;
|
||||
|
||||
matchstack = mo;
|
||||
|
||||
/* Loop over all candidates until we find the best one */
|
||||
|
||||
while (matchstack) {
|
||||
Hash *rs;
|
||||
Hash *p;
|
||||
int depth = 0;
|
||||
DOH *obj;
|
||||
String *key;
|
||||
String *ty;
|
||||
String *name;
|
||||
String *nm;
|
||||
int matched = 0;
|
||||
|
||||
mo = matchstack;
|
||||
/* See if there is a match at this level */
|
||||
rs = mo->ruleset;
|
||||
obj = Getattr(rs,"*obj*");
|
||||
if (obj) {
|
||||
if (mo->depth > bestdepth) {
|
||||
bestdepth = mo->depth;
|
||||
bestobj = obj;
|
||||
}
|
||||
}
|
||||
p = mo->p;
|
||||
|
||||
/* No more parameters. Oh well */
|
||||
if (!p) {
|
||||
matchstack = mo->next;
|
||||
free(mo);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Generate some keys for checking the next parameter */
|
||||
|
||||
depth = mo->depth;
|
||||
name = Getattr(p,"name");
|
||||
ty = Getattr(p,"type");
|
||||
|
||||
|
||||
if (!SwigType_isarray(ty)) {
|
||||
key = NewStringf("*map:-%s",ty);
|
||||
/* See if there is a generic name match for this type */
|
||||
nm = Getattr(rs,key);
|
||||
if (nm) {
|
||||
/* Yes! Add to our stack. Just reuse mo for this */
|
||||
mo->ruleset = nm;
|
||||
mo->p = Swig_next(p);
|
||||
mo->depth++;
|
||||
mo = 0;
|
||||
matched++;
|
||||
}
|
||||
|
||||
/* See if there is a specific name match for this type */
|
||||
Clear(key);
|
||||
Printf(key,"*map:%s-%s",name,ty);
|
||||
nm = Getattr(rs,key);
|
||||
if (nm) {
|
||||
if (!mo) {
|
||||
mo = (MatchObject *) malloc(sizeof(MatchObject));
|
||||
mo->next = matchstack;
|
||||
matchstack = mo;
|
||||
}
|
||||
mo->ruleset = nm;
|
||||
mo->p = Swig_next(p);
|
||||
mo->depth = depth+1;
|
||||
matched++;
|
||||
}
|
||||
Delete(key);
|
||||
} else {
|
||||
/* The next parameter is an array. This is pretty nasty because we have to do a bunch of checks
|
||||
related to array indices */
|
||||
|
||||
int ndim;
|
||||
int i, j, n;
|
||||
int ncheck;
|
||||
String *ntype;
|
||||
|
||||
key = NewString("");
|
||||
|
||||
/* Drop the mo record. This is too complicated */
|
||||
matchstack = mo->next;
|
||||
free(mo);
|
||||
mo = 0;
|
||||
|
||||
/* Get the number of array dimensions */
|
||||
ndim = SwigType_array_ndim(ty);
|
||||
|
||||
/* First, we test all of the generic-unnamed parameters */
|
||||
ncheck = 1 << ndim;
|
||||
|
||||
j = ncheck-1;
|
||||
for (i = 0; i < ncheck; i++, j--) {
|
||||
int k = j;
|
||||
ntype = Copy(ty);
|
||||
for (n = 0; n < ndim; n++, k = k >> 1) {
|
||||
if (k & 1) {
|
||||
SwigType_array_setdim(ntype,n,"");
|
||||
}
|
||||
}
|
||||
Clear(key);
|
||||
Printf(key,"*map:-%s",ntype);
|
||||
Printf(stdout,"matcharray : %s\n", key);
|
||||
nm = Getattr(rs,key);
|
||||
if (nm) {
|
||||
mo = (MatchObject *) malloc(sizeof(MatchObject));
|
||||
mo->ruleset = nm;
|
||||
mo->p = Swig_next(p);
|
||||
mo->depth = depth+1;
|
||||
mo->next = matchstack;
|
||||
matchstack = mo;
|
||||
matched++;
|
||||
mo = 0;
|
||||
}
|
||||
Delete(ntype);
|
||||
}
|
||||
|
||||
/* Next check all of the named parameters */
|
||||
ncheck = 1 << ndim;
|
||||
|
||||
j = ncheck-1;
|
||||
for (i = 0; i < ncheck; i++, j--) {
|
||||
int k = j;
|
||||
ntype = Copy(ty);
|
||||
for (n = 0; n < ndim; n++, k = k >> 1) {
|
||||
if (k & 1) {
|
||||
SwigType_array_setdim(ntype,n,"");
|
||||
}
|
||||
}
|
||||
Clear(key);
|
||||
Printf(key,"*map:%s-%s",name,ntype);
|
||||
Printf(stdout,"matcharray : %s\n", key);
|
||||
nm = Getattr(rs,key);
|
||||
if (nm) {
|
||||
mo = (MatchObject *) malloc(sizeof(MatchObject));
|
||||
mo->ruleset = nm;
|
||||
mo->p = Swig_next(p);
|
||||
mo->depth = depth+1;
|
||||
mo->next = matchstack;
|
||||
matchstack = mo;
|
||||
matched++;
|
||||
mo = 0;
|
||||
}
|
||||
Delete(ntype);
|
||||
}
|
||||
Delete(key);
|
||||
}
|
||||
if ((!matched) && mo) {
|
||||
matchstack = mo->next;
|
||||
free(mo);
|
||||
}
|
||||
}
|
||||
if (bestobj) {
|
||||
*nmatch = bestdepth;
|
||||
} else {
|
||||
/* If there is no match at all. I guess we can check for a default type */
|
||||
DOH *rs;
|
||||
String *key;
|
||||
String *dty = SwigType_default(Getattr(parms,"type"));
|
||||
key = NewStringf("*map:-%s",dty);
|
||||
|
||||
rs = Getattr(ruleset,key);
|
||||
if (rs) {
|
||||
bestobj = Getattr(rs,"*obj*");
|
||||
if (bestobj) *nmatch = 1;
|
||||
}
|
||||
Delete(key);
|
||||
Delete(dty);
|
||||
}
|
||||
if (!bestobj) {
|
||||
DOH *prules = Getattr(ruleset,"parent");
|
||||
if (prules) {
|
||||
bestobj = Swig_map_match_parms(prules,parms,nmatch);
|
||||
}
|
||||
}
|
||||
return bestobj;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_map_match_type()
|
||||
*
|
||||
* Match a rule for a single type
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
Swig_map_match_type(Hash *ruleset, DOH *type, String_or_char *name) {
|
||||
Hash *p;
|
||||
DOH *obj;
|
||||
int nmatch;
|
||||
|
||||
p = NewHash();
|
||||
Setattr(p,"type",type);
|
||||
if (name)
|
||||
Setattr(p,"name",name);
|
||||
|
||||
obj = Swig_map_match_parms(ruleset,p,&nmatch);
|
||||
Delete(p);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_misc_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
#include "swigver.h"
|
||||
|
|
@ -42,72 +42,16 @@ Swig_banner(File *f) {
|
|||
Printf(f,
|
||||
"/* ----------------------------------------------------------------------------\n\
|
||||
* This file was automatically generated by SWIG (http://www.swig.org).\n\
|
||||
* Version %s %s\n\
|
||||
* Version %s\n\
|
||||
* \n\
|
||||
* This file is not intended to be easily readable and contains a number of \n\
|
||||
* coding conventions designed to improve portability and efficiency. Do not make\n\
|
||||
* changes to this file unless you know what you are doing--modify the SWIG \n\
|
||||
* interface file instead. \n\
|
||||
* ----------------------------------------------------------------------------- */\n\n", SWIG_VERSION, SWIG_SPIN);
|
||||
* ----------------------------------------------------------------------------- */\n\n", SWIG_VERSION);
|
||||
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_section()
|
||||
*
|
||||
* Print a comment denoting a section of wrapper code
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_section(File *f, const String_or_char *name) {
|
||||
Printf(f,"/* -----------------------------------------------------------------------------\n");
|
||||
Printf(f," * %s\n", name);
|
||||
Printf(f," * ----------------------------------------------------------------------------- */\n");
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_temp_result()
|
||||
*
|
||||
* This function is used to return a "temporary" result--a result that is only
|
||||
* guaranteed to exist for a short period of time. Typically this is used by
|
||||
* functions that return strings and other intermediate results that are
|
||||
* used in print statements.
|
||||
*
|
||||
* Note: this is really a bit of a kludge to make it easier to work with
|
||||
* temporary variables (so that the caller doesn't have to worry about
|
||||
* memory management). In theory, it is possible to break this if an
|
||||
* operation produces so many temporaries that it overflows the internal
|
||||
* array before they are used. However, in practice, this would only
|
||||
* occur for very deep levels of recursion or functions taking lots of
|
||||
* parameters---neither of which occur very often in SWIG (if at all).
|
||||
* Also, a user can prevent destruction of a temporary object by increasing
|
||||
* it's reference count using DohIncref().
|
||||
*
|
||||
* It is an error to place two identical results onto this list. It is also
|
||||
* an error for a caller to free anything returned by this function.
|
||||
*
|
||||
* Note: SWIG1.1 did something similar to this in a less-organized manner.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#define MAX_RESULT 512
|
||||
|
||||
static DOH *results[MAX_RESULT];
|
||||
static int results_index = 0;
|
||||
static int results_init = 0;
|
||||
|
||||
DOH *Swig_temp_result(DOH *x) {
|
||||
int i;
|
||||
if (!results_init) {
|
||||
for (i = 0; i < MAX_RESULT; i++) results[i] = 0;
|
||||
results_init = 1;
|
||||
}
|
||||
/* Printf(stdout,"results_index = %d, %x, '%s'\n", results_index, x, x); */
|
||||
if (results[results_index]) Delete(results[results_index]);
|
||||
results[results_index] = x;
|
||||
results_index = (results_index + 1) % MAX_RESULT;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_string_escape()
|
||||
*
|
||||
|
|
@ -142,7 +86,108 @@ String *Swig_string_escape(String *s) {
|
|||
}
|
||||
return ns;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_string_upper()
|
||||
*
|
||||
* Takes a string object and convets it to all caps.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *Swig_string_upper(String *s) {
|
||||
String *ns;
|
||||
int c;
|
||||
ns = NewString("");
|
||||
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
Putc(toupper(c),ns);
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_string_lower()
|
||||
*
|
||||
* Takes a string object and convets it to all lower.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *Swig_string_lower(String *s) {
|
||||
String *ns;
|
||||
int c;
|
||||
ns = NewString("");
|
||||
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
Putc(tolower(c),ns);
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_string_title()
|
||||
*
|
||||
* Takes a string object and convets it to all lower.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *Swig_string_title(String *s) {
|
||||
String *ns;
|
||||
int first = 1;
|
||||
int c;
|
||||
ns = NewString("");
|
||||
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
Putc(first ? toupper(c) : tolower(c),ns);
|
||||
first = 0;
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_string_typecode()
|
||||
*
|
||||
* Takes a string with possible type-escapes in it and replaces them with
|
||||
* real C datatypes.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *Swig_string_typecode(String *s) {
|
||||
String *ns;
|
||||
int c;
|
||||
String *tc;
|
||||
ns = NewString("");
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
if (c == '`') {
|
||||
tc = NewString("");
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
if (c == '`') break;
|
||||
Putc(c,tc);
|
||||
}
|
||||
Printf(ns,"%s",SwigType_str(tc,0));
|
||||
} else {
|
||||
Putc(c,ns);
|
||||
if (c == '\'') {
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
Putc(c,ns);
|
||||
if (c == '\'') break;
|
||||
if (c == '\\') {
|
||||
c = Getc(s);
|
||||
Putc(c,ns);
|
||||
}
|
||||
}
|
||||
} else if (c == '\"') {
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
Putc(c,ns);
|
||||
if (c == '\"') break;
|
||||
if (c == '\\') {
|
||||
c = Getc(s);
|
||||
Putc(c,ns);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_string_mangle()
|
||||
*
|
||||
|
|
@ -160,28 +205,188 @@ String *Swig_string_mangle(String *s) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_proto_cmp()
|
||||
* Swig_scopename_prefix()
|
||||
*
|
||||
* Compares a function prototype against an expected type-string.
|
||||
* For example, Swig_proto_cmp("f(p.void,p.Tcl_Interp,int,p.p.char).int", node)
|
||||
* Take a qualified name like "A::B::C" and return the scope name.
|
||||
* In this case, "A::B". Returns NULL if there is no base.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
Swig_proto_cmp(const String_or_char *pat, DOH *node) {
|
||||
SwigType *ty;
|
||||
SwigType *ct;
|
||||
ParmList *p;
|
||||
int r;
|
||||
String *
|
||||
Swig_scopename_prefix(String *s) {
|
||||
char tmp[1024];
|
||||
char *c, *cc;
|
||||
if (!Strstr(s,"::")) return 0;
|
||||
strcpy(tmp,Char(s));
|
||||
c = tmp;
|
||||
cc = c;
|
||||
while (*c) {
|
||||
if (strncmp(c,"::",2) == 0) {
|
||||
cc = c;
|
||||
c += 2;
|
||||
} else {
|
||||
if (*c == '<') {
|
||||
int level = 1;
|
||||
c++;
|
||||
while (*c && level) {
|
||||
if (*c == '<') level++;
|
||||
if (*c == '>') level--;
|
||||
c++;
|
||||
}
|
||||
} else {
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ty = Gettype(node);
|
||||
p = Getparms(node);
|
||||
if (!ty || !p) return -1;
|
||||
ct = Copy(ty);
|
||||
SwigType_add_function(ct,p);
|
||||
SwigType_strip_qualifiers(ct);
|
||||
r = Cmp(pat,ct);
|
||||
Delete(ct);
|
||||
return r;
|
||||
*cc = 0;
|
||||
if (cc != tmp) {
|
||||
return NewString(tmp);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_scopename_last()
|
||||
*
|
||||
* Take a qualified name like "A::B::C" and returns the last. In this
|
||||
* case, "C".
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *
|
||||
Swig_scopename_last(String *s) {
|
||||
char tmp[1024];
|
||||
char *c, *cc;
|
||||
if (!Strstr(s,"::")) return NewString(s);
|
||||
strcpy(tmp,Char(s));
|
||||
c = tmp;
|
||||
cc = c;
|
||||
|
||||
while (*c) {
|
||||
if (strncmp(c,"::",2) == 0) {
|
||||
cc = c;
|
||||
c += 2;
|
||||
} else {
|
||||
if (*c == '<') {
|
||||
int level = 1;
|
||||
c++;
|
||||
while (*c && level) {
|
||||
if (*c == '<') level++;
|
||||
if (*c == '>') level--;
|
||||
c++;
|
||||
}
|
||||
} else {
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NewString(cc+2);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_scopename_first()
|
||||
*
|
||||
* Take a qualified name like "A::B::C" and returns the first scope name.
|
||||
* In this case, "A". Returns NULL if there is no base.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *
|
||||
Swig_scopename_first(String *s) {
|
||||
char tmp[1024];
|
||||
char *c;
|
||||
if (!Strstr(s,"::")) return 0;
|
||||
strcpy(tmp,Char(s));
|
||||
c = tmp;
|
||||
while (*c) {
|
||||
if (strncmp(c,"::",2) == 0) {
|
||||
break;
|
||||
} else {
|
||||
if (*c == '<') {
|
||||
int level = 1;
|
||||
c++;
|
||||
while (*c && level) {
|
||||
if (*c == '<') level++;
|
||||
if (*c == '>') level--;
|
||||
c++;
|
||||
}
|
||||
} else {
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (*c && (c != tmp)) {
|
||||
*c = 0;
|
||||
return NewString(tmp);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_scopename_suffix()
|
||||
*
|
||||
* Take a qualified name like "A::B::C" and returns the suffix.
|
||||
* In this case, "B::C". Returns NULL if there is no suffix.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *
|
||||
Swig_scopename_suffix(String *s) {
|
||||
char tmp[1024];
|
||||
char *c;
|
||||
if (!Strstr(s,"::")) return 0;
|
||||
strcpy(tmp,Char(s));
|
||||
c = tmp;
|
||||
while (*c) {
|
||||
if (strncmp(c,"::",2) == 0) {
|
||||
break;
|
||||
} else {
|
||||
if (*c == '<') {
|
||||
int level = 1;
|
||||
c++;
|
||||
while (*c && level) {
|
||||
if (*c == '<') level++;
|
||||
if (*c == '>') level--;
|
||||
c++;
|
||||
}
|
||||
} else {
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (*c && (c != tmp)) {
|
||||
return NewString(c+2);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_scopename_check()
|
||||
*
|
||||
* Checks to see if a name is qualified with a scope name
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int Swig_scopename_check(String *s) {
|
||||
char *c = Char(s);
|
||||
if (!Strstr(s,"::")) return 0;
|
||||
while (*c) {
|
||||
if (strncmp(c,"::",2) == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
if (*c == '<') {
|
||||
int level = 1;
|
||||
c++;
|
||||
while (*c && level) {
|
||||
if (*c == '<') level++;
|
||||
if (*c == '>') level--;
|
||||
c++;
|
||||
}
|
||||
} else {
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -193,7 +398,20 @@ Swig_proto_cmp(const String_or_char *pat, DOH *node) {
|
|||
|
||||
void
|
||||
Swig_init() {
|
||||
/* Set some useful string encoding methods */
|
||||
DohEncoding("escape", Swig_string_escape);
|
||||
DohEncoding("upper", Swig_string_upper);
|
||||
DohEncoding("lower", Swig_string_lower);
|
||||
DohEncoding("title", Swig_string_title);
|
||||
DohEncoding("typecode",Swig_string_typecode);
|
||||
|
||||
/* Initialize typemaps */
|
||||
Swig_typemap_init();
|
||||
|
||||
/* Initialize symbol table */
|
||||
Swig_symbol_init();
|
||||
|
||||
/* Initialize type system */
|
||||
SwigType_typesystem_init();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,210 +0,0 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* module.c
|
||||
*
|
||||
* This file implements the SWIG module system. Modules are simply
|
||||
* pieces of code that manipulate tree objects. Each module is defined
|
||||
* by 4 quantities:
|
||||
*
|
||||
* - Module name (used to select the module on the command line)
|
||||
* - init function (called with the SWIG command line options).
|
||||
* - start function (called to launch the module)
|
||||
* - start tag (starting tag expected by the module)
|
||||
*
|
||||
* Currently modules must be statically linked with SWIG. However, it
|
||||
* is anticipated that the module system may eventually support
|
||||
* dynamic loading.
|
||||
*
|
||||
* 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.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
#ifdef DYNAMIC_MODULES
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
struct Module {
|
||||
String *modname;
|
||||
int (*initfunc)(int argc, char **argv);
|
||||
DOH *(*startfunc)(DOH *);
|
||||
String *starttag;
|
||||
struct Module *next;
|
||||
};
|
||||
|
||||
static Module *Modules = 0;
|
||||
static Hash *LoadedModules = 0;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_register_module()
|
||||
*
|
||||
* Register a new module with the system
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_register_module(const String_or_char *modname, const String_or_char *starttag,
|
||||
int (*initfunc)(int argc, char **argv),
|
||||
DOH *(*startfunc)(DOH *))
|
||||
{
|
||||
Module *m;
|
||||
m = (Module *) malloc(sizeof(Module));
|
||||
m->modname = NewString(modname);
|
||||
m->starttag = NewString(starttag);
|
||||
m->initfunc = initfunc;
|
||||
m->startfunc = startfunc;
|
||||
m->next = Modules;
|
||||
Modules = m;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_load_module()
|
||||
*
|
||||
* Load a module. Returns the module object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
Module *
|
||||
Swig_load_module(const String_or_char *modname) {
|
||||
Module *m;
|
||||
static int dlcheck = 0;
|
||||
m = Modules;
|
||||
|
||||
while (m) {
|
||||
if (Cmp(m->modname, modname) == 0) {
|
||||
/* Create a new entry in the loaded modules table */
|
||||
List *ml;
|
||||
if (!LoadedModules) LoadedModules = NewHash();
|
||||
ml = Getattr(LoadedModules,m->starttag);
|
||||
if (!ml) {
|
||||
ml = NewList();
|
||||
Setattr(LoadedModules,m->starttag,ml);
|
||||
}
|
||||
Append(ml,NewVoid(m,0));
|
||||
return m;
|
||||
}
|
||||
m = m->next;
|
||||
}
|
||||
/* Module is not a built-in module. See if we can dynamically load it */
|
||||
|
||||
#ifdef DYNAMIC_MODULES
|
||||
if (dlcheck) return 0;
|
||||
{
|
||||
DOH *filename;
|
||||
void *handle;
|
||||
void (*init)(void) = 0;
|
||||
char initfunc[256];
|
||||
FILE *f;
|
||||
filename = NewStringf("./swig%s.so", modname);
|
||||
f = Swig_open(filename);
|
||||
if (!f) return 0;
|
||||
fclose(f);
|
||||
|
||||
Clear(filename);
|
||||
Append(filename,Swig_last_file());
|
||||
|
||||
sprintf(initfunc,"%smodule",Char(modname));
|
||||
handle = dlopen(Char(filename), RTLD_NOW | RTLD_GLOBAL);
|
||||
if (!handle) {
|
||||
Printf(stdout,"%s\n", dlerror());
|
||||
return 0;
|
||||
}
|
||||
|
||||
init = (void (*)(void)) dlsym(handle,initfunc);
|
||||
if (!init) {
|
||||
Printf(stdout,"Dynamic module %s doesn't define %s()\n", initfunc);
|
||||
return 0;
|
||||
}
|
||||
(*init)(); /* Register function */
|
||||
dlcheck = 1;
|
||||
m = Swig_load_module(modname);
|
||||
dlcheck = 0;
|
||||
return m;
|
||||
}
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_init_module()
|
||||
*
|
||||
* Initialize a module
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int Swig_init_module(Module *m, int argc, char **argv) {
|
||||
return (*m->initfunc)(argc,argv);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_start_module()
|
||||
*
|
||||
* Start a module
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
Swig_start_module(Module *m, DOH *obj) {
|
||||
return (*m->startfunc)(obj);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_run_modules()
|
||||
*
|
||||
* Given a tree node. This function tries to run it through all of the loaded
|
||||
* modules. This works by looking at the "tag" attribute of the node and
|
||||
* searching for a loaded module that can handle that tag. If no module can be
|
||||
* found, processing stops and an error is generated.
|
||||
*
|
||||
* If more than one module can work on a given tag, those modules will be
|
||||
* executed one after the other. Caveat: if one of those modules outputs
|
||||
* a different type of tree, processing immediately stops.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *Swig_run_modules(DOH *node) {
|
||||
String *tag;
|
||||
List *ml;
|
||||
DOH *newnode;
|
||||
String *newtag;
|
||||
int i;
|
||||
|
||||
tag = Getattr(node,"tag");
|
||||
if (!tag) {
|
||||
Printf(stderr,"Whoa. No tag attribute on node passed to Swig_module_run.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* Get the set of modules that can respond to this node */
|
||||
while (node) {
|
||||
if (!LoadedModules) {
|
||||
Printf(stderr,"No modules loaded.\n");
|
||||
return 0;
|
||||
}
|
||||
ml = Getattr(LoadedModules,tag);
|
||||
if ((!ml) || (Len(ml) == 0)) {
|
||||
Printf(stderr,"Internal error. No module defined for handling '%s'\n", tag);
|
||||
return 0;
|
||||
}
|
||||
newnode = 0;
|
||||
newtag = 0;
|
||||
for (i = 0; i < Len(ml); i++) {
|
||||
Module *m;
|
||||
m = (Module *) Data(Getitem(ml,i));
|
||||
assert(m);
|
||||
newnode = (*m->startfunc)(node);
|
||||
if (!newnode) return node; /* Done */
|
||||
newtag = Getattr(newnode,"tag");
|
||||
if (!newtag) {
|
||||
Printf(stderr,"Fatal error. Module '%s' returns untagged object.\n", m->modname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (Cmp(newtag,tag)) break; /* Tag is different. Oh well */
|
||||
}
|
||||
if (Cmp(newtag,tag) == 0) break; /* Hmmm. The tag is the same but we already did everything */
|
||||
node = newnode;
|
||||
tag = newtag;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_naming_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
#include <ctype.h>
|
||||
|
|
@ -25,11 +25,99 @@ static Hash *naming_hash = 0;
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_name_register(String_or_char *method, String_or_char *format) {
|
||||
Swig_name_register(const String_or_char *method, const String_or_char *format) {
|
||||
if (!naming_hash) naming_hash = NewHash();
|
||||
Setattr(naming_hash,method,format);
|
||||
}
|
||||
|
||||
void
|
||||
Swig_name_unregister(const String_or_char *method) {
|
||||
if (naming_hash) {
|
||||
Delattr(naming_hash,method);
|
||||
}
|
||||
}
|
||||
|
||||
static int name_mangle(String *r) {
|
||||
char *c;
|
||||
int special;
|
||||
special = 0;
|
||||
Replaceall(r,"::","_");
|
||||
c = Char(r);
|
||||
while (*c) {
|
||||
if (!isalnum(*c) && (*c != '_')) {
|
||||
special = 1;
|
||||
switch(*c) {
|
||||
case '+':
|
||||
*c = 'a';
|
||||
break;
|
||||
case '-':
|
||||
*c = 's';
|
||||
break;
|
||||
case '*':
|
||||
*c = 'm';
|
||||
break;
|
||||
case '/':
|
||||
*c = 'd';
|
||||
break;
|
||||
case '<':
|
||||
*c = 'l';
|
||||
break;
|
||||
case '>':
|
||||
*c = 'g';
|
||||
break;
|
||||
case '=':
|
||||
*c = 'e';
|
||||
break;
|
||||
case ',':
|
||||
*c = 'c';
|
||||
break;
|
||||
case '(':
|
||||
*c = 'p';
|
||||
break;
|
||||
case ')':
|
||||
*c = 'P';
|
||||
break;
|
||||
case '[':
|
||||
*c = 'b';
|
||||
break;
|
||||
case ']':
|
||||
*c = 'B';
|
||||
break;
|
||||
case '^':
|
||||
*c = 'x';
|
||||
break;
|
||||
case '&':
|
||||
*c = 'A';
|
||||
break;
|
||||
case '|':
|
||||
*c = 'o';
|
||||
break;
|
||||
case '~':
|
||||
*c = 'n';
|
||||
break;
|
||||
case '!':
|
||||
*c = 'N';
|
||||
break;
|
||||
case '%':
|
||||
*c = 'M';
|
||||
break;
|
||||
case '.':
|
||||
*c = 'f';
|
||||
break;
|
||||
case '?':
|
||||
*c = 'q';
|
||||
break;
|
||||
default:
|
||||
*c = '_';
|
||||
break;
|
||||
}
|
||||
}
|
||||
c++;
|
||||
}
|
||||
if (special) Append(r,"___");
|
||||
return special;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_name_mangle()
|
||||
*
|
||||
|
|
@ -37,16 +125,10 @@ Swig_name_register(String_or_char *method, String_or_char *format) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *
|
||||
Swig_name_mangle(String_or_char *s) {
|
||||
String *r = NewString("");
|
||||
char *c;
|
||||
Append(r,s);
|
||||
c = Char(r);
|
||||
while (*c) {
|
||||
if (!isalnum(*c)) *c = '_';
|
||||
c++;
|
||||
}
|
||||
return Swig_temp_result(r);
|
||||
Swig_name_mangle(const String_or_char *s) {
|
||||
String *r = NewString(s);
|
||||
name_mangle(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -56,7 +138,7 @@ Swig_name_mangle(String_or_char *s) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *
|
||||
Swig_name_wrapper(String_or_char *fname) {
|
||||
Swig_name_wrapper(const String_or_char *fname) {
|
||||
String *r;
|
||||
String *f;
|
||||
|
||||
|
|
@ -69,8 +151,8 @@ Swig_name_wrapper(String_or_char *fname) {
|
|||
Append(r,f);
|
||||
}
|
||||
Replace(r,"%f",fname, DOH_REPLACE_ANY);
|
||||
Replace(r,":","_", DOH_REPLACE_ANY);
|
||||
return Swig_temp_result(r);
|
||||
name_mangle(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -81,11 +163,13 @@ Swig_name_wrapper(String_or_char *fname) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *
|
||||
Swig_name_member(String_or_char *classname, String_or_char *mname) {
|
||||
Swig_name_member(const String_or_char *classname, const String_or_char *mname) {
|
||||
String *r;
|
||||
String *f;
|
||||
char *cname, *c;
|
||||
String *rclassname;
|
||||
char *cname;
|
||||
|
||||
rclassname = SwigType_namestr(classname);
|
||||
r = NewString("");
|
||||
if (!naming_hash) naming_hash = NewHash();
|
||||
f = Getattr(naming_hash,"member");
|
||||
|
|
@ -94,12 +178,17 @@ Swig_name_member(String_or_char *classname, String_or_char *mname) {
|
|||
} else {
|
||||
Append(r,f);
|
||||
}
|
||||
cname = Char(classname);
|
||||
c = strchr(cname, ' ');
|
||||
if (c) cname = c+1;
|
||||
cname = Char(rclassname);
|
||||
if ((strncmp(cname,"struct ", 7) == 0) ||
|
||||
((strncmp(cname,"class ", 6) == 0)) ||
|
||||
((strncmp(cname,"union ", 6) == 0))) {
|
||||
cname = strchr(cname, ' ')+1;
|
||||
}
|
||||
Replace(r,"%c",cname, DOH_REPLACE_ANY);
|
||||
Replace(r,"%m",mname, DOH_REPLACE_ANY);
|
||||
return Swig_temp_result(r);
|
||||
/* name_mangle(r);*/
|
||||
Delete(rclassname);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -109,7 +198,7 @@ Swig_name_member(String_or_char *classname, String_or_char *mname) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *
|
||||
Swig_name_get(String_or_char *vname) {
|
||||
Swig_name_get(const String_or_char *vname) {
|
||||
String *r;
|
||||
String *f;
|
||||
|
||||
|
|
@ -122,7 +211,8 @@ Swig_name_get(String_or_char *vname) {
|
|||
Append(r,f);
|
||||
}
|
||||
Replace(r,"%v",vname, DOH_REPLACE_ANY);
|
||||
return Swig_temp_result(r);
|
||||
Replace(r,"::","_", DOH_REPLACE_ANY);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -132,7 +222,7 @@ Swig_name_get(String_or_char *vname) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *
|
||||
Swig_name_set(String_or_char *vname) {
|
||||
Swig_name_set(const String_or_char *vname) {
|
||||
String *r;
|
||||
String *f;
|
||||
|
||||
|
|
@ -145,7 +235,8 @@ Swig_name_set(String_or_char *vname) {
|
|||
Append(r,f);
|
||||
}
|
||||
Replace(r,"%v",vname, DOH_REPLACE_ANY);
|
||||
return Swig_temp_result(r);
|
||||
Replace(r,"::","_", DOH_REPLACE_ANY);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -155,10 +246,13 @@ Swig_name_set(String_or_char *vname) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *
|
||||
Swig_name_construct(String_or_char *classname) {
|
||||
Swig_name_construct(const String_or_char *classname) {
|
||||
String *r;
|
||||
String *f;
|
||||
char *cname, *c;
|
||||
String *rclassname;
|
||||
char *cname;
|
||||
|
||||
rclassname = SwigType_namestr(classname);
|
||||
r = NewString("");
|
||||
if (!naming_hash) naming_hash = NewHash();
|
||||
f = Getattr(naming_hash,"construct");
|
||||
|
|
@ -168,14 +262,52 @@ Swig_name_construct(String_or_char *classname) {
|
|||
Append(r,f);
|
||||
}
|
||||
|
||||
cname = Char(classname);
|
||||
c = strchr(cname, ' ');
|
||||
if (c) cname = c+1;
|
||||
cname = Char(rclassname);
|
||||
if ((strncmp(cname,"struct ", 7) == 0) ||
|
||||
((strncmp(cname,"class ", 6) == 0)) ||
|
||||
((strncmp(cname,"union ", 6) == 0))) {
|
||||
cname = strchr(cname, ' ')+1;
|
||||
}
|
||||
Replace(r,"%c",cname, DOH_REPLACE_ANY);
|
||||
Delete(rclassname);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_name_copyconstructor()
|
||||
*
|
||||
* Returns the name of the accessor function used to copy an object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *
|
||||
Swig_name_copyconstructor(const String_or_char *classname) {
|
||||
String *r;
|
||||
String *f;
|
||||
String *rclassname;
|
||||
char *cname;
|
||||
|
||||
rclassname = SwigType_namestr(classname);
|
||||
r = NewString("");
|
||||
if (!naming_hash) naming_hash = NewHash();
|
||||
f = Getattr(naming_hash,"construct");
|
||||
if (!f) {
|
||||
Append(r,"copy_%c");
|
||||
} else {
|
||||
Append(r,f);
|
||||
}
|
||||
|
||||
cname = Char(rclassname);
|
||||
if ((strncmp(cname,"struct ", 7) == 0) ||
|
||||
((strncmp(cname,"class ", 6) == 0)) ||
|
||||
((strncmp(cname,"union ", 6) == 0))) {
|
||||
cname = strchr(cname, ' ')+1;
|
||||
}
|
||||
|
||||
Replace(r,"%c",cname, DOH_REPLACE_ANY);
|
||||
return Swig_temp_result(r);
|
||||
Delete(rclassname);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_name_destroy()
|
||||
|
|
@ -183,10 +315,12 @@ Swig_name_construct(String_or_char *classname) {
|
|||
* Returns the name of the accessor function used to destroy an object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *Swig_name_destroy(String_or_char *classname) {
|
||||
String *Swig_name_destroy(const String_or_char *classname) {
|
||||
String *r;
|
||||
String *f;
|
||||
char *cname, *c;
|
||||
String *rclassname;
|
||||
char *cname;
|
||||
rclassname = SwigType_namestr(classname);
|
||||
r = NewString("");
|
||||
if (!naming_hash) naming_hash = NewHash();
|
||||
f = Getattr(naming_hash,"destroy");
|
||||
|
|
@ -196,14 +330,297 @@ String *Swig_name_destroy(String_or_char *classname) {
|
|||
Append(r,f);
|
||||
}
|
||||
|
||||
cname = Char(classname);
|
||||
c = strchr(cname, ' ');
|
||||
if (c) cname = c+1;
|
||||
|
||||
cname = Char(rclassname);
|
||||
if ((strncmp(cname,"struct ", 7) == 0) ||
|
||||
((strncmp(cname,"class ", 6) == 0)) ||
|
||||
((strncmp(cname,"union ", 6) == 0))) {
|
||||
cname = strchr(cname, ' ')+1;
|
||||
}
|
||||
Replace(r,"%c",cname, DOH_REPLACE_ANY);
|
||||
return Swig_temp_result(r);
|
||||
Delete(rclassname);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_name_object_set()
|
||||
*
|
||||
* Sets an object associated with a name and optional declarators.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_name_object_set(Hash *namehash, String *name, SwigType *decl, DOH *object) {
|
||||
DOH *n;
|
||||
|
||||
/* Printf(stdout,"name: '%s', '%s'\n", name, decl);*/
|
||||
n = Getattr(namehash,name);
|
||||
if (!n) {
|
||||
n = NewHash();
|
||||
Setattr(namehash,name,n);
|
||||
}
|
||||
/* Add an object based on the declarator value */
|
||||
if (!decl) {
|
||||
Setattr(n,NewString("*"),object);
|
||||
} else {
|
||||
Setattr(n,Copy(decl),object);
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_name_object_get()
|
||||
*
|
||||
* Return an object associated with an optional class prefix, name, and
|
||||
* declarator. This function operates according to name matching rules
|
||||
* described for the %rename directive in the SWIG manual.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *get_object(Hash *n, String *decl) {
|
||||
DOH *rn = 0;
|
||||
if (!n) return 0;
|
||||
if (decl) {
|
||||
rn = Getattr(n,decl);
|
||||
} else {
|
||||
rn = Getattr(n,"*");
|
||||
}
|
||||
return rn;
|
||||
}
|
||||
|
||||
DOH *
|
||||
Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *decl) {
|
||||
String *tname;
|
||||
DOH *rn = 0;
|
||||
Hash *n;
|
||||
char *ncdecl = 0;
|
||||
|
||||
if (!namehash) return 0;
|
||||
|
||||
/* DB: This removed to more tightly control feature/name matching */
|
||||
/* if ((decl) && (SwigType_isqualifier(decl))) {
|
||||
ncdecl = strchr(Char(decl),'.');
|
||||
ncdecl++;
|
||||
}
|
||||
*/
|
||||
|
||||
/* Perform a class-based lookup (if class prefix supplied) */
|
||||
if (prefix) {
|
||||
if (Len(prefix)) {
|
||||
tname = NewStringf("%s::%s",prefix,name);
|
||||
n = Getattr(namehash,tname);
|
||||
rn = get_object(n,decl);
|
||||
if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
|
||||
if (!rn) rn = get_object(n,0);
|
||||
Delete(tname);
|
||||
}
|
||||
/* A wildcard-based class lookup */
|
||||
if (!rn) {
|
||||
tname = NewStringf("*::%s",name);
|
||||
n = Getattr(namehash,tname);
|
||||
rn = get_object(n,decl);
|
||||
if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
|
||||
if (!rn) rn = get_object(n,0);
|
||||
Delete(tname);
|
||||
}
|
||||
} else {
|
||||
/* Lookup in the global namespace only */
|
||||
tname = NewStringf("::%s",name);
|
||||
n = Getattr(namehash,tname);
|
||||
rn = get_object(n,decl);
|
||||
if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
|
||||
if (!rn) rn = get_object(n,0);
|
||||
Delete(tname);
|
||||
}
|
||||
/* Catch-all */
|
||||
if (!rn) {
|
||||
n = Getattr(namehash,name);
|
||||
rn = get_object(n,decl);
|
||||
if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
|
||||
if (!rn) rn = get_object(n,0);
|
||||
}
|
||||
return rn;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_name_object_inherit()
|
||||
*
|
||||
* Implements name-based inheritance scheme.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_name_object_inherit(Hash *namehash, String *base, String *derived) {
|
||||
String *key;
|
||||
String *bprefix;
|
||||
String *dprefix;
|
||||
char *cbprefix;
|
||||
int plen;
|
||||
|
||||
if (!namehash) return;
|
||||
|
||||
bprefix = NewStringf("%s::",base);
|
||||
dprefix = NewStringf("%s::",derived);
|
||||
cbprefix = Char(bprefix);
|
||||
plen = strlen(cbprefix);
|
||||
for (key = Firstkey(namehash); key; key = Nextkey(namehash)) {
|
||||
char *k = Char(key);
|
||||
if (strncmp(k,cbprefix,plen) == 0) {
|
||||
Hash *n, *newh;
|
||||
String *nkey, *okey;
|
||||
|
||||
nkey = NewStringf("%s%s",dprefix,k+plen);
|
||||
n = Getattr(namehash,key);
|
||||
newh = Getattr(namehash,nkey);
|
||||
if (!newh) {
|
||||
newh = NewHash();
|
||||
Setattr(namehash,nkey,newh);
|
||||
}
|
||||
for (okey = Firstkey(n); okey; okey = Nextkey(n)) {
|
||||
String *ovalue = Getattr(n,okey);
|
||||
if (!Getattr(newh,okey)) {
|
||||
Setattr(newh,okey,Copy(ovalue));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_features_get()
|
||||
*
|
||||
* Given a node, this function merges features.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void merge_features(Hash *features, Node *n) {
|
||||
String *key;
|
||||
if (!features) return;
|
||||
for (key = Firstkey(features); key; key = Nextkey(features)) {
|
||||
if (Getattr(n,key)) {
|
||||
continue;
|
||||
}
|
||||
Setattr(n,key,Copy(Getattr(features,key)));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl, Node *node) {
|
||||
String *tname;
|
||||
DOH *rn = 0;
|
||||
Hash *n;
|
||||
char *ncdecl = 0;
|
||||
|
||||
if (!features) return;
|
||||
|
||||
if ((decl) && (SwigType_isqualifier(decl))) {
|
||||
ncdecl = strchr(Char(decl),'.');
|
||||
ncdecl++;
|
||||
}
|
||||
|
||||
if (name) {
|
||||
/* Perform a class-based lookup (if class prefix supplied) */
|
||||
if (prefix) {
|
||||
if (Len(prefix)) {
|
||||
tname = NewStringf("%s::%s",prefix,name);
|
||||
n = Getattr(features,tname);
|
||||
rn = get_object(n,decl);
|
||||
merge_features(rn,node);
|
||||
if (ncdecl) {
|
||||
rn = get_object(n,ncdecl);
|
||||
merge_features(rn,node);
|
||||
}
|
||||
rn = get_object(n,0);
|
||||
merge_features(rn,node);
|
||||
Delete(tname);
|
||||
}
|
||||
/* A wildcard-based class lookup */
|
||||
tname = NewStringf("*::%s",name);
|
||||
n = Getattr(features,tname);
|
||||
rn = get_object(n,decl);
|
||||
merge_features(rn,node);
|
||||
if (ncdecl) {
|
||||
rn = get_object(n,ncdecl);
|
||||
merge_features(rn,node);
|
||||
}
|
||||
rn = get_object(n,0);
|
||||
merge_features(rn,node);
|
||||
Delete(tname);
|
||||
|
||||
/* A class-generic feature */
|
||||
if (Len(prefix)) {
|
||||
tname = NewStringf("%s::",prefix);
|
||||
n = Getattr(features,tname);
|
||||
rn = get_object(n,0);
|
||||
merge_features(rn,node);
|
||||
Delete(tname);
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Lookup in the global namespace only */
|
||||
tname = NewStringf("::%s",name);
|
||||
n = Getattr(features,tname);
|
||||
rn = get_object(n,decl);
|
||||
merge_features(rn,node);
|
||||
if (ncdecl) {
|
||||
rn = get_object(n,ncdecl);
|
||||
merge_features(rn,node);
|
||||
}
|
||||
rn = get_object(n,0);
|
||||
merge_features(rn,node);
|
||||
Delete(tname);
|
||||
}
|
||||
/* Catch-all */
|
||||
n = Getattr(features,name);
|
||||
rn = get_object(n,decl);
|
||||
merge_features(rn,node);
|
||||
if (ncdecl) {
|
||||
rn = get_object(n,ncdecl);
|
||||
merge_features(rn,node);
|
||||
}
|
||||
rn = get_object(n,0);
|
||||
merge_features(rn,node);
|
||||
}
|
||||
/* Global features */
|
||||
n = Getattr(features,"");
|
||||
rn = get_object(n,0);
|
||||
merge_features(rn,node);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_feature_set()
|
||||
*
|
||||
* Sets a feature name and value.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_feature_set(Hash *features, String *name, SwigType *decl, String *featurename, DOH *value) {
|
||||
Hash *n;
|
||||
Hash *fhash;
|
||||
/* Printf(stdout,"feature: %s %s %s %s\n", name, decl, featurename, value);*/
|
||||
|
||||
n = Getattr(features,name);
|
||||
if (!n) {
|
||||
n = NewHash();
|
||||
Setattr(features,name,n);
|
||||
}
|
||||
if (!decl) {
|
||||
fhash = Getattr(n,"*");
|
||||
if (!fhash) {
|
||||
fhash = NewHash();
|
||||
Setattr(n,"*",fhash);
|
||||
}
|
||||
} else {
|
||||
fhash = Getattr(n,decl);
|
||||
if (!fhash) {
|
||||
fhash = NewHash();
|
||||
Setattr(n,Copy(decl),fhash);
|
||||
}
|
||||
}
|
||||
if (value) {
|
||||
Setattr(fhash,featurename,value);
|
||||
} else {
|
||||
Delattr(fhash,featurename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_parms_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
|
|
@ -42,27 +42,36 @@ Parm *NewParm(SwigType *type, String_or_char *n) {
|
|||
|
||||
Parm *CopyParm(Parm *p) {
|
||||
SwigType *t;
|
||||
char *name;
|
||||
char *lname;
|
||||
char *value;
|
||||
int ignore;
|
||||
String *name;
|
||||
String *lname;
|
||||
String *value;
|
||||
String *ignore;
|
||||
String *alttype;
|
||||
|
||||
Parm *np = NewHash();
|
||||
t = Getattr(p,"type");
|
||||
name = GetChar(p,"name");
|
||||
lname = GetChar(p,"lname");
|
||||
value = GetChar(p,"value");
|
||||
ignore = GetInt(p,"ignore");
|
||||
name = Getattr(p,"name");
|
||||
lname = Getattr(p,"lname");
|
||||
value = Getattr(p,"value");
|
||||
ignore = Getattr(p,"ignore");
|
||||
alttype = Getattr(p,"alttype");
|
||||
|
||||
Setattr(np,"type",Copy(t));
|
||||
if (t)
|
||||
Setattr(np,"type",Copy(t));
|
||||
if (name)
|
||||
Setattr(np,"name",name);
|
||||
Setattr(np,"name",Copy(name));
|
||||
if (lname)
|
||||
Setattr(np,"lname", lname);
|
||||
Setattr(np,"lname", Copy(lname));
|
||||
if (value)
|
||||
Setattr(np,"value", value);
|
||||
Setattr(np,"value", Copy(value));
|
||||
if (ignore)
|
||||
SetInt(np,"ignore", ignore);
|
||||
Setattr(np,"ignore", Copy(ignore));
|
||||
if (alttype)
|
||||
Setattr(np,"alttype", Copy(alttype));
|
||||
|
||||
Setfile(np,Getfile(p));
|
||||
Setline(np,Getline(p));
|
||||
|
||||
return np;
|
||||
}
|
||||
|
||||
|
|
@ -81,12 +90,12 @@ CopyParmList(ParmList *p) {
|
|||
while (p) {
|
||||
np = CopyParm(p);
|
||||
if (pp) {
|
||||
Setnext(pp,np);
|
||||
set_nextSibling(pp,np);
|
||||
} else {
|
||||
fp = np;
|
||||
}
|
||||
pp = np;
|
||||
p = Getnext(p);
|
||||
p = nextSibling(p);
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
|
@ -98,12 +107,29 @@ CopyParmList(ParmList *p) {
|
|||
int ParmList_numarg(ParmList *p) {
|
||||
int n = 0;
|
||||
while (p) {
|
||||
if (!Getignore(p)) n++;
|
||||
p = Getnext(p);
|
||||
if (!Getattr(p,"ignore")) n++;
|
||||
p = nextSibling(p);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int ParmList_numrequired(). Return number of required arguments
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int ParmList_numrequired(ParmList *p) {
|
||||
int i = 0;
|
||||
while (p) {
|
||||
SwigType *t = Getattr(p,"type");
|
||||
String *value = Getattr(p,"value");
|
||||
if (value) return i;
|
||||
if (!(SwigType_type(t) == T_VOID)) i++;
|
||||
else break;
|
||||
p = nextSibling(p);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int ParmList_len()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -112,7 +138,7 @@ int ParmList_len(ParmList *p) {
|
|||
int i = 0;
|
||||
while (p) {
|
||||
i++;
|
||||
p = Getnext(p);
|
||||
p = nextSibling(p);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
|
@ -129,13 +155,13 @@ String *ParmList_str(ParmList *p) {
|
|||
|
||||
out = NewString("");
|
||||
while(p) {
|
||||
t = Gettype(p);
|
||||
Printf(out,"%s", SwigType_str(t,Getname(p)));
|
||||
p = Getnext(p);
|
||||
t = Getattr(p,"type");
|
||||
Printf(out,"%s", SwigType_str(t,Getattr(p,"name")));
|
||||
p = nextSibling(p);
|
||||
if (p)
|
||||
Printf(out,",");
|
||||
}
|
||||
return Swig_temp_result(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
|
|
@ -150,13 +176,17 @@ String *ParmList_protostr(ParmList *p) {
|
|||
|
||||
out = NewString("");
|
||||
while(p) {
|
||||
t = Gettype(p);
|
||||
if (Getattr(p,"hidden")) {
|
||||
p = nextSibling(p);
|
||||
continue;
|
||||
}
|
||||
t = Getattr(p,"type");
|
||||
Printf(out,"%s", SwigType_str(t,0));
|
||||
p = Getnext(p);
|
||||
p = nextSibling(p);
|
||||
if (p)
|
||||
Printf(out,",");
|
||||
}
|
||||
return Swig_temp_result(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_scanner_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
#include <ctype.h>
|
||||
|
|
@ -598,22 +598,46 @@ look(SwigScanner *s) {
|
|||
if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LONG;
|
||||
if ((c == 'u') || (c == 'U')) {
|
||||
return SWIG_TOKEN_ULONG;
|
||||
} else if ((c == 'l') || (c == 'L')) {
|
||||
state = 870;
|
||||
} else {
|
||||
retract(s,1);
|
||||
return SWIG_TOKEN_LONG;
|
||||
}
|
||||
break;
|
||||
|
||||
/* A long long integer */
|
||||
|
||||
case 870:
|
||||
if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LONGLONG;
|
||||
if ((c == 'u') || (c == 'U')) {
|
||||
return SWIG_TOKEN_ULONGLONG;
|
||||
} else {
|
||||
retract(s,1);
|
||||
return SWIG_TOKEN_LONGLONG;
|
||||
}
|
||||
|
||||
/* An unsigned number */
|
||||
case 88:
|
||||
|
||||
if ((c = nextchar(s)) == 0) return SWIG_TOKEN_UINT;
|
||||
if ((c == 'l') || (c == 'L')) {
|
||||
return SWIG_TOKEN_ULONG;
|
||||
state = 880;
|
||||
} else {
|
||||
retract(s,1);
|
||||
return SWIG_TOKEN_UINT;
|
||||
retract(s,1);
|
||||
return SWIG_TOKEN_UINT;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Possibly an unsigned long long or unsigned long */
|
||||
case 880:
|
||||
if ((c = nextchar(s)) == 0) return SWIG_TOKEN_ULONG;
|
||||
if ((c == 'l') || (c == 'L')) return SWIG_TOKEN_ULONGLONG;
|
||||
else {
|
||||
retract(s,1);
|
||||
return SWIG_TOKEN_ULONG;
|
||||
}
|
||||
|
||||
/* A character constant */
|
||||
case 9:
|
||||
if ((c = nextchar(s)) == 0) {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -22,6 +22,12 @@
|
|||
|
||||
#include "doh.h"
|
||||
|
||||
/* Status codes */
|
||||
|
||||
#define SWIG_OK 1
|
||||
#define SWIG_ERROR 0
|
||||
#define SWIG_NOWRAP 0
|
||||
|
||||
/* Short names for common data types */
|
||||
|
||||
typedef DOH String;
|
||||
|
|
@ -32,30 +38,46 @@ typedef DOH File;
|
|||
typedef DOH Parm;
|
||||
typedef DOH ParmList;
|
||||
typedef DOH Node;
|
||||
typedef DOH Symtab;
|
||||
typedef DOH Typetab;
|
||||
typedef DOH SwigType;
|
||||
|
||||
/* --- Legacy DataType interface. These type codes are provided solely
|
||||
for backwards compatibility with older modules --- */
|
||||
for backwards compatibility with older modules --- */
|
||||
|
||||
#define T_INT 1
|
||||
#define T_SHORT 2
|
||||
#define T_LONG 3
|
||||
#define T_UINT 4
|
||||
/* --- The ordering of type values is used to determine type-promotion
|
||||
in the parser. Do not change */
|
||||
|
||||
/* Numeric types */
|
||||
|
||||
#define T_BOOL 1
|
||||
#define T_SCHAR 2
|
||||
#define T_UCHAR 3
|
||||
#define T_SHORT 4
|
||||
#define T_USHORT 5
|
||||
#define T_ULONG 6
|
||||
#define T_UCHAR 7
|
||||
#define T_SCHAR 8
|
||||
#define T_BOOL 9
|
||||
#define T_DOUBLE 10
|
||||
#define T_FLOAT 11
|
||||
#define T_CHAR 12
|
||||
#define T_USER 13
|
||||
#define T_VOID 14
|
||||
#define T_ENUM 15
|
||||
#define T_STRING 20
|
||||
#define T_POINTER 21
|
||||
#define T_REFERENCE 22
|
||||
#define T_ARRAY 23
|
||||
#define T_FUNCTION 24
|
||||
#define T_ENUM 6
|
||||
#define T_INT 7
|
||||
#define T_UINT 8
|
||||
#define T_LONG 9
|
||||
#define T_ULONG 10
|
||||
#define T_LONGLONG 11
|
||||
#define T_ULONGLONG 12
|
||||
#define T_FLOAT 20
|
||||
#define T_DOUBLE 21
|
||||
#define T_NUMERIC 22
|
||||
|
||||
/* non-numeric */
|
||||
|
||||
#define T_CHAR 30
|
||||
#define T_USER 31
|
||||
#define T_VOID 32
|
||||
#define T_STRING 33
|
||||
#define T_POINTER 34
|
||||
#define T_REFERENCE 35
|
||||
#define T_ARRAY 36
|
||||
#define T_FUNCTION 37
|
||||
#define T_MPOINTER 38
|
||||
#define T_VARARGS 39
|
||||
#define T_SYMBOL 98
|
||||
#define T_ERROR 99
|
||||
|
||||
|
|
@ -68,20 +90,21 @@ extern FILE *Swig_open(const String_or_char *name);
|
|||
extern String *Swig_read_file(FILE *f);
|
||||
extern String *Swig_include(const String_or_char *name);
|
||||
extern int Swig_insert_file(const String_or_char *name, File *outfile);
|
||||
extern int Swig_bytes_read();
|
||||
extern void Swig_register_filebyname(const String_or_char *name, File *outfile);
|
||||
extern File *Swig_filebyname(const String_or_char *name);
|
||||
extern void Swig_swiglib_set(const String_or_char *name);
|
||||
extern void Swig_set_config_file(const String_or_char *filename);
|
||||
extern String *Swig_get_config_file(void);
|
||||
extern void Swig_swiglib_set(const String_or_char *);
|
||||
extern String *Swig_swiglib_get();
|
||||
extern void Swig_set_config_file(const String_or_char *name);
|
||||
extern String *Swig_get_config_file();
|
||||
|
||||
#define OUTFILE(x) Swig_filebyname(x)
|
||||
extern void Swig_register_filebyname(const String_or_char *filename, File *outfile);
|
||||
extern File *Swig_filebyname(const String_or_char *filename);
|
||||
extern char *Swig_file_suffix(const String_or_char *filename);
|
||||
extern char *Swig_file_basename(const String_or_char *filename);
|
||||
extern char *Swig_file_filename(const String_or_char *filename);
|
||||
extern char *Swig_file_dirname(const String_or_char *filename);
|
||||
|
||||
#ifdef MACSWIG
|
||||
#define SWIG_FILE_DELIMETER ":"
|
||||
# define SWIG_FILE_DELIMETER ":"
|
||||
#else
|
||||
#define SWIG_FILE_DELIMETER "/"
|
||||
# define SWIG_FILE_DELIMETER "/"
|
||||
#endif
|
||||
|
||||
/* --- Command line parsing --- */
|
||||
|
|
@ -159,23 +182,29 @@ extern void SwigScanner_idstart(SwigScanner *, char *idchar);
|
|||
#define SWIG_TOKEN_DOLLAR 46
|
||||
#define SWIG_TOKEN_CODEBLOCK 47
|
||||
#define SWIG_TOKEN_RSTRING 48
|
||||
#define SWIG_TOKEN_LONGLONG 49
|
||||
#define SWIG_TOKEN_ULONGLONG 50
|
||||
#define SWIG_TOKEN_ILLEGAL 98
|
||||
#define SWIG_TOKEN_LAST 99
|
||||
|
||||
/* --- Functions for manipulating the string-based type encoding --- */
|
||||
typedef DOH SwigType;
|
||||
|
||||
extern SwigType *NewSwigType(int typecode);
|
||||
extern void SwigType_add_pointer(SwigType *t);
|
||||
extern void SwigType_add_memberpointer(SwigType *t, String_or_char *qual);
|
||||
extern void SwigType_del_pointer(SwigType *t);
|
||||
extern void SwigType_add_array(SwigType *t, String_or_char *size);
|
||||
extern SwigType *SwigType_pop_arrays(SwigType *t);
|
||||
extern void SwigType_add_reference(SwigType *t);
|
||||
extern void SwigType_add_qualifier(SwigType *t, String_or_char *qual);
|
||||
extern void SwigType_add_function(SwigType *t, ParmList *parms);
|
||||
extern void SwigType_add_template(SwigType *t, ParmList *parms);
|
||||
extern SwigType *SwigType_pop_function(SwigType *t);
|
||||
extern ParmList *SwigType_function_parms(SwigType *t);
|
||||
extern List *SwigType_split(SwigType *t);
|
||||
extern String *SwigType_pop(SwigType *t);
|
||||
extern void SwigType_push(SwigType *t, SwigType *s);
|
||||
extern List *SwigType_parmlist(SwigType *p);
|
||||
extern List *SwigType_parmlist(const SwigType *p);
|
||||
extern String *SwigType_parm(String *p);
|
||||
extern String *SwigType_str(SwigType *s, const String_or_char *id);
|
||||
extern String *SwigType_lstr(SwigType *s, const String_or_char *id);
|
||||
|
|
@ -184,35 +213,84 @@ extern String *SwigType_lcaststr(SwigType *s, const String_or_char *id);
|
|||
extern String *SwigType_manglestr(SwigType *t);
|
||||
extern SwigType *SwigType_ltype(SwigType *t);
|
||||
extern int SwigType_ispointer(SwigType *t);
|
||||
extern int SwigType_ismemberpointer(SwigType *t);
|
||||
extern int SwigType_isreference(SwigType *t);
|
||||
extern int SwigType_isarray(SwigType *t);
|
||||
extern int SwigType_isfunction(SwigType *t);
|
||||
extern int SwigType_isqualifier(SwigType *t);
|
||||
extern int SwigType_isconst(SwigType *t);
|
||||
|
||||
extern int SwigType_issimple(SwigType *t);
|
||||
extern int SwigType_ismutable(SwigType *t);
|
||||
extern int SwigType_isvarargs(const SwigType *t);
|
||||
extern int SwigType_istemplate(const SwigType *t);
|
||||
extern int SwigType_isenum(SwigType *t);
|
||||
extern int SwigType_check_decl(SwigType *t, const String_or_char *decl);
|
||||
extern SwigType *SwigType_strip_qualifiers(SwigType *t);
|
||||
extern String *SwigType_base(SwigType *t);
|
||||
extern String *SwigType_namestr(const SwigType *t);
|
||||
extern String *SwigType_templateprefix(SwigType *t);
|
||||
extern String *SwigType_templatesuffix(const SwigType *t);
|
||||
extern String *SwigType_templateargs(SwigType *t);
|
||||
extern String *SwigType_prefix(SwigType *t);
|
||||
extern void SwigType_setbase(SwigType *t, String_or_char *name);
|
||||
|
||||
extern int SwigType_typedef(SwigType *type, String_or_char *name);
|
||||
extern void SwigType_inherit(String *subclass, String *baseclass);
|
||||
extern void SwigType_new_scope();
|
||||
extern void SwigType_reset_scopes();
|
||||
extern void SwigType_set_scope_name(String_or_char *name);
|
||||
extern void SwigType_merge_scope(Hash *scope, String *prefix);
|
||||
extern Hash *SwigType_pop_scope();
|
||||
extern SwigType *SwigType_typedef_resolve(SwigType *t);
|
||||
extern SwigType *SwigType_typedef_resolve_all(SwigType *t);
|
||||
extern int SwigType_istypedef(SwigType *t);
|
||||
extern int SwigType_cmp(String_or_char *pat, SwigType *t);
|
||||
extern int SwigType_array_ndim(SwigType *t);
|
||||
extern String *SwigType_array_getdim(SwigType *t, int n);
|
||||
extern void SwigType_array_setdim(SwigType *t, int n, String_or_char *rep);
|
||||
extern SwigType *SwigType_array_type(SwigType *t);
|
||||
extern String *SwigType_default(SwigType *t);
|
||||
extern int SwigType_type(SwigType *t);
|
||||
extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep);
|
||||
|
||||
/* --- Type-system managment --- */
|
||||
extern void SwigType_typesystem_init();
|
||||
extern int SwigType_typedef(SwigType *type, String_or_char *name);
|
||||
extern int SwigType_typedef_class(String_or_char *name);
|
||||
extern int SwigType_typedef_using(String_or_char *qname);
|
||||
extern void SwigType_inherit(String *subclass, String *baseclass, String *cast);
|
||||
extern int SwigType_issubtype(SwigType *subtype, SwigType *basetype);
|
||||
extern void SwigType_scope_alias(String *aliasname, Typetab *t);
|
||||
extern void SwigType_using_scope(Typetab *t);
|
||||
extern void SwigType_new_scope(String_or_char *name);
|
||||
extern void SwigType_reset_scopes();
|
||||
extern void SwigType_set_scope_name(String_or_char *name);
|
||||
extern void SwigType_inherit_scope(Typetab *scope);
|
||||
extern Typetab *SwigType_pop_scope();
|
||||
extern Typetab *SwigType_set_scope(Typetab *h);
|
||||
extern void SwigType_print_scope(Typetab *t);
|
||||
extern SwigType *SwigType_typedef_resolve(SwigType *t);
|
||||
extern SwigType *SwigType_typedef_resolve_all(SwigType *t);
|
||||
extern SwigType *SwigType_typedef_qualified(SwigType *t);
|
||||
extern int SwigType_istypedef(SwigType *t);
|
||||
extern int SwigType_isclass(SwigType *t);
|
||||
extern void SwigType_attach_symtab(Symtab *syms);
|
||||
extern void SwigType_remember(SwigType *t);
|
||||
extern void SwigType_remember_clientdata(SwigType *t, const String_or_char *clientdata);
|
||||
extern void (*SwigType_remember_trace(void (*tf)(SwigType *, String *, String *)))(SwigType *, String *, String *);
|
||||
extern void SwigType_emit_type_table(File *f_headers, File *f_table);
|
||||
extern void SwigType_strip_qualifiers(SwigType *t);
|
||||
extern int SwigType_type(SwigType *t);
|
||||
|
||||
/* --- Symbol table module --- */
|
||||
|
||||
extern void Swig_symbol_init();
|
||||
extern void Swig_symbol_setscopename(const String_or_char *name);
|
||||
extern String *Swig_symbol_getscopename();
|
||||
extern String *Swig_symbol_qualifiedscopename(Symtab *symtab);
|
||||
extern Symtab *Swig_symbol_newscope();
|
||||
extern Symtab *Swig_symbol_setscope(Symtab *);
|
||||
extern Symtab *Swig_symbol_getscope(const String_or_char *symname);
|
||||
extern Symtab *Swig_symbol_current();
|
||||
extern Symtab *Swig_symbol_popscope();
|
||||
extern Node *Swig_symbol_add(String_or_char *symname, Node *node);
|
||||
extern void Swig_symbol_cadd(String_or_char *symname, Node *node);
|
||||
extern Node *Swig_symbol_clookup(String_or_char *symname, Symtab *tab);
|
||||
extern Symtab *Swig_symbol_cscope(String_or_char *symname, Symtab *tab);
|
||||
extern Node *Swig_symbol_clookup_local(String_or_char *symname, Symtab *tab);
|
||||
extern String *Swig_symbol_qualified(Node *node);
|
||||
extern Node *Swig_symbol_isoverloaded(Node *node);
|
||||
extern void Swig_symbol_remove(Node *node);
|
||||
extern void Swig_symbol_alias(String_or_char *aliasname, Symtab *tab);
|
||||
extern void Swig_symbol_inherit(Symtab *tab);
|
||||
extern SwigType *Swig_symbol_type_qualify(SwigType *ty, Symtab *tab);
|
||||
extern String *Swig_symbol_string_qualify(String *s, Symtab *tab);
|
||||
extern SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab);
|
||||
|
||||
/* --- Parameters and Parameter Lists --- */
|
||||
|
||||
|
|
@ -221,58 +299,63 @@ extern void SwigType_strip_qualifiers(SwigType *t);
|
|||
|
||||
extern Parm *NewParm(SwigType *type, String_or_char *n);
|
||||
extern Parm *CopyParm(Parm *p);
|
||||
|
||||
|
||||
|
||||
extern ParmList *CopyParmList(ParmList *);
|
||||
extern int ParmList_len(ParmList *);
|
||||
extern int ParmList_numarg(ParmList *);
|
||||
extern int ParmList_numrequired(ParmList *);
|
||||
extern String *ParmList_str(ParmList *);
|
||||
extern String *ParmList_protostr(ParmList *);
|
||||
|
||||
/* --- Parse tree support --- */
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
int (*action)(DOH *obj, void *clientdata);
|
||||
} SwigRule;
|
||||
/* DOM-like node access */
|
||||
|
||||
#define nodeType(x) Getattr(x,"nodeType")
|
||||
#define parentNode(x) Getattr(x,"parentNode")
|
||||
#define previousSibling(x) Getattr(x,"previousSibling")
|
||||
#define nextSibling(x) Getattr(x,"nextSibling")
|
||||
#define firstChild(x) Getattr(x,"firstChild")
|
||||
#define lastChild(x) Getattr(x,"lastChild")
|
||||
extern int checkAttribute(Node *obj, const String_or_char *name, const String_or_char *value);
|
||||
|
||||
#define SWIG_OK 1
|
||||
#define SWIG_NORULE 0
|
||||
#define SWIG_ERROR -1
|
||||
/* Macros to set up the DOM tree (mostly used by the parser) */
|
||||
|
||||
extern void Swig_add_rule(const String_or_char *, int (*action)(DOH *, void *));
|
||||
extern void Swig_add_rules(SwigRule ruleset[]);
|
||||
extern void Swig_clear_rules();
|
||||
extern int Swig_tag_check(DOH *obj, const String_or_char *tagname);
|
||||
extern int Swig_emit(DOH *obj, void *clientdata);
|
||||
extern int Swig_emit_all(DOH *obj, void *clientdata);
|
||||
extern void Swig_set_callback(DOH *obj, void (*cb)(void *clientdata), void *clientdata);
|
||||
extern void (*Swig_set_trace(DOH *obj, void (*cb)(DOH *, DOH *), DOH *arg))(DOH *, DOH *);
|
||||
extern void Swig_remove_trace(DOH *obj);
|
||||
extern void Swig_node_cut(DOH *obj);
|
||||
extern void Swig_node_insert(DOH *node, DOH *newnode);
|
||||
extern void Swig_node_temporary(DOH *node);
|
||||
extern void Swig_node_ignore(DOH *node);
|
||||
extern void Swig_node_append_child(DOH *node, DOH *cld);
|
||||
extern int Swig_count_nodes(DOH *node);
|
||||
#define set_nodeType(x,v) Setattr(x,"nodeType",v)
|
||||
#define set_parentNode(x,v) Setattr(x,"parentNode",v)
|
||||
#define set_previousSibling(x,v) Setattr(x,"previousSibling",v)
|
||||
#define set_nextSibling(x,v) Setattr(x,"nextSibling",v)
|
||||
#define set_firstChild(x,v) Setattr(x,"firstChild",v)
|
||||
#define set_lastChild(x,v) Setattr(x,"lastChild",v)
|
||||
|
||||
extern DOH *Swig_next(DOH *obj);
|
||||
extern DOH *Swig_prev(DOH *obj);
|
||||
extern void appendChild(Node *node, Node *child);
|
||||
extern void deleteNode(Node *node);
|
||||
extern Node *copyNode(Node *node);
|
||||
|
||||
extern void Swig_tag_nodes(Node *node, const String_or_char *attrname, DOH *value);
|
||||
|
||||
extern int Swig_require(Node **node, ...);
|
||||
extern int Swig_save(Node **node,...);
|
||||
extern void Swig_restore(Node **node);
|
||||
|
||||
/* Debugging of parse trees */
|
||||
extern void Swig_debug_emit(int);
|
||||
extern void Swig_dump_tags(DOH *obj, DOH *root);
|
||||
extern void Swig_dump_tree(DOH *obj);
|
||||
extern void Swig_dump_rules();
|
||||
extern void Swig_print_tags(File *obj, Node *root);
|
||||
extern void Swig_print_tree(Node *obj);
|
||||
extern void Swig_print_node(Node *obj);
|
||||
|
||||
/* -- Wrapper function Object */
|
||||
|
||||
typedef DOH Wrapper;
|
||||
typedef struct {
|
||||
Hash *localh;
|
||||
String *def;
|
||||
String *locals;
|
||||
String *code;
|
||||
} Wrapper;
|
||||
|
||||
extern Wrapper *NewWrapper();
|
||||
extern void DelWrapper(Wrapper *w);
|
||||
extern void Wrapper_pretty_print(String *str, File *f);
|
||||
extern void Wrapper_print(Wrapper *w, File *f);
|
||||
extern int Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl);
|
||||
extern int Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...);
|
||||
extern int Wrapper_check_local(Wrapper *w, const String_or_char *name);
|
||||
|
|
@ -281,160 +364,115 @@ extern char *Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...)
|
|||
|
||||
/* --- Naming functions --- */
|
||||
|
||||
extern void Swig_name_register(String_or_char *method, String_or_char *format);
|
||||
extern String *Swig_name_mangle(String_or_char *s);
|
||||
extern String *Swig_name_wrapper(String_or_char *fname);
|
||||
extern String *Swig_name_member(String_or_char *classname, String_or_char *mname);
|
||||
extern String *Swig_name_get(String_or_char *vname);
|
||||
extern String *Swig_name_set(String_or_char *vname);
|
||||
extern String *Swig_name_construct(String_or_char *classname);
|
||||
extern String *Swig_name_destroy(String_or_char *classname);
|
||||
extern void Swig_name_register(const String_or_char *method, const String_or_char *format);
|
||||
extern void Swig_name_unregister(const String_or_char *method);
|
||||
extern String *Swig_name_mangle(const String_or_char *s);
|
||||
extern String *Swig_name_wrapper(const String_or_char *fname);
|
||||
extern String *Swig_name_member(const String_or_char *classname, const String_or_char *mname);
|
||||
extern String *Swig_name_get(const String_or_char *vname);
|
||||
extern String *Swig_name_set(const String_or_char *vname);
|
||||
extern String *Swig_name_construct(const String_or_char *classname);
|
||||
extern String *Swig_name_copyconstructor(const String_or_char *classname);
|
||||
extern String *Swig_name_destroy(const String_or_char *classname);
|
||||
|
||||
/* --- Mapping interface --- */
|
||||
/* --- parameterized rename functions --- */
|
||||
|
||||
extern void Swig_map_add(Hash *ruleset, Hash *parms, DOH *obj);
|
||||
extern DOH *Swig_map_match(Hash *ruleset, Hash *parms, int *nmatch);
|
||||
extern void Swig_name_object_set(Hash *namehash, String_or_char *name, SwigType *decl, DOH *object);
|
||||
extern DOH *Swig_name_object_get(Hash *namehash, String_or_char *prefix, String_or_char *name, SwigType *decl);
|
||||
extern void Swig_name_object_inherit(Hash *namehash, String *base, String *derived);
|
||||
extern void Swig_features_get(Hash *features, String_or_char *prefix, String_or_char *name, SwigType *decl, Node *n);
|
||||
extern void Swig_feature_set(Hash *features, String_or_char *name, SwigType *decl, String_or_char *fname, String *value);
|
||||
|
||||
/* --- Misc --- */
|
||||
extern char *Swig_copy_string(const char *c);
|
||||
extern void Swig_banner(File *f);
|
||||
extern void Swig_section(File *f, const String_or_char *s);
|
||||
extern DOH *Swig_temp_result(DOH *x);
|
||||
extern String *Swig_string_escape(String *s);
|
||||
extern String *Swig_string_mangle(String *s);
|
||||
extern void Swig_init();
|
||||
extern String *Swig_scopename_prefix(String *s);
|
||||
extern String *Swig_scopename_last(String *s);
|
||||
extern String *Swig_scopename_first(String *s);
|
||||
extern String *Swig_scopename_suffix(String *s);
|
||||
extern int Swig_scopename_check(String *s);
|
||||
|
||||
extern int Swig_proto_cmp(const String_or_char *pat, DOH *node);
|
||||
extern void Swig_init();
|
||||
extern void Swig_warn(const char *filename, int line, const char *msg);
|
||||
|
||||
|
||||
#define WARNING(msg) Swig_warn(__FILE__,__LINE__,msg)
|
||||
|
||||
extern void Swig_warning(int num, const String_or_char *filename, int line, const char *fmt, ...);
|
||||
extern void Swig_error(const String_or_char *filename, int line, const char *fmt, ...);
|
||||
extern int Swig_error_count(void);
|
||||
extern void Swig_error_silent(int s);
|
||||
extern void Swig_warnfilter(const String_or_char *wlist, int val);
|
||||
extern void Swig_warnall(void);
|
||||
extern int Swig_warn_count(void);
|
||||
|
||||
/* --- C Wrappers --- */
|
||||
extern String *Swig_clocal(SwigType *t, String_or_char *name, String_or_char *value);
|
||||
extern SwigType *Swig_clocal_type(SwigType *t);
|
||||
extern String *Swig_clocal_deref(SwigType *t, String_or_char *name);
|
||||
extern String *Swig_clocal_assign(SwigType *t, String_or_char *name);
|
||||
extern String *Swig_cparm_name(Parm *p, int i);
|
||||
extern String *Swig_clocal(SwigType *t, String_or_char *name, String_or_char *value);
|
||||
extern String *Swig_wrapped_var_type(SwigType *t);
|
||||
extern String *Swig_wrapped_var_deref(SwigType *t, String_or_char *name);
|
||||
extern String *Swig_wrapped_var_assign(SwigType *t, String_or_char *name);
|
||||
extern int Swig_cargs(Wrapper *w, ParmList *l);
|
||||
extern void Swig_cresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_char *decl);
|
||||
extern void Swig_cppresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_char *decl);
|
||||
extern String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_char *decl);
|
||||
|
||||
extern String *Swig_cfunction_call(String_or_char *name, ParmList *parms);
|
||||
extern String *Swig_cmethod_call(String_or_char *name, ParmList *parms);
|
||||
extern String *Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self);
|
||||
extern String *Swig_cconstructor_call(String_or_char *name);
|
||||
extern String *Swig_cppconstructor_call(String_or_char *name, ParmList *parms);
|
||||
extern String *Swig_cdestructor_call();
|
||||
extern String *Swig_cppdestructor_call();
|
||||
extern String *Swig_cmemberset_call(String_or_char *name, SwigType *t);
|
||||
extern String *Swig_cmemberget_call(String_or_char *name, SwigType *t);
|
||||
extern String *Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self);
|
||||
extern String *Swig_cmemberget_call(String_or_char *name, SwigType *t, String_or_char *self);
|
||||
|
||||
extern Wrapper *Swig_cfunction_wrapper(String_or_char *funcname,
|
||||
SwigType *rtype,
|
||||
ParmList *parms,
|
||||
String_or_char *code);
|
||||
/* --- Transformations --- */
|
||||
|
||||
extern Wrapper *Swig_cmethod_wrapper(String_or_char *classname,
|
||||
String_or_char *methodname,
|
||||
SwigType *rtype,
|
||||
ParmList *parms,
|
||||
String_or_char *code);
|
||||
extern int Swig_MethodToFunction(Node *n, String *classname, int flags);
|
||||
extern int Swig_ConstructorToFunction(Node *n, String *classname, int cplus, int flags);
|
||||
extern int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags);
|
||||
extern int Swig_MembersetToFunction(Node *n, String *classname, int flags);
|
||||
extern int Swig_MembergetToFunction(Node *n, String *classname, int flags);
|
||||
extern int Swig_VargetToFunction(Node *n);
|
||||
extern int Swig_VarsetToFunction(Node *n);
|
||||
|
||||
extern Wrapper *Swig_cdestructor_wrapper(String_or_char *classname,
|
||||
String_or_char *code);
|
||||
#define CWRAP_EXTEND 0x01
|
||||
#define CWRAP_SMART_POINTER 0x02
|
||||
|
||||
extern Wrapper *Swig_cppdestructor_wrapper(String_or_char *classname,
|
||||
String_or_char *code);
|
||||
/* --- Legacy Typemap API (somewhat simplified, ha!) --- */
|
||||
|
||||
extern Wrapper *Swig_cconstructor_wrapper(String_or_char *classname,
|
||||
ParmList *parms,
|
||||
String_or_char *code);
|
||||
extern void Swig_typemap_init();
|
||||
extern void Swig_typemap_register(const String_or_char *op, ParmList *pattern, String_or_char *code, ParmList *locals, ParmList *kwargs);
|
||||
extern int Swig_typemap_copy(const String_or_char *op, ParmList *srcpattern, ParmList *pattern);
|
||||
extern void Swig_typemap_clear(const String_or_char *op, ParmList *pattern);
|
||||
extern int Swig_typemap_apply(ParmList *srcpat, ParmList *destpat);
|
||||
extern void Swig_typemap_clear_apply(ParmList *pattern);
|
||||
extern void Swig_typemap_debug();
|
||||
|
||||
extern Wrapper *Swig_cppconstructor_wrapper(String_or_char *classname,
|
||||
ParmList *parms,
|
||||
String_or_char *code);
|
||||
extern Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, String_or_char *pname, SwigType **matchtype);
|
||||
extern Hash *Swig_typemap_search_multi(const String_or_char *op, ParmList *parms, int *nmatch);
|
||||
extern String *Swig_typemap_lookup(const String_or_char *op, SwigType *type, String_or_char *pname, String_or_char *lname,
|
||||
String_or_char *source, String_or_char *target, Wrapper *f);
|
||||
|
||||
extern String *Swig_typemap_lookup_new(const String_or_char *op, Node *n, const String_or_char *lname, Wrapper *f);
|
||||
|
||||
extern Wrapper *Swig_cmemberset_wrapper(String_or_char *classname,
|
||||
String_or_char *membername,
|
||||
SwigType *type,
|
||||
String_or_char *code);
|
||||
|
||||
extern Wrapper *Swig_cmemberget_wrapper(String_or_char *classname,
|
||||
String_or_char *membername,
|
||||
SwigType *type,
|
||||
String_or_char *code);
|
||||
|
||||
extern Wrapper *Swig_cvarset_wrapper(String_or_char *varname,
|
||||
SwigType *type,
|
||||
String_or_char *code);
|
||||
|
||||
extern Wrapper *Swig_cvarget_wrapper(String_or_char *varname,
|
||||
SwigType *type,
|
||||
String_or_char *code);
|
||||
|
||||
|
||||
/* --- Module loader and handler --- */
|
||||
|
||||
typedef struct Module Module;
|
||||
extern void Swig_register_module(const String_or_char *modname, const String_or_char *starttag,
|
||||
int (*initfunc)(int, char **),
|
||||
DOH *(*startfunc)(DOH *));
|
||||
|
||||
extern Module *Swig_load_module(const String_or_char *modname);
|
||||
extern int Swig_init_module(Module *m, int argc, char **argv);
|
||||
extern DOH *Swig_start_module(Module *m, DOH *obj);
|
||||
extern DOH *Swig_run_modules(DOH *node);
|
||||
|
||||
/* --- Legacy Typemap API (somewhat simplified) --- */
|
||||
|
||||
extern void Swig_typemap_init();
|
||||
extern void Swig_typemap_register(const String_or_char *op, SwigType *type, String_or_char *name, String_or_char *code, ParmList *locals);
|
||||
extern void Swig_typemap_copy(const String_or_char *op, SwigType *stype, String_or_char *sname,
|
||||
SwigType *ttype, String_or_char *tname);
|
||||
extern void Swig_typemap_clear(const String_or_char *op, SwigType *type, String_or_char *name);
|
||||
extern void Swig_typemap_apply(SwigType *tm_type, String_or_char *tmname, SwigType *type, String_or_char *pname);
|
||||
extern void Swig_typemap_clear_apply(SwigType *type, String_or_char *pname);
|
||||
extern void Swig_typemap_debug();
|
||||
extern Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, String_or_char *pname);
|
||||
extern char *Swig_typemap_lookup(const String_or_char *op, SwigType *type, String_or_char *pname, String_or_char *source, String_or_char *target, Wrapper *f);
|
||||
extern void Swig_typemap_new_scope(Hash *);
|
||||
extern String *Swig_typemap_lookup_multi(const String_or_char *op, ParmList *parms, String_or_char *source, Wrapper *f, int *nmatch);
|
||||
extern void Swig_typemap_new_scope();
|
||||
extern Hash *Swig_typemap_pop_scope();
|
||||
|
||||
/* --- Legacy %except directive API --- */
|
||||
extern void Swig_except_register(String_or_char *code);
|
||||
extern char *Swig_except_lookup();
|
||||
extern void Swig_except_clear();
|
||||
extern void Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f);
|
||||
|
||||
/* --- Attribute access macros --- */
|
||||
|
||||
#define Gettype(x) Getattr(x,"type")
|
||||
#define Getname(x) Getattr(x,"name")
|
||||
#define Getvalue(x) Getattr(x,"value")
|
||||
#define Getlname(x) Getattr(x,"lname")
|
||||
#define Getignore(x) GetInt(x,"ignore")
|
||||
#define Getparms(x) Getattr(x,"parms")
|
||||
#define Gettag(x) Getattr(x,"tag")
|
||||
#define Getparent(x) Getattr(x,"parent")
|
||||
|
||||
#define Settype(x,v) Setattr(x,"type",v)
|
||||
#define Setname(x,v) Setattr(x,"name",v)
|
||||
#define Setlname(x,v) Setattr(x,"lname",v)
|
||||
#define Setvalue(x,v) Setattr(x,"value", v)
|
||||
#define Setignore(x,v) SetInt(x,"ignore",v)
|
||||
#define Settag(x,v) Setattr(x,"tag",v)
|
||||
#define Setparms(x,v) Setattr(x,"parms", v)
|
||||
#define Setparent(x,p) Setattr(x,"parent",p)
|
||||
|
||||
#define Getnext(x) Getattr(x,"next")
|
||||
#define Setnext(x,n) Setattr(x,"next",n)
|
||||
#define Getprev(x) Getattr(x,"prev")
|
||||
#define Setprev(x,n) Setattr(x,"prev",n)
|
||||
|
||||
#define Getchild(x) Getattr(x,"child")
|
||||
#define Setchild(x,c) Setattr(x,"child",c)
|
||||
|
||||
extern int Swig_main(int argc, char **argv, char **modules);
|
||||
extern void Swig_exit(int n);
|
||||
/* --- Code fragment support --- */
|
||||
|
||||
extern void Swig_fragment_register(String *name, String *section, String *code);
|
||||
extern void Swig_fragment_emit(String *name);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -717,11 +717,7 @@ extern FILE *Swig_open(DOH *name);
|
|||
extern DOH *Swig_read_file(FILE *file);
|
||||
extern DOH *Swig_include(DOH *name);
|
||||
|
||||
#ifdef MACSWIG
|
||||
#define SWIG_FILE_DELIMETER ":"
|
||||
#else
|
||||
#define SWIG_FILE_DELIMETER "/"
|
||||
#endif
|
||||
|
||||
%section "Command Line Parsing"
|
||||
|
||||
|
|
|
|||
1124
SWIG/Source/Swig/symbol.c
Normal file
1124
SWIG/Source/Swig/symbol.c
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -11,40 +11,19 @@
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#include "swig.h"
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
/* Hash table mapping tag names to handler functions */
|
||||
static Hash *rules = 0;
|
||||
static int debug_emit = 0;
|
||||
char cvsroot_tree_c[] = "$Header$";
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_next()
|
||||
* Swig_prev()
|
||||
*
|
||||
* Return next/prev node in a parse tree
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *Swig_next(DOH *obj) {
|
||||
return Getnext(obj);
|
||||
}
|
||||
|
||||
DOH *Swig_prev(DOH *obj) {
|
||||
return Getprev(obj);
|
||||
}
|
||||
|
||||
void Swig_debug_emit(int n) {
|
||||
debug_emit = n;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_dump_tags()
|
||||
* Swig_print_tags()
|
||||
*
|
||||
* Dump the tag structure of a parse tree to standard output
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_dump_tags(DOH *obj, DOH *root) {
|
||||
Swig_print_tags(DOH *obj, DOH *root) {
|
||||
DOH *croot, *newroot;
|
||||
DOH *cobj;
|
||||
|
||||
|
|
@ -52,22 +31,21 @@ Swig_dump_tags(DOH *obj, DOH *root) {
|
|||
else croot = root;
|
||||
|
||||
while (obj) {
|
||||
Printf(stdout,"%s . %s (%s:%d)\n", croot, Getattr(obj,"tag"), Getfile(obj), Getline(obj));
|
||||
cobj = Getattr(obj,"child");
|
||||
Printf(stdout,"%s . %s (%s:%d)\n", croot, nodeType(obj), Getfile(obj), Getline(obj));
|
||||
cobj = firstChild(obj);
|
||||
if (cobj) {
|
||||
newroot = NewStringf("%s . %s",croot,Getattr(obj,"tag"));
|
||||
Swig_dump_tags(cobj,newroot);
|
||||
newroot = NewStringf("%s . %s",croot,nodeType(obj));
|
||||
Swig_print_tags(cobj,newroot);
|
||||
Delete(newroot);
|
||||
}
|
||||
obj = Swig_next(obj);
|
||||
obj = nextSibling(obj);
|
||||
}
|
||||
if (!root)
|
||||
Delete(croot);
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_dump_tree()
|
||||
* Swig_print_tree()
|
||||
*
|
||||
* Dump the tree structure of a parse tree to standard output
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -85,429 +63,339 @@ static void print_indent(int l) {
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
Swig_dump_tree(DOH *obj) {
|
||||
DOH *k;
|
||||
DOH *cobj;
|
||||
|
||||
while (obj) {
|
||||
print_indent(0);
|
||||
Printf(stdout,"+++ %s ----------------------------------------\n", Getattr(obj,"tag"));
|
||||
|
||||
k = Firstkey(obj);
|
||||
while (k) {
|
||||
if ((Cmp(k,"tag") == 0) || (Cmp(k,"child") == 0) ||
|
||||
(Cmp(k,"parent") == 0) || (Cmp(k,"next") == 0) ||
|
||||
(Cmp(k,"prev") == 0)) {
|
||||
/* Do nothing */
|
||||
} else if (Cmp(k,"parms") == 0) {
|
||||
print_indent(2);
|
||||
Printf(stdout,"%-12s - %s\n", k, ParmList_protostr(Getattr(obj,k)));
|
||||
} else {
|
||||
DOH *o;
|
||||
char *trunc = "";
|
||||
print_indent(2);
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_dump_node(Node *n)
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_print_node(Node *obj) {
|
||||
String *k;
|
||||
Node *cobj;
|
||||
|
||||
print_indent(0);
|
||||
Printf(stdout,"+++ %s ----------------------------------------\n", nodeType(obj));
|
||||
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) {
|
||||
print_indent(2);
|
||||
Printf(stdout,"%-12s - %s\n", k, ParmList_protostr(Getattr(obj,k)));
|
||||
} else {
|
||||
DOH *o;
|
||||
char *trunc = "";
|
||||
print_indent(2);
|
||||
if (DohIsString(Getattr(obj,k))) {
|
||||
o = Str(Getattr(obj,k));
|
||||
if (Len(o) > 40) {
|
||||
trunc = "...";
|
||||
}
|
||||
Printf(stdout,"%-12s - \"%(escape)-0.40s%s\"\n", k, o, trunc);
|
||||
Delete(o);
|
||||
}
|
||||
k = Nextkey(obj);
|
||||
}
|
||||
cobj = Getattr(obj,"child");
|
||||
if (cobj) {
|
||||
indent_level += 6;
|
||||
Printf(stdout,"\n");
|
||||
Swig_dump_tree(cobj);
|
||||
indent_level -= 6;
|
||||
} else {
|
||||
print_indent(1);
|
||||
Printf(stdout,"\n");
|
||||
}
|
||||
obj = Swig_next(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_add_rule()
|
||||
*
|
||||
* Adds a new rule to the tree walking code.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_add_rule(const String_or_char *name, int (*action)(DOH *node, void *clientdata))
|
||||
{
|
||||
if (!rules) rules = NewHash();
|
||||
if (action)
|
||||
Setattr(rules,name,NewVoid((void *) action,0));
|
||||
else
|
||||
Delattr(rules,name);
|
||||
|
||||
if (debug_emit) {
|
||||
Printf(stderr,"Swig_add_rule : '%s' -> %x\n", name, action);
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_add_rules()
|
||||
*
|
||||
* Add a complete set of rules to the rule system
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_add_rules(SwigRule ruleset[]) {
|
||||
int i = 0;
|
||||
while (ruleset[i].name) {
|
||||
Swig_add_rule(ruleset[i].name, ruleset[i].action);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_clear_rules()
|
||||
*
|
||||
* Clears all of the existing rules
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_clear_rules()
|
||||
{
|
||||
if (rules) Delete(rules);
|
||||
rules = NewHash();
|
||||
if (debug_emit) {
|
||||
Printf(stderr,"Swig_clear_rules :\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_dump_rules()
|
||||
*
|
||||
* Print out debugging information for the rules
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_dump_rules() {
|
||||
String *key;
|
||||
Printf(stdout,"SWIG emit rules:::\n");
|
||||
if (!rules) {
|
||||
Printf(stdout," No rules defined.\n");
|
||||
return;
|
||||
}
|
||||
key = Firstkey(rules);
|
||||
while (key) {
|
||||
Printf(stdout," '%-15s' -> %x\n", key, GetVoid(rules,key));
|
||||
key = Nextkey(rules);
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_tag_check()
|
||||
*
|
||||
* Checks the tag name of an object taking into account namespace issues.
|
||||
* For example, a check of "function" will match any object with a tag
|
||||
* of the form "xxx:function" whereas a check of "c:function" will check
|
||||
* for a more exact match. Returns 1 if a match is found, 0 otherwise
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
Swig_tag_check(DOH *obj, const String_or_char *tagname) {
|
||||
String *tag;
|
||||
char *tc;
|
||||
char *tnc;
|
||||
tag = Getattr(obj,"tag");
|
||||
assert(tag);
|
||||
|
||||
tnc = Char(tag);
|
||||
tc = Char(tagname);
|
||||
|
||||
while (tnc) {
|
||||
if (strcmp(tc,tnc) == 0) return 1;
|
||||
tnc = strchr(tnc,':');
|
||||
if (tnc) tnc++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_set_callback()
|
||||
*
|
||||
* Sets a parser callback function for a node.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
Swig_set_callback(DOH *obj, void (*cb)(void *clientdata), void *clientdata) {
|
||||
SetVoid(obj,"-callback-",(void *)cb);
|
||||
if (clientdata)
|
||||
SetVoid(obj,"-callbackarg-", clientdata);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_set_trace()
|
||||
*
|
||||
* Sets a tracing function on a parse tree node. Returns the old tracing
|
||||
* function (if any).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void (*Swig_set_trace(DOH *obj, void (*cb)(DOH *, DOH *), DOH *arg))(DOH *, DOH *) {
|
||||
void (*old)(DOH *,DOH *);
|
||||
old = (void (*)(DOH *, DOH *)) GetVoid(obj,"-trace-");
|
||||
SetVoid(obj,"-trace-", (void *) cb);
|
||||
if (arg)
|
||||
Setattr(obj,"-tracearg-", arg);
|
||||
return old;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_remove_trace()
|
||||
*
|
||||
* Removes the tracing function from a parse tree node
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_remove_trace(DOH *obj) {
|
||||
Delattr(obj,"-trace-");
|
||||
Delattr(obj,"-tracearg-");
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_node_temporary()
|
||||
*
|
||||
* Sets a node as being temporary (deleted immediately after it is emitted)
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_node_temporary(DOH *obj) {
|
||||
SetInt(obj,"-temp-",1);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_node_ignore()
|
||||
*
|
||||
* Causes a node to be ignored
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_node_ignore(DOH *obj) {
|
||||
SetInt(obj,"-ignore-",1);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int Swig_emit()
|
||||
*
|
||||
* This function calls the handler function (if any) for an object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
Swig_emit(DOH *obj, void *clientdata) {
|
||||
DOH *tag;
|
||||
DOH *actionobj;
|
||||
char *tc;
|
||||
int (*action)(DOH *obj, void *clientdata);
|
||||
void (*callback)(void *clientdata);
|
||||
void (*tracefunc)(DOH *obj, DOH *arg);
|
||||
int ret;
|
||||
|
||||
assert(obj);
|
||||
|
||||
if (!rules) {
|
||||
Printf(stderr,"No rules defined in Swig_emit()!\n");
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
if (obj) {
|
||||
if (Getattr(obj,"-ignore-")) return SWIG_OK;
|
||||
tag = Getattr(obj,"tag");
|
||||
assert(tag);
|
||||
tc = Char(tag);
|
||||
while(tc) {
|
||||
actionobj = Getattr(rules,tc);
|
||||
if (actionobj) {
|
||||
if (debug_emit) {
|
||||
Printf(stderr,"Swig_emit : Matched tag '%s' -> rule '%s'\n", tag, tc);
|
||||
}
|
||||
/* Check for user tracing -- traces occur before any handlers are called */
|
||||
tracefunc = (void (*)(DOH *, DOH *)) GetVoid(obj,"-trace-");
|
||||
if (tracefunc) {
|
||||
DOH *tobj = Getattr(obj,"-tracearg-");
|
||||
(*tracefunc)(obj,tobj);
|
||||
}
|
||||
action = (int (*)(DOH *, void *)) Data(actionobj);
|
||||
ret = (*action)(obj,clientdata);
|
||||
/* Check for a parser callback */
|
||||
callback = (void (*)(void *clientdata)) GetVoid(obj,"-callback-");
|
||||
if (callback) {
|
||||
void *cbarg;
|
||||
cbarg = GetVoid(obj,"-callbackarg-");
|
||||
(*callback)(cbarg);
|
||||
Delattr(obj,"-callback-");
|
||||
Delattr(obj,"-callbackarg-");
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
tc = strchr(tc,':');
|
||||
if (tc) tc++;
|
||||
Printf(stdout,"%-12s - 0x%x\n", k, Getattr(obj,k));
|
||||
}
|
||||
}
|
||||
actionobj = Getattr(rules,"*");
|
||||
if (actionobj) {
|
||||
if (debug_emit) {
|
||||
Printf(stderr,"Swig_emit : Matched tag '%s' -> rule '*'\n", tag);
|
||||
}
|
||||
/* Check for user tracing -- traces occur before any handlers are called */
|
||||
tracefunc = (void (*)(DOH *, DOH *)) GetVoid(obj,"-trace-");
|
||||
if (tracefunc) {
|
||||
DOH *tobj = Getattr(obj,"-tracearg-");
|
||||
(*tracefunc)(obj,tobj);
|
||||
}
|
||||
action = (int (*)(DOH *, void *)) Data(actionobj);
|
||||
ret = (*action)(obj,clientdata);
|
||||
/* Check for a parser callback */
|
||||
callback = (void (*)(void *clientdata)) GetVoid(obj,"-callback-");
|
||||
if (callback) {
|
||||
void *cbarg;
|
||||
cbarg = GetVoid(obj,"-callbackarg-");
|
||||
(*callback)(cbarg);
|
||||
Delattr(obj,"-callback-");
|
||||
Delattr(obj,"-callbackarg-");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
if (debug_emit) {
|
||||
Printf(stderr,"Swig_emit : No rule defined for tag '%s'\n", tag);
|
||||
}
|
||||
k = Nextkey(obj);
|
||||
}
|
||||
cobj = firstChild(obj);
|
||||
if (cobj) {
|
||||
indent_level += 6;
|
||||
Printf(stdout,"\n");
|
||||
Swig_print_tree(cobj);
|
||||
indent_level -= 6;
|
||||
} else {
|
||||
print_indent(1);
|
||||
Printf(stdout,"\n");
|
||||
}
|
||||
return SWIG_NORULE;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_emit_all()
|
||||
*
|
||||
* Emit all of the nodes at this level.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
Swig_emit_all(DOH *obj, void *clientdata) {
|
||||
int ret;
|
||||
void
|
||||
Swig_print_tree(DOH *obj) {
|
||||
while (obj) {
|
||||
ret = Swig_emit(obj,clientdata);
|
||||
if (ret < 0) return ret;
|
||||
obj = Swig_next(obj);
|
||||
Swig_print_node(obj);
|
||||
obj = nextSibling(obj);
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_node_cut()
|
||||
*
|
||||
* This function cuts an object out of a parse tree. To do this, the object
|
||||
* MUST be properly initialized with "next", "prev", and "parent" attributes.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_node_cut(DOH *obj) {
|
||||
DOH *parent;
|
||||
DOH *next;
|
||||
DOH *prev;
|
||||
|
||||
parent = Getattr(obj,"parent");
|
||||
assert(parent);
|
||||
next = Getattr(obj,"next");
|
||||
prev = Getattr(obj,"prev");
|
||||
|
||||
DohIncref(obj); /* Make sure object doesn't go away */
|
||||
Delattr(obj,"parent"); /* Disassociate from my parent */
|
||||
|
||||
if (!next && !prev) {
|
||||
/* Well, this is a single child. Guess we'll just tell the parent that their child is gone */
|
||||
Delattr(parent,"child");
|
||||
return;
|
||||
}
|
||||
|
||||
/* If no next node, then this must be at the end of a list */
|
||||
if (!next) {
|
||||
Delattr(prev,"next"); /* Break the 'next' link in the previous node */
|
||||
Delattr(obj,"prev"); /* Break my link back to the previous object */
|
||||
return;
|
||||
}
|
||||
|
||||
/* No previous node. This must be the beginning of a list */
|
||||
if (!prev) {
|
||||
Delattr(next,"prev"); /* Break the 'prev' link of the next node */
|
||||
Setattr(parent,"child",next); /* Update parent to point at next node */
|
||||
Delattr(obj,"next"); /* Break my link to the next object */
|
||||
return;
|
||||
}
|
||||
|
||||
/* In the middle of a list someplace */
|
||||
Setattr(prev,"next",next); /* Update previous node to my next node */
|
||||
Setattr(next,"prev",prev); /* Update next node to my previous node */
|
||||
Delattr(obj,"next");
|
||||
Delattr(obj,"prev");
|
||||
return;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_node_insert()
|
||||
*
|
||||
* Inserts a node after a given node. The node to be inserted should be
|
||||
* isolated (no parent, no siblings, etc...).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_node_insert(DOH *node, DOH *newnode) {
|
||||
DOH *next;
|
||||
next = Getattr(node,"next");
|
||||
|
||||
if (next) {
|
||||
Setattr(newnode,"next", next);
|
||||
Setattr(next,"prev", newnode);
|
||||
}
|
||||
Setattr(node,"next",newnode);
|
||||
Setattr(newnode,"prev", node);
|
||||
Setattr(newnode,"parent", Getattr(node,"parent"));
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_node_append_child()
|
||||
* appendChild()
|
||||
*
|
||||
* Appends a new child to a node
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_node_append_child(DOH *node, DOH *chd) {
|
||||
DOH *c;
|
||||
DOH *pc;
|
||||
c = Getattr(node,"child");
|
||||
if (!c) {
|
||||
Setattr(node,"child",chd);
|
||||
Setattr(chd,"parent",node);
|
||||
return;
|
||||
appendChild(Node *node, Node *chd) {
|
||||
Node *lc;
|
||||
|
||||
if (!chd) return;
|
||||
|
||||
lc = lastChild(node);
|
||||
if (!lc) {
|
||||
set_firstChild(node,chd);
|
||||
} else {
|
||||
set_nextSibling(lc,chd);
|
||||
set_previousSibling(chd,lc);
|
||||
}
|
||||
while (c) {
|
||||
pc = c;
|
||||
c = Getnext(c);
|
||||
while (chd) {
|
||||
lc = chd;
|
||||
set_parentNode(chd,node);
|
||||
chd = nextSibling(chd);
|
||||
}
|
||||
Setattr(pc,"next",chd);
|
||||
Setattr(chd,"prev",pc);
|
||||
Setattr(chd,"parent",node);
|
||||
set_lastChild(node,lc);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_count_nodes()
|
||||
* deleteNode()
|
||||
*
|
||||
* Count number of nodes at this level
|
||||
* Deletes a node.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int Swig_count_nodes(DOH *node) {
|
||||
int n = 0;
|
||||
while (node) {
|
||||
n++;
|
||||
node = Getnext(node);
|
||||
void
|
||||
deleteNode(Node *n) {
|
||||
Node *parent;
|
||||
Node *prev;
|
||||
Node *next;
|
||||
|
||||
parent = parentNode(n);
|
||||
prev = previousSibling(n);
|
||||
next = nextSibling(n);
|
||||
if (prev) {
|
||||
set_nextSibling(prev,next);
|
||||
} else {
|
||||
if (parent) {
|
||||
set_firstChild(parent,next);
|
||||
}
|
||||
}
|
||||
if (next) {
|
||||
set_previousSibling(next,prev);
|
||||
} else {
|
||||
if (parent) {
|
||||
set_lastChild(parent,prev);
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* copyNode()
|
||||
*
|
||||
* Copies a node, but only copies simple attributes (no lists, hashes).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
Node *
|
||||
copyNode(Node *n) {
|
||||
String *key;
|
||||
DOH *v;
|
||||
Node *c = NewHash();
|
||||
for (key = Firstkey(n); key; key = Nextkey(n)) {
|
||||
v = Getattr(n,key);
|
||||
if (DohIsString(v)) {
|
||||
Setattr(c,key,Copy(v));
|
||||
}
|
||||
}
|
||||
Setfile(c,Getfile(n));
|
||||
Setline(c,Getline(n));
|
||||
return c;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_tag_nodes()
|
||||
*
|
||||
* Tags a collection of nodes with an attribute. Used by the parser to mark
|
||||
* subtypes with extra information.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_tag_nodes(Node *n, const String_or_char *attrname, DOH *value) {
|
||||
while (n) {
|
||||
Setattr(n,attrname,value);
|
||||
Swig_tag_nodes(firstChild(n),attrname, value);
|
||||
n = nextSibling(n);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) {
|
||||
String *v;
|
||||
v = Getattr(n,name);
|
||||
if (!v) return 0;
|
||||
if (Cmp(v,value) == 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_require()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#define MAX_SWIG_STACK 256
|
||||
static Hash *attr_stack[MAX_SWIG_STACK];
|
||||
static Node **nodeptr_stack[MAX_SWIG_STACK];
|
||||
static Node *node_stack[MAX_SWIG_STACK];
|
||||
static int stackp = 0;
|
||||
static int stack_direction = 0;
|
||||
|
||||
static void set_direction(int n, int *x) {
|
||||
if (n == 1) {
|
||||
set_direction(0,&n);
|
||||
} else {
|
||||
if (&n < x) {
|
||||
stack_direction = -1; /* Stack grows down */
|
||||
} else {
|
||||
stack_direction = 1; /* Stack grows up */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Swig_require(Node **nptr, ...) {
|
||||
va_list ap;
|
||||
char *name;
|
||||
DOH *obj;
|
||||
DOH *frame = 0;
|
||||
Node *n = *nptr;
|
||||
va_start(ap, nptr);
|
||||
name = va_arg(ap, char *);
|
||||
while (name) {
|
||||
int newref = 0;
|
||||
int opt = 0;
|
||||
if (*name == '*') {
|
||||
newref = 1;
|
||||
name++;
|
||||
} else if (*name == '?') {
|
||||
newref = 1;
|
||||
opt = 1;
|
||||
name++;
|
||||
}
|
||||
obj = Getattr(n,name);
|
||||
if (!opt && !obj) {
|
||||
Printf(stderr,"%s:%d. Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n",
|
||||
Getfile(n), Getline(n), name, nodeType(n));
|
||||
assert(obj);
|
||||
}
|
||||
if (!obj) obj = DohNone;
|
||||
if (newref) {
|
||||
if (!attr_stack[stackp]) {
|
||||
attr_stack[stackp]= NewHash();
|
||||
}
|
||||
frame = attr_stack[stackp];
|
||||
if (Setattr(frame,name,obj)) {
|
||||
Printf(stderr,"Swig_require('%s'): Warning, attribute '%s' was already saved.\n", nodeType(n), name);
|
||||
}
|
||||
}
|
||||
name = va_arg(ap, char *);
|
||||
}
|
||||
va_end(ap);
|
||||
if (frame) {
|
||||
/* This is a sanity check to make sure no one is saving data, but not restoring it */
|
||||
if (stackp > 0) {
|
||||
int e = 0;
|
||||
if (!stack_direction) set_direction(1,0);
|
||||
|
||||
if (stack_direction < 0) {
|
||||
if ((((char *) nptr) >= ((char *) nodeptr_stack[stackp-1])) && (n != node_stack[stackp-1])) e = 1;
|
||||
} else {
|
||||
if ((((char *) nptr) <= ((char *) nodeptr_stack[stackp-1])) && (n != node_stack[stackp-1])) e = 1;
|
||||
}
|
||||
if (e) {
|
||||
Printf(stderr,
|
||||
"Swig_require('%s'): Fatal memory management error. If you are seeing this\n\
|
||||
message. It means that the target language module is not managing its memory\n\
|
||||
correctly. A handler for '%s' probably forgot to call Swig_restore().\n\
|
||||
Please report this problem to swig-dev@cs.uchicago.edu.\n", nodeType(n), nodeType(node_stack[stackp-1]));
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
nodeptr_stack[stackp] = nptr;
|
||||
node_stack[stackp] = n;
|
||||
stackp++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
Swig_save(Node **nptr, ...) {
|
||||
va_list ap;
|
||||
char *name;
|
||||
DOH *obj;
|
||||
DOH *frame;
|
||||
Node *n = *nptr;
|
||||
|
||||
if ((stackp > 0) && (nodeptr_stack[stackp-1] == nptr)) {
|
||||
frame = attr_stack[stackp-1];
|
||||
} else {
|
||||
if (stackp > 0) {
|
||||
int e = 0;
|
||||
if (!stack_direction) set_direction(1,0);
|
||||
if (stack_direction < 0) {
|
||||
if ((((char *) nptr) >= ((char *) nodeptr_stack[stackp-1])) && (n != node_stack[stackp-1])) e = 1;
|
||||
} else {
|
||||
if ((((char *) nptr) <= ((char *) nodeptr_stack[stackp-1])) && (n != node_stack[stackp-1])) e = 1;
|
||||
}
|
||||
if (e) {
|
||||
Printf(stderr,
|
||||
"Swig_save('%s'): Fatal memory management error. If you are seeing this\n\
|
||||
message. It means that the target language module is not managing its memory\n\
|
||||
correctly. A handler for '%s' probably forgot to call Swig_restore().\n\
|
||||
Please report this problem to swig-dev@cs.uchicago.edu.\n", nodeType(n), nodeType(node_stack[stackp-1]));
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
attr_stack[stackp] = NewHash();
|
||||
nodeptr_stack[stackp] = nptr;
|
||||
node_stack[stackp] = n;
|
||||
frame = attr_stack[stackp];
|
||||
stackp++;
|
||||
}
|
||||
va_start(ap, nptr);
|
||||
name = va_arg(ap, char *);
|
||||
while (name) {
|
||||
if (*name == '*') {
|
||||
name++;
|
||||
} else if (*name == '?') {
|
||||
name++;
|
||||
}
|
||||
obj = Getattr(n,name);
|
||||
if (!obj) {
|
||||
obj = DohNone;
|
||||
}
|
||||
if (Setattr(frame,name,obj)) {
|
||||
Printf(stderr,"Swig_save('%s'): Warning, attribute '%s' was already saved.\n", nodeType(n), name);
|
||||
}
|
||||
name = va_arg(ap, char *);
|
||||
}
|
||||
va_end(ap);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
Swig_restore(Node **nptr) {
|
||||
String *key;
|
||||
Hash *frame;
|
||||
Node *n = *nptr;
|
||||
assert(stackp > 0);
|
||||
if (!(nptr==nodeptr_stack[stackp-1])) {
|
||||
Printf(stderr,
|
||||
"Swig_restore('%s'): Fatal memory management error. If you are seeing this\n\
|
||||
message. It means that the target language module is not managing its memory\n\
|
||||
correctly. A handler for '%s' probably forgot to call Swig_restore().\n\
|
||||
Please report this problem to swig-dev@cs.uchicago.edu.\n", nodeType(n), nodeType(node_stack[stackp-1]));
|
||||
assert(0);
|
||||
}
|
||||
stackp--;
|
||||
frame = attr_stack[stackp];
|
||||
nodeptr_stack[stackp] = 0;
|
||||
node_stack[stackp] = 0;
|
||||
for (key = Firstkey(frame); key; key = Nextkey(frame)) {
|
||||
DOH *obj = Getattr(frame,key);
|
||||
if (obj != DohNone) {
|
||||
Setattr(n,key,obj);
|
||||
} else {
|
||||
Delattr(n,key);
|
||||
}
|
||||
Delattr(frame,key);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
1609
SWIG/Source/Swig/typesys.c
Normal file
1609
SWIG/Source/Swig/typesys.c
Normal file
File diff suppressed because it is too large
Load diff
42
SWIG/Source/Swig/warn.c
Normal file
42
SWIG/Source/Swig/warn.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* warn.c
|
||||
*
|
||||
* SWIG warning framework. This was added to warn developers about
|
||||
* deprecated APIs and other features.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2001. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char cvsroot_warn_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
static Hash *warnings = 0;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_warn()
|
||||
*
|
||||
* Issue a warning
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_warn(const char *filename, int line, const char *msg) {
|
||||
String *key;
|
||||
if (!warnings) {
|
||||
warnings = NewHash();
|
||||
}
|
||||
key = NewStringf("%s:%d", filename,line);
|
||||
if (!Getattr(warnings,key)) {
|
||||
Printf(stderr,"swig-dev warning:%s:%d:%s\n", filename, line, msg);
|
||||
Setattr(warnings,key,key);
|
||||
}
|
||||
Delete(key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,30 +14,41 @@
|
|||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
char cvsroot_wrapfunc_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
#include <ctype.h>
|
||||
|
||||
#include "dohobj.h"
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewWrapper()
|
||||
*
|
||||
* Create a new wrapper function object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct {
|
||||
Hash *attr; /* Attributes */
|
||||
Hash *localh; /* Hash of local variable names */
|
||||
String *code; /* Code string */
|
||||
} WrapObj;
|
||||
Wrapper *
|
||||
NewWrapper() {
|
||||
Wrapper *w;
|
||||
w = (Wrapper *) malloc(sizeof(Wrapper));
|
||||
w->localh = NewHash();
|
||||
w->locals = NewString("");
|
||||
w->code = NewString("");
|
||||
w->def = NewString("");
|
||||
return w;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DelWrapper()
|
||||
*
|
||||
* Delete a wrapper function object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
DelWrapper(DOH *wo) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
void
|
||||
DelWrapper(Wrapper *w) {
|
||||
Delete(w->localh);
|
||||
Delete(w->locals);
|
||||
Delete(w->code);
|
||||
Delete(w->attr);
|
||||
DohFree(w);
|
||||
Delete(w->def);
|
||||
free(w);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -108,6 +119,35 @@ Wrapper_pretty_print(String *str, File *f) {
|
|||
Printf(f,"%s",ts);
|
||||
Clear(ts);
|
||||
empty = 1;
|
||||
} else if (c == '/') {
|
||||
Putc(c,ts);
|
||||
c = Getc(str);
|
||||
if (c != EOF) {
|
||||
Putc(c,ts);
|
||||
if (c == '/') { /* C++ comment */
|
||||
while ((c = Getc(str)) != EOF) {
|
||||
if (c == '\n') {
|
||||
Ungetc(c,str);
|
||||
break;
|
||||
}
|
||||
Putc(c,ts);
|
||||
}
|
||||
} else if (c == '*') { /* C comment */
|
||||
int endstar = 0;
|
||||
while ((c = Getc(str)) != EOF) {
|
||||
if (endstar && c == '/') { /* end of C comment */
|
||||
Putc(c,ts);
|
||||
break;
|
||||
}
|
||||
endstar = (c == '*');
|
||||
Putc(c,ts);
|
||||
if (c == '\n') { /* multi-line C comment. Could be improved slightly. */
|
||||
for (i = 0; i < level; i++)
|
||||
Putc(' ',ts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!empty || !isspace(c)) {
|
||||
Putc(c,ts);
|
||||
|
|
@ -122,39 +162,20 @@ Wrapper_pretty_print(String *str, File *f) {
|
|||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Wrapper_str()
|
||||
* Wrapper_print()
|
||||
*
|
||||
* Create a string representation of the wrapper function.
|
||||
* Print out a wrapper function. Does pretty printing as well.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static String *
|
||||
Wrapper_str(DOH *wo) {
|
||||
String *s, *s1;
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
s = NewString(w->code);
|
||||
s1 = NewString("");
|
||||
void
|
||||
Wrapper_print(Wrapper *w, File *f) {
|
||||
String *str;
|
||||
|
||||
/* Replace the first '{' with a brace followed by local variable definitions */
|
||||
Replace(s,"{", Getattr(w->attr,"locals"), DOH_REPLACE_FIRST);
|
||||
Wrapper_pretty_print(s,s1);
|
||||
Delete(s);
|
||||
return s1;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Wrapper_dump()
|
||||
*
|
||||
* Serialize on out
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
Wrapper_dump(DOH *wo, DOH *out) {
|
||||
String *s;
|
||||
int len;
|
||||
s = Wrapper_str(wo);
|
||||
len = Dump(s,out);
|
||||
Delete(s);
|
||||
return len;
|
||||
str = NewString("");
|
||||
Printf(str,"%s\n", w->def);
|
||||
Printf(str,"%s\n", w->locals);
|
||||
Printf(str,"%s\n", w->code);
|
||||
Wrapper_pretty_print(str,f);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -165,14 +186,13 @@ Wrapper_dump(DOH *wo, DOH *out) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
Wrapper_add_local(Wrapper *wo, const String_or_char *name, const String_or_char *decl) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) {
|
||||
/* See if the local has already been declared */
|
||||
if (Getattr(w->localh,name)) {
|
||||
return -1;
|
||||
}
|
||||
Setattr(w->localh,name,decl);
|
||||
Printf(Getattr(w->attr,"locals"),"%s;\n", decl);
|
||||
Printf(w->locals,"%s;\n", decl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -185,24 +205,23 @@ Wrapper_add_local(Wrapper *wo, const String_or_char *name, const String_or_char
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
Wrapper_add_localv(Wrapper *wo, const String_or_char *name, ...) {
|
||||
Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) {
|
||||
va_list ap;
|
||||
int ret;
|
||||
String *decl;
|
||||
DOH *obj;
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
decl = NewString("");
|
||||
va_start(ap,name);
|
||||
|
||||
obj = va_arg(ap,void *);
|
||||
while (obj) {
|
||||
Printv(decl,obj,0);
|
||||
Printv(decl,obj,NIL);
|
||||
Putc(' ', decl);
|
||||
obj = va_arg(ap, void *);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
ret = Wrapper_add_local(wo,name,decl);
|
||||
ret = Wrapper_add_local(w,name,decl);
|
||||
Delete(decl);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -214,8 +233,7 @@ Wrapper_add_localv(Wrapper *wo, const String_or_char *name, ...) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
Wrapper_check_local(Wrapper *wo, const String_or_char *name) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
Wrapper_check_local(Wrapper *w, const String_or_char *name) {
|
||||
if (Getattr(w->localh,name)) {
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -230,22 +248,22 @@ Wrapper_check_local(Wrapper *wo, const String_or_char *name) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
Wrapper_new_local(Wrapper *wo, const String_or_char *name, const String_or_char *decl) {
|
||||
Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) {
|
||||
int i;
|
||||
char *ret;
|
||||
String *nname = NewString(name);
|
||||
String *ndecl = NewString(decl);
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
char *ret;
|
||||
|
||||
i = 0;
|
||||
|
||||
while (Wrapper_check_local(wo,nname)) {
|
||||
while (Wrapper_check_local(w,nname)) {
|
||||
Clear(nname);
|
||||
Printf(nname,"%s%d",name,i);
|
||||
i++;
|
||||
}
|
||||
Replace(ndecl, name, nname, DOH_REPLACE_ID);
|
||||
Setattr(w->localh,nname,ndecl);
|
||||
Printf(Getattr(w->attr,"locals"),"%s;\n", ndecl);
|
||||
Printf(w->locals,"%s;\n", ndecl);
|
||||
ret = Char(nname);
|
||||
Delete(nname);
|
||||
Delete(ndecl);
|
||||
|
|
@ -262,205 +280,29 @@ Wrapper_new_local(Wrapper *wo, const String_or_char *name, const String_or_char
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
Wrapper_new_localv(Wrapper *wo, const String_or_char *name, ...) {
|
||||
Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...) {
|
||||
va_list ap;
|
||||
char *ret;
|
||||
String *decl;
|
||||
DOH *obj;
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
decl = NewString("");
|
||||
va_start(ap,name);
|
||||
|
||||
obj = va_arg(ap,void *);
|
||||
while (obj) {
|
||||
Printv(decl,obj,0);
|
||||
Printv(decl,obj,NIL);
|
||||
Putc(' ',decl);
|
||||
obj = va_arg(ap, void *);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
ret = Wrapper_new_local(wo,name,decl);
|
||||
ret = Wrapper_new_local(w,name,decl);
|
||||
Delete(decl);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Wrapper_Getattr()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
Wrapper_getattr(Wrapper *wo, DOH *k) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Getattr(w->attr,k);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Wrapper_Delattr()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
Wrapper_delattr(Wrapper *wo, DOH *k) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
Delattr(w->attr,k);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Wrapper_Setattr()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
Wrapper_setattr(Wrapper *wo, DOH *k, DOH *obj) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Setattr(w->attr,k,obj);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Wrapper_firstkey()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
Wrapper_firstkey(Wrapper *wo) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Firstkey(w->attr);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Wrapper_firstkey()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
Wrapper_nextkey(Wrapper *wo) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Nextkey(w->attr);
|
||||
}
|
||||
|
||||
/* File methods. These simply operate on the code string */
|
||||
|
||||
static int
|
||||
Wrapper_read(Wrapper *wo, void *buffer, int nbytes) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Read(w->code,buffer,nbytes);
|
||||
}
|
||||
|
||||
static int
|
||||
Wrapper_write(Wrapper *wo, void *buffer, int nbytes) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Write(w->code,buffer,nbytes);
|
||||
}
|
||||
|
||||
static int
|
||||
Wrapper_putc(Wrapper *wo, int ch) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Putc(ch, w->code);
|
||||
}
|
||||
|
||||
static int
|
||||
Wrapper_getc(Wrapper *wo) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Getc(w->code);
|
||||
}
|
||||
|
||||
static int
|
||||
Wrapper_ungetc(Wrapper *wo, int ch) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Ungetc(ch, w->code);
|
||||
}
|
||||
|
||||
static int
|
||||
Wrapper_seek(Wrapper *wo, long offset, int whence) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Seek(w->code, offset, whence);
|
||||
}
|
||||
|
||||
static long
|
||||
Wrapper_tell(Wrapper *wo) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Tell(w->code);
|
||||
}
|
||||
|
||||
/* String method */
|
||||
|
||||
static int Wrapper_replace(DOH *wo, DOH *tok, DOH *rep, int flags) {
|
||||
WrapObj *w = (WrapObj *) ObjData(wo);
|
||||
return Replace(w->code, tok, rep, flags);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* type information
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DohHashMethods WrapperHashMethods = {
|
||||
Wrapper_getattr,
|
||||
Wrapper_setattr,
|
||||
Wrapper_delattr,
|
||||
Wrapper_firstkey,
|
||||
Wrapper_nextkey,
|
||||
};
|
||||
|
||||
static DohFileMethods WrapperFileMethods = {
|
||||
Wrapper_read,
|
||||
Wrapper_write,
|
||||
Wrapper_putc,
|
||||
Wrapper_getc,
|
||||
Wrapper_ungetc,
|
||||
Wrapper_seek,
|
||||
Wrapper_tell,
|
||||
0, /* close */
|
||||
};
|
||||
|
||||
static DohStringMethods WrapperStringMethods = {
|
||||
Wrapper_replace,
|
||||
0,
|
||||
};
|
||||
|
||||
static DohObjInfo WrapperType = {
|
||||
"Wrapper", /* objname */
|
||||
DelWrapper, /* doh_del */
|
||||
0, /* doh_copy */
|
||||
0, /* doh_clear */
|
||||
Wrapper_str, /* doh_str */
|
||||
0, /* doh_data */
|
||||
0, /* doh_dump */
|
||||
0, /* doh_len */
|
||||
0, /* doh_hash */
|
||||
0, /* doh_cmp */
|
||||
0, /* doh_setfile */
|
||||
0, /* doh_getfile */
|
||||
0, /* doh_setline */
|
||||
0, /* doh_getline */
|
||||
&WrapperHashMethods, /* doh_mapping */
|
||||
0, /* doh_sequence */
|
||||
&WrapperFileMethods, /* doh_file */
|
||||
&WrapperStringMethods, /* doh_string */
|
||||
0, /* doh_positional */
|
||||
0,
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewWrapper()
|
||||
*
|
||||
* Create a new wrapper function object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#define DOHTYPE_WRAPPER 0xa
|
||||
|
||||
Wrapper *
|
||||
NewWrapper() {
|
||||
WrapObj *w;
|
||||
static int init = 0;
|
||||
if (!init) {
|
||||
DohRegisterType(DOHTYPE_WRAPPER, &WrapperType);
|
||||
init = 1;
|
||||
}
|
||||
w = (WrapObj *) DohMalloc(sizeof(WrapObj));
|
||||
w->localh = NewHash();
|
||||
w->code = NewString("");
|
||||
w->attr= NewHash();
|
||||
Setattr(w->attr,"locals","{\n");
|
||||
Setattr(w->attr,"wrapcode", w->code);
|
||||
return DohObjMalloc(DOHTYPE_WRAPPER, w);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue