Merge branch 'master' into C

Merge with the latest master before making more changes.
This commit is contained in:
Vadim Zeitlin 2021-10-04 16:03:36 +02:00
commit ac4f3c78be
1118 changed files with 15064 additions and 34376 deletions

File diff suppressed because it is too large Load diff

View file

@ -227,7 +227,7 @@ int CFFI::classHandler(Node *n) {
int CFFI::constructorHandler(Node *n) {
#ifdef CFFI_DEBUG
Printf(stderr, "constructor %s\n", Getattr(n, "name"));
Printf(stderr, "constructor %s\n and %s and %s", Getattr(n, "kind"), Getattr(n, "sym:name"), Getattr(n, "allegrocl:old-sym:name"));
Printf(stderr, "constructor %s\n and %s", Getattr(n, "kind"), Getattr(n, "sym:name"));
#endif
Setattr(n, "cffi:constructorfunction", "1");
// Let SWIG generate a global forwarding function.
@ -426,7 +426,6 @@ void CFFI::cleanupFunction(Node *n, Wrapper *f, ParmList *parms) {
if (GetFlag(n, "feature:new")) {
String *tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0);
if (tm) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NULL);
Delete(tm);
}
@ -546,7 +545,6 @@ int CFFI::functionWrapper(Node *n) {
/* See if there is any return cleanup code */
String *tm = 0;
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}

File diff suppressed because it is too large Load diff

View file

@ -1,515 +0,0 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* clisp.cxx
*
* clisp language module for SWIG.
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
static const char *usage = "\
CLISP Options (available with -clisp)\n\
-extern-all - Create clisp definitions for all the functions and\n\
global variables otherwise only definitions for\n\
externed functions and variables are created.\n\
-generate-typedef - Use def-c-type to generate shortcuts according to the\n\
typedefs in the input.\n\
";
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 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(Node *n, 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[]) {
int i;
Preprocessor_define("SWIGCLISP 1", 0);
SWIG_library_directory("clisp");
SWIG_config_file("clisp.swg");
generate_typedef_flag = 0;
extern_all_flag = 0;
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-help")) {
Printf(stdout, "%s\n", usage);
} else if ((Strcmp(argv[i], "-extern-all") == 0)) {
extern_all_flag = 1;
Swig_mark_arg(i);
} else if ((Strcmp(argv[i], "-generate-typedef") == 0)) {
generate_typedef_flag = 1;
Swig_mark_arg(i);
}
}
}
int CLISP::top(Node *n) {
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) {
Printf(stderr, "Unable to determine outfile\n");
SWIG_exit(EXIT_FAILURE);
}
output_filename = NewStringf("%s%s.lisp", SWIG_output_directory(), module);
f_cl = NewFile(output_filename, "w+", SWIG_output_files());
if (!f_cl) {
FileErrorDisplay(output_filename);
SWIG_exit(EXIT_FAILURE);
}
Swig_register_filebyname("header", f_null);
Swig_register_filebyname("begin", f_null);
Swig_register_filebyname("runtime", f_null);
Swig_register_filebyname("wrapper", f_null);
String *header = NewString("");
Swig_banner_target_lang(header, ";;");
Printf(header, "\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");
}
//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);
long end = Tell(f_cl);
for (len--; len >= 0; len--) {
end--;
(void)Seek(f_cl, len, SEEK_SET);
int ch = Getc(f_cl);
(void)Seek(f_cl, end, SEEK_SET);
Putc(ch, f_cl);
}
Seek(f_cl, 0, SEEK_SET);
Write(f_cl, Char(header), Len(header));
Delete(f_cl);
return SWIG_OK;
}
int CLISP::functionWrapper(Node *n) {
is_function = 1;
String *storage = Getattr(n, "storage");
if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && !Swig_storage_isexternc(n))))
return SWIG_OK;
String *func_name = Getattr(n, "sym:name");
ParmList *pl = Getattr(n, "parms");
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++) {
String *argname = Getattr(p, "name");
// SwigType *argtype;
String *ffitype = get_ffi_type(n, Getattr(p, "type"));
int tempargname = 0;
if (!argname) {
argname = NewStringf("arg%d", argnum);
tempargname = 1;
}
if (!first) {
Printf(f_cl, "\n\t\t");
}
Printf(f_cl, "(%s %s)", argname, ffitype);
first = 0;
Delete(ffitype);
if (tempargname)
Delete(argname);
}
if (ParmList_len(pl) != 0) {
Printf(f_cl, ")\n"); /* finish arg list */
}
String *ffitype = get_ffi_type(n, 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");
Printf(f_cl, "\n(defconstant %s %s)\n", name, converted_value);
Append(entries, name);
Delete(converted_value);
return SWIG_OK;
}
int CLISP::variableWrapper(Node *n) {
is_function = 0;
String *storage = Getattr(n, "storage");
if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && !Swig_storage_isexternc(n))))
return SWIG_OK;
String *var_name = Getattr(n, "sym:name");
String *lisp_type = get_ffi_type(n, 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);
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(n, Getattr(n, "type")));
}
return Language::typedefHandler(n);
}
int CLISP::enumDeclaration(Node *n) {
if (getCurrentClass() && (cplus_mode != PUBLIC))
return SWIG_NOWRAP;
is_function = 0;
String *name = Getattr(n, "sym:name");
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);
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");
if (Strcmp(kind, "struct")) {
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)) {
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"));
SWIG_exit(EXIT_FAILURE);
}
String *temp = Copy(Getattr(c, "decl"));
if (temp) {
Append(temp, Getattr(c, "type")); //appending type to the end, otherwise wrong type
String *lisp_type = get_ffi_type(n, temp);
Delete(temp);
String *slot_name = Getattr(c, "sym:name");
Printf(f_cl, "\n\t(%s %s)", slot_name, lisp_type);
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 *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;
}
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);
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;
}
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;
}
String *CLISP::get_ffi_type(Node *n, SwigType *ty) {
Node *node = NewHash();
Setattr(node, "type", ty);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("in", node, "", 0);
Delete(node);
if (tm) {
return NewString(tm);
} else if (SwigType_ispointer(ty)) {
SwigType *cp = Copy(ty);
SwigType_del_pointer(cp);
String *inner_type = get_ffi_type(n, cp);
if (SwigType_isfunction(cp)) {
return inner_type;
}
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);
}
Delete(base_name);
Delete(base);
Delete(cp);
Delete(inner_type);
return str;
} else if (SwigType_isarray(ty)) {
SwigType *cp = Copy(ty);
String *array_dim = SwigType_array_getdim(ty, 0);
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(n, cp);
Delete(cp);
return str;
} else {
SwigType_pop_arrays(cp);
String *inner_type = get_ffi_type(n, cp);
Delete(cp);
int ndim = SwigType_array_ndim(ty);
String *dimension;
if (ndim == 1) {
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);
Delete(temp);
}
String *str;
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);
Delete(inner_type);
Delete(dimension);
return str;
}
} else if (SwigType_isfunction(ty)) {
SwigType *cp = Copy(ty);
SwigType *fn = SwigType_pop_function(cp);
String *args = NewString("");
ParmList *pl = SwigType_function_parms(fn, n);
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(n, argtype);
int tempargname = 0;
if (!argname) {
argname = NewStringf("arg%d", argnum);
tempargname = 1;
}
if (!first) {
Printf(args, "\n\t\t");
}
Printf(args, "(%s %s)", argname, ffitype);
first = 0;
Delete(ffitype);
if (tempargname)
Delete(argname);
}
if (ParmList_len(pl) != 0) {
Printf(args, ")\n"); /* finish arg list */
}
String *ffitype = get_ffi_type(n, cp);
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;
return NewString(st);
}
char *cl = Strstr(str, "class");
if (cl) {
cl += 6;
return NewString(cl);
}
}
return str;
}
extern "C" Language *swig_clisp(void) {
return new CLISP();
}

View file

