Major reworking of the Wrapper object. It is now a DOH object.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@948 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-11-22 23:14:01 +00:00
commit 267beb814f
14 changed files with 717 additions and 653 deletions

View file

@ -215,8 +215,8 @@ void Swig_cresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_char
Printf(fcall,"%s = (%s) &_result_ref;\n", name, SwigType_lstr(t,0));
}
if (Replace(w->code,"$function",fcall, DOH_REPLACE_ANY) == 0) {
Printv(w->code, fcall, 0);
if (Replace(w,"$function",fcall, DOH_REPLACE_ANY) == 0) {
Printv(w, fcall, 0);
}
Delete(fcall);
}
@ -278,8 +278,8 @@ void Swig_cppresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_cha
break;
}
if (Replace(w->code,"$function",fcall, DOH_REPLACE_ANY) == 0) {
Printv(w->code, fcall, 0);
if (Replace(w,"$function",fcall, DOH_REPLACE_ANY) == 0) {
Printv(w, fcall, 0);
}
Delete(fcall);
}
@ -519,18 +519,19 @@ Swig_cfunction_wrapper(String_or_char *funcname,
w = NewWrapper();
/* Set the name of the function */
Wrapper_Setname(w,funcname);
Setname(w,funcname);
l = CopyParmList(parms);
fix_parm_names(l);
Printf(w->def,"%s %s(%s) {", SwigType_str(rtype,0), funcname, ParmList_str(l));
Printf(w,"%s %s(%s) {\n", SwigType_str(rtype,0), funcname, ParmList_str(l));
Printf(w,"$locals\n");
if (code) {
Printv(w->code, code, "\n", 0);
Printv(w, code, "\n", 0);
}
Printf(w->code,"}\n");
Wrapper_Settype(w,rtype);
Wrapper_Setparms(w,l);
Printf(w,"}\n");
Setattr(w,"type",rtype);
Setattr(w,"parms",l);
Delete(l);
return w;
}
@ -557,7 +558,7 @@ Swig_cmethod_wrapper(String_or_char *classname,
w = NewWrapper();
/* Set the name of the function */
Wrapper_Setname(w,Swig_name_member(classname, methodname));
Setname(w,Swig_name_member(classname, methodname));
l = CopyParmList(parms);
t = NewString(classname);
@ -569,30 +570,31 @@ Swig_cmethod_wrapper(String_or_char *classname,
l = p;
fix_parm_names(l);
Printf(w->def,"%s %s(%s) {", SwigType_str(rtype,0), Swig_name_member(classname, methodname), ParmList_str(l));
Printf(w,"%s %s(%s) {\n", SwigType_str(rtype,0), Swig_name_member(classname, methodname), ParmList_str(l));
Printf(w,"$locals\n");
if (!code) {
/* No code supplied. Write a function manually */
if (SwigType_type(rtype) != T_VOID) {
Printf(w->code,"return ");
Printf(w,"return ");
}
Printf(w->code,"self->%s(", methodname);
Printf(w,"self->%s(", methodname);
p = Getnext(l);
while (p) {
Printf(w->code,"%s", Getname(p));
Printf(w,"%s", Getname(p));
p = Getnext(p);
if (p)
Printf(w->code,",");
Printf(w,",");
}
Printf(w->code,");\n");
Printf(w->code,"}\n");
Printf(w,");\n");
Printf(w,"}\n");
} else {
Printv(w->code, code, "\n", 0);
Printf(w->code,"}\n");
Printv(w, code, "\n", 0);
Printf(w,"}\n");
}
Wrapper_Settype(w,rtype);
Wrapper_Setparms(w,l);
Setattr(w,"type",rtype);
Setattr(w,"parms",l);
Delete(l);
return w;
}
@ -616,7 +618,7 @@ Swig_cconstructor_wrapper(String_or_char *classname,
w = NewWrapper();
/* Set the name of the function */
Wrapper_Setname(w,Swig_name_construct(classname));
Setname(w,Swig_name_construct(classname));
l = CopyParmList(parms);
t = NewString(classname);
@ -625,17 +627,18 @@ Swig_cconstructor_wrapper(String_or_char *classname,
/* Patch up the argument names */
fix_parm_names(l);
Printf(w->def,"%s %s(%s) {", SwigType_str(t,0), Swig_name_construct(classname), ParmList_str(l));
Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_construct(classname), ParmList_str(l));
Printf(w,"$locals\n");
if (!code) {
/* No code supplied. Write a function manually */
Printf(w->code,"return (%s) calloc(1,sizeof(%s));\n", SwigType_str(t,0), classname);
Printf(w,"return (%s) calloc(1,sizeof(%s));\n", SwigType_str(t,0), classname);
} else {
Printv(w->code, code, "\n", 0);
Printv(w, code, "\n", 0);
}
Printf(w->code,"}\n");
Wrapper_Settype(w,t);
Wrapper_Setparms(w,l);
Printf(w,"}\n");
Setattr(w,"type",t);
Setattr(w,"parms",l);
Delete(l);
Delete(t);
return w;
@ -660,7 +663,7 @@ Swig_cppconstructor_wrapper(String_or_char *classname,
w = NewWrapper();
/* Set the name of the function */
Wrapper_Setname(w,Swig_name_construct(classname));
Setname(w,Swig_name_construct(classname));
l = CopyParmList(parms);
t = NewString(classname);
@ -669,29 +672,30 @@ Swig_cppconstructor_wrapper(String_or_char *classname,
/* Patch up the argument names */
fix_parm_names(l);
Printf(w->def,"%s %s(%s) {", SwigType_str(t,0), Swig_name_construct(classname), ParmList_str(l));
Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_construct(classname), ParmList_str(l));
Printf(w,"$locals\n");
if (!code) {
/* No code supplied. Write a function manually */
Printf(w->code,"return new %s", SwigType_str(t,0));
Printf(w,"return new %s", SwigType_str(t,0));
p = l;
if (p) {
Printf(w->code,"(");
Printf(w,"(");
while (p) {
Printf(w->code,"%s", Getname(p));
Printf(w,"%s", Getname(p));
p = Getnext(p);
if (p)
Printf(w->code,",");
Printf(w,",");
}
Printf(w->code,")");
Printf(w,")");
}
Printf(w->code,";\n");
Printf(w,";\n");
} else {
Printv(w->code, code, "\n", 0);
Printv(w, code, "\n", 0);
}
Printf(w->code,"}\n");
Wrapper_Settype(w,t);
Wrapper_Setparms(w,l);
Printf(w,"}\n");
Setattr(w,"type",t);
Setattr(w,"parms",l);
Delete(l);
Delete(t);
return w;
@ -716,7 +720,7 @@ Swig_cdestructor_wrapper(String_or_char *classname,
w = NewWrapper();
/* Set the name of the function */
Wrapper_Setname(w,Swig_name_destroy(classname));
Setname(w, Swig_name_destroy(classname));
t = NewString(classname);
SwigType_add_pointer(t);
@ -726,17 +730,18 @@ Swig_cdestructor_wrapper(String_or_char *classname,
t = NewString("void");
Printf(w->def,"%s %s(%s) {", SwigType_str(t,0), Swig_name_destroy(classname), ParmList_str(l));
Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_destroy(classname), ParmList_str(l));
Printf(w,"$locals\n");
if (!code) {
/* No code supplied. Write a function manually */
Printf(w->code,"free((char *) self);\n");
Printf(w,"free((char *) self);\n");
} else {
Printv(w->code, code, "\n", 0);
Printv(w, code, "\n", 0);
}
Printf(w->code,"}\n");
Wrapper_Settype(w,t);
Wrapper_Setparms(w,l);
Printf(w,"}\n");
Setattr(w,"type",t);
Setattr(w,"parms",l);
Delete(l);
Delete(t);
return w;
@ -761,7 +766,7 @@ Swig_cppdestructor_wrapper(String_or_char *classname,
w = NewWrapper();
/* Set the name of the function */
Wrapper_Setname(w,Swig_name_destroy(classname));
Setname(w, Swig_name_destroy(classname));
t = NewString(classname);
SwigType_add_pointer(t);
@ -772,17 +777,18 @@ Swig_cppdestructor_wrapper(String_or_char *classname,
t = NewString("void");
Printf(w->def,"%s %s(%s) {", SwigType_str(t,0), Swig_name_destroy(classname), ParmList_str(l));
Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_destroy(classname), ParmList_str(l));
Printf(w,"$locals\n");
if (!code) {
/* No code supplied. Write a function manually */
Printf(w->code,"delete self;\n");
Printf(w,"delete self;\n");
} else {
Printv(w->code, code, "\n", 0);
Printv(w, code, "\n", 0);
}
Printf(w->code,"}\n");
Wrapper_Settype(w,t);
Wrapper_Setparms(w,l);
Printf(w,"}\n");
Setattr(w,"type",t);
Setattr(w,"parms",l);
Delete(l);
Delete(t);
return w;
@ -809,7 +815,7 @@ Swig_cmemberset_wrapper(String_or_char *classname,
w = NewWrapper();
/* Set the name of the function */
Wrapper_Setname(w,Swig_name_member(classname, Swig_name_set(membername)));
Setname(w, Swig_name_member(classname, Swig_name_set(membername)));
t = NewString(classname);
SwigType_add_pointer(t);
@ -821,20 +827,20 @@ Swig_cmemberset_wrapper(String_or_char *classname,
p = NewParm(lt,"value");
Setnext(l,p);
/* Printf(w->def,"%s %s(%s) {", SwigType_str(lt,0), Wrapper_Getname(w), ParmList_str(l)); */
Printf(w->def,"void %s(%s) {", Wrapper_Getname(w), ParmList_str(l));
Printf(w,"void %s(%s) {\n", Getname(w), ParmList_str(l));
Printf(w,"$locals\n");
if (!code) {
/* No code supplied. Write a function manually */
Printf(w->code,"self->%s = %s;\n", membername, Swig_clocal_deref(lt,"value"));
Printf(w->code,"return %s self->%s;\n", Swig_clocal_assign(lt,""), membername);
Printf(w,"self->%s = %s;\n", membername, Swig_clocal_deref(lt,"value"));
Printf(w,"return %s self->%s;\n", Swig_clocal_assign(lt,""), membername);
} else {
Printv(w->code, code, "\n", 0);
Printv(w, code, "\n", 0);
}
Printf(w->code,"}\n");
Printf(w,"}\n");
/* Wrapper_Settype(w,lt); */
Wrapper_Settype(w,"void");
Wrapper_Setparms(w,l);
Setattr(w,"type","void");
Setattr(w,"parms", l);
Delete(l);
Delete(lt);
return w;
@ -862,7 +868,7 @@ Swig_cmemberget_wrapper(String_or_char *classname,
w = NewWrapper();
/* Set the name of the function */
Wrapper_Setname(w,Swig_name_member(classname, Swig_name_get(membername)));
Setname(w,Swig_name_member(classname, Swig_name_get(membername)));
t = NewString(classname);
SwigType_add_pointer(t);
@ -871,17 +877,18 @@ Swig_cmemberget_wrapper(String_or_char *classname,
Delete(t);
lt = Swig_clocal_type(type);
Printf(w->def,"%s %s(%s) {", SwigType_str(lt,0), Wrapper_Getname(w), ParmList_str(l));
Printf(w,"%s %s(%s) {\n", SwigType_str(lt,0), Getname(w), ParmList_str(l));
Printf(w,"$locals\n");
if (!code) {
/* No code supplied. Write a function manually */
Printf(w->code,"return %s self->%s;", Swig_clocal_assign(lt,""), membername);
Printf(w,"return %s self->%s;", Swig_clocal_assign(lt,""), membername);
} else {
Printv(w->code, code, "\n", 0);
Printv(w, code, "\n", 0);
}
Printf(w->code,"}\n");
Wrapper_Settype(w,lt);
Wrapper_Setparms(w,l);
Printf(w,"}\n");
Setattr(w,"type",lt);
Setattr(w,"parms",l);
Delete(l);
Delete(lt);
return w;
@ -906,28 +913,29 @@ Swig_cvarset_wrapper(String_or_char *varname,
w = NewWrapper();
/* Set the name of the function */
Wrapper_Setname(w,Swig_name_set(varname));
Setname(w,Swig_name_set(varname));
lt = Swig_clocal_type(type);
p = NewParm(lt,"value");
l = p;
Printf(w->def,"%s %s(%s) {", SwigType_str(lt,0), Wrapper_Getname(w), ParmList_str(l));
Printf(w,"%s %s(%s) {\n", SwigType_str(lt,0), Getname(w), ParmList_str(l));
Printf(w,"$locals");
if (!code) {
/* No code supplied. Write a function manually */
Printf(w->code,"%s = %s;\n", varname, Swig_clocal_deref(lt,"value"));
Printf(w->code,"return %s;\n", Swig_clocal_assign(lt,varname));
Printf(w,"%s = %s;\n", varname, Swig_clocal_deref(lt,"value"));
Printf(w,"return %s;\n", Swig_clocal_assign(lt,varname));
} else {
Printv(w->code, code, "\n", 0);
Replace(w->code,"$target",varname, DOH_REPLACE_ANY);
Replace(w->code,"$source","value", DOH_REPLACE_ANY);
Replace(w->code,"$ltype", SwigType_str(lt,""), DOH_REPLACE_ANY);
Replace(w->code,"$rtype", SwigType_str(type,""), DOH_REPLACE_ANY);
Printv(w, code, "\n", 0);
Replace(w,"$target",varname, DOH_REPLACE_ANY);
Replace(w,"$source","value", DOH_REPLACE_ANY);
Replace(w,"$ltype", SwigType_str(lt,""), DOH_REPLACE_ANY);
Replace(w,"$rtype", SwigType_str(type,""), DOH_REPLACE_ANY);
}
Printf(w->code,"}\n");
Wrapper_Settype(w,lt);
Wrapper_Setparms(w,l);
Printf(w,"}\n");
Setattr(w,"type",lt);
Setattr(w,"parms",l);
Delete(l);
Delete(lt);
return w;
@ -951,21 +959,22 @@ Swig_cvarget_wrapper(String_or_char *varname,
w = NewWrapper();
/* Set the name of the function */
Wrapper_Setname(w, Swig_name_get(varname));
Setname(w,Swig_name_get(varname));
lt = Swig_clocal_type(type);
Printf(w->def,"%s %s(%s) {", SwigType_str(lt,0), Wrapper_Getname(w), ParmList_str(l));
Printf(w,"%s %s(%s) {\n", SwigType_str(lt,0), Getname(w), ParmList_str(l));
Printf(w,"$locals");
if (!code) {
/* No code supplied. Write a function manually */
Printf(w->code,"return %s;", Swig_clocal_assign(type,varname));
Printf(w,"return %s;", Swig_clocal_assign(type,varname));
} else {
Printv(w->code, code, "\n", 0);
Printv(w, code, "\n", 0);
}
Printf(w->code,"}\n");
Wrapper_Settype(w,lt);
Wrapper_Setparms(w,l);
Printf(w,"}\n");
Setattr(w,"type",lt);
Setattr(w,"parms",l);
Delete(l);
Delete(lt);
return w;

View file

@ -263,31 +263,15 @@ extern void Swig_dump_rules();
/* -- Wrapper function Object */
typedef struct {
SwigType *_type;
ParmList *_parms;
String *_name;
Hash *localh;
String *def;
String *locals;
String *code;
} Wrapper;
typedef DOH Wrapper;
extern Wrapper *NewWrapper();
extern void DelWrapper(Wrapper *w);
extern void Wrapper_pretty_print(String *str, File *f);
extern void Wrapper_print(Wrapper *w, File *f);
extern int Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl);
extern int Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...);
extern int Wrapper_check_local(Wrapper *w, const String_or_char *name);
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 SwigType *Wrapper_Gettype(Wrapper *w);
extern void Wrapper_Settype(Wrapper *w, SwigType *t);
extern ParmList *Wrapper_Getparms(Wrapper *w);
extern void Wrapper_Setparms(Wrapper *w, ParmList *l);
extern char *Wrapper_Getname(Wrapper *w);
extern void Wrapper_Setname(Wrapper *w, String_or_char *name);
/* --- Naming functions --- */

View file

@ -429,7 +429,7 @@ char *Swig_typemap_lookup(char *op, SwigType *type, String_or_char *pname, Strin
DOHString *dim = SwigType_array_getdim(type,i);
sprintf(temp,"$dim%d",i);
if (f)
Replace(f->locals,temp,dim, DOH_REPLACE_ANY);
Replace(Getattr(f,"locals"),temp,dim, DOH_REPLACE_ANY);
Replace(s,temp,dim,DOH_REPLACE_ANY);
}
}

View file

@ -19,42 +19,25 @@ static char cvsroot[] = "$Header$";
#include "swig.h"
#include <ctype.h>
/* -----------------------------------------------------------------------------
* NewWrapper()
*
* Create a new wrapper function object.
* ----------------------------------------------------------------------------- */
#include "dohobj.h"
Wrapper *
NewWrapper() {
Wrapper *w;
w = (Wrapper *) malloc(sizeof(Wrapper));
w->localh = NewHash();
w->locals = NewString("");
w->code = NewString("");
w->def = NewString("");
w->_type = 0;
w->_parms = 0;
w->_name = 0;
return w;
}
typedef struct {
Hash *attr; /* Attributes */
Hash *localh; /* Hash of local variable names */
String *code; /* Code string */
} WrapObj;
/* -----------------------------------------------------------------------------
* DelWrapper()
*
* Delete a wrapper function object.
* ----------------------------------------------------------------------------- */
void
DelWrapper(Wrapper *w) {
static void
DelWrapper(DOH *wo) {
WrapObj *w = (WrapObj *) ObjData(wo);
Delete(w->localh);
Delete(w->locals);
Delete(w->code);
Delete(w->def);
Delete(w->_type);
Delete(w->_parms);
Delete(w->_name);
free(w);
Delete(w->attr);
DohFree(w);
}
/* -----------------------------------------------------------------------------
@ -139,20 +122,37 @@ Wrapper_pretty_print(String *str, File *f) {
/* -----------------------------------------------------------------------------
* Wrapper_print()
* Wrapper_str()
*
* Print out a wrapper function. Does pretty printing as well.
* Create a string representation of the wrapper function.
* ----------------------------------------------------------------------------- */
void
Wrapper_print(Wrapper *w, File *f) {
String *str;
static String *
Wrapper_str(DOH *wo) {
String *s, *s1;
WrapObj *w = (WrapObj *) ObjData(wo);
s = NewString(w->code);
s1 = NewString("");
Replace(s,"$locals", Getattr(w->attr,"locals"), DOH_REPLACE_ANY);
Wrapper_pretty_print(s,s1);
Delete(s);
return s1;
}
str = NewString("");
Printf(str,"%s\n", w->def);
Printf(str,"%s\n", w->locals);
Printf(str,"%s\n", w->code);
Wrapper_pretty_print(str,f);
/* -----------------------------------------------------------------------------
* Wrapper_dump()
*
* Serialize on out
* ----------------------------------------------------------------------------- */
static int
Wrapper_dump(DOH *wo, DOH *out) {
String *s;
int len;
s = Wrapper_str(wo);
len = Dump(s,out);
Delete(s);
return len;
}
/* -----------------------------------------------------------------------------
@ -163,13 +163,14 @@ Wrapper_print(Wrapper *w, File *f) {
* ----------------------------------------------------------------------------- */
int
Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) {
Wrapper_add_local(Wrapper *wo, const String_or_char *name, const String_or_char *decl) {
WrapObj *w = (WrapObj *) ObjData(wo);
/* See if the local has already been declared */
if (Getattr(w->localh,name)) {
return -1;
}
Setattr(w->localh,name,decl);
Printf(w->locals,"%s;\n", decl);
Printf(Getattr(w->attr,"locals"),"%s;\n", decl);
return 0;
}
@ -182,11 +183,12 @@ Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *
* ----------------------------------------------------------------------------- */
int
Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) {
Wrapper_add_localv(Wrapper *wo, const String_or_char *name, ...) {
va_list ap;
int ret;
String *decl;
DOH *obj;
WrapObj *w = (WrapObj *) ObjData(wo);
decl = NewString("");
va_start(ap,name);
@ -198,7 +200,7 @@ Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) {
}
va_end(ap);
ret = Wrapper_add_local(w,name,decl);
ret = Wrapper_add_local(wo,name,decl);
Delete(decl);
return ret;
}
@ -210,7 +212,8 @@ Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) {
* ----------------------------------------------------------------------------- */
int
Wrapper_check_local(Wrapper *w, const String_or_char *name) {
Wrapper_check_local(Wrapper *wo, const String_or_char *name) {
WrapObj *w = (WrapObj *) ObjData(wo);
if (Getattr(w->localh,name)) {
return 1;
}
@ -225,12 +228,12 @@ Wrapper_check_local(Wrapper *w, const String_or_char *name) {
* ----------------------------------------------------------------------------- */
char *
Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) {
Wrapper_new_local(Wrapper *wo, const String_or_char *name, const String_or_char *decl) {
int i;
char *ret;
String *nname = NewString(name);
String *ndecl = NewString(decl);
char *ret;
WrapObj *w = (WrapObj *) ObjData(wo);
i = 0;
while (Wrapper_check_local(w,nname)) {
@ -240,7 +243,7 @@ Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *
}
Replace(ndecl, name, nname, DOH_REPLACE_ID);
Setattr(w->localh,nname,ndecl);
Printf(w->locals,"%s;\n", ndecl);
Printf(Getattr(w->attr,"locals"),"%s;\n", ndecl);
ret = Char(nname);
Delete(nname);
Delete(ndecl);
@ -257,11 +260,12 @@ Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *
* ----------------------------------------------------------------------------- */
char *
Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...) {
Wrapper_new_localv(Wrapper *wo, const String_or_char *name, ...) {
va_list ap;
char *ret;
String *decl;
DOH *obj;
WrapObj *w = (WrapObj *) ObjData(wo);
decl = NewString("");
va_start(ap,name);
@ -273,71 +277,188 @@ Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...) {
}
va_end(ap);
ret = Wrapper_new_local(w,name,decl);
ret = Wrapper_new_local(wo,name,decl);
Delete(decl);
return ret;
}
/* -----------------------------------------------------------------------------
* Wrapper_Gettype()
* Wrapper_Getattr()
* ----------------------------------------------------------------------------- */
SwigType *
Wrapper_Gettype(Wrapper *w) {
return w->_type;
static DOH *
Wrapper_getattr(Wrapper *wo, DOH *k) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Getattr(w->attr,k);
}
/* -----------------------------------------------------------------------------
* Wrapper_Settype()
* Wrapper_Delattr()
* ----------------------------------------------------------------------------- */
void
Wrapper_Settype(Wrapper *w, SwigType *t) {
Delete(w->_type);
w->_type = NewString(t);
static int
Wrapper_delattr(Wrapper *wo, DOH *k) {
WrapObj *w = (WrapObj *) ObjData(wo);
Delattr(w->attr,k);
return 0;
}
/* -----------------------------------------------------------------------------
* Wrapper_Getparms()
* Wrapper_Setattr()
* ----------------------------------------------------------------------------- */
ParmList *
Wrapper_Getparms(Wrapper *w) {
return w->_parms;
static int
Wrapper_setattr(Wrapper *wo, DOH *k, DOH *obj) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Setattr(w->attr,k,obj);
}
/* -----------------------------------------------------------------------------
* Wrapper_Setparms()
* Wrapper_firstkey()
* ----------------------------------------------------------------------------- */
void
Wrapper_Setparms(Wrapper *w, ParmList *l) {
Delete(w->_parms);
w->_parms = l;
DohIncref(l);
static DOH *
Wrapper_firstkey(Wrapper *wo) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Firstkey(w->attr);
}
/* -----------------------------------------------------------------------------
* Wrapper_Getname()
* Wrapper_firstkey()
* ----------------------------------------------------------------------------- */
char *
Wrapper_Getname(Wrapper *w) {
return Char(w->_name);
static DOH *
Wrapper_nextkey(Wrapper *wo) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Nextkey(w->attr);
}
/* File methods. These simply operate on the code string */
static int
Wrapper_read(Wrapper *wo, void *buffer, int nbytes) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Read(w->code,buffer,nbytes);
}
static int
Wrapper_write(Wrapper *wo, void *buffer, int nbytes) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Write(w->code,buffer,nbytes);
}
static int
Wrapper_putc(Wrapper *wo, int ch) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Putc(ch, w->code);
}
static int
Wrapper_getc(Wrapper *wo) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Getc(w->code);
}
static int
Wrapper_ungetc(Wrapper *wo, int ch) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Ungetc(ch, w->code);
}
static int
Wrapper_seek(Wrapper *wo, long offset, int whence) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Seek(w->code, offset, whence);
}
static long
Wrapper_tell(Wrapper *wo) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Tell(w->code);
}
/* String method */
static int Wrapper_replace(DOH *wo, DOH *tok, DOH *rep, int flags) {
WrapObj *w = (WrapObj *) ObjData(wo);
return Replace(w->code, tok, rep, flags);
}
/* -----------------------------------------------------------------------------
* Wrapper_Setname()
* type information
* ----------------------------------------------------------------------------- */
void
Wrapper_Setname(Wrapper *w, String_or_char *n) {
Delete(w->_name);
w->_name = NewString(n);
static DohHashMethods WrapperHashMethods = {
Wrapper_getattr,
Wrapper_setattr,
Wrapper_delattr,
Wrapper_firstkey,
Wrapper_nextkey,
};
static DohFileMethods WrapperFileMethods = {
Wrapper_read,
Wrapper_write,
Wrapper_putc,
Wrapper_getc,
Wrapper_ungetc,
Wrapper_seek,
Wrapper_tell,
0, /* close */
};
static DohStringMethods WrapperStringMethods = {
Wrapper_replace,
0,
};
static DohObjInfo WrapperType = {
"Wrapper", /* objname */
DelWrapper, /* doh_del */
0, /* doh_copy */
0, /* doh_clear */
Wrapper_str, /* doh_str */
0, /* doh_data */
0, /* doh_dump */
0, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_setfile */
0, /* doh_getfile */
0, /* doh_setline */
0, /* doh_getline */
&WrapperHashMethods, /* doh_mapping */
0, /* doh_sequence */
&WrapperFileMethods, /* doh_file */
&WrapperStringMethods, /* doh_string */
0, /* doh_positional */
0,
};
/* -----------------------------------------------------------------------------
* NewWrapper()
*
* Create a new wrapper function object.
* ----------------------------------------------------------------------------- */
#define DOHTYPE_WRAPPER 0xa
Wrapper *
NewWrapper() {
WrapObj *w;
static int init = 0;
if (!init) {
DohRegisterType(DOHTYPE_WRAPPER, &WrapperType);
init = 1;
}
w = (WrapObj *) DohMalloc(sizeof(WrapObj));
w->localh = NewHash();
w->code = NewString("");
w->attr= NewHash();
Setattr(w->attr,"locals","");
Setattr(w->attr,"wrapcode", w->code);
return DohObjMalloc(DOHTYPE_WRAPPER, w);
}