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:
Dave Beazley 2002-11-30 22:01:28 +00:00
commit 516036631c
1508 changed files with 125983 additions and 44037 deletions

View file

@ -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
View 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;
}

View 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);
}
}

View file

@ -18,7 +18,7 @@
* Should have cleaner error handling in general.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
char cvsroot_getopt_c[] = "$Header$";
#include "swig.h"

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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

View file

@ -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

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

File diff suppressed because it is too large Load diff

42
SWIG/Source/Swig/warn.c Normal file
View 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);
}

View file

@ -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);
}