@ -901,8 +901,6 @@ public:
// Get typemap for this argument
if ((tm = Getattr(p, "tmap:in"))) {
canThrow(n, "in", p);
Replaceall(tm, "$source", arg); /* deprecated */
Replaceall(tm, "$target", ln); /* deprecated */
Replaceall(tm, "$arg", arg); /* deprecated? */
Replaceall(tm, "$input", arg);
Setattr(p, "emit:input", arg);
@ -921,7 +919,6 @@ public:
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:check"))) {
canThrow(n, "check", p);
Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */
Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(f->code, tm, "\n", NIL);
@ -935,7 +932,6 @@ public:
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
canThrow(n, "freearg", p);
Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */
Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(cleanup, tm, "\n", NIL);
@ -949,8 +945,6 @@ public:
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:argout"))) {
canThrow(n, "argout", p);
Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */
Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */
Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */
Replaceall(tm, "$result", "jresult");
Replaceall(tm, "$input", Getattr(p, "emit:input"));
@ -982,8 +976,6 @@ public:
/* Return value if necessary */
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
canThrow(n, "out", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Replaceall(tm, "$target", "jresult"); /* deprecated */
Replaceall(tm, "$result", "jresult");
if (GetFlag(n, "feature:new"))
@ -1011,7 +1003,6 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
canThrow(n, "newfree", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Printf(f->code, "%s\n", tm);
}
}
@ -1020,7 +1011,6 @@ public:
if (!native_function_flag) {
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
canThrow(n, "ret", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Printf(f->code, "%s\n", tm);
}
}
@ -1533,7 +1523,7 @@ public:
if (classname_substituted_flag) {
if (SwigType_isenum(t)) {
// This handles wrapping of inline initialised const enum static member variables (not when wrapping enum items - ignored later on)
Printf(constants_code, "(%s)%s.%s();\n", return_type, full_imclass_name, Swig_name_get(getNSpace(), symname));
Printf(constants_code, "(%s)%s.%s();\n", return_type, full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname));
} else {
// This handles function pointers using the %constant directive
Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname));
@ -1709,11 +1699,11 @@ public:
* addInterfaceNameAndUpcasts()
* ----------------------------------------------------------------------------- */
void addInterfaceNameAndUpcasts(SwigType *smart, String *interface_list, String *interface_upcasts, Hash *base_list, String *c_classname) {
void addInterfaceNameAndUpcasts(SwigType *smart, String *interface_list, String *interface_upcasts, Hash *base_list, SwigType *c_classname) {
List *keys = Keys(base_list);
for (Iterator it = First(keys); it.item; it = Next(it)) {
Node *base = Getattr(base_list, it.item);
String *c_baseclass = SwigType_namestr(Getattr(base, "name"));
SwigType *c_baseclassname = Getattr(base, "name");
String *interface_name = Getattr(base, "interface:name");
if (Len(interface_list))
Append(interface_list, ", ");
@ -1733,12 +1723,11 @@ public:
Replaceall(cptr_method_name, "$interfacename", interface_name);
String *upcast_method_name = Swig_name_member(getNSpace(), getClassPrefix(), cptr_method_name);
upcastsCode(smart, upcast_method_name, c_classname, c_baseclass);
upcastsCode(smart, upcast_method_name, c_classname, c_baseclassname);
Delete(upcast_method_name);
Delete(cptr_method_name);
Delete(interface_code);
Delete(c_baseclass);
}
Delete(keys);
}
@ -1749,7 +1738,7 @@ public:
* Add code for C++ casting to base class
* ----------------------------------------------------------------------------- */
void upcastsCode(SwigType *smart, String *upcast_method_name, String *c_classname, String *c_baseclass) {
void upcastsCode(SwigType *smart, String *upcast_method_name, SwigType *c_classname, SwigType *c_baseclassname) {
String *wname = Swig_name_wrapper(upcast_method_name);
Printv(imclass_cppcasts_code, "\n [global::System.Runtime.InteropServices.DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL);
@ -1757,28 +1746,35 @@ public:
Replaceall(imclass_cppcasts_code, "$csclassname", proxy_class_name);
String *classname = SwigType_namestr(c_classname);
String *baseclassname = SwigType_namestr(c_baseclassname);
if (smart) {
SwigType *bsmart = Copy(smart);
SwigType *rclassname = SwigType_typedef_resolve_all(c_classname);
SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass);
Replaceall(bsmart, rclassname, rbaseclass);
Delete(rclassname);
Delete(rbaseclass);
String *smartnamestr = SwigType_namestr(smart);
String *bsmartnamestr = SwigType_namestr(bsmart);
String *bsmartnamestr = SwigType_namestr(smart);
// TODO: SwigType_typedef_resolve_all on a String instead of SwigType is incorrect for templates
SwigType *rclassname = SwigType_typedef_resolve_all(classname);
SwigType *rbaseclassname = SwigType_typedef_resolve_all(baseclassname);
Replaceall(bsmartnamestr, rclassname, rbaseclassname);
Printv(upcasts_code,
"SWIGEXPORT ", bsmartnamestr, " * SWIGSTDCALL ", wname, "(", smartnamestr, " *jarg1) {\n",
" return jarg1 ? new ", bsmartnamestr, "(*jarg1) : 0;\n"
"}\n", "\n", NIL);
Delete(rbaseclassname);
Delete(rclassname);
Delete(bsmartnamestr);
Delete(smartnamestr);
Delete(bsmart);
} else {
Printv(upcasts_code,
"SWIGEXPORT ", c_baseclass, " * SWIGSTDCALL ", wname, "(", c_classname, " *jarg1) {\n",
" return (", c_baseclass, " *)jarg1;\n"
"SWIGEXPORT ", baseclassname, " * SWIGSTDCALL ", wname, "(", classname, " *jarg1) {\n",
" return (", baseclassname, " *)jarg1;\n"
"}\n", "\n", NIL);
}
Delete(baseclassname);
Delete(classname);
Delete(wname);
}
@ -1787,10 +1783,9 @@ public:
* ----------------------------------------------------------------------------- */
void emitProxyClassDefAndCPPCasts(Node *n) {
String *c_classname = SwigType_namestr(Getattr(n, "name"));
String *c_baseclass = NULL;
SwigType *c_classname = Getattr(n, "name");
SwigType *c_baseclassname = NULL;
String *baseclass = NULL;
String *c_baseclassname = NULL;
String *interface_list = NewStringEmpty();
String *interface_upcasts = NewStringEmpty();
SwigType *typemap_lookup_type = Getattr(n, "classtypeobj");
@ -1812,12 +1807,13 @@ public:
Iterator base = First(baselist);
while (base.item) {
if (!(GetFlag(base.item, "feature:ignore") || Getattr(base.item, "feature:interface"))) {
String *baseclassname = Getattr(base.item, "name");
SwigType *baseclassname = Getattr(base.item, "name");
if (!c_baseclassname) {
c_baseclassname = baseclassname;
baseclass = Copy(getProxyName(baseclassname));
if (baseclass)
c_baseclass = SwigType_namestr(baseclassname);
String *name = getProxyName(baseclassname);
if (name) {
c_baseclassname = baseclassname;
baseclass = name;
}
} else {
/* Warn about multiple inheritance for additional base class(es) */
String *proxyclassname = Getattr(n, "classtypeobj");
@ -1833,7 +1829,7 @@ public:
if (interface_bases)
addInterfaceNameAndUpcasts(smart, interface_list, interface_upcasts, interface_bases, c_classname);
bool derived = baseclass && getProxyName(c_baseclassname);
bool derived = baseclass != 0;
if (derived && purebase_notderived)
pure_baseclass = empty_string;
const String *wanted_base = baseclass ? baseclass : pure_baseclass;
@ -1841,7 +1837,6 @@ public:
if (purebase_replace) {
wanted_base = pure_baseclass;
derived = false;
Delete(baseclass);
baseclass = NULL;
if (purebase_notderived)
Swig_error(Getfile(n), Getline(n), "The csbase typemap for proxy %s must contain just one of the 'replace' or 'notderived' attributes.\n", typemap_lookup_type);
@ -2032,12 +2027,11 @@ public:
if (derived) {
String *upcast_method_name = Swig_name_member(getNSpace(), getClassPrefix(), smart != 0 ? "SWIGSmartPtrUpcast" : "SWIGUpcast");
upcastsCode(smart, upcast_method_name, c_classname, c_baseclass);
upcastsCode(smart, upcast_method_name, c_classname, c_baseclassname);
Delete(upcast_method_name);
}
Delete(smart);
Delete(baseclass);
}
/* ----------------------------------------------------------------------
@ -2046,7 +2040,8 @@ public:
void emitInterfaceDeclaration(Node *n, String *interface_name, File *f_interface) {
Printv(f_interface, typemapLookup(n, "csimports", Getattr(n, "classtypeobj"), WARN_NONE), "\n", NIL);
Printf(f_interface, "public interface %s", interface_name);
Printv(f_interface, typemapLookup(n, "csinterfacemodifiers", Getattr(n, "classtypeobj"), WARN_CSHARP_TYPEMAP_INTERFACEMODIFIERS_UNDEF), NIL);
Printf(f_interface, " %s", interface_name);
if (List *baselist = Getattr(n, "bases")) {
String *bases = 0;
for (Iterator base = First(baselist); base.item; base = Next(base)) {
@ -4064,11 +4059,10 @@ public:
/* Get the C# parameter type */
if ((tm = Getattr(p, "tmap:cstype"))) {
substituteClassname(pt, tm);
if (Strncmp(tm, "ref ", 4) == 0) {
Replace(tm, "ref ", "", DOH_REPLACE_FIRST);
int flags = DOH_REPLACE_FIRST | DOH_REPLACE_ID_BEGIN | DOH_REPLACE_NOCOMMENT;
if (Replace(tm, "ref ", "", flags) || Replace(tm, "ref\t", "", flags)) {
Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
} else if (Strncmp(tm, "out ", 4) == 0) {
Replace(tm, "out ", "", DOH_REPLACE_FIRST);
} else if (Replace(tm, "out ", "", flags) || Replace(tm, "out\t", "", flags)) {
Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
} else {
Printf(proxy_method_types, "typeof(%s)", tm);

View file

@ -3140,11 +3140,10 @@ private:
* Handle inheriting from D and C++ classes.
*/
String *c_classname = SwigType_namestr(Getattr(n, "name"));
String *c_baseclass = NULL;
Node *basenode = NULL;
String *basename = NULL;
String *c_classname = Getattr(n, "name");
String *c_baseclassname = NULL;
Node *basenode = NULL;
String *baseclass = NULL;
// Inheritance from pure D classes.
Node *attributes = NewHash();
@ -3161,13 +3160,14 @@ private:
Iterator base = First(baselist);
while (base.item) {
if (!GetFlag(base.item, "feature:ignore")) {
String *baseclassname = Getattr(base.item, "name");
SwigType *baseclassname = Getattr(base.item, "name");
if (!c_baseclassname) {
basenode = base.item;
c_baseclassname = baseclassname;
basename = createProxyName(c_baseclassname);
if (basename)
c_baseclass = SwigType_namestr(baseclassname);
String *name = createProxyName(baseclassname);
if (name) {
c_baseclassname = baseclassname;
baseclass = name;
}
} else {
/* Warn about multiple inheritance for additional base class(es) */
String *proxyclassname = Getattr(n, "classtypeobj");
@ -3180,25 +3180,24 @@ private:
}
}
bool derived = (basename != NULL);
bool derived = baseclass != NULL;
if (derived && purebase_notderived) {
pure_baseclass = empty_string;
}
const String *wanted_base = basename ? basename : pure_baseclass;
const String *wanted_base = baseclass ? baseclass : pure_baseclass;
if (purebase_replace) {
wanted_base = pure_baseclass;
derived = false;
basenode = NULL;
Delete(basename);
basename = NULL;
baseclass = NULL;
if (purebase_notderived) {
Swig_error(Getfile(n), Getline(n),
"The dbase typemap for proxy %s must contain just one of the 'replace' or 'notderived' attributes.\n",
typemap_lookup_type);
}
} else if (basename && Len(pure_baseclass) > 0) {
} else if (baseclass && Len(pure_baseclass) > 0) {
Swig_warning(WARN_D_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s, base class %s ignored. Multiple inheritance is not supported in D. "
"Perhaps you need one of the 'replace' or 'notderived' attributes in the dbase typemap?\n", typemap_lookup_type, pure_baseclass);
@ -3206,7 +3205,7 @@ private:
// Add code to do C++ casting to base class (only for classes in an inheritance hierarchy)
if (derived) {
writeClassUpcast(n, proxy_class_name, c_classname, c_baseclass);
writeClassUpcast(n, proxy_class_name, c_classname, c_baseclassname);
}
/*
@ -3354,8 +3353,7 @@ private:
// Write the class body and the curly bracket closing the class definition
// to the proxy module.
indentCode(body);
Replaceall(body, "$dbaseclass", basename);
Delete(basename);
Replaceall(body, "$dbaseclass", baseclass);
Printv(proxy_class_code, body, "\n}\n", NIL);
Delete(body);
@ -3368,7 +3366,7 @@ private:
/* ---------------------------------------------------------------------------
* D::writeClassUpcast()
* --------------------------------------------------------------------------- */
void writeClassUpcast(Node *n, const String* d_class_name, String* c_class_name, String* c_base_name) {
void writeClassUpcast(Node *n, const String* d_class_name, SwigType* c_classname, SwigType* c_baseclassname) {
SwigType *smart = Swig_cparse_smartptr(n);
String *upcast_name = Swig_name_member(getNSpace(), d_class_name, (smart != 0 ? "SmartPtrUpcast" : "Upcast"));
@ -3377,36 +3375,42 @@ private:
writeImDModuleFunction(upcast_name, "void*", "(void* objectRef)",
upcast_wrapper_name);
String *classname = SwigType_namestr(c_classname);
String *baseclassname = SwigType_namestr(c_baseclassname);
if (smart) {
SwigType *bsmart = Copy(smart);
SwigType *rclassname = SwigType_typedef_resolve_all(c_class_name);
SwigType *rbaseclass = SwigType_typedef_resolve_all(c_base_name);
Replaceall(bsmart, rclassname, rbaseclass);
Delete(rclassname);
Delete(rbaseclass);
String *smartnamestr = SwigType_namestr(smart);
String *bsmartnamestr = SwigType_namestr(bsmart);
String *bsmartnamestr = SwigType_namestr(smart);
// TODO: SwigType_typedef_resolve_all on a String instead of SwigType is incorrect for templates
SwigType *rclassname = SwigType_typedef_resolve_all(classname);
SwigType *rbaseclassname = SwigType_typedef_resolve_all(baseclassname);
Replaceall(bsmartnamestr, rclassname, rbaseclassname);
Printv(upcasts_code,
"SWIGEXPORT ", bsmartnamestr, " * ", upcast_wrapper_name,
"(", smartnamestr, " *objectRef) {\n",
" return objectRef ? new ", bsmartnamestr, "(*objectRef) : 0;\n"
"}\n",
"\n", NIL);
Delete(rbaseclassname);
Delete(rclassname);
Delete(bsmartnamestr);
Delete(smartnamestr);
Delete(bsmart);
} else {
Printv(upcasts_code,
"SWIGEXPORT ", c_base_name, " * ", upcast_wrapper_name,
"(", c_base_name, " *objectRef) {\n",
" return (", c_base_name, " *)objectRef;\n"
"SWIGEXPORT ", baseclassname, " * ", upcast_wrapper_name,
"(", baseclassname, " *objectRef) {\n",
" return (", baseclassname, " *)objectRef;\n"
"}\n",
"\n", NIL);
}
Replaceall(upcasts_code, "$cclass", c_class_name);
Replaceall(upcasts_code, "$cbaseclass", c_base_name);
Replaceall(upcasts_code, "$cclass", classname);
Replaceall(upcasts_code, "$cbaseclass", baseclassname);
Delete(baseclassname);
Delete(classname);
Delete(upcast_name);
Delete(upcast_wrapper_name);
Delete(smart);

View file

@ -160,7 +160,7 @@ String *Swig_method_decl(SwigType *return_base_type, SwigType *decl, const_Strin
SwigType *rettype_stripped = SwigType_strip_qualifiers(rettype);
String *rtype = SwigType_str(rettype, 0);
Append(result, rtype);
if (SwigType_issimple(rettype_stripped) && return_base_type)
if ((SwigType_issimple(rettype_stripped) && return_base_type) || SwigType_isqualifier(rettype))
Append(result, " ");
Delete(rtype);
Delete(rettype_stripped);
@ -175,10 +175,6 @@ String *Swig_method_decl(SwigType *return_base_type, SwigType *decl, const_Strin
if (qualifiers)
Printv(result, " ", qualifiers, NIL);
// Reformat result to how it has been historically
Replaceall(result, ",", ", ");
Replaceall(result, "=", " = ");
Delete(args_string);
Delete(popped_decl);
Delete(qualifiers);

View file

@ -74,7 +74,6 @@ void emit_parameter_variables(ParmList *l, Wrapper *f) {
while (p) {
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");
} else {
@ -87,7 +86,6 @@ void emit_parameter_variables(ParmList *l, Wrapper *f) {
while (p) {
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");
} else {
@ -116,7 +114,6 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) {
while (p) {
String *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)) {

File diff suppressed because it is too large Load diff

View file

@ -255,7 +255,7 @@ public:
if (goops) {
if (linkage != GUILE_LSTYLE_PASSIVE && linkage != GUILE_LSTYLE_MODULE) {
Printf(stderr, "guile: GOOPS support requires passive or module linkage\n");
exit(1);
SWIG_exit(EXIT_FAILURE);
}
}
@ -719,7 +719,6 @@ public:
sprintf(source, "argv[%d]", i);
else
sprintf(source, "s_%d", i);
String *target = Getattr(p, "lname");
if (!args_passed_as_array) {
if (i != 0)
@ -730,8 +729,6 @@ public:
Printf(f->code, " if (%s != SCM_UNDEFINED) {\n", source);
}
if ((tm = Getattr(p, "tmap:in"))) {
Replaceall(tm, "$source", source);
Replaceall(tm, "$target", target);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source);
Printv(f->code, tm, "\n", NIL);
@ -794,7 +791,6 @@ public:
/* 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");
} else {
@ -807,8 +803,6 @@ public:
String *returns_argout = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:argout"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Replaceall(tm, "$target", Getattr(p, "lname"));
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(outarg, tm, "\n", NIL);
@ -828,7 +822,6 @@ public:
/* Insert cleanup code */
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
Replaceall(tm, "$target", Getattr(p, "lname"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(cleanup, tm, "\n", NIL);
p = Getattr(p, "tmap:freearg:next");
@ -859,8 +852,6 @@ public:
// Now have return value, figure out what to do with it.
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$result", "gswig_result");
Replaceall(tm, "$target", "gswig_result");
Replaceall(tm, "$source", Swig_cresult_name());
if (GetFlag(n, "feature:new"))
Replaceall(tm, "$owner", "1");
else
@ -898,13 +889,11 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
}
}
// Free any memory allocated by the function being wrapped..
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
}
// Wrap things up (in a manner of speaking)
@ -1141,9 +1130,7 @@ public:
/* Check for a setting of the variable value */
Printf(f->code, "if (s_0 != SCM_UNDEFINED) {\n");
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
Replaceall(tm, "$source", "s_0");
Replaceall(tm, "$input", "s_0");
Replaceall(tm, "$target", name);
/* Printv(f->code,tm,"\n",NIL); */
emit_action_code(n, f->code, tm);
} else {
@ -1155,8 +1142,6 @@ public:
// of evaluating or setting)
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "gswig_result");
Replaceall(tm, "$result", "gswig_result");
/* Printv(f->code,tm,"\n",NIL); */
emit_action_code(n, f->code, tm);
@ -1334,9 +1319,7 @@ public:
// See if there's a typemap
if ((tm = Swig_typemap_lookup("constant", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$value", value);
Replaceall(tm, "$target", name);
Printv(f_header, tm, "\n", NIL);
} else {
// Create variable and assign it a value

View file

@ -1001,8 +1001,6 @@ public:
// Get typemap for this argument
if ((tm = Getattr(p, "tmap:in"))) {
addThrows(n, "tmap:in", p);
Replaceall(tm, "$source", arg); /* deprecated */
Replaceall(tm, "$target", ln); /* deprecated */
Replaceall(tm, "$arg", arg); /* deprecated? */
Replaceall(tm, "$input", arg);
Setattr(p, "emit:input", arg);
@ -1027,7 +1025,6 @@ public:
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:check"))) {
addThrows(n, "tmap:check", p);
Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */
Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(f->code, tm, "\n", NIL);
@ -1041,7 +1038,6 @@ public:
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
addThrows(n, "tmap:freearg", p);
Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */
Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(cleanup, tm, "\n", NIL);
@ -1055,8 +1051,6 @@ public:
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:argout"))) {
addThrows(n, "tmap:argout", p);
Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */
Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */
Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */
Replaceall(tm, "$result", "jresult");
Replaceall(tm, "$input", Getattr(p, "emit:input"));
@ -1090,8 +1084,6 @@ public:
/* Return value if necessary */
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
addThrows(n, "tmap:out", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Replaceall(tm, "$target", "jresult"); /* deprecated */
Replaceall(tm, "$result", "jresult");
if (GetFlag(n, "feature:new"))
@ -1118,7 +1110,6 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
addThrows(n, "tmap:newfree", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Printf(f->code, "%s\n", tm);
}
}
@ -1127,7 +1118,6 @@ public:
if (!native_function_flag) {
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
addThrows(n, "tmap:ret", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Printf(f->code, "%s\n", tm);
}
}
@ -1633,7 +1623,7 @@ public:
if (classname_substituted_flag) {
if (SwigType_isenum(t)) {
// This handles wrapping of inline initialised const enum static member variables (not when wrapping enum items - ignored later on)
Printf(constants_code, "%s.swigToEnum(%s.%s());\n", return_type, full_imclass_name, Swig_name_get(getNSpace(), symname));
Printf(constants_code, "%s.swigToEnum(%s.%s());\n", return_type, full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname));
} else {
// This handles function pointers using the %constant directive
Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname));
@ -1853,11 +1843,11 @@ public:
* addInterfaceNameAndUpcasts()
* ----------------------------------------------------------------------------- */
void addInterfaceNameAndUpcasts(SwigType *smart, String *interface_list, String *interface_upcasts, Hash *base_list, String *c_classname) {
void addInterfaceNameAndUpcasts(SwigType *smart, String *interface_list, String *interface_upcasts, Hash *base_list, SwigType *c_classname) {
List *keys = Keys(base_list);
for (Iterator it = First(keys); it.item; it = Next(it)) {
Node *base = Getattr(base_list, it.item);
String *c_baseclass = SwigType_namestr(Getattr(base, "name"));
SwigType *c_baseclassname = Getattr(base, "name");
String *interface_name = Getattr(base, "interface:name");
if (Len(interface_list))
Append(interface_list, ", ");
@ -1877,11 +1867,11 @@ public:
Replaceall(cptr_method_name, "$interfacename", interface_name);
String *upcast_method_name = Swig_name_member(getNSpace(), getClassPrefix(), cptr_method_name);
upcastsCode(smart, upcast_method_name, c_classname, c_baseclass);
upcastsCode(smart, upcast_method_name, c_classname, c_baseclassname);
Delete(upcast_method_name);
Delete(cptr_method_name);
Delete(interface_code);
Delete(c_baseclass);
}
Delete(keys);
}
@ -1892,19 +1882,23 @@ public:
* Add code for C++ casting to base class
* ----------------------------------------------------------------------------- */
void upcastsCode(SwigType *smart, String *upcast_method_name, String *c_classname, String *c_baseclass) {
void upcastsCode(SwigType *smart, String *upcast_method_name, SwigType *c_classname, SwigType *c_baseclassname) {
String *jniname = makeValidJniName(upcast_method_name);
String *wname = Swig_name_wrapper(jniname);
Printf(imclass_cppcasts_code, " public final static native long %s(long jarg1);\n", upcast_method_name);
String *classname = SwigType_namestr(c_classname);
String *baseclassname = SwigType_namestr(c_baseclassname);
if (smart) {
SwigType *bsmart = Copy(smart);
SwigType *rclassname = SwigType_typedef_resolve_all(c_classname);
SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass);
Replaceall(bsmart, rclassname, rbaseclass);
Delete(rclassname);
Delete(rbaseclass);
String *smartnamestr = SwigType_namestr(smart);
String *bsmartnamestr = SwigType_namestr(bsmart);
String *bsmartnamestr = SwigType_namestr(smart);
// TODO: SwigType_typedef_resolve_all on a String instead of SwigType is incorrect for templates
SwigType *rclassname = SwigType_typedef_resolve_all(classname);
SwigType *rbaseclassname = SwigType_typedef_resolve_all(baseclassname);
Replaceall(bsmartnamestr, rclassname, rbaseclassname);
Printv(upcasts_code,
"SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n",
" jlong baseptr = 0;\n"
@ -1915,19 +1909,24 @@ public:
" *(", bsmartnamestr, " **)&baseptr = argp1 ? new ", bsmartnamestr, "(*argp1) : 0;\n"
" return baseptr;\n"
"}\n", "\n", NIL);
Delete(rbaseclassname);
Delete(rclassname);
Delete(bsmartnamestr);
Delete(smartnamestr);
Delete(bsmart);
} else {
Printv(upcasts_code,
"SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n",
" jlong baseptr = 0;\n"
" (void)jenv;\n"
" (void)jcls;\n"
" *(", c_baseclass, " **)&baseptr = *(", c_classname, " **)&jarg1;\n"
" *(", baseclassname, " **)&baseptr = *(", classname, " **)&jarg1;\n"
" return baseptr;\n"
"}\n", "\n", NIL);
}
Delete(baseclassname);
Delete(classname);
Delete(wname);
Delete(jniname);
}
@ -1937,10 +1936,9 @@ public:
* ----------------------------------------------------------------------------- */
void emitProxyClassDefAndCPPCasts(Node *n) {
String *c_classname = SwigType_namestr(Getattr(n, "name"));
String *c_baseclass = NULL;
SwigType *c_classname = Getattr(n, "name");
SwigType *c_baseclassname = NULL;
String *baseclass = NULL;
String *c_baseclassname = NULL;
String *interface_list = NewStringEmpty();
String *interface_upcasts = NewStringEmpty();
SwigType *typemap_lookup_type = Getattr(n, "classtypeobj");
@ -1962,12 +1960,13 @@ public:
Iterator base = First(baselist);
while (base.item) {
if (!(GetFlag(base.item, "feature:ignore") || Getattr(base.item, "feature:interface"))) {
String *baseclassname = Getattr(base.item, "name");
SwigType *baseclassname = Getattr(base.item, "name");
if (!c_baseclassname) {
c_baseclassname = baseclassname;
baseclass = Copy(getProxyName(baseclassname));
if (baseclass)
c_baseclass = SwigType_namestr(baseclassname);
String *name = getProxyName(baseclassname);
if (name) {
c_baseclassname = baseclassname;
baseclass = name;
}
} else {
/* Warn about multiple inheritance for additional base class(es) */
String *proxyclassname = Getattr(n, "classtypeobj");
@ -1984,7 +1983,7 @@ public:
if (interface_bases)
addInterfaceNameAndUpcasts(smart, interface_list, interface_upcasts, interface_bases, c_classname);
bool derived = baseclass && getProxyName(c_baseclassname);
bool derived = baseclass != 0;
if (derived && purebase_notderived)
pure_baseclass = empty_string;
const String *wanted_base = baseclass ? baseclass : pure_baseclass;
@ -1992,7 +1991,6 @@ public:
if (purebase_replace) {
wanted_base = pure_baseclass;
derived = false;
Delete(baseclass);
baseclass = NULL;
if (purebase_notderived)
Swig_error(Getfile(n), Getline(n), "The javabase typemap for proxy %s must contain just one of the 'replace' or 'notderived' attributes.\n", typemap_lookup_type);
@ -2115,12 +2113,11 @@ public:
if (derived) {
String *upcast_method_name = Swig_name_member(getNSpace(), getClassPrefix(), smart != 0 ? "SWIGSmartPtrUpcast" : "SWIGUpcast");
upcastsCode(smart, upcast_method_name, c_classname, c_baseclass);
upcastsCode(smart, upcast_method_name, c_classname, c_baseclassname);
Delete(upcast_method_name);
}
Delete(smart);
Delete(baseclass);
}
/* ----------------------------------------------------------------------
@ -2138,7 +2135,8 @@ public:
}
Printv(f_interface, typemapLookup(n, "javaimports", Getattr(n, "classtypeobj"), WARN_NONE), "\n", NIL);
Printf(f_interface, "public interface %s", interface_name);
Printv(f_interface, typemapLookup(n, "javainterfacemodifiers", Getattr(n, "classtypeobj"), WARN_JAVA_TYPEMAP_INTERFACEMODIFIERS_UNDEF), NIL);
Printf(f_interface, " %s", interface_name);
if (List *baselist = Getattr(n, "bases")) {
String *bases = 0;
for (Iterator base = First(baselist); base.item; base = Next(base)) {
@ -4828,34 +4826,27 @@ public:
// .'s to delimit namespaces, so we need to replace those with /'s
Replace(internal_classname, NSPACE_SEPARATOR, "/", DOH_REPLACE_ANY);
Wrapper_add_localv(w, "baseclass", "static jclass baseclass", "= 0", NIL);
Printf(w->def, "void %s::swig_connect_director(JNIEnv *jenv, jobject jself, jclass jcls, bool swig_mem_own, bool weak_global) {", director_classname);
Printf(w->def, "static jclass baseclass = swig_new_global_ref(jenv, \"%s\");\n", internal_classname);
Printf(w->def, "if (!baseclass) return;\n");
if (first_class_dmethod != curr_class_dmethod) {
Printf(w->def, "static struct {\n");
Printf(w->def, "const char *mname;\n");
Printf(w->def, "const char *mdesc;\n");
Printf(w->def, "jmethodID base_methid;\n");
Printf(w->def, "} methods[] = {\n");
Printf(w->def, "static SwigDirectorMethod methods[] = {\n");
for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) {
UpcallData *udata = Getitem(dmethods_seq, i);
Printf(w->def, "{ \"%s\", \"%s\", NULL }", Getattr(udata, "method"), Getattr(udata, "fdesc"));
Printf(w->def, "SwigDirectorMethod(jenv, baseclass, \"%s\", \"%s\")", Getattr(udata, "method"), Getattr(udata, "fdesc"));
if (i != curr_class_dmethod - 1)
Putc(',', w->def);
Putc('\n', w->def);
}
Printf(w->def, "};\n");
Printf(w->def, "};");
}
Printf(w->code, "if (swig_set_self(jenv, jself, swig_mem_own, weak_global)) {\n");
Printf(w->code, "if (!baseclass) {\n");
Printf(w->code, "baseclass = jenv->FindClass(\"%s\");\n", internal_classname);
Printf(w->code, "if (!baseclass) return;\n");
Printf(w->code, "baseclass = (jclass) jenv->NewGlobalRef(baseclass);\n");
Printf(w->code, "}\n");
int n_methods = curr_class_dmethod - first_class_dmethod;
@ -4870,12 +4861,8 @@ public:
/* Emit the code to look up the class's methods, initialize the override array */
Printf(w->code, "bool derived = (jenv->IsSameObject(baseclass, jcls) ? false : true);\n");
Printf(w->code, "for (int i = 0; i < %d; ++i) {\n", n_methods);
Printf(w->code, " if (!methods[i].base_methid) {\n");
Printf(w->code, " methods[i].base_methid = jenv->GetMethodID(baseclass, methods[i].mname, methods[i].mdesc);\n");
Printf(w->code, " if (!methods[i].base_methid) return;\n");
Printf(w->code, " }\n");
Printf(w->code, " bool derived = (jenv->IsSameObject(baseclass, jcls) ? false : true);\n");
Printf(w->code, " for (int i = 0; i < %d; ++i) {\n", n_methods);
// Generally, derived classes have a mix of overridden and
// non-overridden methods and it is worth making a GetMethodID
// check during initialization to determine if each method is
@ -4895,8 +4882,8 @@ public:
} else {
Printf(w->code, " swig_override[i] = false;\n");
Printf(w->code, " if (derived) {\n");
Printf(w->code, " jmethodID methid = jenv->GetMethodID(jcls, methods[i].mname, methods[i].mdesc);\n");
Printf(w->code, " swig_override[i] = (methid != methods[i].base_methid);\n");
Printf(w->code, " jmethodID methid = jenv->GetMethodID(jcls, methods[i].name, methods[i].desc);\n");
Printf(w->code, " swig_override[i] = methods[i].methid && (methid != methods[i].methid);\n");
Printf(w->code, " jenv->ExceptionClear();\n");
Printf(w->code, " }\n");
}

View file

@ -197,6 +197,11 @@ public:
*/
virtual int emitWrapperFunction(Node *n);
/**
* Invoked by nativeWrapper callback
*/
virtual int emitNativeFunction(Node *n);
/**
* Invoked from constantWrapper after call to Language::constantWrapper.
**/
@ -311,6 +316,7 @@ public:
virtual int classHandler(Node *n);
virtual int functionWrapper(Node *n);
virtual int constantWrapper(Node *n);
virtual int nativeWrapper(Node *n);
virtual void main(int argc, char *argv[]);
virtual int top(Node *n);
@ -441,6 +447,18 @@ int JAVASCRIPT::constantWrapper(Node *n) {
return SWIG_OK;
}
/* ---------------------------------------------------------------------
* nativeWrapper()
*
* Function wrapper for generating placeholders for native functions
* --------------------------------------------------------------------- */
int JAVASCRIPT::nativeWrapper(Node *n) {
emitter->emitNativeFunction(n);
return SWIG_OK;
}
/* ---------------------------------------------------------------------
* classHandler()
*
@ -709,7 +727,7 @@ Node *JSEmitter::getBaseClass(Node *n) {
/* -----------------------------------------------------------------------------
* JSEmitter::emitWrapperFunction() : dispatches emitter functions.
*
* This allows to have small sized, dedicated emitting functions.
* This allows having small sized, dedicated emitting functions.
* All state dependent branching is done here.
* ----------------------------------------------------------------------------- */
@ -768,6 +786,14 @@ int JSEmitter::emitWrapperFunction(Node *n) {
return ret;
}
int JSEmitter::emitNativeFunction(Node *n) {
String *wrapname = Getattr(n, "wrap:name");
enterFunction(n);
state.function(WRAPPER_NAME, wrapname);
exitFunction(n);
return SWIG_OK;
}
int JSEmitter::enterClass(Node *n) {
state.clazz(RESET);
state.clazz(NAME, Getattr(n, "sym:name"));
@ -1549,7 +1575,8 @@ void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Ma
Printf(arg, "argv[%d]", i);
break;
default:
throw "Illegal state.";
Printf(stderr, "Illegal MarshallingMode.");
SWIG_exit(EXIT_FAILURE);
}
tm = emitInputTypemap(n, p, wrapper, arg);
Delete(arg);
@ -2186,7 +2213,8 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar
Printf(arg, "args[%d]", i);
break;
default:
throw "Illegal state.";
Printf(stderr, "Illegal MarshallingMode.");
SWIG_exit(EXIT_FAILURE);
}
tm = emitInputTypemap(n, p, wrapper, arg);

View file

@ -722,18 +722,18 @@ int Language::typemapDirective(Node *n) {
String *code = Getattr(n, "code");
Parm *kwargs = Getattr(n, "kwargs");
Node *items = firstChild(n);
static int namewarn = 0;
static int nameerror = 0;
if (code && (Strstr(code, "$source") || (Strstr(code, "$target")))) {
Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "Deprecated typemap feature ($source/$target).\n");
if (!namewarn) {
Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "The use of $source and $target in a typemap declaration is deprecated.\n\
Swig_error(Getfile(n), Getline(n), "Obsolete typemap feature ($source/$target).\n");
if (!nameerror) {
Swig_error(Getfile(n), Getline(n), "The use of $source and $target in a typemap declaration is no longer supported.\n\
For typemaps related to argument input (in,ignore,default,arginit,check), replace\n\
$source by $input and $target by $1. For typemaps related to return values (out,\n\
argout,ret,except), replace $source by $1 and $target by $result. See the file\n\
Doc/Manual/Typemaps.html for complete details.\n");
namewarn = 1;
nameerror = 1;
}
}
@ -1481,8 +1481,6 @@ int Language::membervariableHandler(Node *n) {
} else {
String *pname0 = Swig_cparm_name(0, 0);
String *pname1 = Swig_cparm_name(0, 1);
Replace(tm, "$source", pname1, DOH_REPLACE_ANY);
Replace(tm, "$target", target, DOH_REPLACE_ANY);
Replace(tm, "$input", pname1, DOH_REPLACE_ANY);
Replace(tm, "$self", pname0, DOH_REPLACE_ANY);
Setattr(n, "wrap:action", tm);
@ -3049,8 +3047,6 @@ int Language::variableWrapper(Node *n) {
}
} else {
String *pname0 = Swig_cparm_name(0, 0);
Replace(tm, "$source", pname0, DOH_REPLACE_ANY);
Replace(tm, "$target", name, DOH_REPLACE_ANY);
Replace(tm, "$input", pname0, DOH_REPLACE_ANY);
Setattr(n, "wrap:action", tm);
Delete(tm);

View file

@ -613,13 +613,9 @@ public:
}
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);
if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) {
@ -678,7 +674,6 @@ public:
/* 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");
} else {
@ -690,7 +685,6 @@ public:
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");
} else {
@ -709,8 +703,6 @@ public:
// returnval+=GetInt(p,"tmap:argout:numoutputs");
// }
// else returnval++;
Replaceall(tm, "$source", Getattr(p, "lname"));
Replaceall(tm, "$target", Swig_cresult_name());
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(outarg, tm, "\n", NIL);
@ -740,7 +732,6 @@ public:
// returnval+=GetInt(tm,"numoutputs");
// }
// else returnval++;
Replaceall(tm, "$source", Swig_cresult_name());
if (GetFlag(n, "feature:new")) {
Replaceall(tm, "$owner", "1");
} else {
@ -762,14 +753,12 @@ public:
/* Look to see if there is any newfree cleanup code */
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
@ -1002,6 +991,7 @@ public:
// REPORT("variableWrapper", n);
String *lua_name = Getattr(n, "lua:name");
assert(lua_name);
(void)lua_name;
current[VARIABLE] = true;
// let SWIG generate the wrappers
int result = Language::variableWrapper(n);
@ -1073,14 +1063,10 @@ public:
}
if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", lua_name);
Replaceall(tm, "$value", value);
Replaceall(tm, "$nsname", nsname);
registerConstant(luaCurrentSymbolNSpace(), tm);
} else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", lua_name);
Replaceall(tm, "$value", value);
Replaceall(tm, "$nsname", nsname);
Printf(f_init, "%s\n", tm);
@ -1109,8 +1095,6 @@ public:
Setattr(n_v2, "sym:name", lua_name_v2);
tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0);
if (tm_v2) {
Replaceall(tm_v2, "$source", value);
Replaceall(tm_v2, "$target", lua_name_v2);
Replaceall(tm_v2, "$value", value);
Replaceall(tm_v2, "$nsname", nsname);
registerConstant(getNSpace(), tm_v2);
@ -1122,8 +1106,6 @@ public:
Swig_restore(n);
return SWIG_ERROR;
}
Replaceall(tm_v2, "$source", value);
Replaceall(tm_v2, "$target", lua_name_v2);
Replaceall(tm_v2, "$value", value);
Replaceall(tm_v2, "$nsname", nsname);
Printf(f_init, "%s\n", tm_v2);

View file

@ -23,6 +23,7 @@
#include "swigwarn.h"
#include "cparse.h"
#include <ctype.h>
#include <errno.h>
#include <limits.h> // for INT_MAX
// Global variables
@ -1140,9 +1141,9 @@ int SWIG_main(int argc, char *argv[], const TargetLanguageModule *tlm) {
} else
f_dependencies_file = stdout;
if (dependencies_target) {
Printf(f_dependencies_file, "%s: ", dependencies_target);
Printf(f_dependencies_file, "%s: ", Swig_filename_escape_space(dependencies_target));
} else {
Printf(f_dependencies_file, "%s: ", outfile);
Printf(f_dependencies_file, "%s: ", Swig_filename_escape_space(outfile));
}
List *files = Preprocessor_depend();
List *phony_targets = NewList();
@ -1153,7 +1154,7 @@ int SWIG_main(int argc, char *argv[], const TargetLanguageModule *tlm) {
use_file = 0;
}
if (use_file) {
Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
Printf(f_dependencies_file, "\\\n %s ", Swig_filename_escape_space(Getitem(files, i)));
if (depend_phony)
Append(phony_targets, Getitem(files, i));
}
@ -1161,7 +1162,7 @@ int SWIG_main(int argc, char *argv[], const TargetLanguageModule *tlm) {
Printf(f_dependencies_file, "\n");
if (depend_phony) {
for (int i = 0; i < Len(phony_targets); i++) {
Printf(f_dependencies_file, "\n%s:\n", Getitem(phony_targets, i));
Printf(f_dependencies_file, "\n%s:\n", Swig_filename_escape_space(Getitem(phony_targets, i)));
}
}
@ -1376,13 +1377,15 @@ int SWIG_main(int argc, char *argv[], const TargetLanguageModule *tlm) {
while (freeze) {
}
if ((werror) && (Swig_warn_count())) {
return Swig_warn_count();
}
delete lang;
return Swig_error_count();
int error_count = werror ? Swig_warn_count() : 0;
error_count += Swig_error_count();
if (error_count != 0)
SWIG_exit(error_count);
return 0;
}
/* -----------------------------------------------------------------------------
@ -1394,5 +1397,20 @@ int SWIG_main(int argc, char *argv[], const TargetLanguageModule *tlm) {
void SWIG_exit(int exit_code) {
while (freeze) {
}
if (exit_code > 0) {
CloseAllOpenFiles();
/* Remove all generated files */
if (all_output_files) {
for (int i = 0; i < Len(all_output_files); i++) {
String *filename = Getitem(all_output_files, i);
int removed = remove(Char(filename));
if (removed == -1)
fprintf(stderr, "On exit, could not delete file %s: %s\n", Char(filename), strerror(errno));
}
}
}
exit(exit_code);
}

File diff suppressed because it is too large Load diff

View file

@ -322,8 +322,6 @@ public:
}
// Handle parameter types.
if ((tm = Getattr(p, "tmap:in"))) {
Replaceall(tm, "$source", source);
Replaceall(tm, "$target", target);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source);
Printv(f->code, tm, "\n", NIL);
@ -343,7 +341,6 @@ public:
/* 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");
} else {
@ -355,8 +352,6 @@ public:
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:argout"))) {
Replaceall(tm, "$source", Getattr(p, "emit:input")); /* Deprecated */
Replaceall(tm, "$target", Getattr(p, "lname")); /* Deprecated */
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(outarg, tm, "\n", NIL);
@ -371,7 +366,6 @@ public:
/* Insert cleanup code */
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
Replaceall(tm, "$target", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
p = Getattr(p, "tmap:freearg:next");
} else {
@ -385,8 +379,6 @@ public:
// Now have return value, figure out what to do with it.
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "values[0]");
Replaceall(tm, "$result", "values[0]");
if (GetFlag(n, "feature:new"))
Replaceall(tm, "$owner", "1");
@ -408,14 +400,12 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
}
}
// Free any memory allocated by the function being wrapped..
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
}
// Wrap things up (in a manner of speaking)
@ -453,7 +443,7 @@ public:
Printv(df->def, "static Scheme_Object *\n", dname, "(int argc, Scheme_Object **argv) {", NIL);
Printv(df->code, dispatch, "\n", NIL);
Printf(df->code, "scheme_signal_error(\"No matching function for overloaded '%s'\");\n", iname);
Printf(df->code, "return NULL;\n", iname);
Printf(df->code, "return NULL;\n");
Printv(df->code, "}\n", NIL);
Wrapper_print(df, f_wrappers);
Printf(init_func_def, "scheme_add_global(\"%s\", scheme_make_prim_w_arity(%s,\"%s\",%d,%d),menv);\n", proc_name, dname, proc_name, 0, maxargs);
@ -521,8 +511,6 @@ public:
/* Check for a setting of the variable value */
Printf(f->code, "if (argc) {\n");
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
Replaceall(tm, "$source", "argv[0]");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "argv[0]");
Replaceall(tm, "$argnum", "1");
emit_action_code(n, f->code, tm);
@ -535,8 +523,6 @@ public:
// of evaluating or setting)
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "swig_result");
Replaceall(tm, "$result", "swig_result");
/* Printf (f->code, "%s\n", tm); */
emit_action_code(n, f->code, tm);
@ -609,9 +595,7 @@ public:
Printv(rvalue, "'", temp, "'", NIL);
}
if ((tm = Swig_typemap_lookup("constant", n, name, 0))) {
Replaceall(tm, "$source", rvalue);
Replaceall(tm, "$value", rvalue);
Replaceall(tm, "$target", name);
Printf(f_init, "%s\n", tm);
} else {
// Create variable and assign it a value

View file

@ -590,8 +590,6 @@ public:
}
// Handle parameter types.
if ((tm = Getattr(p, "tmap:in"))) {
Replaceall(tm, "$source", source);
Replaceall(tm, "$target", target);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source);
Printv(f->code, tm, "\n", NIL);
@ -611,7 +609,6 @@ public:
/* 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");
} else {
@ -623,8 +620,6 @@ public:
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:argout"))) {
Replaceall(tm, "$source", Getattr(p, "emit:input")); /* Deprecated */
Replaceall(tm, "$target", Getattr(p, "lname")); /* Deprecated */
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Replaceall(tm, "$ntype", normalizeTemplatedClassName(Getattr(p, "type")));
@ -640,7 +635,6 @@ public:
/* Insert cleanup code */
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
Replaceall(tm, "$target", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
p = Getattr(p, "tmap:freearg:next");
} else {
@ -681,8 +675,6 @@ public:
String *actioncode = emit_action(n);
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$source", "swig_result");
Replaceall(tm, "$target", "rv");
Replaceall(tm, "$result", "rv");
Replaceall(tm, "$ntype", return_type_normalized);
Printv(f->code, tm, "\n", NIL);
@ -701,14 +693,12 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", "swig_result");
Printv(f->code, tm, "\n", NIL);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
@ -716,7 +706,6 @@ public:
// Free any memory allocated by the function being wrapped..
if ((tm = Swig_typemap_lookup("swig_result", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
}
// Wrap things up (in a manner of speaking)
@ -853,13 +842,9 @@ public:
/* Check for a setting of the variable value */
Printf(f->code, "if (args != Val_int(0)) {\n");
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
Replaceall(tm, "$source", "args");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "args");
emit_action_code(n, f->code, tm);
} else if ((tm = Swig_typemap_lookup("in", n, name, 0))) {
Replaceall(tm, "$source", "args");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "args");
emit_action_code(n, f->code, tm);
} else {
@ -871,13 +856,9 @@ public:
// of evaluating or setting)
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "swig_result");
Replaceall(tm, "$result", "swig_result");
emit_action_code(n, f->code, tm);
} else if ((tm = Swig_typemap_lookup("out", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "swig_result");
Replaceall(tm, "$result", "swig_result");
emit_action_code(n, f->code, tm);
} else {
@ -1619,7 +1600,7 @@ public:
/* pass the method call on to the OCaml object */
Printv(w->code,
"swig_result = caml_swig_alloc(1,C_list);\n" "SWIG_Store_field(swig_result,0,args);\n" "args = swig_result;\n" "swig_result = Val_unit;\n", 0);
Printf(w->code, "static CAML_VALUE *swig_ocaml_func_val = NULL;\n" "if (!swig_ocaml_func_val) {\n");
Printf(w->code, "static const CAML_VALUE *swig_ocaml_func_val = NULL;\n" "if (!swig_ocaml_func_val) {\n");
Printf(w->code, " swig_ocaml_func_val = caml_named_value(\"swig_runmethod\");\n }\n");
Printf(w->code, "swig_result = caml_callback3(*swig_ocaml_func_val,swig_get_self(),caml_copy_string(\"%s\"),args);\n", Getattr(n, "name"));
/* exception handling */

View file

@ -567,6 +567,10 @@ public:
Wrapper *f = NewWrapper();
Octave_begin_function(n, f->def, iname, overname, !overloaded);
// Start default try block to execute
// cleanup code if exception is thrown
Printf(f->code, "try {\n");
emit_parameter_variables(l, f);
emit_attach_parmmaps(l, f);
Setattr(n, "wrap:parms", l);
@ -607,9 +611,7 @@ public:
sprintf(source, "args(%d)", j);
Setattr(p, "emit:input", source);
Replaceall(tm, "$source", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Replaceall(tm, "$target", Getattr(p, "lname"));
if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) {
Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
@ -654,7 +656,6 @@ public:
// 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");
} else {
@ -677,7 +678,6 @@ public:
}
}
if (tm && (Len(tm) != 0)) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
}
p = Getattr(p, "tmap:freearg:next");
@ -690,8 +690,6 @@ public:
String *outarg = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:argout"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Replaceall(tm, "$target", "_outp");
Replaceall(tm, "$result", "_outp");
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
@ -719,8 +717,6 @@ public:
// Return the function value
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "_outv");
Replaceall(tm, "$result", "_outv");
if (GetFlag(n, "feature:new"))
@ -741,22 +737,31 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
}
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$result", "_outv");
Printf(f->code, "%s\n", tm);
Delete(tm);
}
Printf(f->code, "return _out;\n");
Printf(f->code, "fail:\n"); // we should free locals etc if this happens
// Execute cleanup code if branched to fail: label
Printf(f->code, "fail:\n");
Printv(f->code, cleanup, NIL);
Printf(f->code, "return octave_value_list();\n");
// Execute cleanup code if exception was thrown
Printf(f->code, "}\n");
Printf(f->code, "catch(...) {\n");
Printv(f->code, cleanup, NIL);
Printf(f->code, "throw;\n");
Printf(f->code, "}\n");
// End wrapper function
Printf(f->code, "}\n");
/* Substitute the cleanup code */
@ -800,7 +805,7 @@ public:
Printf(tmp, "}");
Wrapper_add_local(f, "argv", tmp);
Printv(f->code, dispatch, "\n", NIL);
Printf(f->code, "error(\"No matching function for overload\");\n", iname);
Printf(f->code, "error(\"No matching function for overload\");\n");
Printf(f->code, "return octave_value_list();\n");
Printv(f->code, "}\n", NIL);
@ -830,12 +835,10 @@ public:
String *setwname = Swig_name_wrapper(setname);
Octave_begin_function(n, setf->def, setname, setwname, true);
Printf(setf->def, "if (!SWIG_check_num_args(\"%s_set\",args.length(),1,1,0)) return octave_value_list();", iname);
Printf(setf->code, "if (!SWIG_check_num_args(\"%s_set\",args.length(),1,1,0)) return octave_value_list();", iname);
if (is_assignable(n)) {
Setattr(n, "wrap:name", setname);
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
Replaceall(tm, "$source", "args(0)");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "args(0)");
if (Getattr(n, "tmap:varin:implicitconv")) {
Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
@ -845,8 +848,9 @@ public:
} else {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0));
}
Append(setf->code, "return octave_value_list();\n");
Append(setf->code, "fail:\n");
Printf(setf->code, "return octave_value_list();\n");
Append(setf->code, "return octave_value_list();\n");
} else {
Printf(setf->code, "return octave_set_immutable(args,nargout);");
}
@ -858,18 +862,16 @@ public:
Octave_begin_function(n, getf->def, getname, getwname, true);
Wrapper_add_local(getf, "obj", "octave_value obj");
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "obj");
Replaceall(tm, "$result", "obj");
addfail = emit_action_code(n, getf->code, tm);
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t, 0));
}
Append(getf->code, " return obj;\n");
Append(getf->code, "return obj;\n");
if (addfail) {
Append(getf->code, "fail:\n");
Append(getf->code, " return octave_value_list();\n");
Append(getf->code, "return octave_value_list();\n");
}
Append(getf->code, "}\n");
Wrapper_print(getf, f_wrappers);
@ -904,8 +906,6 @@ public:
value = wname;
}
if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", cppvalue ? cppvalue : value);
Replaceall(tm, "$nsname", iname);
Printf(f_init, "%s\n", tm);

