beautify/format source code with gnu indent
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9505 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
cb8ae0ab98
commit
68891541d1
72 changed files with 27038 additions and 28016 deletions
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -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,"&","&");
|
||||
Replaceall(o,"<","<");
|
||||
Replaceall(o,">",">");
|
||||
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, "&", "&");
|
||||
Replaceall(o, "<", "<");
|
||||
Replaceall(o, ">", ">");
|
||||
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - %s\n", Getattr(obj, k), k, o);
|
||||
Delete(o);
|
||||
} else {
|
||||
DOH *o;
|
||||
char *trunc = "";
|
||||
if (DohIsString(Getattr(obj,k))) {
|
||||
o = Str(Getattr(obj,k));
|
||||
if (DohIsString(Getattr(obj, k))) {
|
||||
o = Str(Getattr(obj, k));
|
||||
if (Len(o) > 70) {
|
||||
trunc = "...";
|
||||
}
|
||||
Replaceall(o,"&","&");
|
||||
Replaceall(o,"<","<");
|
||||
Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc);
|
||||
Replaceall(o, "&", "&");
|
||||
Replaceall(o, "<", "<");
|
||||
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
|
||||
Delete(o);
|
||||
} else {
|
||||
Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k));
|
||||
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,"<","<");
|
||||
Printf(os," <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc);
|
||||
Replaceall(o, "<", "<");
|
||||
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
|
||||
Delete(o);
|
||||
} else {
|
||||
Printf(os," <a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k));
|
||||
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,"<","<");
|
||||
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(o));
|
||||
Replaceall(o, "<", "<");
|
||||
Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(o));
|
||||
Delete(o);
|
||||
} else if (DohIsSequence(obj)) {
|
||||
int i;
|
||||
String *os = NewString("");
|
||||
Printf(os,"List [\n");
|
||||
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,"<","<");
|
||||
Printf(os," <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o,i,s, trunc);
|
||||
Replaceall(o, "<", "<");
|
||||
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc);
|
||||
Delete(s);
|
||||
} else {
|
||||
Printf(os," <a href=\"data.html?n=0x%x\">?</a> [%d] - 0x%x\n", o, i, o);
|
||||
Printf(os, " <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
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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, "<", "<");
|
||||
/* Do first to avoid aliasing errors. */
|
||||
Replaceall(o, "&", "&");
|
||||
Replaceall(o, "<", "<");
|
||||
Replaceall(o, "\"", """);
|
||||
Replaceall(o, "\\", "\\\\");
|
||||
Replaceall(o, "\n", " ");
|
||||
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, "<", "<" );
|
||||
/* Do first to avoid aliasing errors. */
|
||||
Replaceall( o, "&", "&" );
|
||||
Replaceall( o, "<", "<" );
|
||||
Replaceall( o, "\"", """ );
|
||||
Replaceall( o, "\\", "\\\\" );
|
||||
Replaceall( o, "\n", " " );
|
||||
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, "&", "&" );
|
||||
Replaceall( escaped_str, "<", "<" );
|
||||
Replaceall( escaped_str, "\"", """ );
|
||||
Replaceall( escaped_str, "\\", "\\\\" );
|
||||
Replaceall( escaped_str, "\n", " " );
|
||||
}
|
||||
return escaped_str;
|
||||
}
|
||||
String *Xml_escape_string(String *str) {
|
||||
String *escaped_str = 0;
|
||||
if (str) {
|
||||
escaped_str = NewString(str);
|
||||
Replaceall(escaped_str, "&", "&");
|
||||
Replaceall(escaped_str, "<", "<");
|
||||
Replaceall(escaped_str, "\"", """);
|
||||
Replaceall(escaped_str, "\\", "\\\\");
|
||||
Replaceall(escaped_str, "\n", " ");
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue