beautify/format source code with gnu indent

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9505 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2006-11-01 23:54:54 +00:00
parent 5364d135c7
commit aa04c4c057
72 changed files with 27038 additions and 28016 deletions

View File

@ -20,55 +20,51 @@ extern "C" {
#endif
/* cscanner.c */
extern char *cparse_file;
extern int cparse_line;
extern int cparse_cplusplus;
extern int cparse_start_line;
extern char *cparse_file;
extern int cparse_line;
extern int cparse_cplusplus;
extern int cparse_start_line;
extern void Swig_cparse_cplusplus(int);
extern void scanner_file(File *);
extern void scanner_next_token(int);
extern void skip_balanced(int startchar, int endchar);
extern void skip_decl(void);
extern void scanner_check_typedef(void);
extern void scanner_ignore_typedef(void);
extern void scanner_last_id(int);
extern void scanner_clear_rename(void);
extern void start_inline(char *, int);
extern String *scanner_ccode;
extern int yylex();
extern void Swig_cparse_cplusplus(int);
extern void scanner_file(File *);
extern void scanner_next_token(int);
extern void skip_balanced(int startchar, int endchar);
extern void skip_decl(void);
extern void scanner_check_typedef(void);
extern void scanner_ignore_typedef(void);
extern void scanner_last_id(int);
extern void scanner_clear_rename(void);
extern void start_inline(char *, int);
extern String *scanner_ccode;
extern int yylex();
/* parser.y */
extern SwigType *Swig_cparse_type(String *);
extern Node *Swig_cparse(File *);
extern Hash *Swig_cparse_features();
extern void SWIG_cparse_set_compact_default_args(int defargs);
extern int SWIG_cparse_template_reduce(int treduce);
extern SwigType *Swig_cparse_type(String *);
extern Node *Swig_cparse(File *);
extern Hash *Swig_cparse_features();
extern void SWIG_cparse_set_compact_default_args(int defargs);
extern int SWIG_cparse_template_reduce(int treduce);
/* util.c */
extern void Swig_cparse_replace_descriptor(String *s);
extern void cparse_normalize_void(Node *);
extern Parm *Swig_cparse_parm(String *s);
extern ParmList *Swig_cparse_parms(String *s);
extern void Swig_cparse_replace_descriptor(String *s);
extern void cparse_normalize_void(Node *);
extern Parm *Swig_cparse_parm(String *s);
extern ParmList *Swig_cparse_parms(String *s);
/* templ.c */
extern int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope);
extern Node *Swig_cparse_template_locate(String *name, ParmList *tparms, Symtab *tscope);
extern void Swig_cparse_debug_templates(int);
extern int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope);
extern Node *Swig_cparse_template_locate(String *name, ParmList *tparms, Symtab *tscope);
extern void Swig_cparse_debug_templates(int);
#ifdef __cplusplus
}
#endif
#define SWIG_WARN_NODE_BEGIN(Node) \
{ \
String *wrnfilter = Node ? Getattr(Node,"feature:warnfilter") : 0; \
if (wrnfilter) Swig_warnfilter(wrnfilter,1)
if (wrnfilter) Swig_warnfilter(wrnfilter,1)
#define SWIG_WARN_NODE_END(Node) \
if (wrnfilter) Swig_warnfilter(wrnfilter,0); \
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -18,8 +18,7 @@ static int template_debug = 0;
String *baselists[3];
void SwigType_template_init()
{
void SwigType_template_init() {
baselists[0] = k_baselist;
baselists[1] = k_protectedbaselist;
baselists[2] = k_privatebaselist;
@ -28,17 +27,17 @@ void SwigType_template_init()
static void add_parms(ParmList *p, List *patchlist, List *typelist) {
while (p) {
SwigType *ty = Getattr(p,k_type);
SwigType *val = Getattr(p,k_value);
Append(typelist,ty);
Append(typelist,val);
Append(patchlist,val);
SwigType *ty = Getattr(p, k_type);
SwigType *val = Getattr(p, k_value);
Append(typelist, ty);
Append(typelist, val);
Append(patchlist, val);
p = nextSibling(p);
}
}
void Swig_cparse_debug_templates(int x) {
template_debug = x;
template_debug = x;
}
/* -----------------------------------------------------------------------------
@ -49,69 +48,70 @@ void Swig_cparse_debug_templates(int x) {
* template parameters
* ----------------------------------------------------------------------------- */
static int
cparse_template_expand(Node *n, String *tname, String *rname, String *templateargs, List *patchlist, List *typelist, List *cpatchlist) {
static int cparse_template_expand(Node *n, String *tname, String *rname, String *templateargs, List *patchlist, List *typelist, List *cpatchlist) {
static int expanded = 0;
int ret;
String *nodeType = Getattr(n,k_nodetype);
if (!n) return 0;
if (Getattr(n,k_error)) return 0;
String *nodeType = Getattr(n, k_nodetype);
if (!n)
return 0;
if (Getattr(n, k_error))
return 0;
if (StringEqual(nodeType,k_template)) {
if (StringEqual(nodeType, k_template)) {
/* Change the node type back to normal */
if (!expanded) {
expanded = 1;
Setattr(n,k_nodetype,Getattr(n,k_templatetype));
ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist);
Setattr(n, k_nodetype, Getattr(n, k_templatetype));
ret = cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist);
expanded = 0;
return ret;
} else {
/* Called when template appears inside another template */
/* Member templates */
/* Called when template appears inside another template */
/* Member templates */
Setattr(n,k_nodetype,Getattr(n,k_templatetype));
ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist);
Setattr(n,k_nodetype,k_template);
Setattr(n, k_nodetype, Getattr(n, k_templatetype));
ret = cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist);
Setattr(n, k_nodetype, k_template);
return ret;
}
} else if (StringEqual(nodeType,k_cdecl)) {
} else if (StringEqual(nodeType, k_cdecl)) {
/* A simple C declaration */
SwigType *t, *v, *d;
String *code;
t = Getattr(n,k_type);
v = Getattr(n,k_value);
d = Getattr(n,k_decl);
String *code;
t = Getattr(n, k_type);
v = Getattr(n, k_value);
d = Getattr(n, k_decl);
code = Getattr(n,k_code);
Append(typelist,t);
Append(typelist,d);
Append(patchlist,v);
Append(cpatchlist,code);
if (Getattr(n,k_conversionoperator)) {
Append(cpatchlist, Getattr(n,k_name));
if (Getattr(n,k_symname)) {
Append(cpatchlist, Getattr(n,k_symname));
code = Getattr(n, k_code);
Append(typelist, t);
Append(typelist, d);
Append(patchlist, v);
Append(cpatchlist, code);
if (Getattr(n, k_conversionoperator)) {
Append(cpatchlist, Getattr(n, k_name));
if (Getattr(n, k_symname)) {
Append(cpatchlist, Getattr(n, k_symname));
}
}
add_parms(Getattr(n,k_parms), cpatchlist, typelist);
add_parms(Getattr(n,k_throws), cpatchlist, typelist);
} else if (StringEqual(nodeType,k_class)) {
add_parms(Getattr(n, k_parms), cpatchlist, typelist);
add_parms(Getattr(n, k_throws), cpatchlist, typelist);
} else if (StringEqual(nodeType, k_class)) {
/* Patch base classes */
{
int b = 0;
for (b = 0; b < 3; ++b) {
List *bases = Getattr(n,baselists[b]);
List *bases = Getattr(n, baselists[b]);
if (bases) {
int i;
int ilen = Len(bases);
int ilen = Len(bases);
for (i = 0; i < ilen; i++) {
String *name = Copy(Getitem(bases,i));
Setitem(bases,i,name);
Append(typelist,name);
String *name = Copy(Getitem(bases, i));
Setitem(bases, i, name);
Append(typelist, name);
}
}
}
@ -120,90 +120,90 @@ cparse_template_expand(Node *n, String *tname, String *rname, String *templatear
{
Node *cn = firstChild(n);
while (cn) {
cparse_template_expand(cn,tname, rname, templateargs, patchlist,typelist,cpatchlist);
cparse_template_expand(cn, tname, rname, templateargs, patchlist, typelist, cpatchlist);
cn = nextSibling(cn);
}
}
} else if (StringEqual(nodeType,k_constructor)) {
String *name = Getattr(n,k_name);
if (!(Getattr(n,k_templatetype))) {
} else if (StringEqual(nodeType, k_constructor)) {
String *name = Getattr(n, k_name);
if (!(Getattr(n, k_templatetype))) {
String *symname;
String *stripped_name = SwigType_templateprefix(name);
if (Strstr(tname,stripped_name)) {
Replaceid(name,stripped_name,tname);
if (Strstr(tname, stripped_name)) {
Replaceid(name, stripped_name, tname);
}
Delete(stripped_name);
symname = Getattr(n,k_symname);
symname = Getattr(n, k_symname);
if (symname) {
stripped_name = SwigType_templateprefix(symname);
if (Strstr(tname,stripped_name)) {
Replaceid(symname,stripped_name,tname);
if (Strstr(tname, stripped_name)) {
Replaceid(symname, stripped_name, tname);
}
Delete(stripped_name);
}
if (strchr(Char(name),'<')) {
Append(patchlist,Getattr(n,k_name));
if (strchr(Char(name), '<')) {
Append(patchlist, Getattr(n, k_name));
} else {
Append(name,templateargs);
Append(name, templateargs);
}
name = Getattr(n,k_symname);
name = Getattr(n, k_symname);
if (name) {
if (strchr(Char(name),'<')) {
if (strchr(Char(name), '<')) {
Clear(name);
Append(name,rname);
Append(name, rname);
} else {
String *tmp = Copy(name);
Replace(tmp,tname,rname, DOH_REPLACE_ANY);
Replace(tmp, tname, rname, DOH_REPLACE_ANY);
Clear(name);
Append(name,tmp);
Append(name, tmp);
Delete(tmp);
}
}
/* Setattr(n,k_symname,name); */
}
Append(cpatchlist,Getattr(n,k_code));
Append(typelist, Getattr(n,k_decl));
add_parms(Getattr(n,k_parms), cpatchlist, typelist);
add_parms(Getattr(n,k_throws), cpatchlist, typelist);
} else if (StringEqual(nodeType,k_destructor)) {
String *name = Getattr(n,k_name);
if (name && strchr(Char(name),'<')) {
Append(patchlist,Getattr(n,k_name));
Append(cpatchlist, Getattr(n, k_code));
Append(typelist, Getattr(n, k_decl));
add_parms(Getattr(n, k_parms), cpatchlist, typelist);
add_parms(Getattr(n, k_throws), cpatchlist, typelist);
} else if (StringEqual(nodeType, k_destructor)) {
String *name = Getattr(n, k_name);
if (name && strchr(Char(name), '<')) {
Append(patchlist, Getattr(n, k_name));
} else {
Append(name,templateargs);
Append(name, templateargs);
}
name = Getattr(n,k_symname);
if (name && strchr(Char(name),'<')) {
name = Getattr(n, k_symname);
if (name && strchr(Char(name), '<')) {
String *sn = Copy(tname);
Setattr(n,k_symname, sn);
Setattr(n, k_symname, sn);
Delete(sn);
} else {
Replace(name,tname,rname, DOH_REPLACE_ANY);
Replace(name, tname, rname, DOH_REPLACE_ANY);
}
/* Setattr(n,k_symname,name); */
Append(cpatchlist,Getattr(n,k_code));
} else if (StringEqual(nodeType,k_using)) {
String *uname = Getattr(n,k_uname);
if (uname && strchr(Char(uname),'<')) {
Append(cpatchlist, Getattr(n, k_code));
} else if (StringEqual(nodeType, k_using)) {
String *uname = Getattr(n, k_uname);
if (uname && strchr(Char(uname), '<')) {
Append(patchlist, uname);
}
if (Getattr(n,k_namespace)) {
if (Getattr(n, k_namespace)) {
/* Namespace link. This is nasty. Is other namespace defined? */
}
} else {
/* Look for obvious parameters */
Node *cn;
Append(cpatchlist,Getattr(n,k_code));
Append(typelist, Getattr(n,k_type));
Append(typelist, Getattr(n,k_decl));
add_parms(Getattr(n,k_parms), cpatchlist, typelist);
add_parms(Getattr(n,k_kwargs), cpatchlist, typelist);
add_parms(Getattr(n,k_pattern), cpatchlist, typelist);
add_parms(Getattr(n,k_throws), cpatchlist, typelist);
Append(cpatchlist, Getattr(n, k_code));
Append(typelist, Getattr(n, k_type));
Append(typelist, Getattr(n, k_decl));
add_parms(Getattr(n, k_parms), cpatchlist, typelist);
add_parms(Getattr(n, k_kwargs), cpatchlist, typelist);
add_parms(Getattr(n, k_pattern), cpatchlist, typelist);
add_parms(Getattr(n, k_throws), cpatchlist, typelist);
cn = firstChild(n);
while (cn) {
cparse_template_expand(cn,tname, rname, templateargs, patchlist, typelist, cpatchlist);
cparse_template_expand(cn, tname, rname, templateargs, patchlist, typelist, cpatchlist);
cn = nextSibling(cn);
}
}
@ -219,19 +219,18 @@ String *partial_arg(String *s, String *p) {
/* Find the prefix on the partial argument */
c = strchr(cp,'$');
c = strchr(cp, '$');
if (!c) {
return Copy(s);
}
prefix = NewStringWithSize(cp,c-cp);
prefix = NewStringWithSize(cp, c - cp);
newarg = Copy(s);
Replace(newarg,prefix,"",DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Replace(newarg, prefix, "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Delete(prefix);
return newarg;
}
int
Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope) {
int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope) {
List *patchlist, *cpatchlist, *typelist;
String *templateargs;
String *tname;
@ -244,31 +243,31 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts
{
String *tmp = NewStringEmpty();
if (tparms) {
SwigType_add_template(tmp,tparms);
SwigType_add_template(tmp, tparms);
}
templateargs = Copy(tmp);
Delete(tmp);
}
tname = Copy(Getattr(n,k_name));
tname = Copy(Getattr(n, k_name));
tbase = Swig_scopename_last(tname);
/* Look for partial specialization matching */
if (Getattr(n,k_partialargs)) {
if (Getattr(n, k_partialargs)) {
Parm *p, *tp;
ParmList *ptargs = SwigType_function_parms(Getattr(n,k_partialargs));
ParmList *ptargs = SwigType_function_parms(Getattr(n, k_partialargs));
p = ptargs;
tp = tparms;
while (p && tp) {
SwigType *ptype;
SwigType *tptype;
SwigType *partial_type;
ptype = Getattr(p,k_type);
tptype = Getattr(tp,k_type);
ptype = Getattr(p, k_type);
tptype = Getattr(tp, k_type);
if (ptype && tptype) {
partial_type = partial_arg(tptype,ptype);
/* Printf(stdout,"partial '%s' '%s' ---> '%s'\n", tptype, ptype, partial_type); */
Setattr(tp,k_type,partial_type);
partial_type = partial_arg(tptype, ptype);
/* Printf(stdout,"partial '%s' '%s' ---> '%s'\n", tptype, ptype, partial_type); */
Setattr(tp, k_type, partial_type);
Delete(partial_type);
}
p = nextSibling(p);
@ -281,93 +280,94 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts
if (0) {
Parm *p = tparms;
while (p) {
Printf(stdout,"tparm: '%s' '%s' '%s'\n", Getattr(p,k_name), Getattr(p,k_type), Getattr(p,k_value));
Printf(stdout, "tparm: '%s' '%s' '%s'\n", Getattr(p, k_name), Getattr(p, k_type), Getattr(p, k_value));
p = nextSibling(p);
}
}
/* Printf(stdout,"targs = '%s'\n", templateargs);
Printf(stdout,"rname = '%s'\n", rname);
Printf(stdout,"tname = '%s'\n", tname); */
cparse_template_expand(n,tname, rname, templateargs, patchlist, typelist, cpatchlist);
Printf(stdout,"rname = '%s'\n", rname);
Printf(stdout,"tname = '%s'\n", tname); */
cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist);
/* Set the name */
{
String *name = Getattr(n,k_name);
String *name = Getattr(n, k_name);
if (name) {
Append(name,templateargs);
Append(name, templateargs);
}
iname = name;
}
/* Patch all of the types */
{
Parm *tp = Getattr(n,k_templateparms);
Parm *p = tparms;
Parm *tp = Getattr(n, k_templateparms);
Parm *p = tparms;
/* Printf(stdout,"%s\n", ParmList_str_defaultargs(tp)); */
if (tp) {
Symtab *tsdecl = Getattr(n,k_symsymtab);
Symtab *tsdecl = Getattr(n, k_symsymtab);
while (p && tp) {
String *name, *value, *valuestr, *tydef, *tmp, *tmpr;
int sz, i;
int sz, i;
String *dvalue = 0;
String *qvalue = 0;
name = Getattr(tp,k_name);
value = Getattr(p,k_value);
tydef = Getattr(p,k_typedef);
name = Getattr(tp, k_name);
value = Getattr(p, k_value);
tydef = Getattr(p, k_typedef);
if (name) {
if (!value) value = Getattr(p,k_type);
if (!value)
value = Getattr(p, k_type);
qvalue = Swig_symbol_typedef_reduce(value, tsdecl);
dvalue = Swig_symbol_type_qualify(qvalue,tsdecl);
dvalue = Swig_symbol_type_qualify(qvalue, tsdecl);
if (SwigType_istemplate(dvalue)) {
String *ty = Swig_symbol_template_deftype(dvalue, tscope);
Delete(dvalue);
dvalue = ty;
}
assert(dvalue);
valuestr = SwigType_str(dvalue,0);
valuestr = SwigType_str(dvalue, 0);
/* Need to patch default arguments */
{
Parm *rp = nextSibling(p);
while (rp) {
String *rvalue = Getattr(rp,k_value);
String *rvalue = Getattr(rp, k_value);
if (rvalue) {
Replace(rvalue,name,dvalue, DOH_REPLACE_ID);
Replace(rvalue, name, dvalue, DOH_REPLACE_ID);
}
rp = nextSibling(rp);
}
}
sz = Len(patchlist);
for (i = 0; i < sz; i++) {
String *s = Getitem(patchlist,i);
Replace(s,name,dvalue, DOH_REPLACE_ID);
String *s = Getitem(patchlist, i);
Replace(s, name, dvalue, DOH_REPLACE_ID);
}
sz = Len(typelist);
for (i = 0; i < sz; i++) {
String *s = Getitem(typelist,i);
/* Replace(s,name,value, DOH_REPLACE_ID); */
/* Printf(stdout,"name = '%s', value = '%s', tbase = '%s', iname='%s' s = '%s' --> ", name, dvalue, tbase, iname, s); */
SwigType_typename_replace(s,name,dvalue);
SwigType_typename_replace(s,tbase,iname);
/* Printf(stdout,"'%s'\n", s);*/
String *s = Getitem(typelist, i);
/* Replace(s,name,value, DOH_REPLACE_ID); */
/* Printf(stdout,"name = '%s', value = '%s', tbase = '%s', iname='%s' s = '%s' --> ", name, dvalue, tbase, iname, s); */
SwigType_typename_replace(s, name, dvalue);
SwigType_typename_replace(s, tbase, iname);
/* Printf(stdout,"'%s'\n", s); */
}
if (!tydef) {
tydef = dvalue;
}
tmp = NewStringf("#%s",name);
tmp = NewStringf("#%s", name);
tmpr = NewStringf("\"%s\"", valuestr);
sz = Len(cpatchlist);
for (i = 0; i < sz; i++) {
String *s = Getitem(cpatchlist,i);
Replace(s,tmp,tmpr, DOH_REPLACE_ID);
/* Replace(s,name,tydef, DOH_REPLACE_ID); */
Replace(s,name,valuestr, DOH_REPLACE_ID);
String *s = Getitem(cpatchlist, i);
Replace(s, tmp, tmpr, DOH_REPLACE_ID);
/* Replace(s,name,tydef, DOH_REPLACE_ID); */
Replace(s, name, valuestr, DOH_REPLACE_ID);
}
Delete(tmp);
Delete(tmpr);
@ -377,28 +377,29 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts
}
p = nextSibling(p);
tp = nextSibling(tp);
if (!p) p = tp;
if (!p)
p = tp;
}
} else {
/* No template parameters at all. This could be a specialization */
int i, sz;
sz = Len(typelist);
for (i = 0; i < sz; i++) {
String *s = Getitem(typelist,i);
SwigType_typename_replace(s,tbase,iname);
String *s = Getitem(typelist, i);
SwigType_typename_replace(s, tbase, iname);
}
}
}
/* Patch bases */
{
List *bases = Getattr(n,k_baselist);
List *bases = Getattr(n, k_baselist);
if (bases) {
Iterator b;
for (b = First(bases); b.item; b = Next(b)) {
String *qn = Swig_symbol_type_qualify(b.item,tscope);
String *qn = Swig_symbol_type_qualify(b.item, tscope);
Clear(b.item);
Append(b.item,qn);
Append(b.item, qn);
Delete(qn);
}
}
@ -410,7 +411,7 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts
Delete(tname);
Delete(templateargs);
/* set_nodeType(n,k_template);*/
/* set_nodeType(n,k_template); */
return 0;
}
@ -420,168 +421,166 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts
* Search for a template that matches name with given parameters.
* ----------------------------------------------------------------------------- */
static Node *
template_locate(String *name, Parm *tparms, Symtab *tscope) {
Node *n;
static Node *template_locate(String *name, Parm *tparms, Symtab *tscope) {
Node *n;
String *tname, *rname = 0;
Node *templ;
List *mpartials = 0;
Parm *p;
Parm *parms;
Parm *targs;
Node *templ;
List *mpartials = 0;
Parm *p;
Parm *parms;
Parm *targs;
tname = Copy(name);
parms = CopyParmList(tparms);
/* Search for generic template */
templ = Swig_symbol_clookup(name,0);
templ = Swig_symbol_clookup(name, 0);
/* Add default values from generic template */
if (templ) {
Symtab *tsdecl = Getattr(templ,k_symsymtab);
Symtab *tsdecl = Getattr(templ, k_symsymtab);
targs = Getattr(templ,k_templateparms);
targs = Getattr(templ, k_templateparms);
Swig_symbol_template_defargs(parms, targs, tscope, tsdecl);
}
/* reduce the typedef */
p = parms;
while (p) {
SwigType *ty = Getattr(p,k_type);
SwigType *ty = Getattr(p, k_type);
if (ty) {
SwigType *nt = Swig_symbol_type_qualify(ty,tscope);
Setattr(p,k_type,nt);
SwigType *nt = Swig_symbol_type_qualify(ty, tscope);
Setattr(p, k_type, nt);
Delete(nt);
}
p = nextSibling(p);
}
SwigType_add_template(tname,parms);
SwigType_add_template(tname, parms);
if (template_debug) {
Printf(stdout,"\n%s:%d: template_debug: Searching for %s\n", cparse_file, cparse_line, tname);
Printf(stdout, "\n%s:%d: template_debug: Searching for %s\n", cparse_file, cparse_line, tname);
}
/* Search for an exact specialization.
Example: template<> class name<int> { ... } */
{
if (template_debug) {
Printf(stdout," searching: '%s' (exact specialization)\n", tname);
Printf(stdout, " searching: '%s' (exact specialization)\n", tname);
}
n = Swig_symbol_clookup_local(tname,0);
n = Swig_symbol_clookup_local(tname, 0);
if (!n) {
SwigType *rname = Swig_symbol_typedef_reduce(tname,tscope);
if (!StringEqual(rname,tname)) {
SwigType *rname = Swig_symbol_typedef_reduce(tname, tscope);
if (!StringEqual(rname, tname)) {
if (template_debug) {
Printf(stdout," searching: '%s' (exact specialization)\n", rname);
Printf(stdout, " searching: '%s' (exact specialization)\n", rname);
}
n = Swig_symbol_clookup_local(rname,0);
n = Swig_symbol_clookup_local(rname, 0);
}
Delete(rname);
}
if (n) {
Node *tn;
String *nodeType = Getattr(n,k_nodetype);
if (StringEqual(nodeType,k_template)) goto success;
tn = Getattr(n,k_template);
String *nodeType = Getattr(n, k_nodetype);
if (StringEqual(nodeType, k_template))
goto success;
tn = Getattr(n, k_template);
if (tn) {
n = tn;
goto success; /* Previously wrapped by a template return that */
goto success; /* Previously wrapped by a template return that */
}
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, Getattr(n,k_nodetype));
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, Getattr(n, k_nodetype));
Delete(tname);
Delete(parms);
return 0; /* Found a match, but it's not a template of any kind. */
return 0; /* Found a match, but it's not a template of any kind. */
}
}
/* Search for partial specialization.
Example: template<typename T> class name<T *> { ... } */
/* Generate reduced template name (stripped of extraneous pointers, etc.) */
rname = NewStringf("%s<(",name);
rname = NewStringf("%s<(", name);
p = parms;
while (p) {
String *t;
t = Getattr(p,k_type);
if (!t) t = Getattr(p,k_value);
t = Getattr(p, k_type);
if (!t)
t = Getattr(p, k_value);
if (t) {
String *ty = Swig_symbol_typedef_reduce(t,tscope);
String *tb = SwigType_base(ty);
String *ty = Swig_symbol_typedef_reduce(t, tscope);
String *tb = SwigType_base(ty);
String *td = SwigType_default(ty);
Replaceid(td,"enum SWIGTYPE",tb);
Replaceid(td,"SWIGTYPE",tb);
Append(rname,td);
Replaceid(td, "enum SWIGTYPE", tb);
Replaceid(td, "SWIGTYPE", tb);
Append(rname, td);
Delete(tb);
Delete(ty);
Delete(td);
}
p = nextSibling(p);
if (p) {
Append(rname,",");
Append(rname, ",");
}
}
Append(rname,")>");
Append(rname, ")>");
mpartials = NewList();
if (templ) {
/* First, we search using an exact type prototype */
Parm *p;
char tmp[32];
int i;
List *partials;
String *ss;
Iterator pi;
/* First, we search using an exact type prototype */
Parm *p;
char tmp[32];
int i;
List *partials;
String *ss;
Iterator pi;
partials = Getattr(templ,k_partials);
if (partials) {
for (pi = First(partials); pi.item; pi = Next(pi)) {
ss = Copy(pi.item);
p = parms;
i = 1;
while (p) {
String *t,*tn;
sprintf(tmp,"$%d",i);
t = Getattr(p,k_type);
if (!t) t = Getattr(p,k_value);
if (t) {
String *ty = Swig_symbol_typedef_reduce(t,tscope);
tn = SwigType_base(ty);
Replaceid(ss,tmp,tn);
Delete(tn);
Delete(ty);
}
i++;
p = nextSibling(p);
partials = Getattr(templ, k_partials);
if (partials) {
for (pi = First(partials); pi.item; pi = Next(pi)) {
ss = Copy(pi.item);
p = parms;
i = 1;
while (p) {
String *t, *tn;
sprintf(tmp, "$%d", i);
t = Getattr(p, k_type);
if (!t)
t = Getattr(p, k_value);
if (t) {
String *ty = Swig_symbol_typedef_reduce(t, tscope);
tn = SwigType_base(ty);
Replaceid(ss, tmp, tn);
Delete(tn);
Delete(ty);
}
if (template_debug) {
Printf(stdout," searching: '%s' (partial specialization - %s)\n", ss, pi.item);
}
if ((StringEqual(ss,tname)) || (StringEqual(ss,rname))) {
Append(mpartials,pi.item);
}
Delete(ss);
i++;
p = nextSibling(p);
}
if (template_debug) {
Printf(stdout, " searching: '%s' (partial specialization - %s)\n", ss, pi.item);
}
if ((StringEqual(ss, tname)) || (StringEqual(ss, rname))) {
Append(mpartials, pi.item);
}
Delete(ss);
}
}
}
if (template_debug) {
Printf(stdout," Matched partials: %s\n", mpartials);
Printf(stdout, " Matched partials: %s\n", mpartials);
}
if (Len(mpartials)) {
String *s = Getitem(mpartials,0);
n = Swig_symbol_clookup_local(s,0);
String *s = Getitem(mpartials, 0);
n = Swig_symbol_clookup_local(s, 0);
if (Len(mpartials) > 1) {
if (n) {
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG,cparse_file,cparse_line,
"Instantiation of template '%s' is ambiguous,\n",
SwigType_namestr(tname));
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG,Getfile(n),Getline(n),
" instantiation '%s' is used.\n",
SwigType_namestr(Getattr(n,k_name)));
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, cparse_file, cparse_line, "Instantiation of template '%s' is ambiguous,\n", SwigType_namestr(tname));
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, Getfile(n), Getline(n), " instantiation '%s' is used.\n", SwigType_namestr(Getattr(n, k_name)));
}
}
}
@ -591,20 +590,20 @@ template_locate(String *name, Parm *tparms, Symtab *tscope) {
}
if (!n) {
Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name);
} else if (n) {
String *nodeType = Getattr(n,k_nodetype);
if (!StringEqual(nodeType,k_template)) {
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType);
} else if (n) {
String *nodeType = Getattr(n, k_nodetype);
if (!StringEqual(nodeType, k_template)) {
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType);
n = 0;
}
}
success:
success:
Delete(tname);
Delete(rname);
Delete(mpartials);
if ((template_debug) && (n)) {
Printf(stdout,"Node: %p\n", n);
Swig_print_node(n);
Printf(stdout, "Node: %p\n", n);
Swig_print_node(n);
}
Delete(parms);
return n;
@ -620,15 +619,14 @@ template_locate(String *name, Parm *tparms, Symtab *tscope) {
* template exists.
* ----------------------------------------------------------------------------- */
Node *
Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) {
Node *n = template_locate(name, tparms, tscope); /* this function does what we want for templated classes */
Node *Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) {
Node *n = template_locate(name, tparms, tscope); /* this function does what we want for templated classes */
if (n) {
String *nodeType = Getattr(n,k_nodetype);
String *nodeType = Getattr(n, k_nodetype);
int isclass = 0;
assert(StringEqual(nodeType,k_template));
isclass = (StringEqual(Getattr(n,k_templatetype),k_class));
assert(StringEqual(nodeType, k_template));
isclass = (StringEqual(Getattr(n, k_templatetype), k_class));
if (!isclass) {
/* If not a templated class we must have a templated function.
The template found is not necessarily the one we want when dealing with templated
@ -638,31 +636,30 @@ Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) {
templated function with different numbers of template parameters. */
if (template_debug) {
Printf(stdout," Not a templated class, seeking most appropriate templated function\n");
Printf(stdout, " Not a templated class, seeking most appropriate templated function\n");
}
n = Swig_symbol_clookup_local(name,0);
n = Swig_symbol_clookup_local(name, 0);
while (n) {
Parm *tparmsfound = Getattr(n,k_templateparms);
if (ParmList_len(tparms) == ParmList_len(tparmsfound)) {
/* successful match */
break;
}
/* repeat until we find a match with correct number of templated parameters */
n = Getattr(n,k_symnextSibling);
Parm *tparmsfound = Getattr(n, k_templateparms);
if (ParmList_len(tparms) == ParmList_len(tparmsfound)) {
/* successful match */
break;
}
/* repeat until we find a match with correct number of templated parameters */
n = Getattr(n, k_symnextSibling);
}
if (!n) {
Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name);
Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name);
}
if ((template_debug) && (n)) {
Printf(stdout,"Templated function found: %p\n", n);
Swig_print_node(n);
Printf(stdout, "Templated function found: %p\n", n);
Swig_print_node(n);
}
}
}
return n;
}

View File

@ -21,16 +21,17 @@ char cvsroot_util_c[] = "$Header$";
* ----------------------------------------------------------------------------- */
void Swig_cparse_replace_descriptor(String *s) {
char tmp[512];
char tmp[512];
String *arg = 0;
SwigType *t;
char *c = 0;
while ((c = strstr(Char(s),"$descriptor("))) {
while ((c = strstr(Char(s), "$descriptor("))) {
char *d = tmp;
int level = 0;
int level = 0;
while (*c) {
if (*c == '(') level++;
if (*c == '(')
level++;
if (*c == ')') {
level--;
if (level == 0) {
@ -42,7 +43,7 @@ void Swig_cparse_replace_descriptor(String *s) {
c++;
}
*d = 0;
arg = NewString(tmp+12);
arg = NewString(tmp + 12);
t = Swig_cparse_type(arg);
Delete(arg);
arg = 0;
@ -50,19 +51,19 @@ void Swig_cparse_replace_descriptor(String *s) {
if (t) {
String *mangle;
String *descriptor;
mangle = SwigType_manglestr(t);
descriptor = NewStringf("SWIGTYPE%s",mangle);
descriptor = NewStringf("SWIGTYPE%s", mangle);
SwigType_remember(t);
*d = ')';
d++;
*d = 0;
Replace(s,tmp,descriptor,DOH_REPLACE_ANY);
Replace(s, tmp, descriptor, DOH_REPLACE_ANY);
Delete(mangle);
Delete(descriptor);
Delete(t);
} else {
Swig_error(Getfile(s),Getline(s),"Bad $descriptor() macro.\n");
Swig_error(Getfile(s), Getline(s), "Bad $descriptor() macro.\n");
break;
}
}
@ -76,15 +77,13 @@ void Swig_cparse_replace_descriptor(String *s) {
* ----------------------------------------------------------------------------- */
void cparse_normalize_void(Node *n) {
String *decl = Getattr(n,k_decl);
Parm *parms = Getattr(n,k_parms);
String *decl = Getattr(n, k_decl);
Parm *parms = Getattr(n, k_parms);
if (SwigType_isfunction(decl)) {
if ((ParmList_len(parms) == 1) && (SwigType_type(Getattr(parms,k_type)) == T_VOID)) {
Replaceall(decl,"f(void).","f().");
Delattr(n,k_parms);
if ((ParmList_len(parms) == 1) && (SwigType_type(Getattr(parms, k_type)) == T_VOID)) {
Replaceall(decl, "f(void).", "f().");
Delattr(n, k_parms);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -165,11 +165,11 @@ typedef void DOH;
/* Iterator objects */
typedef struct {
void *key; /* Current key (if any) */
void *item; /* Current item */
void *object; /* Object being iterated over */
void *_current; /* Internal use */
int _index; /* Internal use */
void *key; /* Current key (if any) */
void *item; /* Current item */
void *object; /* Object being iterated over */
void *_current; /* Internal use */
int _index; /* Internal use */
} DohIterator;
/* Memory management */
@ -184,77 +184,77 @@ typedef struct {
#define DohFree free
#endif
extern int DohCheck(const DOH *ptr); /* Check if a DOH object */
extern void DohIntern(DOH *); /* Intern an object */
extern int DohCheck(const DOH *ptr); /* Check if a DOH object */
extern void DohIntern(DOH *); /* Intern an object */
/* Basic object methods. Common to most objects */
extern void DohDelete(DOH *obj); /* Delete an object */
extern DOH *DohCopy(const DOH *obj);
extern void DohClear(DOH *obj);
extern DOHString *DohStr(const DOH *obj);
extern void *DohData(const DOH *obj);
extern int DohDump(const DOH *obj, DOHFile *out);
extern int DohLen(const DOH *obj);
extern int DohHashval(const DOH *obj);
extern int DohCmp(const DOH *obj1, const DOH *obj2);
extern int DohEqual(const DOH *obj1, const DOH *obj2);
extern void DohIncref(DOH *obj);
extern void DohDelete(DOH *obj); /* Delete an object */
extern DOH *DohCopy(const DOH *obj);
extern void DohClear(DOH *obj);
extern DOHString *DohStr(const DOH *obj);
extern void *DohData(const DOH *obj);
extern int DohDump(const DOH *obj, DOHFile * out);
extern int DohLen(const DOH *obj);
extern int DohHashval(const DOH *obj);
extern int DohCmp(const DOH *obj1, const DOH *obj2);
extern int DohEqual(const DOH *obj1, const DOH *obj2);
extern void DohIncref(DOH *obj);
/* Mapping methods */
extern DOH *DohGetattr(DOH *obj, const DOHString_or_char *name);
extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_char *value);
extern int DohDelattr(DOH *obj, const DOHString_or_char *name);
extern DOH *DohKeys(DOH *obj);
extern int DohGetInt(DOH *obj, const DOHString_or_char *name);
extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int);
extern double DohGetDouble(DOH *obj, const DOHString_or_char *name);
extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double);
extern char *DohGetChar(DOH *obj, const DOHString_or_char *name);
extern void DohSetChar(DOH *obj, const DOH *name, char *value);
extern void *DohGetFlagAttr(DOH *obj, const DOHString_or_char *name);
extern int DohGetFlag(DOH *obj, const DOHString_or_char *name);
extern void DohSetFlagAttr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *attr);
extern void DohSetFlag(DOH *obj, const DOHString_or_char *name);
extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name);
extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value);
extern DOH *DohGetattr(DOH *obj, const DOHString_or_char *name);
extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_char * value);
extern int DohDelattr(DOH *obj, const DOHString_or_char *name);
extern DOH *DohKeys(DOH *obj);
extern int DohGetInt(DOH *obj, const DOHString_or_char *name);
extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int);
extern double DohGetDouble(DOH *obj, const DOHString_or_char *name);
extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double);
extern char *DohGetChar(DOH *obj, const DOHString_or_char *name);
extern void DohSetChar(DOH *obj, const DOH *name, char *value);
extern void *DohGetFlagAttr(DOH *obj, const DOHString_or_char *name);
extern int DohGetFlag(DOH *obj, const DOHString_or_char *name);
extern void DohSetFlagAttr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *attr);
extern void DohSetFlag(DOH *obj, const DOHString_or_char *name);
extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name);
extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value);
/* Sequence methods */
extern DOH *DohGetitem(DOH *obj, int index);
extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char *value);
extern int DohDelitem(DOH *obj, int index);
extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char *value);
extern int DohDelslice(DOH *obj, int sindex, int eindex);
extern DOH *DohGetitem(DOH *obj, int index);
extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char * value);
extern int DohDelitem(DOH *obj, int index);
extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char * value);
extern int DohDelslice(DOH *obj, int sindex, int eindex);
/* File methods */
extern int DohWrite(DOHFile *obj, void *buffer, int length);
extern int DohRead(DOHFile *obj, void *buffer, int length);
extern int DohSeek(DOHFile *obj, long offset, int whence);
extern long DohTell(DOHFile *obj);
extern int DohGetc(DOHFile *obj);
extern int DohPutc(int ch, DOHFile *obj);
extern int DohUngetc(int ch, DOHFile *obj);
extern int DohWrite(DOHFile * obj, void *buffer, int length);
extern int DohRead(DOHFile * obj, void *buffer, int length);
extern int DohSeek(DOHFile * obj, long offset, int whence);
extern long DohTell(DOHFile * obj);
extern int DohGetc(DOHFile * obj);
extern int DohPutc(int ch, DOHFile * obj);
extern int DohUngetc(int ch, DOHFile * obj);
/* Iterators */
extern DohIterator DohFirst(DOH *obj);
extern DohIterator DohNext(DohIterator x);
extern DohIterator DohFirst(DOH *obj);
extern DohIterator DohNext(DohIterator x);
/* Positional */
extern int DohGetline(DOH *obj);
extern void DohSetline(DOH *obj, int line);
extern DOH *DohGetfile(DOH *obj);
extern void DohSetfile(DOH *obj, DOH *file);
extern int DohGetline(DOH *obj);
extern void DohSetline(DOH *obj, int line);
extern DOH *DohGetfile(DOH *obj);
extern void DohSetfile(DOH *obj, DOH *file);
/* String Methods */
extern int DohReplace(DOHString *src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags);
extern void DohChop(DOHString *src);
extern int DohReplace(DOHString * src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags);
extern void DohChop(DOHString * src);
extern int DohString_putc(DOH *so, int ch);
extern int DohString_getc(DOH *so);
@ -274,39 +274,39 @@ extern int DohString_delslice(DOH *so, int sindex, int eindex);
#define DohStringEqual(s1,s2) DohString_equal((DOH *)s1, (DOH *)s2)
/* Meta-variables */
extern DOH *DohGetmeta(DOH *, const DOH *);
extern int DohSetmeta(DOH *, const DOH *, const DOH *value);
extern int DohDelmeta(DOH *, const DOH *);
extern DOH *DohGetmeta(DOH *, const DOH *);
extern int DohSetmeta(DOH *, const DOH *, const DOH *value);
extern int DohDelmeta(DOH *, const DOH *);
/* Utility functions */
extern void DohEncoding(char *name, DOH *(*fn)(DOH *s));
extern int DohPrintf(DOHFile *obj, const char *format, ...);
extern int DohvPrintf(DOHFile *obj, const char *format, va_list ap);
extern int DohPrintv(DOHFile *obj, ...);
extern DOH *DohReadline(DOHFile *in);
extern void DohEncoding(char *name, DOH *(*fn) (DOH *s));
extern int DohPrintf(DOHFile * obj, const char *format, ...);
extern int DohvPrintf(DOHFile * obj, const char *format, va_list ap);
extern int DohPrintv(DOHFile * obj, ...);
extern DOH *DohReadline(DOHFile * in);
/* Miscellaneous */
extern int DohIsMapping(const DOH *obj);
extern int DohIsSequence(const DOH *obj);
extern int DohIsString(const DOH *obj);
extern int DohIsFile(const DOH *obj);
extern int DohIsMapping(const DOH *obj);
extern int DohIsSequence(const DOH *obj);
extern int DohIsString(const DOH *obj);
extern int DohIsFile(const DOH *obj);
extern void DohSetmark(DOH *obj, int x);
extern int DohGetmark(DOH *obj);
extern void DohSetmark(DOH *obj, int x);
extern int DohGetmark(DOH *obj);
/* -----------------------------------------------------------------------------
* Strings.
* ----------------------------------------------------------------------------- */
extern DOHString *DohNewStringEmpty();
extern DOHString *DohNewString(const DOH *c);
extern DOHString *DohNewStringWithSize(const DOH *c, int len);
extern DOHString *DohNewStringf(const DOH *fmt, ...);
extern DOHString *DohNewStringEmpty();
extern DOHString *DohNewString(const DOH *c);
extern DOHString *DohNewStringWithSize(const DOH *c, int len);
extern DOHString *DohNewStringf(const DOH *fmt, ...);
extern int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2);
extern int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n);
extern int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2);
extern int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n);
extern char *DohStrstr(const DOHString_or_char *s1, const DOHString_or_char *s2);
extern char *DohStrchr(const DOHString_or_char *s1, int ch);
@ -329,36 +329,36 @@ extern char *DohStrchr(const DOHString_or_char *s1, int ch);
extern DOHFile *DohNewFile(DOH *file, const char *mode);
extern DOHFile *DohNewFileFromFile(FILE *f);
extern DOHFile *DohNewFileFromFd(int fd);
extern void DohFileErrorDisplay(DOHString *filename);
extern int DohClose(DOH *file);
extern int DohCopyto(DOHFile *input, DOHFile *output);
extern void DohFileErrorDisplay(DOHString * filename);
extern int DohClose(DOH *file);
extern int DohCopyto(DOHFile * input, DOHFile * output);
/* -----------------------------------------------------------------------------
* List
* ----------------------------------------------------------------------------- */
extern DOHList *DohNewList();
extern void DohSortList(DOH *lo, int (*cmp)(const DOH *, const DOH *));
extern DOHList *DohNewList();
extern void DohSortList(DOH *lo, int (*cmp) (const DOH *, const DOH *));
/* -----------------------------------------------------------------------------
* Hash
* ----------------------------------------------------------------------------- */
extern DOHHash *DohNewHash();
extern DOH *DohHashGetAttr(DOH *hash, const DOH *key);
extern int DohHashCheckAttr(DOH *hash, DOH *key, DOH *value);
extern DOHHash *DohNewHash();
extern DOH *DohHashGetAttr(DOH *hash, const DOH *key);
extern int DohHashCheckAttr(DOH *hash, DOH *key, DOH *value);
/* -----------------------------------------------------------------------------
* Void
* ----------------------------------------------------------------------------- */
extern DOHVoid *DohNewVoid(void *ptr, void (*del)(void *));
extern DOHList *DohSplit(DOHFile *input, char ch, int nsplits);
extern DOHList *DohSplitLines(DOHFile *input);
extern DOH *DohNone;
extern DOHVoid *DohNewVoid(void *ptr, void (*del) (void *));
extern DOHList *DohSplit(DOHFile * input, char ch, int nsplits);
extern DOHList *DohSplitLines(DOHFile * input);
extern DOH *DohNone;
extern void DohMemoryDebug(void);
extern void DohMemoryDebug(void);
#ifndef DOH_LONG_NAMES
/* Macros to invoke the above functions. Includes the location of
@ -468,8 +468,4 @@ extern void DohMemoryDebug(void);
#define NIL (char *) NULL
#endif /* DOH_H */
#endif /* DOH_H */

View File

@ -26,37 +26,37 @@
/* Hash objects */
typedef struct {
DOH *(*doh_getattr)(DOH *obj, DOH *name); /* Get attribute */
int (*doh_setattr)(DOH *obj, DOH *name, DOH *value); /* Set attribute */
int (*doh_delattr)(DOH *obj, DOH *name); /* Del attribute */
DOH *(*doh_keys)(DOH *obj); /* All keys as a list */
DOH *(*doh_getattr) (DOH *obj, DOH *name); /* Get attribute */
int (*doh_setattr) (DOH *obj, DOH *name, DOH *value); /* Set attribute */
int (*doh_delattr) (DOH *obj, DOH *name); /* Del attribute */
DOH *(*doh_keys) (DOH *obj); /* All keys as a list */
} DohHashMethods;
/* List objects */
typedef struct {
DOH *(*doh_getitem)(DOH *obj, int index); /* Get item */
int (*doh_setitem)(DOH *obj, int index, DOH *value); /* Set item */
int (*doh_delitem)(DOH *obj, int index); /* Delete item */
int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */
int (*doh_delslice)(DOH *obj, int sindex, int eindex); /* Delete slice */
DOH *(*doh_getitem) (DOH *obj, int index); /* Get item */
int (*doh_setitem) (DOH *obj, int index, DOH *value); /* Set item */
int (*doh_delitem) (DOH *obj, int index); /* Delete item */
int (*doh_insitem) (DOH *obj, int index, DOH *value); /* Insert item */
int (*doh_delslice) (DOH *obj, int sindex, int eindex); /* Delete slice */
} DohListMethods;
/* File methods */
typedef struct {
int (*doh_read)(DOH *obj, void *buffer, int nbytes); /* Read bytes */
int (*doh_write)(DOH *obj, void *buffer, int nbytes); /* Write bytes */
int (*doh_putc)(DOH *obj, int ch); /* Put character */
int (*doh_getc)(DOH *obj); /* Get character */
int (*doh_ungetc)(DOH *obj, int ch); /* Unget character */
int (*doh_seek)(DOH *obj, long offset, int whence); /* Seek */
long (*doh_tell)(DOH *obj); /* Tell */
int (*doh_close)(DOH *obj); /* Close */
int (*doh_read) (DOH *obj, void *buffer, int nbytes); /* Read bytes */
int (*doh_write) (DOH *obj, void *buffer, int nbytes); /* Write bytes */
int (*doh_putc) (DOH *obj, int ch); /* Put character */
int (*doh_getc) (DOH *obj); /* Get character */
int (*doh_ungetc) (DOH *obj, int ch); /* Unget character */
int (*doh_seek) (DOH *obj, long offset, int whence); /* Seek */
long (*doh_tell) (DOH *obj); /* Tell */
int (*doh_close) (DOH *obj); /* Close */
} DohFileMethods;
/* String methods */
typedef struct {
int (*doh_replace)(DOH *obj, DOH *old, DOH *rep, int flags);
void (*doh_chop)(DOH *obj);
int (*doh_replace) (DOH *obj, DOH *old, DOH *rep, int flags);
void (*doh_chop) (DOH *obj);
} DohStringMethods;
/* -----------------------------------------------------------------------------
@ -64,55 +64,55 @@ typedef struct {
* ----------------------------------------------------------------------------- */
typedef struct DohObjInfo {
char *objname; /* Object name */
char *objname; /* Object name */
/* Basic object methods */
void (*doh_del)(DOH *obj); /* Delete object */
DOH *(*doh_copy)(DOH *obj); /* Copy and object */
void (*doh_clear)(DOH *obj); /* Clear an object */
void (*doh_del) (DOH *obj); /* Delete object */
DOH *(*doh_copy) (DOH *obj); /* Copy and object */
void (*doh_clear) (DOH *obj); /* Clear an object */
/* I/O methods */
DOH *(*doh_str)(DOH *obj); /* Make a full string */
void *(*doh_data)(DOH *obj); /* Return raw data */
int (*doh_dump)(DOH *obj, DOH *out); /* Serialize on out */
DOH *(*doh_str) (DOH *obj); /* Make a full string */
void *(*doh_data) (DOH *obj); /* Return raw data */
int (*doh_dump) (DOH *obj, DOH *out); /* Serialize on out */
/* Length and hash values */
int (*doh_len)(DOH *obj);
int (*doh_hashval)(DOH *obj);
int (*doh_len) (DOH *obj);
int (*doh_hashval) (DOH *obj);
/* Compare */
int (*doh_cmp)(DOH *obj1, DOH *obj2);
int (*doh_cmp) (DOH *obj1, DOH *obj2);
/* Equal */
int (*doh_equal)(DOH *obj1, DOH *obj2);
int (*doh_equal) (DOH *obj1, DOH *obj2);
/* Iterators */
DohIterator (*doh_first)(DOH *obj);
DohIterator (*doh_next)(DohIterator );
DohIterator (*doh_first) (DOH *obj);
DohIterator (*doh_next) (DohIterator);
/* Positional */
void (*doh_setfile)(DOH *obj, DOHString_or_char *file);
DOH *(*doh_getfile)(DOH *obj);
void (*doh_setline)(DOH *obj, int line);
int (*doh_getline)(DOH *obj);
void (*doh_setfile) (DOH *obj, DOHString_or_char *file);
DOH *(*doh_getfile) (DOH *obj);
void (*doh_setline) (DOH *obj, int line);
int (*doh_getline) (DOH *obj);
DohHashMethods *doh_hash; /* Hash methods */
DohListMethods *doh_list; /* List methods */
DohFileMethods *doh_file; /* File methods */
DohStringMethods *doh_string; /* String methods */
void *doh_reserved; /* Reserved */
void *clientdata; /* User data */
DohHashMethods *doh_hash; /* Hash methods */
DohListMethods *doh_list; /* List methods */
DohFileMethods *doh_file; /* File methods */
DohStringMethods *doh_string; /* String methods */
void *doh_reserved; /* Reserved */
void *clientdata; /* User data */
} DohObjInfo;
typedef struct {
void *data; /* Data pointer */
DohObjInfo *type;
void *meta; /* Meta data */
unsigned int flag_intern : 1; /* Interned object */
unsigned int flag_marked : 1; /* Mark flag. Used to avoid recursive loops in places */
unsigned int flag_user : 1; /* User flag */
unsigned int flag_usermark : 1; /* User marked */
unsigned int refcount : 28; /* Reference count (max 16 million) */
void *data; /* Data pointer */
DohObjInfo *type;
void *meta; /* Meta data */
unsigned int flag_intern:1; /* Interned object */
unsigned int flag_marked:1; /* Mark flag. Used to avoid recursive loops in places */
unsigned int flag_user:1; /* User flag */
unsigned int flag_usermark:1; /* User marked */
unsigned int refcount:28; /* Reference count (max 16 million) */
} DohBase;
/* Macros for decrefing and increfing (safe for null objects). */
@ -127,12 +127,7 @@ typedef struct {
#define ObjGetMark(a) ((DohBase *)a)->flag_marked
#define ObjType(a) ((DohBase *)a)->type
extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */
extern void DohObjFree(DOH *ptr); /* Free a DOH object */
#endif /* DOHINT_H */
extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */
extern void DohObjFree(DOH *ptr); /* Free a DOH object */
#endif /* DOHINT_H */

View File

@ -20,17 +20,16 @@ char cvsroot_file_c[] = "$Header$";
#include <errno.h>
typedef struct {
FILE *filep;
int fd;
int closeondel;
FILE *filep;
int fd;
int closeondel;
} DohFile;
/* -----------------------------------------------------------------------------
* DelFile()
* ----------------------------------------------------------------------------- */
static void
DelFile(DOH *fo) {
static void DelFile(DOH *fo) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->closeondel) {
if (f->filep) {
@ -49,15 +48,14 @@ DelFile(DOH *fo) {
* File_read()
* ----------------------------------------------------------------------------- */
static int
File_read(DOH *fo, void *buffer, int len) {
static int File_read(DOH *fo, void *buffer, int len) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return fread(buffer,1,len,f->filep);
return fread(buffer, 1, len, f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
return read(f->fd,buffer,len);
return read(f->fd, buffer, len);
#endif
}
return -1;
@ -67,16 +65,15 @@ File_read(DOH *fo, void *buffer, int len) {
* File_write()
* ----------------------------------------------------------------------------- */
static int
File_write(DOH *fo, void *buffer, int len) {
static int File_write(DOH *fo, void *buffer, int len) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
int ret = (int) fwrite(buffer, 1, len, f->filep);
int err = (ret != len) ? ferror(f->filep) : 0;
return err ? -1: ret;
return err ? -1 : ret;
} else if (f->fd) {
#ifdef DOH_INTFILE
return write(f->fd,buffer,len);
return write(f->fd, buffer, len);
#endif
}
return -1;
@ -86,11 +83,10 @@ File_write(DOH *fo, void *buffer, int len) {
* File_seek()
* ----------------------------------------------------------------------------- */
static int
File_seek(DOH *fo, long offset, int whence) {
static int File_seek(DOH *fo, long offset, int whence) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return fseek(f->filep,offset,whence);
return fseek(f->filep, offset, whence);
} else if (f->fd) {
#ifdef DOH_INTFILE
return lseek(f->fd, offset, whence);
@ -103,8 +99,7 @@ File_seek(DOH *fo, long offset, int whence) {
* File_tell()
* ----------------------------------------------------------------------------- */
static long
File_tell(DOH *fo) {
static long File_tell(DOH *fo) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return ftell(f->filep);
@ -120,16 +115,15 @@ File_tell(DOH *fo) {
* File_putc()
* ----------------------------------------------------------------------------- */
static int
File_putc(DOH *fo, int ch) {
static int File_putc(DOH *fo, int ch) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return fputc(ch,f->filep);
return fputc(ch, f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
char c;
c = (char) ch;
return write(f->fd,&c,1);
return write(f->fd, &c, 1);
#endif
}
return -1;
@ -139,15 +133,15 @@ File_putc(DOH *fo, int ch) {
* File_getc()
* ----------------------------------------------------------------------------- */
static int
File_getc(DOH *fo) {
static int File_getc(DOH *fo) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return fgetc(f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
char c;
if (read(f->fd,&c,1) < 0) return EOF;
if (read(f->fd, &c, 1) < 0)
return EOF;
return c;
#endif
}
@ -160,8 +154,7 @@ File_getc(DOH *fo) {
* Put a character back onto the input
* ----------------------------------------------------------------------------- */
static int
File_ungetc(DOH *fo, int ch) {
static int File_ungetc(DOH *fo, int ch) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return ungetc(ch, f->filep);
@ -179,8 +172,7 @@ File_ungetc(DOH *fo, int ch) {
* Close the file
* ----------------------------------------------------------------------------- */
static int
File_close(DOH *fo) {
static int File_close(DOH *fo) {
int ret = 0;
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
@ -196,40 +188,40 @@ File_close(DOH *fo) {
}
static DohFileMethods FileFileMethods = {
File_read,
File_read,
File_write,
File_putc,
File_getc,
File_ungetc,
File_seek,
File_tell,
File_close, /* close */
File_close, /* close */
};
static DohObjInfo DohFileType = {
"DohFile", /* objname */
DelFile, /* doh_del */
0, /* doh_copy */
0, /* doh_clear */
0, /* doh_str */
0, /* doh_data */
0, /* doh_dump */
0, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
0, /* doh_first */
0, /* doh_next */
0, /* doh_setfile */
0, /* doh_getfile */
0, /* doh_setline */
0, /* doh_getline */
0, /* doh_mapping */
0, /* doh_sequence */
&FileFileMethods,/* doh_file */
0, /* doh_string */
0, /* doh_callable */
0, /* doh_position */
"DohFile", /* objname */
DelFile, /* doh_del */
0, /* doh_copy */
0, /* doh_clear */
0, /* doh_str */
0, /* doh_data */
0, /* doh_dump */
0, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
0, /* doh_first */
0, /* doh_next */
0, /* doh_setfile */
0, /* doh_getfile */
0, /* doh_setline */
0, /* doh_getline */
0, /* doh_mapping */
0, /* doh_sequence */
&FileFileMethods, /* doh_file */
0, /* doh_string */
0, /* doh_callable */
0, /* doh_position */
};
/* -----------------------------------------------------------------------------
@ -238,16 +230,15 @@ static DohObjInfo DohFileType = {
* Create a new file from a given filename and mode.
* ----------------------------------------------------------------------------- */
DOH *
DohNewFile(DOH *fn, const char *mode)
{
DOH *DohNewFile(DOH *fn, const char *mode) {
DohFile *f;
FILE *file;
char *filename;
filename = Char(fn);
file = fopen(filename,mode);
if (!file) return 0;
file = fopen(filename, mode);
if (!file)
return 0;
f = (DohFile *) DohMalloc(sizeof(DohFile));
if (!f) {
@ -257,7 +248,7 @@ DohNewFile(DOH *fn, const char *mode)
f->filep = file;
f->fd = 0;
f->closeondel = 1;
return DohObjMalloc(&DohFileType,f);
return DohObjMalloc(&DohFileType, f);
}
/* -----------------------------------------------------------------------------
@ -266,16 +257,15 @@ DohNewFile(DOH *fn, const char *mode)
* Create a file object from an already open FILE *.
* ----------------------------------------------------------------------------- */
DOH *
DohNewFileFromFile(FILE *file)
{
DOH *DohNewFileFromFile(FILE *file) {
DohFile *f;
f = (DohFile *) DohMalloc(sizeof(DohFile));
if (!f) return 0;
if (!f)
return 0;
f->filep = file;
f->fd = 0;
f->closeondel = 0;
return DohObjMalloc(&DohFileType,f);
return DohObjMalloc(&DohFileType, f);
}
/* -----------------------------------------------------------------------------
@ -284,16 +274,15 @@ DohNewFileFromFile(FILE *file)
* Create a file object from an already open FILE *.
* ----------------------------------------------------------------------------- */
DOH *
DohNewFileFromFd(int fd)
{
DOH *DohNewFileFromFd(int fd) {
DohFile *f;
f = (DohFile *) DohMalloc(sizeof(DohFile));
if (!f) return 0;
if (!f)
return 0;
f->filep = 0;
f->fd = fd;
f->closeondel = 0;
return DohObjMalloc(&DohFileType,f);
return DohObjMalloc(&DohFileType, f);
}
/* -----------------------------------------------------------------------------
@ -302,9 +291,6 @@ DohNewFileFromFd(int fd)
* Display cause of one of the NewFile functions failing.
* ----------------------------------------------------------------------------- */
void
DohFileErrorDisplay(DOHString *filename)
{
void DohFileErrorDisplay(DOHString * filename) {
Printf(stderr, "Unable to open file %s: %s\n", filename, strerror(errno));
}

View File

@ -16,7 +16,7 @@ char cvsroot_fio_c[] = "$Header$";
#define OBUFLEN 512
static DOH *encodings = 0; /* Encoding hash */
static DOH *encodings = 0; /* Encoding hash */
/* -----------------------------------------------------------------------------
* Writen()
@ -29,8 +29,9 @@ static int Writen(DOH *out, void *buffer, int len) {
int nw = len, ret;
char *cb = (char *) buffer;
while (nw) {
ret = Write(out,cb,nw);
if (ret < 0) return -1;
ret = Write(out, cb, nw);
if (ret < 0)
return -1;
nw = nw - ret;
cb += ret;
}
@ -44,36 +45,38 @@ static int Writen(DOH *out, void *buffer, int len) {
* two file-like objects and operate as a filter.
* ----------------------------------------------------------------------------- */
void
DohEncoding(char *name, DOH *(*fn)(DOH *s)) {
if (!encodings) encodings = NewHash();
Setattr(encodings,(void *) name, NewVoid((void *)fn,0));
void DohEncoding(char *name, DOH *(*fn) (DOH *s)) {
if (!encodings)
encodings = NewHash();
Setattr(encodings, (void *) name, NewVoid((void *) fn, 0));
}
/* internal function for processing an encoding */
static DOH *encode(char *name, DOH *s) {
static DOH *encode(char *name, DOH *s) {
DOH *handle, *ns;
DOH *(*fn)(DOH *);
long pos;
char *cfmt = strchr(name,':');
DOH *tmp = 0;
DOH *(*fn) (DOH *);
long pos;
char *cfmt = strchr(name, ':');
DOH *tmp = 0;
if (cfmt) {
tmp = NewString(cfmt + 1);
Append(tmp,s);
Setfile(tmp,Getfile((DOH *)s));
Setline(tmp,Getline((DOH *)s));
Append(tmp, s);
Setfile(tmp, Getfile((DOH *) s));
Setline(tmp, Getline((DOH *) s));
*cfmt = '\0';
}
if (!encodings || !(handle = Getattr(encodings,name))) {
if (!encodings || !(handle = Getattr(encodings, name))) {
return Copy(s);
}
if (tmp) s = tmp;
if (tmp)
s = tmp;
pos = Tell(s);
Seek(s,0,SEEK_SET);
Seek(s, 0, SEEK_SET);
fn = (DOH *(*)(DOH *)) Data(handle);
ns = (*fn)(s);
Seek(s,pos,SEEK_SET);
if (tmp) Delete(tmp);
ns = (*fn) (s);
Seek(s, pos, SEEK_SET);
if (tmp)
Delete(tmp);
return ns;
}
@ -95,37 +98,35 @@ static DOH *encode(char *name, DOH *s) {
* It's better to use Dump() or some other method instead.
* ----------------------------------------------------------------------------- */
int
DohvPrintf(DOH *so, const char *format, va_list ap)
{
int DohvPrintf(DOH *so, const char *format, va_list ap) {
static char *fmt_codes = "dioxXucsSfeEgGpn";
int state = 0;
const char *p = format;
char newformat[256];
char obuffer[OBUFLEN];
char newformat[256];
char obuffer[OBUFLEN];
char *fmt = 0;
char temp[64];
int widthval = 0;
int precval = 0;
int maxwidth;
char *w = 0;
int ivalue;
char temp[64];
int widthval = 0;
int precval = 0;
int maxwidth;
char *w = 0;
int ivalue;
double dvalue;
void *pvalue;
char *stemp;
int nbytes = 0;
char encoder[128], *ec = 0;
int plevel = 0;
void *pvalue;
char *stemp;
int nbytes = 0;
char encoder[128], *ec = 0;
int plevel = 0;
memset (newformat, 0, sizeof (newformat));
memset(newformat, 0, sizeof(newformat));
while (*p) {
switch(state) {
case 0: /* Ordinary text */
switch (state) {
case 0: /* Ordinary text */
if (*p != '%') {
Putc(*p,so);
Putc(*p, so);
nbytes++;
} else{
} else {
fmt = newformat;
widthval = 0;
precval = 0;
@ -134,26 +135,26 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
state = 10;
}
break;
case 10: /* Look for a width and precision */
if (isdigit((int)*p) && (*p != '0')) {
case 10: /* Look for a width and precision */
if (isdigit((int) *p) && (*p != '0')) {
w = temp;
*(w++) = *p;
*(fmt++) = *p;
state = 20;
} else if (strchr(fmt_codes,*p)) {
} else if (strchr(fmt_codes, *p)) {
/* Got one of the formatting codes */
p--;
state = 100;
} else if (*p == '*') {
/* Width field is specified in the format list */
widthval = va_arg(ap,int);
sprintf(temp,"%d",widthval);
widthval = va_arg(ap, int);
sprintf(temp, "%d", widthval);
for (w = temp; *w; w++) {
*(fmt++) = *w;
}
state = 30;
} else if (*p == '%') {
Putc(*p,so);
Putc(*p, so);
fmt = newformat;
nbytes++;
state = 0;
@ -165,12 +166,12 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
*(fmt++) = *p;
}
break;
case 20: /* Hmmm. At the start of a width field */
if (isdigit((int)*p)) {
case 20: /* Hmmm. At the start of a width field */
if (isdigit((int) *p)) {
*(w++) = *p;
*(fmt++) = *p;
} else if (strchr(fmt_codes,*p)) {
} else if (strchr(fmt_codes, *p)) {
/* Got one of the formatting codes */
/* Figure out width */
*w = 0;
@ -191,12 +192,12 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
}
break;
case 30: /* Parsed a width from an argument. Look for a . */
case 30: /* Parsed a width from an argument. Look for a . */
if (*p == '.') {
w = temp;
*(fmt++) = *p;
state = 40;
} else if (strchr(fmt_codes,*p)) {
} else if (strchr(fmt_codes, *p)) {
/* Got one of the formatting codes */
/* Figure out width */
p--;
@ -209,19 +210,19 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
case 40:
/* Start of precision expected */
if (isdigit((int)*p) && (*p != '0')) {
if (isdigit((int) *p) && (*p != '0')) {
*(fmt++) = *p;
*(w++) = *p;
state = 41;
} else if (*p == '*') {
/* Precision field is specified in the format list */
precval = va_arg(ap,int);
sprintf(temp,"%d",precval);
precval = va_arg(ap, int);
sprintf(temp, "%d", precval);
for (w = temp; *w; w++) {
*(fmt++) = *w;
}
state = 50;
} else if (strchr(fmt_codes,*p)) {
} else if (strchr(fmt_codes, *p)) {
p--;
state = 100;
} else {
@ -230,10 +231,10 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
}
break;
case 41:
if (isdigit((int)*p)) {
if (isdigit((int) *p)) {
*(fmt++) = *p;
*(w++) = *p;
} else if (strchr(fmt_codes,*p)) {
} else if (strchr(fmt_codes, *p)) {
/* Got one of the formatting codes */
/* Figure out width */
*w = 0;
@ -249,7 +250,7 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
break;
/* Hang out, wait for format specifier */
case 50:
if (strchr(fmt_codes,*p)) {
if (strchr(fmt_codes, *p)) {
p--;
state = 100;
} else {
@ -279,43 +280,47 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
break;
case 100:
/* Got a formatting code */
if (widthval < precval) maxwidth = precval;
else maxwidth = widthval;
if ((*p == 's') || (*p == 'S')) { /* Null-Terminated string */
DOH *doh;
DOH *Sval;
DOH *enc = 0;
if (widthval < precval)
maxwidth = precval;
else
maxwidth = widthval;
if ((*p == 's') || (*p == 'S')) { /* Null-Terminated string */
DOH *doh;
DOH *Sval;
DOH *enc = 0;
doh = va_arg(ap, DOH *);
if (DohCheck(doh)) {
/* Is a DOH object. */
if (DohIsString(doh)) {
if (DohIsString(doh)) {
Sval = doh;
} else {
Sval = Str(doh);
}
if (strlen(encoder)) {
enc = encode(encoder,Sval);
maxwidth = maxwidth+strlen(newformat)+Len(enc);
enc = encode(encoder, Sval);
maxwidth = maxwidth + strlen(newformat) + Len(enc);
} else {
maxwidth = maxwidth+strlen(newformat)+Len(Sval);
maxwidth = maxwidth + strlen(newformat) + Len(Sval);
}
*(fmt++) = 's';
*fmt = 0;
if ((maxwidth + 1) < OBUFLEN) {
stemp = obuffer;
} else {
stemp = (char *) DohMalloc(maxwidth+1);
stemp = (char *) DohMalloc(maxwidth + 1);
}
if (enc) {
nbytes+=sprintf(stemp,newformat,Data(enc));
nbytes += sprintf(stemp, newformat, Data(enc));
} else {
nbytes+=sprintf(stemp,newformat,Data(Sval));
nbytes += sprintf(stemp, newformat, Data(Sval));
}
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
if (Writen(so, stemp, strlen(stemp)) < 0)
return -1;
if ((DOH *) Sval != doh) {
Delete(Sval);
}
if (enc) Delete(enc);
if (enc)
Delete(enc);
if (*p == 'S') {
Delete(doh);
}
@ -323,45 +328,48 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
DohFree(stemp);
}
} else {
if (!doh) doh = (char *)"";
if (!doh)
doh = (char *) "";
if (strlen(encoder)) {
DOH *s = NewString(doh);
Seek(s,0, SEEK_SET);
enc = encode(encoder,s);
Seek(s, 0, SEEK_SET);
enc = encode(encoder, s);
Delete(s);
doh = Char(enc);
} else {
enc = 0;
}
maxwidth = maxwidth+strlen(newformat)+strlen((char *) doh);
maxwidth = maxwidth + strlen(newformat) + strlen((char *) doh);
*(fmt++) = 's';
*fmt = 0;
if ((maxwidth+1) < OBUFLEN) {
if ((maxwidth + 1) < OBUFLEN) {
stemp = obuffer;
} else {
stemp = (char *) DohMalloc(maxwidth + 1);
}
nbytes+=sprintf(stemp,newformat,doh);
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
nbytes += sprintf(stemp, newformat, doh);
if (Writen(so, stemp, strlen(stemp)) < 0)
return -1;
if (stemp != obuffer) {
DohFree(stemp);
}
if (enc) Delete(enc);
if (enc)
Delete(enc);
}
} else {
*(fmt++) = *p;
*fmt = 0;
maxwidth = maxwidth+strlen(newformat)+64;
maxwidth = maxwidth + strlen(newformat) + 64;
/* Only allocate a buffer if it is too big to fit. Shouldn't have to do
this very often */
this very often */
if (maxwidth < OBUFLEN)
stemp = obuffer;
else
stemp = (char *) DohMalloc(maxwidth+1);
switch(*p) {
else
stemp = (char *) DohMalloc(maxwidth + 1);
switch (*p) {
case 'd':
case 'i':
case 'o':
@ -369,26 +377,28 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
case 'x':
case 'X':
case 'c':
ivalue = va_arg(ap,int);
nbytes+=sprintf(stemp,newformat,ivalue);
ivalue = va_arg(ap, int);
nbytes += sprintf(stemp, newformat, ivalue);
break;
case 'f':
case 'g':
case 'e':
case 'E':
case 'G':
dvalue = va_arg(ap,double);
nbytes+=sprintf(stemp,newformat,dvalue);
dvalue = va_arg(ap, double);
nbytes += sprintf(stemp, newformat, dvalue);
break;
case 'p':
pvalue = va_arg(ap,void *);
nbytes+=sprintf(stemp,newformat,pvalue);
pvalue = va_arg(ap, void *);
nbytes += sprintf(stemp, newformat, pvalue);
break;
default:
break;
}
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
if (stemp != obuffer) DohFree(stemp);
if (Writen(so, stemp, strlen(stemp)) < 0)
return -1;
if (stemp != obuffer)
DohFree(stemp);
}
state = 0;
break;
@ -398,8 +408,9 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
if (state) {
int r;
*fmt = 0;
r = Writen(so,fmt,strlen(fmt));
if (r < 0) return -1;
r = Writen(so, fmt, strlen(fmt));
if (r < 0)
return -1;
nbytes += r;
}
return nbytes;
@ -411,12 +422,11 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
* Variable length argument entry point to Printf
* ----------------------------------------------------------------------------- */
int
DohPrintf(DOH *obj, const char *format, ...) {
int DohPrintf(DOH *obj, const char *format, ...) {
va_list ap;
int ret;
va_start(ap,format);
ret = DohvPrintf(obj,format,ap);
va_start(ap, format);
ret = DohvPrintf(obj, format, ap);
va_end(ap);
return ret;
}
@ -427,18 +437,19 @@ DohPrintf(DOH *obj, const char *format, ...) {
* Print a null-terminated variable length list of DOH objects
* ----------------------------------------------------------------------------- */
int DohPrintv(DOHFile *f, ...) {
int DohPrintv(DOHFile * f, ...) {
va_list ap;
int ret = 0;
DOH *obj;
va_start(ap,f);
while(1) {
obj = va_arg(ap,void *);
if ((!obj) || (obj == DohNone)) break;
va_start(ap, f);
while (1) {
obj = va_arg(ap, void *);
if ((!obj) || (obj == DohNone))
break;
if (DohCheck(obj)) {
ret += DohDump(obj,f);
ret += DohDump(obj, f);
} else {
ret += DohWrite(f,obj,strlen((char *) obj));
ret += DohWrite(f, obj, strlen((char *) obj));
}
}
va_end(ap);
@ -452,22 +463,23 @@ int DohPrintv(DOHFile *f, ...) {
* number of bytes copied.
* ----------------------------------------------------------------------------- */
int
DohCopyto(DOH *in, DOH *out) {
int DohCopyto(DOH *in, DOH *out) {
int nbytes = 0, ret;
int nwrite = 0, wret;
char *cw;
char buffer[16384];
if ((!in) || (!out)) return 0;
if ((!in) || (!out))
return 0;
while (1) {
ret = Read(in,buffer,16384);
ret = Read(in, buffer, 16384);
if (ret > 0) {
nwrite = ret;
cw = buffer;
while (nwrite) {
wret = Write(out,cw,nwrite);
if (wret < 0) return -1;
wret = Write(out, cw, nwrite);
if (wret < 0)
return -1;
nwrite = nwrite - wret;
cw += wret;
}
@ -486,16 +498,15 @@ DohCopyto(DOH *in, DOH *out) {
* character. Optionally accepts a maximum number of splits to perform.
* ----------------------------------------------------------------------------- */
DOH *
DohSplit(DOH *in, char ch, int nsplits) {
DOH *DohSplit(DOH *in, char ch, int nsplits) {
DOH *list;
DOH *str;
int c;
list = NewList();
if (DohIsString(in)) {
Seek(in,0,SEEK_SET);
Seek(in, 0, SEEK_SET);
}
while (1) {
@ -504,17 +515,19 @@ DohSplit(DOH *in, char ch, int nsplits) {
c = Getc(in);
} while ((c != EOF) && (c == ch));
if (c != EOF) {
Putc(c,str);
Putc(c, str);
while (1) {
c = Getc(in);
if ((c == EOF) || ((c == ch) && (nsplits != 0))) break;
Putc(c,str);
if ((c == EOF) || ((c == ch) && (nsplits != 0)))
break;
Putc(c, str);
}
nsplits--;
}
Append(list,str);
Append(list, str);
Delete(str);
if (c == EOF) break;
if (c == EOF)
break;
}
return list;
}
@ -525,16 +538,15 @@ DohSplit(DOH *in, char ch, int nsplits) {
* Split an input stream into a list of strings delimited by newline characters.
* ----------------------------------------------------------------------------- */
DOH *
DohSplitLines(DOH *in) {
DOH *DohSplitLines(DOH *in) {
DOH *list;
DOH *str;
int c = 0;
int c = 0;
list = NewList();
if (DohIsString(in)) {
Seek(in,0,SEEK_SET);
Seek(in, 0, SEEK_SET);
}
while (c != EOF) {
@ -542,7 +554,7 @@ DohSplitLines(DOH *in) {
while ((c = Getc(in)) != '\n' && c != EOF) {
Putc(c, str);
}
Append(list,str);
Append(list, str);
Delete(str);
}
return list;
@ -555,24 +567,23 @@ DohSplitLines(DOH *in) {
* Read a single input line and return it as a string.
* ----------------------------------------------------------------------------- */
DOH *
DohReadline(DOH *in) {
DOH *DohReadline(DOH *in) {
char c;
int n = 0;
DOH *s = NewStringEmpty();
while (1) {
if (Read(in,&c,1) < 0) {
if (Read(in, &c, 1) < 0) {
if (n == 0) {
Delete(s);
return 0;
}
return s;
}
if (c == '\n') return s;
if (c == '\r') continue;
Putc(c,s);
if (c == '\n')
return s;
if (c == '\r')
continue;
Putc(c, s);
n++;
}
}

View File

@ -17,59 +17,65 @@ extern DohObjInfo DohHashType;
/* Hash node */
typedef struct HashNode {
DOH *key;
DOH *object;
struct HashNode *next;
DOH *key;
DOH *object;
struct HashNode *next;
} HashNode;
/* Hash object */
typedef struct Hash {
DOH *file;
int line;
HashNode **hashtable;
int hashsize;
int nitems;
DOH *file;
int line;
HashNode **hashtable;
int hashsize;
int nitems;
} Hash;
/* Key interning structure */
typedef struct KeyValue {
char *cstr;
DOH *sstr;
struct KeyValue *left;
struct KeyValue *right;
char *cstr;
DOH *sstr;
struct KeyValue *left;
struct KeyValue *right;
} KeyValue;
static KeyValue *root = 0;
/* Find or create a key in the interned key table */
static DOH *find_key (DOH *doh_c) {
static DOH *find_key(DOH *doh_c) {
char *c = (char *) doh_c;
KeyValue *r, *s;
int d = 0;
/* OK, sure, we use a binary tree for maintaining interned
symbols. Then we use their hash values for accessing secondary
hash tables. */
hash tables. */
r = root;
s = 0;
while (r) {
s = r;
d = strcmp(r->cstr,c);
if (d == 0) return r->sstr;
if (d < 0) r = r->left;
else r = r->right;
d = strcmp(r->cstr, c);
if (d == 0)
return r->sstr;
if (d < 0)
r = r->left;
else
r = r->right;
}
/* fprintf(stderr,"Interning '%s'\n", c);*/
/* fprintf(stderr,"Interning '%s'\n", c); */
r = (KeyValue *) DohMalloc(sizeof(KeyValue));
r->cstr = (char *) DohMalloc(strlen(c)+1);
strcpy(r->cstr,c);
r->cstr = (char *) DohMalloc(strlen(c) + 1);
strcpy(r->cstr, c);
r->sstr = NewString(c);
DohIntern(r->sstr);
r->left = 0;
r->right = 0;
if (!s) { root = r; }
else {
if (d < 0) s->left = r;
else s->right = r;
if (!s) {
root = r;
} else {
if (d < 0)
s->left = r;
else
s->right = r;
}
return r->sstr;
}
@ -78,20 +84,20 @@ static DOH *find_key (DOH *doh_c) {
/* Create a new hash node */
static HashNode *NewNode(DOH *k, void *obj) {
HashNode *hn = (HashNode *) DohMalloc(sizeof(HashNode));
hn->key = k;
Incref(hn->key);
hn->object = obj;
Incref(obj);
hn->next = 0;
return hn;
HashNode *hn = (HashNode *) DohMalloc(sizeof(HashNode));
hn->key = k;
Incref(hn->key);
hn->object = obj;
Incref(obj);
hn->next = 0;
return hn;
}
/* Delete a hash node */
static void DelNode(HashNode *hn) {
Delete(hn->key);
Delete(hn->object);
DohFree(hn);
Delete(hn->key);
Delete(hn->object);
DohFree(hn);
}
/* -----------------------------------------------------------------------------
@ -100,25 +106,24 @@ static void DelNode(HashNode *hn) {
* Delete a hash table.
* ----------------------------------------------------------------------------- */
static void
DelHash(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
HashNode *n,*next;
int i;
static void DelHash(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
HashNode *n, *next;
int i;
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
next = n->next;
DelNode(n);
n = next;
}
}
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
next = n->next;
DelNode(n);
n = next;
}
}
DohFree(h->hashtable);
h->hashtable = 0;
h->hashsize = 0;
DohFree(h);
}
DohFree(h->hashtable);
h->hashtable = 0;
h->hashsize = 0;
DohFree(h);
}
/* -----------------------------------------------------------------------------
@ -127,67 +132,67 @@ DelHash(DOH *ho) {
* Clear all of the entries in the hash table.
* ----------------------------------------------------------------------------- */
static void
Hash_clear(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
HashNode *n,*next;
int i;
static void Hash_clear(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
HashNode *n, *next;
int i;
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
next = n->next;
DelNode(n);
n = next;
}
}
h->hashtable[i] = 0;
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
next = n->next;
DelNode(n);
n = next;
}
}
h->nitems = 0;
h->hashtable[i] = 0;
}
h->nitems = 0;
}
/* resize the hash table */
static void resize(Hash *h) {
HashNode *n, *next, **table;
int oldsize, newsize;
int i, p, hv;
HashNode *n, *next, **table;
int oldsize, newsize;
int i, p, hv;
if (h->nitems < 2*h->hashsize) return;
if (h->nitems < 2 * h->hashsize)
return;
/* Too big. We have to rescale everything now */
oldsize = h->hashsize;
/* Too big. We have to rescale everything now */
oldsize = h->hashsize;
/* Calculate a new size */
newsize = 2*oldsize+1;
p = 3;
while (p < (newsize >> 1)) {
if (((newsize/p)*p) == newsize) {
newsize+=2;
p = 3;
continue;
}
p = p + 2;
/* Calculate a new size */
newsize = 2 * oldsize + 1;
p = 3;
while (p < (newsize >> 1)) {
if (((newsize / p) * p) == newsize) {
newsize += 2;
p = 3;
continue;
}
p = p + 2;
}
table = (HashNode **) DohMalloc(newsize*sizeof(HashNode *));
for (i = 0; i < newsize; i++ ) {
table[i] = 0;
}
table = (HashNode **) DohMalloc(newsize * sizeof(HashNode *));
for (i = 0; i < newsize; i++) {
table[i] = 0;
}
/* Walk down the old set of nodes and re-place */
h->hashsize = newsize;
for (i = 0; i < oldsize; i++) {
n = h->hashtable[i];
while (n) {
hv = Hashval(n->key) % newsize;
next = n->next;
n->next = table[hv];
table[hv] = n;
n = next;
}
/* Walk down the old set of nodes and re-place */
h->hashsize = newsize;
for (i = 0; i < oldsize; i++) {
n = h->hashtable[i];
while (n) {
hv = Hashval(n->key) % newsize;
next = n->next;
n->next = table[hv];
table[hv] = n;
n = next;
}
DohFree(h->hashtable);
h->hashtable = table;
}
DohFree(h->hashtable);
h->hashtable = table;
}
/* -----------------------------------------------------------------------------
@ -197,46 +202,48 @@ static void resize(Hash *h) {
* exists.
* ----------------------------------------------------------------------------- */
static int
Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
int hv;
HashNode *n, *prev;
Hash *h = (Hash *) ObjData(ho);
if (!obj) {
return DohDelattr(ho,k);
}
if (!DohCheck(k)) k = find_key(k);
if (!DohCheck(obj)) {
obj = NewString((char *) obj);
Decref(obj);
}
hv = (Hashval(k)) % h->hashsize;
n = h->hashtable[hv];
prev = 0;
while (n) {
if (Cmp(n->key,k) == 0) {
/* Node already exists. Just replace its contents */
if (n->object == obj) {
/* Whoa. Same object. Do nothing */
return 1;
}
Delete(n->object);
n->object = obj;
Incref(obj);
return 1; /* Return 1 to indicate a replacement */
} else {
prev = n;
n = n->next;
static int Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
int hv;
HashNode *n, *prev;
Hash *h = (Hash *) ObjData(ho);
if (!obj) {
return DohDelattr(ho, k);
}
if (!DohCheck(k))
k = find_key(k);
if (!DohCheck(obj)) {
obj = NewString((char *) obj);
Decref(obj);
}
hv = (Hashval(k)) % h->hashsize;
n = h->hashtable[hv];
prev = 0;
while (n) {
if (Cmp(n->key, k) == 0) {
/* Node already exists. Just replace its contents */
if (n->object == obj) {
/* Whoa. Same object. Do nothing */
return 1;
}
Delete(n->object);
n->object = obj;
Incref(obj);
return 1; /* Return 1 to indicate a replacement */
} else {
prev = n;
n = n->next;
}
/* Add this to the table */
n = NewNode(k,obj);
if (prev) prev->next = n;
else h->hashtable[hv] = n;
h->nitems++;
resize(h);
return 0;
}
/* Add this to the table */
n = NewNode(k, obj);
if (prev)
prev->next = n;
else
h->hashtable[hv] = n;
h->nitems++;
resize(h);
return 0;
}
/* -----------------------------------------------------------------------------
@ -244,7 +251,7 @@ Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
*
* Get an attribute from the hash table. Returns 0 if it doesn't exist.
* ----------------------------------------------------------------------------- */
typedef int (*binop)(DOH *obj1, DOH *obj2);
typedef int (*binop) (DOH *obj1, DOH *obj2);
#define _Hash_getattr(h, k, o) \
int hv = Hashval(k) % h->hashsize; \
@ -267,8 +274,7 @@ typedef int (*binop)(DOH *obj1, DOH *obj2);
}
static DOH *
Hash_getattr(DOH *h, DOH *k) {
static DOH *Hash_getattr(DOH *h, DOH *k) {
DOH *obj = 0;
Hash *ho = (Hash *) ObjData(h);
DOH *ko = DohCheck(k) ? k : find_key(k);
@ -276,8 +282,7 @@ Hash_getattr(DOH *h, DOH *k) {
return obj;
}
DOH *
DohHashGetAttr(DOH *h, const DOH *k) {
DOH *DohHashGetAttr(DOH *h, const DOH *k) {
DOH *obj = 0;
Hash *ho = (Hash *) ObjData(h);
_Hash_getattr(ho, (DOH *) k, obj);
@ -291,14 +296,13 @@ DohHashGetAttr(DOH *h, const DOH *k) {
* Check an attribute from the hash table.
* ----------------------------------------------------------------------------- */
int
DohHashCheckAttr(DOH *h, DOH *k, DOH *v) {
int DohHashCheckAttr(DOH *h, DOH *k, DOH *v) {
DOH *obj = 0;
Hash *ho = (Hash *) ObjData(h);
_Hash_getattr(ho, k, obj);
if (obj) {
DohObjInfo *o_type = ((DohBase*)obj)->type;
if (o_type == ((DohBase*)v)->type) {
DohObjInfo *o_type = ((DohBase *) obj)->type;
if (o_type == ((DohBase *) v)->type) {
binop equal = o_type->doh_equal;
return equal ? equal(obj, v) : (o_type->doh_cmp(obj, v) == 0);
}
@ -312,44 +316,43 @@ DohHashCheckAttr(DOH *h, DOH *k, DOH *v) {
* Delete an object from the hash table.
* ----------------------------------------------------------------------------- */
static int
Hash_delattr(DOH *ho, DOH *k) {
HashNode *n, *prev;
int hv;
Hash *h = (Hash *) ObjData(ho);
static int Hash_delattr(DOH *ho, DOH *k) {
HashNode *n, *prev;
int hv;
Hash *h = (Hash *) ObjData(ho);
if (!DohCheck(k)) k = find_key(k);
hv = Hashval(k) % h->hashsize;
n = h->hashtable[hv];
prev = 0;
while (n) {
if (Cmp(n->key, k) == 0) {
/* Found it, kill it */
if (!DohCheck(k))
k = find_key(k);
hv = Hashval(k) % h->hashsize;
n = h->hashtable[hv];
prev = 0;
while (n) {
if (Cmp(n->key, k) == 0) {
/* Found it, kill it */
if (prev) {
prev->next = n->next;
} else {
h->hashtable[hv] = n->next;
}
DelNode(n);
h->nitems--;
return 1;
}
prev = n;
n = n->next;
if (prev) {
prev->next = n->next;
} else {
h->hashtable[hv] = n->next;
}
DelNode(n);
h->nitems--;
return 1;
}
return 0;
prev = n;
n = n->next;
}
return 0;
}
static DohIterator
Hash_firstiter(DOH *ho) {
static DohIterator Hash_firstiter(DOH *ho) {
DohIterator iter;
Hash *h = (Hash *) ObjData(ho);
iter.object = ho;
iter._current = 0;
iter.item = 0;
iter.key = 0;
iter._index = 0; /* Index in hash table */
iter._index = 0; /* Index in hash table */
while ((iter._index < h->hashsize) && !h->hashtable[iter._index])
iter._index++;
@ -359,15 +362,14 @@ Hash_firstiter(DOH *ho) {
iter._current = h->hashtable[iter._index];
iter.item = ((HashNode *) iter._current)->object;
iter.key = ((HashNode *) iter._current)->key;
/* Actually save the next slot in the hash. This makes it possible to
delete the item being iterated over without trashing the universe */
iter._current = ((HashNode*)iter._current)->next;
iter._current = ((HashNode *) iter._current)->next;
return iter;
}
static DohIterator
Hash_nextiter(DohIterator iter) {
static DohIterator Hash_nextiter(DohIterator iter) {
Hash *h = (Hash *) ObjData(iter.object);
if (!iter._current) {
iter._index++;
@ -386,7 +388,7 @@ Hash_nextiter(DohIterator iter) {
iter.item = ((HashNode *) iter._current)->object;
/* Store the next node to iterator on */
iter._current = ((HashNode*)iter._current)->next;
iter._current = ((HashNode *) iter._current)->next;
return iter;
}
@ -396,14 +398,13 @@ Hash_nextiter(DohIterator iter) {
* Return a list of keys
* ----------------------------------------------------------------------------- */
static DOH *
Hash_keys(DOH *so) {
static DOH *Hash_keys(DOH *so) {
DOH *keys;
Iterator i;
keys = NewList();
for (i = First(so); i.key; i = Next(i)) {
Append(keys,i.key);
Append(keys, i.key);
}
return keys;
}
@ -414,35 +415,36 @@ Hash_keys(DOH *so) {
* Create a string representation of a hash table (mainly for debugging).
* ----------------------------------------------------------------------------- */
static DOH *
Hash_str(DOH *ho) {
int i,j;
HashNode *n;
DOH *s;
static int indent = 4;
Hash *h = (Hash *) ObjData(ho);
static DOH *Hash_str(DOH *ho) {
int i, j;
HashNode *n;
DOH *s;
static int indent = 4;
Hash *h = (Hash *) ObjData(ho);
s = NewStringEmpty();
if (ObjGetMark(ho)) {
Printf(s,"Hash(0x%x)",ho);
return s;
}
ObjSetMark(ho,1);
Printf(s,"Hash {\n");
for (i = 0; i < h->hashsize; i++) {
n = h->hashtable[i];
while (n) {
for (j = 0; j < indent; j++) Putc(' ',s);
indent+=4;
Printf(s,"'%s' : %s, \n", n->key, n->object);
indent-=4;
n = n->next;
}
}
for (j = 0; j < (indent-4); j++) Putc(' ',s);
Printf(s,"}\n");
ObjSetMark(ho,0);
s = NewStringEmpty();
if (ObjGetMark(ho)) {
Printf(s, "Hash(0x%x)", ho);
return s;
}
ObjSetMark(ho, 1);
Printf(s, "Hash {\n");
for (i = 0; i < h->hashsize; i++) {
n = h->hashtable[i];
while (n) {
for (j = 0; j < indent; j++)
Putc(' ', s);
indent += 4;
Printf(s, "'%s' : %s, \n", n->key, n->object);
indent -= 4;
n = n->next;
}
}
for (j = 0; j < (indent - 4); j++)
Putc(' ', s);
Printf(s, "}\n");
ObjSetMark(ho, 0);
return s;
}
/* -----------------------------------------------------------------------------
@ -451,8 +453,7 @@ Hash_str(DOH *ho) {
* Return number of entries in the hash table.
* ----------------------------------------------------------------------------- */
static int
Hash_len(DOH *ho) {
static int Hash_len(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
return h->nitems;
}
@ -463,67 +464,64 @@ Hash_len(DOH *ho) {
* Make a copy of a hash table. Note: this is a shallow copy.
* ----------------------------------------------------------------------------- */
static DOH *
CopyHash(DOH *ho) {
Hash *h, *nh;
HashNode *n;
DOH *nho;
int i;
h = (Hash *) ObjData(ho);
nh = (Hash *) DohMalloc(sizeof(Hash));
nh->hashsize = h->hashsize;
nh->hashtable = (HashNode **) DohMalloc(nh->hashsize*sizeof(HashNode *));
for (i = 0; i < nh->hashsize; i++) {
nh->hashtable[i] = 0;
}
nh->nitems = 0;
nh->line = h->line;
nh->file = h->file;
if (nh->file) Incref(nh->file);
static DOH *CopyHash(DOH *ho) {
Hash *h, *nh;
HashNode *n;
DOH *nho;
nho = DohObjMalloc(&DohHashType, nh);
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
Hash_setattr(nho, n->key, n->object);
n = n->next;
}
}
int i;
h = (Hash *) ObjData(ho);
nh = (Hash *) DohMalloc(sizeof(Hash));
nh->hashsize = h->hashsize;
nh->hashtable = (HashNode **) DohMalloc(nh->hashsize * sizeof(HashNode *));
for (i = 0; i < nh->hashsize; i++) {
nh->hashtable[i] = 0;
}
nh->nitems = 0;
nh->line = h->line;
nh->file = h->file;
if (nh->file)
Incref(nh->file);
nho = DohObjMalloc(&DohHashType, nh);
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
Hash_setattr(nho, n->key, n->object);
n = n->next;
}
}
return nho;
}
return nho;
}
static void
Hash_setfile(DOH *ho, DOH *file) {
static void Hash_setfile(DOH *ho, DOH *file) {
DOH *fo;
Hash *h = (Hash *) ObjData(ho);
if (!DohCheck(file)) {
fo = NewString(file);
Decref(fo);
} else fo = file;
} else
fo = file;
Incref(fo);
Delete(h->file);
h->file = fo;
}
static DOH *
Hash_getfile(DOH *ho) {
static DOH *Hash_getfile(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
return h->file;
}
static void
Hash_setline(DOH *ho, int line) {
static void Hash_setline(DOH *ho, int line) {
Hash *h = (Hash *) ObjData(ho);
h->line = line;
}
static int
Hash_getline(DOH *ho) {
static int Hash_getline(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
return h->line;
}
@ -540,29 +538,29 @@ static DohHashMethods HashHashMethods = {
};
DohObjInfo DohHashType = {
"Hash", /* objname */
DelHash, /* doh_del */
CopyHash, /* doh_copy */
Hash_clear, /* doh_clear */
Hash_str, /* doh_str */
0, /* doh_data */
0, /* doh_dump */
Hash_len, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
Hash_firstiter, /* doh_first */
Hash_nextiter, /* doh_next */
Hash_setfile, /* doh_setfile */
Hash_getfile, /* doh_getfile */
Hash_setline, /* doh_setline */
Hash_getline, /* doh_getline */
&HashHashMethods, /* doh_mapping */
0, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_positional */
0,
"Hash", /* objname */
DelHash, /* doh_del */
CopyHash, /* doh_copy */
Hash_clear, /* doh_clear */
Hash_str, /* doh_str */
0, /* doh_data */
0, /* doh_dump */
Hash_len, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
Hash_firstiter, /* doh_first */
Hash_nextiter, /* doh_next */
Hash_setfile, /* doh_setfile */
Hash_getfile, /* doh_getfile */
Hash_setline, /* doh_setline */
Hash_getline, /* doh_getline */
&HashHashMethods, /* doh_mapping */
0, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_positional */
0,
};
/* -----------------------------------------------------------------------------
@ -571,18 +569,17 @@ DohObjInfo DohHashType = {
* Create a new hash table.
* ----------------------------------------------------------------------------- */
DOH *
DohNewHash() {
Hash *h;
int i;
h = (Hash *) DohMalloc(sizeof(Hash));
h->hashsize = HASH_INIT_SIZE;
h->hashtable = (HashNode **) DohMalloc(h->hashsize*sizeof(HashNode *));
for (i = 0; i < h->hashsize; i++) {
h->hashtable[i] = 0;
}
h->nitems = 0;
h->file = 0;
h->line = 0;
return DohObjMalloc(&DohHashType,h);
DOH *DohNewHash() {
Hash *h;
int i;
h = (Hash *) DohMalloc(sizeof(Hash));
h->hashsize = HASH_INIT_SIZE;
h->hashtable = (HashNode **) DohMalloc(h->hashsize * sizeof(HashNode *));
for (i = 0; i < h->hashsize; i++) {
h->hashtable[i] = 0;
}
h->nitems = 0;
h->file = 0;
h->line = 0;
return DohObjMalloc(&DohHashType, h);
}

View File

@ -14,21 +14,21 @@ char cvsroot_list_c[] = "$Header$";
#include "dohint.h"
typedef struct List {
int maxitems; /* Max size */
int nitems; /* Num items */
DOH *file;
int line;
DOH **items;
int maxitems; /* Max size */
int nitems; /* Num items */
DOH *file;
int line;
DOH **items;
} List;
extern DohObjInfo DohListType;
/* Doubles amount of memory in a list */
static
static
void more(List *l) {
l->items = (void **) DohRealloc(l->items, l->maxitems*2*sizeof(void *));
assert(l->items);
l->maxitems *= 2;
l->items = (void **) DohRealloc(l->items, l->maxitems * 2 * sizeof(void *));
assert(l->items);
l->maxitems *= 2;
}
/* -----------------------------------------------------------------------------
@ -36,23 +36,23 @@ void more(List *l) {
*
* Make a shallow copy of a list.
* ----------------------------------------------------------------------------- */
static DOH *
CopyList(DOH *lo) {
List *l,*nl;
int i;
l = (List *) ObjData(lo);
nl = (List *) DohMalloc(sizeof(List));
nl->nitems = l->nitems;
nl->maxitems = l->maxitems;
nl->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
for (i = 0; i < l->nitems; i++) {
nl->items[i] = l->items[i];
Incref(nl->items[i]);
}
nl->file = l->file;
if (nl->file) Incref(nl->file);
nl->line = l->line;
return DohObjMalloc(&DohListType, nl);
static DOH *CopyList(DOH *lo) {
List *l, *nl;
int i;
l = (List *) ObjData(lo);
nl = (List *) DohMalloc(sizeof(List));
nl->nitems = l->nitems;
nl->maxitems = l->maxitems;
nl->items = (void **) DohMalloc(l->maxitems * sizeof(void *));
for (i = 0; i < l->nitems; i++) {
nl->items[i] = l->items[i];
Incref(nl->items[i]);
}
nl->file = l->file;
if (nl->file)
Incref(nl->file);
nl->line = l->line;
return DohObjMalloc(&DohListType, nl);
}
/* -----------------------------------------------------------------------------
@ -61,14 +61,13 @@ CopyList(DOH *lo) {
* Delete a list.
* ----------------------------------------------------------------------------- */
static void
DelList(DOH *lo) {
List *l = (List *) ObjData(lo);
int i;
for (i = 0; i < l->nitems; i++)
Delete(l->items[i]);
DohFree(l->items);
DohFree(l);
static void DelList(DOH *lo) {
List *l = (List *) ObjData(lo);
int i;
for (i = 0; i < l->nitems; i++)
Delete(l->items[i]);
DohFree(l->items);
DohFree(l);
}
/* -----------------------------------------------------------------------------
@ -77,14 +76,13 @@ DelList(DOH *lo) {
* Remove all of the list entries, but keep the list object intact.
* ----------------------------------------------------------------------------- */
static void
List_clear(DOH *lo) {
List *l = (List *) ObjData(lo);
int i;
for (i = 0; i < l->nitems; i++) {
Delete(l->items[i]);
}
l->nitems = 0;
static void List_clear(DOH *lo) {
List *l = (List *) ObjData(lo);
int i;
for (i = 0; i < l->nitems; i++) {
Delete(l->items[i]);
}
l->nitems = 0;
}
/* -----------------------------------------------------------------------------
@ -94,22 +92,26 @@ List_clear(DOH *lo) {
* to be a 'char *' and is used to construct an equivalent string object.
* ----------------------------------------------------------------------------- */
static int
List_insert(DOH *lo, int pos, DOH *item) {
static int List_insert(DOH *lo, int pos, DOH *item) {
List *l = (List *) ObjData(lo);
int i;
if (!item) return -1;
if (!item)
return -1;
if (!DohCheck(item)) {
item = NewString(item);
Decref(item);
}
if (pos == DOH_END) pos = l->nitems;
if (pos < 0) pos = 0;
if (pos > l->nitems) pos = l->nitems;
if (l->nitems == l->maxitems) more(l);
if (pos == DOH_END)
pos = l->nitems;
if (pos < 0)
pos = 0;
if (pos > l->nitems)
pos = l->nitems;
if (l->nitems == l->maxitems)
more(l);
for (i = l->nitems; i > pos; i--) {
l->items[i] = l->items[i-1];
l->items[i] = l->items[i - 1];
}
l->items[pos] = item;
Incref(item);
@ -122,20 +124,21 @@ List_insert(DOH *lo, int pos, DOH *item) {
*
* Remove an item from a list.
* ----------------------------------------------------------------------------- */
static int
List_remove(DOH *lo, int pos) {
List *l = (List *) ObjData(lo);
int i;
if (pos == DOH_END) pos = l->nitems-1;
if (pos == DOH_BEGIN) pos = 0;
assert(!((pos < 0) || (pos >= l->nitems)));
Delete(l->items[pos]);
for (i = pos; i < l->nitems-1; i++) {
l->items[i] = l->items[i+1];
}
l->nitems--;
return 0;
static int List_remove(DOH *lo, int pos) {
List *l = (List *) ObjData(lo);
int i;
if (pos == DOH_END)
pos = l->nitems - 1;
if (pos == DOH_BEGIN)
pos = 0;
assert(!((pos < 0) || (pos >= l->nitems)));
Delete(l->items[pos]);
for (i = pos; i < l->nitems - 1; i++) {
l->items[i] = l->items[i + 1];
}
l->nitems--;
return 0;
}
/* -----------------------------------------------------------------------------
@ -144,8 +147,7 @@ List_remove(DOH *lo, int pos) {
* Return the number of elements in the list
* ----------------------------------------------------------------------------- */
static int
List_len(DOH *lo) {
static int List_len(DOH *lo) {
List *l = (List *) ObjData(lo);
return l->nitems;
}
@ -156,13 +158,14 @@ List_len(DOH *lo) {
* Get the nth item from the list.
* ----------------------------------------------------------------------------- */
static DOH *
List_get(DOH *lo, int n) {
List *l = (List *) ObjData(lo);
if (n == DOH_END) n = l->nitems-1;
if (n == DOH_BEGIN) n = 0;
assert(!((n < 0) || (n >= l->nitems)));
return l->items[n];
static DOH *List_get(DOH *lo, int n) {
List *l = (List *) ObjData(lo);
if (n == DOH_END)
n = l->nitems - 1;
if (n == DOH_BEGIN)
n = 0;
assert(!((n < 0) || (n >= l->nitems)));
return l->items[n];
}
/* -----------------------------------------------------------------------------
@ -171,20 +174,20 @@ List_get(DOH *lo, int n) {
* Set the nth item in the list replacing any previous item.
* ----------------------------------------------------------------------------- */
static int
List_set(DOH *lo, int n, DOH *val) {
List *l = (List *) ObjData(lo);
if (!val) return -1;
assert(!((n < 0) || (n >= l->nitems)));
if (!DohCheck(val)) {
val = NewString(val);
Decref(val);
}
Delete(l->items[n]);
l->items[n] = val;
Incref(val);
Delete(val);
return 0;
static int List_set(DOH *lo, int n, DOH *val) {
List *l = (List *) ObjData(lo);
if (!val)
return -1;
assert(!((n < 0) || (n >= l->nitems)));
if (!DohCheck(val)) {
val = NewString(val);
Decref(val);
}
Delete(l->items[n]);
l->items[n] = val;
Incref(val);
Delete(val);
return 0;
}
/* -----------------------------------------------------------------------------
@ -193,8 +196,7 @@ List_set(DOH *lo, int n, DOH *val) {
* Return the first item in the list.
* ----------------------------------------------------------------------------- */
static DohIterator
List_first(DOH *lo) {
static DohIterator List_first(DOH *lo) {
DohIterator iter;
List *l = (List *) ObjData(lo);
iter.object = lo;
@ -215,8 +217,7 @@ List_first(DOH *lo) {
* Return the next item in the list.
* ----------------------------------------------------------------------------- */
static DohIterator
List_next(DohIterator iter) {
static DohIterator List_next(DohIterator iter) {
List *l = (List *) ObjData(iter.object);
iter._index = iter._index + 1;
if (iter._index >= l->nitems) {
@ -233,26 +234,25 @@ List_next(DohIterator iter) {
*
* Create a string representation of the list.
* ----------------------------------------------------------------------------- */
static DOH *
List_str(DOH *lo) {
DOH *s;
int i;
List *l = (List *) ObjData(lo);
s = NewStringEmpty();
if (ObjGetMark(lo)) {
Printf(s,"List(%x)", lo);
return s;
}
ObjSetMark(lo,1);
Printf(s,"List[ ");
for (i = 0; i < l->nitems; i++) {
Printf(s, "%s", l->items[i]);
if ((i+1) < l->nitems)
Printf(s,", ");
}
Printf(s," ]\n");
ObjSetMark(lo,0);
static DOH *List_str(DOH *lo) {
DOH *s;
int i;
List *l = (List *) ObjData(lo);
s = NewStringEmpty();
if (ObjGetMark(lo)) {
Printf(s, "List(%x)", lo);
return s;
}
ObjSetMark(lo, 1);
Printf(s, "List[ ");
for (i = 0; i < l->nitems; i++) {
Printf(s, "%s", l->items[i]);
if ((i + 1) < l->nitems)
Printf(s, ", ");
}
Printf(s, " ]\n");
ObjSetMark(lo, 0);
return s;
}
/* -----------------------------------------------------------------------------
@ -261,41 +261,39 @@ List_str(DOH *lo) {
* Dump the items to an output stream.
* ----------------------------------------------------------------------------- */
static int
List_dump(DOH *lo, DOH *out) {
static int List_dump(DOH *lo, DOH *out) {
int nsent = 0;
int i,ret;
int i, ret;
List *l = (List *) ObjData(lo);
for (i = 0; i < l->nitems; i++) {
ret = Dump(l->items[i],out);
if (ret < 0) return -1;
ret = Dump(l->items[i], out);
if (ret < 0)
return -1;
nsent += ret;
}
return nsent;
}
static void
List_setfile(DOH *lo, DOH *file) {
static void List_setfile(DOH *lo, DOH *file) {
DOH *fo;
List *l = (List *) ObjData(lo);
if (!DohCheck(file)) {
fo = NewString(file);
Decref(fo);
} else fo = file;
} else
fo = file;
Incref(fo);
Delete(l->file);
l->file = fo;
}
static DOH *
List_getfile(DOH *lo) {
static DOH *List_getfile(DOH *lo) {
List *l = (List *) ObjData(lo);
return l->file;
}
static void
List_setline(DOH *lo, int line) {
static void List_setline(DOH *lo, int line) {
List *l = (List *) ObjData(lo);
l->line = line;
}
@ -310,33 +308,33 @@ static DohListMethods ListListMethods = {
List_set,
List_remove,
List_insert,
0, /* delslice */
0, /* delslice */
};
DohObjInfo DohListType = {
"List", /* objname */
DelList, /* doh_del */
CopyList, /* doh_copy */
List_clear, /* doh_clear */
List_str, /* doh_str */
0, /* doh_data */
List_dump, /* doh_dump */
List_len, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
List_first, /* doh_first */
List_next, /* doh_next */
List_setfile, /* doh_setfile */
List_getfile, /* doh_getfile */
List_setline, /* doh_setline */
List_getline, /* doh_getline */
0, /* doh_mapping */
&ListListMethods, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_callable */
0, /* doh_position */
"List", /* objname */
DelList, /* doh_del */
CopyList, /* doh_copy */
List_clear, /* doh_clear */
List_str, /* doh_str */
0, /* doh_data */
List_dump, /* doh_dump */
List_len, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
List_first, /* doh_first */
List_next, /* doh_next */
List_setfile, /* doh_setfile */
List_getfile, /* doh_getfile */
List_setline, /* doh_setline */
List_getline, /* doh_getline */
0, /* doh_mapping */
&ListListMethods, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_callable */
0, /* doh_position */
};
/* -----------------------------------------------------------------------------
@ -347,29 +345,28 @@ DohObjInfo DohListType = {
#define MAXLISTITEMS 8
DOH *
DohNewList() {
List *l;
int i;
l = (List *) DohMalloc(sizeof(List));
l->nitems = 0;
l->maxitems = MAXLISTITEMS;
l->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
for (i = 0; i < MAXLISTITEMS; i++) {
l->items[i] = 0;
}
l->file = 0;
l->line = 0;
return DohObjMalloc(&DohListType,l);
DOH *DohNewList() {
List *l;
int i;
l = (List *) DohMalloc(sizeof(List));
l->nitems = 0;
l->maxitems = MAXLISTITEMS;
l->items = (void **) DohMalloc(l->maxitems * sizeof(void *));
for (i = 0; i < MAXLISTITEMS; i++) {
l->items[i] = 0;
}
l->file = 0;
l->line = 0;
return DohObjMalloc(&DohListType, l);
}
static int (*List_sort_compare_func)(const DOH *, const DOH *);
static int (*List_sort_compare_func) (const DOH *, const DOH *);
static int List_qsort_compare(const void *a, const void *b) {
return List_sort_compare_func(*((DOH **)a), *((DOH **)b));
return List_sort_compare_func(*((DOH **) a), *((DOH **) b));
}
/* Sort a list */
void DohSortList(DOH *lo, int (*cmp)(const DOH *, const DOH *)) {
void DohSortList(DOH *lo, int (*cmp) (const DOH *, const DOH *)) {
List *l = (List *) ObjData(lo);
if (cmp) {
List_sort_compare_func = cmp;

View File

@ -18,40 +18,39 @@ char cvsroot_memory_c[] = "$Header$";
#define DOH_POOL_SIZE 16384
#endif
static int PoolSize = DOH_POOL_SIZE;
static int PoolSize = DOH_POOL_SIZE;
DOH *DohNone = 0; /* The DOH None object */
DOH *DohNone = 0; /* The DOH None object */
typedef struct pool {
DohBase *ptr; /* Start of pool */
int len; /* Length of pool */
int blen; /* Byte length of pool */
int current; /* Current position for next allocation */
char* pbeg; /* Beg of pool */
char* pend; /* End of pool */
struct pool *next; /* Next pool */
DohBase *ptr; /* Start of pool */
int len; /* Length of pool */
int blen; /* Byte length of pool */
int current; /* Current position for next allocation */
char *pbeg; /* Beg of pool */
char *pend; /* End of pool */
struct pool *next; /* Next pool */
} Pool;
static DohBase *FreeList = 0; /* List of free objects */
static Pool *Pools = 0;
static int pools_initialized = 0;
static DohBase *FreeList = 0; /* List of free objects */
static Pool *Pools = 0;
static int pools_initialized = 0;
/* ----------------------------------------------------------------------
* CreatePool() - Create a new memory pool
* ---------------------------------------------------------------------- */
static void
CreatePool() {
static void CreatePool() {
Pool *p = 0;
p = (Pool *) DohMalloc(sizeof(Pool));
assert(p);
p->ptr = (DohBase *) DohMalloc(sizeof(DohBase)*PoolSize);
p->ptr = (DohBase *) DohMalloc(sizeof(DohBase) * PoolSize);
assert(p->ptr);
memset(p->ptr,0,sizeof(DohBase)*PoolSize);
memset(p->ptr, 0, sizeof(DohBase) * PoolSize);
p->len = PoolSize;
p->blen = PoolSize*sizeof(DohBase);
p->blen = PoolSize * sizeof(DohBase);
p->current = 0;
p->pbeg = ((char *)p->ptr);
p->pbeg = ((char *) p->ptr);
p->pend = p->pbeg + p->blen;
p->next = Pools;
Pools = p;
@ -61,12 +60,12 @@ CreatePool() {
* InitPools() - Initialize the memory allocator
* ---------------------------------------------------------------------- */
static void
InitPools() {
if (pools_initialized) return;
CreatePool(); /* Create initial pool */
static void InitPools() {
if (pools_initialized)
return;
CreatePool(); /* Create initial pool */
pools_initialized = 1;
DohNone = NewVoid(0,0); /* Create the None object */
DohNone = NewVoid(0, 0); /* Create the None object */
DohIntern(DohNone);
}
@ -76,15 +75,15 @@ InitPools() {
* Returns 1 if an arbitrary pointer is a DOH object.
* ---------------------------------------------------------------------- */
int
DohCheck(const DOH *ptr) {
int DohCheck(const DOH *ptr) {
register Pool *p = Pools;
register char *cptr = (char *) ptr;
while (p) {
if ((cptr >= p->pbeg) && (cptr < p->pend)) return 1;
if ((cptr >= p->pbeg) && (cptr < p->pend))
return 1;
/*
pptr = (char *) p->ptr;
if ((cptr >= pptr) && (cptr < (pptr+(p->current*sizeof(DohBase))))) return 1; */
pptr = (char *) p->ptr;
if ((cptr >= pptr) && (cptr < (pptr+(p->current*sizeof(DohBase))))) return 1; */
p = p->next;
}
return 0;
@ -94,8 +93,7 @@ DohCheck(const DOH *ptr) {
* DohIntern()
* ----------------------------------------------------------------------------- */
void
DohIntern(DOH *obj) {
void DohIntern(DOH *obj) {
DohBase *b = (DohBase *) obj;
b->flag_intern = 1;
}
@ -106,10 +104,10 @@ DohIntern(DOH *obj) {
* Allocate memory for a new object.
* ---------------------------------------------------------------------- */
DOH *
DohObjMalloc(DohObjInfo *type, void *data) {
DOH *DohObjMalloc(DohObjInfo *type, void *data) {
DohBase *obj;
if (!pools_initialized) InitPools();
if (!pools_initialized)
InitPools();
if (FreeList) {
obj = FreeList;
FreeList = (DohBase *) obj->data;
@ -135,12 +133,12 @@ DohObjMalloc(DohObjInfo *type, void *data) {
* DohObjFree() - Free a DOH object
* ---------------------------------------------------------------------- */
void
DohObjFree(DOH *ptr) {
DohBase *b, *meta;
void DohObjFree(DOH *ptr) {
DohBase *b, *meta;
b = (DohBase *) ptr;
if (b->flag_intern) return;
meta = (DohBase *)b->meta;
if (b->flag_intern)
return;
meta = (DohBase *) b->meta;
b->data = (void *) FreeList;
b->meta = 0;
b->type = 0;
@ -156,42 +154,45 @@ DohObjFree(DOH *ptr) {
* Display memory usage statistics
* ---------------------------------------------------------------------- */
void
DohMemoryDebug(void) {
void DohMemoryDebug(void) {
extern DohObjInfo DohStringType;
extern DohObjInfo DohListType;
extern DohObjInfo DohHashType;
Pool *p;
int totsize = 0;
int totused = 0;
int totfree = 0;
int totsize = 0;
int totused = 0;
int totfree = 0;
int numstring = 0;
int numlist = 0;
int numhash = 0;
int numstring = 0;
int numlist = 0;
int numhash = 0;
printf("Memory statistics:\n\n");
printf("Pools:\n");
p = Pools;
while(p) {
while (p) {
/* Calculate number of used, free items */
int i;
int nused = 0, nfree = 0;
for (i = 0; i < p->len; i++) {
if (p->ptr[i].refcount <= 0) nfree++;
if (p->ptr[i].refcount <= 0)
nfree++;
else {
nused++;
if (p->ptr[i].type == &DohStringType) numstring++;
else if (p->ptr[i].type == &DohListType) numlist++;
else if (p->ptr[i].type == &DohHashType) numhash++;
if (p->ptr[i].type == &DohStringType)
numstring++;
else if (p->ptr[i].type == &DohListType)
numlist++;
else if (p->ptr[i].type == &DohHashType)
numhash++;
}
}
printf(" Pool %8p: size = %10d. used = %10d. free = %10d\n", (void *)p, p->len, nused, nfree);
printf(" Pool %8p: size = %10d. used = %10d. free = %10d\n", (void *) p, p->len, nused, nfree);
totsize += p->len;
totused+= nused;
totfree+= nfree;
totused += nused;
totfree += nfree;
p = p->next;
}
printf("\n Total: size = %10d, used = %10d, free = %10d\n", totsize, totused, totfree);
@ -203,12 +204,12 @@ DohMemoryDebug(void) {
#if 0
p = Pools;
while(p) {
while (p) {
int i;
for (i = 0; i < p->len; i++) {
if (p->ptr[i].refcount > 0) {
if (p->ptr[i].type == &DohStringType) {
Printf(stdout,"%s\n", p->ptr+i);
Printf(stdout, "%s\n", p->ptr + i);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -15,8 +15,8 @@ char cvsroot_void_c[] = "$Header$";
#include "dohint.h"
typedef struct {
void *ptr;
void (*del)(void *);
void *ptr;
void (*del) (void *);
} VoidObj;
/* -----------------------------------------------------------------------------
@ -25,11 +25,10 @@ typedef struct {
* Delete a void object. Invokes the destructor supplied at the time of creation.
* ----------------------------------------------------------------------------- */
static void
Void_delete(DOH *vo) {
static void Void_delete(DOH *vo) {
VoidObj *v = (VoidObj *) ObjData(vo);
if (v->del)
(*v->del)(v->ptr);
(*v->del) (v->ptr);
DohFree(v);
}
@ -40,10 +39,9 @@ Void_delete(DOH *vo) {
* function is not copied in order to avoid potential double-free problems.
* ----------------------------------------------------------------------------- */
static DOH *
Void_copy(DOH *vo) {
static DOH *Void_copy(DOH *vo) {
VoidObj *v = (VoidObj *) ObjData(vo);
return NewVoid(v->ptr,0);
return NewVoid(v->ptr, 0);
}
/* -----------------------------------------------------------------------------
@ -52,36 +50,35 @@ Void_copy(DOH *vo) {
* Returns the void * stored in the object.
* ----------------------------------------------------------------------------- */
static void *
Void_data(DOH *vo) {
static void *Void_data(DOH *vo) {
VoidObj *v = (VoidObj *) ObjData(vo);
return v->ptr;
}
static DohObjInfo DohVoidType = {
"VoidObj", /* objname */
Void_delete, /* doh_del */
Void_copy, /* doh_copy */
0, /* doh_clear */
0, /* doh_str */
Void_data, /* doh_data */
0, /* doh_dump */
0, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
0, /* doh_first */
0, /* doh_next */
0, /* doh_setfile */
0, /* doh_getfile */
0, /* doh_setline */
0, /* doh_getline */
0, /* doh_mapping */
0, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_reserved */
0, /* clientdata */
"VoidObj", /* objname */
Void_delete, /* doh_del */
Void_copy, /* doh_copy */
0, /* doh_clear */
0, /* doh_str */
Void_data, /* doh_data */
0, /* doh_dump */
0, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
0, /* doh_first */
0, /* doh_next */
0, /* doh_setfile */
0, /* doh_getfile */
0, /* doh_setline */
0, /* doh_getline */
0, /* doh_mapping */
0, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_reserved */
0, /* clientdata */
};
/* -----------------------------------------------------------------------------
@ -90,11 +87,10 @@ static DohObjInfo DohVoidType = {
* Creates a new Void object given a void * and an optional destructor function.
* ----------------------------------------------------------------------------- */
DOH *
DohNewVoid(void *obj, void (*del)(void *)) {
DOH *DohNewVoid(void *obj, void (*del) (void *)) {
VoidObj *v;
v = (VoidObj *) DohMalloc(sizeof(VoidObj));
v->ptr = obj;
v->del = del;
return DohObjMalloc(&DohVoidType,v);
return DohObjMalloc(&DohVoidType, v);
}

View File

@ -84,53 +84,53 @@
#define WARN_PARSE_REDUNDANT 322
#define WARN_PARSE_REC_INHERITANCE 323
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */
#define WARN_IGNORE_OPERATOR_PLUS 352 /* + */
#define WARN_IGNORE_OPERATOR_MINUS 353 /* - */
#define WARN_IGNORE_OPERATOR_MUL 354 /* * */
#define WARN_IGNORE_OPERATOR_DIV 355 /* / */
#define WARN_IGNORE_OPERATOR_MOD 356 /* % */
#define WARN_IGNORE_OPERATOR_XOR 357 /* ^ */
#define WARN_IGNORE_OPERATOR_AND 358 /* & */
#define WARN_IGNORE_OPERATOR_OR 359 /* | */
#define WARN_IGNORE_OPERATOR_NOT 360 /* ~ */
#define WARN_IGNORE_OPERATOR_LNOT 361 /* ! */
#define WARN_IGNORE_OPERATOR_EQ 362 /* = */
#define WARN_IGNORE_OPERATOR_LT 363 /* < */
#define WARN_IGNORE_OPERATOR_GT 364 /* > */
#define WARN_IGNORE_OPERATOR_PLUSEQ 365 /* += */
#define WARN_IGNORE_OPERATOR_MINUSEQ 366 /* -= */
#define WARN_IGNORE_OPERATOR_MULEQ 367 /* *= */
#define WARN_IGNORE_OPERATOR_DIVEQ 368 /* /= */
#define WARN_IGNORE_OPERATOR_MODEQ 369 /* %= */
#define WARN_IGNORE_OPERATOR_XOREQ 370 /* ^= */
#define WARN_IGNORE_OPERATOR_ANDEQ 371 /* &= */
#define WARN_IGNORE_OPERATOR_OREQ 372 /* |= */
#define WARN_IGNORE_OPERATOR_LSHIFT 373 /* << */
#define WARN_IGNORE_OPERATOR_RSHIFT 374 /* >> */
#define WARN_IGNORE_OPERATOR_LSHIFTEQ 375 /* <<= */
#define WARN_IGNORE_OPERATOR_RSHIFTEQ 376 /* >>= */
#define WARN_IGNORE_OPERATOR_EQUALTO 377 /* == */
#define WARN_IGNORE_OPERATOR_NOTEQUAL 378 /* != */
#define WARN_IGNORE_OPERATOR_LTEQUAL 379 /* <= */
#define WARN_IGNORE_OPERATOR_GTEQUAL 380 /* >= */
#define WARN_IGNORE_OPERATOR_LAND 381 /* && */
#define WARN_IGNORE_OPERATOR_LOR 382 /* || */
#define WARN_IGNORE_OPERATOR_PLUSPLUS 383 /* ++ */
#define WARN_IGNORE_OPERATOR_MINUSMINUS 384 /* -- */
#define WARN_IGNORE_OPERATOR_COMMA 385 /* , */
#define WARN_IGNORE_OPERATOR_ARROWSTAR 386 /* ->* */
#define WARN_IGNORE_OPERATOR_ARROW 387 /* -> */
#define WARN_IGNORE_OPERATOR_CALL 388 /* () */
#define WARN_IGNORE_OPERATOR_INDEX 389 /* [] */
#define WARN_IGNORE_OPERATOR_UPLUS 390 /* + */
#define WARN_IGNORE_OPERATOR_UMINUS 391 /* - */
#define WARN_IGNORE_OPERATOR_UMUL 392 /* * */
#define WARN_IGNORE_OPERATOR_UAND 393 /* & */
#define WARN_IGNORE_OPERATOR_NEWARR 394 /* new [] */
#define WARN_IGNORE_OPERATOR_DELARR 395 /* delete [] */
#define WARN_IGNORE_OPERATOR_REF 396 /* operator *() */
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */
#define WARN_IGNORE_OPERATOR_PLUS 352 /* + */
#define WARN_IGNORE_OPERATOR_MINUS 353 /* - */
#define WARN_IGNORE_OPERATOR_MUL 354 /* * */
#define WARN_IGNORE_OPERATOR_DIV 355 /* / */
#define WARN_IGNORE_OPERATOR_MOD 356 /* % */
#define WARN_IGNORE_OPERATOR_XOR 357 /* ^ */
#define WARN_IGNORE_OPERATOR_AND 358 /* & */
#define WARN_IGNORE_OPERATOR_OR 359 /* | */
#define WARN_IGNORE_OPERATOR_NOT 360 /* ~ */
#define WARN_IGNORE_OPERATOR_LNOT 361 /* ! */
#define WARN_IGNORE_OPERATOR_EQ 362 /* = */
#define WARN_IGNORE_OPERATOR_LT 363 /* < */
#define WARN_IGNORE_OPERATOR_GT 364 /* > */
#define WARN_IGNORE_OPERATOR_PLUSEQ 365 /* += */
#define WARN_IGNORE_OPERATOR_MINUSEQ 366 /* -= */
#define WARN_IGNORE_OPERATOR_MULEQ 367 /* *= */
#define WARN_IGNORE_OPERATOR_DIVEQ 368 /* /= */
#define WARN_IGNORE_OPERATOR_MODEQ 369 /* %= */
#define WARN_IGNORE_OPERATOR_XOREQ 370 /* ^= */
#define WARN_IGNORE_OPERATOR_ANDEQ 371 /* &= */
#define WARN_IGNORE_OPERATOR_OREQ 372 /* |= */
#define WARN_IGNORE_OPERATOR_LSHIFT 373 /* << */
#define WARN_IGNORE_OPERATOR_RSHIFT 374 /* >> */
#define WARN_IGNORE_OPERATOR_LSHIFTEQ 375 /* <<= */
#define WARN_IGNORE_OPERATOR_RSHIFTEQ 376 /* >>= */
#define WARN_IGNORE_OPERATOR_EQUALTO 377 /* == */
#define WARN_IGNORE_OPERATOR_NOTEQUAL 378 /* != */
#define WARN_IGNORE_OPERATOR_LTEQUAL 379 /* <= */
#define WARN_IGNORE_OPERATOR_GTEQUAL 380 /* >= */
#define WARN_IGNORE_OPERATOR_LAND 381 /* && */
#define WARN_IGNORE_OPERATOR_LOR 382 /* || */
#define WARN_IGNORE_OPERATOR_PLUSPLUS 383 /* ++ */
#define WARN_IGNORE_OPERATOR_MINUSMINUS 384 /* -- */
#define WARN_IGNORE_OPERATOR_COMMA 385 /* , */
#define WARN_IGNORE_OPERATOR_ARROWSTAR 386 /* ->* */
#define WARN_IGNORE_OPERATOR_ARROW 387 /* -> */
#define WARN_IGNORE_OPERATOR_CALL 388 /* () */
#define WARN_IGNORE_OPERATOR_INDEX 389 /* [] */
#define WARN_IGNORE_OPERATOR_UPLUS 390 /* + */
#define WARN_IGNORE_OPERATOR_UMINUS 391 /* - */
#define WARN_IGNORE_OPERATOR_UMUL 392 /* * */
#define WARN_IGNORE_OPERATOR_UAND 393 /* & */
#define WARN_IGNORE_OPERATOR_NEWARR 394 /* new [] */
#define WARN_IGNORE_OPERATOR_DELARR 395 /* delete [] */
#define WARN_IGNORE_OPERATOR_REF 396 /* operator *() */
/* 394-399 are reserved */
@ -157,10 +157,10 @@
#define WARN_TYPEMAP_TYPECHECK 467
#define WARN_TYPEMAP_THROW 468
#define WARN_TYPEMAP_DIRECTORIN_UNDEF 469
#define WARN_TYPEMAP_THREAD_UNSAFE 470 /* mostly used in directorout typemaps */
#define WARN_TYPEMAP_THREAD_UNSAFE 470 /* mostly used in directorout typemaps */
#define WARN_TYPEMAP_DIRECTOROUT_UNDEF 471
#define WARN_TYPEMAP_TYPECHECK_UNDEF 472
#define WARN_TYPEMAP_DIRECTOROUT_PTR 473
#define WARN_TYPEMAP_DIRECTOROUT_PTR 473
/* -- Fragments -- */
#define WARN_FRAGMENT_NOT_FOUND 490
@ -171,7 +171,7 @@
#define WARN_LANG_OVERLOAD_CONSTRUCT 502
#define WARN_LANG_IDENTIFIER 503
#define WARN_LANG_RETURN_TYPE 504
#define WARN_LANG_VARARGS 505
#define WARN_LANG_VARARGS 505
#define WARN_LANG_VARARGS_KEYWORD 506
#define WARN_LANG_NATIVE_UNIMPL 507
#define WARN_LANG_DEREF_SHADOW 508
@ -254,6 +254,3 @@
add an entry here */
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -15,62 +15,60 @@ char cvsroot_browser_cxx[] = "$Header$";
#ifdef SWIG_SWILL
extern "C" {
#include "swill.h"
}
static FILE *out = 0;
} static FILE *out = 0;
static Node *view_top = 0;
class Browser : public Dispatcher {
class Browser:public Dispatcher {
void show_checkbox(Node *t, Node *n) {
int v = 0;
if (Getmeta(n,"visible")) {
if (Getmeta(n, "visible")) {
v = 1;
}
if (v) {
Printf(out,"<a name=\"n%x\"></a>[<a href=\"hide.html?node=0x%x&hn=0x%x#n%x\">-</a>] ", n, t, n,n);
Printf(out, "<a name=\"n%x\"></a>[<a href=\"hide.html?node=0x%x&hn=0x%x#n%x\">-</a>] ", n, t, n, n);
} else {
Printf(out,"<a name=\"n%x\"></a>[<a href=\"show.html?node=0x%x&hn=0x%x#n%x\">+</a>] ", n, t, n,n);
Printf(out, "<a name=\"n%x\"></a>[<a href=\"show.html?node=0x%x&hn=0x%x#n%x\">+</a>] ", n, t, n, n);
}
}
void show_attributes(Node *obj) {
if (!Getmeta(obj,"visible")) return;
if (!Getmeta(obj, "visible"))
return;
String *os = NewString("");
String *k;
Iterator ki;
ki = First(obj);
while (ki.key) {
k = ki.key;
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)) == '$')) {
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) {
} else if (Cmp(k, "parms") == 0) {
String *o = NewString("");
Printf(o,"%s", ParmList_protostr(Getattr(obj,k)));
Replaceall(o,"&","&amp;");
Replaceall(o,"<","&lt;");
Replaceall(o,">","&gt;");
Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - %s\n", Getattr(obj,k), k, o);
Printf(o, "%s", ParmList_protostr(Getattr(obj, k)));
Replaceall(o, "&", "&amp;");
Replaceall(o, "<", "&lt;");
Replaceall(o, ">", "&gt;");
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - %s\n", Getattr(obj, k), k, o);
Delete(o);
} else {
DOH *o;
char *trunc = "";
if (DohIsString(Getattr(obj,k))) {
o = Str(Getattr(obj,k));
if (DohIsString(Getattr(obj, k))) {
o = Str(Getattr(obj, k));
if (Len(o) > 70) {
trunc = "...";
}
Replaceall(o,"&","&amp;");
Replaceall(o,"<","&lt;");
Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc);
Replaceall(o, "&", "&amp;");
Replaceall(o, "<", "&lt;");
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Delete(o);
} else {
Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k));
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
}
}
ki = Next(ki);
}
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Delete(os);
}
@ -78,24 +76,24 @@ public:
virtual int emit_one(Node *n) {
char *tag = Char(nodeType(n));
char *file = Char(Getfile(n));
int line = Getline(n);
char *name = GetChar(n,"name");
int line = Getline(n);
char *name = GetChar(n, "name");
show_checkbox(view_top, n);
Printf(out,"<b><a href=\"index.html?node=0x%x\">%s</a></b>", n, tag);
Printf(out, "<b><a href=\"index.html?node=0x%x\">%s</a></b>", n, tag);
if (name) {
Printf(out," (%s)", name);
Printf(out, " (%s)", name);
}
Printf(out,". %s:%d\n", file, line);
Printf(out,"<br>");
Printf(out, ". %s:%d\n", file, line);
Printf(out, "<br>");
Dispatcher::emit_one(n);
return SWIG_OK;
}
virtual int emit_children(Node *n) {
if (Getmeta(n,"visible")) {
Printf(out,"<blockquote>\n");
if (Getmeta(n, "visible")) {
Printf(out, "<blockquote>\n");
Dispatcher::emit_children(n);
Printf(out,"</blockquote>\n");
Printf(out, "</blockquote>\n");
}
return SWIG_OK;
}
@ -169,7 +167,7 @@ static Browser *browse = 0;
void exit_handler(FILE *f) {
browser_exit = 1;
Printf(f,"Terminated.\n");
Printf(f, "Terminated.\n");
}
/* ----------------------------------------------------------------------
@ -178,23 +176,23 @@ void exit_handler(FILE *f) {
static void display(FILE *f, Node *n) {
/* Print standard HTML header */
Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f,"<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f, "<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
if (n != tree_top) {
Printf(f," [ <a href=\"index.html?node=0x%x\">Up</a> ]", parentNode(n));
Printf(f, " [ <a href=\"index.html?node=0x%x\">Up</a> ]", parentNode(n));
}
Printf(f," [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f,"<br><hr><p>\n");
Printf(f, " [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f, "<br><hr><p>\n");
out = f;
browse->emit_one(n);
/* Print standard footer */
Printf(f,"<br><hr></BODY></HTML>\n");
Printf(f, "<br><hr></BODY></HTML>\n");
}
@ -204,7 +202,7 @@ void node_handler(FILE *f) {
n = tree_top;
}
view_top = n;
display(f,n);
display(f, n);
}
@ -218,7 +216,7 @@ void hide_handler(FILE *f) {
n = 0;
}
if (n) {
Delmeta(n,"visible");
Delmeta(n, "visible");
}
node_handler(f);
}
@ -229,65 +227,66 @@ void show_handler(FILE *f) {
n = 0;
}
if (n) {
Setmeta(n,"visible","1");
Setmeta(n, "visible", "1");
}
node_handler(f);
}
void raw_data(FILE *out, Node *obj) {
if (!obj) return;
if (!obj)
return;
if (DohIsMapping(obj)) {
String *k;
Iterator ki;
String *os = NewString("");
Printf(os,"Hash {\n");
Printf(os, "Hash {\n");
ki = First(obj);
while (ki.key) {
k = ki.key;
DOH *o;
const char *trunc = "";
if (DohIsString(Getattr(obj,k))) {
o = Str(Getattr(obj,k));
if (DohIsString(Getattr(obj, k))) {
o = Str(Getattr(obj, k));
if (Len(o) > 70) {
trunc = "...";
}
Replaceall(o,"<","&lt;");
Printf(os," <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc);
Replaceall(o, "<", "&lt;");
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Delete(o);
} else {
Printf(os," <a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k));
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
}
ki = Next(ki);
}
Printf(os,"}\n");
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Printf(os, "}\n");
Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Delete(os);
} else if (DohIsString(obj)) {
String *o = Str(obj);
Replaceall(o,"<","&lt;");
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(o));
Replaceall(o, "<", "&lt;");
Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(o));
Delete(o);
} else if (DohIsSequence(obj)) {
int i;
String *os = NewString("");
Printf(os,"List [\n");
Printf(os, "List [\n");
for (i = 0; i < Len(obj); i++) {
DOH *o = Getitem(obj,i);
DOH *o = Getitem(obj, i);
const char *trunc = "";
if (DohIsString(o)) {
String *s = Str(o);
if (Len(s) > 70) {
trunc = "...";
}
Replaceall(o,"<","&lt;");
Printf(os," <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o,i,s, trunc);
Replaceall(o, "<", "&lt;");
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc);
Delete(s);
} else {
Printf(os," <a href=\"data.html?n=0x%x\">?</a> [%d] - 0x%x\n", o, i, o);
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> [%d] - 0x%x\n", o, i, o);
}
}
Printf(os,"\n]\n");
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Printf(os, "\n]\n");
Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Delete(os);
}
}
@ -297,86 +296,85 @@ void data_handler(FILE *f) {
if (!swill_getargs("p(n)", &n)) {
n = 0;
}
Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f,"<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f,"<br><hr><p>\n");
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f, "<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, "<br><hr><p>\n");
if (n) {
raw_data(f,n);
raw_data(f, n);
}
/* Print standard footer */
Printf(f,"<br><hr></BODY></HTML>\n");
Printf(f, "<br><hr></BODY></HTML>\n");
}
void symbol_handler(FILE *f) {
Symtab *sym;
char *name = 0;
char *name = 0;
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f, "<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, " [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f, "<br><hr><p>\n");
Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f,"<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f," [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f,"<br><hr><p>\n");
if (!swill_getargs("p(sym)|s(name)", &sym, &name)) {
sym = Swig_symbol_getscope("");
name = 0;
}
if (!sym) {
Printf(f,"No symbol table specified!\n");
Printf(f, "No symbol table specified!\n");
return;
}
{
String *q = Swig_symbol_qualifiedscopename(sym);
if (!Len(q)) {
Printf(f,"<b>Symbol table: :: (global)</b><br>\n");
Printf(f, "<b>Symbol table: :: (global)</b><br>\n");
} else {
Printf(f,"<b>Symbol table: %s</b><br>\n", q);
Printf(f, "<b>Symbol table: %s</b><br>\n", q);
}
Delete(q);
}
fprintf(f,"<p><form action=\"symbol.html\" method=GET>\n");
fprintf(f,"Symbol lookup: <input type=text name=name size=40></input><br>\n");
fprintf(f,"<input type=hidden name=sym value=\"0x%x\">\n", sym);
fprintf(f,"Submit : <input type=submit></input>\n");
fprintf(f,"</form>");
fprintf(f, "<p><form action=\"symbol.html\" method=GET>\n");
fprintf(f, "Symbol lookup: <input type=text name=name size=40></input><br>\n");
fprintf(f, "<input type=hidden name=sym value=\"0x%x\">\n", sym);
fprintf(f, "Submit : <input type=submit></input>\n");
fprintf(f, "</form>");
if (name) {
Node *n = Swig_symbol_clookup(name,sym);
Printf(f,"Symbol '%s':\n", name);
Printf(f,"<blockquote>\n");
Node *n = Swig_symbol_clookup(name, sym);
Printf(f, "Symbol '%s':\n", name);
Printf(f, "<blockquote>\n");
if (!n) {
Printf(f,"Not defined!\n");
Printf(f, "Not defined!\n");
} else {
raw_data(f,n);
raw_data(f, n);
}
Printf(f,"</blockquote>\n");
Printf(f, "</blockquote>\n");
}
Printf(f,"<p><b>Nested scopes</b><br>\n");
Printf(f,"<blockquote><pre>\n");
Printf(f, "<p><b>Nested scopes</b><br>\n");
Printf(f, "<blockquote><pre>\n");
{
Hash *h;
Hash *h;
h = firstChild(sym);
while (h) {
Printf(f,"<a href=\"symbol.html?sym=0x%x\">%s</a>\n", h, Getattr(h,"name"));
Printf(f, "<a href=\"symbol.html?sym=0x%x\">%s</a>\n", h, Getattr(h, "name"));
h = nextSibling(h);
}
}
Printf(f,"</pre></blockquote>\n");
Printf(f,"<p><b>Symbol table contents</b></br>\n");
raw_data(f,Getattr(sym,"symtab"));
Printf(f,"<br><hr></BODY></HTML>\n");
Printf(f, "</pre></blockquote>\n");
Printf(f, "<p><b>Symbol table contents</b></br>\n");
raw_data(f, Getattr(sym, "symtab"));
Printf(f, "<br><hr></BODY></HTML>\n");
}
#endif
void
Swig_browser(Node *top, int port) {
void Swig_browser(Node *top, int port) {
#ifdef SWIG_SWILL
int sport;
browser_exit = 0;
@ -384,37 +382,32 @@ Swig_browser(Node *top, int port) {
/* Initialize the server */
sport = swill_init(port);
if (sport < 0) {
Printf(stderr,"Couldn't open socket on port %d. Sorry.\n", port);
Printf(stderr, "Couldn't open socket on port %d. Sorry.\n", port);
return;
}
browse = new Browser();
Setmeta(top,"visible","1");
Setmeta(top, "visible", "1");
tree_top = top;
Printf(stderr,"SWIG: Tree browser listening on port %d\n", sport);
Printf(stderr, "SWIG: Tree browser listening on port %d\n", sport);
swill_handle("exit.html", exit_handler,0);
swill_handle("exit.html", exit_handler, 0);
swill_handle("index.html", node_handler, 0);
swill_handle("hide.html", hide_handler,0);
swill_handle("show.html", show_handler,0);
swill_handle("data.html", data_handler,0);
swill_handle("hide.html", hide_handler, 0);
swill_handle("show.html", show_handler, 0);
swill_handle("data.html", data_handler, 0);
swill_handle("symbol.html", symbol_handler, 0);
swill_netscape("index.html");
while (!browser_exit) {
swill_serve();
}
Printf(stderr,"Browser terminated.\n");
Printf(stderr, "Browser terminated.\n");
swill_close();
delete browse;
return;
#else
(void)top;
(void)port;
(void) top;
(void) port;
#endif
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -11,343 +11,335 @@ char cvsroot_clisp_cxx[] = "$Header$";
#include "swigmod.h"
class CLISP : public Language {
class CLISP:public Language {
public:
File *f_cl;
String *module;
virtual void main(int argc, char *argv[]);
virtual int top(Node *n);
virtual int functionWrapper(Node *n);
virtual int variableWrapper(Node *n);
virtual int variableWrapper(Node *n);
virtual int constantWrapper(Node *n);
virtual int classDeclaration(Node *n);
virtual int enumDeclaration(Node *n);
virtual int typedefHandler(Node *n);
List *entries;
private:
String* get_ffi_type(SwigType *ty);
String* convert_literal(String *num_param, String *type);
String* strip_parens(String *string);
String *get_ffi_type(SwigType *ty);
String *convert_literal(String *num_param, String *type);
String *strip_parens(String *string);
int extern_all_flag;
int generate_typedef_flag;
int is_function;
};
void CLISP :: main(int argc, char *argv[]) {
void CLISP::main(int argc, char *argv[]) {
int i;
SWIG_library_directory("clisp");
SWIG_library_directory("clisp");
SWIG_config_file("clisp.swg");
generate_typedef_flag = 0;
extern_all_flag=0;
for(i=1; i<argc; i++) {
extern_all_flag = 0;
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-help")) {
Printf(stdout, "clisp Options (available with -clisp)\n");
Printf(stdout,
Printf(stdout,
" -extern-all\n"
"\t If this option is given then clisp definitions for all the functions\n"
"and global variables will be created otherwise only definitions for \n"
"externed functions and variables are created.\n"
" -generate-typedef\n"
"\t If this option is given then def-c-type will be used to generate shortcuts\n"
"according to the typedefs in the input.\n"
);
}
else if ( (Strcmp(argv[i],"-extern-all") == 0)) {
"according to the typedefs in the input.\n");
} else if ((Strcmp(argv[i], "-extern-all") == 0)) {
extern_all_flag = 1;
Swig_mark_arg(i);
}
else if ( (Strcmp(argv[i],"-generate-typedef") == 0)) {
} else if ((Strcmp(argv[i], "-generate-typedef") == 0)) {
generate_typedef_flag = 1;
Swig_mark_arg(i);
}
}
}
int CLISP :: top(Node *n) {
int CLISP::top(Node *n) {
File *f_null=NewString("");
module=Getattr(n, "name");
File *f_null = NewString("");
module = Getattr(n, "name");
String *output_filename;
entries = NewList();
/* Get the output file name */
String *outfile = Getattr(n,"outfile");
if(!outfile)
output_filename=outfile;
else {
output_filename=NewString("");
String *outfile = Getattr(n, "outfile");
if (!outfile)
output_filename = outfile;
else {
output_filename = NewString("");
Printf(output_filename, "%s%s.lisp", SWIG_output_directory(), module);
}
f_cl=NewFile(output_filename, "w+");
f_cl = NewFile(output_filename, "w+");
if (!f_cl) {
FileErrorDisplay(output_filename);
SWIG_exit(EXIT_FAILURE);
}
Swig_register_filebyname("header",f_null);
Swig_register_filebyname("runtime",f_null);
Swig_register_filebyname("header", f_null);
Swig_register_filebyname("runtime", f_null);
Swig_register_filebyname("wrapper", f_null);
String *header=NewStringf(";; This is an automatically generated file. \n;;Make changes as you feel are necessary (but remember if you try to regenerate this file, your changes will be lost). \n\n(defpackage :%s\n (:use :common-lisp :ffi)", module);
String *header =
NewStringf
(";; This is an automatically generated file. \n;;Make changes as you feel are necessary (but remember if you try to regenerate this file, your changes will be lost). \n\n(defpackage :%s\n (:use :common-lisp :ffi)",
module);
Language::top(n);
Iterator i;
long len=Len(entries);
if(len > 0) {
Printf(header,"\n (:export");
long len = Len(entries);
if (len > 0) {
Printf(header, "\n (:export");
}
//else nothing to export
for (i = First(entries); i.item; i = Next(i)) {
Printf(header,"\n\t:%s", i.item);
}
if(len > 0) {
Printf(header,")");
}
Printf(header, ")\n");
Printf(header,"\n(in-package :%s)\n",module);
Printf(header,"\n(default-foreign-language :stdc)\n");
len= Tell(f_cl);
Printf(f_cl,"%s",header);
for (i = First(entries); i.item; i = Next(i)) {
Printf(header, "\n\t:%s", i.item);
}
if (len > 0) {
Printf(header, ")");
}
Printf(header, ")\n");
Printf(header, "\n(in-package :%s)\n", module);
Printf(header, "\n(default-foreign-language :stdc)\n");
len = Tell(f_cl);
Printf(f_cl, "%s", header);
long end = Tell(f_cl);
for(len--;len >=0 ; len --) {
for (len--; len >= 0; len--) {
end--;
Seek(f_cl,len,SEEK_SET);
int ch=Getc(f_cl);
Seek(f_cl,end,SEEK_SET);
Putc(ch,f_cl);
Seek(f_cl, len, SEEK_SET);
int ch = Getc(f_cl);
Seek(f_cl, end, SEEK_SET);
Putc(ch, f_cl);
}
Seek(f_cl,0,SEEK_SET);
Write(f_cl,Char(header), Len(header));
Seek(f_cl, 0, SEEK_SET);
Write(f_cl, Char(header), Len(header));
Close(f_cl);
Delete(f_cl); // Deletes the handle, not the file
Delete(f_cl); // Deletes the handle, not the file
return SWIG_OK;
}
int CLISP :: functionWrapper(Node *n) {
is_function=1;
String *storage=Getattr(n,"storage");
if(!extern_all_flag && (!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc"))))
int CLISP::functionWrapper(Node *n) {
is_function = 1;
String *storage = Getattr(n, "storage");
if (!extern_all_flag && (!storage || (Strcmp(storage, "extern") && Strcmp(storage, "externc"))))
return SWIG_OK;
String *func_name=Getattr(n, "sym:name");
ParmList *pl=Getattr(n, "parms");
String *func_name = Getattr(n, "sym:name");
int argnum=0, first=1;
ParmList *pl = Getattr(n, "parms");
Printf(f_cl, "\n(ffi:def-call-out %s\n\t(:name \"%s\")\n", func_name,func_name);
Append(entries,func_name);
int argnum = 0, first = 1;
Printf(f_cl, "\n(ffi:def-call-out %s\n\t(:name \"%s\")\n", func_name, func_name);
Append(entries, func_name);
if (ParmList_len(pl) != 0) {
Printf(f_cl, "\t(:arguments ");
}
for (Parm *p=pl; p; p=nextSibling(p), argnum++) {
for (Parm *p = pl; p; p = nextSibling(p), argnum++) {
String *argname=Getattr(p, "name");
String *argname = Getattr(p, "name");
// SwigType *argtype;
String *ffitype=get_ffi_type(Getattr(p, "type"));
int tempargname=0;
String *ffitype = get_ffi_type(Getattr(p, "type"));
int tempargname = 0;
if (!argname) {
argname=NewStringf("arg%d", argnum);
tempargname=1;
argname = NewStringf("arg%d", argnum);
tempargname = 1;
}
if (!first) {
Printf(f_cl, "\n\t\t");
}
Printf(f_cl, "(%s %s)", argname, ffitype);
first=0;
first = 0;
Delete(ffitype);
if (tempargname)
if (tempargname)
Delete(argname);
}
if (ParmList_len(pl) != 0) {
Printf(f_cl, ")\n"); /* finish arg list */
Printf(f_cl, ")\n"); /* finish arg list */
}
String *ffitype=get_ffi_type(Getattr(n, "type"));
if(Strcmp(ffitype,"NIL")) { //when return type is not nil
String *ffitype = get_ffi_type(Getattr(n, "type"));
if (Strcmp(ffitype, "NIL")) { //when return type is not nil
Printf(f_cl, "\t(:return-type %s)\n", ffitype);
}
Printf(f_cl, "\t(:library +library-name+))\n");
return SWIG_OK;
}
int CLISP :: constantWrapper(Node *n) {
is_function=0;
String *type=Getattr(n, "type");
String *converted_value=convert_literal(Getattr(n, "value"), type);
String *name=Getattr(n, "sym:name");
int CLISP::constantWrapper(Node *n) {
is_function = 0;
String *type = Getattr(n, "type");
String *converted_value = convert_literal(Getattr(n, "value"), type);
String *name = Getattr(n, "sym:name");
Printf(f_cl, "\n(defconstant %s %s)\n", name, converted_value);
Append(entries,name);
Append(entries, name);
Delete(converted_value);
return SWIG_OK;
}
int CLISP :: variableWrapper(Node *n) {
is_function=0;
int CLISP::variableWrapper(Node *n) {
is_function = 0;
// SwigType *type=;
String *storage=Getattr(n,"storage");
if(!extern_all_flag && (!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc"))))
String *storage = Getattr(n, "storage");
if (!extern_all_flag && (!storage || (Strcmp(storage, "extern") && Strcmp(storage, "externc"))))
return SWIG_OK;
String *var_name=Getattr(n, "sym:name");
String *lisp_type=get_ffi_type(Getattr(n, "type"));
Printf(f_cl,"\n(ffi:def-c-var %s\n (:name \"%s\")\n (:type %s)\n",var_name,var_name,lisp_type);
String *var_name = Getattr(n, "sym:name");
String *lisp_type = get_ffi_type(Getattr(n, "type"));
Printf(f_cl, "\n(ffi:def-c-var %s\n (:name \"%s\")\n (:type %s)\n", var_name, var_name, lisp_type);
Printf(f_cl, "\t(:library +library-name+))\n");
Append(entries,var_name);
Append(entries, var_name);
Delete(lisp_type);
return SWIG_OK;
}
int CLISP :: typedefHandler(Node *n) {
if(generate_typedef_flag) {
is_function=0;
Printf(f_cl,"\n(ffi:def-c-type %s %s)\n",Getattr(n,"name"),get_ffi_type(Getattr(n,"type")));
int CLISP::typedefHandler(Node *n) {
if (generate_typedef_flag) {
is_function = 0;
Printf(f_cl, "\n(ffi:def-c-type %s %s)\n", Getattr(n, "name"), get_ffi_type(Getattr(n, "type")));
}
return Language::typedefHandler(n);
}
int CLISP :: enumDeclaration(Node *n) {
is_function=0;
String *name=Getattr(n, "sym:name");
Printf(f_cl,"\n(ffi:def-c-enum %s ",name);
int CLISP::enumDeclaration(Node *n) {
is_function = 0;
String *name = Getattr(n, "sym:name");
for (Node *c=firstChild(n); c; c=nextSibling(c)) {
Printf(f_cl, "\n(ffi:def-c-enum %s ", name);
for (Node *c = firstChild(n); c; c = nextSibling(c)) {
String *slot_name = Getattr(c, "name");
String *value = Getattr(c, "enumvalue");
Printf(f_cl,"(%s %s)",slot_name,value);
Append(entries,slot_name);
Printf(f_cl, "(%s %s)", slot_name, value);
Append(entries, slot_name);
Delete(value);
}
Printf(f_cl, ")\n");
return SWIG_OK;
}
// Includes structs
int CLISP :: classDeclaration(Node *n) {
is_function=0;
String *name=Getattr(n, "sym:name");
String *kind = Getattr(n,"kind");
int CLISP::classDeclaration(Node *n) {
is_function = 0;
String *name = Getattr(n, "sym:name");
String *kind = Getattr(n, "kind");
if (Strcmp(kind, "struct")) {
Printf(stderr, "Don't know how to deal with %s kind of class yet.\n",
kind);
Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", kind);
Printf(stderr, " (name: %s)\n", name);
SWIG_exit(EXIT_FAILURE);
}
Printf(f_cl,"\n(ffi:def-c-struct %s",name);
Append(entries,NewStringf("make-%s",name));
for (Node *c=firstChild(n); c; c=nextSibling(c)) {
Printf(f_cl, "\n(ffi:def-c-struct %s", name);
Append(entries, NewStringf("make-%s", name));
for (Node *c = firstChild(n); c; c = nextSibling(c)) {
if (Strcmp(nodeType(c), "cdecl")) {
Printf(stderr, "Structure %s has a slot that we can't deal with.\n",
name);
Printf(stderr, "nodeType: %s, name: %s, type: %s\n",
nodeType(c),
Getattr(c, "name"),
Getattr(c, "type"));
Printf(stderr, "Structure %s has a slot that we can't deal with.\n", name);
Printf(stderr, "nodeType: %s, name: %s, type: %s\n", nodeType(c), Getattr(c, "name"), Getattr(c, "type"));
SWIG_exit(EXIT_FAILURE);
}
String *temp=Copy(Getattr(c,"decl"));
Append(temp,Getattr(c,"type")); //appending type to the end, otherwise wrong type
String *lisp_type=get_ffi_type(temp);
String *temp = Copy(Getattr(c, "decl"));
Append(temp, Getattr(c, "type")); //appending type to the end, otherwise wrong type
String *lisp_type = get_ffi_type(temp);
Delete(temp);
String *slot_name = Getattr(c, "sym:name");
Printf(f_cl,
"\n\t(%s %s)",
slot_name,
lisp_type);
Printf(f_cl, "\n\t(%s %s)", slot_name, lisp_type);
Append(entries, NewStringf("%s-%s", name, slot_name));
Append(entries,NewStringf("%s-%s",name,slot_name));
Delete(lisp_type);
}
Printf(f_cl, ")\n");
/* Add this structure to the known lisp types */
//Printf(stdout, "Adding %s foreign type\n", name);
// add_defined_foreign_type(name);
return SWIG_OK;
}
/* utilities */
/* returns new string w/ parens stripped */
String* CLISP::strip_parens(String *string) {
char *s=Char(string), *p;
int len=Len(string);
String *CLISP::strip_parens(String *string) {
char *s = Char(string), *p;
int len = Len(string);
String *res;
if (len==0 || s[0] != '(' || s[len-1] != ')') {
if (len == 0 || s[0] != '(' || s[len - 1] != ')') {
return NewString(string);
}
p=(char *)malloc(len-2+1);
p = (char *) malloc(len - 2 + 1);
if (!p) {
Printf(stderr, "Malloc failed\n");
SWIG_exit(EXIT_FAILURE);
}
strncpy(p, s+1, len-1);
p[len-2]=0; /* null terminate */
res=NewString(p);
strncpy(p, s + 1, len - 1);
p[len - 2] = 0; /* null terminate */
res = NewString(p);
free(p);
return res;
}
String* CLISP::convert_literal(String *num_param, String *type) {
String *num=strip_parens(num_param), *res;
char *s=Char(num);
String *CLISP::convert_literal(String *num_param, String *type) {
String *num = strip_parens(num_param), *res;
char *s = Char(num);
/* Make sure doubles use 'd' instead of 'e' */
if (!Strcmp(type, "double")) {
String *updated=Copy(num);
String *updated = Copy(num);
if (Replace(updated, "e", "d", DOH_REPLACE_ANY) > 1) {
Printf(stderr, "Weird!! number %s looks invalid.\n", num);
SWIG_exit(EXIT_FAILURE);
@ -359,154 +351,145 @@ String* CLISP::convert_literal(String *num_param, String *type) {
if (SwigType_type(type) == T_CHAR) {
/* Use CL syntax for character literals */
return NewStringf("#\\%s", num_param);
}
else if (SwigType_type(type) == T_STRING) {
} else if (SwigType_type(type) == T_STRING) {
/* Use CL syntax for string literals */
return NewStringf("\"%s\"", num_param);
}
if (Len(num) < 2 || s[0] != '0') {
return num;
}
/* octal or hex */
res=NewStringf("#%c%s",
s[1] == 'x' ? 'x' : 'o',
s+2);
res = NewStringf("#%c%s", s[1] == 'x' ? 'x' : 'o', s + 2);
Delete(num);
return res;
}
String* CLISP::get_ffi_type(SwigType *ty) {
Hash *typemap =Swig_typemap_search("in", ty,"", 0);
String *CLISP::get_ffi_type(SwigType *ty) {
Hash *typemap = Swig_typemap_search("in", ty, "", 0);
if (typemap) {
String *typespec = Getattr(typemap, "code");
return NewString(typespec);
}
else if(SwigType_ispointer(ty)) {
} else if (SwigType_ispointer(ty)) {
SwigType *cp = Copy(ty);
SwigType_del_pointer(cp);
String *inner_type=get_ffi_type(cp);
String *inner_type = get_ffi_type(cp);
if(SwigType_isfunction(cp)) {
if (SwigType_isfunction(cp)) {
return inner_type;
}
SwigType *base=SwigType_base(ty);
String *base_name=SwigType_str(base,0);
SwigType *base = SwigType_base(ty);
String *base_name = SwigType_str(base, 0);
String *str;
if(!Strcmp(base_name,"int") || !Strcmp(base_name,"float") || !Strcmp(base_name,"short")
|| !Strcmp(base_name,"double") || !Strcmp(base_name,"long") || !Strcmp(base_name,"char")) {
str = NewStringf("(ffi:c-ptr %s)",inner_type);
}
else {
str = NewStringf("(ffi:c-pointer %s)",inner_type);
if (!Strcmp(base_name, "int") || !Strcmp(base_name, "float") || !Strcmp(base_name, "short")
|| !Strcmp(base_name, "double") || !Strcmp(base_name, "long") || !Strcmp(base_name, "char")) {
str = NewStringf("(ffi:c-ptr %s)", inner_type);
} else {
str = NewStringf("(ffi:c-pointer %s)", inner_type);
}
Delete(base_name);
Delete(base);
Delete(cp);
Delete(inner_type);
return str;
}
else if(SwigType_isarray(ty)) {
} else if (SwigType_isarray(ty)) {
SwigType *cp = Copy(ty);
String *array_dim=SwigType_array_getdim(ty,0);
String *array_dim = SwigType_array_getdim(ty, 0);
if(!Strcmp(array_dim,"")) { //dimension less array convert to pointer
if (!Strcmp(array_dim, "")) { //dimension less array convert to pointer
Delete(array_dim);
SwigType_del_array(cp);
SwigType_add_pointer(cp);
String *str =get_ffi_type(cp);
String *str = get_ffi_type(cp);
Delete(cp);
return str;
}
else {
} else {
SwigType_pop_arrays(cp);
String *inner_type = get_ffi_type(cp);
Delete(cp);
int ndim=SwigType_array_ndim(ty);
int ndim = SwigType_array_ndim(ty);
String *dimension;
if(ndim == 1) {
dimension=array_dim;
}
else {
if (ndim == 1) {
dimension = array_dim;
for(int i=1;i<ndim;i++) {
array_dim=SwigType_array_getdim(ty,i);
Append(dimension," ");
Append(dimension,array_dim);
} else {
dimension = array_dim;
for (int i = 1; i < ndim; i++) {
array_dim = SwigType_array_getdim(ty, i);
Append(dimension, " ");
Append(dimension, array_dim);
Delete(array_dim);
}
String *temp=dimension;
dimension=NewStringf("(%s)",dimension);
String *temp = dimension;
dimension = NewStringf("(%s)", dimension);
Delete(temp);
}
String *str;
if(is_function)
str=NewStringf("(ffi:c-ptr (ffi:c-array %s %s))",inner_type,dimension);
if (is_function)
str = NewStringf("(ffi:c-ptr (ffi:c-array %s %s))", inner_type, dimension);
else
str=NewStringf("(ffi:c-array %s %s)",inner_type,dimension);
str = NewStringf("(ffi:c-array %s %s)", inner_type, dimension);
Delete(inner_type);
Delete(dimension);
return str;
}
}
else if(SwigType_isfunction(ty)) {
} else if (SwigType_isfunction(ty)) {
SwigType *cp = Copy(ty);
SwigType *fn=SwigType_pop_function(cp);
String *args=NewString("");
ParmList *pl= SwigType_function_parms(fn);
SwigType *fn = SwigType_pop_function(cp);
String *args = NewString("");
ParmList *pl = SwigType_function_parms(fn);
if (ParmList_len(pl) != 0) {
Printf(args, "(:arguments ");
}
int argnum=0, first=1;
for (Parm *p=pl; p; p=nextSibling(p), argnum++) {
String *argname=Getattr(p, "name");
SwigType *argtype=Getattr(p, "type");
String *ffitype=get_ffi_type(argtype);
int tempargname=0;
int argnum = 0, first = 1;
for (Parm *p = pl; p; p = nextSibling(p), argnum++) {
String *argname = Getattr(p, "name");
SwigType *argtype = Getattr(p, "type");
String *ffitype = get_ffi_type(argtype);
int tempargname = 0;
if (!argname) {
argname=NewStringf("arg%d", argnum);
tempargname=1;
argname = NewStringf("arg%d", argnum);
tempargname = 1;
}
if (!first) {
Printf(args, "\n\t\t");
Printf(args, "\n\t\t");
}
Printf(args, "(%s %s)", argname, ffitype);
first=0;
first = 0;
Delete(ffitype);
if (tempargname)
Delete(argname);
if (tempargname)
Delete(argname);
}
if (ParmList_len(pl) != 0) {
Printf(args, ")\n"); /* finish arg list */
Printf(args, ")\n"); /* finish arg list */
}
String *ffitype = get_ffi_type(cp);
String *str=NewStringf("(ffi:c-function %s \t\t\t\t(:return-type %s))",args,ffitype);
String *str = NewStringf("(ffi:c-function %s \t\t\t\t(:return-type %s))", args, ffitype);
Delete(fn);
Delete(args);
Delete(cp);
Delete(ffitype);
return str;
}
String *str=SwigType_str(ty,0);
if(str) {
char *st = Strstr(str,"struct");
if(st) {
st+=7;
String *str = SwigType_str(ty, 0);
if (str) {
char *st = Strstr(str, "struct");
if (st) {
st += 7;
return NewString(st);
}
char *cl = Strstr(str,"class");
if(cl) {
cl+=6;
char *cl = Strstr(str, "class");
if (cl) {
cl += 6;
return NewString(cl);
}
}
@ -516,5 +499,3 @@ String* CLISP::get_ffi_type(SwigType *ty) {
extern "C" Language *swig_clisp(void) {
return new CLISP();
}

View File

@ -23,8 +23,8 @@ struct contract {
static contract Rules[] = {
{"require:", "&&"},
{"ensure:", "||"},
{ NULL, NULL}
{"ensure:", "||"},
{NULL, NULL}
};
/* ----------------------------------------------------------------------------
@ -34,14 +34,14 @@ static contract Rules[] = {
* "wrap by contract" module.
* ------------------------------------------------------------------------- */
class Contracts : public Dispatcher {
class Contracts:public Dispatcher {
String *make_expression(String *s, Node *n);
void substitute_parms(String *s, ParmList *p, int method);
void substitute_parms(String *s, ParmList *p, int method);
public:
Hash *ContractSplit(Node *n);
int emit_contract(Node *n, int method);
int cDeclaration(Node *n);
int constructorDeclaration(Node *n);
int constructorDeclaration(Node *n);
int externDeclaration(Node *n);
int extendDirective(Node *n);
int importDirective(Node *n);
@ -50,16 +50,17 @@ public:
virtual int top(Node *n);
};
static int Contract_Mode = 0; /* contract option */
static int InClass = 0; /* Parsing C++ or not */
static int InConstructor = 0;
static Node *CurrentClass = 0;
static int Contract_Mode = 0; /* contract option */
static int InClass = 0; /* Parsing C++ or not */
static int InConstructor = 0;
static Node *CurrentClass = 0;
/* Set the contract mode, default is 0 (not open) */
/* Normally set in main.cxx, when get the "-contracts" option */
void Swig_contract_mode_set(int flag) {
Contract_Mode = flag;
}
/* Get the contract mode */
int Swig_contract_mode_get() {
return Contract_Mode;
@ -76,50 +77,56 @@ void Swig_contracts(Node *n) {
/* Split the whole contract into preassertion, postassertion and others */
Hash *Contracts::ContractSplit(Node *n) {
String *contract = Getattr(n, "feature:contract");
Hash *result;
String *contract = Getattr(n, "feature:contract");
Hash *result;
if (!contract)
return NULL;
result = NewHash();
String *current_section = NewString("");
const char *current_section_name = Rules[0].section;
const char *current_section_name = Rules[0].section;
List *l = SplitLines(contract);
Iterator i;
for (i = First(l); i.item; i = Next(i)) {
int found = 0;
if (Strchr(i.item,'{')) continue;
if (Strchr(i.item,'}')) continue;
if (Strchr(i.item, '{'))
continue;
if (Strchr(i.item, '}'))
continue;
for (int j = 0; Rules[j].section; j++) {
if (Strstr(i.item,Rules[j].section)) {
if (Strstr(i.item, Rules[j].section)) {
if (Len(current_section)) {
Setattr(result,current_section_name,current_section);
current_section = Getattr(result,Rules[j].section);
if (!current_section) current_section = NewString("");
Setattr(result, current_section_name, current_section);
current_section = Getattr(result, Rules[j].section);
if (!current_section)
current_section = NewString("");
}
current_section_name = Rules[j].section;
found = 1;
break;
}
}
if (!found) Append(current_section, i.item);
if (!found)
Append(current_section, i.item);
}
if (Len(current_section)) Setattr(result, current_section_name, current_section);
if (Len(current_section))
Setattr(result, current_section_name, current_section);
return result;
}
/* This function looks in base classes and collects contracts found */
void inherit_contracts(Node *c, Node *n, Hash *contracts, Hash *messages) {
Node *b, *temp;
String *name, *type, *local_decl, *base_decl;
List *bases;
int found = 0;
List *bases;
int found = 0;
bases = Getattr(c, "bases");
if (!bases)
return;
bases = Getattr(c,"bases");
if (!bases) return;
name = Getattr(n, "name");
type = Getattr(n, "type");
local_decl = Getattr(n, "decl");
@ -130,19 +137,17 @@ void inherit_contracts(Node *c, Node *n, Hash *contracts, Hash *messages) {
}
/* Width first search */
for (int i = 0; i < Len(bases); i++) {
b = Getitem(bases,i);
temp = firstChild (b);
b = Getitem(bases, i);
temp = firstChild(b);
while (temp) {
base_decl = Getattr(temp, "decl");
if (base_decl) {
base_decl = SwigType_typedef_resolve_all(base_decl);
if ( (checkAttribute(temp, "storage", "virtual")) &&
(checkAttribute(temp, "name", name)) &&
(checkAttribute(temp, "type", type)) &&
(!Strcmp(local_decl, base_decl)) ) {
if ((checkAttribute(temp, "storage", "virtual")) &&
(checkAttribute(temp, "name", name)) && (checkAttribute(temp, "type", type)) && (!Strcmp(local_decl, base_decl))) {
/* Yes, match found. */
Hash *icontracts = Getattr(temp,"contract:rules");
Hash *imessages = Getattr(temp,"contract:messages");
Hash *icontracts = Getattr(temp, "contract:rules");
Hash *imessages = Getattr(temp, "contract:messages");
found = 1;
if (icontracts && imessages) {
/* Add inherited contracts and messages to the contract rules above */
@ -152,13 +157,13 @@ void inherit_contracts(Node *c, Node *n, Hash *contracts, Hash *messages) {
String *s = Getattr(icontracts, Rules[j].section);
if (s) {
if (t) {
Insert(t,0,"(");
Printf(t,") %s (%s)", Rules[j].combiner, s);
Insert(t, 0, "(");
Printf(t, ") %s (%s)", Rules[j].combiner, s);
String *m = Getattr(messages, Rules[j].section);
Printf(m," %s [%s from %s]", Rules[j].combiner, Getattr(imessages,Rules[j].section), Getattr(b,"name"));
Printf(m, " %s [%s from %s]", Rules[j].combiner, Getattr(imessages, Rules[j].section), Getattr(b, "name"));
} else {
Setattr(contracts, Rules[j].section, NewString(s));
Setattr(messages,Rules[j].section,NewStringf("[%s from %s]", Getattr(imessages,Rules[j].section), Getattr(b,"name")));
Setattr(messages, Rules[j].section, NewStringf("[%s from %s]", Getattr(imessages, Rules[j].section), Getattr(b, "name")));
}
}
}
@ -172,8 +177,8 @@ void inherit_contracts(Node *c, Node *n, Hash *contracts, Hash *messages) {
Delete(local_decl);
if (!found) {
for (int j = 0; j < Len(bases); j++) {
b = Getitem(bases,j);
inherit_contracts(b,n,contracts,messages);
b = Getitem(bases, j);
inherit_contracts(b, n, contracts, messages);
}
}
}
@ -182,8 +187,8 @@ void inherit_contracts(Node *c, Node *n, Hash *contracts, Hash *messages) {
Splitting the assertion into pieces */
String *Contracts::make_expression(String *s, Node *n) {
String *str_assert, *expr = 0;
List *list_assert;
String *str_assert, *expr = 0;
List *list_assert;
str_assert = NewString(s);
/* Omit all useless characters and split by ; */
@ -195,7 +200,7 @@ String *Contracts::make_expression(String *s, Node *n) {
list_assert = Split(str_assert, ';', -1);
Delete(str_assert);
/* build up new assertion */
str_assert = NewString("");
Iterator ei;
@ -203,7 +208,7 @@ String *Contracts::make_expression(String *s, Node *n) {
for (ei = First(list_assert); ei.item; ei = Next(ei)) {
expr = ei.item;
if (Len(expr)) {
Replaceid(expr, Getattr(n,"name"), "result");
Replaceid(expr, Getattr(n, "name"), "result");
if (Len(str_assert))
Append(str_assert, "&&");
Printf(str_assert, "(%s)", expr);
@ -218,18 +223,18 @@ String *Contracts::make_expression(String *s, Node *n) {
uses arg1--argn for arguments. */
void Contracts::substitute_parms(String *s, ParmList *p, int method) {
int argnum = 1;
char argname[32];
int argnum = 1;
char argname[32];
if (method) {
Replaceid(s,"self","arg0");
Replaceid(s, "self", "arg0");
argnum++;
}
while (p) {
sprintf(argname,"arg%d",argnum);
String *name = Getattr(p,"name");
sprintf(argname, "arg%d", argnum);
String *name = Getattr(p, "name");
if (name) {
Replaceid(s,name,argname);
Replaceid(s, name, argname);
}
argnum++;
p = nextSibling(p);
@ -237,8 +242,8 @@ void Contracts::substitute_parms(String *s, ParmList *p, int method) {
}
int Contracts::emit_contract(Node *n, int method) {
Hash *contracts;
Hash *messages;
Hash *contracts;
Hash *messages;
String *c;
ParmList *cparms;
@ -249,9 +254,10 @@ int Contracts::emit_contract(Node *n, int method) {
/* Get contract parameters */
cparms = Getmeta(Getattr(n, "feature:contract"), "parms");
/* Split contract into preassert & postassert */
/* Split contract into preassert & postassert */
contracts = ContractSplit(n);
if (!contracts) return SWIG_ERROR;
if (!contracts)
return SWIG_ERROR;
/* This messages hash is used to hold the error messages that will be displayed on
failed contract. */
@ -263,66 +269,71 @@ int Contracts::emit_contract(Node *n, int method) {
for (i = First(contracts); i.item; i = Next(i)) {
String *e = make_expression(i.item, n);
substitute_parms(e, cparms, method);
Setattr(contracts,i.key,e);
Setattr(contracts, i.key, e);
/* Make a string containing error messages */
Setattr(messages,i.key, NewString(e));
Setattr(messages, i.key, NewString(e));
}
/* If we're in a class. We need to inherit other assertions. */
if (InClass) {
inherit_contracts(CurrentClass, n, contracts, messages);
}
/* Save information */
Setattr(n,"contract:rules", contracts);
Setattr(n,"contract:messages", messages);
Setattr(n, "contract:rules", contracts);
Setattr(n, "contract:messages", messages);
/* Okay. Generate the contract runtime code. */
if ((c = Getattr(contracts,"require:"))) {
Setattr(n,"contract:preassert",
NewStringf("SWIG_contract_assert(%s, \"Contract violation: require: %s\");\n",
c, Getattr(messages,"require:")));
if ((c = Getattr(contracts, "require:"))) {
Setattr(n, "contract:preassert", NewStringf("SWIG_contract_assert(%s, \"Contract violation: require: %s\");\n", c, Getattr(messages, "require:")));
}
if ((c = Getattr(contracts,"ensure:"))) {
Setattr(n,"contract:postassert",
NewStringf("SWIG_contract_assert(%s, \"Contract violation: ensure: %s\");\n",
c, Getattr(messages,"ensure:")));
if ((c = Getattr(contracts, "ensure:"))) {
Setattr(n, "contract:postassert", NewStringf("SWIG_contract_assert(%s, \"Contract violation: ensure: %s\");\n", c, Getattr(messages, "ensure:")));
}
return SWIG_OK;
}
int Contracts::cDeclaration(Node *n) {
int ret = SWIG_OK;
String *decl = Getattr(n,"decl");
String *decl = Getattr(n, "decl");
/* Not a function. Don't even bother with it (for now) */
if (!SwigType_isfunction(decl)) return SWIG_OK;
if (!SwigType_isfunction(decl))
return SWIG_OK;
if (Getattr(n, "feature:contract"))
ret = emit_contract(n, (InClass && !checkAttribute(n,"storage","static")));
ret = emit_contract(n, (InClass && !checkAttribute(n, "storage", "static")));
return ret;
}
int Contracts::constructorDeclaration(Node *n){
int Contracts::constructorDeclaration(Node *n) {
int ret = SWIG_OK;
InConstructor = 1;
if (Getattr(n, "feature:contract"))
ret = emit_contract(n,0);
ret = emit_contract(n, 0);
InConstructor = 0;
return ret;
}
int Contracts::externDeclaration(Node *n) { return emit_children(n); }
int Contracts::extendDirective(Node *n) { return emit_children(n); }
int Contracts::importDirective(Node *n) { return emit_children(n); }
int Contracts::includeDirective(Node *n) { return emit_children(n); }
int Contracts::externDeclaration(Node *n) {
return emit_children(n);
}
int Contracts::extendDirective(Node *n) {
return emit_children(n);
}
int Contracts::importDirective(Node *n) {
return emit_children(n);
}
int Contracts::includeDirective(Node *n) {
return emit_children(n);
}
int Contracts::classDeclaration(Node *n) {
int ret = SWIG_OK;
InClass = 1;
CurrentClass = n;
CurrentClass = n;
emit_children(n);
InClass = 0;
CurrentClass = 0;

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@ char cvsroot_directors_cxx[] = "$Header";
*
*/
String *Swig_csuperclass_call(String* base, String* method, ParmList* l) {
String *Swig_csuperclass_call(String *base, String *method, ParmList *l) {
String *call = NewString("");
int arg_idx = 0;
Parm *p;
@ -28,13 +28,14 @@ String *Swig_csuperclass_call(String* base, String* method, ParmList* l) {
Printf(call, "%s::", base);
}
Printf(call, "%s(", method);
for (p=l; p; p = nextSibling(p)) {
for (p = l; p; p = nextSibling(p)) {
String *pname = Getattr(p, "name");
if (!pname && Cmp(Getattr(p,"type"), "void")) {
if (!pname && Cmp(Getattr(p, "type"), "void")) {
pname = NewString("");
Printf(pname, "arg%d", arg_idx++);
}
if (p != l) Printf(call, ", ");
if (p != l)
Printf(call, ", ");
Printv(call, pname, NIL);
}
Printf(call, ")");
@ -47,7 +48,7 @@ String *Swig_csuperclass_call(String* base, String* method, ParmList* l) {
* e.g. "class myclass"
*
*/
String *Swig_class_declaration(Node *n, String *name) {
if (!name) {
name = Getattr(n, "sym:name");
@ -63,7 +64,7 @@ String *Swig_class_name(Node *n) {
name = Copy(Getattr(n, "sym:name"));
return name;
}
/* Swig_director_declaration()
*
* Generate the full director class declaration, complete with base classes.
@ -72,7 +73,7 @@ String *Swig_class_name(Node *n) {
*/
String *Swig_director_declaration(Node *n) {
String* classname = Swig_class_name(n);
String *classname = Swig_class_name(n);
String *directorname = NewStringf("SwigDirector_%s", classname);
String *base = Getattr(n, "classtype");
String *declaration = Swig_class_declaration(n, directorname);
@ -89,24 +90,25 @@ String *Swig_method_call(String_or_char *name, ParmList *parms) {
int comma = 0;
Parm *p = parms;
SwigType *pt;
String *nname;
String *nname;
func = NewString("");
nname = SwigType_namestr(name);
Printf(func,"%s(", nname);
Printf(func, "%s(", nname);
while (p) {
String *pname;
pt = Getattr(p,"type");
pt = Getattr(p, "type");
if ((SwigType_type(pt) != T_VOID)) {
if (comma) Printf(func,",");
if (comma)
Printf(func, ",");
pname = Getattr(p, "name");
Printf(func,"%s", pname);
Printf(func, "%s", pname);
comma = 1;
i++;
}
p = nextSibling(p);
}
Printf(func,")");
Printf(func, ")");
return func;
}
@ -148,7 +150,7 @@ String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int
}
for (i = 0; i < nelements; i++) {
if (i < (nelements - 1)) {
nextelement = Getitem(elements, i+1);
nextelement = Getitem(elements, i + 1);
} else {
nextelement = 0;
}
@ -160,74 +162,75 @@ String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int
if (!Cmp(q, "const")) {
is_const = 1;
is_func = SwigType_isfunction(nextelement);
if (is_func) skip = 1;
if (is_func)
skip = 1;
skip = 1;
}
if (!skip) {
Insert(result,0," ");
Insert(result,0,q);
Insert(result, 0, " ");
Insert(result, 0, q);
}
Delete(q);
}
} else if (SwigType_ispointer(element)) {
Insert(result,0,"*");
Insert(result, 0, "*");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
Insert(result,0,"(");
Append(result,")");
Insert(result, 0, "(");
Append(result, ")");
}
} else if (SwigType_ismemberpointer(element)) {
String *q;
q = SwigType_parm(element);
Insert(result,0,"::*");
Insert(result,0,q);
Insert(result, 0, "::*");
Insert(result, 0, q);
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
Insert(result,0,"(");
Append(result,")");
Insert(result, 0, "(");
Append(result, ")");
}
Delete(q);
}
else if (SwigType_isreference(element)) {
Insert(result,0,"&");
} else if (SwigType_isarray(element)) {
} else if (SwigType_isreference(element)) {
Insert(result, 0, "&");
} else if (SwigType_isarray(element)) {
DOH *size;
Append(result,"[");
Append(result, "[");
size = SwigType_parm(element);
Append(result,size);
Append(result,"]");
Append(result, size);
Append(result, "]");
Delete(size);
} else if (SwigType_isfunction(element)) {
Parm *parm;
String *p;
Append(result,"(");
Append(result, "(");
parm = args;
while (parm != 0) {
String *type = Getattr(parm, "type");
String* name = Getattr(parm, "name");
if (!name && Cmp(type, "void")) {
name = NewString("");
Printf(name, "arg%d", arg_idx++);
Setattr(parm, "name", name);
String *type = Getattr(parm, "type");
String *name = Getattr(parm, "name");
if (!name && Cmp(type, "void")) {
name = NewString("");
Printf(name, "arg%d", arg_idx++);
Setattr(parm, "name", name);
}
if (!name) {
name = NewString("");
name = NewString("");
}
p = SwigType_str(type, name);
Append(result,p);
String* value = Getattr(parm, "value");
if (values && (value != 0)) {
Printf(result, " = %s", value);
}
Append(result, p);
String *value = Getattr(parm, "value");
if (values && (value != 0)) {
Printf(result, " = %s", value);
}
parm = nextSibling(parm);
if (parm != 0) Append(result,", ");
if (parm != 0)
Append(result, ", ");
}
Append(result,")");
Append(result, ")");
} else {
if (Strcmp(element,"v(...)") == 0) {
Insert(result,0,"...");
if (Strcmp(element, "v(...)") == 0) {
Insert(result, 0, "...");
} else {
String *bs = SwigType_namestr(element);
Insert(result,0," ");
Insert(result,0,bs);
Insert(result, 0, " ");
Insert(result, 0, bs);
Delete(bs);
}
}
@ -245,4 +248,3 @@ String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int
Chop(result);
return result;
}

View File

@ -34,11 +34,11 @@ void emit_args(SwigType *rt, ParmList *l, Wrapper *f) {
SwigType *vt = cplus_value_type(rt);
SwigType *tt = vt ? vt : rt;
SwigType *lt = SwigType_ltype(tt);
String *lstr = SwigType_str(lt,"result");
String *lstr = SwigType_str(lt, "result");
if (SwigType_ispointer(lt)) {
Wrapper_add_localv(f,"result", lstr, "= 0", NULL);
} else{
Wrapper_add_local(f,"result", lstr);
Wrapper_add_localv(f, "result", lstr, "= 0", NULL);
} else {
Wrapper_add_local(f, "result", lstr);
}
if (vt) {
Delete(vt);
@ -46,21 +46,21 @@ void emit_args(SwigType *rt, ParmList *l, Wrapper *f) {
Delete(lt);
Delete(lstr);
}
/* Attach typemaps to parameters */
/* Swig_typemap_attach_parms("ignore",l,f); */
Swig_typemap_attach_parms("default",l,f);
Swig_typemap_attach_parms("arginit",l,f);
Swig_typemap_attach_parms("default", l, f);
Swig_typemap_attach_parms("arginit", l, f);
/* Apply the arginit and default */
p = l;
while (p) {
tm = Getattr(p,"tmap:arginit");
tm = Getattr(p, "tmap:arginit");
if (tm) {
Replace(tm,"$target", Getattr(p,"lname"), DOH_REPLACE_ANY);
Printv(f->code,tm,"\n",NIL);
p = Getattr(p,"tmap:arginit:next");
Replace(tm, "$target", Getattr(p, "lname"), DOH_REPLACE_ANY);
Printv(f->code, tm, "\n", NIL);
p = Getattr(p, "tmap:arginit:next");
} else {
p = nextSibling(p);
}
@ -69,11 +69,11 @@ void emit_args(SwigType *rt, ParmList *l, Wrapper *f) {
/* Apply the default typemap */
p = l;
while (p) {
tm = Getattr(p,"tmap:default");
tm = Getattr(p, "tmap:default");
if (tm) {
Replace(tm,"$target", Getattr(p,"lname"), DOH_REPLACE_ANY);
Printv(f->code,tm,"\n",NIL);
p = Getattr(p,"tmap:default:next");
Replace(tm, "$target", Getattr(p, "lname"), DOH_REPLACE_ANY);
Printv(f->code, tm, "\n", NIL);
p = Getattr(p, "tmap:default:next");
} else {
p = nextSibling(p);
}
@ -88,11 +88,11 @@ void emit_args(SwigType *rt, ParmList *l, Wrapper *f) {
* ----------------------------------------------------------------------------- */
void emit_attach_parmmaps(ParmList *l, Wrapper *f) {
Swig_typemap_attach_parms("in",l,f);
Swig_typemap_attach_parms("typecheck",l,0);
Swig_typemap_attach_parms("argout",l,f);
Swig_typemap_attach_parms("check",l,f);
Swig_typemap_attach_parms("freearg",l,f);
Swig_typemap_attach_parms("in", l, f);
Swig_typemap_attach_parms("typecheck", l, 0);
Swig_typemap_attach_parms("argout", l, f);
Swig_typemap_attach_parms("check", l, f);
Swig_typemap_attach_parms("freearg", l, f);
{
/* This is compatibility code to deal with the deprecated "ignore" typemap */
@ -100,17 +100,17 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) {
Parm *np;
String *tm;
while (p) {
tm = Getattr(p,"tmap:in");
if (tm && checkAttribute(p,"tmap:in:numinputs","0")) {
Replaceall(tm,"$target", Getattr(p,"lname"));
Printv(f->code,tm,"\n",NIL);
np = Getattr(p,"tmap:in:next");
tm = Getattr(p, "tmap:in");
if (tm && checkAttribute(p, "tmap:in:numinputs", "0")) {
Replaceall(tm, "$target", Getattr(p, "lname"));
Printv(f->code, tm, "\n", NIL);
np = Getattr(p, "tmap:in:next");
while (p && (p != np)) {
Setattr(p,"ignore","1");
Setattr(p, "ignore", "1");
p = nextSibling(p);
}
} else if (tm) {
p = Getattr(p,"tmap:in:next");
p = Getattr(p, "tmap:in:next");
} else {
p = nextSibling(p);
}
@ -125,22 +125,22 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) {
Parm *p = l;
Parm *npin, *npfreearg;
while (p) {
npin = Getattr(p,"tmap:in:next");
/*
if (Getattr(p,"tmap:ignore")) {
npin = Getattr(p,"tmap:ignore:next");
} else if (Getattr(p,"tmap:in")) {
npin = Getattr(p,"tmap:in:next");
}
*/
npin = Getattr(p, "tmap:in:next");
if (Getattr(p,"tmap:freearg")) {
npfreearg = Getattr(p,"tmap:freearg:next");
/*
if (Getattr(p,"tmap:ignore")) {
npin = Getattr(p,"tmap:ignore:next");
} else if (Getattr(p,"tmap:in")) {
npin = Getattr(p,"tmap:in:next");
}
*/
if (Getattr(p, "tmap:freearg")) {
npfreearg = Getattr(p, "tmap:freearg:next");
if (npin != npfreearg) {
while (p != npin) {
Delattr(p,"tmap:freearg");
Delattr(p,"tmap:freearg:next");
Delattr(p, "tmap:freearg");
Delattr(p, "tmap:freearg:next");
p = nextSibling(p);
}
}
@ -148,7 +148,7 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) {
p = npin;
}
}
/* Check for variable length arguments with no input typemap.
If no input is defined, we set this to ignore and print a
message.
@ -157,25 +157,25 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) {
Parm *p = l;
Parm *lp = 0;
while (p) {
if (!checkAttribute(p,"tmap:in:numinputs","0")) {
if (!checkAttribute(p, "tmap:in:numinputs", "0")) {
lp = p;
p = Getattr(p,"tmap:in:next");
p = Getattr(p, "tmap:in:next");
continue;
}
if (SwigType_isvarargs(Getattr(p,"type"))) {
Swig_warning(WARN_LANG_VARARGS,input_file,line_number,"Variable length arguments discarded.\n");
Setattr(p,"tmap:in","");
if (SwigType_isvarargs(Getattr(p, "type"))) {
Swig_warning(WARN_LANG_VARARGS, input_file, line_number, "Variable length arguments discarded.\n");
Setattr(p, "tmap:in", "");
}
lp = 0;
p = nextSibling(p);
}
/* Check if last input argument is variable length argument */
if (lp) {
p = lp;
while (p) {
if (SwigType_isvarargs(Getattr(p,"type"))) {
Setattr(l,"emit:varargs",lp);
if (SwigType_isvarargs(Getattr(p, "type"))) {
Setattr(l, "emit:varargs", lp);
break;
}
p = nextSibling(p);
@ -194,12 +194,12 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) {
int emit_num_arguments(ParmList *parms) {
Parm *p = parms;
int nargs = 0;
int nargs = 0;
while (p) {
if (Getattr(p,"tmap:in")) {
nargs += GetInt(p,"tmap:in:numinputs");
p = Getattr(p,"tmap:in:next");
if (Getattr(p, "tmap:in")) {
nargs += GetInt(p, "tmap:in:numinputs");
p = Getattr(p, "tmap:in:next");
} else {
p = nextSibling(p);
}
@ -207,12 +207,12 @@ int emit_num_arguments(ParmList *parms) {
/* DB 04/02/2003: Not sure this is necessary with tmap:in:numinputs */
/*
if (parms && (p = Getattr(parms,"emit:varargs"))) {
if (!nextSibling(p)) {
nargs--;
}
}
*/
if (parms && (p = Getattr(parms,"emit:varargs"))) {
if (!nextSibling(p)) {
nargs--;
}
}
*/
return nargs;
}
@ -227,23 +227,25 @@ int emit_num_arguments(ParmList *parms) {
int emit_num_required(ParmList *parms) {
Parm *p = parms;
int nargs = 0;
int nargs = 0;
Parm *first_default_arg = 0;
int compactdefargs = ParmList_is_compactdefargs(p);
int compactdefargs = ParmList_is_compactdefargs(p);
while (p) {
if (Getattr(p,"tmap:in") && checkAttribute(p,"tmap:in:numinputs","0")) {
p = Getattr(p,"tmap:in:next");
if (Getattr(p, "tmap:in") && checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
} else {
if (Getattr(p,"tmap:default")) break;
if (Getattr(p,"value")) {
if (!first_default_arg)
first_default_arg = p;
if (compactdefargs) break;
if (Getattr(p, "tmap:default"))
break;
if (Getattr(p, "value")) {
if (!first_default_arg)
first_default_arg = p;
if (compactdefargs)
break;
}
nargs+= GetInt(p,"tmap:in:numinputs");
if (Getattr(p,"tmap:in")) {
p = Getattr(p,"tmap:in:next");
nargs += GetInt(p, "tmap:in:numinputs");
if (Getattr(p, "tmap:in")) {
p = Getattr(p, "tmap:in:next");
} else {
p = nextSibling(p);
}
@ -255,29 +257,29 @@ int emit_num_required(ParmList *parms) {
if (first_default_arg) {
p = first_default_arg;
while (p) {
if (Getattr(p,"tmap:in") && checkAttribute(p,"tmap:in:numinputs","0")) {
p = Getattr(p,"tmap:in:next");
if (Getattr(p, "tmap:in") && checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
} else {
if (!Getattr(p,"value") && (!Getattr(p,"tmap:default"))) {
Swig_error(Getfile(p),Getline(p),"Non-optional argument '%s' follows an optional argument.\n",Getattr(p,"name"));
}
if (Getattr(p,"tmap:in")) {
p = Getattr(p,"tmap:in:next");
} else {
p = nextSibling(p);
}
if (!Getattr(p, "value") && (!Getattr(p, "tmap:default"))) {
Swig_error(Getfile(p), Getline(p), "Non-optional argument '%s' follows an optional argument.\n", Getattr(p, "name"));
}
if (Getattr(p, "tmap:in")) {
p = Getattr(p, "tmap:in:next");
} else {
p = nextSibling(p);
}
}
}
}
/* DB 04/02/2003: Not sure this is necessary with tmap:in:numinputs */
/*
if (parms && (p = Getattr(parms,"emit:varargs"))) {
if (!nextSibling(p)) {
nargs--;
}
}
*/
if (parms && (p = Getattr(parms,"emit:varargs"))) {
if (!nextSibling(p)) {
nargs--;
}
}
*/
return nargs;
}
@ -287,10 +289,11 @@ int emit_num_required(ParmList *parms) {
* Checks if a function is a varargs function
* ----------------------------------------------------------------------------- */
int
emit_isvarargs(ParmList *p) {
if (!p) return 0;
if (Getattr(p,"emit:varargs")) return 1;
int emit_isvarargs(ParmList *p) {
if (!p)
return 0;
if (Getattr(p, "emit:varargs"))
return 1;
return 0;
}
@ -305,9 +308,9 @@ emit_isvarargs(ParmList *p) {
void emit_mark_varargs(ParmList *l) {
Parm *p = l;
while (p) {
if (SwigType_isvarargs(Getattr(p,"type")))
if (!Getattr(p,"tmap:in"))
Setattr(p,"varargs:ignore","1");
if (SwigType_isvarargs(Getattr(p, "type")))
if (!Getattr(p, "tmap:in"))
Setattr(p, "varargs:ignore", "1");
p = nextSibling(p);
}
}
@ -316,12 +319,11 @@ void emit_mark_varargs(ParmList *l) {
/* replace_contract_args. This function replaces argument names in contract
specifications. Used in conjunction with the %contract directive. */
static
void replace_contract_args(Parm *cp, Parm *rp, String *s) {
static void replace_contract_args(Parm *cp, Parm *rp, String *s) {
while (cp && rp) {
String *n = Getattr(cp,"name");
String *n = Getattr(cp, "name");
if (n) {
Replace(s,n,Getattr(rp,"lname"), DOH_REPLACE_ID);
Replace(s, n, Getattr(rp, "lname"), DOH_REPLACE_ID);
}
cp = nextSibling(cp);
rp = nextSibling(rp);
@ -336,18 +338,19 @@ void replace_contract_args(Parm *cp, Parm *rp, String *s) {
* ----------------------------------------------------------------------------- */
int emit_action_code(Node *n, Wrapper *f, String *eaction) {
/* Look for except feature */
String *tm = GetFlagAttr(n,"feature:except");
if (tm) tm = Copy(tm);
if ((tm) && Len(tm) && (Strcmp(tm,"1") != 0)) {
Replaceall(tm,"$name",Getattr(n,"name"));
Replaceall(tm,"$symname", Getattr(n,"sym:name"));
Replaceall(tm,"$function", eaction);
Replaceall(tm,"$action", eaction);
Printv(f->code,tm,"\n", NIL);
String *tm = GetFlagAttr(n, "feature:except");
if (tm)
tm = Copy(tm);
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
Replaceall(tm, "$name", Getattr(n, "name"));
Replaceall(tm, "$symname", Getattr(n, "sym:name"));
Replaceall(tm, "$function", eaction);
Replaceall(tm, "$action", eaction);
Printv(f->code, tm, "\n", NIL);
Delete(tm);
return 1;
} else {
Printv(f->code,eaction,"\n", NIL);
Printv(f->code, eaction, "\n", NIL);
return 0;
}
}
@ -357,120 +360,118 @@ void emit_action(Node *n, Wrapper *f) {
String *action;
String *wrap;
SwigType *rt;
ParmList *catchlist = Getattr(n,"catchlist");
ParmList *catchlist = Getattr(n, "catchlist");
/* Look for fragments */
{
String *f;
f = Getattr(n,"feature:fragment");
f = Getattr(n, "feature:fragment");
if (f) {
char *c, *tok;
char *c, *tok;
String *t = Copy(f);
c = Char(t);
tok = strtok(c,",");
tok = strtok(c, ",");
while (tok) {
String *fname = NewString(tok);
Setfile(fname, Getfile(n));
Setline(fname, Getline(n));
Swig_fragment_emit(fname);
Delete(fname);
tok = strtok(NULL,",");
tok = strtok(NULL, ",");
}
Delete(t);
}
}
/* Emit wrapper code (if any) */
wrap = Getattr(n,"wrap:code");
if (wrap && Swig_filebyname("header")!=Getattr(n,"wrap:code:done") ) {
wrap = Getattr(n, "wrap:code");
if (wrap && Swig_filebyname("header") != Getattr(n, "wrap:code:done")) {
File *f_code = Swig_filebyname("header");
if (f_code) {
Printv(f_code,wrap,NIL);
Printv(f_code, wrap, NIL);
}
Setattr(n,"wrap:code:done",f_code);
Setattr(n, "wrap:code:done", f_code);
}
action = Getattr(n,"feature:action");
action = Getattr(n, "feature:action");
if (!action)
action = Getattr(n,"wrap:action");
action = Getattr(n, "wrap:action");
assert(action != 0);
if (!is_public(n) && (is_member_director(n) || GetFlag(n, "explicitcall"))) {
/* In order to call protected virtual director methods from the target language, we need
* to add an extra dynamic_cast to call the public C++ wrapper in the director class. */
Node* parent = Getattr(n,"parentNode");
String* symname = Getattr(parent, "sym:name");
String* dirname = NewStringf("SwigDirector_%s", symname);
String* dirdecl = NewStringf("%s *darg = 0", dirname);
Node *parent = Getattr(n, "parentNode");
String *symname = Getattr(parent, "sym:name");
String *dirname = NewStringf("SwigDirector_%s", symname);
String *dirdecl = NewStringf("%s *darg = 0", dirname);
Wrapper_add_local(f, "darg", dirdecl);
Printf(f->code, "darg = dynamic_cast<%s *>(arg1);\n",dirname);
Printf(f->code, "darg = dynamic_cast<%s *>(arg1);\n", dirname);
Delete(dirname);
Delete(dirdecl);
}
/* Get the return type */
rt = Getattr(n,"type");
rt = Getattr(n, "type");
/* Emit contract code (if any) */
if (Swig_contract_mode_get()) {
/* Preassertion */
tm = Getattr(n, "contract:preassert");
if (Len(tm)) {
Printv(f->code,tm,"\n",NIL);
Printv(f->code, tm, "\n", NIL);
}
}
/* Exception handling code */
/* saves action -> eaction for postcatching exception */
String *eaction = NewString("");
/* If we are in C++ mode and there is an exception specification. We're going to
enclose the block in a try block */
if (catchlist) {
Printf(eaction,"try {\n");
Printf(eaction, "try {\n");
}
Printv(eaction, action, NIL);
if (catchlist) {
int unknown_catch = 0;
Printf(eaction,"}\n");
Printf(eaction, "}\n");
for (Parm *ep = catchlist; ep; ep = nextSibling(ep)) {
String *em = Swig_typemap_lookup_new("throws",ep,"_e",0);
String *em = Swig_typemap_lookup_new("throws", ep, "_e", 0);
if (em) {
SwigType *et = Getattr(ep,"type");
SwigType *etr = SwigType_typedef_resolve_all(et);
if (SwigType_isreference(etr) || SwigType_ispointer(etr) || SwigType_isarray(etr)) {
Printf(eaction,"catch(%s) {", SwigType_str(et, "_e"));
} else if (SwigType_isvarargs(etr)) {
Printf(eaction,"catch(...) {");
SwigType *et = Getattr(ep, "type");
SwigType *etr = SwigType_typedef_resolve_all(et);
if (SwigType_isreference(etr) || SwigType_ispointer(etr) || SwigType_isarray(etr)) {
Printf(eaction, "catch(%s) {", SwigType_str(et, "_e"));
} else if (SwigType_isvarargs(etr)) {
Printf(eaction, "catch(...) {");
} else {
Printf(eaction,"catch(%s) {", SwigType_str(et, "&_e"));
}
Printv(eaction,em,"\n",NIL);
Printf(eaction,"}\n");
Printf(eaction, "catch(%s) {", SwigType_str(et, "&_e"));
}
Printv(eaction, em, "\n", NIL);
Printf(eaction, "}\n");
} else {
Swig_warning(WARN_TYPEMAP_THROW, Getfile(n), Getline(n),
"No 'throws' typemap defined for exception type '%s'\n",
SwigType_str(Getattr(ep,"type"),0));
Swig_warning(WARN_TYPEMAP_THROW, Getfile(n), Getline(n), "No 'throws' typemap defined for exception type '%s'\n", SwigType_str(Getattr(ep, "type"), 0));
unknown_catch = 1;
}
}
if (unknown_catch) {
Printf(eaction,"catch(...) { throw; }\n");
Printf(eaction, "catch(...) { throw; }\n");
}
}
/* Look for except typemap (Deprecated) */
tm = Swig_typemap_lookup_new("except",n,"result",0);
tm = Swig_typemap_lookup_new("except", n, "result", 0);
if (tm) {
Setattr(n,"feature:except", tm);
Setattr(n, "feature:except", tm);
tm = 0;
}
/* emit the except feature code */
emit_action_code(n, f, eaction);
Delete(eaction);
/* Emit contract code (if any) */
@ -478,10 +479,8 @@ void emit_action(Node *n, Wrapper *f) {
/* Postassertion */
tm = Getattr(n, "contract:postassert");
if (Len(tm)) {
Printv(f->code,tm,"\n",NIL);
Printv(f->code, tm, "\n", NIL);
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -49,27 +49,26 @@ char cvsroot_lua_cxx[] = "$Header$";
This helps me search the parse tree & figure out what is going on inside SWIG
(because its not clear or documented)
*/
#define REPORT(T,D) // no info:
//#define REPORT(T,D) {Printf(stdout,T"\n");} // only title
//#define REPORT(T,D) {Printf(stdout,T"\n");display_mapping(D);} // the works
//#define REPORT(T,D) {Printf(stdout,T"\n");Swig_print_node(D);} // the works
#define REPORT(T,D) // no info:
//#define REPORT(T,D) {Printf(stdout,T"\n");} // only title
//#define REPORT(T,D) {Printf(stdout,T"\n");display_mapping(D);} // the works
//#define REPORT(T,D) {Printf(stdout,T"\n");Swig_print_node(D);} // the works
void display_mapping(DOH* d)
{
if (d==0 || !DohIsMapping(d)) return;
for(DohIterator it=DohFirst(d);it.item;it=DohNext(it))
{
if (DohIsString(it.item))
Printf(stdout, " %s = %s\n", it.key,it.item);
else if (DohIsMapping(it.item))
Printf(stdout, " %s = <mapping>\n", it.key);
else if (DohIsSequence(it.item))
Printf(stdout, " %s = <sequence>\n", it.key);
else
Printf(stdout, " %s = <unknown>\n", it.key);
}
void display_mapping(DOH *d) {
if (d == 0 || !DohIsMapping(d))
return;
for (DohIterator it = DohFirst(d); it.item; it = DohNext(it)) {
if (DohIsString(it.item))
Printf(stdout, " %s = %s\n", it.key, it.item);
else if (DohIsMapping(it.item))
Printf(stdout, " %s = <mapping>\n", it.key);
else if (DohIsSequence(it.item))
Printf(stdout, " %s = <sequence>\n", it.key);
else
Printf(stdout, " %s = <unknown>\n", it.key);
}
}
/* NEW LANGUAGE NOTE:***********************************************
@ -77,7 +76,7 @@ void display_mapping(DOH* d)
you can add new ones here
(though for now I have not bothered)
NEW LANGUAGE NOTE:END ************************************************/
static const char *usage = (char*)"\
static const char *usage = (char *) "\
Lua Options (available with -lua)\n\
(coming soon.)\n\n";
@ -89,7 +88,7 @@ Lua Options (available with -lua)\n\
(more on this as I figure it out)
NEW LANGUAGE NOTE:END ************************************************/
class LUA : public Language {
class LUA:public Language {
private:
File *f_runtime;
@ -98,16 +97,16 @@ private:
File *f_init;
File *f_initbeforefunc;
String *PrefixPlusUnderscore;
String *s_cmd_tab; // table of command names
String *s_var_tab; // table of global variables
String *s_const_tab; // table of global constants
String *s_methods_tab; // table of class methods
String *s_attr_tab; // table of class atributes
String *s_cmd_tab; // table of command names
String *s_var_tab; // table of global variables
String *s_const_tab; // table of global constants
String *s_methods_tab; // table of class methods
String *s_attr_tab; // table of class atributes
int have_constructor;
int have_destructor;
String* destructor_action;
String* class_name;
String *destructor_action;
String *class_name;
public:
@ -118,7 +117,7 @@ public:
* Initialize member data
* --------------------------------------------------------------------- */
LUA() {
LUA() {
f_runtime = 0;
f_header = 0;
f_wrappers = 0;
@ -126,22 +125,23 @@ public:
f_initbeforefunc = 0;
PrefixPlusUnderscore = 0;
s_cmd_tab=s_var_tab=s_const_tab=0;
s_cmd_tab = s_var_tab = s_const_tab = 0;
}
/* NEW LANGUAGE NOTE:***********************************************
This is called to initalise the system & read any command line args
most of this is boilerplate code, except the command line args
which depends upon what args your code supports
NEW LANGUAGE NOTE:END ************************************************/
/* ---------------------------------------------------------------------
/* NEW LANGUAGE NOTE:***********************************************
This is called to initalise the system & read any command line args
most of this is boilerplate code, except the command line args
which depends upon what args your code supports
NEW LANGUAGE NOTE:END ************************************************/
/* ---------------------------------------------------------------------
* main()
*
* Parse command line options and initializes variables.
* --------------------------------------------------------------------- */
virtual void main(int argc, char *argv[]) {
virtual void main(int argc, char *argv[]) {
/* Set location of SWIG library */
SWIG_library_directory("lua");
@ -149,9 +149,9 @@ NEW LANGUAGE NOTE:END ************************************************/
/* Look for certain command line options */
for (int i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp (argv[i], "-help") == 0) { // usage flags
fputs(usage,stderr);
}
if (strcmp(argv[i], "-help") == 0) { // usage flags
fputs(usage, stderr);
}
}
}
@ -224,10 +224,10 @@ NEW LANGUAGE NOTE:END ************************************************/
just before it is written to file
NEW LANGUAGE NOTE:END ************************************************/
// Initialize some variables for the object interface
s_cmd_tab = NewString("");
s_var_tab = NewString("");
s_cmd_tab = NewString("");
s_var_tab = NewString("");
// s_methods_tab = NewString("");
s_const_tab = NewString("");
s_const_tab = NewString("");
/* Standard stuff for the SWIG runtime section */
Swig_banner(f_runtime);
@ -235,34 +235,34 @@ NEW LANGUAGE NOTE:END ************************************************/
// Printf(f_runtime, "#define SWIG_NOINCLUDE\n");
// }
String *init_name = NewStringf("%(title)s_Init",module);
String *init_name = NewStringf("%(title)s_Init", module);
Printf(f_header, "#define SWIG_init %s\n", init_name);
Printf(f_header, "#define SWIG_name \"%s\"\n", module);
/* SWIG_import is a special function name for importing within Lua5.1 */
Printf(f_header, "#define SWIG_import luaopen_%s\n\n", module);
Printf(s_cmd_tab, "\nstatic const struct luaL_reg swig_commands[] = {\n");
Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n");
Printf(s_cmd_tab, "\nstatic const struct luaL_reg swig_commands[] = {\n");
Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n");
Printf(s_const_tab, "\nstatic swig_lua_const_info swig_constants[] = {\n");
Printf(f_wrappers,"#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
/* Change naming scheme for constructors and destructors */
// Swig_name_register("construct","%c_create");
// Swig_name_register("destroy","%c_destroy");
/* %init code inclusion, effectively in the SWIG_init function */
Printf(f_init,"#ifdef __cplusplus\nextern \"C\"\n#endif\n");
Printf(f_init, "#ifdef __cplusplus\nextern \"C\"\n#endif\n");
Printf(f_init, "void SWIG_init_user(lua_State* L)\n{\n");
Language::top(n);
Printf(f_init, "}\n" );
Printf(f_init, "}\n");
Printf(f_wrappers,"#ifdef __cplusplus\n}\n#endif\n");
Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n");
// Done. Close up the module & write to the wrappers
Printv(s_cmd_tab, tab4, "{0,0}\n", "};\n",NIL);
Printv(s_var_tab, tab4, "{0,0,0}\n", "};\n",NIL);
Printv(s_cmd_tab, tab4, "{0,0}\n", "};\n", NIL);
Printv(s_var_tab, tab4, "{0,0,0}\n", "};\n", NIL);
Printv(s_const_tab, tab4, "{0,0,0,0,0,0}\n", "};\n", NIL);
Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab,NIL);
Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL);
SwigType_emit_type_table(f_runtime, f_wrappers);
//
@ -317,21 +317,22 @@ NEW LANGUAGE NOTE:END ************************************************/
virtual int functionWrapper(Node *n) {
// REPORT("functionWrapper",n);
String *name = Getattr(n,"name");
String *iname = Getattr(n,"sym:name");
SwigType *d = Getattr(n,"type");
ParmList *l = Getattr(n,"parms");
String *name = Getattr(n, "name");
String *iname = Getattr(n, "sym:name");
SwigType *d = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
Parm *p;
String *tm;
int i;
// int returnval=0; // number of arguments returned
// int returnval=0; // number of arguments returned
String *overname = 0;
if (Getattr(n,"sym:overloaded")) {
overname = Getattr(n,"sym:overname");
if (Getattr(n, "sym:overloaded")) {
overname = Getattr(n, "sym:overname");
} else {
if (!addSymbol(iname,n)) return SWIG_ERROR;
if (!addSymbol(iname, n))
return SWIG_ERROR;
}
/* NEW LANGUAGE NOTE:***********************************************
@ -339,12 +340,12 @@ NEW LANGUAGE NOTE:END ************************************************/
we need to add a couple of local variables
NEW LANGUAGE NOTE:END ************************************************/
Wrapper *f = NewWrapper();
Wrapper_add_local(f,"SWIG_arg", "int SWIG_arg = -1");
Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = -1");
String *wname = Swig_name_wrapper(iname);
if (overname) {
Append(wname,overname);
Append(wname, overname);
}
/* NEW LANGUAGE NOTE:***********************************************
@ -352,9 +353,7 @@ NEW LANGUAGE NOTE:END ************************************************/
static int wrap_XXX(lua_State* L){...}
this line adds this into the wrappering code
NEW LANGUAGE NOTE:END ************************************************/
Printv(f->def,
"static int ", wname, "(lua_State* L) {",
NIL);
Printv(f->def, "static int ", wname, "(lua_State* L) {", NIL);
/* NEW LANGUAGE NOTE:***********************************************
this prints the list of args, eg for a C fn
@ -368,12 +367,12 @@ NEW LANGUAGE NOTE:END ************************************************/
emit_args(d, l, f);
/* Attach the standard typemaps */
emit_attach_parmmaps(l,f);
Setattr(n,"wrap:parms",l);
emit_attach_parmmaps(l, f);
Setattr(n, "wrap:parms", l);
/* Get number of required and total arguments */
int num_arguments = emit_num_arguments(l);
int num_required = emit_num_required(l);
int num_required = emit_num_required(l);
int varargs = emit_isvarargs(l);
/* Which input argument to start with? */
@ -398,25 +397,25 @@ NEW LANGUAGE NOTE:END ************************************************/
NEW LANGUAGE NOTE:END ************************************************/
String *argument_check = NewString("");
String *argument_parse = NewString("");
String *checkfn=NULL;
String *checkfn = NULL;
// String *numoutputs=NULL;
char source[64];
for (i = 0, p = l; i < num_arguments; i++) {
while (checkAttribute(p,"tmap:in:numinputs","0")) {
p = Getattr(p,"tmap:in:next");
while (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
}
SwigType *pt = Getattr(p,"type");
String *ln = Getattr(p,"lname");
SwigType *pt = Getattr(p, "type");
String *ln = Getattr(p, "lname");
/* Look for an input typemap */
sprintf(source, "%d", i+1);
if ((tm = Getattr(p,"tmap:in"))) {
Replaceall(tm, "$source", source);
Replaceall(tm, "$target", ln);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source);
/* Look for an input typemap */
sprintf(source, "%d", i + 1);
if ((tm = Getattr(p, "tmap:in"))) {
Replaceall(tm, "$source", source);
Replaceall(tm, "$target", ln);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source);
/* NEW LANGUAGE NOTE:***********************************************
look for a 'checkfn' typemap
@ -425,61 +424,55 @@ NEW LANGUAGE NOTE:END ************************************************/
this will result in code either in the
argument_check or argument_parse string
NEW LANGUAGE NOTE:END ************************************************/
if ((checkfn=Getattr(p,"tmap:in:checkfn"))){
if (i<num_required)
{
Printf(argument_check,"if(!%s(L,%s))",checkfn,source);
}
else
{
Printf(argument_check,"if(lua_gettop(L)>=%s && !%s(L,%s))",source,checkfn,source);
}
Printf(argument_check," SWIG_fail_arg(%s);\n",source);
}
if ((checkfn = Getattr(p, "tmap:in:checkfn"))) {
if (i < num_required) {
Printf(argument_check, "if(!%s(L,%s))", checkfn, source);
} else {
Printf(argument_check, "if(lua_gettop(L)>=%s && !%s(L,%s))", source, checkfn, source);
}
Printf(argument_check, " SWIG_fail_arg(%s);\n", source);
}
/* NEW LANGUAGE NOTE:***********************************************
lua states the number of arguments passed to a function using the fn
lua_gettop()
we can use this to deal with default arguments
NEW LANGUAGE NOTE:END ************************************************/
if (i<num_required){
Printf(argument_parse, "%s\n", tm);
}
else
{
Printf(argument_parse,"if(lua_gettop(L)>=%s){%s}\n",source,tm);
}
p = Getattr(p,"tmap:in:next");
continue;
} else {
if (i < num_required) {
Printf(argument_parse, "%s\n", tm);
} else {
Printf(argument_parse, "if(lua_gettop(L)>=%s){%s}\n", source, tm);
}
p = Getattr(p, "tmap:in:next");
continue;
} else {
/* NEW LANGUAGE NOTE:***********************************************
// why is this code not called when I dont have a typemap?
// instead of giving a warning, no code is generated
NEW LANGUAGE NOTE:END ************************************************/
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number,
"Unable to use type %s as a function argument.\n",SwigType_str(pt,0));
break;
}
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
break;
}
p = nextSibling(p);
}
// add all argcheck code
Printv(f->code,argument_check,argument_parse,NIL);
Printv(f->code, argument_check, argument_parse, NIL);
/* Check for trailing varargs */
if (varargs) {
if (p && (tm = Getattr(p,"tmap:in"))) {
Replaceall(tm,"$input", "varargs");
Printv(f->code,tm,"\n",NIL);
if (p && (tm = Getattr(p, "tmap:in"))) {
Replaceall(tm, "$input", "varargs");
Printv(f->code, tm, "\n", NIL);
}
}
/* Insert constraint checking code */
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:check"))) {
Replaceall(tm,"$target",Getattr(p,"lname"));
Printv(f->code,tm,"\n",NIL);
p = Getattr(p,"tmap:check:next");
if ((tm = Getattr(p, "tmap:check"))) {
Replaceall(tm, "$target", Getattr(p, "lname"));
Printv(f->code, tm, "\n", NIL);
p = Getattr(p, "tmap:check:next");
} else {
p = nextSibling(p);
}
@ -488,10 +481,10 @@ NEW LANGUAGE NOTE:END ************************************************/
/* Insert cleanup code */
String *cleanup = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:freearg"))) {
Replaceall(tm,"$source",Getattr(p,"lname"));
Printv(cleanup,tm,"\n",NIL);
p = Getattr(p,"tmap:freearg:next");
if ((tm = Getattr(p, "tmap:freearg"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
p = Getattr(p, "tmap:freearg:next");
} else {
p = nextSibling(p);
}
@ -500,109 +493,108 @@ NEW LANGUAGE NOTE:END ************************************************/
/* Insert argument output code */
String *outarg = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:argout"))) {
// // managing the number of returning variables
if ((tm = Getattr(p, "tmap:argout"))) {
// // managing the number of returning variables
// if (numoutputs=Getattr(p,"tmap:argout:numoutputs")){
// int i=GetInt(p,"tmap:argout:numoutputs");
// printf("got argout:numoutputs of %d\n",i);
// returnval+=GetInt(p,"tmap:argout:numoutputs");
// int i=GetInt(p,"tmap:argout:numoutputs");
// printf("got argout:numoutputs of %d\n",i);
// returnval+=GetInt(p,"tmap:argout:numoutputs");
// }
// else returnval++;
Replaceall(tm,"$source",Getattr(p,"lname"));
Replaceall(tm,"$target","result");
Replaceall(tm,"$arg",Getattr(p,"emit:input"));
Replaceall(tm,"$input",Getattr(p,"emit:input"));
Printv(outarg,tm,"\n",NIL);
p = Getattr(p,"tmap:argout:next");
Replaceall(tm, "$source", Getattr(p, "lname"));
Replaceall(tm, "$target", "result");
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(outarg, tm, "\n", NIL);
p = Getattr(p, "tmap:argout:next");
} else {
p = nextSibling(p);
p = nextSibling(p);
}
}
/* Emit the function call */
emit_action(n,f);
emit_action(n, f);
/* NEW LANGUAGE NOTE:***********************************************
FIXME:
returns 1 if there is a void return type
this is because there is a typemap for void
NEW LANGUAGE NOTE:END ************************************************/
Printv(f->code,"SWIG_arg=0;\n",NIL);
Printv(f->code, "SWIG_arg=0;\n", NIL);
// Return value if necessary
if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) {
if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) {
// managing the number of returning variables
// if (numoutputs=Getattr(tm,"numoutputs")){
// int i=GetInt(tm,"numoutputs");
// printf("return numoutputs %d\n",i);
// returnval+=GetInt(tm,"numoutputs");
// int i=GetInt(tm,"numoutputs");
// printf("return numoutputs %d\n",i);
// returnval+=GetInt(tm,"numoutputs");
// }
// else returnval++;
Replaceall(tm,"$source", "result");
if (GetFlag(n,"feature:new")) {
Replaceall(tm,"$owner","1");
} else {
Replaceall(tm,"$owner","0");
}
Printf(f->code,"%s\n", tm);
Replaceall(tm, "$source", "result");
if (GetFlag(n, "feature:new")) {
Replaceall(tm, "$owner", "1");
} else {
Replaceall(tm, "$owner", "0");
}
Printf(f->code, "%s\n", tm);
// returnval++;
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number,
"Unable to use return type %s in function %s.\n", SwigType_str(d,0), name);
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);
}
/* Output argument output code */
Printv(f->code,outarg,NIL);
Printv(f->code, outarg, NIL);
/* Output cleanup code */
Printv(f->code,cleanup,NIL);
Printv(f->code, cleanup, NIL);
/* Look to see if there is any newfree cleanup code */
if (GetFlag(n,"feature:new")) {
if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) {
Replaceall(tm,"$source","result");
Printf(f->code,"%s\n",tm);
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) {
Replaceall(tm, "$source", "result");
Printf(f->code, "%s\n", tm);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) {
Replaceall(tm,"$source","result");
Printf(f->code,"%s\n",tm);
Replaceall(tm, "$source", "result");
Printf(f->code, "%s\n", tm);
}
/* Close the function */
Printv(f->code, "return SWIG_arg;\n",NIL);
Printv(f->code, "return SWIG_arg;\n", NIL);
// add the failure cleanup code:
Printv(f->code, "\nfail:\n",NIL);
Printv(f->code, "$cleanup","lua_error(L);\n",NIL);
Printv(f->code, "return SWIG_arg;\n",NIL);
Printv(f->code, "\nfail:\n", NIL);
Printv(f->code, "$cleanup", "lua_error(L);\n", NIL);
Printv(f->code, "return SWIG_arg;\n", NIL);
Printf(f->code, "}\n");
/* Substitute the cleanup code */
Replaceall(f->code,"$cleanup",cleanup);
Replaceall(f->code, "$cleanup", cleanup);
/* Substitute the function name */
Replaceall(f->code,"$symname",iname);
Replaceall(f->code,"$result","result");
Replaceall(f->code, "$symname", iname);
Replaceall(f->code, "$result", "result");
/* Dump the function out */
Wrapper_print(f,f_wrappers);
Wrapper_print(f, f_wrappers);
Setattr(n,"wrap:name", wname); // you need this to make the overloading work
Setattr(n, "wrap:name", wname); // you need this to make the overloading work
/* NEW LANGUAGE NOTE:***********************************************
register the function in SWIG
different language mappings seem to use different ideas
NEW LANGUAGE NOTE:END ************************************************/
/* Now register the function with the interpreter. */
if (!Getattr(n,"sym:overloaded")) {
if (!Getattr(n, "sym:overloaded")) {
// add_method(n, iname, wname, description);
Printv(s_cmd_tab, tab4, "{ \"", iname, "\", ", Swig_name_wrapper(iname), "},\n", NIL);
// Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", Swig_name_wrapper(iname), "},\n", NIL);
} else {
// Setattr(n,"wrap:name", wname);
if (!Getattr(n,"sym:nextSibling")) {
if (!Getattr(n, "sym:nextSibling")) {
dispatchFunction(n);
}
}
@ -636,37 +628,34 @@ NEW LANGUAGE NOTE:END ************************************************/
int maxargs;
String *tmp = NewString("");
String *dispatch = Swig_overload_dispatch(n,"return %s(L);",&maxargs);
String *dispatch = Swig_overload_dispatch(n, "return %s(L);", &maxargs);
/* Generate a dispatch wrapper for all overloaded functions */
Wrapper *f = NewWrapper();
String *symname = Getattr(n,"sym:name");
String *wname = Swig_name_wrapper(symname);
Wrapper *f = NewWrapper();
String *symname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(symname);
//Printf(stdout,"Swig_overload_dispatch %s %s '%s' %d\n",symname,wname,dispatch,maxargs);
Printv(f->def,
"static int ", wname, "(lua_State* L) {",
NIL);
Wrapper_add_local(f,"argc","int argc");
Printf(tmp,"int argv[%d]={1", maxargs+1);
for(int i=1;i<=maxargs;i++)
{
Printf(tmp,",%d",i+1);
}
Printf(tmp,"}");
Wrapper_add_local(f,"argv",tmp);
Printf(f->code,"argc = lua_gettop(L);\n");
Printv(f->def, "static int ", wname, "(lua_State* L) {", NIL);
Wrapper_add_local(f, "argc", "int argc");
Printf(tmp, "int argv[%d]={1", maxargs + 1);
for (int i = 1; i <= maxargs; i++) {
Printf(tmp, ",%d", i + 1);
}
Printf(tmp, "}");
Wrapper_add_local(f, "argv", tmp);
Printf(f->code, "argc = lua_gettop(L);\n");
Replaceall(dispatch,"$args","self,args");
Printv(f->code,dispatch,"\n",NIL);
Printf(f->code,"lua_pushstring(L,\"No matching function for overloaded '%s'\");\n", symname);
Printf(f->code,"lua_error(L);return 0;\n");
Printv(f->code,"}\n",NIL);
Wrapper_print(f,f_wrappers);
Replaceall(dispatch, "$args", "self,args");
Printv(f->code, dispatch, "\n", NIL);
Printf(f->code, "lua_pushstring(L,\"No matching function for overloaded '%s'\");\n", symname);
Printf(f->code, "lua_error(L);return 0;\n");
Printv(f->code, "}\n", NIL);
Wrapper_print(f, f_wrappers);
//add_method(symname,wname,0);
Printv(s_cmd_tab, tab4, "{ \"", symname, "\",", wname, "},\n", NIL);
Printv(s_cmd_tab, tab4, "{ \"", symname, "\",", wname, "},\n", NIL);
DelWrapper(f);
Delete(dispatch);
@ -687,68 +676,68 @@ so we will just add these into the variable lists
ideally we should not have registered these as functions,
only WRT this variable will look into this later.
NEW LANGUAGE NOTE:END ************************************************/
REPORT("variableWrapper",n);
String *iname = Getattr(n,"sym:name");
SwigType *type = Getattr(n,"type");
REPORT("variableWrapper", n);
String *iname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
// let SWIG generate the wrappers
int result=Language::variableWrapper(n);
int result = Language::variableWrapper(n);
// normally SWIG will generate 2 wrappers, a get and a set
// but in certain scenarios (immutable, or if its arrays), it will not
String *getName=Swig_name_wrapper(Swig_name_get(iname));
String *setName=0;
if (is_assignable(n)==false || SwigType_isarray(type)) {
// TODO: how about calling a 'this is not settable' error message?
setName=NewString("0");
String *getName = Swig_name_wrapper(Swig_name_get(iname));
String *setName = 0;
if (is_assignable(n) == false || SwigType_isarray(type)) {
// TODO: how about calling a 'this is not settable' error message?
setName = NewString("0");
} else {
setName=Swig_name_wrapper(Swig_name_set(iname));
setName = Swig_name_wrapper(Swig_name_set(iname));
}
// register the variable
Printf(s_var_tab,"%s{ \"%s\", %s, %s },\n",tab4,iname,getName,setName);
Printf(s_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, iname, getName, setName);
Delete(getName);
Delete(setName);
return result;
return result;
}
/* ------------------------------------------------------------
* constantWrapper()
* ------------------------------------------------------------ */
virtual int constantWrapper(Node *n) {
REPORT("constantWrapper",n);
String *name = Getattr(n,"name");
String *iname = Getattr(n,"sym:name");
virtual int constantWrapper(Node *n) {
REPORT("constantWrapper", n);
String *name = Getattr(n, "name");
String *iname = Getattr(n, "sym:name");
//String *nsname = !nspace ? Copy(iname) : NewStringf("%s::%s",ns_name,iname);
String *nsname = Copy(iname);
SwigType *type = Getattr(n,"type");
String *rawval = Getattr(n,"rawval");
String *value = rawval ? rawval : Getattr(n,"value");
String *nsname = Copy(iname);
SwigType *type = Getattr(n, "type");
String *rawval = Getattr(n, "rawval");
String *value = rawval ? rawval : Getattr(n, "value");
String *tm;
if (!addSymbol(iname,n)) return SWIG_ERROR;
if (!addSymbol(iname, n))
return SWIG_ERROR;
//if (nspace) Setattr(n,"sym:name",nsname);
/* Special hook for member pointer */
if (SwigType_type(type) == T_MPOINTER) {
String *wname = Swig_name_wrapper(iname);
Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type,wname), value);
Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type, wname), value);
value = Char(wname);
}
if ((tm = Swig_typemap_lookup_new("consttab",n,name,0))) {
Replaceall(tm,"$source",value);
Replaceall(tm,"$target",name);
Replaceall(tm,"$value",value);
Replaceall(tm,"$nsname",nsname);
Printf(s_const_tab,"%s,\n", tm);
if ((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
Replaceall(tm, "$nsname", nsname);
Printf(s_const_tab, "%s,\n", tm);
} else if ((tm = Swig_typemap_lookup_new("constcode", n, name, 0))) {
Replaceall(tm,"$source", value);
Replaceall(tm,"$target", name);
Replaceall(tm,"$value",value);
Replaceall(tm,"$nsname",nsname);
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
Replaceall(tm, "$nsname", nsname);
Printf(f_init, "%s\n", tm);
} else {
Delete(nsname);
Swig_warning(WARN_TYPEMAP_CONST_UNDEF,
input_file, line_number, "Unsupported constant value.\n");
Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n");
return SWIG_NOWRAP;
}
Delete(nsname);
@ -760,10 +749,11 @@ virtual int constantWrapper(Node *n) {
* ------------------------------------------------------------ */
virtual int nativeWrapper(Node *n) {
REPORT("nativeWrapper",n);
String *symname = Getattr(n,"sym:name");
String *wrapname = Getattr(n,"wrap:name");
if (!addSymbol(wrapname,n)) return SWIG_ERROR;
REPORT("nativeWrapper", n);
String *symname = Getattr(n, "sym:name");
String *wrapname = Getattr(n, "wrap:name");
if (!addSymbol(wrapname, n))
return SWIG_ERROR;
Printv(s_cmd_tab, tab4, "{ \"", symname, "\",", wrapname, "},\n", NIL);
// return Language::nativeWrapper(n); // this does nothing...
@ -798,20 +788,21 @@ virtual int constantWrapper(Node *n) {
* classHandler()
* ------------------------------------------------------------ */
virtual int classHandler(Node *n) {
REPORT("classHandler",n);
virtual int classHandler(Node *n) {
REPORT("classHandler", n);
String *mangled_classname = 0;
String *real_classname = 0;
String *mangled_classname = 0;
String *real_classname = 0;
have_constructor = 0;
have_destructor = 0;
destructor_action = 0;
class_name = Getattr(n,"sym:name");
if (!addSymbol(class_name,n)) return SWIG_ERROR;
class_name = Getattr(n, "sym:name");
if (!addSymbol(class_name, n))
return SWIG_ERROR;
real_classname = Getattr(n,"name");
real_classname = Getattr(n, "name");
mangled_classname = Swig_name_mangle(real_classname);
// note: tcl has a static hashtable of all classes emitted, I wonder why?
@ -825,21 +816,21 @@ virtual int constantWrapper(Node *n) {
Printv(s_attr_tab, mangled_classname, "_attributes[] = {\n", NIL);
s_methods_tab = NewString("");
Printf(s_methods_tab,"static swig_lua_method swig_");
Printf(s_methods_tab, "static swig_lua_method swig_");
Printv(s_methods_tab, mangled_classname, "_methods[] = {\n", NIL);
// Generate normal wrappers
// Generate normal wrappers
//return SWIG_OK;
Language::classHandler(n);
//return SWIG_OK;
SwigType *t = Copy(Getattr(n,"name"));
SwigType *t = Copy(Getattr(n, "name"));
SwigType_add_pointer(t);
// Catch all: eg. a class with only static functions and/or variables will not have 'remembered'
String *wrap_class = NewStringf("&_wrap_class_%s", mangled_classname);
SwigType_remember_clientdata(t,wrap_class);
SwigType_remember_clientdata(t, wrap_class);
String *rt = Copy(Getattr(n,"classtype"));
String *rt = Copy(Getattr(n, "classtype"));
SwigType_add_pointer(rt);
// Register the class structure with the type checker
@ -847,39 +838,39 @@ virtual int constantWrapper(Node *n) {
if (have_destructor) {
Printv(f_wrappers, "static void swig_delete_", class_name, "(void *obj) {\n", NIL);
if (destructor_action) {
Printv(f_wrappers, SwigType_str(rt,"arg1"), " = (", SwigType_str(rt,0), ") obj;\n", NIL);
Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL);
Printv(f_wrappers, destructor_action, NIL);
} else {
if (CPlusPlus) {
Printv(f_wrappers," delete (", SwigType_str(rt,0), ") obj;\n",NIL);
Printv(f_wrappers, " delete (", SwigType_str(rt, 0), ") obj;\n", NIL);
} else {
Printv(f_wrappers," free((char *) obj);\n",NIL);
Printv(f_wrappers, " free((char *) obj);\n", NIL);
}
}
Printf(f_wrappers,"}\n");
Printf(f_wrappers, "}\n");
}
Printf(s_methods_tab, " {0,0}\n};\n");
Printv(f_wrappers,s_methods_tab,NIL);
Printv(f_wrappers, s_methods_tab, NIL);
Printf(s_attr_tab, " {0,0,0}\n};\n");
Printv(f_wrappers,s_attr_tab,NIL);
Printv(f_wrappers, s_attr_tab, NIL);
Delete(s_methods_tab);
Delete(s_attr_tab);
Delete(s_methods_tab);
Delete(s_attr_tab);
// Handle inheritance
String *base_class = NewString("");
List *baselist = Getattr(n,"bases");
List *baselist = Getattr(n, "bases");
if (baselist && Len(baselist)) {
Iterator b;
int index = 0;
b = First(baselist);
while (b.item) {
String *bname = Getattr(b.item, "name");
if ((!bname) || GetFlag(b.item,"feature:ignore") || (!Getattr(b.item,"module"))) {
if ((!bname) || GetFlag(b.item, "feature:ignore") || (!Getattr(b.item, "module"))) {
b = Next(b);
continue;
}
@ -889,15 +880,15 @@ virtual int constantWrapper(Node *n) {
Printv( base_class_init , " ", bname, "Ptr::constructor $ptr\n", NIL );
}*/
String *bmangle = Swig_name_mangle(bname);
// Printv(f_wrappers,"extern swig_class _wrap_class_", bmangle, ";\n", NIL);
Printf(base_class,"&_wrap_class_%s",bmangle);
// Printv(f_wrappers,"extern swig_class _wrap_class_", bmangle, ";\n", NIL);
Printf(base_class, "&_wrap_class_%s", bmangle);
// Put code to register base classes in init function
// Printf(f_init,"/* Register base : %s */\n", bmangle);
// Printf(f_init,"swig_%s_bases[%d] = (swig_class *) SWIG_TypeQuery(\"%s *\")->clientdata;\n", mangled_classname, index, SwigType_namestr(bname));
// Printf(f_init,"/* Register base : %s */\n", bmangle);
// Printf(f_init,"swig_%s_bases[%d] = (swig_class *) SWIG_TypeQuery(\"%s *\")->clientdata;\n", mangled_classname, index, SwigType_namestr(bname));
b = Next(b);
index++;
Putc(',',base_class);
Putc(',', base_class);
Delete(bmangle);
}
}
@ -919,23 +910,22 @@ virtual int constantWrapper(Node *n) {
}
}*/
Printv(f_wrappers,"static swig_lua_class *swig_",mangled_classname,"_bases[] = {", base_class,"0};\n", NIL);
Printv(f_wrappers, "static swig_lua_class *swig_", mangled_classname, "_bases[] = {", base_class, "0};\n", NIL);
Delete(base_class);
Printv(f_wrappers, "swig_lua_class _wrap_class_", mangled_classname, " = { \"", class_name,
"\", &SWIGTYPE", SwigType_manglestr(t), ",",NIL);
Printv(f_wrappers, "swig_lua_class _wrap_class_", mangled_classname, " = { \"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL);
if (have_constructor) {
Printf(f_wrappers,"%s", Swig_name_wrapper(Swig_name_construct(class_name)));
Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(class_name)));
} else {
Printf(f_wrappers,"0");
Printf(f_wrappers, "0");
}
if (have_destructor) {
Printv(f_wrappers, ", swig_delete_", class_name,NIL);
Printv(f_wrappers, ", swig_delete_", class_name, NIL);
} else {
Printf(f_wrappers,",0");
Printf(f_wrappers, ",0");
}
Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname,"_bases };\n\n", NIL);
Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname, "_bases };\n\n", NIL);
// Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, &_wrap_class_", mangled_classname, "},\n", NIL);
Delete(t);
Delete(mangled_classname);
@ -947,16 +937,16 @@ virtual int constantWrapper(Node *n) {
* ------------------------------------------------------------ */
virtual int memberfunctionHandler(Node *n) {
String *name = Getattr(n,"name");
String *iname = GetChar(n,"sym:name");
String *name = Getattr(n, "name");
String *iname = GetChar(n, "sym:name");
String *realname, *rname;
String *realname, *rname;
Language::memberfunctionHandler(n);
realname = iname ? iname : name;
rname = Swig_name_wrapper(Swig_name_member(class_name, realname));
if (!Getattr(n,"sym:nextSibling")) {
if (!Getattr(n, "sym:nextSibling")) {
Printv(s_methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL);
}
Delete(rname);
@ -969,17 +959,17 @@ virtual int constantWrapper(Node *n) {
virtual int membervariableHandler(Node *n) {
// REPORT("membervariableHandler",n);
String *symname = Getattr(n,"sym:name");
String *rname;
String *symname = Getattr(n, "sym:name");
String *rname;
Language::membervariableHandler(n);
Printv(s_attr_tab, tab4, "{ \"", symname, "\",", NIL);
rname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name,symname)));
rname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name, symname)));
Printv(s_attr_tab, rname, ", ", NIL);
Delete(rname);
if (!GetFlag(n,"feature:immutable")) {
rname = Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name,symname)));
Printv(s_attr_tab, rname, "},\n",NIL);
if (!GetFlag(n, "feature:immutable")) {
rname = Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name, symname)));
Printv(s_attr_tab, rname, "},\n", NIL);
Delete(rname);
} else {
Printf(s_attr_tab, "0 },\n");
@ -993,7 +983,7 @@ virtual int constantWrapper(Node *n) {
* Method for adding C++ member constructor
* ------------------------------------------------------------ */
virtual int constructorHandler(Node *n) {
virtual int constructorHandler(Node *n) {
Language::constructorHandler(n);
have_constructor = 1;
return SWIG_OK;
@ -1006,7 +996,7 @@ virtual int constantWrapper(Node *n) {
virtual int destructorHandler(Node *n) {
Language::destructorHandler(n);
have_destructor = 1;
destructor_action = Getattr(n,"wrap:action");
destructor_action = Getattr(n, "wrap:action");
return SWIG_OK;
}
@ -1043,28 +1033,28 @@ virtual int constantWrapper(Node *n) {
/* ---------------------------------------------------------------------
* external runtime generation
* --------------------------------------------------------------------- */
/* This is to support the usage
SWIG -external-runtime <filename>
SWIG -external-runtime <filename>
The code consists of two functions:
String *runtimeCode() // returns a large string with all the runtimes in
String *defaultExternalRuntimeFilename() // returns the default filename
String *runtimeCode() // returns a large string with all the runtimes in
String *defaultExternalRuntimeFilename() // returns the default filename
I am writing a generic solution, even though SWIG-Lua only has one file right now...
*/
*/
String *runtimeCode() {
String *s = NewString("");
const char* filenames[]={"luarun.swg",0}; // must be 0 termiated
const char *filenames[] = { "luarun.swg", 0 }; // must be 0 termiated
String *sfile;
for (int i=0;filenames[i]!=0;i++) {
for (int i = 0; filenames[i] != 0; i++) {
sfile = Swig_include_sys(filenames[i]);
if (!sfile) {
Printf(stderr, "*** Unable to open '%s'\n",filenames[i]);
Printf(stderr, "*** Unable to open '%s'\n", filenames[i]);
} else {
Append(s, sfile);
Delete(sfile);
Append(s, sfile);
Delete(sfile);
}
}
return s;
}
@ -1107,8 +1097,6 @@ NEW LANGUAGE NOTE:END ************************************************/
* swig_lua() - Instantiate module
* ----------------------------------------------------------------------------- */
extern "C" Language *
swig_lua(void) {
extern "C" Language *swig_lua(void) {
return new LUA();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -12,19 +12,16 @@ char cvsroot_module_cxx[] = "$Header$";
#include "swigmod.h"
struct Module {
ModuleFactory fac;
char *name;
Module *next;
Module(const char *n, ModuleFactory f) {
ModuleFactory fac;
char *name;
Module *next;
Module(const char *n, ModuleFactory f) {
fac = f;
name = new char[strlen(n)+1];
strcpy(name, n);
next = 0;
}
~Module()
{
delete[] name;
name = new char[strlen(n) + 1];
strcpy(name, n);
next = 0;
} ~Module() {
delete[]name;
}
};
@ -37,7 +34,7 @@ static Module *modules = 0;
* ----------------------------------------------------------------------------- */
void Swig_register_module(const char *n, ModuleFactory f) {
Module *m = new Module(n,f);
Module *m = new Module(n, f);
m->next = modules;
modules = m;
}
@ -51,7 +48,7 @@ void Swig_register_module(const char *n, ModuleFactory f) {
ModuleFactory Swig_find_module(const char *name) {
Module *m = modules;
while (m) {
if (strcmp(m->name,name) == 0) {
if (strcmp(m->name, name) == 0) {
return m->fac;
}
m = m->next;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -24,19 +24,19 @@
* address, etc. for extension objects. Should we do something here?
*
*/
char cvsroot_pike_cxx[] = "$Header$";
#include "swigmod.h"
#include <ctype.h> // for isalnum()
#include <ctype.h> // for isalnum()
static const char *usage = (char *)"\
static const char *usage = (char *) "\
Pike Options (available with -pike)\n\
[None]\n\
\n";
class PIKE : public Language {
class PIKE:public Language {
private:
File *f_runtime;
@ -47,7 +47,7 @@ private:
String *PrefixPlusUnderscore;
int current;
// Wrap modes
enum {
NO_CPP,
@ -68,7 +68,7 @@ public:
* Initialize member data
* --------------------------------------------------------------------- */
PIKE() {
PIKE() {
f_runtime = 0;
f_header = 0;
f_wrappers = 0;
@ -83,8 +83,8 @@ public:
*
* Parse command line options and initializes variables.
* --------------------------------------------------------------------- */
virtual void main(int argc, char *argv[]) {
virtual void main(int argc, char *argv[]) {
/* Set location of SWIG library */
SWIG_library_directory("pike");
@ -92,8 +92,8 @@ public:
/* Look for certain command line options */
for (int i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stdout);
if (strcmp(argv[i], "-help") == 0) {
fputs(usage, stdout);
}
}
}
@ -101,12 +101,12 @@ public:
/* Add a symbol to the parser for conditional compilation */
Preprocessor_define("SWIGPIKE 1", 0);
/* Set language-specific configuration file */
/* Set language-specific configuration file */
SWIG_config_file("pike.swg");
/* Set typemap language */
SWIG_typemap_lang("pike");
/* Enable overloaded methods support */
allow_overloading();
}
@ -118,10 +118,10 @@ public:
virtual int top(Node *n) {
/* Get the module name */
String *module = Getattr(n, "name");
/* Get the output file name */
String *outfile = Getattr(n, "outfile");
/* Open the output file */
f_runtime = NewFile(outfile, "w");
if (!f_runtime) {
@ -140,26 +140,26 @@ public:
Swig_register_filebyname("init", f_init);
Swig_register_filebyname("classInit", f_classInit);
/* Standard stuff for the SWIG runtime section */
/* Standard stuff for the SWIG runtime section */
Swig_banner(f_runtime);
Printf(f_header, "#define SWIG_init pike_module_init\n");
Printf(f_header, "#define SWIG_name \"%s\"\n\n", module);
/* Change naming scheme for constructors and destructors */
Swig_name_register("construct","%c_create");
Swig_name_register("destroy","%c_destroy");
Swig_name_register("construct", "%c_create");
Swig_name_register("destroy", "%c_destroy");
/* Current wrap type */
current = NO_CPP;
/* Emit code for children */
Language::top(n);
/* Close the initialization function */
Printf(f_init, "}\n");
SwigType_emit_type_table(f_runtime, f_wrappers);
/* Close all of the files */
Dump(f_header, f_runtime);
Dump(f_wrappers, f_runtime);
@ -176,7 +176,7 @@ public:
/* Done */
return SWIG_OK;
}
/* ------------------------------------------------------------
* validIdentifier()
* ------------------------------------------------------------ */
@ -187,10 +187,12 @@ public:
const char *c1 = c0 + 1;
while (*c) {
if (*c == '`' && c == c0) {
c++; continue;
c++;
continue;
}
if ((*c == '+' || *c == '-' || *c == '*' || *c == '/') && c == c1) {
c++; continue;
c++;
continue;
}
if (!(isalnum(*c) || (*c == '_')))
return 0;
@ -198,19 +200,19 @@ public:
}
return 1;
}
/* ------------------------------------------------------------
* importDirective()
* ------------------------------------------------------------ */
virtual int importDirective(Node *n) {
String *modname = Getattr(n,"module");
String *modname = Getattr(n, "module");
if (modname) {
Printf(f_init,"pike_require(\"%s\");\n", modname);
Printf(f_init, "pike_require(\"%s\");\n", modname);
}
return Language::importDirective(n);
}
/* ------------------------------------------------------------
* strip()
*
@ -235,26 +237,26 @@ public:
void add_method(const DOHString_or_char *name, const DOHString_or_char *function, const DOHString_or_char *description) {
String *rename = NULL;
switch (current) {
case NO_CPP:
rename = NewString(name);
Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
break;
case STATIC_FUNC:
case STATIC_VAR:
rename = NewString(name);
Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
break;
case CONSTRUCTOR:
case DESTRUCTOR:
case MEMBER_FUNC:
case MEMBER_VAR:
rename = strip(name);
Printf(f_classInit, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
break;
case CLASS_CONST:
assert(false); // shouldn't have gotten here for CLASS_CONST nodes
default:
assert(false); // what is this?
case NO_CPP:
rename = NewString(name);
Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
break;
case STATIC_FUNC:
case STATIC_VAR:
rename = NewString(name);
Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
break;
case CONSTRUCTOR:
case DESTRUCTOR:
case MEMBER_FUNC:
case MEMBER_VAR:
rename = strip(name);
Printf(f_classInit, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
break;
case CLASS_CONST:
assert(false); // shouldn't have gotten here for CLASS_CONST nodes
default:
assert(false); // what is this?
}
Delete(rename);
}
@ -267,83 +269,83 @@ public:
virtual int functionWrapper(Node *n) {
String *name = Getattr(n,"name");
String *iname = Getattr(n,"sym:name");
SwigType *d = Getattr(n,"type");
ParmList *l = Getattr(n,"parms");
String *name = Getattr(n, "name");
String *iname = Getattr(n, "sym:name");
SwigType *d = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
Parm *p;
String *tm;
String *tm;
int i;
String *overname = 0;
if (Getattr(n,"sym:overloaded")) {
overname = Getattr(n,"sym:overname");
if (Getattr(n, "sym:overloaded")) {
overname = Getattr(n, "sym:overname");
} else {
if (!addSymbol(iname,n)) return SWIG_ERROR;
if (!addSymbol(iname, n))
return SWIG_ERROR;
}
Wrapper *f = NewWrapper();
/* Write code to extract function parameters. */
emit_args(d, l, f);
/* Attach the standard typemaps */
emit_attach_parmmaps(l,f);
Setattr(n,"wrap:parms",l);
emit_attach_parmmaps(l, f);
Setattr(n, "wrap:parms", l);
/* Get number of required and total arguments */
int num_arguments = emit_num_arguments(l);
int varargs = emit_isvarargs(l);
/* Which input argument to start with? */
int start = (current == MEMBER_FUNC || current == MEMBER_VAR || current == DESTRUCTOR) ? 1 : 0;
/* Offset to skip over the attribute name */
/* Offset to skip over the attribute name */
// int offset = (current == MEMBER_VAR) ? 1 : 0;
int offset = 0;
String *wname = Swig_name_wrapper(iname);
if (overname) {
Append(wname,overname);
Append(wname, overname);
}
Printv(f->def, "static void ", wname, "(INT32 args) {", NIL);
/* Generate code for argument marshalling */
String *description = NewString("");
char source[64];
for (i = 0, p = l; i < num_arguments; i++) {
while (checkAttribute(p,"tmap:in:numinputs","0")) {
p = Getattr(p,"tmap:in:next");
while (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
}
SwigType *pt = Getattr(p,"type");
String *ln = Getattr(p,"lname");
SwigType *pt = Getattr(p, "type");
String *ln = Getattr(p, "lname");
if (i < start) {
String *lstr = SwigType_lstr(pt,0);
Printf(f->code, "%s = (%s) THIS;\n", ln, lstr);
String *lstr = SwigType_lstr(pt, 0);
Printf(f->code, "%s = (%s) THIS;\n", ln, lstr);
Delete(lstr);
} else {
} else {
/* Look for an input typemap */
sprintf(source, "Pike_sp[%d-args]", i-start+offset);
if ((tm = Getattr(p,"tmap:in"))) {
Replaceall(tm, "$source", source);
sprintf(source, "Pike_sp[%d-args]", i - start + offset);
if ((tm = Getattr(p, "tmap:in"))) {
Replaceall(tm, "$source", source);
Replaceall(tm, "$target", ln);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source);
Printf(f->code, "%s\n", tm);
String *pikedesc = Getattr(p, "tmap:in:pikedesc");
String *pikedesc = Getattr(p, "tmap:in:pikedesc");
if (pikedesc) {
Printv(description, pikedesc, " ", NIL);
}
p = Getattr(p,"tmap:in:next");
p = Getattr(p, "tmap:in:next");
continue;
} else {
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number,
"Unable to use type %s as a function argument.\n",SwigType_str(pt,0));
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
break;
}
}
@ -352,30 +354,30 @@ public:
/* Check for trailing varargs */
if (varargs) {
if (p && (tm = Getattr(p,"tmap:in"))) {
Replaceall(tm,"$input", "varargs");
Printv(f->code,tm,"\n",NIL);
if (p && (tm = Getattr(p, "tmap:in"))) {
Replaceall(tm, "$input", "varargs");
Printv(f->code, tm, "\n", NIL);
}
}
/* Insert constraint checking code */
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:check"))) {
Replaceall(tm,"$target",Getattr(p,"lname"));
Printv(f->code,tm,"\n",NIL);
p = Getattr(p,"tmap:check:next");
if ((tm = Getattr(p, "tmap:check"))) {
Replaceall(tm, "$target", Getattr(p, "lname"));
Printv(f->code, tm, "\n", NIL);
p = Getattr(p, "tmap:check:next");
} else {
p = nextSibling(p);
}
}
/* Insert cleanup code */
String *cleanup = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:freearg"))) {
Replaceall(tm,"$source",Getattr(p,"lname"));
Printv(cleanup,tm,"\n",NIL);
p = Getattr(p,"tmap:freearg:next");
if ((tm = Getattr(p, "tmap:freearg"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
p = Getattr(p, "tmap:freearg:next");
} else {
p = nextSibling(p);
}
@ -384,20 +386,20 @@ public:
/* Insert argument output code */
String *outarg = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:argout"))) {
Replaceall(tm,"$source",Getattr(p,"lname"));
Replaceall(tm,"$target","resultobj");
Replaceall(tm,"$arg",Getattr(p,"emit:input"));
Replaceall(tm,"$input",Getattr(p,"emit:input"));
Printv(outarg,tm,"\n",NIL);
p = Getattr(p,"tmap:argout:next");
if ((tm = Getattr(p, "tmap:argout"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Replaceall(tm, "$target", "resultobj");
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(outarg, tm, "\n", NIL);
p = Getattr(p, "tmap:argout:next");
} else {
p = nextSibling(p);
}
}
/* Emit the function call */
emit_action(n,f);
emit_action(n, f);
/* Clear the return stack */
Printf(f->code, "pop_n_elems(args);\n");
@ -411,65 +413,64 @@ public:
} else {
// Wrapper_add_local(f, "resultobj", "struct object *resultobj");
Printv(description, ", ", NIL);
if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) {
Replaceall(tm,"$source", "result");
Replaceall(tm,"$target", "resultobj");
Replaceall(tm,"$result", "resultobj");
if (GetFlag(n,"feature:new")) {
Replaceall(tm,"$owner","1");
if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) {
Replaceall(tm, "$source", "result");
Replaceall(tm, "$target", "resultobj");
Replaceall(tm, "$result", "resultobj");
if (GetFlag(n, "feature:new")) {
Replaceall(tm, "$owner", "1");
} else {
Replaceall(tm,"$owner","0");
Replaceall(tm, "$owner", "0");
}
String *pikedesc = Getattr(n, "tmap:out:pikedesc");
if (pikedesc) {
Printv(description, pikedesc, NIL);
}
Printf(f->code,"%s\n", tm);
Printf(f->code, "%s\n", tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number,
"Unable to use return type %s in function %s.\n", SwigType_str(d,0), name);
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);
}
}
/* Output argument output code */
Printv(f->code,outarg,NIL);
Printv(f->code, outarg, NIL);
/* Output cleanup code */
Printv(f->code,cleanup,NIL);
Printv(f->code, cleanup, NIL);
/* Look to see if there is any newfree cleanup code */
if (GetFlag(n,"feature:new")) {
if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) {
Replaceall(tm,"$source","result");
Printf(f->code,"%s\n",tm);
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) {
Replaceall(tm, "$source", "result");
Printf(f->code, "%s\n", tm);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) {
Replaceall(tm,"$source","result");
Printf(f->code,"%s\n",tm);
Replaceall(tm, "$source", "result");
Printf(f->code, "%s\n", tm);
}
/* Close the function */
Printf(f->code, "}\n");
/* Substitute the cleanup code */
Replaceall(f->code,"$cleanup",cleanup);
Replaceall(f->code, "$cleanup", cleanup);
/* Substitute the function name */
Replaceall(f->code,"$symname",iname);
Replaceall(f->code,"$result","resultobj");
Replaceall(f->code, "$symname", iname);
Replaceall(f->code, "$result", "resultobj");
/* Dump the function out */
Wrapper_print(f,f_wrappers);
Wrapper_print(f, f_wrappers);
/* Now register the function with the interpreter. */
if (!Getattr(n,"sym:overloaded")) {
if (!Getattr(n, "sym:overloaded")) {
add_method(iname, wname, description);
} else {
Setattr(n,"wrap:name", wname);
if (!Getattr(n,"sym:nextSibling")) {
Setattr(n, "wrap:name", wname);
if (!Getattr(n, "sym:nextSibling")) {
dispatchFunction(n);
}
}
@ -495,32 +496,32 @@ public:
int maxargs;
String *tmp = NewString("");
String *dispatch = Swig_overload_dispatch(n, "%s(args); return;", &maxargs);
/* Generate a dispatch wrapper for all overloaded functions */
Wrapper *f = NewWrapper();
String *symname = Getattr(n,"sym:name");
String *wname = Swig_name_wrapper(symname);
Wrapper *f = NewWrapper();
String *symname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(symname);
Printf(f->def, "static void %s(INT32 args) {", wname);
Wrapper_add_local(f, "argc", "INT32 argc");
Printf(tmp, "struct svalue argv[%d]", maxargs);
Wrapper_add_local(f, "argv", tmp);
Wrapper_add_local(f, "ii", "INT32 ii");
Printf(f->code, "argc = args;\n");
Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", maxargs);
Printf(f->code, "argv[ii] = Pike_sp[ii-args];\n");
Printf(f->code, "}\n");
Replaceall(dispatch, "$args", "self, args");
Printv(f->code, dispatch, "\n", NIL);
Printf(f->code, "Pike_error(\"No matching function for overloaded '%s'.\");\n", symname);
Printv(f->code, "}\n", NIL);
Wrapper_print(f, f_wrappers);
String *description = NewString("");
Printf(description, "tAny,");
if (current == CONSTRUCTOR || current == DESTRUCTOR) {
@ -553,12 +554,12 @@ public:
virtual int constantWrapper(Node *n) {
Swig_require("constantWrapper",n, "*sym:name", "type", "value", NIL);
Swig_require("constantWrapper", n, "*sym:name", "type", "value", NIL);
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
String *value = Getattr(n, "value");
SwigType *type = Getattr(n, "type");
String *value = Getattr(n, "value");
/* Special hook for member pointer */
if (SwigType_type(type) == T_MPOINTER) {
String *wname = Swig_name_wrapper(symname);
@ -575,12 +576,11 @@ public:
Replaceall(tm, "$value", value);
Printf(f_init, "%s\n", tm);
} else {
Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number,
"Unsupported constant value %s = %s\n", SwigType_str(type, 0), value);
Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value %s = %s\n", SwigType_str(type, 0), value);
}
Swig_restore(n);
return SWIG_OK;
}
@ -590,19 +590,20 @@ public:
virtual int nativeWrapper(Node *n) {
// return Language::nativeWrapper(n);
String *name = Getattr(n,"sym:name");
String *wrapname = Getattr(n,"wrap:name");
String *name = Getattr(n, "sym:name");
String *wrapname = Getattr(n, "wrap:name");
if (!addSymbol(wrapname,n)) return SWIG_ERROR;
if (!addSymbol(wrapname, n))
return SWIG_ERROR;
add_method(name, wrapname,0);
add_method(name, wrapname, 0);
return SWIG_OK;
}
}
/* ------------------------------------------------------------
* enumDeclaration()
* ------------------------------------------------------------ */
virtual int enumDeclaration(Node *n) {
return Language::enumDeclaration(n);
}
@ -610,7 +611,7 @@ public:
/* ------------------------------------------------------------
* enumvalueDeclaration()
* ------------------------------------------------------------ */
virtual int enumvalueDeclaration(Node *n) {
return Language::enumvalueDeclaration(n);
}
@ -622,7 +623,7 @@ public:
virtual int classDeclaration(Node *n) {
return Language::classDeclaration(n);
}
/* ------------------------------------------------------------
* classHandler()
* ------------------------------------------------------------ */
@ -632,45 +633,45 @@ public:
String *symname = Getattr(n, "sym:name");
if (!addSymbol(symname, n))
return SWIG_ERROR;
PrefixPlusUnderscore = NewStringf("%s_", getClassPrefix());
Printf(f_classInit, "start_new_program();\n");
/* Handle inheritance */
List *baselist = Getattr(n,"bases");
List *baselist = Getattr(n, "bases");
if (baselist && Len(baselist) > 0) {
Iterator base = First(baselist);
while (base.item) {
String *basename = Getattr(base.item,"name");
SwigType *basetype = NewString(basename);
SwigType_add_pointer(basetype);
SwigType_remember(basetype);
String *basemangle = SwigType_manglestr(basetype);
Printf(f_classInit, "low_inherit((struct program *) SWIGTYPE%s->clientdata, 0, 0, 0, 0, 0);\n", basemangle);
String *basename = Getattr(base.item, "name");
SwigType *basetype = NewString(basename);
SwigType_add_pointer(basetype);
SwigType_remember(basetype);
String *basemangle = SwigType_manglestr(basetype);
Printf(f_classInit, "low_inherit((struct program *) SWIGTYPE%s->clientdata, 0, 0, 0, 0, 0);\n", basemangle);
Delete(basemangle);
Delete(basetype);
base = Next(base);
base = Next(base);
}
} else {
Printf(f_classInit, "ADD_STORAGE(swig_object_wrapper);\n");
}
Language::classHandler(n);
/* Accessors for member variables */
/*
List *membervariables = Getattr(n,"membervariables");
if (membervariables && Len(membervariables) > 0) {
membervariableAccessors(membervariables);
}
*/
List *membervariables = Getattr(n,"membervariables");
if (membervariables && Len(membervariables) > 0) {
membervariableAccessors(membervariables);
}
*/
/* Done, close the class and dump its definition to the init function */
Printf(f_classInit, "add_program_constant(\"%s\", pr = end_program(), 0);\n", symname);
Dump(f_classInit, f_init);
Clear(f_classInit);
SwigType *tt = NewString(symname);
SwigType_add_pointer(tt);
SwigType_remember(tt);
@ -678,8 +679,9 @@ public:
Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) pr);\n", tm);
Delete(tm);
Delete(tt);
Delete(PrefixPlusUnderscore); PrefixPlusUnderscore = 0;
Delete(PrefixPlusUnderscore);
PrefixPlusUnderscore = 0;
return SWIG_OK;
}
@ -720,7 +722,7 @@ public:
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* membervariableAccessors()
* ------------------------------------------------------------ */
@ -730,18 +732,18 @@ public:
Iterator i;
bool need_setter;
String *funcname;
/* If at least one of them is mutable, we need a setter */
need_setter = false;
i = First(membervariables);
while (i.item) {
if (!GetFlag(i.item, "feature:immutable")) {
need_setter = true;
need_setter = true;
break;
}
i = Next(i);
}
/* Create a function to set the values of the (mutable) variables */
if (need_setter) {
Wrapper *wrapper = NewWrapper();
@ -749,7 +751,7 @@ public:
String *wname = Swig_name_wrapper(setter);
Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL);
Printf(wrapper->locals, "char *name = (char *) STR0(Pike_sp[0-args].u.string);\n");
i = First(membervariables);
while (i.item) {
if (!GetFlag(i.item, "feature:immutable")) {
@ -770,7 +772,7 @@ public:
/* Dump wrapper code to the output file */
Wrapper_print(wrapper, f_wrappers);
/* Register it with Pike */
String *description = NewString("tStr tFloat, tVoid");
add_method("`->=", wname, description);
@ -781,7 +783,7 @@ public:
Delete(setter);
DelWrapper(wrapper);
}
/* Create a function to get the values of the (mutable) variables */
Wrapper *wrapper = NewWrapper();
String *getter = Swig_name_member(getClassPrefix(), (char *) "`->");
@ -807,12 +809,12 @@ public:
/* Dump wrapper code to the output file */
Wrapper_print(wrapper, f_wrappers);
/* Register it with Pike */
String *description = NewString("tStr, tMix");
add_method("`->", wname, description);
Delete(description);
/* Clean up */
Delete(wname);
Delete(getter);
@ -824,12 +826,12 @@ public:
* ------------------------------------------------------------ */
virtual int membervariableHandler(Node *n) {
List *membervariables = Getattr(getCurrentClass(),"membervariables");
List *membervariables = Getattr(getCurrentClass(), "membervariables");
if (!membervariables) {
membervariables = NewList();
Setattr(getCurrentClass(),"membervariables",membervariables);
Setattr(getCurrentClass(), "membervariables", membervariables);
}
Append(membervariables,n);
Append(membervariables, n);
current = MEMBER_VAR;
Language::membervariableHandler(n);
current = NO_CPP;
@ -848,7 +850,7 @@ public:
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* memberconstantHandler()
*
@ -878,9 +880,9 @@ public:
* swig_pike() - Instantiate module
* ----------------------------------------------------------------------------- */
static Language * new_swig_pike() {
static Language *new_swig_pike() {
return new PIKE();
}
extern "C" Language * swig_pike(void) {
extern "C" Language *swig_pike(void) {
return new_swig_pike();
}

File diff suppressed because it is too large Load Diff

View File

@ -320,10 +320,9 @@ public:
return status;
}
// Grab the name of the current class being processed so that we can
// deal with members of that class.
int classHandler(Node *n){
/* Grab the name of the current class being processed so that we can
deal with members of that class. */
int classHandler(Node *n){
if(!ClassMemberTable)
ClassMemberTable = NewHash();
@ -333,6 +332,7 @@ public:
class_name = NULL;
return status;
};
// Not used:
String *runtimeCode();
@ -362,6 +362,7 @@ protected:
namespaceFunctions = NewList();
Append(namespaceFunctions, name);
}
void addNamespaceMethod(String *name) {
if(!namespaceMethods)
namespaceMethods = NewList();
@ -474,8 +475,7 @@ static int getFunctionPointerNumArgs(Node *n, SwigType *tt) {
}
void
R::addSMethodInfo(String *name, String *argType, int nargs) {
void R::addSMethodInfo(String *name, String *argType, int nargs) {
(void) argType;
if(!SMethodInfo)
@ -2953,8 +2953,7 @@ void R::main(int argc, char *argv[]) {
Could make this work for String or File and then just store the resulting string
rather than the collection of arguments and argc.
*/
int
R::outputCommandLineArguments(File *out)
int R::outputCommandLineArguments(File *out)
{
if(argc < 1 || !argv || !argv[0])
return(-1);
@ -2973,8 +2972,7 @@ R::outputCommandLineArguments(File *out)
/* How SWIG instantiates an object from this module.
See swigmain.cxx */
extern "C"
Language *swig_r(void)
{
Language *swig_r(void) {
return new R();
}

File diff suppressed because it is too large Load Diff

View File

@ -18,32 +18,33 @@ S-Exp Options (available with -sexp)\n\
//static Node *view_top = 0;
static File *out = 0;
class Sexp : public Language {
class Sexp:public Language {
public:
int indent_level;
Sexp() : indent_level( 0 ) {}
virtual ~Sexp() {}
Sexp():indent_level(0) {
}
virtual ~ Sexp() {
}
virtual void main(int argc, char *argv[]) {
SWIG_typemap_lang("sexp");
for( int iX = 0; iX < argc; iX++ )
{
if( strcmp( argv[iX], "-typemaplang" ) == 0 )
{
Swig_mark_arg (iX);
iX++;
SWIG_typemap_lang(argv[iX]);
Swig_mark_arg (iX);
continue;
}
if( strcmp( argv[iX], "-help" ) == 0 )
{
fputs( usage, stdout );
}
for (int iX = 0; iX < argc; iX++) {
if (strcmp(argv[iX], "-typemaplang") == 0) {
Swig_mark_arg(iX);
iX++;
SWIG_typemap_lang(argv[iX]);
Swig_mark_arg(iX);
continue;
}
if (strcmp(argv[iX], "-help") == 0) {
fputs(usage, stdout);
}
}
// Add a symbol to the parser for conditional compilation
Preprocessor_define("SWIGSEXP 1",0);
// Add a symbol to the parser for conditional compilation
Preprocessor_define("SWIGSEXP 1", 0);
}
DOHHash *print_circle_hash;
@ -53,28 +54,25 @@ public:
bool need_newline;
/* Top of the parse tree */
virtual int top(Node *n)
{
if( out == 0 )
{
String *outfile = Getattr(n,"outfile");
Replaceall(outfile,"_wrap.cxx", ".lisp");
Replaceall(outfile,"_wrap.c", ".lisp");
out = NewFile(outfile,"w");
if (!out)
{
FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE);
}
virtual int top(Node *n) {
if (out == 0) {
String *outfile = Getattr(n, "outfile");
Replaceall(outfile, "_wrap.cxx", ".lisp");
Replaceall(outfile, "_wrap.c", ".lisp");
out = NewFile(outfile, "w");
if (!out) {
FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE);
}
}
String *f_sink = NewString("");
Swig_register_filebyname("header",f_sink);
Swig_register_filebyname("wrapper",f_sink);
Swig_register_filebyname("runtime",f_sink);
Swig_register_filebyname("init",f_sink);
Swig_register_filebyname("header", f_sink);
Swig_register_filebyname("wrapper", f_sink);
Swig_register_filebyname("runtime", f_sink);
Swig_register_filebyname("init", f_sink);
Language::top(n);
Printf( out, ";;; Lisp parse tree produced by SWIG\n" );
Printf(out, ";;; Lisp parse tree produced by SWIG\n");
print_circle_hash = DohNewHash();
print_circle_count = 0;
hanging_parens = 0;
@ -85,36 +83,32 @@ public:
return SWIG_OK;
}
void print_indent()
{
void print_indent() {
int i;
for (i = 0; i < indent_level; i++)
{
Printf(out, " ");
}
for (i = 0; i < indent_level; i++) {
Printf(out, " ");
}
}
void open_paren(const String *oper)
{
void open_paren(const String *oper) {
flush_parens();
Printf(out, "(");
if (oper) Printf(out, "%s ", oper);
if (oper)
Printf(out, "%s ", oper);
indent_level += 2;
}
void close_paren(bool neednewline = false)
{
void close_paren(bool neednewline = false) {
hanging_parens++;
if (neednewline)
print_lazy_whitespace();
indent_level -= 2;
}
void flush_parens()
{
void flush_parens() {
int i;
if (hanging_parens) {
for (i = 0; i<hanging_parens; i++)
for (i = 0; i < hanging_parens; i++)
Printf(out, ")");
hanging_parens = 0;
need_newline = true;
@ -125,71 +119,64 @@ public:
print_indent();
need_newline = false;
need_whitespace = false;
}
else if (need_whitespace) {
} else if (need_whitespace) {
Printf(out, " ");
need_whitespace = false;
}
}
void print_lazy_whitespace()
{
void print_lazy_whitespace() {
need_whitespace = 1;
}
void print_lazy_newline()
{
void print_lazy_newline() {
need_newline = 1;
}
bool internal_key_p(DOH *key)
{
return ((Cmp(key,"nodeType") == 0)
|| (Cmp(key,"firstChild") == 0)
|| (Cmp(key,"lastChild") == 0)
|| (Cmp(key,"parentNode") == 0)
|| (Cmp(key,"nextSibling") == 0)
|| (Cmp(key,"previousSibling") == 0)
|| (Cmp(key,"csym:nextSibling") == 0)
|| (Cmp(key,"csym:previousSibling") == 0)
|| (Cmp(key,"typepass:visit") == 0)
|| (Cmp(key,"allocate:visit") == 0)
bool internal_key_p(DOH *key) {
return ((Cmp(key, "nodeType") == 0)
|| (Cmp(key, "firstChild") == 0)
|| (Cmp(key, "lastChild") == 0)
|| (Cmp(key, "parentNode") == 0)
|| (Cmp(key, "nextSibling") == 0)
|| (Cmp(key, "previousSibling") == 0)
|| (Cmp(key, "csym:nextSibling") == 0)
|| (Cmp(key, "csym:previousSibling") == 0)
|| (Cmp(key, "typepass:visit") == 0)
|| (Cmp(key, "allocate:visit") == 0)
|| (*(Char(key)) == '$'));
}
bool boolean_key_p(DOH *key)
{
return ((Cmp(key,"allocate:default_constructor") == 0)
|| (Cmp(key,"allocate:default_destructor") == 0)
|| (Cmp(key,"allows_typedef") == 0)
|| (Cmp(key,"feature:immutable") == 0));
bool boolean_key_p(DOH *key) {
return ((Cmp(key, "allocate:default_constructor") == 0)
|| (Cmp(key, "allocate:default_destructor") == 0)
|| (Cmp(key, "allows_typedef") == 0)
|| (Cmp(key, "feature:immutable") == 0));
}
bool list_key_p(DOH *key)
{
bool list_key_p(DOH *key) {
return ((Cmp(key, "parms") == 0)
|| (Cmp(key, "baselist") == 0));
}
bool plist_key_p(DOH *key)
// true if KEY is the name of data that is a mapping from keys to
// values, which should be printed as a plist.
// true if KEY is the name of data that is a mapping from keys to
// values, which should be printed as a plist.
{
return ((Cmp(key, "typescope") == 0));
}
bool maybe_plist_key_p(DOH *key)
{
bool maybe_plist_key_p(DOH *key) {
return (Strncmp(key, "tmap:", 5) == 0);
}
bool print_circle(DOH *obj, bool list_p)
// We have a complex object, which might be referenced several
// times, or even recursively. Use Lisp's reader notation for
// circular structures (#n#, #n=).
//
// An object can be printed in list-mode or object-mode; LIST_P toggles.
// return TRUE if OBJ still needs to be printed
// We have a complex object, which might be referenced several
// times, or even recursively. Use Lisp's reader notation for
// circular structures (#n#, #n=).
//
// An object can be printed in list-mode or object-mode; LIST_P toggles.
// return TRUE if OBJ still needs to be printed
{
flush_parens();
// Following is a silly hack. It works around the limitation of
@ -200,17 +187,15 @@ public:
if (placeholder) {
Printv(out, placeholder, NIL);
return false;
}
else {
} else {
String *placeholder = NewStringf("#%d#", ++print_circle_count);
Setattr(print_circle_hash, address, placeholder);
Printf(out, "#%d=", print_circle_count);
return true;
}
}
}
void Sexp_print_value_of_key(DOH *value, DOH *key)
{
void Sexp_print_value_of_key(DOH *value, DOH *key) {
if ((Cmp(key, "parms") == 0) || (Cmp(key, "wrap:parms") == 0)
|| (Cmp(key, "kwargs") == 0) || (Cmp(key, "pattern") == 0))
Sexp_print_parms(value);
@ -221,29 +206,27 @@ public:
Sexp_print_plist(value);
else
Sexp_print_doh(value);
}
else if (list_key_p(key))
} else if (list_key_p(key))
Sexp_print_list(value);
else if (boolean_key_p(key))
Sexp_print_boolean(value);
else
Sexp_print_doh(value);
}
void Sexp_print_boolean(DOH *obj)
{
void Sexp_print_boolean(DOH *obj) {
flush_parens();
/* See DOH/Doh/base.c, DohGetInt() */
if (DohIsString(obj)) {
if (atoi(Char(obj)) != 0)
Printf(out, "t");
else Printf(out, "nil");
}
else Printf(out, "nil");
else
Printf(out, "nil");
} else
Printf(out, "nil");
}
void Sexp_print_list(DOH *obj)
{
void Sexp_print_list(DOH *obj) {
if (print_circle(obj, true)) {
open_paren(NIL);
for (; obj; obj = nextSibling(obj)) {
@ -254,9 +237,8 @@ public:
}
}
void Sexp_print_parms(DOH *obj)
void Sexp_print_parms(DOH *obj) {
// print it as a list of plists
{
if (print_circle(obj, true)) {
open_paren(NIL);
for (; obj; obj = nextSibling(obj)) {
@ -270,33 +252,31 @@ public:
Sexp_print_value_of_key(value, k.key);
print_lazy_whitespace();
}
}
}
close_paren(true);
}
else Sexp_print_doh(obj);
} else
Sexp_print_doh(obj);
print_lazy_whitespace();
}
close_paren(true);
}
}
void Sexp_print_doh(DOH *obj)
{
void Sexp_print_doh(DOH *obj) {
flush_parens();
if (DohIsString(obj)) {
String *o = Str(obj);
Replaceall( o, "\\", "\\\\" );
Replaceall( o, "\"", "\\\"" );
Printf(out,"\"%s\"", o);
Replaceall(o, "\\", "\\\\");
Replaceall(o, "\"", "\\\"");
Printf(out, "\"%s\"", o);
Delete(o);
}
else {
} else {
if (print_circle(obj, false)) {
// Dispatch type
if (nodeType(obj)) {
Sexp_print_node(obj);
}
else if (DohIsMapping(obj)) {
Iterator k;
open_paren(NIL);
@ -312,41 +292,37 @@ public:
}
}
close_paren();
}
else if (strcmp(ObjType(obj)->objname, "List") == 0) {
} else if (strcmp(ObjType(obj)->objname, "List") == 0) {
int i;
open_paren(NIL);
for (i = 0; i<Len(obj); i++) {
for (i = 0; i < Len(obj); i++) {
DOH *item = Getitem(obj, i);
Sexp_print_doh(item);
}
close_paren();
}
else {
} else {
// What is it?
Printf(out,"#<DOH %s %x>", ObjType(obj)->objname, obj);
Printf(out, "#<DOH %s %x>", ObjType(obj)->objname, obj);
}
}
}
}
void Sexp_print_as_keyword(const DOH *k)
{
void Sexp_print_as_keyword(const DOH *k) {
/* Print key, replacing ":" with "-" because : is CL's package prefix */
flush_parens();
String *key = NewString(k);
Replaceall(key, ":", "-");
Replaceall(key, "_", "-");
Printf(out,":%s ", key);
Printf(out, ":%s ", key);
Delete(key);
}
void Sexp_print_plist_noparens(DOH *obj)
{
void Sexp_print_plist_noparens(DOH *obj) {
/* attributes map names to objects */
Iterator k;
bool first;
for (k = First(obj), first = true; k.key; k = Next(k), first=false) {
for (k = First(obj), first = true; k.key; k = Next(k), first = false) {
if (!internal_key_p(k.key)) {
DOH *value = Getattr(obj, k.key);
flush_parens();
@ -359,9 +335,8 @@ public:
}
}
}
void Sexp_print_plist(DOH *obj)
{
void Sexp_print_plist(DOH *obj) {
flush_parens();
if (print_circle(obj, true)) {
open_paren(NIL);
@ -370,14 +345,12 @@ public:
}
}
void Sexp_print_attributes(Node * obj)
{
void Sexp_print_attributes(Node *obj) {
Sexp_print_plist_noparens(obj);
}
void Sexp_print_node(Node *obj)
{
Node *cobj;
void Sexp_print_node(Node *obj) {
Node *cobj;
open_paren(nodeType(obj));
/* A node has an attribute list... */
Sexp_print_attributes(obj);
@ -397,21 +370,20 @@ public:
}
virtual int functionWrapper(Node *n)
{
ParmList *l = Getattr(n,"parms");
virtual int functionWrapper(Node *n) {
ParmList *l = Getattr(n, "parms");
Wrapper *f = NewWrapper();
emit_attach_parmmaps(l,f);
Setattr(n,"wrap:parms",l);
emit_attach_parmmaps(l, f);
Setattr(n, "wrap:parms", l);
return SWIG_OK;
}
};
static Language * new_swig_sexp() {
static Language *new_swig_sexp() {
return new Sexp();
}
extern "C" Language * swig_sexp( void ) {
extern "C" Language *swig_sexp(void) {
return new_swig_sexp();
}

View File

@ -49,41 +49,41 @@ extern "C" {
}
struct swig_module {
const char *name;
ModuleFactory fac;
const char *help;
const char *name;
ModuleFactory fac;
const char *help;
};
/* Association of command line options to language modules.
Place an entry for new language modules here, keeping the
list sorted alphabetically. */
static swig_module modules[] = {
static swig_module modules[] = {
{"-allegrocl", swig_allegrocl, "ALLEGROCL"},
{"-chicken", swig_chicken, "CHICKEN"},
{"-clisp", swig_clisp, "CLISP"},
{"-cffi", swig_cffi, "CFFI"},
{"-csharp", swig_csharp, "C#"},
{"-guile", swig_guile, "Guile"},
{"-java", swig_java, "Java"},
{"-lua", swig_lua, "Lua"},
{"-modula3", swig_modula3, "Modula 3"},
{"-mzscheme", swig_mzscheme, "Mzscheme"},
{"-ocaml", swig_ocaml, "Ocaml"},
{"-perl", swig_perl5, "Perl"},
{"-perl5", swig_perl5, 0},
{"-php", swig_php4, 0},
{"-php4", swig_php4, "PHP4"},
{"-php5", swig_php5, "PHP5"},
{"-pike", swig_pike, "Pike"},
{"-python", swig_python, "Python"},
{"-ruby", swig_ruby, "Ruby"},
{"-sexp", swig_sexp, "Lisp S-Expressions"},
{"-tcl", swig_tcl, "Tcl"},
{"-tcl8", swig_tcl, 0},
{"-uffi", swig_uffi, "Common Lisp / UFFI"},
{"-xml", swig_xml, "XML"},
{"-r", swig_r, "R (aka GNU S)"},
{"-chicken", swig_chicken, "CHICKEN"},
{"-clisp", swig_clisp, "CLISP"},
{"-cffi", swig_cffi, "CFFI"},
{"-csharp", swig_csharp, "C#"},
{"-guile", swig_guile, "Guile"},
{"-java", swig_java, "Java"},
{"-lua", swig_lua, "Lua"},
{"-modula3", swig_modula3, "Modula 3"},
{"-mzscheme", swig_mzscheme, "Mzscheme"},
{"-ocaml", swig_ocaml, "Ocaml"},
{"-perl", swig_perl5, "Perl"},
{"-perl5", swig_perl5, 0},
{"-php", swig_php4, 0},
{"-php4", swig_php4, "PHP4"},
{"-php5", swig_php5, "PHP5"},
{"-pike", swig_pike, "Pike"},
{"-python", swig_python, "Python"},
{"-ruby", swig_ruby, "Ruby"},
{"-sexp", swig_sexp, "Lisp S-Expressions"},
{"-tcl", swig_tcl, "Tcl"},
{"-tcl8", swig_tcl, 0},
{"-uffi", swig_uffi, "Common Lisp / UFFI"},
{"-xml", swig_xml, "XML"},
{"-r", swig_r, "R (aka GNU S)"},
{NULL, NULL, NULL}
};
@ -102,9 +102,7 @@ static swig_module modules[] = {
// Main program. Initializes the files and starts the parser.
//-----------------------------------------------------------------
void SWIG_merge_envopt(const char *env, int oargc, char *oargv[],
int *nargc, char ***nargv)
{
void SWIG_merge_envopt(const char *env, int oargc, char *oargv[], int *nargc, char ***nargv) {
if (!env) {
*nargc = oargc;
*nargv = oargv;
@ -113,13 +111,14 @@ void SWIG_merge_envopt(const char *env, int oargc, char *oargv[],
int argc = 1;
int arge = oargc + 1024;
char **argv = (char **) malloc(sizeof(char*)*(arge));
char *buffer = (char*) malloc(2048);
char **argv = (char **) malloc(sizeof(char *) * (arge));
char *buffer = (char *) malloc(2048);
char *b = buffer;
char *be = b + 1023;
const char *c = env;
while ((b != be) && *c && (argc < arge)) {
while (isspace(*c) && *c) ++c;
while (isspace(*c) && *c)
++c;
if (*c) {
argv[argc] = b;
++argc;
@ -159,33 +158,30 @@ int main(int margc, char **margv) {
Swig_register_module(modules[i].name, modules[i].fac);
}
Swig_init_args(argc,argv);
Swig_init_args(argc, argv);
/* Get options */
for (i = 1; i < argc; i++) {
if (argv[i]) {
fac = Swig_find_module(argv[i]);
if (fac) {
dl = (fac)();
dl = (fac) ();
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-nolang") == 0) {
} else if (strcmp(argv[i], "-nolang") == 0) {
dl = new Language;
Swig_mark_arg(i);
} else if ((strcmp(argv[i],"-dnone") == 0) ||
(strcmp(argv[i],"-dhtml") == 0) ||
(strcmp(argv[i],"-dlatex") == 0) ||
(strcmp(argv[i],"-dascii") == 0) ||
(strcmp(argv[i],"-stat") == 0))
{
Printf(stderr,"swig: Warning. %s option deprecated.\n",argv[i]);
} else if ((strcmp(argv[i], "-dnone") == 0) ||
(strcmp(argv[i], "-dhtml") == 0) ||
(strcmp(argv[i], "-dlatex") == 0) || (strcmp(argv[i], "-dascii") == 0) || (strcmp(argv[i], "-stat") == 0)) {
Printf(stderr, "swig: Warning. %s option deprecated.\n", argv[i]);
Swig_mark_arg(i);
} else if ((strcmp(argv[i],"-help") == 0) || (strcmp(argv[i],"--help") == 0)) {
if (strcmp(argv[i],"--help") == 0)
} else if ((strcmp(argv[i], "-help") == 0) || (strcmp(argv[i], "--help") == 0)) {
if (strcmp(argv[i], "--help") == 0)
strcpy(argv[i], "-help");
Printf(stdout,"Target Language Options\n");
Printf(stdout, "Target Language Options\n");
for (int j = 0; modules[j].name; j++) {
if (modules[j].help) {
Printf(stdout," %-15s - Generate %s wrappers\n", modules[j].name, modules[j].help);
Printf(stdout, " %-15s - Generate %s wrappers\n", modules[j].name, modules[j].help);
}
}
// Swig_mark_arg not called as the general -help options also need to be displayed later on
@ -195,11 +191,10 @@ int main(int margc, char **margv) {
if (!dl) {
fac = Swig_find_module(SWIG_LANG);
if (fac) {
dl = (fac)();
dl = (fac) ();
}
}
int res = SWIG_main(argc,argv,dl);
int res = SWIG_main(argc, argv, dl);
delete dl;
return res;
return res;
}

View File

@ -26,18 +26,18 @@ typedef int bool;
#define PLAIN_VIRTUAL 1
#define PURE_VIRTUAL 2
extern char *input_file;
extern int line_number;
extern int start_line;
extern int CPlusPlus; // C++ mode
extern int Extend; // Extend mode
extern int Verbose;
extern int IsVirtual;
extern int ImportMode;
extern int NoExcept; // -no_except option
extern int Abstract; // abstract base class
extern int SmartPointer; // smart pointer methods being emitted
extern int SwigRuntime;
extern char *input_file;
extern int line_number;
extern int start_line;
extern int CPlusPlus; // C++ mode
extern int Extend; // Extend mode
extern int Verbose;
extern int IsVirtual;
extern int ImportMode;
extern int NoExcept; // -no_except option
extern int Abstract; // abstract base class
extern int SmartPointer; // smart pointer methods being emitted
extern int SwigRuntime;
/* Overload "argc" and "argv" */
extern String *argv_template_string;
@ -50,18 +50,19 @@ extern String *argc_template_string;
#define tab8 " "
class Dispatcher {
public:
public:
Dispatcher() : cplus_mode(PUBLIC) {}
virtual ~Dispatcher() {}
Dispatcher ():cplus_mode(PUBLIC) {
} virtual ~ Dispatcher () {
}
virtual int emit_one(Node *n);
virtual int emit_children(Node *n);
virtual int defaultHandler(Node *n);
/* Top of the parse tree */
virtual int top(Node *n) = 0;
virtual int top(Node *n) = 0;
/* SWIG directives */
virtual int applyDirective(Node *n);
@ -81,7 +82,7 @@ class Dispatcher {
virtual int typesDirective(Node *n);
/* C/C++ parsing */
virtual int cDeclaration(Node *n);
virtual int externDeclaration(Node *n);
virtual int enumDeclaration(Node *n);
@ -110,10 +111,10 @@ protected:
* functions to output different types of code for different languages.
* ------------------------------------------------------------------------- */
class Language : public Dispatcher {
class Language:public Dispatcher {
public:
Language();
virtual ~Language();
Language ();
virtual ~ Language ();
virtual int emit_one(Node *n);
/* Parse command line options */
@ -122,10 +123,10 @@ public:
/* Top of the parse tree */
virtual int top(Node *n);
virtual int top(Node *n);
/* SWIG directives */
virtual int applyDirective(Node *n);
virtual int clearDirective(Node *n);
@ -143,7 +144,7 @@ public:
virtual int typesDirective(Node *n);
/* C/C++ parsing */
virtual int cDeclaration(Node *n);
virtual int externDeclaration(Node *n);
virtual int enumDeclaration(Node *n);
@ -195,12 +196,7 @@ public:
virtual int classDirector(Node *n);
virtual int classDirectorInit(Node *n);
virtual int classDirectorEnd(Node *n);
virtual int unrollVirtualMethods(Node *n,
Node *parent,
List *vm,
int default_director,
int &virtual_destructor,
int protectedbase = 0);
virtual int unrollVirtualMethods(Node *n, Node *parent, List *vm, int default_director, int &virtual_destructor, int protectedbase = 0);
virtual int classDirectorConstructor(Node *n);
virtual int classDirectorDefaultConstructor(Node *n);
virtual int classDirectorMethod(Node *n, Node *parent, String *super);
@ -210,16 +206,16 @@ public:
virtual int classDirectorDisown(Node *n);
/* Miscellaneous */
virtual int validIdentifier(String *s); /* valid identifier? */
virtual int addSymbol(const String *s, const Node *n); /* Add symbol */
virtual Node *symbolLookup(String *s); /* Symbol lookup */
virtual Node *classLookup(SwigType *s); /* Class lookup */
virtual Node *enumLookup(SwigType *s); /* Enum lookup */
virtual int abstractClassTest(Node *n); /* Is class really abstract? */
virtual int is_assignable(Node *n); /* Is variable assignable? */
virtual String *runtimeCode(); /* returns the language specific runtime code */
virtual String *defaultExternalRuntimeFilename(); /* the default filename for the external runtime */
virtual int validIdentifier(String *s); /* valid identifier? */
virtual int addSymbol(const String *s, const Node *n); /* Add symbol */
virtual Node *symbolLookup(String *s); /* Symbol lookup */
virtual Node *classLookup(SwigType *s); /* Class lookup */
virtual Node *enumLookup(SwigType *s); /* Enum lookup */
virtual int abstractClassTest(Node *n); /* Is class really abstract? */
virtual int is_assignable(Node *n); /* Is variable assignable? */
virtual String *runtimeCode(); /* returns the language specific runtime code */
virtual String *defaultExternalRuntimeFilename(); /* the default filename for the external runtime */
/* Allow director related code generation */
void allow_directors(int val = 1);
@ -227,10 +223,10 @@ public:
int directorsEnabled() const;
/* Allow director protected members related code generation */
void allow_dirprot(int val = 1);
void allow_dirprot(int val = 1);
/* Returns the dirprot mode */
int dirprot_mode() const;
int dirprot_mode() const;
/* Check if the non public constructor is needed (for directors) */
int need_nonpublic_ctor(Node *n);
@ -246,10 +242,10 @@ public:
protected:
/* Allow multiple-input typemaps */
void allow_multiple_input(int val = 1);
void allow_multiple_input(int val = 1);
/* Allow overloaded functions */
void allow_overloading(int val = 1);
void allow_overloading(int val = 1);
/* Wrapping class query */
int is_wrapping_class();
@ -281,7 +277,7 @@ protected:
/* Director constructor "template" code */
String *director_ctor_code;
/* Director 'protected' constructor "template" code*/
/* Director 'protected' constructor "template" code */
String *director_prot_ctor_code;
/* Director allows multiple inheritance */
@ -291,37 +287,37 @@ protected:
int director_language;
private:
Hash *symbols;
Hash *classtypes;
Hash *enumtypes;
int overloading;
int multiinput;
int directors;
Hash *symbols;
Hash *classtypes;
Hash *enumtypes;
int overloading;
int multiinput;
int directors;
};
int SWIG_main(int, char **, Language *);
void emit_args(SwigType *, ParmList *, Wrapper *f);
void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */
void SWIG_config_file(const String_or_char *);
int SWIG_main(int, char **, Language *);
void emit_args(SwigType *, ParmList *, Wrapper *f);
void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */
void SWIG_config_file(const String_or_char *);
const String *SWIG_output_directory();
void SWIG_config_cppext(const char *ext);
void SWIG_config_cppext(const char *ext);
void SWIG_library_directory(const char *);
int emit_num_arguments(ParmList *);
int emit_num_required(ParmList *);
int emit_isvarargs(ParmList *);
void emit_attach_parmmaps(ParmList *, Wrapper *f);
void emit_mark_varargs(ParmList *l);
void emit_action(Node *n, Wrapper *f);
int emit_action_code(Node *n, Wrapper *f, String *action);
void Swig_overload_check(Node *n);
void SWIG_library_directory(const char *);
int emit_num_arguments(ParmList *);
int emit_num_required(ParmList *);
int emit_isvarargs(ParmList *);
void emit_attach_parmmaps(ParmList *, Wrapper *f);
void emit_mark_varargs(ParmList *l);
void emit_action(Node *n, Wrapper *f);
int emit_action_code(Node *n, Wrapper *f, String *action);
void Swig_overload_check(Node *n);
String *Swig_overload_dispatch(Node *n, const String_or_char *fmt, int *);
String *Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *);
String *Swig_overload_dispatch_fast(Node *n, const String_or_char *fmt, int *);
SwigType *cplus_value_type(SwigType *t);
/* directors.cxx start */
String *Swig_csuperclass_call(String* base, String* method, ParmList* l);
String *Swig_csuperclass_call(String *base, String *method, ParmList *l);
String *Swig_class_declaration(Node *n, String *name);
String *Swig_class_name(Node *n);
String *Swig_method_call(String_or_char *name, ParmList *parms);
@ -330,20 +326,18 @@ String *Swig_director_declaration(Node *n);
/* directors.cxx end */
extern "C" {
void SWIG_typemap_lang(const char *);
typedef Language *(*ModuleFactory)(void);
}
void Swig_register_module(const char *name, ModuleFactory fac);
void SWIG_typemap_lang(const char *);
typedef Language *(*ModuleFactory) (void);
} void Swig_register_module(const char *name, ModuleFactory fac);
ModuleFactory Swig_find_module(const char *name);
/* Utilities */
int is_public(Node* n);
int is_private(Node* n);
int is_protected(Node* n);
int is_member_director(Node* parentnode, Node* member);
int is_member_director(Node* member);
int is_public(Node *n);
int is_private(Node *n);
int is_protected(Node *n);
int is_member_director(Node *parentnode, Node *member);
int is_member_director(Node *member);
int use_naturalvar_mode(Node *n);
void Wrapper_virtual_elimination_mode_set(int);
@ -360,7 +354,7 @@ void clean_overloaded(Node *n);
void Swig_contracts(Node *n);
void Swig_contract_mode_set(int flag);
int Swig_contract_mode_get();
int Swig_contract_mode_get();
/* Browser */
@ -370,7 +364,3 @@ void Swig_process_types(Node *n);
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -13,32 +13,32 @@ char cvsroot_uffi_cxx[] = "$Header$";
#include "swigmod.h"
class UFFI : public Language {
class UFFI:public Language {
public:
virtual void main(int argc, char *argv[]);
virtual int top(Node *n);
virtual int functionWrapper(Node *n);
virtual int functionWrapper(Node *n);
virtual int constantWrapper(Node *n);
virtual int classHandler(Node *n);
virtual int membervariableHandler(Node *n);
};
static File *f_cl=0;
static File *f_null=0;
static File *f_cl = 0;
static File *f_null = 0;
static struct {
int count;
String **entries;
} defined_foreign_types;
static const char *identifier_converter="identifier-convert-null";
static const char *identifier_converter = "identifier-convert-null";
static int any_varargs(ParmList *pl) {
Parm *p;
for(p=pl; p; p=nextSibling(p)) {
for (p = pl; p; p = nextSibling(p)) {
if (SwigType_isvarargs(Getattr(p, "type")))
return 1;
}
@ -46,83 +46,79 @@ static int any_varargs(ParmList *pl) {
return 0;
}
/* utilities */
/* returns new string w/ parens stripped */
static String *strip_parens(String *string) {
char *s=Char(string), *p;
int len=Len(string);
String *res;
if (len==0 || s[0] != '(' || s[len-1] != ')') {
return NewString(string);
}
p=(char *)malloc(len-2+1);
if (!p) {
Printf(stderr, "Malloc failed\n");
SWIG_exit(EXIT_FAILURE);
}
strncpy(p, s+1, len-1);
p[len-2]=0; /* null terminate */
res=NewString(p);
free(p);
return res;
char *s = Char(string), *p;
int len = Len(string);
String *res;
if (len == 0 || s[0] != '(' || s[len - 1] != ')') {
return NewString(string);
}
p = (char *) malloc(len - 2 + 1);
if (!p) {
Printf(stderr, "Malloc failed\n");
SWIG_exit(EXIT_FAILURE);
}
strncpy(p, s + 1, len - 1);
p[len - 2] = 0; /* null terminate */
res = NewString(p);
free(p);
return res;
}
static String *convert_literal(String *num_param, String *type) {
String *num=strip_parens(num_param), *res;
char *s=Char(num);
/* Make sure doubles use 'd' instead of 'e' */
if (!Strcmp(type, "double")) {
String *updated=Copy(num);
if (Replace(updated, "e", "d", DOH_REPLACE_ANY) > 1) {
Printf(stderr, "Weird!! number %s looks invalid.\n", num);
SWIG_exit(EXIT_FAILURE);
}
Delete(num);
return updated;
}
String *num = strip_parens(num_param), *res;
char *s = Char(num);
if (SwigType_type(type) == T_CHAR) {
/* Use CL syntax for character literals */
return NewStringf("#\\%s", num_param);
}
else if (SwigType_type(type) == T_STRING) {
/* Use CL syntax for string literals */
return NewStringf("\"%s\"", num_param);
}
if (Len(num) < 2 || s[0] != '0') {
return num;
}
/* octal or hex */
res=NewStringf("#%c%s",
s[1] == 'x' ? 'x' : 'o',
s+2);
Delete(num);
/* Make sure doubles use 'd' instead of 'e' */
if (!Strcmp(type, "double")) {
String *updated = Copy(num);
if (Replace(updated, "e", "d", DOH_REPLACE_ANY) > 1) {
Printf(stderr, "Weird!! number %s looks invalid.\n", num);
SWIG_exit(EXIT_FAILURE);
}
Delete(num);
return updated;
}
return res;
if (SwigType_type(type) == T_CHAR) {
/* Use CL syntax for character literals */
return NewStringf("#\\%s", num_param);
} else if (SwigType_type(type) == T_STRING) {
/* Use CL syntax for string literals */
return NewStringf("\"%s\"", num_param);
}
if (Len(num) < 2 || s[0] != '0') {
return num;
}
/* octal or hex */
res = NewStringf("#%c%s", s[1] == 'x' ? 'x' : 'o', s + 2);
Delete(num);
return res;
}
static void add_defined_foreign_type(String *type) {
if (!defined_foreign_types.count) {
/* Make fresh */
defined_foreign_types.count=1;
defined_foreign_types.entries=(String **)malloc(sizeof(String *));
defined_foreign_types.count = 1;
defined_foreign_types.entries = (String **) malloc(sizeof(String *));
} else {
/* make room */
defined_foreign_types.count++;
defined_foreign_types.entries=(String **)
realloc(defined_foreign_types.entries,
defined_foreign_types.count*sizeof(String *));
defined_foreign_types.entries = (String **)
realloc(defined_foreign_types.entries, defined_foreign_types.count * sizeof(String *));
}
if (!defined_foreign_types.entries) {
@ -131,121 +127,110 @@ static void add_defined_foreign_type(String *type) {
}
/* Fill in the new data */
defined_foreign_types.entries[defined_foreign_types.count-1]=
Copy(type);
defined_foreign_types.entries[defined_foreign_types.count - 1] = Copy(type);
}
static String *get_ffi_type(SwigType *ty, const String_or_char *name) {
Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0);
if (typemap) {
String *typespec = Getattr(typemap, "code");
return NewString(typespec);
}
else {
SwigType *tr=SwigType_typedef_resolve_all(ty);
char *type_reduced=Char(tr);
int i;
String *typespec = Getattr(typemap, "code");
return NewString(typespec);
} else {
SwigType *tr = SwigType_typedef_resolve_all(ty);
char *type_reduced = Char(tr);
int i;
//Printf(stdout,"convert_type %s\n", ty);
if (SwigType_isconst(tr)) {
SwigType_pop(tr);
type_reduced=Char(tr);
}
//Printf(stdout,"convert_type %s\n", ty);
if (SwigType_isconst(tr)) {
SwigType_pop(tr);
type_reduced = Char(tr);
}
if (SwigType_ispointer(type_reduced) || SwigType_isarray(ty) ||
!strncmp(type_reduced, "p.f", 3)) {
return NewString(":pointer-void");
}
for(i=0; i<defined_foreign_types.count; i++) {
if (!Strcmp(ty, defined_foreign_types.entries[i])) {
return NewStringf("#.(%s \"%s\" :type :type)",
identifier_converter,
ty);
}
}
if (!Strncmp(type_reduced, "enum ", 5)) {
return NewString(":int");
}
if (SwigType_ispointer(type_reduced) || SwigType_isarray(ty) || !strncmp(type_reduced, "p.f", 3)) {
return NewString(":pointer-void");
}
Printf(stderr, "Unsupported data type: %s (was: %s)\n", type_reduced, ty);
SWIG_exit(EXIT_FAILURE);
for (i = 0; i < defined_foreign_types.count; i++) {
if (!Strcmp(ty, defined_foreign_types.entries[i])) {
return NewStringf("#.(%s \"%s\" :type :type)", identifier_converter, ty);
}
}
if (!Strncmp(type_reduced, "enum ", 5)) {
return NewString(":int");
}
Printf(stderr, "Unsupported data type: %s (was: %s)\n", type_reduced, ty);
SWIG_exit(EXIT_FAILURE);
}
return 0;
}
static String *get_lisp_type(SwigType *ty, const String_or_char *name)
{
static String *get_lisp_type(SwigType *ty, const String_or_char *name) {
Hash *typemap = Swig_typemap_search("lisptype", ty, name, 0);
if (typemap) {
String *typespec = Getattr(typemap, "code");
return NewString(typespec);
}
else {
} else {
return NewString("");
}
}
void UFFI :: main(int argc, char *argv[]) {
void UFFI::main(int argc, char *argv[]) {
int i;
SWIG_library_directory("uffi");
SWIG_library_directory("uffi");
SWIG_config_file("uffi.swg");
for(i=1; i<argc; i++) {
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-identifier-converter")) {
char *conv=argv[i+1];
char *conv = argv[i + 1];
if (!conv)
Swig_arg_error();
Swig_mark_arg(i);
Swig_mark_arg(i+1);
Swig_mark_arg(i + 1);
i++;
/* check for built-ins */
if (!strcmp(conv, "lispify")) {
identifier_converter="identifier-convert-lispify";
identifier_converter = "identifier-convert-lispify";
} else if (!strcmp(conv, "null")) {
identifier_converter="identifier-convert-null";
identifier_converter = "identifier-convert-null";
} else {
/* Must be user defined */
char *idconv = new char[strlen(conv)+1];
strcpy(idconv, conv);
identifier_converter=idconv;
char *idconv = new char[strlen(conv) + 1];
strcpy(idconv, conv);
identifier_converter = idconv;
}
}
if (!strcmp(argv[i], "-help")) {
fprintf(stdout, "UFFI Options (available with -uffi)\n");
fprintf(stdout,
fprintf(stdout,
" -identifier-converter <type or funcname>\n"
"\tSpecifies the type of conversion to do on C identifiers to convert\n"
"\tthem to symbols. There are two built-in converters: 'null' and\n"
"\t 'lispify'. The default is 'null'. If you supply a name other\n"
"\tthan one of the built-ins, then a function by that name will be\n"
"\tcalled to convert identifiers to symbols.\n");
}
}
}
int UFFI :: top(Node *n) {
String *module=Getattr(n, "name");
String *output_filename=NewString("");
String *devnull=NewString("/dev/null");
int UFFI::top(Node *n) {
String *module = Getattr(n, "name");
String *output_filename = NewString("");
String *devnull = NewString("/dev/null");
f_null=NewFile(devnull, "w+");
f_null = NewFile(devnull, "w+");
if (!f_null) {
FileErrorDisplay(devnull);
SWIG_exit(EXIT_FAILURE);
FileErrorDisplay(devnull);
SWIG_exit(EXIT_FAILURE);
}
Delete(devnull);
@ -253,166 +238,153 @@ int UFFI :: top(Node *n) {
Printf(output_filename, "%s%s.cl", SWIG_output_directory(), module);
f_cl=NewFile(output_filename, "w");
f_cl = NewFile(output_filename, "w");
if (!f_cl) {
FileErrorDisplay(output_filename);
SWIG_exit(EXIT_FAILURE);
}
Swig_register_filebyname("header",f_null);
Swig_register_filebyname("runtime",f_null);
Swig_register_filebyname("header", f_null);
Swig_register_filebyname("runtime", f_null);
Swig_register_filebyname("wrapper", f_cl);
Printf(f_cl, ";; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; package: %s -*-\n;; This is an automatically generated file. Make changes in\n;; the definition file, not here.\n\n(defpackage :%s\n (:use :common-lisp :uffi))\n\n(in-package :%s)\n", module, module, module);
Printf(f_cl,
";; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; package: %s -*-\n;; This is an automatically generated file. Make changes in\n;; the definition file, not here.\n\n(defpackage :%s\n (:use :common-lisp :uffi))\n\n(in-package :%s)\n",
module, module, module);
Printf(f_cl, "(eval-when (compile load eval)\n (defparameter *swig-identifier-converter* '%s))\n", identifier_converter);
Language::top(n);
Close(f_cl);
Delete(f_cl); // Delete the handle, not the file
Delete(f_cl); // Delete the handle, not the file
Close(f_null);
Delete(f_null);
return SWIG_OK;
}
int UFFI :: functionWrapper(Node *n) {
String *funcname=Getattr(n, "sym:name");
ParmList *pl=Getattr(n, "parms");
int UFFI::functionWrapper(Node *n) {
String *funcname = Getattr(n, "sym:name");
ParmList *pl = Getattr(n, "parms");
Parm *p;
int argnum=0, first=1, varargs=0;
int argnum = 0, first = 1, varargs = 0;
//Language::functionWrapper(n);
Printf(f_cl, "(swig-defun \"%s\"\n", funcname);
Printf(f_cl, " (");
/* Special cases */
if (ParmList_len(pl) == 0) {
Printf(f_cl, ":void");
} else if (any_varargs(pl)) {
Printf(f_cl, "#| varargs |#");
varargs=1;
varargs = 1;
} else {
for (p=pl; p; p=nextSibling(p), argnum++) {
String *argname=Getattr(p, "name");
SwigType *argtype=Getattr(p, "type");
String *ffitype=get_ffi_type(argtype, argname);
String *lisptype=get_lisp_type(argtype, argname);
int tempargname=0;
for (p = pl; p; p = nextSibling(p), argnum++) {
String *argname = Getattr(p, "name");
SwigType *argtype = Getattr(p, "type");
String *ffitype = get_ffi_type(argtype, argname);
String *lisptype = get_lisp_type(argtype, argname);
int tempargname = 0;
if (!argname) {
argname=NewStringf("arg%d", argnum);
tempargname=1;
argname = NewStringf("arg%d", argnum);
tempargname = 1;
}
if (!first) {
Printf(f_cl, "\n ");
}
Printf(f_cl, "(%s %s %s)", argname, ffitype, lisptype);
first=0;
first = 0;
Delete(ffitype);
Delete(lisptype);
if (tempargname)
if (tempargname)
Delete(argname);
}
}
Printf(f_cl, ")\n"); /* finish arg list */
Printf(f_cl, ")\n"); /* finish arg list */
Printf(f_cl, " :returning %s\n"
//" :strings-convert t\n"
//" :call-direct %s\n"
//" :optimize-for-space t"
")\n",
get_ffi_type(Getattr(n, "type"), "result")
")\n", get_ffi_type(Getattr(n, "type"), "result")
//,varargs ? "nil" : "t"
);
);
return SWIG_OK;
}
int UFFI :: constantWrapper(Node *n) {
String *type=Getattr(n, "type");
String *converted_value=convert_literal(Getattr(n, "value"), type);
String *name=Getattr(n, "sym:name");
int UFFI::constantWrapper(Node *n) {
String *type = Getattr(n, "type");
String *converted_value = convert_literal(Getattr(n, "value"), type);
String *name = Getattr(n, "sym:name");
#if 0
Printf(stdout, "constant %s is of type %s. value: %s\n",
name, type, converted_value);
Printf(stdout, "constant %s is of type %s. value: %s\n", name, type, converted_value);
#endif
Printf(f_cl, "(swig-defconstant \"%s\" %s)\n",
name, converted_value);
Printf(f_cl, "(swig-defconstant \"%s\" %s)\n", name, converted_value);
Delete(converted_value);
return SWIG_OK;
}
// Includes structs
int UFFI :: classHandler(Node *n) {
int UFFI::classHandler(Node *n) {
String *name=Getattr(n, "sym:name");
String *kind = Getattr(n,"kind");
String *name = Getattr(n, "sym:name");
String *kind = Getattr(n, "kind");
Node *c;
if (Strcmp(kind, "struct")) {
Printf(stderr, "Don't know how to deal with %s kind of class yet.\n",
kind);
Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", kind);
Printf(stderr, " (name: %s)\n", name);
SWIG_exit(EXIT_FAILURE);
}
Printf(f_cl,
"(swig-def-struct \"%s\"\n \n",
name);
Printf(f_cl, "(swig-def-struct \"%s\"\n \n", name);
for (c=firstChild(n); c; c=nextSibling(c)) {
SwigType *type=Getattr(c, "type");
SwigType *decl=Getattr(c, "decl");
for (c = firstChild(n); c; c = nextSibling(c)) {
SwigType *type = Getattr(c, "type");
SwigType *decl = Getattr(c, "decl");
type = Copy(type);
SwigType_push(type, decl);
String *lisp_type;
if (Strcmp(nodeType(c), "cdecl")) {
Printf(stderr, "Structure %s has a slot that we can't deal with.\n",
name);
Printf(stderr, "nodeType: %s, name: %s, type: %s\n",
nodeType(c),
Getattr(c, "name"),
Getattr(c, "type"));
Printf(stderr, "Structure %s has a slot that we can't deal with.\n", name);
Printf(stderr, "nodeType: %s, name: %s, type: %s\n", nodeType(c), Getattr(c, "name"), Getattr(c, "type"));
SWIG_exit(EXIT_FAILURE);
}
/* Printf(stdout, "Converting %s in %s\n", type, name); */
lisp_type=get_ffi_type(type, Getattr(c, "sym:name"));
Printf(f_cl,
" (#.(%s \"%s\" :type :slot) %s)\n",
identifier_converter,
Getattr(c, "sym:name"),
lisp_type);
/* Printf(stdout, "Converting %s in %s\n", type, name); */
lisp_type = get_ffi_type(type, Getattr(c, "sym:name"));
Printf(f_cl, " (#.(%s \"%s\" :type :slot) %s)\n", identifier_converter, Getattr(c, "sym:name"), lisp_type);
Delete(lisp_type);
}
// Language::classHandler(n);
Printf(f_cl, " )\n");
/* Add this structure to the known lisp types */
//Printf(stdout, "Adding %s foreign type\n", name);
add_defined_foreign_type(name);
return SWIG_OK;
}
int UFFI :: membervariableHandler(Node *n)
{
int UFFI::membervariableHandler(Node *n) {
Language::membervariableHandler(n);
return SWIG_OK;
}
@ -421,7 +393,3 @@ int UFFI :: membervariableHandler(Node *n)
extern "C" Language *swig_uffi(void) {
return new UFFI();
}

View File

@ -11,42 +11,38 @@ char cvsroot_utils_cxx[] = "$Header$";
#include <swigmod.h>
int is_public(Node* n)
{
String* access = Getattr(n, "access");
int is_public(Node *n) {
String *access = Getattr(n, "access");
return !access || !Cmp(access, "public");
}
int is_private(Node* n)
{
String* access = Getattr(n, "access");
int is_private(Node *n) {
String *access = Getattr(n, "access");
return access && !Cmp(access, "private");
}
int is_protected(Node* n)
{
String* access = Getattr(n, "access");
int is_protected(Node *n) {
String *access = Getattr(n, "access");
return access && !Cmp(access, "protected");
}
int is_member_director(Node* parentnode, Node* member)
{
int is_member_director(Node *parentnode, Node *member) {
int director_mode = Swig_director_mode();
if (parentnode && checkAttribute(member, "storage", "virtual")) {
int parent_nodirector = GetFlag(parentnode,"feature:nodirector");
if (parent_nodirector) return 0;
int parent_director = director_mode && GetFlag(parentnode,"feature:director");
int cdecl_director = parent_director || GetFlag(member,"feature:director");
int cdecl_nodirector = GetFlag(member,"feature:nodirector");
int parent_nodirector = GetFlag(parentnode, "feature:nodirector");
if (parent_nodirector)
return 0;
int parent_director = director_mode && GetFlag(parentnode, "feature:director");
int cdecl_director = parent_director || GetFlag(member, "feature:director");
int cdecl_nodirector = GetFlag(member, "feature:nodirector");
return cdecl_director && !cdecl_nodirector && !GetFlag(member, "feature:extend");
} else {
return 0;
}
}
int is_member_director(Node* member)
{
int is_member_director(Node *member) {
return is_member_director(Getattr(member, "parentNode"), member);
}
@ -54,37 +50,36 @@ int is_member_director(Node* member)
/* Clean overloaded list. Removes templates, ignored, and errors */
void clean_overloaded(Node *n) {
Node *nn = Getattr(n,"sym:overloaded");
Node *nn = Getattr(n, "sym:overloaded");
Node *first = 0;
int cnt = 0;
int cnt = 0;
while (nn) {
String *ntype = nodeType(nn);
if ((GetFlag(nn,"feature:ignore")) ||
(Getattr(nn,"error")) ||
(Strcmp(ntype,"template") == 0) ||
((Strcmp(ntype,"cdecl") == 0) && is_protected(nn) && !is_member_director(nn)) ||
((Strcmp(ntype,"using") == 0) && !firstChild(nn))) {
if ((GetFlag(nn, "feature:ignore")) ||
(Getattr(nn, "error")) ||
(Strcmp(ntype, "template") == 0) ||
((Strcmp(ntype, "cdecl") == 0) && is_protected(nn) && !is_member_director(nn)) || ((Strcmp(ntype, "using") == 0) && !firstChild(nn))) {
/* Remove from overloaded list */
Node *ps = Getattr(nn,"sym:previousSibling");
Node *ns = Getattr(nn,"sym:nextSibling");
Node *ps = Getattr(nn, "sym:previousSibling");
Node *ns = Getattr(nn, "sym:nextSibling");
if (ps) {
Setattr(ps,"sym:nextSibling",ns);
}
if (ns) {
Setattr(ns,"sym:previousSibling",ps);
Setattr(ps, "sym:nextSibling", ns);
}
Delattr(nn,"sym:previousSibling");
Delattr(nn,"sym:nextSibling");
Delattr(nn,"sym:overloaded");
if (ns) {
Setattr(ns, "sym:previousSibling", ps);
}
Delattr(nn, "sym:previousSibling");
Delattr(nn, "sym:nextSibling");
Delattr(nn, "sym:overloaded");
nn = ns;
continue;
} else if ((Strcmp(ntype,"using") == 0)) {
} else if ((Strcmp(ntype, "using") == 0)) {
/* A possibly dangerous parse tree hack. We're going to
cut the parse tree node out and stick in the resolved
using declarations */
Node *ps = Getattr(nn,"sym:previousSibling");
Node *ns = Getattr(nn,"sym:nextSibling");
cut the parse tree node out and stick in the resolved
using declarations */
Node *ps = Getattr(nn, "sym:previousSibling");
Node *ns = Getattr(nn, "sym:nextSibling");
Node *un = firstChild(nn);
Node *pn = un;
@ -92,32 +87,34 @@ void clean_overloaded(Node *n) {
first = un;
}
while (pn) {
Node *ppn = Getattr(pn,"sym:nextSibling");
Setattr(pn,"sym:overloaded",first);
Setattr(pn,"sym:overname", NewStringf("%s_%d", Getattr(nn,"sym:overname"), cnt++));
if (ppn) pn = ppn;
else break;
Node *ppn = Getattr(pn, "sym:nextSibling");
Setattr(pn, "sym:overloaded", first);
Setattr(pn, "sym:overname", NewStringf("%s_%d", Getattr(nn, "sym:overname"), cnt++));
if (ppn)
pn = ppn;
else
break;
}
if (ps) {
Setattr(ps,"sym:nextSibling",un);
Setattr(un,"sym:previousSibling",ps);
Setattr(ps, "sym:nextSibling", un);
Setattr(un, "sym:previousSibling", ps);
}
if (ns) {
Setattr(ns,"sym:previousSibling", pn);
Setattr(pn,"sym:nextSibling",ns);
Setattr(ns, "sym:previousSibling", pn);
Setattr(pn, "sym:nextSibling", ns);
}
if (!first) {
first = un;
Setattr(nn,"sym:overloaded",first);
Setattr(nn, "sym:overloaded", first);
}
} else {
if (!first) first = nn;
Setattr(nn,"sym:overloaded",first);
if (!first)
first = nn;
Setattr(nn, "sym:overloaded", first);
}
nn = Getattr(nn,"sym:nextSibling");
nn = Getattr(nn, "sym:nextSibling");
}
if (!first || (first && !Getattr(first,"sym:nextSibling"))) {
Delattr(n,"sym:overloaded");
if (!first || (first && !Getattr(first, "sym:nextSibling"))) {
Delattr(n, "sym:overloaded");
}
}

View File

@ -22,321 +22,266 @@ static File *out = 0;
static int xmllite = 0;
class XML
: public Language
{
class XML:public Language {
public:
int indent_level;
long id;
XML()
: indent_level( 0 )
, id( 0 )
{
}
int indent_level;
long id;
virtual ~XML()
{
}
XML() :indent_level(0) , id(0) {
}
virtual ~ XML() {
}
virtual void main(int argc, char *argv[])
{
SWIG_typemap_lang("xml");
for( int iX = 0; iX < argc; iX++ )
{
if( strcmp( argv[iX], "-xml" ) == 0 )
{
char * extension = 0;
if( iX + 1 >= argc )
continue;
extension = argv[iX+1]+strlen(argv[iX+1])-4;
if( strcmp( extension, ".xml" ) )
continue;
iX++;
Swig_mark_arg (iX);
String * outfile = NewString( argv[iX] );
out = NewFile(outfile,"w");
if (!out)
{
FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE);
}
continue;
}
if( strcmp( argv[iX], "-xmllang" ) == 0 )
{
Swig_mark_arg (iX);
iX++;
SWIG_typemap_lang(argv[iX]);
Swig_mark_arg (iX);
continue;
}
if( strcmp( argv[iX], "-help" ) == 0 )
{
fputs( usage, stdout );
}
if( strcmp( argv[iX], "-xmllite" ) == 0 )
{
Swig_mark_arg (iX);
xmllite = 1;
}
}
// Add a symbol to the parser for conditional compilation
Preprocessor_define("SWIGXML 1",0);
virtual void main(int argc, char *argv[]) {
SWIG_typemap_lang("xml");
for (int iX = 0; iX < argc; iX++) {
if (strcmp(argv[iX], "-xml") == 0) {
char *extension = 0;
if (iX + 1 >= argc)
continue;
extension = argv[iX + 1] + strlen(argv[iX + 1]) - 4;
if (strcmp(extension, ".xml"))
continue;
iX++;
Swig_mark_arg(iX);
String *outfile = NewString(argv[iX]);
out = NewFile(outfile, "w");
if (!out) {
FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE);
}
continue;
}
if (strcmp(argv[iX], "-xmllang") == 0) {
Swig_mark_arg(iX);
iX++;
SWIG_typemap_lang(argv[iX]);
Swig_mark_arg(iX);
continue;
}
if (strcmp(argv[iX], "-help") == 0) {
fputs(usage, stdout);
}
if (strcmp(argv[iX], "-xmllite") == 0) {
Swig_mark_arg(iX);
xmllite = 1;
}
}
// Add a symbol to the parser for conditional compilation
Preprocessor_define("SWIGXML 1", 0);
}
/* Top of the parse tree */
virtual int top(Node *n)
{
if( out == 0 )
{
String *outfile = Getattr(n,"outfile");
Replaceall(outfile,".cxx", ".xml");
Replaceall(outfile,".cpp", ".xml");
Replaceall(outfile,".c", ".xml");
out = NewFile(outfile,"w");
if (!out)
{
FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE);
}
}
Printf( out, "<?xml version=\"1.0\" ?> \n" );
Xml_print_tree(n);
return SWIG_OK;
}
virtual int top(Node *n) {
if (out == 0) {
String *outfile = Getattr(n, "outfile");
Replaceall(outfile, ".cxx", ".xml");
Replaceall(outfile, ".cpp", ".xml");
Replaceall(outfile, ".c", ".xml");
out = NewFile(outfile, "w");
if (!out) {
FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE);
}
}
Printf(out, "<?xml version=\"1.0\" ?> \n");
Xml_print_tree(n);
return SWIG_OK;
}
void print_indent(int l) {
int i;
for (i = 0; i < indent_level; i++) {
Printf(out, " ");
}
if (l) {
Printf(out, " ");
}
}
void Xml_print_tree(DOH *obj) {
while (obj) {
Xml_print_node(obj);
obj = nextSibling(obj);
}
}
void print_indent(int l)
{
int i;
for (i = 0; i < indent_level; i++)
{
Printf(out, " ");
}
if (l)
{
Printf(out, " ");
}
void Xml_print_attributes(Node *obj) {
String *k;
indent_level += 4;
print_indent(0);
Printf(out, "<attributelist id=\"%ld\" addr=\"%x\" >\n", ++id, obj);
indent_level += 4;
Iterator ki;
ki = First(obj);
while (ki.key) {
k = ki.key;
if ((Cmp(k, "nodeType") == 0)
|| (Cmp(k, "firstChild") == 0)
|| (Cmp(k, "lastChild") == 0)
|| (Cmp(k, "parentNode") == 0)
|| (Cmp(k, "nextSibling") == 0)
|| (Cmp(k, "previousSibling") == 0)
|| (*(Char(k)) == '$')) {
/* Do nothing */
} else if (Cmp(k, "module") == 0) {
Xml_print_module(Getattr(obj, k));
} else if (Cmp(k, "baselist") == 0) {
Xml_print_baselist(Getattr(obj, k));
} else if (!xmllite && Cmp(k, "typescope") == 0) {
Xml_print_typescope(Getattr(obj, k));
} else if (!xmllite && Cmp(k, "typetab") == 0) {
Xml_print_typetab(Getattr(obj, k));
} else if (Cmp(k, "kwargs") == 0) {
Xml_print_kwargs(Getattr(obj, k));
} else if (Cmp(k, "parms") == 0 || Cmp(k, "pattern") == 0) {
Xml_print_parmlist(Getattr(obj, k));
} else {
DOH *o;
print_indent(0);
if (DohIsString(Getattr(obj, k))) {
String *ck = NewString(k);
o = Str(Getattr(obj, k));
Replaceall(ck, ":", "_");
Replaceall(ck, "<", "&lt;");
/* Do first to avoid aliasing errors. */
Replaceall(o, "&", "&amp;");
Replaceall(o, "<", "&lt;");
Replaceall(o, "\"", "&quot;");
Replaceall(o, "\\", "\\\\");
Replaceall(o, "\n", "&#10;");
Printf(out, "<attribute name=\"%s\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o);
Delete(o);
Delete(ck);
} else {
o = Getattr(obj, k);
String *ck = NewString(k);
Replaceall(ck, ":", "_");
Printf(out, "<attribute name=\"%s\" value=\"%x\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o);
Delete(ck);
}
}
ki = Next(ki);
}
indent_level -= 4;
print_indent(0);
Printf(out, "</attributelist >\n");
indent_level -= 4;
}
void Xml_print_tree(DOH *obj)
{
while (obj)
{
Xml_print_node(obj);
obj = nextSibling(obj);
}
}
void Xml_print_node(Node *obj) {
Node *cobj;
void Xml_print_attributes(Node * obj)
{
String *k;
indent_level += 4;
print_indent(0);
Printf( out, "<attributelist id=\"%ld\" addr=\"%x\" >\n", ++id, obj );
indent_level += 4;
Iterator ki;
ki = First(obj);
while (ki.key) {
k = ki.key;
if ((Cmp(k,"nodeType") == 0)
|| (Cmp(k,"firstChild") == 0)
|| (Cmp(k,"lastChild") == 0)
|| (Cmp(k,"parentNode") == 0)
|| (Cmp(k,"nextSibling") == 0)
|| (Cmp(k,"previousSibling") == 0)
|| (*(Char(k)) == '$'))
{
/* Do nothing */
}
else if (Cmp(k,"module") == 0)
{
Xml_print_module( Getattr(obj,k) );
}
else if (Cmp(k,"baselist") == 0)
{
Xml_print_baselist( Getattr(obj,k) );
}
else if (!xmllite && Cmp(k,"typescope") == 0)
{
Xml_print_typescope( Getattr(obj,k) );
}
else if (!xmllite && Cmp(k,"typetab") == 0)
{
Xml_print_typetab( Getattr(obj,k) );
}
else if (Cmp(k,"kwargs") == 0)
{
Xml_print_kwargs( Getattr(obj,k) );
}
else if (Cmp(k,"parms") == 0 || Cmp(k, "pattern") == 0 )
{
Xml_print_parmlist( Getattr(obj,k) );
}
else
{
DOH *o;
print_indent(0);
if (DohIsString(Getattr(obj,k)))
{
String *ck = NewString(k);
o = Str(Getattr(obj,k));
Replaceall( ck, ":", "_" );
Replaceall( ck, "<", "&lt;" );
/* Do first to avoid aliasing errors. */
Replaceall( o, "&", "&amp;" );
Replaceall( o, "<", "&lt;" );
Replaceall( o, "\"", "&quot;" );
Replaceall( o, "\\", "\\\\" );
Replaceall( o, "\n", "&#10;" );
Printf(out,"<attribute name=\"%s\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o );
Delete(o);
Delete(ck);
}
else
{
o = Getattr(obj,k);
String *ck = NewString(k);
Replaceall( ck, ":", "_" );
Printf(out,"<attribute name=\"%s\" value=\"%x\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o );
Delete(ck);
}
}
ki = Next(ki);
}
indent_level -= 4;
print_indent(0);
Printf( out, "</attributelist >\n" );
indent_level -= 4;
}
void Xml_print_node(Node *obj)
{
Node *cobj;
print_indent(0);
Printf(out,"<%s id=\"%ld\" addr=\"%x\" >\n", nodeType(obj), ++id, obj);
Xml_print_attributes( obj );
cobj = firstChild(obj);
if (cobj)
{
indent_level += 4;
Printf(out,"\n");
Xml_print_tree(cobj);
indent_level -= 4;
}
else
{
print_indent(1);
Printf(out,"\n");
}
print_indent(0);
Printf(out,"</%s >\n", nodeType(obj));
}
print_indent(0);
Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", nodeType(obj), ++id, obj);
Xml_print_attributes(obj);
cobj = firstChild(obj);
if (cobj) {
indent_level += 4;
Printf(out, "\n");
Xml_print_tree(cobj);
indent_level -= 4;
} else {
print_indent(1);
Printf(out, "\n");
}
print_indent(0);
Printf(out, "</%s >\n", nodeType(obj));
}
void Xml_print_parmlist(ParmList *p)
{
void Xml_print_parmlist(ParmList *p) {
print_indent(0);
Printf( out, "<parmlist id=\"%ld\" addr=\"%x\" >\n", ++id, p );
indent_level += 4;
while(p)
{
print_indent(0);
Printf( out, "<parm id=\"%ld\">\n", ++id );
Xml_print_attributes( p );
print_indent(0);
Printf( out, "</parm >\n" );
p = nextSibling(p);
}
indent_level -= 4;
print_indent(0);
Printf( out, "</parmlist >\n" );
}
print_indent(0);
Printf(out, "<parmlist id=\"%ld\" addr=\"%x\" >\n", ++id, p);
indent_level += 4;
while (p) {
print_indent(0);
Printf(out, "<parm id=\"%ld\">\n", ++id);
Xml_print_attributes(p);
print_indent(0);
Printf(out, "</parm >\n");
p = nextSibling(p);
}
indent_level -= 4;
print_indent(0);
Printf(out, "</parmlist >\n");
}
void Xml_print_baselist(List *p)
{
void Xml_print_baselist(List *p) {
print_indent(0);
Printf( out, "<baselist id=\"%ld\" addr=\"%x\" >\n", ++id, p );
indent_level += 4;
Iterator s;
for (s = First(p); s.item; s = Next(s))
{
print_indent(0);
String *item_name = Xml_escape_string(s.item);
Printf( out, "<base name=\"%s\" id=\"%ld\" addr=\"%x\" />\n", item_name, ++id, s.item );
Delete(item_name);
}
indent_level -= 4;
print_indent(0);
Printf( out, "</baselist >\n" );
}
print_indent(0);
Printf(out, "<baselist id=\"%ld\" addr=\"%x\" >\n", ++id, p);
indent_level += 4;
Iterator s;
for (s = First(p); s.item; s = Next(s)) {
print_indent(0);
String *item_name = Xml_escape_string(s.item);
Printf(out, "<base name=\"%s\" id=\"%ld\" addr=\"%x\" />\n", item_name, ++id, s.item);
Delete(item_name);
}
indent_level -= 4;
print_indent(0);
Printf(out, "</baselist >\n");
}
String *Xml_escape_string(String *str) {
String *escaped_str = 0;
if (str) {
escaped_str = NewString(str);
Replaceall( escaped_str, "&", "&amp;" );
Replaceall( escaped_str, "<", "&lt;" );
Replaceall( escaped_str, "\"", "&quot;" );
Replaceall( escaped_str, "\\", "\\\\" );
Replaceall( escaped_str, "\n", "&#10;" );
}
return escaped_str;
}
String *Xml_escape_string(String *str) {
String *escaped_str = 0;
if (str) {
escaped_str = NewString(str);
Replaceall(escaped_str, "&", "&amp;");
Replaceall(escaped_str, "<", "&lt;");
Replaceall(escaped_str, "\"", "&quot;");
Replaceall(escaped_str, "\\", "\\\\");
Replaceall(escaped_str, "\n", "&#10;");
}
return escaped_str;
}
void Xml_print_module(Node *p)
{
void Xml_print_module(Node *p) {
print_indent(0);
Printf( out, "<attribute name=\"module\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", Getattr( p, "name"), ++id, p );
}
print_indent(0);
Printf(out, "<attribute name=\"module\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", Getattr(p, "name"), ++id, p);
}
void Xml_print_kwargs(Hash *p)
{
Xml_print_hash( p, "kwargs" );
}
void Xml_print_kwargs(Hash *p) {
Xml_print_hash(p, "kwargs");
}
void Xml_print_typescope(Hash *p)
{
void Xml_print_typescope(Hash *p) {
Xml_print_hash( p, "typescope" );
}
Xml_print_hash(p, "typescope");
}
void Xml_print_typetab(Hash *p)
{
void Xml_print_typetab(Hash *p) {
Xml_print_hash( p, "typetab" );
}
Xml_print_hash(p, "typetab");
}
void Xml_print_hash(Hash *p, const char * markup)
{
void Xml_print_hash(Hash *p, const char *markup) {
print_indent(0);
Printf( out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p );
Xml_print_attributes( p );
indent_level += 4;
Iterator n = First(p);
while(n.key)
{
print_indent(0);
Printf( out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n.item );
Xml_print_attributes( n.item );
print_indent(0);
Printf( out, "</%ssitem >\n", markup );
n = Next(n);
}
indent_level -= 4;
print_indent(0);
Printf( out, "</%s >\n", markup );
}
print_indent(0);
Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p);
Xml_print_attributes(p);
indent_level += 4;
Iterator n = First(p);
while (n.key) {
print_indent(0);
Printf(out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n.item);
Xml_print_attributes(n.item);
print_indent(0);
Printf(out, "</%ssitem >\n", markup);
n = Next(n);
}
indent_level -= 4;
print_indent(0);
Printf(out, "</%s >\n", markup);
}
};
@ -349,29 +294,27 @@ public:
* up being a post-processing version of the tree.
* ----------------------------------------------------------------------------- */
void Swig_print_xml(DOH *obj, String* filename)
{
XML xml;
xmllite = 1;
void Swig_print_xml(DOH *obj, String *filename) {
XML xml;
xmllite = 1;
if (! filename) {
out = stdout;
if (!filename) {
out = stdout;
} else {
out = NewFile(filename, "w");
if (!out) {
FileErrorDisplay(filename);
SWIG_exit(EXIT_FAILURE);
}
else {
out = NewFile(filename, "w");
if (!out) {
FileErrorDisplay(filename);
SWIG_exit(EXIT_FAILURE);
}
}
Printf( out, "<?xml version=\"1.0\" ?> \n" );
xml.Xml_print_tree(obj);
}
Printf(out, "<?xml version=\"1.0\" ?> \n");
xml.Xml_print_tree(obj);
}
static Language * new_swig_xml() {
return new XML();
static Language *new_swig_xml() {
return new XML();
}
extern "C" Language * swig_xml( void ) {
return new_swig_xml();
extern "C" Language *swig_xml(void) {
return new_swig_xml();
}

File diff suppressed because it is too large Load Diff

View File

@ -16,9 +16,9 @@ char cvsroot_expr_c[] = "$Header$";
static SwigScanner *scan = 0;
typedef struct {
int op;
long value;
String *svalue;
int op;
long value;
String *svalue;
} exprval;
#define EXPR_TOP 1
@ -27,11 +27,11 @@ typedef struct {
#define EXPR_GROUP 4
#define EXPR_UMINUS 100
static exprval stack[256]; /* Parsing stack */
static int sp = 0; /* Stack pointer */
static int prec[256]; /* Precedence rules */
static int expr_init = 0; /* Initialization flag */
static char *errmsg = 0; /* Parsing error */
static exprval stack[256]; /* Parsing stack */
static int sp = 0; /* Stack pointer */
static int prec[256]; /* Precedence rules */
static int expr_init = 0; /* Initialization flag */
static char *errmsg = 0; /* Parsing error */
/* Initialize the precedence table for various operators. Low values have higher precedence */
static void init_precedence() {
@ -66,9 +66,9 @@ static void init_precedence() {
/* Reduce a single operator on the stack */
/* return 0 on failure, 1 on success */
static int reduce_op() {
long op_token = stack[sp-1].value;
long op_token = stack[sp - 1].value;
assert(sp > 0);
assert(stack[sp-1].op == EXPR_OP);
assert(stack[sp - 1].op == EXPR_OP);
/* do some basic checking first: */
if (stack[sp].op != EXPR_VALUE) {
errmsg = "Right-hand side is not value";
@ -90,23 +90,23 @@ static int reduce_op() {
errmsg = "Left-hand side of binary operator is not a value";
return 0;
}
if ((!stack[sp-2].svalue) != (!stack[sp].svalue)) {
if ((!stack[sp - 2].svalue) != (!stack[sp].svalue)) {
errmsg = "Can't mix strings and integers in expression";
return 0;
}
}
if (stack[sp].svalue) {
/* A binary string expression */
switch(stack[sp-1].value) {
switch (stack[sp - 1].value) {
case SWIG_TOKEN_EQUALTO:
stack[sp-2].value = (Strcmp(stack[sp-2].svalue,stack[sp].svalue) == 0);
Delete(stack[sp-2].svalue);
stack[sp - 2].value = (Strcmp(stack[sp - 2].svalue, stack[sp].svalue) == 0);
Delete(stack[sp - 2].svalue);
Delete(stack[sp].svalue);
sp -= 2;
break;
case SWIG_TOKEN_NOTEQUAL:
stack[sp-2].value = (Strcmp(stack[sp-2].svalue,stack[sp].svalue) != 0);
Delete(stack[sp-2].svalue);
stack[sp - 2].value = (Strcmp(stack[sp - 2].svalue, stack[sp].svalue) != 0);
Delete(stack[sp - 2].svalue);
Delete(stack[sp].svalue);
sp -= 2;
break;
@ -116,89 +116,89 @@ static int reduce_op() {
break;
}
} else {
switch(op_token) {
switch (op_token) {
case SWIG_TOKEN_STAR:
stack[sp-2].value = stack[sp-2].value * stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value * stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_EQUALTO:
stack[sp-2].value = stack[sp-2].value == stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value == stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_NOTEQUAL:
stack[sp-2].value = stack[sp-2].value != stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value != stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_PLUS:
stack[sp-2].value = stack[sp-2].value + stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value + stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_MINUS:
stack[sp-2].value = stack[sp-2].value - stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value - stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_AND:
stack[sp-2].value = stack[sp-2].value & stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value & stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_LAND:
stack[sp-2].value = stack[sp-2].value && stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value && stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_OR:
stack[sp-2].value = stack[sp-2].value | stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value | stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_LOR:
stack[sp-2].value = stack[sp-2].value || stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value || stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_XOR:
stack[sp-2].value = stack[sp-2].value ^ stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value ^ stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_LESSTHAN:
stack[sp-2].value = stack[sp-2].value < stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value < stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_GREATERTHAN:
stack[sp-2].value = stack[sp-2].value > stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value > stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_LTEQUAL:
stack[sp-2].value = stack[sp-2].value <= stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value <= stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_GTEQUAL:
stack[sp-2].value = stack[sp-2].value >= stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value >= stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_NOT:
stack[sp-1].value = ~stack[sp].value;
stack[sp - 1].value = ~stack[sp].value;
sp--;
break;
case SWIG_TOKEN_LNOT:
stack[sp-1].value = !stack[sp].value;
stack[sp - 1].value = !stack[sp].value;
sp--;
break;
case EXPR_UMINUS:
stack[sp-1].value = -stack[sp].value;
stack[sp - 1].value = -stack[sp].value;
sp--;
break;
case SWIG_TOKEN_SLASH:
stack[sp-2].value = stack[sp-2].value / stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value / stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_PERCENT:
stack[sp-2].value = stack[sp-2].value % stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value % stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_LSHIFT:
stack[sp-2].value = stack[sp-2].value << stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value << stack[sp].value;
sp -= 2;
break;
case SWIG_TOKEN_RSHIFT:
stack[sp-2].value = stack[sp-2].value >> stack[sp].value;
stack[sp - 2].value = stack[sp - 2].value >> stack[sp].value;
sp -= 2;
break;
default:
@ -218,14 +218,14 @@ static int reduce_op() {
* Initialize the expression evaluator
* ----------------------------------------------------------------------------- */
void
Preprocessor_expr_init (void) {
if (!expr_init) init_precedence();
if (!scan) scan = NewSwigScanner();
void Preprocessor_expr_init(void) {
if (!expr_init)
init_precedence();
if (!scan)
scan = NewSwigScanner();
}
void
Preprocessor_expr_delete (void) {
void Preprocessor_expr_delete(void) {
SwigScanner_clear(scan);
DelSwigScanner(scan);
}
@ -235,11 +235,12 @@ Preprocessor_expr_delete (void) {
* Tokenizer
* ----------------------------------------------------------------------------- */
static int expr_token(SwigScanner *s) {
static int expr_token(SwigScanner * s) {
int t;
while(1) {
while (1) {
t = SwigScanner_token(s);
if (!((t == SWIG_TOKEN_BACKSLASH) || (t == SWIG_TOKEN_ENDLINE))) break;
if (!((t == SWIG_TOKEN_BACKSLASH) || (t == SWIG_TOKEN_ENDLINE)))
break;
}
return t;
}
@ -250,20 +251,19 @@ static int expr_token(SwigScanner *s) {
* Evaluates an arithmetic expression. Returns the result and sets an error code.
* ----------------------------------------------------------------------------- */
int
Preprocessor_expr(DOH *s, int *error) {
int token = 0;
int op = 0;
int Preprocessor_expr(DOH *s, int *error) {
int token = 0;
int op = 0;
sp = 0;
assert(s);
assert(scan);
Seek(s,0,SEEK_SET);
Seek(s, 0, SEEK_SET);
/* Printf(stdout,"evaluating : '%s'\n", s); */
*error = 0;
SwigScanner_clear(scan);
SwigScanner_push(scan,s);
SwigScanner_push(scan, s);
/* Put initial state onto the stack */
stack[sp].op = EXPR_TOP;
@ -271,7 +271,7 @@ Preprocessor_expr(DOH *s, int *error) {
while (1) {
/* Look at the top of the stack */
switch(stack[sp].op) {
switch (stack[sp].op) {
case EXPR_TOP:
/* An expression. Can be a number or another expression enclosed in parens */
token = expr_token(scan);
@ -283,13 +283,14 @@ Preprocessor_expr(DOH *s, int *error) {
if ((token == SWIG_TOKEN_INT) || (token == SWIG_TOKEN_UINT) || (token == SWIG_TOKEN_LONG) || (token == SWIG_TOKEN_ULONG)) {
/* A number. Reduce EXPR_TOP to an EXPR_VALUE */
char *c = Char(SwigScanner_text(scan));
stack[sp].value = (long) strtol(c,0,0);
stack[sp].value = (long) strtol(c, 0, 0);
stack[sp].svalue = 0;
/* stack[sp].value = (long) atol(Char(SwigScanner_text(scan))); */
/* stack[sp].value = (long) atol(Char(SwigScanner_text(scan))); */
stack[sp].op = EXPR_VALUE;
} else if (token == SWIG_TOKEN_PLUS) { }
else if ((token == SWIG_TOKEN_MINUS) || (token == SWIG_TOKEN_LNOT) || (token==SWIG_TOKEN_NOT)) {
if (token == SWIG_TOKEN_MINUS) token = EXPR_UMINUS;
} else if (token == SWIG_TOKEN_PLUS) {
} else if ((token == SWIG_TOKEN_MINUS) || (token == SWIG_TOKEN_LNOT) || (token == SWIG_TOKEN_NOT)) {
if (token == SWIG_TOKEN_MINUS)
token = EXPR_UMINUS;
stack[sp].value = token;
stack[sp++].op = EXPR_OP;
stack[sp].op = EXPR_TOP;
@ -299,7 +300,7 @@ Preprocessor_expr(DOH *s, int *error) {
stack[sp].op = EXPR_TOP;
stack[sp].value = 0;
stack[sp].svalue = 0;
} else if (token == SWIG_TOKEN_ENDLINE) {
} else if (token == SWIG_TOKEN_ENDLINE) {
} else if ((token == SWIG_TOKEN_STRING)) {
stack[sp].svalue = NewString(SwigScanner_text(scan));
stack[sp].op = EXPR_VALUE;
@ -307,7 +308,8 @@ Preprocessor_expr(DOH *s, int *error) {
stack[sp].value = 0;
stack[sp].svalue = 0;
stack[sp].op = EXPR_VALUE;
} else goto syntax_error;
} else
goto syntax_error;
break;
case EXPR_VALUE:
/* A value is on the stack. We may reduce or evaluate depending on what the next token is */
@ -315,18 +317,20 @@ Preprocessor_expr(DOH *s, int *error) {
if (!token) {
/* End of input. Might have to reduce if an operator is on stack */
while (sp > 0) {
if (stack[sp-1].op == EXPR_OP) {
if (!reduce_op()) goto reduce_error;
} else if (stack[sp-1].op == EXPR_GROUP) {
if (stack[sp - 1].op == EXPR_OP) {
if (!reduce_op())
goto reduce_error;
} else if (stack[sp - 1].op == EXPR_GROUP) {
errmsg = "Missing \')\'";
*error = 1;
return 0;
} else goto syntax_error;
} else
goto syntax_error;
}
return stack[sp].value;
}
/* Token must be an operator */
switch(token) {
switch (token) {
case SWIG_TOKEN_STAR:
case SWIG_TOKEN_EQUALTO:
case SWIG_TOKEN_NOTEQUAL:
@ -345,7 +349,7 @@ Preprocessor_expr(DOH *s, int *error) {
case SWIG_TOKEN_PERCENT:
case SWIG_TOKEN_LSHIFT:
case SWIG_TOKEN_RSHIFT:
if ((sp == 0) || (stack[sp-1].op == EXPR_GROUP)) {
if ((sp == 0) || (stack[sp - 1].op == EXPR_GROUP)) {
/* No possibility of reduce. Push operator and expression */
sp++;
stack[sp].op = EXPR_OP;
@ -354,15 +358,17 @@ Preprocessor_expr(DOH *s, int *error) {
stack[sp].op = EXPR_TOP;
stack[sp].value = 0;
} else {
if (stack[sp-1].op != EXPR_OP) goto syntax_error_expected_operator;
op = stack[sp-1].value; /* Previous operator */
if (stack[sp - 1].op != EXPR_OP)
goto syntax_error_expected_operator;
op = stack[sp - 1].value; /* Previous operator */
/* Now, depending on the precedence relationship between the last operator and the current
we will reduce or push */
if (prec[op] <= prec[token]) {
/* Reduce the previous operator */
if (!reduce_op()) goto reduce_error;
if (!reduce_op())
goto reduce_error;
}
sp++;
stack[sp].op = EXPR_OP;
@ -373,15 +379,18 @@ Preprocessor_expr(DOH *s, int *error) {
}
break;
case SWIG_TOKEN_RPAREN:
if (sp == 0) goto extra_rparen;
if (sp == 0)
goto extra_rparen;
/* Might have to reduce operators first */
while ((sp > 0) && (stack[sp-1].op == EXPR_OP)) {
if (!reduce_op()) goto reduce_error;
while ((sp > 0) && (stack[sp - 1].op == EXPR_OP)) {
if (!reduce_op())
goto reduce_error;
}
if ((sp == 0) || (stack[sp-1].op != EXPR_GROUP)) goto extra_rparen;
stack[sp-1].op = EXPR_VALUE;
stack[sp-1].value = stack[sp].value;
if ((sp == 0) || (stack[sp - 1].op != EXPR_GROUP))
goto extra_rparen;
stack[sp - 1].op = EXPR_VALUE;
stack[sp - 1].value = stack[sp].value;
sp--;
break;
default:
@ -391,27 +400,27 @@ Preprocessor_expr(DOH *s, int *error) {
break;
default:
fprintf(stderr,"Internal error in expression evaluator.\n");
fprintf(stderr, "Internal error in expression evaluator.\n");
abort();
}
}
syntax_error:
syntax_error:
errmsg = "Syntax error";
*error = 1;
return 0;
syntax_error_expected_operator:
syntax_error_expected_operator:
errmsg = "Syntax error: expected operator";
*error = 1;
return 0;
reduce_error:
reduce_error:
/* errmsg has been set by reduce_op */
*error = 1;
return 0;
extra_rparen:
extra_rparen:
errmsg = "Extra \')\'";
*error = 1;
return 0;
@ -423,14 +432,6 @@ Preprocessor_expr(DOH *s, int *error) {
* Return error message set by the evaluator (if any)
* ----------------------------------------------------------------------------- */
char *
Preprocessor_expr_error() {
char *Preprocessor_expr_error() {
return errmsg;
}

View File

@ -17,27 +17,22 @@
#ifdef __cplusplus
extern "C" {
#endif
extern int Preprocessor_expr(String *s, int *error);
extern char *Preprocessor_expr_error(void);
extern Hash *Preprocessor_define(const String_or_char *str, int swigmacro);
extern void Preprocessor_undef(const String_or_char *name);
extern void Preprocessor_init(void);
extern void Preprocessor_delete(void);
extern String *Preprocessor_parse(String *s);
extern void Preprocessor_include_all(int);
extern void Preprocessor_import_all(int);
extern void Preprocessor_ignore_missing(int);
extern void Preprocessor_error_as_warning(int);
extern List *Preprocessor_depend(void);
extern void Preprocessor_expr_init(void);
extern void Preprocessor_expr_delete(void);
extern int Preprocessor_expr(String *s, int *error);
extern char *Preprocessor_expr_error(void);
extern Hash *Preprocessor_define(const String_or_char *str, int swigmacro);
extern void Preprocessor_undef(const String_or_char *name);
extern void Preprocessor_init(void);
extern void Preprocessor_delete(void);
extern String *Preprocessor_parse(String *s);
extern void Preprocessor_include_all(int);
extern void Preprocessor_import_all(int);
extern void Preprocessor_ignore_missing(int);
extern void Preprocessor_error_as_warning(int);
extern List *Preprocessor_depend(void);
extern void Preprocessor_expr_init(void);
extern void Preprocessor_expr_delete(void);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -38,8 +38,8 @@ char cvsroot_error_c[] = "$Header$";
# define DEFAULT_ERROR_MSG_FORMAT EMF_STANDARD
#endif
static ErrorMessageFormat msg_format = DEFAULT_ERROR_MSG_FORMAT;
static int silence = 0; /* Silent operation */
static String *filter = 0; /* Warning filter */
static int silence = 0; /* Silent operation */
static String *filter = 0; /* Warning filter */
static int warnall = 0;
static int nwarning = 0;
static int nerrors = 0;
@ -58,22 +58,23 @@ static String *format_filename(const String_or_char *filename);
* Issue a warning message
* ----------------------------------------------------------------------------- */
void
Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt, ...) {
void Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt, ...) {
String *out;
char *msg;
int wrn = 1;
char *msg;
int wrn = 1;
va_list ap;
if (silence) return;
if (!init_fmt) Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT);
if (silence)
return;
if (!init_fmt)
Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT);
va_start(ap,fmt);
va_start(ap, fmt);
out = NewStringEmpty();
vPrintf(out,fmt,ap);
vPrintf(out, fmt, ap);
msg = Char(out);
if (isdigit((unsigned char)*msg)) {
if (isdigit((unsigned char) *msg)) {
unsigned long result = strtoul(msg, &msg, 10);
if (msg != Char(out)) {
msg++;
@ -83,13 +84,15 @@ Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt
/* Check in the warning filter */
if (filter) {
char temp[32];
char temp[32];
char *c;
char *f = Char(filter);
sprintf(temp,"%d",wnum);
while(*f != '\0' && (c = strstr(f,temp))) {
if (*(c-1) == '-') wrn = 0; /* Warning disabled */
if (*(c-1) == '+') wrn = 1; /* Warning enabled */
sprintf(temp, "%d", wnum);
while (*f != '\0' && (c = strstr(f, temp))) {
if (*(c - 1) == '-')
wrn = 0; /* Warning disabled */
if (*(c - 1) == '+')
wrn = 1; /* Warning enabled */
f += strlen(temp);
}
}
@ -100,7 +103,7 @@ Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt
} else {
Printf(stderr, wrn_nnum_fmt, formatted_filename, line);
}
Printf(stderr,"%s",msg);
Printf(stderr, "%s", msg);
nwarning++;
Delete(formatted_filename);
}
@ -114,22 +117,23 @@ Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt
* Issue an error message
* ----------------------------------------------------------------------------- */
void
Swig_error(const String_or_char *filename, int line, const char *fmt, ...) {
void Swig_error(const String_or_char *filename, int line, const char *fmt, ...) {
va_list ap;
String *formatted_filename = NULL;
if (silence) return;
if (!init_fmt) Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT);
va_start(ap,fmt);
if (silence)
return;
if (!init_fmt)
Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT);
va_start(ap, fmt);
formatted_filename = format_filename(filename);
if (line > 0) {
Printf(stderr, err_line_fmt, formatted_filename, line);
} else {
Printf(stderr, err_eof_fmt, formatted_filename);
}
vPrintf(stderr,fmt,ap);
vPrintf(stderr, fmt, ap);
va_end(ap);
nerrors++;
Delete(formatted_filename);
@ -141,8 +145,7 @@ Swig_error(const String_or_char *filename, int line, const char *fmt, ...) {
* Returns number of errors received.
* ----------------------------------------------------------------------------- */
int
Swig_error_count(void) {
int Swig_error_count(void) {
return nerrors;
}
@ -152,8 +155,7 @@ Swig_error_count(void) {
* Set silent flag
* ----------------------------------------------------------------------------- */
void
Swig_error_silent(int s) {
void Swig_error_silent(int s) {
silence = s;
}
@ -164,14 +166,14 @@ Swig_error_silent(int s) {
* Takes a comma separate list of warning numbers and puts in the filter.
* ----------------------------------------------------------------------------- */
void
Swig_warnfilter(const String_or_char *wlist, int add) {
void Swig_warnfilter(const String_or_char *wlist, int add) {
char *c;
char *cw;
String *s;
if (!filter) filter = NewStringEmpty();
if (!filter)
filter = NewStringEmpty();
s = NewString("");
Clear(s);
cw = Char(wlist);
@ -182,31 +184,30 @@ Swig_warnfilter(const String_or_char *wlist, int add) {
++cw;
}
c = Char(s);
c = strtok(c,", ");
c = strtok(c, ", ");
while (c) {
if (isdigit((int) *c) || (*c == '+') || (*c == '-')) {
if (add) {
Insert(filter,0,c);
Insert(filter, 0, c);
if (isdigit((int) *c)) {
Insert(filter,0,"-");
Insert(filter, 0, "-");
}
} else {
char temp[32];
if (isdigit((int) *c)) {
sprintf(temp,"-%s",c);
sprintf(temp, "-%s", c);
} else {
strcpy(temp,c);
strcpy(temp, c);
}
Replace(filter,temp,"", DOH_REPLACE_FIRST);
Replace(filter, temp, "", DOH_REPLACE_FIRST);
}
}
c = strtok(NULL,", ");
c = strtok(NULL, ", ");
}
Delete(s);
}
void
Swig_warnall(void) {
void Swig_warnall(void) {
warnall = 1;
}
@ -217,8 +218,7 @@ Swig_warnall(void) {
* Return the number of warnings
* ----------------------------------------------------------------------------- */
int
Swig_warn_count(void) {
int Swig_warn_count(void) {
return nwarning;
}
@ -228,31 +228,30 @@ Swig_warn_count(void) {
* Set the type of error/warning message display
* ----------------------------------------------------------------------------- */
void
Swig_error_msg_format(ErrorMessageFormat format) {
const char* error = "Error";
const char* warning = "Warning";
void Swig_error_msg_format(ErrorMessageFormat format) {
const char *error = "Error";
const char *warning = "Warning";
const char* fmt_eof = 0;
const char* fmt_line = 0;
const char *fmt_eof = 0;
const char *fmt_line = 0;
/* here 'format' could be directly a string instead of an enum, but
by now a switch is used to translated into one. */
switch (format) {
case EMF_MICROSOFT:
fmt_line = "%s(%d)";
fmt_eof = "%s(999999)"; /* Is there a special character for EOF? Just use a large number. */
fmt_eof = "%s(999999)"; /* Is there a special character for EOF? Just use a large number. */
break;
case EMF_STANDARD:
default:
fmt_line = "%s:%d";
fmt_eof = "%s:EOF";
fmt_eof = "%s:EOF";
}
sprintf(wrn_wnum_fmt, "%s: %s(%%d): ", fmt_line, warning);
sprintf(wrn_nnum_fmt, "%s: %s: ", fmt_line, warning);
sprintf(err_line_fmt, "%s: %s: ", fmt_line, error);
sprintf(err_eof_fmt, "%s: %s: ", fmt_eof, error);
sprintf(wrn_nnum_fmt, "%s: %s: ", fmt_line, warning);
sprintf(err_line_fmt, "%s: %s: ", fmt_line, error);
sprintf(err_eof_fmt, "%s: %s: ", fmt_eof, error);
msg_format = format;
init_fmt = 1;
@ -263,12 +262,10 @@ Swig_error_msg_format(ErrorMessageFormat format) {
*
* Remove double backslashes in Windows filename paths for display
* ----------------------------------------------------------------------------- */
static String *
format_filename(const String_or_char *filename) {
static String *format_filename(const String_or_char *filename) {
String *formatted_filename = NewString(filename);
#if defined(_WIN32)
Replaceall(formatted_filename,"\\\\","\\");
Replaceall(formatted_filename, "\\\\", "\\");
#endif
return formatted_filename;
return formatted_filename;
}

View File

@ -30,35 +30,36 @@ static int debug = 0;
* changed, lang.cxx doesn't nedd to be touched again.
* ----------------------------------------------------------------------------- */
void
Swig_fragment_register(Node* fragment) {
if (Getattr(fragment,k_emitonly)) {
void Swig_fragment_register(Node *fragment) {
if (Getattr(fragment, k_emitonly)) {
Swig_fragment_emit(fragment);
return;
} else {
String *name = Copy(Getattr(fragment,k_value));
String *type = Getattr(fragment,k_type);
String *name = Copy(Getattr(fragment, k_value));
String *type = Getattr(fragment, k_type);
if (type) {
SwigType *rtype = SwigType_typedef_resolve_all(type);
String *mangle = Swig_string_mangle(type);
Append(name,mangle);
Append(name, mangle);
Delete(mangle);
Delete(rtype);
if (debug) Printf(stdout,"register fragment %s %s\n",name,type);
if (debug)
Printf(stdout, "register fragment %s %s\n", name, type);
}
if (!fragments) {
fragments = NewHash();
}
if (!Getattr(fragments,name)) {
String *section = Copy(Getattr(fragment,k_section));
String *ccode = Copy(Getattr(fragment,k_code));
Hash *kwargs = Getattr(fragment,k_kwargs);
Setmeta(ccode,k_section,section);
if (!Getattr(fragments, name)) {
String *section = Copy(Getattr(fragment, k_section));
String *ccode = Copy(Getattr(fragment, k_code));
Hash *kwargs = Getattr(fragment, k_kwargs);
Setmeta(ccode, k_section, section);
if (kwargs) {
Setmeta(ccode,k_kwargs,kwargs);
Setmeta(ccode, k_kwargs, kwargs);
}
Setattr(fragments,name,ccode);
if (debug) Printf(stdout,"registering fragment %s %s\n",name,section);
Setattr(fragments, name, ccode);
if (debug)
Printf(stdout, "registering fragment %s %s\n", name, section);
Delete(section);
Delete(ccode);
}
@ -73,16 +74,15 @@ Swig_fragment_register(Node* fragment) {
* ----------------------------------------------------------------------------- */
static
char* char_index(char* str, char c)
{
while (*str && (c != *str)) ++str;
char *char_index(char *str, char c) {
while (*str && (c != *str))
++str;
return (c == *str) ? str : 0;
}
void
Swig_fragment_emit(Node *n) {
void Swig_fragment_emit(Node *n) {
String *code;
char *pc, *tok;
char *pc, *tok;
String *t;
String *mangle = 0;
String *name = 0;
@ -92,38 +92,44 @@ Swig_fragment_emit(Node *n) {
Swig_warning(WARN_FRAGMENT_NOT_FOUND, Getfile(n), Getline(n), "Fragment '%s' not found.\n", name);
return;
}
name = Getattr(n,k_value);
name = Getattr(n, k_value);
if (!name) {
name = n;
}
type = Getattr(n,k_type);
type = Getattr(n, k_type);
if (type) {
mangle = Swig_string_mangle(type);
}
if (debug) Printf(stdout,"looking fragment %s %s\n",name, type);
if (debug)
Printf(stdout, "looking fragment %s %s\n", name, type);
t = Copy(name);
tok = Char(t);
pc = char_index(tok,',');
if (pc) *pc = 0;
pc = char_index(tok, ',');
if (pc)
*pc = 0;
while (tok) {
String *name = NewString(tok);
if (mangle) Append(name,mangle);
if (looking_fragments && Getattr(looking_fragments,name)) {
if (mangle)
Append(name, mangle);
if (looking_fragments && Getattr(looking_fragments, name)) {
return;
}
code = Getattr(fragments,name);
if (debug) Printf(stdout,"looking subfragment %s\n", name);
if (code && (Strcmp(code,k_ignore) != 0)) {
String *section = Getmeta(code,k_section);
Hash *nn = Getmeta(code,k_kwargs);
if (!looking_fragments) looking_fragments = NewHash();
Setattr(looking_fragments,name,"1");
}
code = Getattr(fragments, name);
if (debug)
Printf(stdout, "looking subfragment %s\n", name);
if (code && (Strcmp(code, k_ignore) != 0)) {
String *section = Getmeta(code, k_section);
Hash *nn = Getmeta(code, k_kwargs);
if (!looking_fragments)
looking_fragments = NewHash();
Setattr(looking_fragments, name, "1");
while (nn) {
if (Equal(Getattr(nn,k_name),k_fragment)) {
if (debug) Printf(stdout,"emitting fragment %s %s\n",nn, type);
if (Equal(Getattr(nn, k_name), k_fragment)) {
if (debug)
Printf(stdout, "emitting fragment %s %s\n", nn, type);
Setfile(nn, Getfile(n));
Setline(nn, Getline(n));
Swig_fragment_emit(nn);
@ -133,23 +139,25 @@ Swig_fragment_emit(Node *n) {
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);
Swig_error(Getfile(code), Getline(code), "Bad section '%s' for code fragment '%s'\n", section, name);
} else {
if (debug) Printf(stdout,"emitting subfragment %s %s\n",name, section);
if (debug) Printf(f,"/* begin fragment %s */\n",name);
Printf(f,"%s\n",code);
if (debug) Printf(f,"/* end fragment %s */\n\n",name);
Setattr(fragments,name,k_ignore);
Delattr(looking_fragments,name);
if (debug)
Printf(stdout, "emitting subfragment %s %s\n", name, section);
if (debug)
Printf(f, "/* begin fragment %s */\n", name);
Printf(f, "%s\n", code);
if (debug)
Printf(f, "/* end fragment %s */\n\n", name);
Setattr(fragments, name, k_ignore);
Delattr(looking_fragments, name);
}
}
} else if (!code && type) {
SwigType *rtype = SwigType_typedef_resolve_all(type);
if (!Equal(type,rtype)) {
String *name = Copy(Getattr(n,k_value));
if (!Equal(type, rtype)) {
String *name = Copy(Getattr(n, k_value));
String *mangle = Swig_string_mangle(type);
Append(name,mangle);
Append(name, mangle);
Setfile(name, Getfile(n));
Setline(name, Getline(n));
Swig_fragment_emit(name);
@ -158,17 +166,17 @@ Swig_fragment_emit(Node *n) {
}
Delete(rtype);
}
if (!code) {
Swig_warning(WARN_FRAGMENT_NOT_FOUND, Getfile(n), Getline(n), "Fragment '%s' not found.\n", name);
}
tok = pc ? pc + 1 : 0;
if (tok) {
pc = char_index(tok,',');
if (pc) *pc = 0;
pc = char_index(tok, ',');
if (pc)
*pc = 0;
}
Delete(name);
}
Delete(t);
}

View File

@ -21,8 +21,8 @@ char cvsroot_getopt_c[] = "$Header$";
#include "swig.h"
static char **args;
static int numargs;
static int *marked;
static int numargs;
static int *marked;
/* -----------------------------------------------------------------------------
* Swig_init_args()
@ -30,8 +30,7 @@ static int *marked;
* Initialize the argument list handler.
* ----------------------------------------------------------------------------- */
void
Swig_init_args(int argc, char **argv) {
void Swig_init_args(int argc, char **argv) {
int i;
assert(argc > 0);
assert(argv);
@ -51,11 +50,10 @@ Swig_init_args(int argc, char **argv) {
* Marks an argument as being parsed.
* ----------------------------------------------------------------------------- */
void
Swig_mark_arg(int n) {
assert(marked);
assert((n >= 0) && (n < numargs));
marked[n] = 1;
void Swig_mark_arg(int n) {
assert(marked);
assert((n >= 0) && (n < numargs));
marked[n] = 1;
}
/* -----------------------------------------------------------------------------
@ -64,9 +62,8 @@ Swig_mark_arg(int n) {
* Checks to see if argument has been picked up.
* ----------------------------------------------------------------------------- */
int
Swig_check_marked(int n) {
assert((n>=0) && (n < numargs));
int Swig_check_marked(int n) {
assert((n >= 0) && (n < numargs));
return marked[n];
}
@ -75,27 +72,26 @@ Swig_check_marked(int n) {
*
* Checkers for unprocessed command line options and errors.
* ----------------------------------------------------------------------------- */
void
Swig_check_options(int check_input) {
int error = 0;
int i;
int max = check_input ? numargs - 1 : numargs;
assert(marked);
for (i = 1; i < max; i++) {
if (!marked[i]) {
Printf(stderr,"swig error : Unrecognized option %s\n", args[i]);
error=1;
}
}
if (error) {
Printf(stderr,"Use 'swig -help' for available options.\n");
exit(1);
}
if (check_input && marked[numargs-1]) {
Printf(stderr,"Must specify an input file. Use -help for available options.\n");
exit(1);
void Swig_check_options(int check_input) {
int error = 0;
int i;
int max = check_input ? numargs - 1 : numargs;
assert(marked);
for (i = 1; i < max; i++) {
if (!marked[i]) {
Printf(stderr, "swig error : Unrecognized option %s\n", args[i]);
error = 1;
}
}
if (error) {
Printf(stderr, "Use 'swig -help' for available options.\n");
exit(1);
}
if (check_input && marked[numargs - 1]) {
Printf(stderr, "Must specify an input file. Use -help for available options.\n");
exit(1);
}
}
/* -----------------------------------------------------------------------------
@ -104,13 +100,8 @@ Swig_check_options(int check_input) {
* Generates a generic error message and exits.
* ----------------------------------------------------------------------------- */
void
Swig_arg_error() {
Printf(stderr,"SWIG : Unable to parse command line options.\n");
Printf(stderr,"Use 'swig -help' for available options.\n");
void Swig_arg_error() {
Printf(stderr, "SWIG : Unable to parse command line options.\n");
Printf(stderr, "Use 'swig -help' for available options.\n");
exit(1);
}

View File

@ -16,11 +16,11 @@ char cvsroot_include_c[] = "$Header$";
/* Delimeter used in accessing files and directories */
static List *directories = 0; /* List of include directories */
static String *lastpath = 0; /* Last file that was included */
static String *swiglib = 0; /* Location of SWIG library */
static String *lang_config = 0; /* Language configuration file */
static int dopush = 1; /* Whether to push directories */
static List *directories = 0; /* List of include directories */
static String *lastpath = 0; /* Last file that was included */
static String *swiglib = 0; /* Location of SWIG library */
static String *lang_config = 0; /* Language configuration file */
static int dopush = 1; /* Whether to push directories */
/* This functions determine whether to push/pop dirs in the preprocessor */
void Swig_set_push_dir(int push) {
@ -51,13 +51,11 @@ String *Swig_get_config_file() {
* include mechanism, but rather as a query interface for language modules.
* ----------------------------------------------------------------------------- */
void
Swig_swiglib_set(const String_or_char *sl) {
void Swig_swiglib_set(const String_or_char *sl) {
swiglib = NewString(sl);
}
String *
Swig_swiglib_get() {
String *Swig_swiglib_get() {
return swiglib;
}
@ -67,9 +65,9 @@ Swig_swiglib_get() {
* Adds a directory to the SWIG search path.
* ----------------------------------------------------------------------------- */
List *
Swig_add_directory(const String_or_char *dirname) {
if (!directories) directories = NewList();
List *Swig_add_directory(const String_or_char *dirname) {
if (!directories)
directories = NewList();
assert(directories);
if (dirname) {
String *sdir = NewString(dirname);
@ -93,21 +91,23 @@ Swig_add_directory(const String_or_char *dirname) {
* the preprocessor to grab files in the same directory as other included files.
* ----------------------------------------------------------------------------- */
void
Swig_push_directory(const String_or_char *dirname) {
void Swig_push_directory(const String_or_char *dirname) {
String *tmp = 0;
if (!Swig_get_push_dir()) return;
if (!directories) directories = NewList();
if (!Swig_get_push_dir())
return;
if (!directories)
directories = NewList();
assert(directories);
if (!DohIsString(dirname)) {
dirname = tmp = NewString(dirname);
assert(dirname);
}
}
if (dirname) {
Hash *dir = NewHash();
Setattr(dir, k_name, dirname);
Insert(directories, 0, dir);
if (tmp) Delete(tmp);
if (tmp)
Delete(tmp);
}
}
@ -118,11 +118,12 @@ Swig_push_directory(const String_or_char *dirname) {
* the preprocessor.
* ----------------------------------------------------------------------------- */
void
Swig_pop_directory() {
if (!Swig_get_push_dir()) return;
if (!directories) return;
Delitem(directories,0);
void Swig_pop_directory() {
if (!Swig_get_push_dir())
return;
if (!directories)
return;
Delitem(directories, 0);
}
/* -----------------------------------------------------------------------------
@ -131,8 +132,7 @@ Swig_pop_directory() {
* Returns the full pathname of the last file opened.
* ----------------------------------------------------------------------------- */
String *
Swig_last_file() {
String *Swig_last_file() {
assert(lastpath);
return lastpath;
}
@ -143,11 +143,10 @@ Swig_last_file() {
* Returns a list of the current search paths.
* ----------------------------------------------------------------------------- */
static List *
Swig_search_path_any(int syspath) {
static List *Swig_search_path_any(int syspath) {
String *filename;
String *dirname;
List *slist, *llist;
List *slist, *llist;
int i, ilen;
llist = 0;
@ -156,35 +155,35 @@ Swig_search_path_any(int syspath) {
filename = NewStringEmpty();
assert(filename);
#ifdef MACSWIG
Printf(filename,"%s",SWIG_FILE_DELIMETER);
Printf(filename, "%s", SWIG_FILE_DELIMETER);
#else
Printf(filename,".%s", SWIG_FILE_DELIMETER);
Printf(filename, ".%s", SWIG_FILE_DELIMETER);
#endif
if (syspath) {
llist = NewList();
assert(llist);
Append(llist,filename);
Append(llist, filename);
} else {
Append(slist,filename);
}
Append(slist, filename);
}
ilen = Len(directories);
for (i = 0; i < ilen; i++) {
int issimple = 0;
dirname = Getitem(directories,i);
dirname = Getitem(directories, i);
filename = NewStringEmpty();
assert(filename);
if (DohIsString(dirname)) {
filename = Copy(dirname);
issimple = 1;
} else {
filename = Copy(Getattr(dirname,k_name));
filename = Copy(Getattr(dirname, k_name));
}
StringAppend(filename, SWIG_FILE_DELIMETER);
if (syspath && (issimple || !GetFlag(dirname,k_sysdir))) {
Append(llist,filename);
if (syspath && (issimple || !GetFlag(dirname, k_sysdir))) {
Append(llist, filename);
} else {
Append(slist,filename);
Append(slist, filename);
/* Insert(slist,0,filename); */
}
Delete(filename);
@ -192,16 +191,15 @@ Swig_search_path_any(int syspath) {
if (syspath) {
int ilen = Len(llist);
for (i = 0; i < ilen; i++) {
Append(slist,Getitem(llist,i));
Append(slist, Getitem(llist, i));
}
Delete(llist);
}
return slist;
}
}
List *
Swig_search_path() {
List *Swig_search_path() {
return Swig_search_path_any(0);
}
@ -213,36 +211,37 @@ Swig_search_path() {
* Looks for a file and open it. Returns an open FILE * on success.
* ----------------------------------------------------------------------------- */
static FILE *
Swig_open_any(const String_or_char *name, int sysfile) {
FILE *f;
String *filename;
List *spath = 0;
char *cname;
int i, ilen;
static FILE *Swig_open_any(const String_or_char *name, int sysfile) {
FILE *f;
String *filename;
List *spath = 0;
char *cname;
int i, ilen;
if (!directories) directories = NewList();
if (!directories)
directories = NewList();
assert(directories);
cname = Char(name);
filename = NewString(cname);
assert(filename);
f = fopen(Char(filename),"r");
f = fopen(Char(filename), "r");
if (!f) {
spath = Swig_search_path_any(sysfile);
ilen = Len(spath);
for (i = 0; i < ilen; i++) {
Clear(filename);
Printf(filename,"%s%s", Getitem(spath,i), cname);
f = fopen(Char(filename),"r");
if (f) break;
}
Delete(spath);
spath = Swig_search_path_any(sysfile);
ilen = Len(spath);
for (i = 0; i < ilen; i++) {
Clear(filename);
Printf(filename, "%s%s", Getitem(spath, i), cname);
f = fopen(Char(filename), "r");
if (f)
break;
}
Delete(spath);
}
if (f) {
#if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */
Replaceall(filename,"\\\\","\\"); /* remove double '\' in case any already present */
Replaceall(filename,"\\","\\\\");
#if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */
Replaceall(filename, "\\\\", "\\"); /* remove double '\' in case any already present */
Replaceall(filename, "\\", "\\\\");
#endif
Delete(lastpath);
lastpath = Copy(filename);
@ -251,8 +250,7 @@ Swig_open_any(const String_or_char *name, int sysfile) {
return f;
}
FILE *
Swig_open(const String_or_char *name) {
FILE *Swig_open(const String_or_char *name) {
return Swig_open_any(name, 0);
}
@ -264,24 +262,23 @@ Swig_open(const String_or_char *name) {
* Reads data from an open FILE * and returns it as a string.
* ----------------------------------------------------------------------------- */
String *
Swig_read_file(FILE *f) {
int len;
char buffer[4096];
String *Swig_read_file(FILE *f) {
int len;
char buffer[4096];
String *str = NewStringEmpty();
assert(str);
while (fgets(buffer,4095,f)) {
StringAppend(str,buffer);
while (fgets(buffer, 4095, f)) {
StringAppend(str, buffer);
}
len = StringLen(str);
if (len) {
char *cstr = Char(str);
if (cstr[len - 1] != '\n') {
StringAppend(str, "\n");
}
}
}
return str;
}
@ -291,31 +288,29 @@ Swig_read_file(FILE *f) {
* Opens a file and returns it as a string.
* ----------------------------------------------------------------------------- */
static String *
Swig_include_any(const String_or_char *name, int sysfile) {
FILE *f;
String *str;
String *file;
static String *Swig_include_any(const String_or_char *name, int sysfile) {
FILE *f;
String *str;
String *file;
f = Swig_open_any(name, sysfile);
if (!f) return 0;
if (!f)
return 0;
str = Swig_read_file(f);
fclose(f);
Seek(str,0,SEEK_SET);
Seek(str, 0, SEEK_SET);
file = Copy(lastpath);
Setfile(str,file);
Setfile(str, file);
Delete(file);
Setline(str,1);
Setline(str, 1);
return str;
}
String *
Swig_include(const String_or_char *name) {
String *Swig_include(const String_or_char *name) {
return Swig_include_any(name, 0);
}
String *
Swig_include_sys(const String_or_char *name) {
String *Swig_include_sys(const String_or_char *name) {
return Swig_include_any(name, 1);
}
@ -326,15 +321,15 @@ Swig_include_sys(const String_or_char *name) {
* Copies the contents of a file into another file
* ----------------------------------------------------------------------------- */
int
Swig_insert_file(const String_or_char *filename, File *outfile) {
int Swig_insert_file(const String_or_char *filename, File *outfile) {
char buffer[4096];
int nbytes;
int nbytes;
FILE *f = Swig_open(filename);
if (!f) return -1;
while ((nbytes = Read(f,buffer,4096)) > 0) {
Write(outfile,buffer,nbytes);
if (!f)
return -1;
while ((nbytes = Read(f, buffer, 4096)) > 0) {
Write(outfile, buffer, nbytes);
}
return 0;
}
@ -350,9 +345,9 @@ Swig_insert_file(const String_or_char *filename, File *outfile) {
static Hash *named_files = 0;
void
Swig_register_filebyname(const String_or_char *filename, File *outfile) {
if (!named_files) named_files = NewHash();
void Swig_register_filebyname(const String_or_char *filename, File *outfile) {
if (!named_files)
named_files = NewHash();
Setattr(named_files, filename, outfile);
}
@ -362,10 +357,10 @@ Swig_register_filebyname(const String_or_char *filename, File *outfile) {
* Get a named file
* ----------------------------------------------------------------------------- */
File *
Swig_filebyname(const String_or_char *filename) {
if (!named_files) return 0;
return Getattr(named_files,filename);
File *Swig_filebyname(const String_or_char *filename) {
if (!named_files)
return 0;
return Getattr(named_files, filename);
}
/* -----------------------------------------------------------------------------
@ -374,18 +369,18 @@ Swig_filebyname(const String_or_char *filename) {
* Returns the suffix of a file
* ----------------------------------------------------------------------------- */
char *
Swig_file_suffix(const String_or_char *filename) {
char *Swig_file_suffix(const String_or_char *filename) {
char *d;
char *c = Char(filename);
int len = Len(filename);
if (strlen(c)) {
d = c + len - 1;
while (d != c) {
if (*d == '.') return d;
if (*d == '.')
return d;
d--;
}
return c+len;
return c + len;
}
return c;
}
@ -396,12 +391,10 @@ Swig_file_suffix(const String_or_char *filename) {
* Returns the filename with no suffix attached.
* ----------------------------------------------------------------------------- */
char *
Swig_file_basename(const String_or_char *filename)
{
char *Swig_file_basename(const String_or_char *filename) {
static char tmp[1024];
char *c;
strcpy(tmp,Char(filename));
strcpy(tmp, Char(filename));
c = Swig_file_suffix(tmp);
*c = 0;
return tmp;
@ -412,16 +405,16 @@ Swig_file_basename(const String_or_char *filename)
*
* Return the file with any leading path stripped off
* ----------------------------------------------------------------------------- */
char *
Swig_file_filename(const String_or_char *filename)
{
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;
strcpy(tmp, Char(filename));
if ((c = strrchr(tmp, *delim)))
return c + 1;
else
return tmp;
}
/* -----------------------------------------------------------------------------
@ -429,22 +422,17 @@ Swig_file_filename(const String_or_char *filename)
*
* Return the name of the directory associated with a file
* ----------------------------------------------------------------------------- */
char *
Swig_file_dirname(const String_or_char *filename)
{
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)) {
strcpy(tmp, Char(filename));
if (!strstr(tmp, delim)) {
return "";
}
c = tmp + strlen(tmp) -1;
while (*c != *delim) c--;
c = tmp + strlen(tmp) - 1;
while (*c != *delim)
c--;
*(++c) = 0;
return tmp;
}

View File

@ -22,12 +22,11 @@ char cvsroot_misc_c[] = "$Header$";
* Duplicate a NULL-terminate string given as a char *.
* ----------------------------------------------------------------------------- */
char *
Swig_copy_string(const char *s) {
char *Swig_copy_string(const char *s) {
char *c = 0;
if (s) {
c = (char *) malloc(strlen(s)+1);
strcpy(c,s);
c = (char *) malloc(strlen(s) + 1);
strcpy(c, s);
}
return c;
}
@ -38,10 +37,8 @@ Swig_copy_string(const char *s) {
* Emits the SWIG identifying banner.
* ----------------------------------------------------------------------------- */
void
Swig_banner(File *f) {
Printf(f,
"/* ----------------------------------------------------------------------------\n\
void Swig_banner(File *f) {
Printf(f, "/* ----------------------------------------------------------------------------\n\
* This file was automatically generated by SWIG (http://www.swig.org).\n\
* Version %s\n\
* \n\
@ -50,8 +47,7 @@ Swig_banner(File *f) {
* changes to this file unless you know what you are doing--modify the SWIG \n\
* interface file instead. \n", PACKAGE_VERSION);
/* String too long for ISO compliance */
Printf(f,
" * ----------------------------------------------------------------------------- */\n\n");
Printf(f, " * ----------------------------------------------------------------------------- */\n\n");
}
@ -65,27 +61,28 @@ String *Swig_string_escape(String *s) {
String *ns;
int c;
ns = NewStringEmpty();
while ((c = Getc(s)) != EOF) {
if (c == '\n') {
Printf(ns,"\\n");
Printf(ns, "\\n");
} else if (c == '\r') {
Printf(ns,"\\r");
Printf(ns, "\\r");
} else if (c == '\t') {
Printf(ns,"\\t");
Printf(ns, "\\t");
} else if (c == '\\') {
Printf(ns,"\\\\");
Printf(ns, "\\\\");
} else if (c == '\'') {
Printf(ns,"\\'");
Printf(ns, "\\'");
} else if (c == '\"') {
Printf(ns,"\\\"");
Printf(ns, "\\\"");
} else if (c == ' ') {
Putc(c,ns);
Putc(c, ns);
} else if (!isgraph(c)) {
if (c < 0) c += UCHAR_MAX +1;
Printf(ns,"\\%o", c);
if (c < 0)
c += UCHAR_MAX + 1;
Printf(ns, "\\%o", c);
} else {
Putc(c,ns);
Putc(c, ns);
}
}
return ns;
@ -103,9 +100,9 @@ String *Swig_string_upper(String *s) {
int c;
ns = NewStringEmpty();
Seek(s,0,SEEK_SET);
Seek(s, 0, SEEK_SET);
while ((c = Getc(s)) != EOF) {
Putc(toupper(c),ns);
Putc(toupper(c), ns);
}
return ns;
}
@ -121,9 +118,9 @@ String *Swig_string_lower(String *s) {
int c;
ns = NewStringEmpty();
Seek(s,0,SEEK_SET);
Seek(s, 0, SEEK_SET);
while ((c = Getc(s)) != EOF) {
Putc(tolower(c),ns);
Putc(tolower(c), ns);
}
return ns;
}
@ -142,9 +139,9 @@ String *Swig_string_title(String *s) {
int c;
ns = NewStringEmpty();
Seek(s,0,SEEK_SET);
Seek(s, 0, SEEK_SET);
while ((c = Getc(s)) != EOF) {
Putc(first ? toupper(c) : tolower(c),ns);
Putc(first ? toupper(c) : tolower(c), ns);
first = 0;
}
return ns;
@ -166,9 +163,9 @@ String *Swig_string_ccase(String *s) {
int c;
ns = NewStringEmpty();
Seek(s,0,SEEK_SET);
Seek(s, 0, SEEK_SET);
while ((c = Getc(s)) != EOF) {
if (c == '_') {
if (c == '_') {
first = 1;
continue;
}
@ -196,7 +193,7 @@ String *Swig_string_lccase(String *s) {
int c;
ns = NewStringEmpty();
Seek(s,0,SEEK_SET);
Seek(s, 0, SEEK_SET);
while ((c = Getc(s)) != EOF) {
if (c == '_') {
after_underscore = 1;
@ -212,6 +209,7 @@ String *Swig_string_lccase(String *s) {
}
return ns;
}
/* -----------------------------------------------------------------------------
* Swig_string_ucase()
*
@ -224,31 +222,31 @@ String *Swig_string_ucase(String *s) {
String *ns;
int c;
int lastC = 0;
int underscore = 0;
int underscore = 0;
ns = NewStringEmpty();
/* We insert a underscore when:
1. Lower case char followed by upper case char
getFoo > get_foo; getFOo > get_foo; GETFOO > getfoo
2. Number proceded by char
get2D > get_2d; get22D > get_22d; GET2D > get_2d */
1. Lower case char followed by upper case char
getFoo > get_foo; getFOo > get_foo; GETFOO > getfoo
2. Number proceded by char
get2D > get_2d; get22D > get_22d; GET2D > get_2d */
Seek(s,0,SEEK_SET);
Seek(s, 0, SEEK_SET);
while ((c = Getc(s)) != EOF) {
if (isdigit(c) && isalpha(lastC))
underscore = 1;
else if (isupper(c) && isalpha(lastC) && !isupper(lastC))
underscore = 1;
lastC = c;
if (underscore) {
Putc('_',ns);
Putc('_', ns);
underscore = 0;
}
}
Putc(tolower(c),ns);
Putc(tolower(c), ns);
}
return ns;
}
@ -268,7 +266,7 @@ String *Swig_string_first_upper(String *s) {
String *ns = NewStringEmpty();
char *cs = Char(s);
if (cs && cs[0] != 0) {
Putc(toupper(cs[0]),ns);
Putc(toupper(cs[0]), ns);
Append(ns, cs + 1);
}
return ns;
@ -289,7 +287,7 @@ String *Swig_string_first_lower(String *s) {
String *ns = NewStringEmpty();
char *cs = Char(s);
if (cs && cs[0] != 0) {
Putc(tolower(cs[0]),ns);
Putc(tolower(cs[0]), ns);
Append(ns, cs + 1);
}
return ns;
@ -327,30 +325,33 @@ String *Swig_string_typecode(String *s) {
String *str = 0;
tc = NewStringEmpty();
while ((c = Getc(s)) != EOF) {
if (c == '`') break;
Putc(c,tc);
if (c == '`')
break;
Putc(c, tc);
}
str = SwigType_str(tc,0);
Append(ns,str);
str = SwigType_str(tc, 0);
Append(ns, str);
Delete(str);
} else {
Putc(c,ns);
Putc(c, ns);
if (c == '\'') {
while ((c = Getc(s)) != EOF) {
Putc(c,ns);
if (c == '\'') break;
Putc(c, ns);
if (c == '\'')
break;
if (c == '\\') {
c = Getc(s);
Putc(c,ns);
Putc(c, ns);
}
}
} else if (c == '\"') {
while ((c = Getc(s)) != EOF) {
Putc(c,ns);
if (c == '\"') break;
Putc(c, ns);
if (c == '\"')
break;
if (c == '\\') {
c = Getc(s);
Putc(c,ns);
Putc(c, ns);
}
}
}
@ -358,7 +359,7 @@ String *Swig_string_typecode(String *s) {
}
return ns;
}
/* -----------------------------------------------------------------------------
* Swig_string_mangle()
*
@ -382,12 +383,13 @@ String *Swig_string_typecode(String *s) {
* ----------------------------------------------------------------------------- */
String *Swig_string_mangle(const String *s) {
#if 0
#if 0
/* old mangling, not suitable for using in macros */
String *t = Copy(s);
char *c = Char(t);
while (*c) {
if (!isalnum(*c)) *c = '_';
if (!isalnum(*c))
*c = '_';
c++;
}
return t;
@ -399,26 +401,26 @@ String *Swig_string_mangle(const String *s) {
String *b = Copy(s);
if (SwigType_istemplate(b)) {
String *st = Swig_symbol_template_deftype(b, 0);
String *sq = Swig_symbol_type_qualify(st,0);
String *sq = Swig_symbol_type_qualify(st, 0);
String *t = SwigType_namestr(sq);
Delete(st);
Delete(sq);
Delete(b);
b = t ;
b = t;
}
pc = cb = StringChar(b);
while (*pc) {
char c = *pc;
if (isalnum((int)c) || (c == '_')) {
if (isalnum((int) c) || (c == '_')) {
state = 1;
if (space && (space == state)) {
StringAppend(result,"_SS_");
StringAppend(result, "_SS_");
}
space = 0;
Printf(result,"%c",(int)c);
Printf(result, "%c", (int) c);
} else {
if (isspace((int)c)) {
if (isspace((int) c)) {
space = state;
++pc;
continue;
@ -426,10 +428,10 @@ String *Swig_string_mangle(const String *s) {
state = 3;
space = 0;
}
switch(c) {
switch (c) {
case '.':
if ((cb != pc) && (*(pc - 1) == 'p')) {
StringAppend(result,"_");
StringAppend(result, "_");
++pc;
continue;
} else {
@ -438,8 +440,9 @@ String *Swig_string_mangle(const String *s) {
break;
case ':':
if (*(pc + 1) == ':') {
StringAppend(result,"_");
++pc; ++pc;
StringAppend(result, "_");
++pc;
++pc;
continue;
}
break;
@ -503,10 +506,10 @@ String *Swig_string_mangle(const String *s) {
default:
break;
}
if (isalpha((int)c)) {
Printf(result,"_S%c_",(int)c);
} else{
Printf(result,"_S%02X_",(int)c);
if (isalpha((int) c)) {
Printf(result, "_S%c_", (int) c);
} else {
Printf(result, "_S%02X_", (int) c);
}
}
++pc;
@ -528,18 +531,17 @@ String *Swig_string_emangle(String *s) {
* In this case, "A::B". Returns NULL if there is no base.
* ----------------------------------------------------------------------------- */
void
Swig_scopename_split(String *s, String **rprefix, String **rlast) {
void Swig_scopename_split(String *s, String **rprefix, String **rlast) {
char *tmp = Char(s);
char *c = tmp;
char *cc = c;
char *co = 0;
if (!strstr(c,"::")) {
if (!strstr(c, "::")) {
*rprefix = 0;
*rlast = Copy(s);
}
if ((co = strstr(cc,"operator "))) {
if ((co = strstr(cc, "operator "))) {
if (co == cc) {
*rprefix = 0;
*rlast = Copy(s);
@ -551,7 +553,7 @@ Swig_scopename_split(String *s, String **rprefix, String **rlast) {
}
}
while (*c) {
if ((*c == ':') && (*(c+1) == ':')) {
if ((*c == ':') && (*(c + 1) == ':')) {
cc = c;
c += 2;
} else {
@ -559,8 +561,10 @@ Swig_scopename_split(String *s, String **rprefix, String **rlast) {
int level = 1;
c++;
while (*c && level) {
if (*c == '<') level++;
if (*c == '>') level--;
if (*c == '<')
level++;
if (*c == '>')
level--;
c++;
}
} else {
@ -580,14 +584,14 @@ Swig_scopename_split(String *s, String **rprefix, String **rlast) {
}
String *
Swig_scopename_prefix(String *s) {
String *Swig_scopename_prefix(String *s) {
char *tmp = Char(s);
char *c = tmp;
char *cc = c;
char *co = 0;
if (!strstr(c,"::")) return 0;
if ((co = strstr(cc,"operator "))) {
if (!strstr(c, "::"))
return 0;
if ((co = strstr(cc, "operator "))) {
if (co == cc) {
return 0;
} else {
@ -596,7 +600,7 @@ Swig_scopename_prefix(String *s) {
}
}
while (*c) {
if ((*c == ':') && (*(c+1) == ':')) {
if ((*c == ':') && (*(c + 1) == ':')) {
cc = c;
c += 2;
} else {
@ -604,8 +608,10 @@ Swig_scopename_prefix(String *s) {
int level = 1;
c++;
while (*c && level) {
if (*c == '<') level++;
if (*c == '>') level--;
if (*c == '<')
level++;
if (*c == '>')
level--;
c++;
}
} else {
@ -628,21 +634,21 @@ Swig_scopename_prefix(String *s) {
* case, "C".
* ----------------------------------------------------------------------------- */
String *
Swig_scopename_last(String *s) {
String *Swig_scopename_last(String *s) {
char *tmp = Char(s);
char *c = tmp;
char *cc = c;
char *co = 0;
if (!strstr(c,"::")) return NewString(s);
if (!strstr(c, "::"))
return NewString(s);
if ((co = strstr(cc,"operator "))) {
if ((co = strstr(cc, "operator "))) {
return NewString(co);
}
while (*c) {
if ((*c == ':') && (*(c+1) == ':')) {
if ((*c == ':') && (*(c + 1) == ':')) {
cc = c;
c += 2;
} else {
@ -650,8 +656,10 @@ Swig_scopename_last(String *s) {
int level = 1;
c++;
while (*c && level) {
if (*c == '<') level++;
if (*c == '>') level--;
if (*c == '<')
level++;
if (*c == '>')
level--;
c++;
}
} else {
@ -659,7 +667,7 @@ Swig_scopename_last(String *s) {
}
}
}
return NewString(cc+2);
return NewString(cc + 2);
}
/* -----------------------------------------------------------------------------
@ -669,30 +677,32 @@ Swig_scopename_last(String *s) {
* In this case, "A". Returns NULL if there is no base.
* ----------------------------------------------------------------------------- */
String *
Swig_scopename_first(String *s) {
String *Swig_scopename_first(String *s) {
char *tmp = Char(s);
char *c = tmp;
char *c = tmp;
char *co = 0;
if (!strstr(c,"::")) return 0;
if ((co = strstr(c,"operator "))) {
if (!strstr(c, "::"))
return 0;
if ((co = strstr(c, "operator "))) {
if (co == c) {
return 0;
}
} else {
co = c + Len(s);
}
while (*c && (c != co)) {
if ((*c == ':') && (*(c+1) == ':')) {
if ((*c == ':') && (*(c + 1) == ':')) {
break;
} else {
if (*c == '<') {
int level = 1;
c++;
while (*c && level) {
if (*c == '<') level++;
if (*c == '>') level--;
if (*c == '<')
level++;
if (*c == '>')
level--;
c++;
}
} else {
@ -715,25 +725,28 @@ Swig_scopename_first(String *s) {
* In this case, "B::C". Returns NULL if there is no suffix.
* ----------------------------------------------------------------------------- */
String *
Swig_scopename_suffix(String *s) {
String *Swig_scopename_suffix(String *s) {
char *tmp = Char(s);
char *c = tmp;
char *co = 0;
if (!strstr(c,"::")) return 0;
if ((co = strstr(c,"operator "))) {
if (co == c) return 0;
if (!strstr(c, "::"))
return 0;
if ((co = strstr(c, "operator "))) {
if (co == c)
return 0;
}
while (*c) {
if ((*c == ':') && (*(c+1) == ':')) {
if ((*c == ':') && (*(c + 1) == ':')) {
break;
} else {
if (*c == '<') {
int level = 1;
c++;
while (*c && level) {
if (*c == '<') level++;
if (*c == '>') level--;
if (*c == '<')
level++;
if (*c == '>')
level--;
c++;
}
} else {
@ -742,11 +755,12 @@ Swig_scopename_suffix(String *s) {
}
}
if (*c && (c != tmp)) {
return NewString(c+2);
return NewString(c + 2);
} else {
return 0;
}
}
/* -----------------------------------------------------------------------------
* Swig_scopename_check()
*
@ -756,20 +770,24 @@ Swig_scopename_suffix(String *s) {
int Swig_scopename_check(String *s) {
char *c = Char(s);
char *co = 0;
if ((co = strstr(c,"operator "))) {
if (co == c) return 0;
if ((co = strstr(c, "operator "))) {
if (co == c)
return 0;
}
if (!strstr(c,"::")) return 0;
if (!strstr(c, "::"))
return 0;
while (*c) {
if ((*c == ':') && (*(c+1) == ':')) {
if ((*c == ':') && (*(c + 1) == ':')) {
return 1;
} else {
if (*c == '<') {
int level = 1;
c++;
while (*c && level) {
if (*c == '<') level++;
if (*c == '>') level--;
if (*c == '<')
level++;
if (*c == '>')
level--;
c++;
}
} else {
@ -809,15 +827,15 @@ String *Swig_string_command(String *s) {
#if defined(HAVE_POPEN)
if (Len(s)) {
char *command = Char(s);
FILE *fp = popen(command,"r");
FILE *fp = popen(command, "r");
if (fp) {
char buffer[1025];
while(fscanf(fp,"%1024s",buffer) != EOF) {
Append(res,buffer);
while (fscanf(fp, "%1024s", buffer) != EOF) {
Append(res, buffer);
}
pclose(fp);
} else {
Swig_error("SWIG",Getline(s), "Command encoder fails attempting '%s'.\n", s);
Swig_error("SWIG", Getline(s), "Command encoder fails attempting '%s'.\n", s);
exit(1);
}
}
@ -839,8 +857,7 @@ String *Swig_string_command(String *s) {
#define USE_RXSPENCER
#endif
const char *skip_delim(char pb, char pe, const char *ce)
{
const char *skip_delim(char pb, char pe, const char *ce) {
int end = 0;
int lb = 0;
while (!end && *ce != '\0') {
@ -872,45 +889,45 @@ String *Swig_string_rxspencer(String *s) {
int retval;
regex_t compiled;
cb = ++cs;
ce = skip_delim('[',']', cb);
ce = skip_delim('[', ']', cb);
if (ce) {
char bregexp[512];
strncpy(bregexp, cb, ce - cb);
bregexp[ce - cb] = '\0';
++ce;
retval = regcomp(&compiled, bregexp, REG_EXTENDED);
if(retval == 0) {
if (retval == 0) {
cs = ce;
if (*cs == '[') {
cb = ++cs;
ce = skip_delim('[',']', cb) ;
ce = skip_delim('[', ']', cb);
if (ce) {
const char *cvalue = ce + 1;
int nsub = (int) compiled.re_nsub+1;
regmatch_t *pmatch = (regmatch_t *)malloc(sizeof(regmatch_t)*(nsub));
retval = regexec(&compiled,cvalue,nsub,pmatch,0);
int nsub = (int) compiled.re_nsub + 1;
regmatch_t *pmatch = (regmatch_t *) malloc(sizeof(regmatch_t) * (nsub));
retval = regexec(&compiled, cvalue, nsub, pmatch, 0);
if (retval != REG_NOMATCH) {
char *spos = 0;
res = NewStringWithSize(cb, ce - cb);
spos = Strchr(res,'@');
spos = Strchr(res, '@');
while (spos) {
char cd = *(++spos);
if (isdigit(cd)) {
char arg[8];
size_t len;
int i = cd - '0';
sprintf(arg,"@%d", i);
sprintf(arg, "@%d", i);
if (i < nsub && (len = pmatch[i].rm_eo - pmatch[i].rm_so)) {
char value[256];
strncpy(value,cvalue + pmatch[i].rm_so, len);
strncpy(value, cvalue + pmatch[i].rm_so, len);
value[len] = 0;
Replaceall(res,arg,value);
Replaceall(res, arg, value);
} else {
Replaceall(res,arg,"");
Replaceall(res, arg, "");
}
spos = Strchr(res,'@');
spos = Strchr(res, '@');
} else if (cd == '@') {
spos = strchr(spos + 1,'@');
spos = strchr(spos + 1, '@');
}
}
}
@ -922,12 +939,13 @@ String *Swig_string_rxspencer(String *s) {
}
}
}
if (!res) res = NewStringEmpty();
if (!res)
res = NewStringEmpty();
return res;
}
#else
String *Swig_string_rxspencer(String *s) {
(void)s;
(void) s;
return NewStringEmpty();
}
#endif
@ -939,8 +957,7 @@ String *Swig_string_rxspencer(String *s) {
* Initialize the SWIG core
* ----------------------------------------------------------------------------- */
void
Swig_init() {
void Swig_init() {
/* Set some useful string encoding methods */
DohEncoding("escape", Swig_string_escape);
DohEncoding("upper", Swig_string_upper);
@ -949,7 +966,7 @@ Swig_init() {
DohEncoding("ctitle", Swig_string_ccase);
DohEncoding("lctitle", Swig_string_lccase);
DohEncoding("utitle", Swig_string_ucase);
DohEncoding("typecode",Swig_string_typecode);
DohEncoding("typecode", Swig_string_typecode);
DohEncoding("mangle", Swig_string_emangle);
DohEncoding("command", Swig_string_command);
DohEncoding("rxspencer", Swig_string_rxspencer);

File diff suppressed because it is too large Load Diff

View File

@ -20,13 +20,13 @@ char cvsroot_parms_c[] = "$Header$";
Parm *NewParm(SwigType *type, const String_or_char *name) {
Parm *p = NewHash();
Setattr(p,k_nodetype,k_parm);
Setattr(p, k_nodetype, k_parm);
if (type) {
SwigType *ntype = Copy(type);
Setattr(p,k_type,ntype);
Setattr(p, k_type, ntype);
Delete(ntype);
}
Setattr(p,k_name,name);
Setattr(p, k_name, name);
return p;
}
@ -42,7 +42,7 @@ Parm *NewParmFromNode(SwigType *type, const String_or_char *name, Node *n) {
Parm *p = NewParm(type, name);
Setfile(p, Getfile(n));
Setline(p, Getline(n));
return p;
}
@ -51,45 +51,45 @@ Parm *NewParmFromNode(SwigType *type, const String_or_char *name, Node *n) {
* ------------------------------------------------------------------------ */
Parm *CopyParm(Parm *p) {
Parm *np = NewHash();
SwigType *t = HashGetAttr(p,k_type);
String *name = HashGetAttr(p,k_name);
String *lname = HashGetAttr(p,k_lname);
String *value = HashGetAttr(p,k_value);
String *ignore = HashGetAttr(p,k_ignore);
String *alttype = HashGetAttr(p,k_alttype);
String *byname = HashGetAttr(p, k_argbyname);
String *compactdefargs = HashGetAttr(p, k_compactdefargs);
String *self = HashGetAttr(p, k_self);
Parm *np = NewHash();
SwigType *t = HashGetAttr(p, k_type);
String *name = HashGetAttr(p, k_name);
String *lname = HashGetAttr(p, k_lname);
String *value = HashGetAttr(p, k_value);
String *ignore = HashGetAttr(p, k_ignore);
String *alttype = HashGetAttr(p, k_alttype);
String *byname = HashGetAttr(p, k_argbyname);
String *compactdefargs = HashGetAttr(p, k_compactdefargs);
String *self = HashGetAttr(p, k_self);
if (t) {
SwigType *nt = Copy(t);
Setattr(np,k_type,nt);
Setattr(np, k_type, nt);
Delete(nt);
}
if (name) {
String *str = Copy(name);
Setattr(np,k_name,str);
Setattr(np, k_name, str);
Delete(str);
}
if (lname) {
String *str = Copy(lname);
Setattr(np,k_lname, str);
Setattr(np, k_lname, str);
Delete(str);
}
if (value) {
String *str = Copy(value);
Setattr(np,k_value, str);
Setattr(np, k_value, str);
Delete(str);
}
if (ignore) {
String *str = Copy(ignore);
Setattr(np,k_ignore, str);
Setattr(np, k_ignore, str);
Delete(str);
}
if (alttype) {
String *str = Copy(alttype);
Setattr(np,k_alttype, str);
Setattr(np, k_alttype, str);
Delete(str);
}
if (byname) {
@ -98,7 +98,7 @@ Parm *CopyParm(Parm *p) {
Delete(str);
}
if (compactdefargs) {
String *str = Copy(compactdefargs);
String *str = Copy(compactdefargs);
Setattr(np, k_compactdefargs, str);
Delete(str);
}
@ -107,9 +107,9 @@ Parm *CopyParm(Parm *p) {
Setattr(np, k_self, str);
Delete(str);
}
Setfile(np,Getfile(p));
Setline(np,Getline(p));
Setfile(np, Getfile(p));
Setline(np, Getline(p));
return np;
}
@ -118,19 +118,19 @@ Parm *CopyParm(Parm *p) {
* CopyParmList()
* ------------------------------------------------------------------ */
ParmList *
CopyParmList(ParmList *p) {
ParmList *CopyParmList(ParmList *p) {
Parm *np;
Parm *pp = 0;
Parm *fp = 0;
if (!p) return 0;
if (!p)
return 0;
while (p) {
np = CopyParm(p);
if (pp) {
set_nextSibling(pp,np);
Delete(np);
set_nextSibling(pp, np);
Delete(np);
} else {
fp = np;
}
@ -145,9 +145,10 @@ CopyParmList(ParmList *p) {
* ------------------------------------------------------------------ */
int ParmList_numarg(ParmList *p) {
int n = 0;
int n = 0;
while (p) {
if (!HashGetAttr(p,k_ignore)) n++;
if (!HashGetAttr(p, k_ignore))
n++;
p = nextSibling(p);
}
return n;
@ -160,11 +161,14 @@ int ParmList_numarg(ParmList *p) {
int ParmList_numrequired(ParmList *p) {
int i = 0;
while (p) {
SwigType *t = HashGetAttr(p,k_type);
String *value = HashGetAttr(p,k_value);
if (value) return i;
if (!(SwigType_type(t) == T_VOID)) i++;
else break;
SwigType *t = HashGetAttr(p, k_type);
String *value = HashGetAttr(p, k_value);
if (value)
return i;
if (!(SwigType_type(t) == T_VOID))
i++;
else
break;
p = nextSibling(p);
}
return i;
@ -191,12 +195,12 @@ int ParmList_len(ParmList *p) {
String *ParmList_str(ParmList *p) {
String *out = NewStringEmpty();
while(p) {
String *pstr = SwigType_str(HashGetAttr(p,k_type), HashGetAttr(p,k_name));
StringAppend(out,pstr);
while (p) {
String *pstr = SwigType_str(HashGetAttr(p, k_type), HashGetAttr(p, k_name));
StringAppend(out, pstr);
p = nextSibling(p);
if (p) {
StringAppend(out,",");
StringAppend(out, ",");
}
Delete(pstr);
}
@ -211,18 +215,18 @@ String *ParmList_str(ParmList *p) {
String *ParmList_str_defaultargs(ParmList *p) {
String *out = NewStringEmpty();
while(p) {
String *value = HashGetAttr(p,k_value);
String *pstr = SwigType_str(HashGetAttr(p,k_type), HashGetAttr(p,k_name));
StringAppend(out,pstr);
while (p) {
String *value = HashGetAttr(p, k_value);
String *pstr = SwigType_str(HashGetAttr(p, k_type), HashGetAttr(p, k_name));
StringAppend(out, pstr);
if (value) {
Printf(out,"=%s", value);
Printf(out, "=%s", value);
}
p = nextSibling(p);
if (p) {
StringAppend(out,",");
StringAppend(out, ",");
}
Delete(pstr);
Delete(pstr);
}
return out;
}
@ -235,15 +239,15 @@ String *ParmList_str_defaultargs(ParmList *p) {
String *ParmList_protostr(ParmList *p) {
String *out = NewStringEmpty();
while(p) {
if (HashGetAttr(p,k_hidden)) {
while (p) {
if (HashGetAttr(p, k_hidden)) {
p = nextSibling(p);
} else {
String *pstr = SwigType_str(HashGetAttr(p,k_type), 0);
StringAppend(out,pstr);
String *pstr = SwigType_str(HashGetAttr(p, k_type), 0);
StringAppend(out, pstr);
p = nextSibling(p);
if (p) {
StringAppend(out,",");
StringAppend(out, ",");
}
Delete(pstr);
}
@ -260,16 +264,16 @@ String *ParmList_protostr(ParmList *p) {
int ParmList_is_compactdefargs(ParmList *p) {
int compactdefargs = 0;
if (p) {
compactdefargs = HashGetAttr(p,k_compactdefargs) ? 1 : 0;
compactdefargs = HashGetAttr(p, k_compactdefargs) ? 1 : 0;
/* The "compactdefargs" attribute should only be set on the first parameter in the list.
* However, sometimes an extra parameter is inserted at the beginning of the parameter list,
* so we check the 2nd parameter too. */
if (!compactdefargs) {
Parm *nextparm = nextSibling(p);
compactdefargs = (nextparm && HashGetAttr(nextparm,k_compactdefargs)) ? 1 : 0;
compactdefargs = (nextparm && HashGetAttr(nextparm, k_compactdefargs)) ? 1 : 0;
}
}
@ -285,15 +289,15 @@ int ParmList_is_compactdefargs(ParmList *p) {
* ---------------------------------------------------------------------- */
int ParmList_has_defaultargs(ParmList *p) {
int default_args = 0;
while (p) {
if (HashGetAttr(p, k_value)) {
default_args = 1;
break;
}
p = nextSibling(p);
int default_args = 0;
while (p) {
if (HashGetAttr(p, k_value)) {
default_args = 1;
break;
}
return default_args;
p = nextSibling(p);
}
return default_args;
}
/* ---------------------------------------------------------------------
@ -304,14 +308,14 @@ int ParmList_has_defaultargs(ParmList *p) {
* ---------------------------------------------------------------------- */
ParmList *ParmList_copy_all_except_last_parm(ParmList *p) {
ParmList* newparms = 0;
ParmList *newparms = 0;
Parm *newparm = 0;
Parm *pp = 0;
Parm *fp = 0;
while (nextSibling(p)) {
newparm = CopyParm(p);
if (pp) {
set_nextSibling(pp,newparm);
set_nextSibling(pp, newparm);
Delete(newparm);
} else {
fp = newparm;

File diff suppressed because it is too large Load Diff

View File

@ -86,7 +86,7 @@ char cvsroot_stype_c[] = "$Header$";
SwigType *NewSwigType(int t) {
switch(t) {
switch (t) {
case T_BOOL:
return NewString("bool");
break;
@ -102,7 +102,7 @@ SwigType *NewSwigType(int t) {
case T_USHORT:
return NewString("unsigned short");
break;
case T_LONG:
case T_LONG:
return NewString("long");
break;
case T_ULONG:
@ -126,12 +126,12 @@ SwigType *NewSwigType(int t) {
case T_UCHAR:
return NewString("unsigned char");
break;
case T_STRING: {
SwigType *t = NewString("char");
SwigType_add_pointer(t);
return t;
break;
}
case T_STRING:{
SwigType *t = NewString("char");
SwigType_add_pointer(t);
return t;
break;
}
case T_LONGLONG:
return NewString("long long");
break;
@ -141,7 +141,7 @@ SwigType *NewSwigType(int t) {
case T_VOID:
return NewString("void");
break;
default :
default:
break;
}
return NewStringEmpty();
@ -153,17 +153,18 @@ SwigType *NewSwigType(int t) {
* Push a type constructor onto the type
* ----------------------------------------------------------------------------- */
void SwigType_push(SwigType *t, String *cons)
{
if (!cons) return;
if (!Len(cons)) return;
void SwigType_push(SwigType *t, String *cons) {
if (!cons)
return;
if (!Len(cons))
return;
if (Len(t)) {
char *c = Char(cons);
if (c[strlen(c)-1] != '.')
Insert(t,0,".");
if (c[strlen(c) - 1] != '.')
Insert(t, 0, ".");
}
Insert(t,0,cons);
Insert(t, 0, cons);
}
/* -----------------------------------------------------------------------------
@ -178,36 +179,39 @@ void SwigType_push(SwigType *t, String *cons)
* ----------------------------------------------------------------------------- */
int SwigType_ispointer_return(SwigType *t) {
char* c;
char *c;
int idx;
if (!t) return 0;
if (!t)
return 0;
c = Char(t);
idx = strlen(c)-4;
idx = strlen(c) - 4;
if (idx >= 0) {
return (strcmp(c+idx, ").p.") == 0);
return (strcmp(c + idx, ").p.") == 0);
}
return 0;
}
int SwigType_isreference_return(SwigType *t) {
char* c;
char *c;
int idx;
if (!t) return 0;
if (!t)
return 0;
c = Char(t);
idx = strlen(c)-4;
idx = strlen(c) - 4;
if (idx >= 0) {
return (strcmp(c+idx, ").r.") == 0);
return (strcmp(c + idx, ").r.") == 0);
}
return 0;
}
int SwigType_isconst(SwigType *t) {
char *c;
if (!t) return 0;
if (!t)
return 0;
c = Char(t);
if (strncmp(c,"q(",2) == 0) {
if (strncmp(c, "q(", 2) == 0) {
String *q = SwigType_parm(t);
if (strstr(Char(q),"const")) {
if (strstr(Char(q), "const")) {
Delete(q);
return 1;
}
@ -239,8 +243,9 @@ int SwigType_ismutable(SwigType *t) {
int SwigType_isenum(SwigType *t) {
char *c = Char(t);
if (!t) return 0;
if (strncmp(c,"enum ",5) == 0) {
if (!t)
return 0;
if (strncmp(c, "enum ", 5) == 0) {
return 1;
}
return 0;
@ -248,19 +253,23 @@ int SwigType_isenum(SwigType *t) {
int SwigType_issimple(SwigType *t) {
char *c = Char(t);
if (!t) return 0;
if (!t)
return 0;
while (*c) {
if (*c == '<') {
int nest = 1;
c++;
while (*c && nest) {
if (*c == '<') nest++;
if (*c == '>') nest--;
if (*c == '<')
nest++;
if (*c == '>')
nest--;
c++;
}
c--;
}
if (*c == '.') return 0;
if (*c == '.')
return 0;
c++;
}
return 1;
@ -319,14 +328,13 @@ static Hash *default_cache = 0;
p.SWIGTYPE -> SWIGTYPE
*/
static
void SwigType_add_default(String *def, SwigType *nr)
{
if (Strcmp(nr,"SWIGTYPE") == 0) {
StringAppend(def,"SWIGTYPE");
static
void SwigType_add_default(String *def, SwigType *nr) {
if (Strcmp(nr, "SWIGTYPE") == 0) {
StringAppend(def, "SWIGTYPE");
} else {
String *q = SwigType_isqualifier(nr) ? SwigType_pop(nr) : 0;
if (q && strstr(Char(nr),"SWIGTYPE")) {
if (q && strstr(Char(nr), "SWIGTYPE")) {
StringAppend(def, nr);
} else {
String *nd = SwigType_default(nr);
@ -334,17 +342,17 @@ void SwigType_add_default(String *def, SwigType *nr)
String *bdef = nd;
if (q) {
bdef = NewStringf("%s%s", q, nd);
if ((Strcmp(nr,bdef) == 0)) {
if ((Strcmp(nr, bdef) == 0)) {
Delete(bdef);
bdef = nd;
} else {
Delete(nd);
}
}
StringAppend(def,bdef);
StringAppend(def, bdef);
Delete(bdef);
} else {
StringAppend(def,nr);
StringAppend(def, nr);
}
}
Delete(q);
@ -358,28 +366,31 @@ SwigType *SwigType_default(SwigType *t) {
char *cr;
#ifdef SWIG_DEFAULT_CACHE
if (!default_cache) default_cache = NewHash();
r = Getattr(default_cache,t);
if (!default_cache)
default_cache = NewHash();
r = Getattr(default_cache, t);
if (r) {
return Copy(r);
}
#endif
if (SwigType_isvarargs(t)) {
return 0;
}
r = t;
while ((r1 = SwigType_typedef_resolve(r))) {
if (r != t) Delete(r);
if (r != t)
Delete(r);
r = r1;
}
if (SwigType_isqualifier(r)) {
String *q;
if (r == t) r = Copy(t);
if (r == t)
r = Copy(t);
q = SwigType_pop(r);
if (strstr(Char(r),"SWIGTYPE")) {
if (strstr(Char(r), "SWIGTYPE")) {
Delete(q);
def = r;
return def;
@ -387,20 +398,19 @@ SwigType *SwigType_default(SwigType *t) {
Delete(q);
}
cr = Char(r);
if (strcmp(cr,"p.SWIGTYPE") == 0) {
if (strcmp(cr, "p.SWIGTYPE") == 0) {
def = NewString("SWIGTYPE");
} else if (SwigType_ispointer(r)) {
#ifdef SWIG_NEW_TYPE_DEFAULT
SwigType *nr = Copy(r);
SwigType_del_pointer(nr);
def = SwigType_isfunction(nr) ?
NewStringEmpty() : NewString("p.");
def = SwigType_isfunction(nr) ? NewStringEmpty() : NewString("p.");
SwigType_add_default(def, nr);
Delete(nr);
#else
def = NewString("p.SWIGTYPE");
#endif
} else if (strcmp(cr,"r.SWIGTYPE") == 0) {
} else if (strcmp(cr, "r.SWIGTYPE") == 0) {
def = NewString("SWIGTYPE");
} else if (SwigType_isreference(r)) {
#ifdef SWIG_NEW_TYPE_DEFAULT
@ -413,19 +423,19 @@ SwigType *SwigType_default(SwigType *t) {
def = NewString("r.SWIGTYPE");
#endif
} else if (SwigType_isarray(r)) {
if (strcmp(cr,"a().SWIGTYPE") == 0) {
if (strcmp(cr, "a().SWIGTYPE") == 0) {
def = NewString("p.SWIGTYPE");
} else if (strcmp(cr,"a(ANY).SWIGTYPE") == 0) {
} else if (strcmp(cr, "a(ANY).SWIGTYPE") == 0) {
def = NewString("a().SWIGTYPE");
} else {
int i, empty = 0;
int ndim = SwigType_array_ndim(r);
SwigType *nr = Copy(r);
for (i = 0; i < ndim; i++) {
String *dim = SwigType_array_getdim(r,i);
String *dim = SwigType_array_getdim(r, i);
if (!Len(dim)) {
char *c = Char(nr);
empty = strstr(c,"a(ANY).") != c;
empty = strstr(c, "a(ANY).") != c;
}
Delete(dim);
}
@ -438,24 +448,24 @@ SwigType *SwigType_default(SwigType *t) {
SwigType_del_array(nr);
SwigType_add_default(def, nr);
#else
StringAppend(def,"SWIGTYPE");
StringAppend(def, "SWIGTYPE");
#endif
Delete(nr);
}
} else if (SwigType_ismemberpointer(r)) {
if (strcmp(cr,"m(CLASS).SWIGTYPE") == 0) {
if (strcmp(cr, "m(CLASS).SWIGTYPE") == 0) {
def = NewString("p.SWIGTYPE");
} else {
def = NewString("m(CLASS).SWIGTYPE");
}
} else if (SwigType_isenum(r)) {
if (strcmp(cr,"enum SWIGTYPE") == 0) {
if (strcmp(cr, "enum SWIGTYPE") == 0) {
def = NewString("SWIGTYPE");
} else {
def = NewString("enum SWIGTYPE");
}
} else if (SwigType_isfunction(r)) {
if (strcmp(cr,"f(ANY).SWIGTYPE") == 0) {
if (strcmp(cr, "f(ANY).SWIGTYPE") == 0) {
def = NewString("p.SWIGTYPE");
} else {
def = NewString("p.f(ANY).SWIGTYPE");
@ -463,17 +473,17 @@ SwigType *SwigType_default(SwigType *t) {
} else {
def = NewString("SWIGTYPE");
}
if (r != t) Delete(r);
if (StringEqual(def,t)) {
if (r != t)
Delete(r);
if (StringEqual(def, t)) {
Delete(def);
def = 0;
}
#ifdef SWIG_DEFAULT_CACHE
/* The cache produces strange results, see enum_template.i case */
if (def) {
String *cdef = Copy(def);
Setattr(default_cache,t, cdef);
String *cdef = Copy(def);
Setattr(default_cache, t, cdef);
Delete(cdef);
}
#endif
@ -489,35 +499,38 @@ SwigType *SwigType_default(SwigType *t) {
* Returns a string of the base type. Takes care of template expansions
* ----------------------------------------------------------------------------- */
String *
SwigType_namestr(const SwigType *t) {
String *SwigType_namestr(const SwigType *t) {
String *r;
String *suffix;
List *p;
int i, sz;
char *d = Char(t);
char *c = strstr(d,"<(");
List *p;
int i, sz;
char *d = Char(t);
char *c = strstr(d, "<(");
if (!c || !strstr(c+2,")>")) return NewString(t);
if (!c || !strstr(c + 2, ")>"))
return NewString(t);
r = NewStringWithSize(d, c - d);
if (*(c - 1) == '<') Putc(' ',r);
Putc('<',r);
p = SwigType_parmlist(c+1);
if (*(c - 1) == '<')
Putc(' ', r);
Putc('<', r);
p = SwigType_parmlist(c + 1);
sz = Len(p);
for (i = 0; i < sz; i++) {
String *str = SwigType_str(Getitem(p,i),0);
String *str = SwigType_str(Getitem(p, i), 0);
/* Avoid creating a <: token, which is the same as [ in C++. */
if (i == 0 && Len(str) && *Char(str) == ':') Putc(' ', r);
StringAppend(r,str);
if ((i+1) < sz) Putc(',',r);
if (i == 0 && Len(str) && *Char(str) == ':')
Putc(' ', r);
StringAppend(r, str);
if ((i + 1) < sz)
Putc(',', r);
Delete(str);
}
Putc(' ',r);
Putc('>',r);
Putc(' ', r);
Putc('>', r);
suffix = SwigType_templatesuffix(t);
StringAppend(r,suffix);
StringAppend(r, suffix);
Delete(suffix);
Delete(p);
return r;
@ -529,9 +542,7 @@ SwigType_namestr(const SwigType *t) {
* Create a C string representation of a datatype.
* ----------------------------------------------------------------------------- */
String *
SwigType_str(SwigType *s, const String_or_char *id)
{
String *SwigType_str(SwigType *s, const String_or_char *id) {
String *result;
String *element = 0, *nextelement;
List *elements;
@ -547,71 +558,71 @@ SwigType_str(SwigType *s, const String_or_char *id)
nelements = Len(elements);
if (nelements > 0) {
element = Getitem(elements,0);
element = Getitem(elements, 0);
}
/* Now, walk the type list and start emitting */
for (i = 0; i < nelements; i++) {
if (i < (nelements - 1)) {
nextelement = Getitem(elements,i+1);
nextelement = Getitem(elements, i + 1);
} else {
nextelement = 0;
}
if (SwigType_isqualifier(element)) {
DOH *q = 0;
q = SwigType_parm(element);
Insert(result,0," ");
Insert(result,0,q);
Insert(result, 0, " ");
Insert(result, 0, q);
Delete(q);
} else if (SwigType_ispointer(element)) {
Insert(result,0,"*");
Insert(result, 0, "*");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
Insert(result,0,"(");
StringAppend(result,")");
Insert(result, 0, "(");
StringAppend(result, ")");
}
} else if (SwigType_ismemberpointer(element)) {
String *q;
q = SwigType_parm(element);
Insert(result,0,"::*");
Insert(result,0,q);
Insert(result, 0, "::*");
Insert(result, 0, q);
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
Insert(result,0,"(");
StringAppend(result,")");
Insert(result, 0, "(");
StringAppend(result, ")");
}
Delete(q);
}
else if (SwigType_isreference(element)) {
Insert(result,0,"&");
} else if (SwigType_isreference(element)) {
Insert(result, 0, "&");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
Insert(result,0,"(");
StringAppend(result,")");
Insert(result, 0, "(");
StringAppend(result, ")");
}
} else if (SwigType_isarray(element)) {
} else if (SwigType_isarray(element)) {
DOH *size;
StringAppend(result,"[");
StringAppend(result, "[");
size = SwigType_parm(element);
StringAppend(result,size);
StringAppend(result,"]");
StringAppend(result, size);
StringAppend(result, "]");
Delete(size);
} else if (SwigType_isfunction(element)) {
DOH *parms, *p;
int j, plen;
StringAppend(result,"(");
StringAppend(result, "(");
parms = SwigType_parmlist(element);
plen = Len(parms);
for (j = 0; j < plen; j++) {
p = SwigType_str(Getitem(parms,j),0);
StringAppend(result,p);
if (j < (plen-1)) StringAppend(result,",");
p = SwigType_str(Getitem(parms, j), 0);
StringAppend(result, p);
if (j < (plen - 1))
StringAppend(result, ",");
}
StringAppend(result,")");
StringAppend(result, ")");
Delete(parms);
} else {
if (strcmp(Char(element),"v(...)") == 0) {
Insert(result,0,"...");
if (strcmp(Char(element), "v(...)") == 0) {
Insert(result, 0, "...");
} else {
String *bs = SwigType_namestr(element);
Insert(result,0," ");
Insert(result,0,bs);
Insert(result, 0, " ");
Insert(result, 0, bs);
Delete(bs);
}
}
@ -628,8 +639,7 @@ SwigType_str(SwigType *s, const String_or_char *id)
* Create a locally assignable type
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_ltype(SwigType *s) {
SwigType *SwigType_ltype(SwigType *s) {
String *result;
String *element;
SwigType *td, *tc = 0;
@ -646,9 +656,9 @@ SwigType_ltype(SwigType *s) {
}
if (SwigType_issimple(tc)) {
/* Resolve any typedef definitions */
SwigType *tt = Copy(tc);
SwigType *tt = Copy(tc);
td = 0;
while ((td = SwigType_typedef_resolve(tt))) {
while ((td = SwigType_typedef_resolve(tt))) {
if (td && (SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) {
/* We need to use the typedef type */
Delete(tt);
@ -661,7 +671,7 @@ SwigType_ltype(SwigType *s) {
}
if (td) {
Delete(tc);
tc = td;
tc = td;
}
}
elements = SwigType_split(tc);
@ -669,7 +679,7 @@ SwigType_ltype(SwigType *s) {
/* Now, walk the type list and start emitting */
for (i = 0; i < nelements; i++) {
element = Getitem(elements,i);
element = Getitem(elements, i);
/* when we see a function, we need to preserve the following types */
if (SwigType_isfunction(element)) {
notypeconv = 1;
@ -677,34 +687,34 @@ SwigType_ltype(SwigType *s) {
if (SwigType_isqualifier(element)) {
/* Do nothing. Ignore */
} else if (SwigType_ispointer(element)) {
StringAppend(result,element);
StringAppend(result, element);
firstarray = 0;
} else if (SwigType_ismemberpointer(element)) {
StringAppend(result,element);
StringAppend(result, element);
firstarray = 0;
} else if (SwigType_isreference(element)) {
if (notypeconv) {
StringAppend(result,element);
StringAppend(result, element);
} else {
StringAppend(result,"p.");
StringAppend(result, "p.");
}
firstarray = 0;
} else if (SwigType_isarray(element) && firstarray) {
if (notypeconv) {
StringAppend(result,element);
StringAppend(result, element);
} else {
StringAppend(result,"p.");
StringAppend(result, "p.");
}
firstarray = 0;
} else if (SwigType_isenum(element)) {
int anonymous_enum = (Cmp(element,"enum ") == 0);
int anonymous_enum = (Cmp(element, "enum ") == 0);
if (notypeconv || !anonymous_enum) {
StringAppend(result,element);
StringAppend(result, element);
} else {
StringAppend(result,"int");
StringAppend(result, "int");
}
} else {
StringAppend(result,element);
StringAppend(result, element);
}
}
Delete(elements);
@ -727,14 +737,12 @@ SwigType_ltype(SwigType *s) {
* with an equivalent assignable version.
* -------------------------------------------------------------------- */
String *
SwigType_lstr(SwigType *s, const String_or_char *id)
{
String *SwigType_lstr(SwigType *s, const String_or_char *id) {
String *result;
SwigType *tc;
SwigType *tc;
tc = SwigType_ltype(s);
result = SwigType_str(tc,id);
result = SwigType_str(tc, id);
Delete(tc);
return result;
}
@ -751,11 +759,11 @@ String *SwigType_rcaststr(SwigType *s, const String_or_char *name) {
String *element = 0, *nextelement;
SwigType *td, *rs, *tc = 0;
List *elements;
int nelements, i;
int clear = 1;
int firstarray = 1;
int isreference = 0;
int isarray = 0;
int nelements, i;
int clear = 1;
int firstarray = 1;
int isreference = 0;
int isarray = 0;
result = NewStringEmpty();
@ -772,70 +780,70 @@ String *SwigType_rcaststr(SwigType *s, const String_or_char *name) {
} else {
td = SwigType_typedef_resolve(rs);
}
if (td) {
if ((SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) {
elements = SwigType_split(td);
} else {
elements = SwigType_split(rs);
}
}
Delete(td);
} else {
elements = SwigType_split(rs);
}
nelements = Len(elements);
if (nelements > 0) {
element = Getitem(elements,0);
element = Getitem(elements, 0);
}
/* Now, walk the type list and start emitting */
for (i = 0; i < nelements; i++) {
if (i < (nelements - 1)) {
nextelement = Getitem(elements,i+1);
nextelement = Getitem(elements, i + 1);
} else {
nextelement = 0;
}
if (SwigType_isqualifier(element)) {
DOH *q = 0;
q = SwigType_parm(element);
Insert(result,0," ");
Insert(result,0,q);
Insert(result, 0, " ");
Insert(result, 0, q);
Delete(q);
clear = 0;
} else if (SwigType_ispointer(element)) {
Insert(result,0,"*");
Insert(result, 0, "*");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
Insert(result,0,"(");
StringAppend(result,")");
Insert(result, 0, "(");
StringAppend(result, ")");
}
firstarray = 0;
} else if (SwigType_ismemberpointer(element)) {
} else if (SwigType_ismemberpointer(element)) {
String *q;
Insert(result,0,"::*");
Insert(result, 0, "::*");
q = SwigType_parm(element);
Insert(result,0,q);
Insert(result, 0, q);
Delete(q);
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
Insert(result,0,"(");
StringAppend(result,")");
Insert(result, 0, "(");
StringAppend(result, ")");
}
firstarray = 0;
} else if (SwigType_isreference(element)) {
Insert(result,0,"&");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
Insert(result,0,"(");
StringAppend(result,")");
}
isreference = 1;
Insert(result, 0, "&");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
Insert(result, 0, "(");
StringAppend(result, ")");
}
isreference = 1;
} else if (SwigType_isarray(element)) {
DOH *size;
if (firstarray && !isreference) {
StringAppend(result,"(*)");
StringAppend(result, "(*)");
firstarray = 0;
} else {
StringAppend(result,"[");
StringAppend(result, "[");
size = SwigType_parm(element);
StringAppend(result,size);
StringAppend(result,"]");
StringAppend(result, size);
StringAppend(result, "]");
Delete(size);
clear = 0;
}
@ -843,21 +851,22 @@ String *SwigType_rcaststr(SwigType *s, const String_or_char *name) {
} else if (SwigType_isfunction(element)) {
DOH *parms, *p;
int j, plen;
StringAppend(result,"(");
StringAppend(result, "(");
parms = SwigType_parmlist(element);
plen = Len(parms);
for (j = 0; j < plen; j++) {
p = SwigType_str(Getitem(parms,j),0);
StringAppend(result,p);
p = SwigType_str(Getitem(parms, j), 0);
StringAppend(result, p);
Delete(p);
if (j < (plen-1)) StringAppend(result,",");
if (j < (plen - 1))
StringAppend(result, ",");
}
StringAppend(result,")");
StringAppend(result, ")");
Delete(parms);
} else {
String *bs = SwigType_namestr(element);
Insert(result,0," ");
Insert(result,0,bs);
Insert(result, 0, " ");
Insert(result, 0, bs);
Delete(bs);
}
element = nextelement;
@ -866,14 +875,15 @@ String *SwigType_rcaststr(SwigType *s, const String_or_char *name) {
if (clear) {
cast = NewStringEmpty();
} else {
cast = NewStringf("(%s)",result);
cast = NewStringf("(%s)", result);
}
if (name) {
if (isreference) {
if (isarray) Clear(cast);
StringAppend(cast,"*");
if (isarray)
Clear(cast);
StringAppend(cast, "*");
}
StringAppend(cast,name);
StringAppend(cast, name);
}
Delete(result);
Delete(tc);
@ -893,22 +903,22 @@ String *SwigType_lcaststr(SwigType *s, const String_or_char *name) {
result = NewStringEmpty();
if (SwigType_isarray(s)) {
String *lstr = SwigType_lstr(s,0);
Printf(result,"(%s)%s", lstr,name);
String *lstr = SwigType_lstr(s, 0);
Printf(result, "(%s)%s", lstr, name);
Delete(lstr);
} else if (SwigType_isreference(s)) {
String *str = SwigType_str(s,0);
Printf(result,"(%s)", str);
String *str = SwigType_str(s, 0);
Printf(result, "(%s)", str);
Delete(str);
if (name)
StringAppend(result,name);
if (name)
StringAppend(result, name);
} else if (SwigType_isqualifier(s)) {
String *lstr = SwigType_lstr(s,0);
Printf(result,"(%s)%s", lstr,name);
String *lstr = SwigType_lstr(s, 0);
Printf(result, "(%s)%s", lstr, name);
Delete(lstr);
} else {
if (name)
StringAppend(result,name);
StringAppend(result, name);
}
return result;
}
@ -922,11 +932,11 @@ String *SwigType_manglestr_default(SwigType *s) {
SwigType *lt;
SwigType *sr = SwigType_typedef_qualified(s);
SwigType *ss = SwigType_typedef_resolve_all(sr);
s = ss;
if (SwigType_istemplate(ss)) {
SwigType *ty = Swig_symbol_template_deftype(ss,0);
SwigType *ty = Swig_symbol_template_deftype(ss, 0);
Delete(ss);
ss = ty;
s = ss;
@ -939,7 +949,8 @@ String *SwigType_manglestr_default(SwigType *s) {
c = Char(result);
while (*c) {
if (!isalnum((int)*c)) *c = '_';
if (!isalnum((int) *c))
*c = '_';
c++;
}
if (SwigType_istemplate(base)) {
@ -948,29 +959,39 @@ String *SwigType_manglestr_default(SwigType *s) {
base = b;
}
Replace(base,"struct ","", DOH_REPLACE_ANY); /* This might be problematic */
Replace(base,"class ","", DOH_REPLACE_ANY);
Replace(base,"union ","", DOH_REPLACE_ANY);
Replace(base,"enum ","", DOH_REPLACE_ANY);
Replace(base, "struct ", "", DOH_REPLACE_ANY); /* This might be problematic */
Replace(base, "class ", "", DOH_REPLACE_ANY);
Replace(base, "union ", "", DOH_REPLACE_ANY);
Replace(base, "enum ", "", DOH_REPLACE_ANY);
c = Char(base);
while (*c) {
if (*c == '<') *c = 'T';
else if (*c == '>') *c = 't';
else if (*c == '*') *c = 'p';
else if (*c == '[') *c = 'a';
else if (*c == ']') *c = 'A';
else if (*c == '&') *c = 'R';
else if (*c == '(') *c = 'f';
else if (*c == ')') *c = 'F';
else if (!isalnum((int)*c)) *c = '_';
if (*c == '<')
*c = 'T';
else if (*c == '>')
*c = 't';
else if (*c == '*')
*c = 'p';
else if (*c == '[')
*c = 'a';
else if (*c == ']')
*c = 'A';
else if (*c == '&')
*c = 'R';
else if (*c == '(')
*c = 'f';
else if (*c == ')')
*c = 'F';
else if (!isalnum((int) *c))
*c = '_';
c++;
}
StringAppend(result,base);
Insert(result,0,"_");
StringAppend(result, base);
Insert(result, 0, "_");
Delete(lt);
Delete(base);
if (ss) Delete(ss);
if (ss)
Delete(ss);
return result;
}
@ -984,51 +1005,52 @@ String *SwigType_manglestr(SwigType *s) {
* Replaces a typename in a type with something else. Needed for templates.
* ----------------------------------------------------------------------------- */
void
SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
void SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
String *nt;
int i, ilen;
List *elem;
int i, ilen;
List *elem;
if (!Strstr(t,pat)) return;
if (!Strstr(t, pat))
return;
if (StringEqual(t,pat)) {
Replace(t,pat,rep,DOH_REPLACE_ANY);
if (StringEqual(t, pat)) {
Replace(t, pat, rep, DOH_REPLACE_ANY);
return;
}
nt = NewStringEmpty();
elem = SwigType_split(t);
ilen = Len(elem);
for (i = 0; i < ilen; i++) {
String *e = Getitem(elem,i);
String *e = Getitem(elem, i);
if (SwigType_issimple(e)) {
if (StringEqual(e,pat)) {
if (StringEqual(e, pat)) {
/* Replaces a type of the form 'pat' with 'rep<args>' */
Replace(e,pat,rep,DOH_REPLACE_ANY);
Replace(e, pat, rep, DOH_REPLACE_ANY);
} else if (SwigType_istemplate(e)) {
/* Replaces a type of the form 'pat<args>' with 'rep' */
if (StringEqual(e,pat)) {
/* Replaces a type of the form 'pat<args>' with 'rep' */
if (StringEqual(e, pat)) {
String *repbase = SwigType_templateprefix(rep);
Replace(e,pat,repbase,DOH_REPLACE_ID | DOH_REPLACE_FIRST);
Replace(e, pat, repbase, DOH_REPLACE_ID | DOH_REPLACE_FIRST);
Delete(repbase);
}
}
{
String *tsuffix;
List *tparms = SwigType_parmlist(e);
int j, jlen;
String *nt = SwigType_templateprefix(e);
StringAppend(nt,"<(");
StringAppend(nt, "<(");
jlen = Len(tparms);
for (j = 0; j < jlen; j++) {
SwigType_typename_replace(Getitem(tparms,j), pat, rep);
StringAppend(nt,Getitem(tparms,j));
if (j < (jlen-1)) Putc(',',nt);
SwigType_typename_replace(Getitem(tparms, j), pat, rep);
StringAppend(nt, Getitem(tparms, j));
if (j < (jlen - 1))
Putc(',', nt);
}
tsuffix = SwigType_templatesuffix(e);
Printf(nt,")>%s", tsuffix);
Printf(nt, ")>%s", tsuffix);
Delete(tsuffix);
Clear(e);
StringAppend(e,nt);
StringAppend(e, nt);
Delete(nt);
Delete(tparms);
}
@ -1036,10 +1058,10 @@ SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
String *first, *rest;
first = Swig_scopename_first(e);
rest = Swig_scopename_suffix(e);
SwigType_typename_replace(rest,pat,rep);
SwigType_typename_replace(first,pat,rep);
SwigType_typename_replace(rest, pat, rep);
SwigType_typename_replace(first, pat, rep);
Clear(e);
Printv(e,first,"::",rest,NIL);
Printv(e, first, "::", rest, NIL);
Delete(first);
Delete(rest);
}
@ -1047,22 +1069,23 @@ SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
int j, jlen;
List *fparms = SwigType_parmlist(e);
Clear(e);
StringAppend(e,"f(");
StringAppend(e, "f(");
jlen = Len(fparms);
for (j = 0; j < jlen; j++) {
SwigType_typename_replace(Getitem(fparms,j), pat, rep);
StringAppend(e,Getitem(fparms,j));
if (j < (jlen-1)) Putc(',',e);
SwigType_typename_replace(Getitem(fparms, j), pat, rep);
StringAppend(e, Getitem(fparms, j));
if (j < (jlen - 1))
Putc(',', e);
}
StringAppend(e,").");
StringAppend(e, ").");
Delete(fparms);
} else if (SwigType_isarray(e)) {
Replace(e,pat,rep, DOH_REPLACE_ID);
Replace(e, pat, rep, DOH_REPLACE_ID);
}
StringAppend(nt,e);
StringAppend(nt, e);
}
Clear(t);
StringAppend(t,nt);
StringAppend(t, nt);
Delete(nt);
Delete(elem);
}
@ -1073,14 +1096,13 @@ SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
* Checks type declarators for a match
* ----------------------------------------------------------------------------- */
int
SwigType_check_decl(SwigType *ty, const SwigType *decl) {
SwigType *t,*t1,*t2;
int SwigType_check_decl(SwigType *ty, const SwigType *decl) {
SwigType *t, *t1, *t2;
int r;
t = SwigType_typedef_resolve_all(ty);
t1 = SwigType_strip_qualifiers(t);
t2 = SwigType_prefix(t1);
r = Equal(t2,decl);
r = Equal(t2, decl);
Delete(t);
Delete(t1);
Delete(t2);

View File

@ -35,17 +35,17 @@ extern "C" {
/* Short names for common data types */
typedef DOH String;
typedef DOH Hash;
typedef DOH List;
typedef DOH String_or_char;
typedef DOH File;
typedef DOH Parm;
typedef DOH ParmList;
typedef DOH Node;
typedef DOH Symtab;
typedef DOH Typetab;
typedef DOH SwigType;
typedef DOH String;
typedef DOH Hash;
typedef DOH List;
typedef DOH String_or_char;
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 --- */
@ -94,28 +94,28 @@ typedef DOH SwigType;
/* --- File interface --- */
extern List *Swig_add_directory(const String_or_char *dirname);
extern void Swig_push_directory(const String_or_char *dirname);
extern void Swig_pop_directory();
extern String *Swig_last_file();
extern List *Swig_search_path();
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 String *Swig_include_sys(const String_or_char *name);
extern int Swig_insert_file(const String_or_char *name, File *outfile);
extern void Swig_set_config_file(const String_or_char *filename);
extern String *Swig_get_config_file(void);
extern void Swig_set_push_dir(int dopush);
extern int Swig_get_push_dir(void);
extern void Swig_swiglib_set(const String_or_char *);
extern String *Swig_swiglib_get();
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);
extern List *Swig_add_directory(const String_or_char *dirname);
extern void Swig_push_directory(const String_or_char *dirname);
extern void Swig_pop_directory();
extern String *Swig_last_file();
extern List *Swig_search_path();
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 String *Swig_include_sys(const String_or_char *name);
extern int Swig_insert_file(const String_or_char *name, File *outfile);
extern void Swig_set_config_file(const String_or_char *filename);
extern String *Swig_get_config_file(void);
extern void Swig_set_push_dir(int dopush);
extern int Swig_get_push_dir(void);
extern void Swig_swiglib_set(const String_or_char *);
extern String *Swig_swiglib_get();
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);
#if defined(MACSWIG)
# define SWIG_FILE_DELIMETER ":"
@ -127,32 +127,32 @@ extern char *Swig_file_dirname(const String_or_char *filename);
/* --- Command line parsing --- */
extern void Swig_init_args(int argc, char **argv);
extern void Swig_mark_arg(int n);
extern int Swig_check_marked(int n);
extern void Swig_check_options(int check_input);
extern void Swig_arg_error();
extern void Swig_init_args(int argc, char **argv);
extern void Swig_mark_arg(int n);
extern int Swig_check_marked(int n);
extern void Swig_check_options(int check_input);
extern void Swig_arg_error();
/* --- Scanner Interface --- */
typedef struct SwigScanner SwigScanner;
typedef struct SwigScanner SwigScanner;
extern SwigScanner *NewSwigScanner();
extern void DelSwigScanner(SwigScanner *);
extern void SwigScanner_clear(SwigScanner *);
extern void SwigScanner_push(SwigScanner *, String *);
extern void SwigScanner_pushtoken(SwigScanner *, int);
extern int SwigScanner_token(SwigScanner *);
extern String *SwigScanner_text(SwigScanner *);
extern void SwigScanner_skip_line(SwigScanner *);
extern int SwigScanner_skip_balanced(SwigScanner *, int startchar, int endchar);
extern void SwigScanner_set_location(SwigScanner *, String *file, int line);
extern String *SwigScanner_get_file(SwigScanner *);
extern int SwigScanner_get_line(SwigScanner *);
extern void SwigScanner_idstart(SwigScanner *, char *idchar);
extern SwigScanner *NewSwigScanner();
extern void DelSwigScanner(SwigScanner *);
extern void SwigScanner_clear(SwigScanner *);
extern void SwigScanner_push(SwigScanner *, String *);
extern void SwigScanner_pushtoken(SwigScanner *, int);
extern int SwigScanner_token(SwigScanner *);
extern String *SwigScanner_text(SwigScanner *);
extern void SwigScanner_skip_line(SwigScanner *);
extern int SwigScanner_skip_balanced(SwigScanner *, int startchar, int endchar);
extern void SwigScanner_set_location(SwigScanner *, String *file, int line);
extern String *SwigScanner_get_file(SwigScanner *);
extern int SwigScanner_get_line(SwigScanner *);
extern void SwigScanner_idstart(SwigScanner *, char *idchar);
#define SWIG_MAXTOKENS 512
#define SWIG_TOKEN_LPAREN 1
#define SWIG_TOKEN_LPAREN 1
#define SWIG_TOKEN_RPAREN 2
#define SWIG_TOKEN_SEMI 3
#define SWIG_TOKEN_COMMA 4
@ -203,146 +203,146 @@ extern void SwigScanner_idstart(SwigScanner *, char *idchar);
#define SWIG_TOKEN_LONGLONG 49
#define SWIG_TOKEN_ULONGLONG 50
#define SWIG_TOKEN_ILLEGAL 98
#define SWIG_TOKEN_LAST 99
#define SWIG_TOKEN_LAST 99
/* --- Functions for manipulating the string-based type encoding --- */
extern SwigType *NewSwigType(int typecode);
extern SwigType *SwigType_del_element(SwigType *t);
extern SwigType *SwigType_add_pointer(SwigType *t);
extern SwigType *SwigType_add_memberpointer(SwigType *t, const String_or_char *qual);
extern SwigType *SwigType_del_pointer(SwigType *t);
extern SwigType *SwigType_add_array(SwigType *t, const String_or_char *size);
extern SwigType *SwigType_del_array(SwigType *t);
extern SwigType *SwigType_pop_arrays(SwigType *t);
extern SwigType *SwigType_add_reference(SwigType *t);
extern SwigType *SwigType_del_reference(SwigType *t);
extern SwigType *SwigType_add_qualifier(SwigType *t, const String_or_char *qual);
extern SwigType *SwigType_del_qualifier(SwigType *t);
extern SwigType *SwigType_add_function(SwigType *t, ParmList *parms);
extern SwigType *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(const SwigType *t);
extern String *SwigType_pop(SwigType *t);
extern void SwigType_push(SwigType *t, SwigType *s);
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);
extern String *SwigType_rcaststr(SwigType *s, const String_or_char *id);
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_ispointer_return(SwigType *t);
extern int SwigType_ismemberpointer(SwigType *t);
extern int SwigType_isreference(SwigType *t);
extern int SwigType_isreference_return(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(const SwigType *t);
extern String *SwigType_namestr(const SwigType *t);
extern String *SwigType_templateprefix(const SwigType *t);
extern String *SwigType_templatesuffix(const SwigType *t);
extern String *SwigType_templateargs(const SwigType *t);
extern String *SwigType_prefix(const 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, const String_or_char *rep);
extern SwigType *SwigType_array_type(SwigType *t);
extern String *SwigType_default(SwigType *t);
extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep);
extern SwigType *SwigType_alttype(SwigType *t, int ltmap);
extern SwigType *NewSwigType(int typecode);
extern SwigType *SwigType_del_element(SwigType *t);
extern SwigType *SwigType_add_pointer(SwigType *t);
extern SwigType *SwigType_add_memberpointer(SwigType *t, const String_or_char *qual);
extern SwigType *SwigType_del_pointer(SwigType *t);
extern SwigType *SwigType_add_array(SwigType *t, const String_or_char *size);
extern SwigType *SwigType_del_array(SwigType *t);
extern SwigType *SwigType_pop_arrays(SwigType *t);
extern SwigType *SwigType_add_reference(SwigType *t);
extern SwigType *SwigType_del_reference(SwigType *t);
extern SwigType *SwigType_add_qualifier(SwigType *t, const String_or_char *qual);
extern SwigType *SwigType_del_qualifier(SwigType *t);
extern SwigType *SwigType_add_function(SwigType *t, ParmList *parms);
extern SwigType *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(const SwigType *t);
extern String *SwigType_pop(SwigType *t);
extern void SwigType_push(SwigType *t, SwigType *s);
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);
extern String *SwigType_rcaststr(SwigType *s, const String_or_char *id);
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_ispointer_return(SwigType *t);
extern int SwigType_ismemberpointer(SwigType *t);
extern int SwigType_isreference(SwigType *t);
extern int SwigType_isreference_return(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(const SwigType *t);
extern String *SwigType_namestr(const SwigType *t);
extern String *SwigType_templateprefix(const SwigType *t);
extern String *SwigType_templatesuffix(const SwigType *t);
extern String *SwigType_templateargs(const SwigType *t);
extern String *SwigType_prefix(const 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, const String_or_char *rep);
extern SwigType *SwigType_array_type(SwigType *t);
extern String *SwigType_default(SwigType *t);
extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep);
extern SwigType *SwigType_alttype(SwigType *t, int ltmap);
extern void SwigType_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl);
extern SwigType* SwigType_template_deftype(const SwigType *type, Symtab *tscope);
extern void SwigType_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl);
extern SwigType *SwigType_template_deftype(const SwigType *type, Symtab *tscope);
/* --- 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(const 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_mangleddata(String *mangled, 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 int SwigType_type(SwigType *t);
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(const 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_mangleddata(String *mangled, 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 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 Node *Swig_symbol_clookup_check(String_or_char *symname, Symtab *tab, int (*check)(Node *));
extern Symtab *Swig_symbol_cscope(String_or_char *symname, Symtab *tab);
extern Node *Swig_symbol_clookup_local(String_or_char *symname, Symtab *tab);
extern Node *Swig_symbol_clookup_local_check(String_or_char *symname, Symtab *tab, int (*check)(Node *));
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(const SwigType *ty, Symtab *tab);
extern String *Swig_symbol_string_qualify(String *s, Symtab *tab);
extern SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab);
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 Node *Swig_symbol_clookup_check(String_or_char *symname, Symtab *tab, int (*check) (Node *));
extern Symtab *Swig_symbol_cscope(String_or_char *symname, Symtab *tab);
extern Node *Swig_symbol_clookup_local(String_or_char *symname, Symtab *tab);
extern Node *Swig_symbol_clookup_local_check(String_or_char *symname, Symtab *tab, int (*check) (Node *));
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(const SwigType *ty, Symtab *tab);
extern String *Swig_symbol_string_qualify(String *s, Symtab *tab);
extern SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab);
extern void Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl);
extern SwigType *Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope);
extern SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab);
extern void Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl);
extern SwigType *Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope);
extern SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab);
/* --- Parameters and Parameter Lists --- */
/* Parameters are really just hidden behind a DOH object. The following
interface will probably be simplified even further. */
extern Parm *NewParm(SwigType *type, const String_or_char *name);
extern Parm *NewParmFromNode(SwigType *type, const String_or_char *name, Node *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_str_defaultargs(ParmList *);
extern String *ParmList_protostr(ParmList *);
extern int ParmList_is_compactdefargs(ParmList *p);
extern int ParmList_has_defaultargs(ParmList *p);
extern ParmList *ParmList_copy_all_except_last_parm(ParmList *p);
extern Parm *NewParm(SwigType *type, const String_or_char *name);
extern Parm *NewParmFromNode(SwigType *type, const String_or_char *name, Node *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_str_defaultargs(ParmList *);
extern String *ParmList_protostr(ParmList *);
extern int ParmList_is_compactdefargs(ParmList *p);
extern int ParmList_has_defaultargs(ParmList *p);
extern ParmList *ParmList_copy_all_except_last_parm(ParmList *p);
/* --- Parse tree support --- */
@ -354,7 +354,7 @@ extern ParmList *ParmList_copy_all_except_last_parm(ParmList *p);
#define nextSibling(x) Getattr(x,k_nextsibling)
#define firstChild(x) Getattr(x,k_firstchild)
#define lastChild(x) Getattr(x,k_lastchild)
extern int checkAttribute(Node *obj, const String_or_char *name, const String_or_char *value);
extern int checkAttribute(Node *obj, const String_or_char *name, const String_or_char *value);
/* Macros to set up the DOM tree (mostly used by the parser) */
@ -365,145 +365,142 @@ extern int checkAttribute(Node *obj, const String_or_char *name, const String_or
#define set_firstChild(x,v) Setattr(x,"firstChild",v)
#define set_lastChild(x,v) Setattr(x,"lastChild",v)
extern void appendChild(Node *node, Node *child);
extern void preppendChild(Node *node, Node *child);
extern void deleteNode(Node *node);
extern Node *copyNode(Node *node);
extern void appendChild(Node *node, Node *child);
extern void preppendChild(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 void Swig_tag_nodes(Node *node, const String_or_char *attrname, DOH *value);
extern int Swig_require(const char *ns, Node *node, ...);
extern int Swig_save(const char *ns, Node *node,...);
extern void Swig_restore(Node *node);
extern int Swig_require(const char *ns, Node *node, ...);
extern int Swig_save(const char *ns, Node *node, ...);
extern void Swig_restore(Node *node);
/* Debugging of parse trees */
extern void Swig_print_tags(File *obj, Node *root);
extern void Swig_print_tree(Node *obj);
extern void Swig_print_node(Node *obj);
extern void Swig_print_tags(File *obj, Node *root);
extern void Swig_print_tree(Node *obj);
extern void Swig_print_node(Node *obj);
extern void Swig_print_xml(Node *obj, String* filename);
extern void Swig_print_xml(Node *obj, String *filename);
/* -- Wrapper function Object */
typedef struct {
Hash *localh;
String *def;
String *locals;
String *code;
} Wrapper;
typedef struct {
Hash *localh;
String *def;
String *locals;
String *code;
} Wrapper;
extern Wrapper *NewWrapper();
extern void DelWrapper(Wrapper *w);
extern void Wrapper_compact_print_mode_set(int flag);
extern void Wrapper_pretty_print(String *str, File *f);
extern void Wrapper_compact_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);
extern char *Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl);
extern char *Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...);
extern Wrapper *NewWrapper();
extern void DelWrapper(Wrapper *w);
extern void Wrapper_compact_print_mode_set(int flag);
extern void Wrapper_pretty_print(String *str, File *f);
extern void Wrapper_compact_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);
extern char *Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl);
extern char *Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...);
/* --- Naming functions --- */
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);
extern String *Swig_name_disown(const 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);
extern String *Swig_name_disown(const String_or_char *classname);
extern void Swig_naming_init();
extern void Swig_name_namewarn_add(String *prefix, String *name, SwigType *decl, Hash *namewrn);
extern Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name,SwigType *decl);
extern void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *namewrn, ParmList *declaratorparms);
extern void Swig_name_inherit(String *base, String *derived);
extern int Swig_need_protected(Node *n);
extern int Swig_need_name_warning(Node *n);
extern int Swig_need_redefined_warn(Node* a, Node* b, int InClass);
extern void Swig_naming_init();
extern void Swig_name_namewarn_add(String *prefix, String *name, SwigType *decl, Hash *namewrn);
extern Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl);
extern void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *namewrn, ParmList *declaratorparms);
extern void Swig_name_inherit(String *base, String *derived);
extern int Swig_need_protected(Node *n);
extern int Swig_need_name_warning(Node *n);
extern int Swig_need_redefined_warn(Node *a, Node *b, int InClass);
extern String *Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, String *oldname);
extern String *Swig_name_warning(Node *n, String *prefix, String *name,SwigType *decl);
extern String *Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, String *oldname);
extern String *Swig_name_warning(Node *n, String *prefix, String *name, SwigType *decl);
/* --- parameterized rename functions --- */
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, const String_or_char *name, SwigType *decl, const String_or_char *featurename, String *value, Hash *featureattribs);
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, const String_or_char *name, SwigType *decl, const String_or_char *featurename, String *value,
Hash *featureattribs);
/* --- Misc --- */
extern char *Swig_copy_string(const char *c);
extern void Swig_banner(File *f);
extern String *Swig_string_escape(String *s);
extern String *Swig_string_mangle(const String *s);
extern void Swig_scopename_split(String *s, String **prefix, String **last);
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 String *Swig_string_lower(String *s);
extern String *Swig_string_upper(String *s);
extern String *Swig_string_title(String *s);
extern char *Swig_copy_string(const char *c);
extern void Swig_banner(File *f);
extern String *Swig_string_escape(String *s);
extern String *Swig_string_mangle(const String *s);
extern void Swig_scopename_split(String *s, String **prefix, String **last);
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 String *Swig_string_lower(String *s);
extern String *Swig_string_upper(String *s);
extern String *Swig_string_title(String *s);
extern void Swig_init();
extern void Swig_warn(const char *filename, int line, const char *msg);
extern void Swig_init();
extern void Swig_warn(const char *filename, int line, const char *msg);
extern int Swig_value_wrapper_mode(int mode);
extern int Swig_value_wrapper_mode(int mode);
#define WARNING(msg) Swig_warn(__FILE__,__LINE__,msg)
typedef enum { EMF_STANDARD, EMF_MICROSOFT } ErrorMessageFormat;
typedef enum { EMF_STANDARD, EMF_MICROSOFT } ErrorMessageFormat;
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);
extern void Swig_error_msg_format(ErrorMessageFormat format);
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);
extern void Swig_error_msg_format(ErrorMessageFormat format);
/* --- C Wrappers --- */
extern String *Swig_cparm_name(Parm *p, int i);
extern String *Swig_wrapped_var_type(SwigType *t, int varcref);
extern int Swig_cargs(Wrapper *w, ParmList *l);
extern String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_char *decl);
extern String *Swig_cparm_name(Parm *p, int i);
extern String *Swig_wrapped_var_type(SwigType *t, int varcref);
extern int Swig_cargs(Wrapper *w, ParmList *l);
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_cconstructor_call(String_or_char *name);
extern String *Swig_cppconstructor_call(String_or_char *name, ParmList *parms);
extern String *Swig_unref_call(Node *n);
extern String *Swig_ref_call(Node *n, const String* lname);
extern String *Swig_cdestructor_call(Node *n);
extern String *Swig_cppdestructor_call(Node *n);
extern String *Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self, int varcref);
extern String *Swig_cmemberget_call(const String_or_char *name, SwigType *t, String_or_char *self, int varcref);
extern String *Swig_cfunction_call(String_or_char *name, ParmList *parms);
extern String *Swig_cconstructor_call(String_or_char *name);
extern String *Swig_cppconstructor_call(String_or_char *name, ParmList *parms);
extern String *Swig_unref_call(Node *n);
extern String *Swig_ref_call(Node *n, const String *lname);
extern String *Swig_cdestructor_call(Node *n);
extern String *Swig_cppdestructor_call(Node *n);
extern String *Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self, int varcref);
extern String *Swig_cmemberget_call(const String_or_char *name, SwigType *t, String_or_char *self, int varcref);
extern String *Swig_extension_code(const String *function_name,
ParmList *parms, SwigType* return_type, const String *code, int cplusplus);
extern int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType* return_type, const String *code, int cplusplus);
extern String *Swig_extension_code(const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus);
extern int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus);
/* --- Transformations --- */
extern int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director);
extern int Swig_ConstructorToFunction(Node *n, String *classname,
String *none_comparison,
String *director_ctor,
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, int flags);
extern int Swig_VarsetToFunction(Node *n, int flags);
extern int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director);
extern int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, 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, int flags);
extern int Swig_VarsetToFunction(Node *n, int flags);
#define CWRAP_EXTEND 0x01
#define CWRAP_SMART_POINTER 0x02
@ -512,49 +509,47 @@ extern int Swig_VarsetToFunction(Node *n, int flags);
#define CWRAP_DIRECTOR_TWO_CALLS 0x10
/* --- Director Helpers --- */
extern Node *Swig_methodclass(Node *n);
extern int Swig_directorclass(Node *n);
extern Node *Swig_directormap(Node *n, String *type);
extern Node *Swig_methodclass(Node *n);
extern int Swig_directorclass(Node *n);
extern Node *Swig_directormap(Node *n, String *type);
/* --- Legacy Typemap API (somewhat simplified, ha!) --- */
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 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 Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, const 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 Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, const 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 void Swig_typemap_attach_kwargs(Hash *tm, const String_or_char *op, Parm *p);
extern void Swig_typemap_new_scope();
extern Hash *Swig_typemap_pop_scope();
extern String *Swig_typemap_lookup_new(const String_or_char *op, Node *n, const String_or_char *lname, Wrapper *f);
extern void Swig_typemap_attach_kwargs(Hash *tm, const String_or_char *op, Parm *p);
extern void Swig_typemap_new_scope();
extern Hash *Swig_typemap_pop_scope();
extern void Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f);
extern void Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f);
/* --- Code fragment support --- */
extern void Swig_fragment_register(Node* fragment);
extern void Swig_fragment_emit(String *name);
extern void Swig_fragment_register(Node *fragment);
extern void Swig_fragment_emit(String *name);
/* hacks defined in C++ ! */
extern int Swig_director_mode();
extern void Wrapper_director_mode_set(int);
extern int Swig_director_mode();
extern void Wrapper_director_mode_set(int);
/* -- template init -- */
extern void SwigType_template_init();
extern void SwigType_template_init();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -261,6 +261,6 @@ void Swig_keys_init() {
k_previoussibling = NewString("previousSibling");
k_nextsibling = NewString("nextSibling");
k_firstchild = NewString("firstChild");
k_lastchild = NewString("lastChild");
k_firstchild = NewString("firstChild");
k_lastchild = NewString("lastChild");
}

View File

@ -140,4 +140,4 @@ extern String *k_previoussibling;
extern String *k_nextsibling;
extern String *k_firstchild;
extern String *k_lastchild;
#endif /* SWIG_SWIGKEYS_H_ */
#endif /* SWIG_SWIGKEYS_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -21,20 +21,21 @@ char cvsroot_tree_c[] = "$Header$";
* Dump the tag structure of a parse tree to standard output
* ----------------------------------------------------------------------------- */
void
Swig_print_tags(DOH *obj, DOH *root) {
void Swig_print_tags(DOH *obj, DOH *root) {
DOH *croot, *newroot;
DOH *cobj;
if (!root) croot = NewStringEmpty();
else croot = root;
if (!root)
croot = NewStringEmpty();
else
croot = root;
while (obj) {
Printf(stdout,"%s . %s (%s:%d)\n", croot, nodeType(obj), Getfile(obj), Getline(obj));
Printf(stdout, "%s . %s (%s:%d)\n", croot, nodeType(obj), Getfile(obj), Getline(obj));
cobj = firstChild(obj);
if (cobj) {
newroot = NewStringf("%s . %s",croot,nodeType(obj));
Swig_print_tags(cobj,newroot);
newroot = NewStringf("%s . %s", croot, nodeType(obj));
Swig_print_tags(cobj, newroot);
Delete(newroot);
}
obj = nextSibling(obj);
@ -61,36 +62,34 @@ static void print_indent(int l) {
* Swig_print_node(Node *n)
* ----------------------------------------------------------------------------- */
void
Swig_print_node(Node *obj) {
void Swig_print_node(Node *obj) {
Iterator ki;
Node *cobj;
Node *cobj;
print_indent(0);
Printf(stdout,"+++ %s ----------------------------------------\n", nodeType(obj));
Printf(stdout, "+++ %s ----------------------------------------\n", nodeType(obj));
ki = First(obj);
while (ki.key) {
String *k = ki.key;
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)) == '$')) {
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) {
} else if (Cmp(k, "parms") == 0) {
print_indent(2);
Printf(stdout,"%-12s - %s\n", k, ParmList_protostr(Getattr(obj,k)));
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 (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);
Printf(stdout, "%-12s - \"%(escape)-0.40s%s\"\n", k, o, trunc);
Delete(o);
} else {
Printf(stdout,"%-12s - 0x%x\n", k, Getattr(obj,k));
Printf(stdout, "%-12s - 0x%x\n", k, Getattr(obj, k));
}
}
ki = Next(ki);
@ -98,12 +97,12 @@ Swig_print_node(Node *obj) {
cobj = firstChild(obj);
if (cobj) {
indent_level += 6;
Printf(stdout,"\n");
Printf(stdout, "\n");
Swig_print_tree(cobj);
indent_level -= 6;
} else {
print_indent(1);
Printf(stdout,"\n");
Printf(stdout, "\n");
}
}
@ -113,8 +112,7 @@ Swig_print_node(Node *obj) {
* Dump the tree structure of a parse tree to standard output
* ----------------------------------------------------------------------------- */
void
Swig_print_tree(DOH *obj) {
void Swig_print_tree(DOH *obj) {
while (obj) {
Swig_print_node(obj);
obj = nextSibling(obj);
@ -127,25 +125,25 @@ Swig_print_tree(DOH *obj) {
* Appends a new child to a node
* ----------------------------------------------------------------------------- */
void
appendChild(Node *node, Node *chd) {
void appendChild(Node *node, Node *chd) {
Node *lc;
if (!chd) return;
if (!chd)
return;
lc = lastChild(node);
if (!lc) {
set_firstChild(node,chd);
set_firstChild(node, chd);
} else {
set_nextSibling(lc,chd);
set_previousSibling(chd,lc);
set_nextSibling(lc, chd);
set_previousSibling(chd, lc);
}
while (chd) {
lc = chd;
set_parentNode(chd,node);
set_parentNode(chd, node);
chd = nextSibling(chd);
}
set_lastChild(node,lc);
set_lastChild(node, lc);
}
/* -----------------------------------------------------------------------------
@ -154,20 +152,20 @@ appendChild(Node *node, Node *chd) {
* Preppends a new child to a node
* ----------------------------------------------------------------------------- */
void
preppendChild(Node *node, Node *chd) {
void preppendChild(Node *node, Node *chd) {
Node *fc;
if (!chd) return;
if (!chd)
return;
fc = firstChild(node);
if (fc) {
set_nextSibling(chd,fc);
set_previousSibling(fc,chd);
set_nextSibling(chd, fc);
set_previousSibling(fc, chd);
}
set_firstChild(node,chd);
set_firstChild(node, chd);
while (chd) {
set_parentNode(chd,node);
set_parentNode(chd, node);
chd = nextSibling(chd);
}
}
@ -178,8 +176,7 @@ preppendChild(Node *node, Node *chd) {
* Deletes a node.
* ----------------------------------------------------------------------------- */
void
deleteNode(Node *n) {
void deleteNode(Node *n) {
Node *parent;
Node *prev;
Node *next;
@ -188,17 +185,17 @@ deleteNode(Node *n) {
prev = previousSibling(n);
next = nextSibling(n);
if (prev) {
set_nextSibling(prev,next);
set_nextSibling(prev, next);
} else {
if (parent) {
set_firstChild(parent,next);
set_firstChild(parent, next);
}
}
if (next) {
set_previousSibling(next,prev);
set_previousSibling(next, prev);
} else {
if (parent) {
set_lastChild(parent,prev);
set_lastChild(parent, prev);
}
}
}
@ -209,17 +206,16 @@ deleteNode(Node *n) {
* Copies a node, but only copies simple attributes (no lists, hashes).
* ----------------------------------------------------------------------------- */
Node *
copyNode(Node *n) {
Node *copyNode(Node *n) {
Iterator ki;
Node *c = NewHash();
for (ki = First(n); ki.key; ki = Next(ki)) {
if (DohIsString(ki.item)) {
Setattr(c,ki.key,Copy(ki.item));
Setattr(c, ki.key, Copy(ki.item));
}
}
Setfile(c,Getfile(n));
Setline(c,Getline(n));
Setfile(c, Getfile(n));
Setline(c, Getline(n));
return c;
}
@ -230,11 +226,10 @@ copyNode(Node *n) {
* subtypes with extra information.
* ----------------------------------------------------------------------------- */
void
Swig_tag_nodes(Node *n, const String_or_char *attrname, DOH *value) {
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);
Setattr(n, attrname, value);
Swig_tag_nodes(firstChild(n), attrname, value);
n = nextSibling(n);
}
}
@ -243,10 +238,9 @@ Swig_tag_nodes(Node *n, const String_or_char *attrname, DOH *value) {
* checkAttribute()
* ----------------------------------------------------------------------------- */
int
checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) {
String *v = Getattr(n,name);
return v ? Equal(v,value) : 0;
int checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) {
String *v = Getattr(n, name);
return v ? Equal(v, value) : 0;
}
/* -----------------------------------------------------------------------------
@ -263,8 +257,7 @@ checkAttribute(Node *n, const String_or_char *name, const String_or_char *value)
* This function can be called more than once with different namespaces.
* ----------------------------------------------------------------------------- */
int
Swig_require(const char *ns, Node *n, ...) {
int Swig_require(const char *ns, Node *n, ...) {
va_list ap;
char *name;
DOH *obj;
@ -282,13 +275,13 @@ Swig_require(const char *ns, Node *n, ...) {
opt = 1;
name++;
}
obj = Getattr(n,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));
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 (!obj)
obj = DohNone;
if (newref) {
/* Save a copy of the attribute */
Setattr(n, NewStringf("%s:%s", ns, name), obj);
@ -299,14 +292,14 @@ Swig_require(const char *ns, Node *n, ...) {
/* Save the view */
{
String *view = Getattr(n,k_view);
String *view = Getattr(n, k_view);
if (view) {
if (Strcmp(view,ns) != 0) {
if (Strcmp(view, ns) != 0) {
Setattr(n, NewStringf("%s:view", ns), view);
Setattr(n,k_view,ns);
Setattr(n, k_view, ns);
}
} else {
Setattr(n,k_view,ns);
Setattr(n, k_view, ns);
}
}
@ -320,8 +313,7 @@ Swig_require(const char *ns, Node *n, ...) {
* are saved, ie behaves as if all the attribute names were prefixed by ?.
* ----------------------------------------------------------------------------- */
int
Swig_save(const char *ns, Node *n, ...) {
int Swig_save(const char *ns, Node *n, ...) {
va_list ap;
char *name;
DOH *obj;
@ -334,12 +326,13 @@ Swig_save(const char *ns, Node *n, ...) {
} else if (*name == '?') {
name++;
}
obj = Getattr(n,name);
if (!obj) obj = DohNone;
obj = Getattr(n, name);
if (!obj)
obj = DohNone;
/* Save a copy of the attribute */
if (Setattr(n, NewStringf("%s:%s", ns, name), obj)) {
Printf(stderr,"Swig_save('%s','%s'): Warning, attribute '%s' was already saved.\n", ns, nodeType(n), name);
Printf(stderr, "Swig_save('%s','%s'): Warning, attribute '%s' was already saved.\n", ns, nodeType(n), name);
}
name = va_arg(ap, char *);
}
@ -347,14 +340,14 @@ Swig_save(const char *ns, Node *n, ...) {
/* Save the view */
{
String *view = Getattr(n,k_view);
String *view = Getattr(n, k_view);
if (view) {
if (Strcmp(view,ns) != 0) {
if (Strcmp(view, ns) != 0) {
Setattr(n, NewStringf("%s:view", ns), view);
Setattr(n,k_view,ns);
Setattr(n, k_view, ns);
}
} else {
Setattr(n,k_view,ns);
Setattr(n, k_view, ns);
}
}
@ -366,15 +359,14 @@ Swig_save(const char *ns, Node *n, ...) {
* Restores attributes saved by a previous call to Swig_require() or Swig_save().
* ----------------------------------------------------------------------------- */
void
Swig_restore(Node *n) {
void Swig_restore(Node *n) {
String *temp;
int len;
List *l;
int len;
List *l;
String *ns;
Iterator ki;
ns = Getattr(n,k_view);
ns = Getattr(n, k_view);
assert(ns);
l = NewList();
@ -384,16 +376,14 @@ Swig_restore(Node *n) {
for (ki = First(n); ki.key; ki = Next(ki)) {
if (Strncmp(temp, ki.key, len) == 0) {
Append(l,ki.key);
Append(l, ki.key);
}
}
for (ki = First(l); ki.item; ki = Next(ki)) {
DOH *obj = Getattr(n,ki.item);
Setattr(n,Char(ki.item)+len,obj);
Delattr(n,ki.item);
DOH *obj = Getattr(n, ki.item);
Setattr(n, Char(ki.item) + len, obj);
Delattr(n, ki.item);
}
Delete(l);
Delete(temp);
}

File diff suppressed because it is too large Load Diff

View File

@ -111,8 +111,7 @@ char cvsroot_typeobj_c[] = "$Header$";
* ----------------------------------------------------------------------------- */
#ifdef NEW
SwigType *
NewSwigType(const String_or_char *initial) {
SwigType *NewSwigType(const String_or_char *initial) {
return NewString(initial);
}
@ -132,8 +131,7 @@ NewSwigType(const String_or_char *initial) {
* substring, to chop the element off, or for other purposes).
* ----------------------------------------------------------------------------- */
static int
element_size(char *c) {
static int element_size(char *c) {
int nparen;
char *s = c;
while (*c) {
@ -144,15 +142,18 @@ element_size(char *c) {
nparen = 1;
c++;
while (*c) {
if (*c == '(') nparen++;
if (*c == '(')
nparen++;
if (*c == ')') {
nparen--;
if (nparen == 0) break;
if (nparen == 0)
break;
}
c++;
}
}
if (*c) c++;
if (*c)
c++;
}
return (int) (c - s);
}
@ -163,10 +164,9 @@ element_size(char *c) {
* Deletes one type element from the type.
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_del_element(SwigType *t) {
SwigType *SwigType_del_element(SwigType *t) {
int sz = element_size(Char(t));
Delslice(t,0,sz);
Delslice(t, 0, sz);
return t;
}
@ -176,21 +176,21 @@ SwigType_del_element(SwigType *t) {
* Pop one type element off the type.
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_pop(SwigType *t) {
SwigType *result;
char *c;
int sz;
SwigType *SwigType_pop(SwigType *t) {
SwigType *result;
char *c;
int sz;
c = Char(t);
if (!*c) return 0;
if (!*c)
return 0;
sz = element_size(c);
result = NewStringWithSize(c,sz);
Delslice(t,0,sz);
result = NewStringWithSize(c, sz);
Delslice(t, 0, sz);
c = Char(t);
if (*c == '.') {
Delitem(t,0);
Delitem(t, 0);
}
return result;
}
@ -201,26 +201,28 @@ SwigType_pop(SwigType *t) {
* Returns the parameter of an operator as a string
* ----------------------------------------------------------------------------- */
String *
SwigType_parm(SwigType *t) {
String *SwigType_parm(SwigType *t) {
char *start, *c;
int nparens = 0;
int nparens = 0;
c = Char(t);
while (*c && (*c != '(') && (*c != '.')) c++;
if (!*c || (*c == '.')) return 0;
while (*c && (*c != '(') && (*c != '.'))
c++;
if (!*c || (*c == '.'))
return 0;
c++;
start = c;
while (*c) {
if (*c == ')') {
if (nparens == 0) break;
if (nparens == 0)
break;
nparens--;
} else if (*c == '(') {
nparens++;
}
c++;
}
return NewStringWithSize(start, (int) (c-start));
return NewStringWithSize(start, (int) (c - start));
}
/* -----------------------------------------------------------------------------
@ -230,20 +232,21 @@ SwigType_parm(SwigType *t) {
* ----------------------------------------------------------------------------- */
List *SwigType_split(const SwigType *t) {
DOH *item;
List *list;
char *c;
int len;
DOH *item;
List *list;
char *c;
int len;
c = Char(t);
list = NewList();
while (*c) {
len = element_size(c);
item = NewStringWithSize(c,len);
Append(list,item);
item = NewStringWithSize(c, len);
Append(list, item);
Delete(item);
c = c + len;
if (*c == '.') c++;
if (*c == '.')
c++;
}
return list;
}
@ -255,40 +258,45 @@ List *SwigType_split(const SwigType *t) {
* ----------------------------------------------------------------------------- */
List *SwigType_parmlist(const String *p) {
DOH *item;
DOH *item;
List *list;
char *c, *itemstart;
c = Char(p);
while (*c && (*c != '(') && (*c != '.')) c++;
if (!*c || (*c == '.')) return 0;
while (*c && (*c != '(') && (*c != '.'))
c++;
if (!*c || (*c == '.'))
return 0;
c++;
list = NewList();
itemstart = c;
while (*c) {
if (*c == ',') {
item = NewStringWithSize(itemstart, (int) (c - itemstart));
Append(list,item);
Append(list, item);
Delete(item);
itemstart = c+1;
itemstart = c + 1;
} else if (*c == '(') {
int nparens = 1;
c++;
while (*c) {
if (*c == '(') nparens++;
if (*c == '(')
nparens++;
if (*c == ')') {
nparens--;
if (nparens == 0) break;
if (nparens == 0)
break;
}
c++;
}
} else if (*c == ')') {
break;
}
if (*c) c++;
if (*c)
c++;
}
item = NewStringWithSize(itemstart,(int) (c - itemstart));
Append(list,item);
item = NewStringWithSize(itemstart, (int) (c - itemstart));
Append(list, item);
Delete(item);
return list;
}
@ -304,43 +312,42 @@ List *SwigType_parmlist(const String *p) {
* functions take into account qualifiers (if any).
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_add_pointer(SwigType *t) {
Insert(t,0,"p.");
SwigType *SwigType_add_pointer(SwigType *t) {
Insert(t, 0, "p.");
return t;
}
SwigType *
SwigType_del_pointer(SwigType *t) {
SwigType *SwigType_del_pointer(SwigType *t) {
char *c, *s;
c = Char(t);
s = c;
/* Skip qualifiers, if any */
if (strncmp(c,"q(",2) == 0) {
c = strchr(c,'.');
if (strncmp(c, "q(", 2) == 0) {
c = strchr(c, '.');
assert(c);
c++;
}
if (strncmp(c,"p.",2)) {
if (strncmp(c, "p.", 2)) {
printf("Fatal error. SwigType_del_pointer applied to non-pointer.\n");
abort();
}
Delslice(t,0,(c-s)+2);
Delslice(t, 0, (c - s) + 2);
return t;
}
int
SwigType_ispointer(SwigType *t) {
int SwigType_ispointer(SwigType *t) {
char *c;
if (!t) return 0;
if (!t)
return 0;
c = Char(t);
/* Skip qualifiers, if any */
if (strncmp(c,"q(",2) == 0) {
c = strchr(c,'.');
if (!c) return 0;
if (strncmp(c, "q(", 2) == 0) {
c = strchr(c, '.');
if (!c)
return 0;
c++;
}
if (strncmp(c,"p.",2) == 0) {
if (strncmp(c, "p.", 2) == 0) {
return 1;
}
return 0;
@ -357,29 +364,27 @@ SwigType_ispointer(SwigType *t) {
* functions take into account qualifiers (if any).
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_add_reference(SwigType *t) {
Insert(t,0,"r.");
return t;
}
SwigType *
SwigType_del_reference(SwigType *t) {
char *c = Char(t);
int check = strncmp(c,"r.",2);
assert(check == 0);
Delslice(t,0,2);
SwigType *SwigType_add_reference(SwigType *t) {
Insert(t, 0, "r.");
return t;
}
int
SwigType_isreference(SwigType *t) {
SwigType *SwigType_del_reference(SwigType *t) {
char *c = Char(t);
int check = strncmp(c, "r.", 2);
assert(check == 0);
Delslice(t, 0, 2);
return t;
}
int SwigType_isreference(SwigType *t) {
char *c;
if (!t) return 0;
if (!t)
return 0;
c = Char(t);
if (strncmp(c,"r.",2) == 0) {
if (strncmp(c, "r.", 2) == 0) {
return 1;
}
}
return 0;
}
@ -397,20 +402,19 @@ SwigType_isreference(SwigType *t) {
* stored in exactly the same way as "q(const volatile)".
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_add_qualifier(SwigType *t, const String_or_char *qual) {
SwigType *SwigType_add_qualifier(SwigType *t, const String_or_char *qual) {
char temp[256], newq[256];
int sz, added = 0;
int sz, added = 0;
char *q, *cqual;
char *c = Char(t);
cqual = Char(qual);
if (!(strncmp(c,"q(",2) == 0)) {
sprintf(temp,"q(%s).",cqual);
Insert(t,0,temp);
if (!(strncmp(c, "q(", 2) == 0)) {
sprintf(temp, "q(%s).", cqual);
Insert(t, 0, temp);
return t;
}
}
/* The type already has a qualifier on it. In this case, we first check to
see if the qualifier is already specified. In that case do nothing.
@ -418,58 +422,57 @@ SwigType_add_qualifier(SwigType *t, const String_or_char *qual) {
order */
sz = element_size(c);
strncpy(temp,c, (sz < 256) ? sz : 256);
strncpy(temp, c, (sz < 256) ? sz : 256);
if (strstr(temp,cqual)) {
if (strstr(temp, cqual)) {
/* Qualifier already added */
return t;
}
/* Add the qualifier to the existing list. */
strcpy(newq,"q(");
q = temp+2;
q = strtok(q," ).");
strcpy(newq, "q(");
q = temp + 2;
q = strtok(q, " ).");
while (q) {
if (strcmp(cqual,q) < 0) {
if (strcmp(cqual, q) < 0) {
/* New qualifier is less that current qualifier. We need to insert it */
strcat(newq,cqual);
strcat(newq," ");
strcat(newq,q);
strcat(newq, cqual);
strcat(newq, " ");
strcat(newq, q);
added = 1;
} else {
strcat(newq,q);
strcat(newq, q);
}
q = strtok(NULL," ).");
q = strtok(NULL, " ).");
if (q) {
strcat(newq," ");
strcat(newq, " ");
}
}
if (!added) {
strcat(newq," ");
strcat(newq,cqual);
strcat(newq, " ");
strcat(newq, cqual);
}
strcat(newq,").");
Delslice(t,0,sz);
Insert(t,0,newq);
strcat(newq, ").");
Delslice(t, 0, sz);
Insert(t, 0, newq);
return t;
}
SwigType *
SwigType_del_qualifier(SwigType *t) {
SwigType *SwigType_del_qualifier(SwigType *t) {
char *c = Char(t);
int check = strncmp(c,"q(",2);
int check = strncmp(c, "q(", 2);
assert(check == 0);
Delslice(t,0,element_size(c));
Delslice(t, 0, element_size(c));
return t;
}
int
SwigType_isqualifier(SwigType *t) {
int SwigType_isqualifier(SwigType *t) {
char *c;
if (!t) return 0;
if (!t)
return 0;
c = Char(t);
if (strncmp(c,"q(",2) == 0) {
if (strncmp(c, "q(", 2) == 0) {
return 1;
}
return 0;
@ -485,29 +488,27 @@ SwigType_isqualifier(SwigType *t) {
* Add, remove, and test for C++ pointer to members.
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_add_memberpointer(SwigType *t, const String_or_char *name) {
SwigType *SwigType_add_memberpointer(SwigType *t, const String_or_char *name) {
String *temp = NewStringf("m(%s).", name);
Insert(t,0,temp);
Insert(t, 0, temp);
Delete(temp);
return t;
}
SwigType *
SwigType_del_memberpointer(SwigType *t) {
SwigType *SwigType_del_memberpointer(SwigType *t) {
char *c = Char(t);
int check = strncmp(c,"m(",2);
int check = strncmp(c, "m(", 2);
assert(check == 0);
Delslice(t,0,element_size(c));
Delslice(t, 0, element_size(c));
return t;
}
int
SwigType_ismemberpointer(SwigType *t) {
int SwigType_ismemberpointer(SwigType *t) {
char *c;
if (!t) return 0;
if (!t)
return 0;
c = Char(t);
if (strncmp(c,"m(",2) == 0) {
if (strncmp(c, "m(", 2) == 0) {
return 1;
}
return 0;
@ -529,57 +530,54 @@ SwigType_ismemberpointer(SwigType *t) {
* SwigType_pop_arrays() - Remove all arrays
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_add_array(SwigType *t, const String_or_char *size) {
SwigType *SwigType_add_array(SwigType *t, const String_or_char *size) {
char temp[512];
strcpy(temp,"a(");
strcat(temp,Char(size));
strcat(temp,").");
Insert(t,0,temp);
strcpy(temp, "a(");
strcat(temp, Char(size));
strcat(temp, ").");
Insert(t, 0, temp);
return t;
}
SwigType *
SwigType_del_array(SwigType *t) {
SwigType *SwigType_del_array(SwigType *t) {
char *c = Char(t);
int check = strncmp(c,"a(",2);
int check = strncmp(c, "a(", 2);
assert(check == 0);
Delslice(t,0,element_size(c));
Delslice(t, 0, element_size(c));
return t;
}
int SwigType_isarray(SwigType *t) {
char *c;
if (!t) return 0;
if (!t)
return 0;
c = Char(t);
if (strncmp(c,"a(",2) == 0) {
if (strncmp(c, "a(", 2) == 0) {
return 1;
}
return 0;
}
/* Remove all arrays */
SwigType *
SwigType_pop_arrays(SwigType *t) {
SwigType *SwigType_pop_arrays(SwigType *t) {
String *ta;
assert(SwigType_isarray(t));
ta = NewStringEmpty();
while (SwigType_isarray(t)) {
SwigType *td = SwigType_pop(t);
Append(ta,td);
Append(ta, td);
Delete(td);
}
return ta;
}
/* Return number of array dimensions */
int
SwigType_array_ndim(SwigType *t) {
int SwigType_array_ndim(SwigType *t) {
int ndim = 0;
char *c = Char(t);
while (c && (strncmp(c,"a(",2) == 0)) {
c = strchr(c,'.');
while (c && (strncmp(c, "a(", 2) == 0)) {
c = strchr(c, '.');
c++;
ndim++;
}
@ -587,25 +585,24 @@ SwigType_array_ndim(SwigType *t) {
}
/* Get nth array dimension */
String *
SwigType_array_getdim(SwigType *t, int n) {
String *SwigType_array_getdim(SwigType *t, int n) {
char *c = Char(t);
while (c && (strncmp(c,"a(",2) == 0) && (n > 0)) {
c = strchr(c,'.');
while (c && (strncmp(c, "a(", 2) == 0) && (n > 0)) {
c = strchr(c, '.');
c++;
n--;
}
if (n == 0) {
String *dim = SwigType_parm(c);
String *dim = SwigType_parm(c);
if (SwigType_istemplate(dim)) {
String *ndim = SwigType_namestr(dim);
Delete(dim);
dim = ndim;
}
return dim;
}
return 0;
}
@ -617,10 +614,11 @@ void SwigType_array_setdim(SwigType *t, int n, const String_or_char *rep) {
char *c = Char(t);
start = c;
if (strncmp(c,"a(",2)) abort();
if (strncmp(c, "a(", 2))
abort();
while (c && (strncmp(c,"a(",2) == 0) && (n > 0)) {
c = strchr(c,'.');
while (c && (strncmp(c, "a(", 2) == 0) && (n > 0)) {
c = strchr(c, '.');
c++;
n--;
}
@ -628,19 +626,18 @@ void SwigType_array_setdim(SwigType *t, int n, const String_or_char *rep) {
temp = *c;
*c = 0;
result = NewString(start);
Printf(result,"a(%s)",rep);
Printf(result, "a(%s)", rep);
*c = temp;
c = strchr(c,'.');
Append(result,c);
c = strchr(c, '.');
Append(result, c);
}
Clear(t);
Append(t,result);
Append(t, result);
Delete(result);
}
/* Return base type of an array */
SwigType *
SwigType_array_type(SwigType *ty) {
SwigType *SwigType_array_type(SwigType *ty) {
SwigType *t;
t = Copy(ty);
while (SwigType_isarray(t)) {
@ -662,72 +659,73 @@ SwigType_array_type(SwigType *ty) {
* ----------------------------------------------------------------------------- */
/* Returns the function type, t, constructed from the parameters, parms */
SwigType *
SwigType_add_function(SwigType *t, ParmList *parms) {
SwigType *SwigType_add_function(SwigType *t, ParmList *parms) {
String *pstr;
Parm *p;
Parm *p;
Insert(t,0,").");
Insert(t, 0, ").");
pstr = NewString("f(");
p = parms;
for (p = parms; p; p = nextSibling(p)) {
if (p != parms) Putc(',',pstr);
Append(pstr, Getattr(p,k_type));
if (p != parms)
Putc(',', pstr);
Append(pstr, Getattr(p, k_type));
}
Insert(t,0,pstr);
Insert(t, 0, pstr);
Delete(pstr);
return t;
}
SwigType *
SwigType_pop_function(SwigType *t) {
SwigType *SwigType_pop_function(SwigType *t) {
SwigType *f = 0;
SwigType *g = 0;
char *c = Char(t);
if (strncmp(c,"q(",2) == 0) {
if (strncmp(c, "q(", 2) == 0) {
f = SwigType_pop(t);
c = Char(t);
}
if (strncmp(c,"f(",2)) {
if (strncmp(c, "f(", 2)) {
printf("Fatal error. SwigType_pop_function applied to non-function.\n");
abort();
}
g = SwigType_pop(t);
if (f) SwigType_push(g,f);
if (f)
SwigType_push(g, f);
Delete(f);
return g;
}
int
SwigType_isfunction(SwigType *t) {
int SwigType_isfunction(SwigType *t) {
char *c;
if (!t) {
return 0;
}
c = Char(t);
if (strncmp(c,"q(",2) == 0) {
if (strncmp(c, "q(", 2) == 0) {
/* Might be a 'const' function. Try to skip over the 'const' */
c = strchr(c,'.');
if (c) c++;
else return 0;
c = strchr(c, '.');
if (c)
c++;
else
return 0;
}
if (strncmp(c,"f(",2) == 0) {
if (strncmp(c, "f(", 2) == 0) {
return 1;
}
return 0;
}
ParmList *
SwigType_function_parms(SwigType *t) {
ParmList *SwigType_function_parms(SwigType *t) {
List *l = SwigType_parmlist(t);
Hash *p, *pp = 0, *firstp = 0;
Iterator o;
for (o = First(l); o.item; o = Next(o)) {
p = NewParm(o.item,0);
if (!firstp) firstp = p;
p = NewParm(o.item, 0);
if (!firstp)
firstp = p;
if (pp) {
set_nextSibling(pp,p);
set_nextSibling(pp, p);
Delete(p);
}
pp = p;
@ -737,7 +735,8 @@ SwigType_function_parms(SwigType *t) {
}
int SwigType_isvarargs(const SwigType *t) {
if (Strcmp(t,"v(...)") == 0) return 1;
if (Strcmp(t, "v(...)") == 0)
return 1;
return 0;
}
@ -758,24 +757,25 @@ int SwigType_isvarargs(const SwigType *t) {
* vector<int *> ----> "vector<(p.int)>"
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_add_template(SwigType *t, ParmList *parms) {
Parm *p;
SwigType *SwigType_add_template(SwigType *t, ParmList *parms) {
Parm *p;
Append(t,"<(");
Append(t, "<(");
p = parms;
for (p = parms; p; p = nextSibling(p)) {
String *v;
if (Getattr(p,k_default)) continue;
if (p != parms) Append(t,",");
v = Getattr(p,k_value);
if (Getattr(p, k_default))
continue;
if (p != parms)
Append(t, ",");
v = Getattr(p, k_value);
if (v) {
Append(t,v);
Append(t, v);
} else {
Append(t,Getattr(p,k_type));
Append(t, Getattr(p, k_type));
}
}
Append(t,")>");
Append(t, ")>");
return t;
}
@ -791,11 +791,10 @@ SwigType_add_template(SwigType *t, ParmList *parms) {
* Results in "Foo"
* ----------------------------------------------------------------------------- */
String *
SwigType_templateprefix(const SwigType *t) {
String *SwigType_templateprefix(const SwigType *t) {
const char *s = Char(t);
const char *c = strstr(s,"<(");
return c ? NewStringWithSize(s, c-s) : NewString(s);
const char *c = strstr(s, "<(");
return c ? NewStringWithSize(s, c - s) : NewString(s);
}
/* -----------------------------------------------------------------------------
@ -809,17 +808,18 @@ SwigType_templateprefix(const SwigType *t) {
* returns "::bar"
* ----------------------------------------------------------------------------- */
String *
SwigType_templatesuffix(const SwigType *t) {
String *SwigType_templatesuffix(const SwigType *t) {
const char *c;
c = Char(t);
while (*c) {
if ((*c == '<') && (*(c+1) == '(')) {
if ((*c == '<') && (*(c + 1) == '(')) {
int nest = 1;
c++;
while (*c && nest) {
if (*c == '<') nest++;
if (*c == '>') nest--;
if (*c == '<')
nest++;
if (*c == '>')
nest--;
c++;
}
return NewString(c);
@ -835,22 +835,23 @@ SwigType_templatesuffix(const SwigType *t) {
* Returns the template part
* ----------------------------------------------------------------------------- */
String *
SwigType_templateargs(const SwigType *t) {
String *SwigType_templateargs(const SwigType *t) {
const char *c;
const char *start;
c = Char(t);
while (*c) {
if ((*c == '<') && (*(c+1) == '(')) {
if ((*c == '<') && (*(c + 1) == '(')) {
int nest = 1;
start = c;
c++;
while (*c && nest) {
if (*c == '<') nest++;
if (*c == '>') nest--;
if (*c == '<')
nest++;
if (*c == '>')
nest--;
c++;
}
return NewStringWithSize(start,c-start);
return NewStringWithSize(start, c - start);
}
c++;
}
@ -863,10 +864,10 @@ SwigType_templateargs(const SwigType *t) {
* Tests a type to see if it includes template parameters
* ----------------------------------------------------------------------------- */
int
SwigType_istemplate(const SwigType *t) {
int SwigType_istemplate(const SwigType *t) {
char *ct = Char(t);
if ((ct = strstr(ct,"<(")) && (strstr(ct + 2,")>"))) return 1;
if ((ct = strstr(ct, "<(")) && (strstr(ct + 2, ")>")))
return 1;
return 0;
}
@ -877,8 +878,7 @@ SwigType_istemplate(const SwigType *t) {
* type "p.p.int", the function would return "int".
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_base(const SwigType *t) {
SwigType *SwigType_base(const SwigType *t) {
char *c;
char *lastop = 0;
c = Char(t);
@ -888,8 +888,8 @@ SwigType_base(const SwigType *t) {
/* Search for the last type constructor separator '.' */
while (*c) {
if (*c == '.') {
if (*(c+1)) {
lastop = c+1;
if (*(c + 1)) {
lastop = c + 1;
}
c++;
continue;
@ -899,11 +899,14 @@ SwigType_base(const SwigType *t) {
int ntemp = 1;
c++;
while ((*c) && (ntemp > 0)) {
if (*c == '>') ntemp--;
else if (*c == '<') ntemp++;
if (*c == '>')
ntemp--;
else if (*c == '<')
ntemp++;
c++;
}
if (ntemp) break;
if (ntemp)
break;
continue;
}
if (*c == '(') {
@ -911,11 +914,14 @@ SwigType_base(const SwigType *t) {
int nparen = 1;
c++;
while ((*c) && (nparen > 0)) {
if (*c == '(') nparen++;
else if (*c == ')') nparen--;
if (*c == '(')
nparen++;
else if (*c == ')')
nparen--;
c++;
}
if (nparen) break;
if (nparen)
break;
continue;
}
c++;
@ -930,8 +936,7 @@ SwigType_base(const SwigType *t) {
* type "p.p.int" is "p.p.".
* ----------------------------------------------------------------------------- */
String *
SwigType_prefix(const SwigType *t) {
String *SwigType_prefix(const SwigType *t) {
char *c, *d;
String *r = 0;
@ -939,7 +944,8 @@ SwigType_prefix(const SwigType *t) {
d = c + strlen(c);
/* Check for a type constructor */
if ((d > c) && (*(d-1) == '.')) d--;
if ((d > c) && (*(d - 1) == '.'))
d--;
while (d > c) {
d--;
@ -947,8 +953,10 @@ SwigType_prefix(const SwigType *t) {
int nest = 1;
d--;
while ((d > c) && (nest)) {
if (*d == '>') nest++;
if (*d == '<') nest--;
if (*d == '>')
nest++;
if (*d == '<')
nest--;
d--;
}
}
@ -957,17 +965,19 @@ SwigType_prefix(const SwigType *t) {
int nparen = 1;
d--;
while ((d > c) && (nparen)) {
if (*d == ')') nparen++;
if (*d == '(') nparen--;
if (*d == ')')
nparen++;
if (*d == '(')
nparen--;
d--;
}
}
if (*d == '.') {
char t = *(d+1);
*(d+1) = 0;
char t = *(d + 1);
*(d + 1) = 0;
r = NewString(c);
*(d+1) = t;
*(d + 1) = t;
return r;
}
}
@ -980,34 +990,34 @@ SwigType_prefix(const SwigType *t) {
* Strip all qualifiers from a type and return a new type
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_strip_qualifiers(SwigType *t) {
SwigType *SwigType_strip_qualifiers(SwigType *t) {
static Hash *memoize_stripped = 0;
SwigType *r;
List *l;
Iterator ei;
List *l;
Iterator ei;
if (!memoize_stripped)
memoize_stripped = NewHash();
r = Getattr(memoize_stripped, t);
if (r)
return Copy(r);
if (!memoize_stripped) memoize_stripped = NewHash();
r = Getattr(memoize_stripped,t);
if (r) return Copy(r);
l = SwigType_split(t);
r = NewStringEmpty();
for (ei = First(l);ei.item; ei = Next(ei)) {
if (SwigType_isqualifier(ei.item)) continue;
Append(r,ei.item);
for (ei = First(l); ei.item; ei = Next(ei)) {
if (SwigType_isqualifier(ei.item))
continue;
Append(r, ei.item);
}
Delete(l);
{
String *key, *value;
key = Copy(t);
value = Copy(r);
Setattr(memoize_stripped,key,value);
Setattr(memoize_stripped, key, value);
Delete(key);
Delete(value);
}
return r;
}

File diff suppressed because it is too large Load Diff

View File

@ -20,21 +20,15 @@ static Hash *warnings = 0;
* Issue a warning
* ----------------------------------------------------------------------------- */
void
Swig_warn(const char *filename, int line, const char *msg) {
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);
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,7 +14,7 @@ char cvsroot_wrapfunc_c[] = "$Header$";
#include "swig.h"
#include <ctype.h>
static int Compact_mode = 0; /* set to 0 on default */
static int Compact_mode = 0; /* set to 0 on default */
static int Max_line_size = 128;
/* -----------------------------------------------------------------------------
@ -23,8 +23,7 @@ static int Max_line_size = 128;
* Create a new wrapper function object.
* ----------------------------------------------------------------------------- */
Wrapper *
NewWrapper() {
Wrapper *NewWrapper() {
Wrapper *w;
w = (Wrapper *) malloc(sizeof(Wrapper));
w->localh = NewHash();
@ -40,8 +39,7 @@ NewWrapper() {
* Delete a wrapper function object.
* ----------------------------------------------------------------------------- */
void
DelWrapper(Wrapper *w) {
void DelWrapper(Wrapper *w) {
Delete(w->localh);
Delete(w->locals);
Delete(w->code);
@ -55,8 +53,7 @@ DelWrapper(Wrapper *w) {
* Set compact_mode.
* ----------------------------------------------------------------------------- */
void
Wrapper_compact_print_mode_set(int flag) {
void Wrapper_compact_print_mode_set(int flag) {
Compact_mode = flag;
}
@ -66,8 +63,7 @@ Wrapper_compact_print_mode_set(int flag) {
* Formats a wrapper function and fixes up the indentation.
* ----------------------------------------------------------------------------- */
void
Wrapper_pretty_print(String *str, File *f) {
void Wrapper_pretty_print(String *str, File *f) {
String *ts;
int level = 0;
int c, i;
@ -77,127 +73,132 @@ Wrapper_pretty_print(String *str, File *f) {
int label = 0;
ts = NewStringEmpty();
Seek(str,0, SEEK_SET);
Seek(str, 0, SEEK_SET);
while ((c = Getc(str)) != EOF) {
if (c == '\"') {
Putc(c,ts);
Putc(c, ts);
while ((c = Getc(str)) != EOF) {
if (c == '\\') {
Putc(c,ts);
Putc(c, ts);
c = Getc(str);
}
Putc(c,ts);
if (c == '\"') break;
Putc(c, ts);
if (c == '\"')
break;
}
empty = 0;
} else if (c == '\'') {
Putc(c,ts);
Putc(c, ts);
while ((c = Getc(str)) != EOF) {
if (c == '\\') {
Putc(c,ts);
Putc(c, ts);
c = Getc(str);
}
Putc(c,ts);
if (c == '\'') break;
Putc(c, ts);
if (c == '\'')
break;
}
empty = 0;
} else if (c == ':') {
Putc(c,ts);
Putc(c, ts);
if ((c = Getc(str)) == '\n') {
if (!empty && !strchr(Char(ts),'?')) label = 1;
if (!empty && !strchr(Char(ts), '?'))
label = 1;
}
Ungetc(c,str);
Ungetc(c, str);
} else if (c == '(') {
Putc(c,ts);
plevel+=indent;
Putc(c, ts);
plevel += indent;
empty = 0;
} else if (c == ')') {
Putc(c,ts);
plevel-=indent;
Putc(c, ts);
plevel -= indent;
empty = 0;
} else if (c == '{') {
Putc(c,ts);
Putc('\n',ts);
for (i = 0; i < level; i++)
Putc(' ',f);
Printf(f,"%s", ts);
Putc(c, ts);
Putc('\n', ts);
for (i = 0; i < level; i++)
Putc(' ', f);
Printf(f, "%s", ts);
Clear(ts);
level+=indent;
level += indent;
while ((c = Getc(str)) != EOF) {
if (!isspace(c)) {
Ungetc(c,str);
Ungetc(c, str);
break;
}
}
empty = 0;
} else if (c == '}') {
if (!empty) {
Putc('\n',ts);
Putc('\n', ts);
for (i = 0; i < level; i++)
Putc(' ',f);
Printf(f,"%s",ts);
Putc(' ', f);
Printf(f, "%s", ts);
Clear(ts);
}
level-=indent;
Putc(c,ts);
level -= indent;
Putc(c, ts);
empty = 0;
} else if (c == '\n') {
Putc(c,ts);
Putc(c, ts);
empty = 0;
if (!empty) {
int slevel = level;
if (label && (slevel >= indent)) slevel -= indent;
if (label && (slevel >= indent))
slevel -= indent;
if ((Char(ts))[0] != '#') {
for (i = 0; i < slevel; i++)
Putc(' ',f);
Putc(' ', f);
}
Printf(f,"%s",ts);
Printf(f, "%s", ts);
for (i = 0; i < plevel; i++)
Putc(' ',f);
Putc(' ', f);
}
Clear(ts);
label = 0;
empty = 1;
} else if (c == '/') {
empty = 0;
Putc(c,ts);
Putc(c, ts);
c = Getc(str);
if (c != EOF) {
Putc(c,ts);
if (c == '/') { /* C++ comment */
Putc(c, ts);
if (c == '/') { /* C++ comment */
while ((c = Getc(str)) != EOF) {
if (c == '\n') {
Ungetc(c,str);
Ungetc(c, str);
break;
}
Putc(c,ts);
Putc(c, ts);
}
} else if (c == '*') { /* C comment */
int endstar = 0;
} else if (c == '*') { /* C comment */
int endstar = 0;
while ((c = Getc(str)) != EOF) {
if (endstar && c == '/') { /* end of C comment */
Putc(c,ts);
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);
}
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);
Putc(c, ts);
empty = 0;
}
}
}
if (!empty) Printf(f,"%s",ts);
if (!empty)
Printf(f, "%s", ts);
Delete(ts);
Printf(f,"\n");
Printf(f, "\n");
}
/* -----------------------------------------------------------------------------
@ -207,9 +208,8 @@ Wrapper_pretty_print(String *str, File *f) {
* Print out in compact format, with Compact enabled.
* ----------------------------------------------------------------------------- */
void
Wrapper_compact_print(String *str, File *f) {
String *ts, *tf; /*temp string & temp file */
void Wrapper_compact_print(String *str, File *f) {
String *ts, *tf; /*temp string & temp file */
int level = 0;
int c, i;
int empty = 1;
@ -217,163 +217,165 @@ Wrapper_compact_print(String *str, File *f) {
ts = NewStringEmpty();
tf = NewStringEmpty();
Seek(str,0, SEEK_SET);
Seek(str, 0, SEEK_SET);
while ((c = Getc(str)) != EOF) {
if (c == '\"') { /* string 1 */
if (c == '\"') { /* string 1 */
empty = 0;
Putc(c,ts);
Putc(c, ts);
while ((c = Getc(str)) != EOF) {
if (c == '\\') {
Putc(c,ts);
Putc(c, ts);
c = Getc(str);
}
Putc(c,ts);
if (c == '\"') break;
Putc(c, ts);
if (c == '\"')
break;
}
} else if (c == '\'') { /* string 2 */
} else if (c == '\'') { /* string 2 */
empty = 0;
Putc(c,ts);
Putc(c, ts);
while ((c = Getc(str)) != EOF) {
if (c == '\\') {
Putc(c,ts);
Putc(c, ts);
c = Getc(str);
}
Putc(c,ts);
if (c == '\'') break;
Putc(c, ts);
if (c == '\'')
break;
}
} else if (c == '{') { /* start of {...} */
} else if (c == '{') { /* start of {...} */
empty = 0;
Putc(c,ts);
Putc(c, ts);
if (Len(tf) == 0) {
for (i = 0; i < level; i++)
Putc(' ',tf);
for (i = 0; i < level; i++)
Putc(' ', tf);
} else if ((Len(tf) + Len(ts)) < Max_line_size) {
Putc(' ',tf);
Putc(' ', tf);
} else {
Putc('\n',tf);
Printf(f,"%s", tf);
Putc('\n', tf);
Printf(f, "%s", tf);
Clear(tf);
for (i = 0; i < level; i++)
Putc(' ',tf);
for (i = 0; i < level; i++)
Putc(' ', tf);
}
Append(tf,ts);
Append(tf, ts);
Clear(ts);
level+=indent;
level += indent;
while ((c = Getc(str)) != EOF) {
if (!isspace(c)) {
Ungetc(c,str);
Ungetc(c, str);
break;
}
}
} else if (c == '}') { /* end of {...} */
} else if (c == '}') { /* end of {...} */
empty = 0;
if (Len(tf) == 0) {
for (i = 0; i < level; i++)
Putc(' ',tf);
for (i = 0; i < level; i++)
Putc(' ', tf);
} else if ((Len(tf) + Len(ts)) < Max_line_size) {
Putc(' ',tf);
Putc(' ', tf);
} else {
Putc('\n',tf);
Printf(f,"%s", tf);
Putc('\n', tf);
Printf(f, "%s", tf);
Clear(tf);
for (i = 0; i < level; i++)
Putc(' ',tf);
for (i = 0; i < level; i++)
Putc(' ', tf);
}
Append(tf, ts);
Putc(c, tf);
Clear(ts);
level-=indent;
} else if (c == '\n') { /* line end */
level -= indent;
} else if (c == '\n') { /* line end */
while ((c = Getc(str)) != EOF) {
if (!isspace(c))
break;
}
if (c == '#'){
Putc('\n',ts);
if (c == '#') {
Putc('\n', ts);
} else if (c == '}') {
Putc(' ',ts);
} else if ( (c != EOF) || (Len(ts)!=0) ){
Putc(' ', ts);
} else if ((c != EOF) || (Len(ts) != 0)) {
if (Len(tf) == 0) {
for (i = 0; i < level; i++)
Putc(' ',tf);
for (i = 0; i < level; i++)
Putc(' ', tf);
} else if ((Len(tf) + Len(ts)) < Max_line_size) {
Putc(' ',tf);
Putc(' ', tf);
} else {
Putc('\n',tf);
Printf(f,"%s", tf);
Putc('\n', tf);
Printf(f, "%s", tf);
Clear(tf);
for (i = 0; i < level; i++)
Putc(' ',tf);
for (i = 0; i < level; i++)
Putc(' ', tf);
}
Append(tf,ts);
Append(tf, ts);
Clear(ts);
}
Ungetc(c,str);
Ungetc(c, str);
empty = 1;
} else if (c == '/') { /* comment */
} else if (c == '/') { /* comment */
empty = 0;
c = Getc(str);
if (c != EOF) {
if (c == '/') { /* C++ comment */
if (c == '/') { /* C++ comment */
while ((c = Getc(str)) != EOF) {
if (c == '\n') {
Ungetc(c,str);
Ungetc(c, str);
break;
}
}
} else if (c == '*') { /* C comment */
} else if (c == '*') { /* C comment */
int endstar = 0;
while ((c = Getc(str)) != EOF) {
if (endstar && c == '/') { /* end of C comment */
if (endstar && c == '/') { /* end of C comment */
break;
}
endstar = (c == '*');
endstar = (c == '*');
}
} else {
Putc('/',ts);
Putc(c,ts);
} else {
Putc('/', ts);
Putc(c, ts);
}
}
} else if (c == '#') { /* Preprocessor line */
} else if (c == '#') { /* Preprocessor line */
Putc('#', ts);
while ((c = Getc(str)) != EOF) {
Putc(c, ts);
if (c == '\\') { /* Continued line of the same PP */
if (c == '\\') { /* Continued line of the same PP */
c = Getc(str);
if (c == '\n')
Putc(c, ts);
else
Ungetc(c, str);
} else if (c == '\n')
} else if (c == '\n')
break;
}
if (!empty) {
Append(tf,"\n");
Append(tf, "\n");
}
Append(tf,ts);
Append(tf, ts);
Printf(f, "%s", tf);
Clear(tf);
Clear(ts);
for (i = 0; i < level; i++)
Putc(' ',tf);
for (i = 0; i < level; i++)
Putc(' ', tf);
empty = 1;
} else {
if (!empty || !isspace(c)) {
Putc(c,ts);
Putc(c, ts);
empty = 0;
}
}
}
if (!empty) {
Append(tf,ts);
Append(tf, ts);
}
if (Len(tf) != 0)
Printf(f,"%s",tf);
Printf(f, "%s", tf);
Delete(ts);
Delete(tf);
Printf(f,"\n");
Printf(f, "\n");
}
/* -----------------------------------------------------------------------------
@ -382,18 +384,17 @@ Wrapper_compact_print(String *str, File *f) {
* Print out a wrapper function. Does pretty or compact printing as well.
* ----------------------------------------------------------------------------- */
void
Wrapper_print(Wrapper *w, File *f) {
void Wrapper_print(Wrapper *w, File *f) {
String *str;
str = NewStringEmpty();
Printf(str,"%s\n", w->def);
Printf(str,"%s\n", w->locals);
Printf(str,"%s\n", w->code);
Printf(str, "%s\n", w->def);
Printf(str, "%s\n", w->locals);
Printf(str, "%s\n", w->code);
if (Compact_mode == 1)
Wrapper_compact_print(str,f);
Wrapper_compact_print(str, f);
else
Wrapper_pretty_print(str,f);
Wrapper_pretty_print(str, f);
Delete(str);
}
@ -405,14 +406,13 @@ Wrapper_print(Wrapper *w, File *f) {
* present (which may or may not be okay to the caller).
* ----------------------------------------------------------------------------- */
int
Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) {
int 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)) {
if (Getattr(w->localh, name)) {
return -1;
}
Setattr(w->localh,name,decl);
Printf(w->locals,"%s;\n", decl);
Setattr(w->localh, name, decl);
Printf(w->locals, "%s;\n", decl);
return 0;
}
@ -424,24 +424,23 @@ Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *
* to manually construct the 'decl' string before calling.
* ----------------------------------------------------------------------------- */
int
Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) {
int Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) {
va_list ap;
int ret;
int ret;
String *decl;
DOH *obj;
DOH *obj;
decl = NewStringEmpty();
va_start(ap,name);
va_start(ap, name);
obj = va_arg(ap,void *);
obj = va_arg(ap, void *);
while (obj) {
Append(decl,obj);
Append(decl, obj);
Putc(' ', decl);
obj = va_arg(ap, void *);
}
va_end(ap);
ret = Wrapper_add_local(w,name,decl);
ret = Wrapper_add_local(w, name, decl);
Delete(decl);
return ret;
}
@ -452,9 +451,8 @@ Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) {
* Check to see if a local name has already been declared
* ----------------------------------------------------------------------------- */
int
Wrapper_check_local(Wrapper *w, const String_or_char *name) {
if (Getattr(w->localh,name)) {
int Wrapper_check_local(Wrapper *w, const String_or_char *name) {
if (Getattr(w->localh, name)) {
return 1;
}
return 0;
@ -467,27 +465,26 @@ Wrapper_check_local(Wrapper *w, const String_or_char *name) {
* used. Returns the name that was actually selected.
* ----------------------------------------------------------------------------- */
char *
Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) {
char *Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) {
int i;
String *nname = NewString(name);
String *ndecl = NewString(decl);
char *ret;
char *ret;
i = 0;
while (Wrapper_check_local(w,nname)) {
while (Wrapper_check_local(w, nname)) {
Clear(nname);
Printf(nname,"%s%d",name,i);
Printf(nname, "%s%d", name, i);
i++;
}
Replace(ndecl, name, nname, DOH_REPLACE_ID);
Setattr(w->localh,nname,ndecl);
Printf(w->locals,"%s;\n", ndecl);
Setattr(w->localh, nname, ndecl);
Printf(w->locals, "%s;\n", ndecl);
ret = Char(nname);
Delete(nname);
Delete(ndecl);
return ret; /* Note: nname should still exists in the w->localh hash */
return ret; /* Note: nname should still exists in the w->localh hash */
}
@ -499,30 +496,23 @@ Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *
* to manually construct the 'decl' string before calling.
* ----------------------------------------------------------------------------- */
char *
Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...) {
char *Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...) {
va_list ap;
char *ret;
String *decl;
DOH *obj;
DOH *obj;
decl = NewStringEmpty();
va_start(ap,name);
va_start(ap, name);
obj = va_arg(ap,void *);
obj = va_arg(ap, void *);
while (obj) {
Append(decl,obj);
Putc(' ',decl);
Append(decl, obj);
Putc(' ', decl);
obj = va_arg(ap, void *);
}
va_end(ap);
ret = Wrapper_new_local(w,name,decl);
ret = Wrapper_new_local(w, name, decl);
Delete(decl);
return ret;
}