View file

@ -21,6 +21,7 @@
String *argv_template_string;
String *argc_template_string;
namespace {
struct Overloaded {
Node *n; /* Node */
int argc; /* Argument count */
@ -28,6 +29,7 @@ struct Overloaded {
int error; /* Ambiguity error */
bool implicitconv_function; /* For ordering implicitconv functions*/
};
}
static int fast_dispatch_mode = 0;
static int cast_dispatch_mode = 0;
@ -809,7 +811,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar
}
if (num_arguments) {
Printf(f, "int _v;\n");
Printf(f, "int _v = 0;\n");
}
int num_braces = 0;

View file

@ -725,14 +725,11 @@ public:
/* Produce string representation of source and target arguments */
sprintf(source, "ST(%d)", i);
String *target = Getattr(p, "lname");
if (i >= num_required) {
Printf(f->code, " if (items > %d) {\n", i);
}
if ((tm = Getattr(p, "tmap:in"))) {
Replaceall(tm, "$target", target);
Replaceall(tm, "$source", source);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source); /* Save input location */
@ -767,7 +764,6 @@ public:
/* 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");
} else {
@ -778,7 +774,6 @@ public:
/* Insert cleanup code */
for (i = 0, p = l; p; i++) {
if ((tm = Getattr(p, "tmap:freearg"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(cleanup, tm, "\n", NIL);
@ -793,8 +788,6 @@ public:
for (i = 0, p = l; p; i++) {
if ((tm = Getattr(p, "tmap:argout"))) {
SwigType *t = Getattr(p, "type");
Replaceall(tm, "$source", Getattr(p, "lname"));
Replaceall(tm, "$target", "ST(argvi)");
Replaceall(tm, "$result", "ST(argvi)");
if (is_shadow(t)) {
Replaceall(tm, "$shadow", "SWIG_SHADOW");
@ -855,8 +848,6 @@ public:
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
SwigType *t = Getattr(n, "type");
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "ST(argvi)");
Replaceall(tm, "$result", "ST(argvi)");
if (is_shadow(t)) {
Replaceall(tm, "$shadow", "SWIG_SHADOW");
@ -884,13 +875,11 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
}
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
@ -995,8 +984,6 @@ public:
/* Check for a few typemaps */
tm = Swig_typemap_lookup("varin", n, name, 0);
if (tm) {
Replaceall(tm, "$source", "sv");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "sv");
/* Printf(setf->code,"%s\n", tm); */
emit_action_code(n, setf->code, tm);
@ -1019,9 +1006,7 @@ public:
Printv(getf->code, tab4, "MAGIC_PPERL\n", NIL);
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$target", "sv");
Replaceall(tm, "$result", "sv");
Replaceall(tm, "$source", name);
if (is_shadow(t)) {
Replaceall(tm, "$shadow", "SWIG_SHADOW");
} else {
@ -1111,8 +1096,6 @@ public:
}
if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
if (is_shadow(type)) {
Replaceall(tm, "$shadow", "SWIG_SHADOW");
@ -1121,8 +1104,6 @@ public:
}
Printf(constant_tab, "%s,\n", tm);
} else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
if (is_shadow(type)) {
Replaceall(tm, "$shadow", "SWIG_SHADOW");
@ -2341,7 +2322,7 @@ public:
Replaceall(tm, "$error", "ERRSV");
Printv(w->code, Str(tm), "\n", NIL);
} else {
Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n", classname, pyname);
Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n");
}
Append(w->code, "}\n");
Delete(tm);

File diff suppressed because it is too large Load diff

View file

@ -1,904 +0,0 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* pike.cxx
*
* Pike language module for SWIG.
* ----------------------------------------------------------------------------- */
/*
* Notes:
*
* - The current approach used for "out" typemaps is inconsistent with
* how "out" typemaps are handled by other language modules. Instead
* of converting the C/C++ type ($1) to a Pike object type (e.g. a
* struct svalue), we're just calling the appropriate push_XXX
* (e.g. push_int) to push the return value onto the stack.
*
* - Pike classes can't have static member functions or data, so we need
* to find some other appropriate mapping for C++ static member functions
* and data.
*
* - Pike doesn't seem to provide any default way to print the memory
* address, etc. for extension objects. Should we do something here?
*
*/
#include "swigmod.h"
#include <ctype.h> // for isalnum()
static const char *usage = "\
Pike Options (available with -pike)\n\
[no additional options]\n\
\n";
class PIKE:public Language {
private:
File *f_begin;
File *f_runtime;
File *f_header;
File *f_wrappers;
File *f_init;
File *f_classInit;
String *PrefixPlusUnderscore;
int current;
// Wrap modes
enum {
NO_CPP,
MEMBER_FUNC,
CONSTRUCTOR,
DESTRUCTOR,
MEMBER_VAR,
CLASS_CONST,
STATIC_FUNC,
STATIC_VAR
};
public:
/* ---------------------------------------------------------------------
* PIKE()
*
* Initialize member data
* --------------------------------------------------------------------- */
PIKE() {
f_begin = 0;
f_runtime = 0;
f_header = 0;
f_wrappers = 0;
f_init = 0;
f_classInit = 0;
PrefixPlusUnderscore = 0;
current = NO_CPP;
}
/* ---------------------------------------------------------------------
* main()
*
* Parse command line options and initializes variables.
* --------------------------------------------------------------------- */
virtual void main(int argc, char *argv[]) {
/* Set location of SWIG library */
SWIG_library_directory("pike");
/* 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);
}
}
}
/* Add a symbol to the parser for conditional compilation */
Preprocessor_define("SWIGPIKE 1", 0);
/* Set language-specific configuration file */
SWIG_config_file("pike.swg");
/* Set typemap language */
SWIG_typemap_lang("pike");
/* Enable overloaded methods support */
allow_overloading();
}
/* ---------------------------------------------------------------------
* top()
* --------------------------------------------------------------------- */
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_begin = NewFile(outfile, "w", SWIG_output_files());
if (!f_begin) {
FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE);
}
f_runtime = NewString("");
f_init = NewString("");
f_classInit = NewString("");
f_header = NewString("");
f_wrappers = NewString("");
/* Register file targets with the SWIG file handler */
Swig_register_filebyname("header", f_header);
Swig_register_filebyname("wrapper", f_wrappers);
Swig_register_filebyname("begin", f_begin);
Swig_register_filebyname("runtime", f_runtime);
Swig_register_filebyname("init", f_init);
Swig_register_filebyname("classInit", f_classInit);
/* Standard stuff for the SWIG runtime section */
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGPIKE\n#define SWIGPIKE\n#endif\n\n");
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", "%n%c_create");
Swig_name_register("destroy", "%n%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_runtime, f_begin);
Dump(f_header, f_begin);
Dump(f_wrappers, f_begin);
Wrapper_pretty_print(f_init, f_begin);
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Delete(f_classInit);
Delete(f_runtime);
Delete(f_begin);
/* Done */
return SWIG_OK;
}
/* ------------------------------------------------------------
* validIdentifier()
* ------------------------------------------------------------ */
virtual int validIdentifier(String *s) {
char *c = Char(s);
const char *c0 = c;
const char *c1 = c0 + 1;
while (*c) {
if (*c == '`' && c == c0) {
c++;
continue;
}
if ((*c == '+' || *c == '-' || *c == '*' || *c == '/') && c == c1) {
c++;
continue;
}
if (!(isalnum(*c) || (*c == '_')))
return 0;
c++;
}
return 1;
}
/* ------------------------------------------------------------
* importDirective()
* ------------------------------------------------------------ */
virtual int importDirective(Node *n) {
String *modname = Getattr(n, "module");
if (modname) {
Printf(f_init, "pike_require(\"%s\");\n", modname);
}
return Language::importDirective(n);
}
/* ------------------------------------------------------------
* strip()
*
* For names that begin with the current class prefix plus an
* underscore (e.g. "Foo_enum_test"), return the base function
* name (i.e. "enum_test").
* ------------------------------------------------------------ */
String *strip(const DOHconst_String_or_char_ptr name) {
String *s = Copy(name);
if (Strncmp(name, PrefixPlusUnderscore, Len(PrefixPlusUnderscore)) != 0) {
return s;
}
Replaceall(s, PrefixPlusUnderscore, "");
return s;
}
/* ------------------------------------------------------------
* add_method()
* ------------------------------------------------------------ */
void add_method(const DOHconst_String_or_char_ptr name, const DOHconst_String_or_char_ptr function, const DOHconst_String_or_char_ptr 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: // shouldn't have gotten here for CLASS_CONST nodes
default: // what is this?
assert(false);
}
Delete(rename);
}
/* ---------------------------------------------------------------------
* functionWrapper()
*
* Create a function declaration and register it with the interpreter.
* --------------------------------------------------------------------- */
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");
Parm *p;
String *tm;
int i;
String *overname = 0;
if (Getattr(n, "sym:overloaded")) {
overname = Getattr(n, "sym:overname");
} else {
if (!addSymbol(iname, n))
return SWIG_ERROR;
}
Wrapper *f = NewWrapper();
// Emit all of the local variables for holding arguments.
emit_parameter_variables(l, f);
/* Attach the standard typemaps */
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 */
// int offset = (current == MEMBER_VAR) ? 1 : 0;
int offset = 0;
String *wname = Swig_name_wrapper(iname);
if (overname) {
Append(wname, overname);
}
Setattr(n, "wrap:name", wname);
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");
}
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);
Delete(lstr);
} 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);
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");
if (pikedesc) {
Printv(description, pikedesc, " ", NIL);
}
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));
break;
}
}
p = nextSibling(p);
}
/* Check for trailing varargs */
if (varargs) {
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");
} 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");
} else {
p = nextSibling(p);
}
}
/* 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");
} else {
p = nextSibling(p);
}
}
/* Emit the function call */
String *actioncode = emit_action(n);
/* Clear the return stack */
Printf(actioncode, "pop_n_elems(args);\n");
/* Return the function value */
if (current == CONSTRUCTOR) {
Printv(actioncode, "THIS = (void *) ", Swig_cresult_name(), ";\n", NIL);
Printv(description, ", tVoid", NIL);
} else if (current == DESTRUCTOR) {
Printv(description, ", tVoid", NIL);
} else {
Printv(description, ", ", NIL);
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
actioncode = 0;
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "resultobj");
Replaceall(tm, "$result", "resultobj");
if (GetFlag(n, "feature:new")) {
Replaceall(tm, "$owner", "1");
} else {
Replaceall(tm, "$owner", "0");
}
String *pikedesc = Getattr(n, "tmap:out:pikedesc");
if (pikedesc) {
Printv(description, pikedesc, NIL);
}
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);
}
}
if (actioncode) {
Append(f->code, actioncode);
Delete(actioncode);
}
emit_return_variable(n, d, f);
/* Output argument output code */
Printv(f->code, outarg, NIL);
/* Output cleanup code */
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("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
/* Close the function */
Printf(f->code, "}\n");
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
/* Substitute the function name */
Replaceall(f->code, "$symname", iname);
Replaceall(f->code, "$result", "resultobj");
/* Dump the function out */
Wrapper_print(f, f_wrappers);
/* Now register the function with the interpreter. */
if (!Getattr(n, "sym:overloaded")) {
add_method(iname, wname, description);
} else {
if (!Getattr(n, "sym:nextSibling")) {
dispatchFunction(n);
}
}
Delete(cleanup);
Delete(outarg);
Delete(description);
Delete(wname);
DelWrapper(f);
return SWIG_OK;
}
/* ------------------------------------------------------------
* dispatchFunction()
*
* Emit overloading dispatch function
* ------------------------------------------------------------ */
void dispatchFunction(Node *n) {
/* Last node in overloaded chain */
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);
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) {
Printf(description, " tVoid");
} else {
String *pd = Getattr(n, "tmap:out:pikedesc");
if (pd)
Printf(description, " %s", pd);
}
add_method(symname, wname, description);
Delete(description);
DelWrapper(f);
Delete(dispatch);
Delete(tmp);
Delete(wname);
}
/* ------------------------------------------------------------
* variableWrapper()
* ------------------------------------------------------------ */
virtual int variableWrapper(Node *n) {
return Language::variableWrapper(n);
}
/* ------------------------------------------------------------
* constantWrapper()
* ------------------------------------------------------------ */
virtual int constantWrapper(Node *n) {
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");
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
if (SwigType_type(type) == T_MPOINTER) {
/* Special hook for member pointer */
String *wname = Swig_name_wrapper(symname);
Printf(f_header, "static %s = %s;\n", SwigType_str(type, wname), value);
value = wname;
} else if (SwigType_type(type) == T_CHAR && is_enum_item) {
type = NewSwigType(T_INT);
Setattr(n, "type", type);
}
/* Perform constant typemap substitution */
String *tm = Swig_typemap_lookup("constant", n, value, 0);
if (tm) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", symname);
Replaceall(tm, "$symname", symname);
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_restore(n);
return SWIG_OK;
}
/* ------------------------------------------------------------
* nativeWrapper()
* ------------------------------------------------------------ */
virtual int nativeWrapper(Node *n) {
// return Language::nativeWrapper(n);
String *name = Getattr(n, "sym:name");
String *wrapname = Getattr(n, "wrap:name");
if (!addSymbol(wrapname, n))
return SWIG_ERROR;
add_method(name, wrapname, 0);
return SWIG_OK;
}
/* ------------------------------------------------------------
* enumDeclaration()
* ------------------------------------------------------------ */
virtual int enumDeclaration(Node *n) {
return Language::enumDeclaration(n);
}
/* ------------------------------------------------------------
* enumvalueDeclaration()
* ------------------------------------------------------------ */
virtual int enumvalueDeclaration(Node *n) {
return Language::enumvalueDeclaration(n);
}
/* ------------------------------------------------------------
* classDeclaration()
* ------------------------------------------------------------ */
virtual int classDeclaration(Node *n) {
return Language::classDeclaration(n);
}
/* ------------------------------------------------------------
* classHandler()
* ------------------------------------------------------------ */
virtual int classHandler(Node *n) {
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");
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);
Delete(basemangle);
Delete(basetype);
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);
}
*/
/* 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);
String *tm = SwigType_manglestr(tt);
Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) pr);\n", tm);
Delete(tm);
Delete(tt);
Delete(PrefixPlusUnderscore);
PrefixPlusUnderscore = 0;
return SWIG_OK;
}
/* ------------------------------------------------------------
* memberfunctionHandler()
*
* Method for adding C++ member function
* ------------------------------------------------------------ */
virtual int memberfunctionHandler(Node *n) {
current = MEMBER_FUNC;
Language::memberfunctionHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* constructorHandler()
*
* Method for adding C++ member constructor
* ------------------------------------------------------------ */
virtual int constructorHandler(Node *n) {
current = CONSTRUCTOR;
Language::constructorHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* destructorHandler()
* ------------------------------------------------------------ */
virtual int destructorHandler(Node *n) {
current = DESTRUCTOR;
Language::destructorHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* membervariableAccessors()
* ------------------------------------------------------------ */
void membervariableAccessors(List *membervariables) {
String *name;
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;
break;
}
i = Next(i);
}
/* Create a function to set the values of the (mutable) variables */
if (need_setter) {
Wrapper *wrapper = NewWrapper();
String *setter = Swig_name_member(NSPACE_TODO, getClassPrefix(), "`->=");
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")) {
name = Getattr(i.item, "name");
funcname = Swig_name_wrapper(Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, getClassPrefix(), name)));
Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name);
Printf(wrapper->code, "%s(args);\n", funcname);
Printf(wrapper->code, "return;\n");
Printf(wrapper->code, "}\n");
Delete(funcname);
}
i = Next(i);
}
/* Close the function */
Printf(wrapper->code, "pop_n_elems(args);\n");
Printf(wrapper->code, "}\n");
/* 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);
Delete(description);
/* Clean up */
Delete(wname);
Delete(setter);
DelWrapper(wrapper);
}
/* Create a function to get the values of the (mutable) variables */
Wrapper *wrapper = NewWrapper();
String *getter = Swig_name_member(NSPACE_TODO, getClassPrefix(), "`->");
String *wname = Swig_name_wrapper(getter);
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) {
name = Getattr(i.item, "name");
funcname = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, getClassPrefix(), name)));
Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name);
Printf(wrapper->code, "%s(args);\n", funcname);
Printf(wrapper->code, "return;\n");
Printf(wrapper->code, "}\n");
Delete(funcname);
i = Next(i);
}
/* Close the function */
Printf(wrapper->code, "pop_n_elems(args);\n");
Printf(wrapper->code, "}\n");
/* 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);
DelWrapper(wrapper);
}
/* ------------------------------------------------------------
* membervariableHandler()
* ------------------------------------------------------------ */
virtual int membervariableHandler(Node *n) {
List *membervariables = Getattr(getCurrentClass(), "membervariables");
if (!membervariables) {
membervariables = NewList();
Setattr(getCurrentClass(), "membervariables", membervariables);
}
Append(membervariables, n);
current = MEMBER_VAR;
Language::membervariableHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* -----------------------------------------------------------------------
* staticmemberfunctionHandler()
*
* Wrap a static C++ function
* ---------------------------------------------------------------------- */
virtual int staticmemberfunctionHandler(Node *n) {
current = STATIC_FUNC;
Language::staticmemberfunctionHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* memberconstantHandler()
*
* Create a C++ constant
* ------------------------------------------------------------ */
virtual int memberconstantHandler(Node *n) {
current = CLASS_CONST;
constantWrapper(n);
current = NO_CPP;
return SWIG_OK;
}
/* ---------------------------------------------------------------------
* staticmembervariableHandler()
* --------------------------------------------------------------------- */
virtual int staticmembervariableHandler(Node *n) {
current = STATIC_VAR;
Language::staticmembervariableHandler(n);
current = NO_CPP;
return SWIG_OK;
}
};
/* -----------------------------------------------------------------------------
* swig_pike() - Instantiate module
* ----------------------------------------------------------------------------- */
static Language *new_swig_pike() {
return new PIKE();
}
extern "C" Language *swig_pike(void) {
return new_swig_pike();
}

View file

@ -16,7 +16,6 @@
#include "cparse.h"
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include "pydoc.h"
#include <stdint.h>
@ -94,6 +93,7 @@ static int nortti = 0;
static int relativeimport = 0;
/* flags for the make_autodoc function */
namespace {
enum autodoc_t {
AUTODOC_CLASS,
AUTODOC_CTOR,
@ -104,7 +104,7 @@ enum autodoc_t {
AUTODOC_CONST,
AUTODOC_VAR
};
}
static const char *usage1 = "\
Python Options (available with -python)\n\
@ -847,8 +847,13 @@ public:
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
Printv(f_shadow_py, "\nfrom sys import version_info as _swig_python_version_info\n", NULL);
Printv(f_shadow_py, "if _swig_python_version_info < (2, 7, 0):\n", NULL);
Printv(f_shadow_py, tab4, "raise RuntimeError(\"Python 2.7 or later required\")\n\n", NULL);
if (py3) {
Printv(f_shadow_py, "if _swig_python_version_info < (3, 0):\n", NULL);
Printv(f_shadow_py, tab4, "raise RuntimeError(\"Python 3.x or later required\")\n\n", NULL);
} else {
Printv(f_shadow_py, "if _swig_python_version_info < (2, 7, 0):\n", NULL);
Printv(f_shadow_py, tab4, "raise RuntimeError(\"Python 2.7 or later required\")\n\n", NULL);
}
if (Len(f_shadow_after_begin) > 0)
Printv(f_shadow_py, f_shadow_after_begin, "\n", NIL);
@ -1485,8 +1490,15 @@ public:
String *build_combined_docstring(Node *n, autodoc_t ad_type, const String *indent = "", bool low_level = false) {
String *docstr = Getattr(n, "feature:docstring");
if (docstr && Len(docstr)) {
docstr = Copy(docstr);
if (docstr) {
// Simplify the code below by just ignoring empty docstrings.
if (!Len(docstr))
docstr = NULL;
else
docstr = Copy(docstr);
}
if (docstr) {
char *t = Char(docstr);
if (*t == '{') {
Delitem(docstr, 0);
@ -1497,7 +1509,7 @@ public:
if (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")) {
String *autodoc = make_autodoc(n, ad_type, low_level);
if (autodoc && Len(autodoc) > 0) {
if (docstr && Len(docstr)) {
if (docstr) {
Append(autodoc, "\n");
Append(autodoc, docstr);
}
@ -1510,7 +1522,7 @@ public:
Delete(autodoc);
}
if (!docstr || !Len(docstr)) {
if (!docstr) {
if (doxygen) {
docstr = Getattr(n, "python:docstring");
if (!docstr && doxygenTranslator->hasDocumentation(n)) {
@ -1565,7 +1577,8 @@ public:
String *docstring(Node *n, autodoc_t ad_type, const String *indent, bool low_level = false) {
String *docstr = build_combined_docstring(n, ad_type, indent, low_level);
if (!Len(docstr))
const int len = Len(docstr);
if (!len)
return docstr;
// Notice that all comments are created as raw strings (prefix "r"),
@ -1578,9 +1591,32 @@ public:
// escape '\x'. '\' may additionally appear in verbatim or htmlonly sections
// of doxygen doc, Latex expressions, ...
String *doc = NewString("");
Append(doc, "r\"\"\"");
// Determine which kind of quotes to use as delimiters: for single line
// strings we can avoid problems with having a quote as the last character
// of the docstring by using different kind of quotes as delimiters. For
// multi-line strings this problem doesn't arise, as we always have a new
// line or spaces at the end of it, but it still does no harm to do it for
// them too.
//
// Note: we use double quotes by default, i.e. if there is no reason to
// prefer using single ones, for consistency with the older SWIG versions.
const bool useSingleQuotes = (Char(docstr))[len - 1] == '"';
Append(doc, useSingleQuotes ? "r'''" : "r\"\"\"");
// We also need to avoid having triple quotes of whichever type we use, as
// this would break Python doc string syntax too. Unfortunately there is no
// way to have triple quotes inside of raw-triple-quoted string, so we have
// to break the string in parts and rely on concatenation of the adjacent
// string literals.
if (useSingleQuotes)
Replaceall(docstr, "'''", "''' \"'''\" '''");
else
Replaceall(docstr, "\"\"\"", "\"\"\" '\"\"\"' \"\"\"");
Append(doc, docstr);
Append(doc, "\"\"\"");
Append(doc, useSingleQuotes ? "'''" : "\"\"\"");
Delete(docstr);
return doc;
@ -2494,7 +2530,7 @@ public:
String *symname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(symname);
const char *builtin_kwargs = builtin_ctor ? ", PyObject *SWIGUNUSEDPARM(kwargs)" : "";
const char *builtin_kwargs = builtin_ctor ? ", PyObject *kwargs" : "";
Printv(f->def, linkage, builtin_ctor ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
Wrapper_add_local(f, "argc", "Py_ssize_t argc");
@ -2504,6 +2540,9 @@ public:
if (!fastunpack) {
Wrapper_add_local(f, "ii", "Py_ssize_t ii");
if (builtin_ctor)
Printf(f->code, "if (!SWIG_Python_CheckNoKeywords(kwargs, \"%s\")) SWIG_fail;\n", symname);
if (maxargs - (add_self ? 1 : 0) > 0) {
Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
Append(f->code, "argc = PyObject_Length(args);\n");
@ -2519,8 +2558,9 @@ public:
if (add_self)
Append(f->code, "argc++;\n");
} else {
String *iname = Getattr(n, "sym:name");
Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args, \"%s\", 0, %d, argv%s))) SWIG_fail;\n", iname, maxargs, add_self ? "+1" : "");
if (builtin_ctor)
Printf(f->code, "if (!SWIG_Python_CheckNoKeywords(kwargs, \"%s\")) SWIG_fail;\n", symname);
Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args, \"%s\", 0, %d, argv%s))) SWIG_fail;\n", symname, maxargs, add_self ? "+1" : "");
if (add_self)
Append(f->code, "argv[0] = self;\n");
else
@ -2701,8 +2741,12 @@ public:
--tuple_required;
}
num_fixed_arguments = tuple_required;
// builtin handles/checks kwargs by default except in constructor wrappers so we need to explicitly handle them in the C constructor wrapper
// The check below is for zero arguments. Sometimes (eg directors) self is the first argument for a method with zero arguments.
if (((num_arguments == 0) && (num_required == 0)) || ((num_arguments == 1) && (num_required == 1) && Getattr(l, "self")))
allow_kwargs = 0;
if (!builtin_ctor)
allow_kwargs = 0;
varargs = emit_isvarargs(l);
String *wname = Copy(wrapper_name);
@ -2710,12 +2754,12 @@ public:
Append(wname, overname);
}
const char *builtin_kwargs = builtin_ctor ? ", PyObject *SWIGUNUSEDPARM(kwargs)" : "";
const char *builtin_kwargs = builtin_ctor ? ", PyObject *kwargs" : "";
if (!allow_kwargs || overname) {
if (!varargs) {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
} else {
Printv(f->def, linkage, wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs", builtin_kwargs, ") {", NIL);
}
if (allow_kwargs) {
Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions (%s).\n", Swig_name_decl(n));
@ -2728,7 +2772,7 @@ public:
}
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL);
}
if (!builtin || !in_class || tuple_arguments > 0) {
if (!builtin || !in_class || tuple_arguments > 0 || builtin_ctor) {
if (!allow_kwargs) {
Append(parse_args, " if (!PyArg_ParseTuple(args, \"");
} else {
@ -2824,8 +2868,6 @@ public:
} else {
Replaceall(tm, "$self", "obj0");
}
Replaceall(tm, "$source", source);
Replaceall(tm, "$target", ln);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source); /* Save the location of the object */
@ -2877,14 +2919,13 @@ public:
Printv(f->locals, " char * kwnames[] = ", kwargs, ";\n", NIL);
}
if (builtin && !funpack && in_class && tuple_arguments == 0) {
Printf(parse_args, " if (args && PyTuple_Check(args) && PyTuple_GET_SIZE(args) > 0) SWIG_exception_fail(SWIG_TypeError, \"%s takes no arguments\");\n", iname);
} else if (use_parse || allow_kwargs) {
if (use_parse || allow_kwargs) {
Printf(parse_args, ":%s\"", iname);
Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL);
funpack = 0;
} else {
Clear(parse_args);
if (funpack) {
Clear(f->def);
if (overname) {
@ -2897,6 +2938,8 @@ public:
} else {
int is_tp_call = Equal(Getattr(n, "feature:python:slot"), "tp_call");
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
if (builtin_ctor)
Printf(parse_args, "if (!SWIG_Python_CheckNoKeywords(kwargs, \"%s\")) SWIG_fail;\n", iname);
if (onearg && !builtin_ctor && !is_tp_call) {
Printf(parse_args, "if (!args) SWIG_fail;\n");
Append(parse_args, "swig_obj[0] = args;\n");
@ -2907,8 +2950,14 @@ public:
}
}
} else {
Printf(parse_args, "if (!PyArg_UnpackTuple(args, \"%s\", %d, %d", iname, num_fixed_arguments, tuple_arguments);
Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL);
if (builtin_ctor)
Printf(parse_args, "if (!SWIG_Python_CheckNoKeywords(kwargs, \"%s\")) SWIG_fail;\n", iname);
if (builtin && in_class && tuple_arguments == 0) {
Printf(parse_args, " if (args && PyTuple_Check(args) && PyTuple_GET_SIZE(args) > 0) SWIG_exception_fail(SWIG_TypeError, \"%s takes no arguments\");\n", iname);
} else {
Printf(parse_args, "if (!PyArg_UnpackTuple(args, \"%s\", %d, %d", iname, num_fixed_arguments, tuple_arguments);
Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL);
}
}
}
@ -2926,7 +2975,6 @@ public:
/* 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");
} else {
@ -2948,7 +2996,6 @@ public:
}
}
if (tm && (Len(tm) != 0)) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
}
p = Getattr(p, "tmap:freearg:next");
@ -2960,8 +3007,6 @@ public:
/* Insert argument output code */
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);
@ -3050,8 +3095,6 @@ public:
} else {
Replaceall(tm, "$self", "obj0");
}
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "resultobj");
Replaceall(tm, "$result", "resultobj");
if (builtin_ctor) {
Replaceall(tm, "$owner", "SWIG_BUILTIN_INIT");
@ -3117,7 +3160,6 @@ public:
/* Look to see if there is any newfree cleanup code */
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
@ -3125,7 +3167,6 @@ public:
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
@ -3208,10 +3249,10 @@ public:
Printf(f->code, " Py_XINCREF(swig_obj[i + %d]);\n", num_fixed_arguments);
Printf(f->code, "}\n");
} else {
Printf(f->code, "newargs = PyTuple_GetSlice(args,0,%d);\n", num_fixed_arguments);
Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args));\n", num_fixed_arguments);
Printf(f->code, "newargs = PyTuple_GetSlice(args, 0, %d);\n", num_fixed_arguments);
Printf(f->code, "varargs = PyTuple_GetSlice(args, %d, PyTuple_Size(args));\n", num_fixed_arguments);
}
Printf(f->code, "resultobj = %s__varargs__(%s,newargs,varargs);\n", wname, builtin ? "self" : "NULL");
Printf(f->code, "resultobj = %s__varargs__(%s, newargs, varargs%s);\n", wname, builtin ? "self" : "NULL", strlen(builtin_kwargs) == 0 ? "" : ", kwargs");
Append(f->code, "Py_XDECREF(newargs);\n");
Append(f->code, "Py_XDECREF(varargs);\n");
Append(f->code, "return resultobj;\n");
@ -3411,8 +3452,6 @@ public:
}
Printf(setf->def, "SWIGINTERN int %s(PyObject *_val) {", varsetname);
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
Replaceall(tm, "$source", "_val");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "_val");
if (Getattr(n, "tmap:varin:implicitconv")) {
Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
@ -3453,8 +3492,6 @@ public:
Append(getf->code, " (void)self;\n");
}
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "pyobj");
Replaceall(tm, "$result", "pyobj");
addfail = emit_action_code(n, getf->code, tm);
Delete(tm);
@ -3534,8 +3571,6 @@ public:
}
if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
Printf(const_code, "%s,\n", tm);
Delete(tm);
@ -3550,8 +3585,6 @@ public:
}
if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
if (needs_swigconstant(n) && !builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER)) && (!in_class || !Getattr(n, "feature:python:callback"))) {
// Generate `*_swigconstant()` method which registers the new constant.
@ -3563,7 +3596,7 @@ public:
// class type (the SWIG_init() is called before shadow classes are
// defined and registered).
Printf(f_wrappers, "SWIGINTERN PyObject *%s_swigconstant(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", iname);
Printf(f_wrappers, tab2 "PyObject *module;\n", tm);
Printf(f_wrappers, tab2 "PyObject *module;\n");
Printf(f_wrappers, tab2 "PyObject *d;\n");
Printf(f_wrappers, tab2 "if (!SWIG_Python_UnpackTuple(args, \"swigconstant\", 1, 1, &module)) return NULL;\n");
Printf(f_wrappers, tab2 "d = PyModule_GetDict(module);\n");
@ -3973,7 +4006,7 @@ public:
if (GetFlag(mgetset, "static")) {
Printf(f, "static PyGetSetDef %s_def = %s;\n", gspair, entry);
Printf(f_init, "static_getset = SwigPyStaticVar_new_getset(metatype, &%s_def);\n", gspair);
Printf(f_init, "PyDict_SetItemString(d, static_getset->d_getset->name, (PyObject *) static_getset);\n", memname);
Printf(f_init, "PyDict_SetItemString(d, static_getset->d_getset->name, (PyObject *) static_getset);\n");
Printf(f_init, "Py_DECREF(static_getset);\n");
} else {
Printf(getset_def, " %s,\n", entry);
@ -4129,6 +4162,13 @@ public:
Printv(f, "#if PY_VERSION_HEX >= 0x03040000\n", NIL);
printSlot(f, getSlot(n, "feature:python:tp_finalize"), "tp_finalize", "destructor");
Printv(f, "#endif\n", NIL);
Printv(f, "#if PY_VERSION_HEX >= 0x03080000\n", NIL);
printSlot(f, getSlot(n, "feature:python:tp_vectorcall"), "tp_vectorcall", "vectorcallfunc");
Printv(f, "#endif\n", NIL);
Printv(f, "#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)\n", NIL);
printSlot(f, getSlot(), "tp_print");
Printv(f, "#endif\n", NIL);
Printv(f, "#ifdef COUNT_ALLOCS\n", NIL);
printSlot(f, getSlot(n, "feature:python:tp_allocs"), "tp_allocs", "Py_ssize_t");
printSlot(f, getSlot(n, "feature:python:tp_frees"), "tp_frees", "Py_ssize_t");
@ -4256,6 +4296,10 @@ public:
// struct _dictkeysobject *ht_cached_keys;
printSlot(f, getSlot(n, "feature:python:ht_cached_keys"), "ht_cached_keys");
Printv(f, "#endif\n", NIL);
Printv(f, "#if PY_VERSION_HEX >= 0x03090000\n", NIL);
printSlot(f, getSlot(n, "feature:python:ht_module"), "ht_module", "PyObject *");
Printv(f, "#endif\n", NIL);
Printf(f, "};\n\n");
String *clientdata = NewString("");
@ -4411,7 +4455,9 @@ public:
Printf(f_shadow, "(Exception)");
} else {
Printf(f_shadow, "(object");
Printf(f_shadow, py3 && GetFlag(n, "feature:python:nondynamic") ? ", metaclass=_SwigNonDynamicMeta" : "", ")");
if (py3 && GetFlag(n, "feature:python:nondynamic")) {
Printf(f_shadow, ", metaclass=_SwigNonDynamicMeta");
}
Printf(f_shadow, ")");
}
}
@ -4819,6 +4865,7 @@ public:
String *classname = Swig_class_name(parent);
String *rclassname = Swig_class_name(getCurrentClass());
assert(rclassname);
(void)rclassname;
String *parms = make_pyParmList(n, true, false, allow_kwargs);
/* Pass 'self' only if using director */

View file

@ -36,11 +36,6 @@ static String * getRTypeName(SwigType *t, int *outCount = NULL) {
if(Strncmp(b, "struct ", 7) == 0)
Replace(b, "struct ", "", DOH_REPLACE_FIRST);
/* Printf(stdout, "<getRTypeName> %s,base = %s\n", t, b);
for(i = 0; i < Len(els); i++)
Printf(stdout, "%d) %s, ", i, Getitem(els,i));
Printf(stdout, "\n"); */
for(i = 0; i < Len(els); i++) {
String *el = Getitem(els, i);
if(Strcmp(el, "p.") == 0 || Strncmp(el, "a(", 2) == 0) {
@ -56,13 +51,6 @@ static String * getRTypeName(SwigType *t, int *outCount = NULL) {
Insert(tmp, 0, retName);
return tmp;
/*
if(count)
return(b);
Delete(b);
return(NewString(""));
*/
}
/* --------------------------------------------------------------
@ -101,7 +89,6 @@ static String *getRClassName(String *retType, int deRef=0, int upRef=0) {
static String * getRClassNameCopyStruct(String *retType, int addRef) {
String *tmp = NewString("");
#if 1
List *l = SwigType_split(retType);
int n = Len(l);
if(!l || n == 0) {
@ -127,24 +114,6 @@ static String * getRClassNameCopyStruct(String *retType, int addRef) {
}
}
#else
char *retName = Char(SwigType_manglestr(retType));
if(!retName)
return(tmp);
if(addRef) {
while(retName && strlen(retName) > 1 &&
strncmp(retName, "_p", 2) == 0) {
retName += 2;
Printf(tmp, "Ref");
}
}
if(retName[0] == '_')
retName ++;
Insert(tmp, 0, retName);
#endif
return tmp;
}
@ -285,12 +254,7 @@ protected:
int generateCopyRoutines(Node *n);
int DumpCode(Node *n);
int OutputMemberReferenceMethod(String *className, int isSet, List *el, File *out);
int OutputArrayMethod(String *className, List *el, File *out);
int OutputClassMemberTable(Hash *tb, File *out);
int OutputClassMethodsTable(File *out);
int OutputClassAccessInfo(Hash *tb, File *out);
int OutputMemberReferenceMethod(String *className, int isSet, List *memberList, List *nameList, List *typeList, File *out);
int defineArrayAccessors(SwigType *type);
void addNamespaceFunction(String *name) {
@ -334,10 +298,14 @@ protected:
void addAccessor(String *memberName, Wrapper *f,
String *name, int isSet = -1);
String *name, String *methodSetGet);
static int getFunctionPointerNumArgs(Node *n, SwigType *tt);
// filtering of class member lists by function type. Used in constructing accessors
// are we allowed to use stl style functors to customise this?
List* filterMemberList(List *class_member_function_types, List *class_member_other, String *R_MEMBER, bool equal);
protected:
bool copyStruct;
bool memoryProfile;
@ -367,11 +335,18 @@ protected:
String *member_name;
String *class_name;
String *R_MEMBER_NORMAL;
String *R_MEMBER_SET;
String *R_MEMBER_GET;
int processing_class_member_function;
List *class_member_functions;
List *class_member_set_functions;
// Spread out the lists so that they are simpler to process
// by storing the type of the method (i.e. set, get or nothing)
// and having separate lists for name, membername and wrapper
List *class_member_function_types;
List *class_member_function_names;
List *class_member_function_membernames;
List *class_member_function_wrappernames;
/* */
Hash *ClassMemberTable;
Hash *ClassMethodsTable;
@ -429,9 +404,14 @@ R::R() :
processing_member_access_function(0),
member_name(0),
class_name(0),
R_MEMBER_NORMAL(NewString("normal")),
R_MEMBER_SET(NewString("set")),
R_MEMBER_GET(NewString("get")),
processing_class_member_function(0),
class_member_functions(0),
class_member_set_functions(0),
class_member_function_types(0),
class_member_function_names(0),
class_member_function_membernames(0),
class_member_function_wrappernames(0),
ClassMemberTable(0),
ClassMethodsTable(0),
SClassDefs(0),
@ -510,7 +490,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
SwigType *funcparams = SwigType_functionpointer_decompose(rettype);
String *rtype = SwigType_str(rettype, 0);
// ParmList *parms = Getattr(n, "parms");
// ParmList *parms = Getattr(n, "parms");
// memory leak
ParmList *parms = SwigType_function_parms(SwigType_del_pointer(Copy(t)), n);
@ -654,7 +634,6 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
if(returnTM) {
String *tm = returnTM;
Replaceall(tm,"$input", "r_swig_cb_data->retValue");
Replaceall(tm,"$target", Swig_cresult_name());
replaceRClass(tm, rettype);
Replaceall(tm,"$owner", "0");
Replaceall(tm,"$disown","0");
@ -720,18 +699,6 @@ void R::init() {
}
#if 0
int R::cDeclaration(Node *n) {
SwigType *t = Getattr(n, "type");
SwigType *name = Getattr(n, "name");
if (debugMode)
Printf(stdout, "cDeclaration (%s): %s\n", name, SwigType_lstr(t, 0));
return Language::cDeclaration(n);
}
#endif
/* -------------------------------------------------------------
* Method from Language that is called to start the entire
* processing off, i.e. the generation of the code.
@ -755,6 +722,8 @@ int R::top(Node *n) {
Swig_register_filebyname("snamespace", s_namespace);
Printf(s_namespace, "useDynLib(%s)\n", DllName);
}
// Register the naming functions
Swig_name_register("wrapper", "R_swig_%f");
/* Associate the different streams with names so that they can be used in %insert directives by the
typemap code. */
@ -888,7 +857,33 @@ int R::DumpCode(Node *n) {
}
List *R::filterMemberList(List *class_member_types,
List *class_member_other,
String *R_MEMBER, bool equal) {
// filters class_member_other based on whether corresponding elements of
// class_member_function_types are equal or notequal to R_MEMBER
List *CM = NewList();
Iterator ftype, other;
for (ftype = First(class_member_types), other = First(class_member_other);
ftype.item;
ftype=Next(ftype), other=Next(other)) {
// verbose, clean up later if the overall structure works
if (equal) {
if (ftype.item == R_MEMBER) {
Append(CM, other.item);
}
} else {
if (ftype.item != R_MEMBER) {
Append(CM, other.item);
}
}
}
return(CM);
}
# if 0
// not called
/* -------------------------------------------------------------
* We may need to do more.... so this is left as a
* stub for the moment.
@ -975,9 +970,6 @@ int R::OutputClassMemberTable(Hash *tb, File *out) {
isSet = strcmp(ptr, "_set") == 0;
}
// OutputArrayMethod(className, el, out);
OutputMemberReferenceMethod(className, isSet, el, out);
if(outputNamespaceInfo)
Printf(s_namespace, "\"%s\"%s", className, i < n-1 ? "," : "");
}
@ -988,6 +980,8 @@ int R::OutputClassMemberTable(Hash *tb, File *out) {
return n;
}
// end not used
#endif
/* --------------------------------------------------------------
* Write the methods for $ or $<- for accessing a member field in an
* struct or union (or class).
@ -1000,9 +994,10 @@ int R::OutputClassMemberTable(Hash *tb, File *out) {
* out - the stream where we write the code.
* --------------------------------------------------------------*/
int R::OutputMemberReferenceMethod(String *className, int isSet,
List *el, File *out) {
int numMems = Len(el), j;
int R::OutputMemberReferenceMethod(String *className, int isSet,
List *memberList, List *nameList,
List *typeList, File *out) {
int numMems = Len(memberList), j;
int varaccessor = 0;
if (numMems == 0)
return SWIG_OK;
@ -1017,13 +1012,12 @@ int R::OutputMemberReferenceMethod(String *className, int isSet,
Node *itemList = NewHash();
bool has_prev = false;
for(j = 0; j < numMems; j+=3) {
String *item = Getitem(el, j);
String *dup = Getitem(el, j + 1);
char *ptr = Char(dup);
ptr = &ptr[Len(dup) - 3];
for(j = 0; j < numMems; j++) {
String *item = Getitem(memberList, j);
String *dup = Getitem(nameList, j);
String *setgetmethod = Getitem(typeList, j);
if (!strcmp(ptr, "get"))
if (setgetmethod == R_MEMBER_GET)
varaccessor++;
if (Getattr(itemList, item))
@ -1053,30 +1047,20 @@ int R::OutputMemberReferenceMethod(String *className, int isSet,
if (!isSet && varaccessor > 0) {
Printf(f->code, "%svaccessors = c(", tab8);
int first = 1;
for(j = 0; j < numMems; j+=3) {
String *item = Getitem(el, j);
String *dup = Getitem(el, j + 1);
char *ptr = Char(dup);
ptr = &ptr[Len(dup) - 3];
bool first = true;
for(j = 0; j < numMems; j++) {
String *item = Getitem(memberList, j);
String *setgetmethod = Getitem(typeList, j);
if (!strcmp(ptr, "get")) {
// Check the type here instead of the name
if (setgetmethod == R_MEMBER_GET) {
Printf(f->code, "%s'%s'", first ? "" : ", ", item);
first = 0;
first = false;
}
}
Printf(f->code, ");\n");
}
/* Printv(f->code, tab8,
"idx = pmatch(name, names(accessorFuns))\n",
tab8,
"if(is.na(idx)) {\n",
tab8, tab4,
"stop(\"No ", (isSet ? "modifiable" : "accessible"), " field named \", name, \" in ", className,
": fields are \", paste(names(accessorFuns), sep = \", \")",
")", "\n}\n", NIL); */
Printv(f->code, ";", tab8,
"idx = pmatch(name, names(accessorFuns));\n",
tab8,
@ -1098,8 +1082,8 @@ int R::OutputMemberReferenceMethod(String *className, int isSet,
}
Printf(f->code, "}\n");
Printf(out, "# Start of accessor method for %s\n", className);
String *classname_str = SwigType_namestr(className);
Printf(out, "# Start of accessor method for %s\n", classname_str);
Printf(out, "setMethod('$%s', '_p%s', ",
isSet ? "<-" : "",
getRClassName(className));
@ -1115,54 +1099,15 @@ int R::OutputMemberReferenceMethod(String *className, int isSet,
Printf(out, ");\n");
}
Printf(out, "# end of accessor method for %s\n", classname_str);
Delete(classname_str);
DelWrapper(attr);
DelWrapper(f);
Printf(out, "# end of accessor method for %s\n", className);
return SWIG_OK;
}
/* -------------------------------------------------------------
* Write the methods for [ or [<- for accessing a member field in an
* struct or union (or class).
* className - the name of the struct or union (e.g. Bar for struct Bar)
* el - a list of length 2 * # accessible member elements + 1.
* The first element is the name of the class.
* The other pairs are member name and the name of the R function to access it.
* out - the stream where we write the code.
* --------------------------------------------------------------*/
int R::OutputArrayMethod(String *className, List *el, File *out) {
int numMems = Len(el), j;
if(!el || numMems == 0)
return(0);
Printf(out, "# start of array methods for %s\n", className);
for(j = 0; j < numMems; j+=3) {
String *item = Getitem(el, j);
String *dup = Getitem(el, j + 1);
if (!Strcmp(item, "__getitem__")) {
Printf(out,
"setMethod('[', '_p%s', function(x, i, j, ..., drop =TRUE) ",
getRClassName(className));
Printf(out, " sapply(i, function (n) %s(x, as.integer(n-1))))\n\n", dup);
}
if (!Strcmp(item, "__setitem__")) {
Printf(out, "setMethod('[<-', '_p%s', function(x, i, j, ..., value)",
getRClassName(className));
Printf(out, " sapply(1:length(i), function(n) %s(x, as.integer(i[n]-1), value[n])))\n\n", dup);
}
}
Printf(out, "# end of array methods for %s\n", className);
return SWIG_OK;
}
/* -------------------------------------------------------------
* Called when a enumeration is to be processed.
* We want to call the R function defineEnumeration().
@ -1207,7 +1152,6 @@ int R::enumDeclaration(Node *n) {
Printf(enum_def_calls, "defineEnumeration(\"%s\",\n .values=c(%s))\n\n", ename, enum_values);
Delete(enum_values);
Delete(ename);
//Delete(symname);
}
return SWIG_OK;
}
@ -1335,31 +1279,21 @@ int R::variableWrapper(Node *n) {
* --------------------------------------------------------------*/
void R::addAccessor(String *memberName, Wrapper *wrapper, String *name,
int isSet) {
if(isSet < 0) {
int n = Len(name);
char *ptr = Char(name);
if (n>4) {
isSet = Strcmp(NewString(&ptr[n-4]), "_set") == 0;
}
String *methodSetGet) {
if (!class_member_function_names) {
class_member_function_names = NewList();
class_member_function_membernames = NewList();
class_member_function_wrappernames = NewList();
class_member_function_types = NewList();
}
List *l = isSet ? class_member_set_functions : class_member_functions;
if(!l) {
l = NewList();
if(isSet)
class_member_set_functions = l;
else
class_member_functions = l;
}
Append(l, memberName);
Append(l, name);
Append(class_member_function_types, methodSetGet);
Append(class_member_function_names, name);
Append(class_member_function_membernames, memberName);
String *tmp = NewString("");
Wrapper_print(wrapper, tmp);
Append(l, tmp);
Append(class_member_function_wrappernames, tmp);
// if we could put the wrapper in directly: Append(l, Copy(sfun));
if (debugMode)
Printf(stdout, "Adding accessor: %s (%s) => %s\n", memberName, name, tmp);
@ -1367,13 +1301,14 @@ void R::addAccessor(String *memberName, Wrapper *wrapper, String *name,
#define MAX_OVERLOAD 256
namespace {
struct Overloaded {
Node *n; /* Node */
int argc; /* Argument count */
ParmList *parms; /* Parameters used for overload check */
int error; /* Ambiguity error */
};
}
List * R::Swig_overload_rank(Node *n,
bool script_lang_wrapping) {
@ -1390,11 +1325,6 @@ List * R::Swig_overload_rank(Node *n,
c = Getattr(c,"sym:nextSibling");
continue;
}
/* if (SmartPointer && Getattr(c,"cplus:staticbase")) {
c = Getattr(c,"sym:nextSibling");
continue;
} */
/* Make a list of all the declarations (methods) that are overloaded with
* this one particular method name */
@ -1815,14 +1745,9 @@ int R::functionWrapper(Node *n) {
/* Add the name of this member to a list for this class_name.
We will dump all these at the end. */
int n = Len(iname);
char *ptr = Char(iname);
bool isSet(0);
if (n > 4) isSet = Strcmp(NewString(&ptr[n-4]), "_set") == 0;
bool isSet = GetFlag(n, "memberset") ? true : false;
String *tmp = NewString("");
Printf(tmp, "%s_%s", class_name, isSet ? "set" : "get");
String *tmp = NewString(isSet ? Swig_name_set(NSPACE_TODO, class_name) : Swig_name_get(NSPACE_TODO, class_name));
List *memList = Getattr(ClassMemberTable, tmp);
if(!memList) {
@ -1839,7 +1764,7 @@ int R::functionWrapper(Node *n) {
int nargs;
String *wname = Swig_name_wrapper(iname);
Replace(wname, "_wrap", "R_swig", DOH_REPLACE_FIRST);
if(overname)
Append(wname, overname);
Setattr(n,"wrap:name", wname);
@ -1859,11 +1784,6 @@ int R::functionWrapper(Node *n) {
if(!isVoidReturnType)
addCopyParam = addCopyParameter(rtype);
// Can we get the nodeType() of the type node! and see if it is a struct.
// int addCopyParam = SwigType_isclass(rtype);
// if(addCopyParam)
if (debugMode)
Printf(stdout, "Adding a .copy argument to %s for %s = %s\n",
iname, type, addCopyParam ? "yes" : "no");
@ -1978,7 +1898,7 @@ int R::functionWrapper(Node *n) {
name, " = getNativeSymbolInfo(", name, ");",
"\n};\n",
"if(is(", name, ", \"NativeSymbolInfo\")) {\n",
name, " = ", name, "$address", ";\n}\n",
name, " = ", name, "$address", ";\n};\n",
"if(is(", name, ", \"ExternalReference\")) {\n",
name, " = ", name, "@ref;\n}\n",
"}; \n",
@ -1992,8 +1912,6 @@ int R::functionWrapper(Node *n) {
if ((tm = Getattr(p,"tmap:scheck"))) {
Replaceall(tm,"$target", lname);
Replaceall(tm,"$source", name);
Replaceall(tm,"$input", name);
replaceRClass(tm, Getattr(p, "type"));
Printf(sfun->code,"%s\n",tm);
@ -2004,8 +1922,6 @@ int R::functionWrapper(Node *n) {
curP = p;
if ((tm = Getattr(p,"tmap:in"))) {
Replaceall(tm,"$target", lname);
Replaceall(tm,"$source", name);
Replaceall(tm,"$input", name);
if (Getattr(p,"wrap:disown") || (Getattr(p,"tmap:in:disown"))) {
@ -2064,8 +1980,9 @@ int R::functionWrapper(Node *n) {
String *cleanup = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
if (tm && (Len(tm) != 0)) {
Printv(cleanup, tm, "\n", NIL);
}
p = Getattr(p, "tmap:freearg:next");
} else {
p = nextSibling(p);
@ -2079,7 +1996,6 @@ int R::functionWrapper(Node *n) {
// String *lname = Getattr(p, "lname");
numOutArgs++;
String *pos = NewStringf("%d", numOutArgs);
Replaceall(tm,"$source", Getattr(p, "lname"));
Replaceall(tm,"$result", "r_ans");
Replaceall(tm,"$n", pos); // The position into which to store the answer.
Replaceall(tm,"$arg", Getattr(p, "emit:input"));
@ -2112,18 +2028,7 @@ int R::functionWrapper(Node *n) {
Replaceall(tm,"$owner", "0");
}
#if 0
if(addCopyParam) {
Printf(f->code, "if(LOGICAL(s_swig_copy)[0]) {\n");
Printf(f->code, "/* Deal with returning a reference. */\nr_ans = R_NilValue;\n");
Printf(f->code, "}\n else {\n");
}
#endif
Printf(f->code, "%s\n", tm);
#if 0
if(addCopyParam)
Printf(f->code, "}\n"); /* end of if(s_swig_copy) ... else { ... } */
#endif
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number,
@ -2157,20 +2062,20 @@ int R::functionWrapper(Node *n) {
}
/* Output cleanup code */
Printv(f->code, cleanup, NIL);
Delete(cleanup);
int need_cleanup = Len(cleanup) != 0;
if (need_cleanup) {
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("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Printf(f->code, "%s\n", tm);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
@ -2179,7 +2084,6 @@ int R::functionWrapper(Node *n) {
/*If the user gave us something to convert the result in */
if ((tm = Swig_typemap_lookup("scoerceout", n, Swig_cresult_name(), sfun))) {
Replaceall(tm,"$source","ans");
Replaceall(tm,"$result","ans");
if (constructor) {
Node * parent = Getattr(n, "parentNode");
@ -2207,7 +2111,7 @@ int R::functionWrapper(Node *n) {
{
String *finalizer = NewString(iname);
Replace(finalizer, "new_", "", DOH_REPLACE_FIRST);
Printf(sfun->code, "reg.finalizer(ans@ref, delete_%s)\n", finalizer);
Printf(sfun->code, "reg.finalizer(ans@ref, delete_%s);\n", finalizer);
}
Printf(sfun->code, "ans\n");
}
@ -2215,7 +2119,18 @@ int R::functionWrapper(Node *n) {
if (destructor)
Printv(f->code, "R_ClearExternalPtr(self);\n", NIL);
Printv(f->code, "return r_ans;\n}\n", NIL);
Printv(f->code, "return r_ans;\n", NIL);
/* Error handling code */
Printv(f->code, "fail: SWIGUNUSED;\n", NIL);
if (need_cleanup) {
Printv(f->code, cleanup, NIL);
}
Printv(f->code, " Rf_error(\"%s %s\", SWIG_ErrorType(SWIG_lasterror_code), SWIG_lasterror_msg);\n", NIL);
Printv(f->code, " return R_NilValue;\n", NIL);
Delete(cleanup);
Printv(f->code, "}\n", NIL);
Printv(sfun->code, "\n}", NIL);
/* Substitute the function name */
@ -2261,7 +2176,13 @@ int R::functionWrapper(Node *n) {
Would like to be able to do this so that we can potentially insert
*/
if(processing_member_access_function || processing_class_member_function) {
addAccessor(member_name, sfun, iname);
String *method_type = R_MEMBER_NORMAL;
if (GetFlag(n, "memberset")) {
method_type = R_MEMBER_SET;
} else if (GetFlag(n, "memberget")) {
method_type = R_MEMBER_GET;
}
addAccessor(member_name, sfun, iname, method_type);
}
if (Getattr(n, "sym:overloaded") &&
@ -2455,20 +2376,49 @@ int R::classDeclaration(Node *n) {
opaqueClassDeclaration = NULL;
// OutputArrayMethod(name, class_member_functions, sfile);
if (class_member_functions)
OutputMemberReferenceMethod(name, 0, class_member_functions, sfile);
if (class_member_set_functions)
OutputMemberReferenceMethod(name, 1, class_member_set_functions, sfile);
if (class_member_function_types) {
if(class_member_functions) {
Delete(class_member_functions);
class_member_functions = NULL;
}
if(class_member_set_functions) {
Delete(class_member_set_functions);
class_member_set_functions = NULL;
}
// collect the "set" methods
List *class_set_membernames = filterMemberList(class_member_function_types,
class_member_function_membernames, R_MEMBER_SET, true);
List *class_set_functionnames = filterMemberList(class_member_function_types,
class_member_function_names, R_MEMBER_SET, true);
// this one isn't used - collecting to keep code simpler
List *class_set_functiontypes = filterMemberList(class_member_function_types,
class_member_function_types, R_MEMBER_SET, true);
// collect the others
List *class_other_membernames = filterMemberList(class_member_function_types,
class_member_function_membernames, R_MEMBER_SET, false);
List *class_other_functionnames = filterMemberList(class_member_function_types,
class_member_function_names, R_MEMBER_SET, false);
List *class_other_functiontypes = filterMemberList(class_member_function_types,
class_member_function_types, R_MEMBER_SET, false);
if (Len(class_other_membernames) > 0) {
OutputMemberReferenceMethod(name, 0, class_other_membernames, class_other_functionnames, class_other_functiontypes, sfile);
}
if (Len(class_set_membernames) > 0) {
OutputMemberReferenceMethod(name, 1, class_set_membernames, class_set_functionnames, class_set_functiontypes, sfile);
}
Delete(class_set_membernames);
Delete(class_set_functionnames);
Delete(class_set_functiontypes);
Delete(class_other_membernames);
Delete(class_other_functionnames);
Delete(class_other_functiontypes);
}
if (class_member_function_types) {
Delete(class_member_function_types);
class_member_function_types = NULL;
Delete(class_member_function_names);
class_member_function_names = NULL;
Delete(class_member_function_membernames);
class_member_function_membernames = NULL;
Delete(class_member_function_wrappernames);
class_member_function_wrappernames = NULL;
}
if (Getattr(n, "has_destructor")) {
Printf(sfile, "setMethod('delete', '_p%s', function(obj) {delete%s(obj)})\n", getRClassName(name), getRClassName(name));
@ -2494,9 +2444,6 @@ int R::classDeclaration(Node *n) {
c = nextSibling(c);
continue;
}
#if 0
tp = getRType(c);
#else
tp = Swig_typemap_lookup("rtype", c, "", 0);
if(!tp) {
c = nextSibling(c);
@ -2523,7 +2470,7 @@ int R::classDeclaration(Node *n) {
// returns "" tp = processType(elType, c, NULL);
// Printf(stdout, "<classDeclaration> elType %p\n", elType);
// tp = getRClassNameCopyStruct(Getattr(c, "type"), 1);
#endif
String *elNameT = replaceInitialDash(elName);
Printf(def, "%s%s = \"%s\"", tab8, elNameT, tp);
firstItem = false;
@ -2884,10 +2831,6 @@ String * R::processType(SwigType *t, Node *n, int *nargs) {
return tmp;
}
#if 0
SwigType_isfunction(t) && SwigType_ispointer(t)
#endif
return NULL;
}

View file

@ -116,6 +116,7 @@ public:
/* flags for the make_autodoc function */
namespace {
enum autodoc_t {
AUTODOC_CLASS,
AUTODOC_CTOR,
@ -127,6 +128,7 @@ enum autodoc_t {
AUTODOC_SETTER,
AUTODOC_NONE
};
}
static const char *usage = "\
Ruby Options (available with -ruby)\n\
@ -1425,16 +1427,14 @@ public:
* applyInputTypemap()
*
* Look up the appropriate "in" typemap for this parameter (p),
* substitute the correct strings for the $target and $input typemap
* parameters, and dump the resulting code to the wrapper file.
* substitute the correct strings for the typemap parameters, and dump the
* resulting code to the wrapper file.
* --------------------------------------------------------------------- */
Parm *applyInputTypemap(Parm *p, String *ln, String *source, Wrapper *f, String *symname) {
Parm *applyInputTypemap(Parm *p, String *source, Wrapper *f, String *symname) {
String *tm;
SwigType *pt = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:in"))) {
Replaceall(tm, "$target", ln);
Replaceall(tm, "$source", source);
Replaceall(tm, "$input", source);
Replaceall(tm, "$symname", symname);
@ -1474,10 +1474,8 @@ public:
Parm *p;
String *tm;
String *source;
String *target;
source = NewString("");
target = NewString("");
bool ctor_director = (current == CONSTRUCTOR_INITIALIZE && Swig_directorclass(n));
@ -1498,7 +1496,6 @@ public:
p = skipIgnoredArgs(p);
String *pn = Getattr(p, "name");
String *ln = Getattr(p, "lname");
/* Produce string representation of source argument */
Clear(source);
@ -1510,10 +1507,6 @@ public:
Printf(source, "argv[%d]", i - start);
}
/* Produce string representation of target argument */
Clear(target);
Printf(target, "%s", Char(ln));
if (i >= (numreq)) { /* Check if parsing an optional argument */
Printf(f->code, " if (argc > %d) {\n", i - start);
}
@ -1526,7 +1519,7 @@ public:
}
/* Look for an input typemap */
p = applyInputTypemap(p, ln, source, f, Getattr(n, "name"));
p = applyInputTypemap(p, source, f, Getattr(n, "name"));
if (i >= numreq) {
Printf(f->code, "}\n");
}
@ -1553,7 +1546,6 @@ public:
}
Delete(source);
Delete(target);
}
/* ---------------------------------------------------------------------
@ -1569,7 +1561,6 @@ public:
String *tm;
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");
} else {
@ -1591,7 +1582,6 @@ public:
for (Parm *p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
if (Len(tm) != 0) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
}
p = Getattr(p, "tmap:freearg:next");
@ -1613,8 +1603,6 @@ public:
String *tm;
for (Parm *p = l; p;) {
if ((tm = Getattr(p, "tmap:argout"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Replaceall(tm, "$target", "vresult");
Replaceall(tm, "$result", "vresult");
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
@ -1876,8 +1864,6 @@ public:
actioncode = 0;
if (tm) {
Replaceall(tm, "$result", "vresult");
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "vresult");
if (GetFlag(n, "feature:new"))
Replaceall(tm, "$owner", "SWIG_POINTER_OWN");
@ -1975,7 +1961,6 @@ public:
if (current != CONSTRUCTOR_ALLOCATE && GetFlag(n, "feature:new")) {
tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0);
if (tm) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
Delete(tm);
}
@ -1984,7 +1969,6 @@ public:
/* Special processing on return value. */
tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0);
if (tm) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, NIL);
Delete(tm);
}
@ -2191,6 +2175,12 @@ public:
String *tm;
String *getfname, *setfname;
Wrapper *getf, *setf;
const int assignable = is_assignable(n);
// Determine whether virtual global variables shall be used
// which have different getter and setter signatures,
// see https://docs.ruby-lang.org/en/2.6.0/extension_rdoc.html#label-Global+Variables+Shared+Between+C+and+Ruby
const bool use_virtual_var = (current == NO_CPP && useGlobalModule);
getf = NewWrapper();
setf = NewWrapper();
@ -2201,15 +2191,13 @@ public:
getfname = Swig_name_wrapper(getname);
Setattr(n, "wrap:name", getfname);
Printv(getf->def, "SWIGINTERN VALUE\n", getfname, "(", NIL);
Printf(getf->def, "VALUE self");
Printf(getf->def, (use_virtual_var) ? "ID id, VALUE *data" : "VALUE self");
Printf(getf->def, ") {");
Wrapper_add_local(getf, "_val", "VALUE _val");
tm = Swig_typemap_lookup("varout", n, name, 0);
if (tm) {
Replaceall(tm, "$result", "_val");
Replaceall(tm, "$target", "_val");
Replaceall(tm, "$source", name);
/* Printv(getf->code,tm, NIL); */
addfail = emit_action_code(n, getf->code, tm);
} else {
@ -2224,8 +2212,8 @@ public:
Wrapper_print(getf, f_wrappers);
if (!is_assignable(n)) {
setfname = NewString("NULL");
if (!assignable) {
setfname = NewString("(rb_gvar_setter_t *)NULL");
} else {
/* create setter */
String* docs = docstring(n, AUTODOC_SETTER);
@ -2235,40 +2223,45 @@ public:
String *setname = Swig_name_set(NSPACE_TODO, iname);
setfname = Swig_name_wrapper(setname);
Setattr(n, "wrap:name", setfname);
Printv(setf->def, "SWIGINTERN VALUE\n", setfname, "(VALUE self, ", NIL);
Printf(setf->def, "VALUE _val) {");
Printf(setf->def, "SWIGINTERN ");
if (use_virtual_var) {
Printv(setf->def, "void\n", setfname, "(VALUE _val, ID id, VALUE *data) {", NIL);
} else {
Printv(setf->def, "VALUE\n", setfname, "(VALUE self, VALUE _val) {", NIL);
}
tm = Swig_typemap_lookup("varin", n, name, 0);
if (tm) {
Replaceall(tm, "$input", "_val");
Replaceall(tm, "$source", "_val");
Replaceall(tm, "$target", name);
/* Printv(setf->code,tm,"\n",NIL); */
emit_action_code(n, setf->code, tm);
} else {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s\n", SwigType_str(t, 0));
}
Printv(setf->code, tab4, "return _val;\n", NIL);
Printf(setf->code, "fail:\n");
Printv(setf->code, tab4, "return Qnil;\n", NIL);
if (use_virtual_var) {
Printf(setf->code, "fail:\n");
Printv(setf->code, tab4, "return;\n", NIL);
} else {
Printv(setf->code, tab4, "return _val;\n", NIL);
Printf(setf->code, "fail:\n");
Printv(setf->code, tab4, "return Qnil;\n", NIL);
}
Printf(setf->code, "}\n");
Wrapper_print(setf, f_wrappers);
Delete(setname);
}
/* define accessor method */
if (CPlusPlus) {
Insert(getfname, 0, "VALUEFUNC(");
Append(getfname, ")");
Insert(setfname, 0, "VALUEFUNC(");
Append(setfname, ")");
}
/* define accessor methods */
Insert(getfname, 0, "VALUEFUNC(");
Append(getfname, ")");
Insert(setfname, 0, (use_virtual_var) ? "SWIG_RUBY_VOID_ANYARGS_FUNC(" : "VALUEFUNC(");
Append(setfname, ")");
String *s = NewString("");
switch (current) {
case STATIC_VAR:
/* C++ class variable */
Printv(s, tab4, "rb_define_singleton_method(", klass->vname, ", \"", klass->strip(iname), "\", ", getfname, ", 0);\n", NIL);
if (!GetFlag(n, "feature:immutable")) {
if (assignable) {
Printv(s, tab4, "rb_define_singleton_method(", klass->vname, ", \"", klass->strip(iname), "=\", ", setfname, ", 1);\n", NIL);
}
Printv(klass->init, s, NIL);
@ -2279,14 +2272,11 @@ public:
assert(current == NO_CPP);
if (!useGlobalModule) {
Printv(s, tab4, "rb_define_singleton_method(", modvar, ", \"", iname, "\", ", getfname, ", 0);\n", NIL);
if (!GetFlag(n, "feature:immutable")) {
if (assignable) {
Printv(s, tab4, "rb_define_singleton_method(", modvar, ", \"", iname, "=\", ", setfname, ", 1);\n", NIL);
}
} else {
Printv(s, tab4, "rb_define_global_method(\"", iname, "\", ", getfname, ", 0);\n", NIL);
if (!GetFlag(n, "feature:immutable")) {
Printv(s, tab4, "rb_define_global_method(\"", iname, "=\", ", setfname, ", 1);\n", NIL);
}
Printv(s, tab4, "rb_define_virtual_variable(\"$", iname, "\", ", getfname, ", ", setfname, ");\n", NIL);
}
Printv(f_init, s, NIL);
Delete(s);
@ -2353,8 +2343,6 @@ public:
if (!tm)
tm = Swig_typemap_lookup("constcode", n, value, 0);
if (tm) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", iname);
Replaceall(tm, "$symname", iname);
Replaceall(tm, "$value", value);
if (current == CLASS_CONST) {

View file

@ -1,402 +0,0 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* s-exp.cxx
*
* A parse tree represented as Lisp s-expressions.
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
#include "dohint.h"
static const char *usage = "\
S-Exp Options (available with -sexp)\n\
-typemaplang <lang> - Typemap language\n\n";
//static Node *view_top = 0;
static File *out = 0;
class Sexp:public Language {
int indent_level;
DOHHash *print_circle_hash;
int print_circle_count;
int hanging_parens;
bool need_whitespace;
bool need_newline;
public:
Sexp():
indent_level(0),
print_circle_hash(0),
print_circle_count(0),
hanging_parens(0),
need_whitespace(0),
need_newline(0) {
}
virtual ~ Sexp() {
}
virtual void main(int argc, char *argv[]) {
// Add a symbol to the parser for conditional compilation
Preprocessor_define("SWIGSEXP 1", 0);
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);
}
}
}
/* 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", SWIG_output_files());
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("begin", f_sink);
Swig_register_filebyname("runtime", f_sink);
Swig_register_filebyname("init", f_sink);
Swig_banner_target_lang(out, ";;;");
Language::top(n);
Printf(out, "\n");
Printf(out, ";;; Lisp parse tree produced by SWIG\n");
print_circle_hash = NewHash();
print_circle_count = 0;
hanging_parens = 0;
need_whitespace = 0;
need_newline = 0;
Sexp_print_node(n);
flush_parens();
return SWIG_OK;
}
void print_indent() {
int i;
for (i = 0; i < indent_level; i++) {
Printf(out, " ");
}
}
void open_paren(const String *oper) {
flush_parens();
Printf(out, "(");
if (oper)
Printf(out, "%s ", oper);
indent_level += 2;
}
void close_paren(bool neednewline = false) {
hanging_parens++;
if (neednewline)
print_lazy_whitespace();
indent_level -= 2;
}
void flush_parens() {
int i;
if (hanging_parens) {
for (i = 0; i < hanging_parens; i++)
Printf(out, ")");
hanging_parens = 0;
need_newline = true;
need_whitespace = true;
}
if (need_newline) {
Printf(out, "\n");
print_indent();
need_newline = false;
need_whitespace = false;
} else if (need_whitespace) {
Printf(out, " ");
need_whitespace = false;
}
}
void print_lazy_whitespace() {
need_whitespace = 1;
}
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)
|| (*(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 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.
{
return ((Cmp(key, "typescope") == 0));
}
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
{
flush_parens();
// Following is a silly hack. It works around the limitation of
// DOH's hash tables that only work with string keys!
char address[32];
sprintf(address, "%p%c", obj, list_p ? 'L' : 'O');
DOH *placeholder = Getattr(print_circle_hash, address);
if (placeholder) {
Printv(out, placeholder, NIL);
return false;
} 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) {
if ((Cmp(key, "parms") == 0) || (Cmp(key, "wrap:parms") == 0)
|| (Cmp(key, "kwargs") == 0) || (Cmp(key, "pattern") == 0))
Sexp_print_parms(value);
else if (plist_key_p(key))
Sexp_print_plist(value);
else if (maybe_plist_key_p(key)) {
if (DohIsMapping(value))
Sexp_print_plist(value);
else
Sexp_print_doh(value);
} 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) {
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");
}
void Sexp_print_list(DOH *obj) {
if (print_circle(obj, true)) {
open_paren(NIL);
for (; obj; obj = nextSibling(obj)) {
Sexp_print_doh(obj);
print_lazy_whitespace();
}
close_paren(true);
}
}
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)) {
if (DohIsMapping(obj)) {
Iterator k;
open_paren(NIL);
for (k = First(obj); k.key; k = Next(k)) {
if (!internal_key_p(k.key)) {
DOH *value = Getattr(obj, k.key);
Sexp_print_as_keyword(k.key);
Sexp_print_value_of_key(value, k.key);
print_lazy_whitespace();
}
}
close_paren(true);
} else
Sexp_print_doh(obj);
print_lazy_whitespace();
}
close_paren(true);
}
}
void Sexp_print_doh(DOH *obj) {
flush_parens();
if (DohIsString(obj)) {
String *o = Str(obj);
Replaceall(o, "\\", "\\\\");
Replaceall(o, "\"", "\\\"");
Printf(out, "\"%s\"", o);
Delete(o);
} else {
if (print_circle(obj, false)) {
// Dispatch type
if (nodeType(obj)) {
Sexp_print_node(obj);
}
else if (DohIsMapping(obj)) {
Iterator k;
open_paren(NIL);
for (k = First(obj); k.key; k = Next(k)) {
if (!internal_key_p(k.key)) {
DOH *value = Getattr(obj, k.key);
flush_parens();
open_paren(NIL);
Sexp_print_doh(k.key);
Printf(out, " . ");
Sexp_print_value_of_key(value, k.key);
close_paren();
}
}
close_paren();
} else if (strcmp(ObjType(obj)->objname, "List") == 0) {
int i;
open_paren(NIL);
for (i = 0; i < Len(obj); i++) {
DOH *item = Getitem(obj, i);
Sexp_print_doh(item);
}
close_paren();
} else {
// What is it?
Printf(out, "#<DOH %s %p>", ObjType(obj)->objname, obj);
}
}
}
}
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);
Delete(key);
}
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) {
if (!internal_key_p(k.key)) {
DOH *value = Getattr(obj, k.key);
flush_parens();
if (!first) {
Printf(out, " ");
}
Sexp_print_as_keyword(k.key);
/* Print value */
Sexp_print_value_of_key(value, k.key);
}
}
}
void Sexp_print_plist(DOH *obj) {
flush_parens();
if (print_circle(obj, true)) {
open_paren(NIL);
Sexp_print_plist_noparens(obj);
close_paren();
}
}
void Sexp_print_attributes(Node *obj) {
Sexp_print_plist_noparens(obj);
}
void Sexp_print_node(Node *obj) {
Node *cobj;
open_paren(nodeType(obj));
/* A node has an attribute list... */
Sexp_print_attributes(obj);
/* ... and child nodes. */
cobj = firstChild(obj);
if (cobj) {
print_lazy_newline();
flush_parens();
Sexp_print_as_keyword("children");
open_paren(NIL);
for (; cobj; cobj = nextSibling(cobj)) {
Sexp_print_node(cobj);
}
close_paren();
}
close_paren();
}
virtual int functionWrapper(Node *n) {
ParmList *l = Getattr(n, "parms");
Wrapper *f = NewWrapper();
emit_attach_parmmaps(l, f);
Setattr(n, "wrap:parms", l);
DelWrapper(f);
return SWIG_OK;
}
};
static Language *new_swig_sexp() {
return new Sexp();
}
extern "C" Language *swig_sexp(void) {
return new_swig_sexp();
}

View file

@ -472,7 +472,6 @@ public:
String *tm;
if ((tm = Getattr(param, "tmap:freearg"))) {
if (tm && (Len(tm) != 0)) {
Replaceall(tm, "$source", Getattr(param, "lname"));
Printf(wrapper->code, "%s\n", tm);
}
param = Getattr(param, "tmap:freearg:next");
@ -484,7 +483,6 @@ public:
/* See if there is any return cleanup code */
String *tm;
if ((tm = Swig_typemap_lookup("ret", node, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(wrapper->code, "%s\n", tm);
Delete(tm);
}

View file

@ -165,7 +165,7 @@ static void merge_options_files(int *argc, char ***argv) {
i = 1;
while (i < new_argc) {
if (new_argv[i] && new_argv[i][0] == '@' && (f = fopen(&new_argv[i][1], "r"))) {
char c;
int ci;
char *b;
char *be = &buffer[BUFFER_SIZE];
int quote = 0;
@ -176,7 +176,8 @@ static void merge_options_files(int *argc, char ***argv) {
insert = i;
b = buffer;
while ((c = fgetc(f)) != EOF) {
while ((ci = fgetc(f)) != EOF) {
const char c = static_cast<char>(ci);
if (escape) {
if (b != be) {
*b = c;

View file

@ -371,7 +371,6 @@ struct TargetLanguageModule {
int SWIG_main(int argc, char *argv[], const TargetLanguageModule *tlm);
void emit_parameter_variables(ParmList *l, Wrapper *f);
void emit_return_variable(Node *n, SwigType *rt, Wrapper *f);
void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */
void SWIG_config_file(const_String_or_char_ptr );
const String *SWIG_output_directory();
void SWIG_config_cppext(const char *ext);

View file

@ -336,8 +336,6 @@ public:
if ((tm = Getattr(p, "tmap:in"))) {
String *parse = Getattr(p, "tmap:in:parse");
if (!parse) {
Replaceall(tm, "$target", ln);
Replaceall(tm, "$source", source);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source);
@ -401,7 +399,6 @@ public:
/* Insert constraint checking code */
for (p = parms; 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");
} else {
@ -414,7 +411,6 @@ public:
if (!checkAttribute(p, "tmap:in:numinputs", "0")
&& !Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) {
if (Len(tm) != 0) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
}
p = Getattr(p, "tmap:freearg:next");
@ -426,12 +422,9 @@ public:
/* Insert argument output code */
for (i = 0, p = parms; p; i++) {
if ((tm = Getattr(p, "tmap:argout"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
#ifdef SWIG_USE_RESULTOBJ
Replaceall(tm, "$target", "resultobj");
Replaceall(tm, "$result", "resultobj");
#else
Replaceall(tm, "$target", "(Tcl_GetObjResult(interp))");
Replaceall(tm, "$result", "(Tcl_GetObjResult(interp))");
#endif
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
@ -450,12 +443,9 @@ public:
/* Return value if necessary */
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$source", Swig_cresult_name());
#ifdef SWIG_USE_RESULTOBJ
Replaceall(tm, "$target", "resultobj");
Replaceall(tm, "$result", "resultobj");
#else
Replaceall(tm, "$target", "(Tcl_GetObjResult(interp))");
Replaceall(tm, "$result", "(Tcl_GetObjResult(interp))");
#endif
if (GetFlag(n, "feature:new")) {
@ -478,13 +468,11 @@ public:
/* Look for any remaining cleanup */
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
}
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
#ifdef SWIG_USE_RESULTOBJ
@ -580,8 +568,6 @@ public:
Printv(getf->def, "SWIGINTERN const char *", getfname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2, int flags) {", NIL);
Wrapper_add_local(getf, "value", "Tcl_Obj *value = 0");
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "value");
Replaceall(tm, "$result", "value");
/* Printf(getf->code, "%s\n",tm); */
addfail = emit_action_code(n, getf->code, tm);
@ -616,8 +602,6 @@ public:
Wrapper_add_local(setf, "name1o", "Tcl_Obj *name1o = 0");
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
Replaceall(tm, "$source", "value");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "value");
Printf(setf->code, "name1o = Tcl_NewStringObj(name1,-1);\n");
Printf(setf->code, "value = Tcl_ObjGetVar2(interp, name1o, 0, flags);\n");
@ -690,14 +674,10 @@ public:
}
if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
Replaceall(tm, "$nsname", nsname);
Printf(const_tab, "%s,\n", tm);
} else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
Replaceall(tm, "$nsname", nsname);
Printf(f_init, "%s\n", tm);

View file

@ -267,6 +267,8 @@ class TypePass:private Dispatcher {
and smart pointer to base class, so that smart pointer upcasts
are automatically generated. */
SwigType *bsmart = Copy(smart);
// TODO: SwigType_typedef_resolve_all on a String instead of SwigType is incorrect for templates
SwigType *rclsname = SwigType_typedef_resolve_all(clsname);
SwigType *rbname = SwigType_typedef_resolve_all(bname);
int replace_count = Replaceall(bsmart, rclsname, rbname);
@ -276,6 +278,12 @@ class TypePass:private Dispatcher {
String *firstname = Getattr(first, "name");
Replaceall(bsmart, firstname, rbname);
}
// The code above currently creates a smartptr of the base class by substitution, replacing Derived
// with Base resulting in something like: 'smartptr< Derived >' from 'smartptr< Base >'. Instead
// the feature:smartptr should be used as it also contains 'smartptr< Base >' as specified by the user.
// A similar fix should also be done in upcastsCode in java.cxx, csharp.cxx and writeClassUpcast in d.cxx.
// Printf(stdout, "smartcomparison %s <=> %s\n", SwigType_namestr(bsmart), Getattr(bclass, "feature:smartptr"));
Delete(rclsname);
Delete(rbname);
String *smartnamestr = SwigType_namestr(smart);
@ -961,7 +969,7 @@ class TypePass:private Dispatcher {
if (Getattr(c, "sym:overloaded") != checkoverloaded) {
Printf(stdout, "sym:overloaded error c:%p checkoverloaded:%p\n", c, checkoverloaded);
Swig_print_node(c);
exit (1);
SWIG_exit(EXIT_FAILURE);
}
String *decl = Strcmp(nodeType(c), "using") == 0 ? NewString("------") : Getattr(c, "decl");
@ -969,7 +977,7 @@ class TypePass:private Dispatcher {
if (!Getattr(c, "sym:overloaded")) {
Printf(stdout, "sym:overloaded error.....%p\n", c);
Swig_print_node(c);
exit (1);
SWIG_exit(EXIT_FAILURE);
}
c = Getattr(c, "sym:nextSibling");
}

View file

@ -1,405 +0,0 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* uffi.cxx
*
* Uffi language module for SWIG.
* ----------------------------------------------------------------------------- */
// TODO: remove remnants of lisptype
#include "swigmod.h"
static const char *usage = "\
UFFI Options (available with -uffi)\n\
-identifier-converter <type or funcname> - \n\
Specifies the type of conversion to do on C identifiers\n\
to convert them to symbols. There are two built-in\n\
converters: 'null' and 'lispify'. The default is\n\
'null'. If you supply a name other than one of the\n\
built-ins, then a function by that name will be\n\
called to convert identifiers to symbols.\n\
";
class UFFI:public Language {
public:
virtual void main(int argc, char *argv[]);
virtual int top(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 struct {
int count;
String **entries;
} defined_foreign_types;
static String *identifier_converter = NewString("identifier-convert-null");
static int any_varargs(ParmList *pl) {
Parm *p;
for (p = pl; p; p = nextSibling(p)) {
if (SwigType_isvarargs(Getattr(p, "type")))
return 1;
}
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;
}
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;
}
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 *));
} else {
/* make room */
defined_foreign_types.count++;
defined_foreign_types.entries = (String **)
realloc(defined_foreign_types.entries, defined_foreign_types.count * sizeof(String *));
}
if (!defined_foreign_types.entries) {
Printf(stderr, "Out of memory\n");
SWIG_exit(EXIT_FAILURE);
}
/* Fill in the new data */
defined_foreign_types.entries[defined_foreign_types.count - 1] = Copy(type);
}
static String *get_ffi_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
Node *node = NewHash();
Setattr(node, "type", ty);
Setattr(node, "name", name);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("ffitype", node, "", 0);
Delete(node);
if (tm) {
return NewString(tm);
} 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);
}
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");
}
Printf(stderr, "Unsupported data type: %s (was: %s)\n", type_reduced, ty);
SWIG_exit(EXIT_FAILURE);
}
return 0;
}
static String *get_lisp_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
Node *node = NewHash();
Setattr(node, "type", ty);
Setattr(node, "name", name);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("lisptype", node, "", 0);
Delete(node);
return tm ? NewString(tm) : NewString("");
}
void UFFI::main(int argc, char *argv[]) {
int i;
Preprocessor_define("SWIGUFFI 1", 0);
SWIG_library_directory("uffi");
SWIG_config_file("uffi.swg");
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-identifier-converter")) {
char *conv = argv[i + 1];
if (!conv)
Swig_arg_error();
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
/* check for built-ins */
if (!strcmp(conv, "lispify")) {
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-lispify");
} else if (!strcmp(conv, "null")) {
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-null");
} else {
/* Must be user defined */
Delete(identifier_converter);
identifier_converter = NewString(conv);
}
}
if (!strcmp(argv[i], "-help")) {
Printf(stdout, "%s\n", usage);
}
}
}
int UFFI::top(Node *n) {
String *module = Getattr(n, "name");
String *output_filename = NewString("");
File *f_null = NewString("");
Printf(output_filename, "%s%s.cl", SWIG_output_directory(), module);
f_cl = NewFile(output_filename, "w", SWIG_output_files());
if (!f_cl) {
FileErrorDisplay(output_filename);
SWIG_exit(EXIT_FAILURE);
}
Swig_register_filebyname("header", f_null);
Swig_register_filebyname("begin", f_null);
Swig_register_filebyname("runtime", f_null);
Swig_register_filebyname("wrapper", f_cl);
Swig_banner_target_lang(f_cl, ";;");
Printf(f_cl, "\n"
";; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; package: %s -*-\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);
Delete(f_cl); // Delete the handle, not the file
Delete(f_null);
return SWIG_OK;
}
int UFFI::functionWrapper(Node *n) {
String *funcname = Getattr(n, "sym:name");
ParmList *pl = Getattr(n, "parms");
Parm *p;
int argnum = 0, first = 1;
// int 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;
} else {
for (p = pl; p; p = nextSibling(p), argnum++) {
String *argname = Getattr(p, "name");
SwigType *argtype = Getattr(p, "type");
String *ffitype = get_ffi_type(n, argtype, argname);
String *lisptype = get_lisp_type(n, argtype, argname);
int tempargname = 0;
if (!argname) {
argname = NewStringf("arg%d", argnum);
tempargname = 1;
}
if (!first) {
Printf(f_cl, "\n ");
}
Printf(f_cl, "(%s %s %s)", argname, ffitype, lisptype);
first = 0;
Delete(ffitype);
Delete(lisptype);
if (tempargname)
Delete(argname);
}
}
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(n, Getattr(n, "type"), Swig_cresult_name())
//,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");
#if 0
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);
Delete(converted_value);
return SWIG_OK;
}
// Includes structs
int UFFI::classHandler(Node *n) {
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, " (name: %s)\n", name);
SWIG_exit(EXIT_FAILURE);
}
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");
if (type) {
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"));
SWIG_exit(EXIT_FAILURE);
}
/* Printf(stdout, "Converting %s in %s\n", type, name); */
lisp_type = get_ffi_type(n, 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) {
Language::membervariableHandler(n);
return SWIG_OK;
}
extern "C" Language *swig_uffi(void) {
return new UFFI();
}