A lot of work on the type system. Experimental language module.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@516 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
33c9ebbdc8
commit
765ad025b9
8 changed files with 609 additions and 96 deletions
|
|
@ -13,6 +13,7 @@
|
|||
#define CPLUS_PRIVATE 2
|
||||
#define CPLUS_PROTECTED 3
|
||||
|
||||
static DOHFile *runtime = 0;
|
||||
static DOHFile *headers = 0;
|
||||
static DOHFile *wrappers = 0;
|
||||
static DOHFile *init = 0;
|
||||
|
|
@ -26,6 +27,15 @@ static DOHString *ModuleName = 0;
|
|||
static int NativeMode = 0;
|
||||
static DOHString *NewName = 0;
|
||||
static DOHHash *RenameHash = 0;
|
||||
static DOHHash *Rules = 0;
|
||||
|
||||
/* Object oriented flags */
|
||||
|
||||
static int InClass = 0;
|
||||
static DOHString *ClassType = 0;
|
||||
static DOHString *ClassName = 0;
|
||||
static DOHString *ClassRename = 0;
|
||||
static int AddMethods = 0;
|
||||
|
||||
/* -------- File inclusion directions -------- */
|
||||
|
||||
|
|
@ -76,18 +86,22 @@ emit_scope(DOH *obj, void *clientdata) {
|
|||
|
||||
|
||||
/* -------- Code blocks -------- */
|
||||
|
||||
/* %{ ... %} directive */
|
||||
static int
|
||||
emit_headerblock(DOH *obj, void *clientdata) {
|
||||
Dump(Getattr(obj,"code"),headers);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* %wrapper %{ ... %} directive */
|
||||
static int
|
||||
emit_wrapperblock(DOH *obj, void *clientdata) {
|
||||
Dump(Getattr(obj,"code"),wrappers);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* %init %{ ... %} directive */
|
||||
static int
|
||||
emit_initblock(DOH *obj, void *clientdata) {
|
||||
Dump(Getattr(obj,"code"),init);
|
||||
|
|
@ -96,18 +110,121 @@ emit_initblock(DOH *obj, void *clientdata) {
|
|||
|
||||
/* ------ Basic C declarations ----- */
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* function
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
emit_function(DOH *obj, void *clientdata) {
|
||||
Printf(stdout,"function\n");
|
||||
DOHString *name, *scriptname, *type, *storage;
|
||||
DOHList *parms;
|
||||
DOHHash *p;
|
||||
SwigWrapper *wf;
|
||||
int numarg = 0, numopt = 0;
|
||||
int i;
|
||||
|
||||
if (ExternMode) return 0;
|
||||
|
||||
name = Getattr(obj,"name"); /* Name of the function */
|
||||
type = Getattr(obj,"type"); /* Return type */
|
||||
parms = Getattr(obj,"parms"); /* Parameters */
|
||||
storage = Getattr(obj,"storage"); /* Storage class */
|
||||
|
||||
/* See if the function is being renamed */
|
||||
if (NewName) scriptname = NewName;
|
||||
else scriptname = name;
|
||||
|
||||
/* Is this a member function? */
|
||||
if (InClass) {
|
||||
/* Handle member functions */
|
||||
/* goto function_exit; */
|
||||
}
|
||||
|
||||
wf = NewSwigWrapper();
|
||||
/* Printf(wf->def,"void %s(args) {\n", Swig_name_wrapper(scriptname));*/
|
||||
|
||||
Printv(wf->def,
|
||||
"static PyObject *", Swig_name_wrapper(scriptname), "(PyObject *self, PyObject *args) {\n",
|
||||
0);
|
||||
|
||||
/* Mapping test */
|
||||
|
||||
{
|
||||
DOH *rules;
|
||||
int mlen = 0;
|
||||
rules = Swig_map_match(Rules,"input",parms, &mlen);
|
||||
Printf(stdout,"match(%d)\n", mlen);
|
||||
}
|
||||
|
||||
/* Loop over all of the function arguments and build pieces of the wrapper function */
|
||||
{
|
||||
DOHString *formatstr; /* Format string for parsing arguments */
|
||||
DOHString *argstr; /* List of arguments */
|
||||
formatstr = NewString("");
|
||||
argstr = NewString("");
|
||||
|
||||
for (p = parms, i=0; p; p = Swig_next(p), i++) {
|
||||
DOHString *pdecl, *pname, *ptype, *value;
|
||||
pname = NewStringf("_arg%d",i);
|
||||
|
||||
ptype = Getattr(p,"type");
|
||||
|
||||
if (SwigType_isarray(ptype)) {
|
||||
int i;
|
||||
int nd;
|
||||
nd = SwigType_array_ndim(ptype);
|
||||
for (i = 0; i < nd; i++) {
|
||||
Printf(stdout,"array[%d] = %s\n", i, SwigType_array_getdim(ptype,i));
|
||||
}
|
||||
}
|
||||
|
||||
pdecl = SwigType_cstr(ptype,pname);
|
||||
|
||||
if ((value = Getattr(p,"value"))) {
|
||||
Printf(pdecl," = %s", value);
|
||||
numopt++;
|
||||
} else {
|
||||
if (numopt > 0) {
|
||||
printf("*** Error: Non-optional argument follows optional argument!\n");
|
||||
}
|
||||
}
|
||||
SwigWrapper_add_local(wf,pdecl,pname);
|
||||
Printf(argstr,",&%s",pname);
|
||||
|
||||
Delete(pname);
|
||||
Delete(pdecl);
|
||||
}
|
||||
|
||||
Printv(wf->code,
|
||||
"if (!PyParseArgs(\"", formatstr, "\"", argstr, ")) {\n",
|
||||
"return NULL;\n",
|
||||
"}\n",
|
||||
0);
|
||||
}
|
||||
|
||||
Printf(wf->code,"}\n");
|
||||
SwigWrapper_print(wf,wrappers);
|
||||
|
||||
function_exit:
|
||||
Delete(NewName);
|
||||
NewName = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* variable
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
emit_variable(DOH *obj, void *clientdata) {
|
||||
Printf(stdout,"variable\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* constant
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
emit_constant(DOH *obj, void *clientdata) {
|
||||
Printf(stdout,"constant\n");
|
||||
|
|
@ -145,7 +262,10 @@ emit_class(DOH *obj, void *clientdata) {
|
|||
Printf(stdout,"class\n");
|
||||
c = Getattr(obj, "child");
|
||||
if (c) {
|
||||
int ic = InClass;
|
||||
InClass = 1;
|
||||
Swig_emit(c,clientdata);
|
||||
InClass = ic;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -197,7 +317,7 @@ static int
|
|||
emit_moduledirective(DOH *obj, void *clientdata) {
|
||||
if (!ModuleName) {
|
||||
ModuleName = Getattr(obj,"name");
|
||||
Incref(ModuleName);
|
||||
DohIncref(ModuleName);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -228,7 +348,7 @@ static int
|
|||
emit_namedirective(DOH *obj, void *clientdata) {
|
||||
if (NewName) Delete(NewName);
|
||||
NewName = Getattr(obj,"name");
|
||||
if (NewName) Incref(NewName);
|
||||
if (NewName) DohIncref(NewName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -287,24 +407,65 @@ emit_cleardirective(DOH *obj, void *clientdata) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
emit_map(DOH *obj, void *clientdata) {
|
||||
DOH *parms;
|
||||
DOH *rulename;
|
||||
DOH *rules;
|
||||
|
||||
rulename = Getattr(obj,"name");
|
||||
parms = Getattr(obj,"parms");
|
||||
rules = Getattr(obj,"child");
|
||||
|
||||
Swig_map_add(Rules,rulename,parms,rules);
|
||||
}
|
||||
|
||||
/* -------- Entry point -------- */
|
||||
|
||||
static char *runtime_banner = "\n\
|
||||
/* ----------------------------------------------------------------------------- \n\
|
||||
Runtime\n\
|
||||
----------------------------------------------------------------------------- */\n";
|
||||
|
||||
static char *header_banner = "\n\
|
||||
/* ----------------------------------------------------------------------------- \n\
|
||||
Headers\n\
|
||||
----------------------------------------------------------------------------- */\n";
|
||||
|
||||
static char *wrapper_banner = "\n\
|
||||
/* ----------------------------------------------------------------------------- \n\
|
||||
Wrappers\n\
|
||||
----------------------------------------------------------------------------- */\n";
|
||||
|
||||
static char *init_banner = "\n\
|
||||
/* ----------------------------------------------------------------------------- \n\
|
||||
Initialization\n\
|
||||
----------------------------------------------------------------------------- */\n";
|
||||
|
||||
void test_emit(DOH *top, void *clientdata) {
|
||||
|
||||
/* Initialization */
|
||||
|
||||
headers = NewString("\n/* --- Headers --- */\n");
|
||||
wrappers = NewString("\n/* --- Wrappers --- */\n");
|
||||
init = NewString("\n/* --- Initialization --- */\n");
|
||||
runtime = NewString(runtime_banner);
|
||||
headers = NewString(header_banner);
|
||||
wrappers = NewString(wrapper_banner);
|
||||
init = NewString(init_banner);
|
||||
|
||||
Rules = NewHash();
|
||||
RenameHash = NewHash();
|
||||
|
||||
Swig_emit(top, clientdata);
|
||||
|
||||
Swig_banner(stdout);
|
||||
|
||||
/* Get the runtime library */
|
||||
Swig_insert_file("python.swg",runtime);
|
||||
|
||||
Dump(runtime,stdout);
|
||||
Dump(headers,stdout);
|
||||
Dump(wrappers,stdout);
|
||||
Dump(init, stdout);
|
||||
Delete(runtime);
|
||||
Delete(headers);
|
||||
Delete(wrappers);
|
||||
Delete(init);
|
||||
|
|
@ -345,6 +506,7 @@ static SwigRule rules[] = {
|
|||
"typemapcopy", emit_typemapcopy,
|
||||
"applydirective", emit_applydirective,
|
||||
"cleardirective", emit_cleardirective,
|
||||
"map", emit_map,
|
||||
NULL, NULL
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue