Merge branch 'master' into director-unwrap-result

This commit is contained in:
Olly Betts 2022-03-01 11:34:59 +13:00 • committed by GitHub
commit deb7cbf741
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1099 changed files with 14845 additions and 34359 deletions

File diff suppressed because it is too large Load diff

View file

@ -779,6 +779,12 @@ Allocate():
if (Swig_storage_isstatic(n)) {
Setattr(n, "cplus:staticbase", inclass);
} else if (Cmp(Getattr(n, "kind"), "variable") == 0) {
/* Check member variable to determine whether assignment is valid */
if (SwigType_isreference(Getattr(n, "type"))) {
/* Can't assign a class with reference member data */
Setattr(inclass, "allocate:noassign", "1");
}
}
String *name = Getattr(n, "name");

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);
}
}
@ -2050,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)) {

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

@ -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

@ -196,7 +196,7 @@ public:
String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString("<unnamed>");
Swig_warning(WARN_JAVA_NSPACE_WITHOUT_PACKAGE, Getfile(n), Getline(n),
"The nspace feature is used on '%s' without -package. "
"The generated code may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name);
"The generated code may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", SwigType_namestr(name));
}
}
@ -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);
}
}
@ -2145,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)) {
@ -4835,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;
@ -4877,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
@ -4902,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

@ -166,7 +166,7 @@ public:
*/
virtual int exitClass(Node *) {
return SWIG_OK;
};
}
/**
* Invoked at the beginning of the variableHandler.
@ -178,7 +178,7 @@ public:
*/
virtual int exitVariable(Node *) {
return SWIG_OK;
};
}
/**
* Invoked at the beginning of the functionHandler.
@ -190,7 +190,7 @@ public:
*/
virtual int exitFunction(Node *) {
return SWIG_OK;
};
}
/**
* Invoked by functionWrapper callback after call to Language::functionWrapper.
@ -727,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.
* ----------------------------------------------------------------------------- */
@ -994,7 +994,7 @@ int JSEmitter::emitDtor(Node *n) {
{
SWIG_PRV_DATA* t = (SWIG_PRV_DATA*)JSObjectGetPrivate(thisObject);
if(t && t->swigCMemOwn) free ((${type}*)t->swigCObject);
if(t) free(t);
free(t);
}
%}
@ -1007,7 +1007,7 @@ int JSEmitter::emitDtor(Node *n) {
${type}* arg1 = (${type}*)t->swigCObject;
${destructor_action}
}
if(t) free(t);
free(t);
Based on what I saw in the Lua and Ruby modules, I use Getattr(n, "wrap:action")
to decide if the user has a preferred destructor action.
@ -1143,7 +1143,7 @@ int JSEmitter::emitConstant(Node *n) {
String *rawval = Getattr(n, "rawval");
String *value = rawval ? rawval : Getattr(n, "value");
// HACK: forcing usage of cppvalue for v8 (which turned out to fix typdef_struct.i, et. al)
// HACK: forcing usage of cppvalue for v8 (which turned out to fix typedef_struct.i, et. al)
if (State::IsSet(state.globals(FORCE_CPP)) && Getattr(n, "cppvalue") != NULL) {
value = Getattr(n, "cppvalue");
}
@ -1255,7 +1255,7 @@ int JSEmitter::emitFunctionDispatcher(Node *n, bool /*is_member */ ) {
// Note: this dispatcher function gets called after the last overloaded function has been created.
// At this time, n.wrap:name contains the name of the last wrapper function.
// To get a valid function name for the dispatcher function we take the last wrapper name and
// substract the extension "sym:overname",
// subtract the extension "sym:overname",
String *wrap_name = NewString(Getattr(n, "wrap:name"));
String *overname = Getattr(n, "sym:overname");
@ -1575,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);
@ -2212,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;
}
}
@ -1320,16 +1320,21 @@ int Language::staticmemberfunctionHandler(Node *n) {
Delete(mrename);
mrename = mangled;
if (Getattr(n, "sym:overloaded") && code) {
Append(cname, Getattr(defaultargs ? defaultargs : n, "sym:overname"));
}
if (code) {
// See Swig_MethodToFunction() for the explanation of this code.
if (Getattr(n, "sym:overloaded")) {
Append(cname, Getattr(defaultargs ? defaultargs : n, "sym:overname"));
} else {
Append(cname, "__SWIG");
}
if (!defaultargs && code) {
/* Hmmm. An added static member. We have to create a little wrapper for this */
String *mangled_cname = Swig_name_mangle(cname);
Swig_add_extension_code(n, mangled_cname, parms, type, code, CPlusPlus, 0);
Setattr(n, "extendname", mangled_cname);
Delete(mangled_cname);
if (!defaultargs) {
/* Hmmm. An added static member. We have to create a little wrapper for this */
String *mangled_cname = Swig_name_mangle(cname);
Swig_add_extension_code(n, mangled_cname, parms, type, code, CPlusPlus, 0);
Setattr(n, "extendname", mangled_cname);
Delete(mangled_cname);
}
}
}
@ -1481,8 +1486,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 +3052,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

@ -50,7 +50,7 @@
/**** Diagnostics:
With the #define REPORT(), you can change the amount of diagnostics given
This helps me search the parse tree & figure out what is going on inside SWIG
(because its not clear or documented)
(because it's not clear or documented)
*/
#define REPORT(T,D) // no info:
//#define REPORT(T,D) {Printf(stdout,T"\n");} // only title
@ -435,7 +435,7 @@ public:
/* NEW LANGUAGE NOTE:***********************************************
This is it!
you get this one right, and most of your work is done
but its going to take some file to get it working right
but it's going to take some file to get it working right
quite a bit of this is generally boilerplate code
(or stuff I don't understand)
that which matters will have extra added comments
@ -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);
@ -2071,8 +2053,8 @@ public:
if (GetFlag(carrays_hash, "lua:class_instance")) {
String *static_cls = Getattr(carrays_hash, "lua:class_instance:static_hash");
assert(static_cls);
// static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR)
// Instead structure describing its methods isused
// static_cls is swig_lua_namespace. This structure can't be used with eLua(LTR)
// Instead a structure describing its methods is used
String *static_cls_cname = Getattr(static_cls, "methods:name");
assert(static_cls_cname);
Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL);
@ -2243,36 +2225,6 @@ public:
};
/* NEW LANGUAGE NOTE:***********************************************
in order to add you language into swig, you need to make the following changes:
- write this file (obviously)
- add into the makefile (not 100% clear on how to do this)
- edit swigmain.cxx to add your module
near the top of swigmain.cxx, look for this code & add you own codes
======= begin change ==========
extern "C" {
Language *swig_tcl(void);
Language *swig_python(void);
//etc,etc,etc...
Language *swig_lua(void); // this is my code
}
//etc,etc,etc...
swig_module modules[] = {
{"-guile", swig_guile, "Guile"},
{"-java", swig_java, "Java"},
//etc,etc,etc...
{"-lua", swig_lua, "Lua"}, // this is my code
{NULL, NULL, NULL} // this must come at the end of the list
};
======= end change ==========
This is all that is needed
NEW LANGUAGE NOTE:END ************************************************/
/* -----------------------------------------------------------------------------
* swig_lua() - Instantiate module
* ----------------------------------------------------------------------------- */

View file

@ -137,7 +137,7 @@ static const char *usage4 = (const char *) "\
-oh <headfile> - Set name of C++ output header file for directors to <headfile>\n\
-outcurrentdir - Set default output dir to current dir instead of input file's path\n\
-outdir <dir> - Set language specific files output directory to <dir>\n\
-pcreversion - Display PCRE version information\n\
-pcreversion - Display PCRE2 version information\n\
-small - Compile in virtual elimination and compact mode\n\
-swiglib - Report location of SWIG library and exit\n\
-templatereduce - Reduce all the typedefs in templates\n\
@ -477,7 +477,10 @@ static void getoptions(int argc, char *argv[]) {
Swig_mark_arg(i);
} else if (strncmp(argv[i], "-D", 2) == 0) {
String *d = NewString(argv[i] + 2);
Replace(d, "=", " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
if (Replace(d, "=", " ", DOH_REPLACE_FIRST) == 0) {
// Match C preprocessor behaviour whereby -DFOO sets FOO=1.
Append(d, " 1");
}
Preprocessor_define((DOH *) d, 0);
Delete(d);
// Create a symbol

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

@ -396,7 +396,7 @@ void Swig_nested_name_unnamed_c_structs(Node *n) {
Delete(ins);
Delattr(c, "nested:outer");
} else {
// global unnamed struct - ignore it and it's instances
// global unnamed struct - ignore it and its instances
SetFlag(c, "feature:ignore");
while (next && Getattr(next, "nested:unnamedtype") == c) {
SetFlag(next, "feature:ignore");

View file

@ -407,7 +407,7 @@ public:
printf("Fatal error. SwigType_del_pointer applied to non-pointer.\n");
abort();
}
Replace(t, "r.", "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Replace(t, "r.", "", DOH_REPLACE_FIRST);
}
void oc_SwigType_del_array(SwigType *t) {
@ -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 {

View file

@ -611,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");
@ -658,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 {
@ -681,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");
@ -694,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"));
@ -723,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"))
@ -745,13 +737,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());
Replaceall(tm, "$result", "_outv");
Printf(f->code, "%s\n", tm);
Delete(tm);
@ -815,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);
@ -849,8 +839,6 @@ public:
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));
@ -874,8 +862,6 @@ 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);
@ -920,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

@ -445,13 +445,7 @@ public:
Printv(magic,
"#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n",
"#ifdef PERL_OBJECT\n",
"#define MAGIC_CLASS _wrap_", underscore_module, "_var::\n",
"class _wrap_", underscore_module, "_var : public CPerlObj {\n",
"public:\n",
"#else\n",
"#define MAGIC_CLASS\n",
"#endif\n",
"SWIGCLASS_STATIC int swig_magic_readonly(pTHX_ SV *SWIGUNUSEDPARM(sv), MAGIC *SWIGUNUSEDPARM(mg)) {\n",
tab4, "MAGIC_PPERL\n", tab4, "croak(\"Value is read-only.\");\n", tab4, "return 0;\n", "}\n", NIL);
@ -470,7 +464,6 @@ public:
/* Dump out variable wrappers */
Printv(magic, "\n\n#ifdef PERL_OBJECT\n", "};\n", "#endif\n", NIL);
Printv(magic, "\n#ifdef __cplusplus\n}\n#endif\n", NIL);
Printf(f_header, "%s\n", magic);
@ -725,14 +718,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 +757,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 +767,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 +781,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 +841,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 +868,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 +977,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 +999,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 +1089,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 +1097,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 +2315,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

@ -73,8 +73,10 @@ static int py3 = 0;
/* C++ Support + Shadow Classes */
static int have_constructor;
static int have_repr;
static int have_constructor = 0;
static int have_repr = 0;
static bool have_builtin_static_member_method_callback = false;
static bool have_fast_proxy_static_member_method_callback = false;
static String *real_classname;
/* Thread Support */
@ -93,6 +95,7 @@ static int nortti = 0;
static int relativeimport = 0;
/* flags for the make_autodoc function */
namespace {
enum autodoc_t {
AUTODOC_CLASS,
AUTODOC_CTOR,
@ -103,7 +106,7 @@ enum autodoc_t {
AUTODOC_CONST,
AUTODOC_VAR
};
}
static const char *usage1 = "\
Python Options (available with -python)\n\
@ -313,7 +316,6 @@ public:
} else {
Swig_arg_error();
}
/* end added */
} else if (strcmp(argv[i], "-globals") == 0) {
if (argv[i + 1]) {
global_name = NewString(argv[i + 1]);
@ -444,6 +446,15 @@ public:
}
}
if (builtin && !shadow) {
Printf(stderr, "Incompatible options -builtin and -noproxy specified.\n");
SWIG_exit(EXIT_FAILURE);
}
if (fastproxy) {
Preprocessor_define("SWIGPYTHON_FASTPROXY", 0);
}
if (doxygen)
doxygenTranslator = new PyDocConverter(doxygen_translator_flags);
@ -611,6 +622,10 @@ public:
Printf(f_runtime, "#define SWIGPYTHON_BUILTIN\n");
}
if (fastproxy) {
Printf(f_runtime, "#define SWIGPYTHON_FASTPROXY\n");
}
Printf(f_runtime, "\n");
Printf(f_header, "#ifdef SWIG_TypeQuery\n");
@ -814,6 +829,10 @@ public:
Append(const_code, "{0, 0, 0, 0.0, 0, 0}};\n");
Printf(f_wrappers, "%s\n", const_code);
if (have_fast_proxy_static_member_method_callback)
Printf(f_init, " SWIG_Python_FixMethods(SwigMethods_proxydocs, swig_const_table, swig_types, swig_type_initial);\n\n");
initialize_threads(f_init);
Printf(f_init, "#if PY_VERSION_HEX >= 0x03000000\n");
@ -846,8 +865,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);
@ -905,15 +929,15 @@ public:
* as a replacement of new.instancemethod in Python 3.
* ------------------------------------------------------------ */
int add_pyinstancemethod_new() {
String *name = NewString("SWIG_PyInstanceMethod_New");
String *line = NewString("");
Printf(line, "\t { \"%s\", %s, METH_O, NULL},\n", name, name);
Append(methods, line);
if (fastproxy) {
if (!builtin && fastproxy) {
String *name = NewString("SWIG_PyInstanceMethod_New");
String *line = NewString("");
Printf(line, "\t { \"%s\", %s, METH_O, NULL},\n", name, name);
Append(methods, line);
Append(methods_proxydocs, line);
Delete(line);
Delete(name);
}
Delete(line);
Delete(name);
return 0;
}
@ -923,7 +947,7 @@ public:
* generated for static methods when using -fastproxy
* ------------------------------------------------------------ */
int add_pystaticmethod_new() {
if (fastproxy) {
if (!builtin && fastproxy) {
String *name = NewString("SWIG_PyStaticMethod_New");
String *line = NewString("");
Printf(line, "\t { \"%s\", %s, METH_O, NULL},\n", name, name);
@ -2250,7 +2274,7 @@ public:
return parms;
}
bool funcanno = py3 ? true : false;
bool funcanno = Equal(Getattr(n, "feature:python:annotations"), "c") ? true : false;
String *params = NewString("");
String *_params = make_autodocParmList(n, false, ((in_class || has_self_for_count)? 2 : 1), is_calling, funcanno);
@ -2366,8 +2390,8 @@ public:
if (ret)
ret = SwigType_str(ret, 0);
}
return (ret && py3) ? NewStringf(" -> \"%s\"", ret)
: NewString("");
bool funcanno = Equal(Getattr(n, "feature:python:annotations"), "c") ? true : false;
return (ret && funcanno) ? NewStringf(" -> \"%s\"", ret) : NewString("");
}
/* ------------------------------------------------------------
@ -2472,6 +2496,7 @@ public:
Printf(methods, "\"swig_ptr: %s\"", Getattr(n, "feature:callback:name"));
if (fastproxy) {
Printf(methods_proxydocs, "\"swig_ptr: %s\"", Getattr(n, "feature:callback:name"));
have_fast_proxy_static_member_method_callback = true;
}
} else {
Append(methods, "NULL");
@ -2527,6 +2552,11 @@ public:
const char *builtin_kwargs = builtin_ctor ? ", PyObject *kwargs" : "";
Printv(f->def, linkage, builtin_ctor ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
if (builtin) {
/* Avoid warning if the self parameter is not used. */
Append(f->code, "(void)self;\n");
}
Wrapper_add_local(f, "argc", "Py_ssize_t argc");
Printf(tmp, "PyObject *argv[%d] = {0}", maxargs + 1);
Wrapper_add_local(f, "argv", tmp);
@ -2696,7 +2726,6 @@ public:
bool add_self = builtin_self && (!builtin_ctor || director_class);
bool builtin_getter = (builtin && GetFlag(n, "memberget"));
bool builtin_setter = (builtin && GetFlag(n, "memberset") && !builtin_getter);
char const *self_param = builtin ? "self" : "SWIGUNUSEDPARM(self)";
char const *wrap_return = builtin_ctor ? "int " : "PyObject *";
String *linkage = NewString("SWIGINTERN ");
String *wrapper_name = Swig_name_wrapper(iname);
@ -2751,9 +2780,9 @@ public:
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);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, 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, 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));
@ -2764,8 +2793,14 @@ public:
Swig_warning(WARN_LANG_VARARGS_KEYWORD, input_file, line_number, "Can't wrap varargs with keyword arguments enabled\n");
varargs = 0;
}
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args, PyObject *kwargs) {", NIL);
}
if (builtin) {
/* Avoid warning if the self parameter is not used. */
Append(f->code, "(void)self;\n");
}
if (!builtin || !in_class || tuple_arguments > 0 || builtin_ctor) {
if (!allow_kwargs) {
Append(parse_args, " if (!PyArg_ParseTuple(args, \"");
@ -2792,7 +2827,7 @@ public:
/* Generate code for argument marshalling */
if (funpack) {
if (num_arguments > 0 && !overname) {
if (num_arguments > (builtin_self && !constructor ? 1 : 0) && !overname) {
sprintf(source, "PyObject *swig_obj[%d]", num_arguments);
Wrapper_add_localv(f, "swig_obj", source, NIL);
}
@ -2862,8 +2897,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 */
@ -2926,14 +2959,14 @@ public:
Clear(f->def);
if (overname) {
if (noargs) {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
} else {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
}
Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments);
} 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);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, 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) {
@ -2971,7 +3004,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 {
@ -2993,7 +3025,6 @@ public:
}
}
if (tm && (Len(tm) != 0)) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
}
p = Getattr(p, "tmap:freearg:next");
@ -3005,8 +3036,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);
@ -3095,8 +3124,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");
@ -3160,7 +3187,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);
}
@ -3168,7 +3194,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);
}
@ -3231,9 +3256,9 @@ public:
f = NewWrapper();
if (funpack) {
// Note: funpack is currently always false for varargs
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
} else {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
}
Wrapper_add_local(f, "resultobj", builtin_ctor ? "int resultobj" : "PyObject *resultobj");
Wrapper_add_local(f, "varargs", "PyObject *varargs");
@ -3251,10 +3276,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");
@ -3426,7 +3451,6 @@ public:
Printf(f_init, "#endif\n");
Printf(f_init, "\t }\n");
Printf(f_init, "\t PyDict_SetItemString(md, \"%s\", globals);\n", global_name);
Printf(f_init, "\t Py_DECREF(globals);\n");
if (builtin)
Printf(f_init, "\t SwigPyBuiltin_AddPublicSymbol(public_interface, \"%s\");\n", global_name);
have_globals = 1;
@ -3454,8 +3478,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));
@ -3496,8 +3518,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);
@ -3577,8 +3597,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);
@ -3593,8 +3611,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.
@ -3606,7 +3622,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");
@ -3946,6 +3962,10 @@ public:
int funpack = fastunpack;
static String *tp_new = NewString("PyType_GenericNew");
if (have_builtin_static_member_method_callback) {
Printf(f_init, " SWIG_Python_FixMethods(SwigPyBuiltin_%s_methods, swig_const_table, swig_types, swig_type_initial);\n", mname);
}
Printv(f_init, " SwigPyBuiltin_SetMetaType(builtin_pytype, metatype);\n", NIL);
// We can’t statically initialize a structure member with a function defined in another C module
@ -4016,7 +4036,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);
@ -4306,6 +4326,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("");
@ -4372,6 +4396,7 @@ public:
/* Create new strings for building up a wrapper function */
have_constructor = 0;
have_repr = 0;
have_builtin_static_member_method_callback = false;
class_name = Getattr(n, "sym:name");
real_classname = Getattr(n, "name");
@ -4461,7 +4486,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, ")");
}
}
@ -4732,6 +4759,7 @@ public:
Swig_restore(n);
}
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
if (builtin && in_class) {
if ((GetFlagAttr(n, "feature:extend") || checkAttribute(n, "access", "public"))
&& !Getattr(class_members, symname)) {
@ -4746,7 +4774,7 @@ public:
else if (funpack && argcount == 1)
Append(pyflags, "METH_O");
else
Append(pyflags, "METH_VARARGS");
Append(pyflags, kw ? "METH_VARARGS|METH_KEYWORDS" : "METH_VARARGS");
// Cast via void(*)(void) to suppress GCC -Wcast-function-type warning.
// Python should always call the function correctly, but the Python C
// API requires us to store it in function pointer of a different type.
@ -4754,6 +4782,11 @@ public:
String *ds = cdocstring(n, AUTODOC_STATICFUNC);
Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"%s\" },\n", symname, wname, pyflags, ds);
Delete(ds);
} else if (Getattr(n, "feature:callback")) {
String *ds = NewStringf("swig_ptr: %s", Getattr(n, "feature:callback:name"));
Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"%s\" },\n", symname, wname, pyflags, ds);
Delete(ds);
have_builtin_static_member_method_callback = true;
} else {
Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"\" },\n", symname, wname, pyflags);
}
@ -4772,7 +4805,6 @@ public:
String *staticfunc_name = NewString(fastproxy ? "_swig_new_static_method" : "staticmethod");
bool fast = (fastproxy && !have_addtofunc(n)) || Getattr(n, "feature:callback");
if (!fast || olddefs) {
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
String *parms = make_pyParmList(n, false, false, kw);
String *callParms = make_pyParmList(n, false, true, kw);
Printv(f_shadow, "\n", tab4, "@staticmethod", NIL);
@ -4869,6 +4901,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

@ -634,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");
@ -1302,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) {
@ -1745,7 +1745,7 @@ 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. */
bool isSet(GetFlag(n, "memberset"));
bool isSet = GetFlag(n, "memberset") ? true : false;
String *tmp = NewString(isSet ? Swig_name_set(NSPACE_TODO, class_name) : Swig_name_get(NSPACE_TODO, class_name));
@ -1912,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);
@ -1924,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"))) {
@ -1984,7 +1980,6 @@ int R::functionWrapper(Node *n) {
String *cleanup = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
if (tm && (Len(tm) != 0)) {
Printv(cleanup, tm, "\n", NIL);
}
@ -2001,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"));
@ -2076,14 +2070,12 @@ int R::functionWrapper(Node *n) {
/* 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);
}
@ -2092,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");
@ -2578,7 +2569,7 @@ int R::generateCopyRoutines(Node *n) {
Printf(sfile, "# Start definition of copy methods for %s\n", rclassName);
Printf(sfile, "setMethod('copyToR', '_p_%s', CopyToR%s);\n", rclassName,
Printf(sfile, "setMethod('copyToR', '_p%s', CopyToR%s);\n", mangledName,
mangledName);
Printf(sfile, "setMethod('copyToC', '%s', CopyToC%s);\n\n", rclassName,
mangledName);

View file

@ -106,9 +106,10 @@ public:
char *strip(const_String_or_char_ptr s) {
Clear(temp);
Append(temp, s);
if (Strncmp(s, prefix, Len(prefix)) == 0) {
Replaceall(temp, prefix, "");
Append(temp, Char(s) + Len(prefix));
} else {
Append(temp, s);
}
return Char(temp);
}
@ -116,6 +117,7 @@ public:
/* flags for the make_autodoc function */
namespace {
enum autodoc_t {
AUTODOC_CLASS,
AUTODOC_CTOR,
@ -127,6 +129,7 @@ enum autodoc_t {
AUTODOC_SETTER,
AUTODOC_NONE
};
}
static const char *usage = "\
Ruby Options (available with -ruby)\n\
@ -1425,16 +1428,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 +1475,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 +1497,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 +1508,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 +1520,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 +1547,6 @@ public:
}
Delete(source);
Delete(target);
}
/* ---------------------------------------------------------------------
@ -1569,7 +1562,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 +1583,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 +1604,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 +1865,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");
@ -1973,7 +1960,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);
}
@ -1982,7 +1968,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);
}
@ -2212,8 +2197,6 @@ public:
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 {
@ -2248,8 +2231,6 @@ public:
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 {
@ -2361,8 +2342,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

@ -11,10 +11,11 @@
* Scilab language module for SWIG.
* --------------------------------------------------------------------------*/
#include <cstddef>
#include <cstdlib>
#include "swigmod.h"
static const int SCILAB_IDENTIFIER_NAME_CHAR_MAX = 24;
static const int SCILAB_VARIABLE_NAME_CHAR_MAX = SCILAB_IDENTIFIER_NAME_CHAR_MAX - 4;
static const char *usage = (char *) " \
Scilab options (available with -scilab)\n \
@ -25,7 +26,6 @@ Scilab options (available with -scilab)\n \
-buildersources <files> - Add the (comma separated) files <files> to the builder sources\n \
-builderverbositylevel <level> - Set the builder verbosity level to <level> (default 0: off, 2: high)\n \
-gatewayxml <gateway_id> - Generate gateway xml with the given <gateway_id>\n \
-targetversion <scilab_major_version> - Generate for Scilab target (major) version (default: 5)\n \
\n";
@ -40,11 +40,11 @@ protected:
String *variablesCode;
int targetVersion;
bool generateBuilder;
File *builderFile;
String *builderCode;
String *builderCode5;
String *builderCode6;
int builderFunctionCount;
List *sourceFileList;
@ -67,6 +67,9 @@ protected:
bool createLoader;
File *loaderFile;
String *loaderScript;
String *loaderScript5;
String *loaderScript6;
int loaderFunctionCount;
public:
/* ------------------------------------------------------------------------
@ -74,8 +77,6 @@ public:
* ----------------------------------------------------------------------*/
virtual void main(int argc, char *argv[]) {
targetVersion = 5;
generateBuilder = false;
sourceFileList = NewList();
cflags = NewList();
@ -99,23 +100,23 @@ public:
/* Manage command line arguments */
for (int argIndex = 1; argIndex < argc; argIndex++) {
if (argv[argIndex] != NULL) {
if (strcmp(argv[argIndex], "-help") == 0) {
Printf(stdout, "%s\n", usage);
} else if (strcmp(argv[argIndex], "-builder") == 0) {
Swig_mark_arg(argIndex);
generateBuilder = true;
createLoader = false;
} else if (strcmp(argv[argIndex], "-buildersources") == 0) {
if (argv[argIndex + 1] != NULL) {
Swig_mark_arg(argIndex);
char *sourceFile = strtok(argv[argIndex + 1], ",");
while (sourceFile != NULL) {
Insert(sourceFileList, Len(sourceFileList), sourceFile);
sourceFile = strtok(NULL, ",");
}
Swig_mark_arg(argIndex + 1);
}
} else if (strcmp(argv[argIndex], "-buildercflags") == 0) {
if (strcmp(argv[argIndex], "-help") == 0) {
Printf(stdout, "%s\n", usage);
} else if (strcmp(argv[argIndex], "-builder") == 0) {
Swig_mark_arg(argIndex);
generateBuilder = true;
createLoader = false;
} else if (strcmp(argv[argIndex], "-buildersources") == 0) {
if (argv[argIndex + 1] != NULL) {
Swig_mark_arg(argIndex);
char *sourceFile = strtok(argv[argIndex + 1], ",");
while (sourceFile != NULL) {
Insert(sourceFileList, Len(sourceFileList), sourceFile);
sourceFile = strtok(NULL, ",");
}
Swig_mark_arg(argIndex + 1);
}
} else if (strcmp(argv[argIndex], "-buildercflags") == 0) {
Swig_mark_arg(argIndex);
if (argv[argIndex + 1] != NULL) {
Insert(cflags, Len(cflags), argv[argIndex + 1]);
@ -140,12 +141,6 @@ public:
createGatewayXML = true;
gatewayID = NewString(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
} else if (strcmp(argv[argIndex], "-targetversion") == 0) {
if (argv[argIndex + 1] != NULL) {
Swig_mark_arg(argIndex);
targetVersion = atoi(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
}
}
}
}
@ -227,10 +222,13 @@ public:
}
// Module initialization function
String *smallFunctionName = createSmallIdentifierName(gatewayName, SCILAB_IDENTIFIER_NAME_CHAR_MAX - 5);
String *gatewayInitFunctionName = NewStringf("%s_Init", gatewayName);
String *gatewayInitSmallFunctionName = NewStringf("%s_Init", smallFunctionName);
String *wrapperFunctionName = NewStringf("SWIG_%s_Init", gatewayName);
/* Add initialization function to builder table */
addFunctionToScilab(gatewayInitFunctionName, gatewayInitFunctionName);
addFunctionToScilab(gatewayInitFunctionName, gatewayInitSmallFunctionName, wrapperFunctionName);
// Add helper functions to builder table
addHelperFunctions();
@ -316,6 +314,8 @@ public:
/* Get some useful attributes of this function */
String *functionName = Getattr(node, "sym:name");
String *smallFunctionName = createSmallIdentifierName(functionName);
SwigType *functionReturnType = Getattr(node, "type");
ParmList *functionParamsList = Getattr(node, "parms");
@ -360,7 +360,7 @@ public:
int maxInputArguments = emit_num_arguments(functionParamsList);
int minInputArguments = emit_num_required(functionParamsList);
int minOutputArguments = 0;
int maxOutputArguments = 0;
int maxOutputArguments = 1;
if (!emit_isvarargs(functionParamsList)) {
Printf(wrapper->code, "SWIG_CheckInputArgument(pvApiCtx, $mininputarguments, $maxinputarguments);\n");
@ -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);
}
@ -500,10 +498,12 @@ public:
Replaceall(wrapper->code, "$symname", functionName);
/* Set CheckInputArgument and CheckOutputArgument input arguments */
/* In Scilab there is always one output even if not defined */
if (minOutputArguments == 0) {
if (maxOutputArguments < 1) {
maxOutputArguments = 1;
}
if (minOutputArguments == 1) {
minOutputArguments = 0;
}
String *argnumber = NewString("");
Printf(argnumber, "%d", minInputArguments);
Replaceall(wrapper->code, "$mininputarguments", argnumber);
@ -523,16 +523,14 @@ public:
/* Dump the function out */
Wrapper_print(wrapper, wrappersSection);
String *scilabFunctionName = checkIdentifierName(functionName, SCILAB_IDENTIFIER_NAME_CHAR_MAX);
/* Update builder.sce contents */
if (isLastOverloaded) {
addFunctionToScilab(scilabFunctionName, wrapperName);
addFunctionToScilab(functionName, smallFunctionName, wrapperName);
dispatchFunction(node);
}
if (!isOverloaded) {
addFunctionToScilab(scilabFunctionName, wrapperName);
addFunctionToScilab(functionName, smallFunctionName, wrapperName);
}
/* tidy up */
@ -593,21 +591,20 @@ public:
/* Get information about variable */
String *origVariableName = Getattr(node, "name"); // Ex: Shape::nshapes
String *variableName = Getattr(node, "sym:name"); // Ex; Shape_nshapes (can be used for function names, ...)
// Variable names can have SCILAB_VARIABLE_NAME_CHAR_MAX because of suffixes "_get" or "_set" added to function
String *scilabVariableName = checkIdentifierName(variableName, SCILAB_VARIABLE_NAME_CHAR_MAX);
String *smallVariableName = createSmallIdentifierName(variableName, SCILAB_IDENTIFIER_NAME_CHAR_MAX - 4);
/* Manage GET function */
Wrapper *getFunctionWrapper = NewWrapper();
String *getFunctionName = Swig_name_get(NSPACE_TODO, variableName);
String *scilabGetFunctionName = Swig_name_get(NSPACE_TODO, scilabVariableName);
String *scilabGetFunctionName = Swig_name_get(NSPACE_TODO, variableName);
String *scilabGetSmallFunctionName = Swig_name_get(NSPACE_TODO, smallVariableName);
Setattr(node, "wrap:name", getFunctionName);
Printv(getFunctionWrapper->def, "int ", getFunctionName, "(SWIG_GatewayParameters) {\n", NIL);
/* Check the number of input and output */
Printf(getFunctionWrapper->def, "SWIG_CheckInputArgument(pvApiCtx, 0, 0);\n");
Printf(getFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 1, 1);\n");
Printf(getFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 0, 1);\n");
Printf(getFunctionWrapper->def, "SWIG_Scilab_SetApiContext(pvApiCtx);\n");
String *varoutTypemap = Swig_typemap_lookup("varout", node, origVariableName, 0);
@ -623,20 +620,21 @@ public:
Wrapper_print(getFunctionWrapper, wrappersSection);
/* Add function to builder table */
addFunctionToScilab(scilabGetFunctionName, getFunctionName);
addFunctionToScilab(scilabGetFunctionName, scilabGetSmallFunctionName, getFunctionName);
/* Manage SET function */
if (is_assignable(node)) {
Wrapper *setFunctionWrapper = NewWrapper();
String *setFunctionName = Swig_name_set(NSPACE_TODO, variableName);
String *scilabSetFunctionName = Swig_name_set(NSPACE_TODO, scilabVariableName);
String *scilabSetFunctionName = Swig_name_set(NSPACE_TODO, variableName);
String *scilabSetSmallFunctionName = Swig_name_set(NSPACE_TODO, smallVariableName);
Setattr(node, "wrap:name", setFunctionName);
Printv(setFunctionWrapper->def, "int ", setFunctionName, "(SWIG_GatewayParameters) {\n", NIL);
/* Check the number of input and output */
Printf(setFunctionWrapper->def, "SWIG_CheckInputArgument(pvApiCtx, 1, 1);\n");
Printf(setFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 1, 1);\n");
Printf(setFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 0, 1);\n");
Printf(setFunctionWrapper->def, "SWIG_Scilab_SetApiContext(pvApiCtx);\n");
String *varinTypemap = Swig_typemap_lookup("varin", node, origVariableName, 0);
@ -650,7 +648,7 @@ public:
Wrapper_print(setFunctionWrapper, wrappersSection);
/* Add function to builder table */
addFunctionToScilab(scilabSetFunctionName, setFunctionName);
addFunctionToScilab(scilabSetFunctionName, scilabSetSmallFunctionName, setFunctionName);
DelWrapper(setFunctionWrapper);
}
@ -686,10 +684,9 @@ public:
constantTypemap = Swig_typemap_lookup("scilabconstcode", node, nodeName, 0);
if (constantTypemap != NULL) {
String *scilabConstantName = checkIdentifierName(constantName, SCILAB_IDENTIFIER_NAME_CHAR_MAX);
Setattr(node, "wrap:name", constantName);
Replaceall(constantTypemap, "$result", scilabConstantName);
Replaceall(constantTypemap, "$result", constantName);
Replaceall(constantTypemap, "$value", constantValue);
emit_action_code(node, variablesCode, constantTypemap);
@ -707,19 +704,21 @@ public:
Delete(str);
constantValue = wname;
}
// Constant names can have SCILAB_VARIABLE_NAME_CHAR_MAX because of suffixes "_get" added to function
String *scilabConstantName = checkIdentifierName(constantName, SCILAB_VARIABLE_NAME_CHAR_MAX);
String *smallConstantName = createSmallIdentifierName(constantName, SCILAB_IDENTIFIER_NAME_CHAR_MAX - 4);
/* Create GET function to get the constant value */
Wrapper *getFunctionWrapper = NewWrapper();
String *getFunctionName = Swig_name_get(NSPACE_TODO, constantName);
String *scilabGetFunctionName = Swig_name_get(NSPACE_TODO, scilabConstantName);
String *scilabGetSmallFunctionName = Swig_name_get(NSPACE_TODO, smallConstantName);
Setattr(node, "wrap:name", getFunctionName);
Setattr(node, "wrap:name", getFunctionName);
Printv(getFunctionWrapper->def, "int ", getFunctionName, "(SWIG_GatewayParameters) {\n", NIL);
/* Check the number of input and output */
Printf(getFunctionWrapper->def, "SWIG_CheckInputArgument(pvApiCtx, 0, 0);\n");
Printf(getFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 1, 1);\n");
Printf(getFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 0, 1);\n");
Printf(getFunctionWrapper->def, "SWIG_Scilab_SetApiContext(pvApiCtx);\n");
constantTypemap = Swig_typemap_lookup("constcode", node, nodeName, 0);
@ -737,7 +736,7 @@ public:
Wrapper_print(getFunctionWrapper, wrappersSection);
/* Add the function to Scilab */
addFunctionToScilab(scilabGetFunctionName, getFunctionName);
addFunctionToScilab(getFunctionName, scilabGetSmallFunctionName, getFunctionName);
DelWrapper(getFunctionWrapper);
@ -784,78 +783,13 @@ public:
return Language::enumvalueDeclaration(node);
}
/* ---------------------------------------------------------------------
* membervariableHandler()
* --------------------------------------------------------------------- */
virtual int membervariableHandler(Node *node) {
checkMemberIdentifierName(node, SCILAB_VARIABLE_NAME_CHAR_MAX);
return Language::membervariableHandler(node);
}
/* -----------------------------------------------------------------------
* checkIdentifierName()
* If Scilab target version is lower than 6:
* truncates (and displays a warning) too long member identifier names
* (applies on members of structs, classes...)
* (Scilab 5 identifier names are limited to 24 chars max)
* ----------------------------------------------------------------------- */
String *checkIdentifierName(String *name, int char_size_max) {
String *scilabIdentifierName;
if (targetVersion <= 5) {
if (Len(name) > char_size_max) {
scilabIdentifierName = DohNewStringWithSize(name, char_size_max);
Swig_warning(WARN_SCILAB_TRUNCATED_NAME, input_file, line_number,
"Identifier name '%s' exceeds 24 characters and has been truncated to '%s'.\n", name, scilabIdentifierName);
} else
scilabIdentifierName = name;
} else {
scilabIdentifierName = DohNewString(name);
}
return scilabIdentifierName;
}
/* -----------------------------------------------------------------------
* checkMemberIdentifierName()
* If Scilab target version is lower than 6:
* truncates (and displays a warning) too long member identifier names
* (applies on members of structs, classes...)
* (Scilab 5 identifier names are limited to 24 chars max)
* ----------------------------------------------------------------------- */
void checkMemberIdentifierName(Node *node, int char_size_max) {
if (targetVersion <= 5) {
String *memberName = Getattr(node, "sym:name");
Node *containerNode = parentNode(node);
String *containerName = Getattr(containerNode, "sym:name");
int lenContainerName = Len(containerName);
int lenMemberName = Len(memberName);
if (lenContainerName + lenMemberName + 1 > char_size_max) {
int lenScilabMemberName = char_size_max - lenContainerName - 1;
if (lenScilabMemberName > 0) {
String *scilabMemberName = DohNewStringWithSize(memberName, lenScilabMemberName);
Setattr(node, "sym:name", scilabMemberName);
Swig_warning(WARN_SCILAB_TRUNCATED_NAME, input_file, line_number,
"Wrapping functions names for member '%s.%s' will exceed 24 characters, "
"so member name has been truncated to '%s'.\n", containerName, memberName, scilabMemberName);
} else {
Swig_error(input_file, line_number,
"Wrapping functions names for member '%s.%s' will exceed 24 characters, "
"please rename the container of member '%s'.\n", containerName, memberName, containerName);
}
}
}
}
/* -----------------------------------------------------------------------
* addHelperFunctions()
* ----------------------------------------------------------------------- */
void addHelperFunctions() {
addFunctionToScilab("SWIG_this", "SWIG_this");
addFunctionToScilab("SWIG_ptr", "SWIG_ptr");
addFunctionToScilab("SWIG_this", "SWIG_this", "SWIG_this");
addFunctionToScilab("SWIG_ptr", "SWIG_ptr", "SWIG_ptr");
}
/* -----------------------------------------------------------------------
@ -863,20 +797,20 @@ public:
* Declare a wrapped function in Scilab (builder, gateway, XML, ...)
* ----------------------------------------------------------------------- */
void addFunctionToScilab(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) {
void addFunctionToScilab(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr scilabSmallFunctionName, const_String_or_char_ptr wrapperFunctionName) {
if (!generateBuilder)
addFunctionInGatewayHeader(scilabFunctionName, wrapperFunctionName);
addFunctionInGatewayHeader(scilabFunctionName, scilabSmallFunctionName, wrapperFunctionName);
if (generateBuilder) {
addFunctionInScriptTable(scilabFunctionName, wrapperFunctionName, builderCode);
addFunctionInScriptTable(scilabFunctionName, scilabSmallFunctionName, wrapperFunctionName, builderCode5, builderCode6);
}
if (createLoader) {
addFunctionInLoader(scilabFunctionName);
addFunctionInLoader(scilabFunctionName, scilabSmallFunctionName);
}
if (gatewayXMLFile) {
Printf(gatewayXML, "<PRIMITIVE gatewayId=\"%s\" primitiveId=\"%d\" primitiveName=\"%s\"/>\n", gatewayID, primitiveID++, scilabFunctionName);
Printf(gatewayXML, "<PRIMITIVE gatewayId=\"%s\" primitiveId=\"%d\" primitiveName=\"%s\"/>\n", gatewayID, primitiveID++, scilabSmallFunctionName);
}
}
@ -945,7 +879,8 @@ public:
}
}
Printf(builderCode, "table = [");
Printf(builderCode5, "table = [ ..\n");
Printf(builderCode6, "table = [ ..\n");
}
/* -----------------------------------------------------------------------
@ -953,11 +888,13 @@ public:
* Add a function wrapper in the function table of generated builder script
* ----------------------------------------------------------------------- */
void addFunctionInScriptTable(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName, String *scriptCode) {
void addFunctionInScriptTable(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr scilabSmallFunctionName, const_String_or_char_ptr wrapperFunctionName, String *scriptCode5, String *scriptCode6) {
if (++builderFunctionCount % 10 == 0) {
Printf(scriptCode, "];\ntable = [table;");
Printf(scriptCode5, "];\ntable = [table; ..\n");
Printf(scriptCode6, "];\ntable = [table; ..\n");
}
Printf(scriptCode, "\"%s\",\"%s\";", scilabFunctionName, wrapperFunctionName);
Printf(scriptCode5, "\"%s\",\"%s\"; ..\n", scilabSmallFunctionName, wrapperFunctionName);
Printf(scriptCode6, "\"%s\",\"%s\"; ..\n", scilabFunctionName, wrapperFunctionName);
}
/* -----------------------------------------------------------------------
@ -965,7 +902,26 @@ public:
* ----------------------------------------------------------------------- */
void saveBuilderFile(String *gatewayName) {
Printf(builderCode, "];\n");
Printf(builderCode5, "];\n");
Printf(builderCode6, "];\n");
if (Equal(builderCode5, builderCode6)) {
Append(builderCode, builderCode6);
} else {
Printf(builderCode, "ver = getversion('scilab');\n");
Printf(builderCode, "if ver(1) < 6 then\n");
Printf(builderCode, " // version is less or equal to 5.5.2\n");
Printf(builderCode, " \n");
Append(builderCode, builderCode5);
Printf(builderCode, " \n");
Printf(builderCode, "else\n");
Printf(builderCode, " // version is 6.0.0 or more\n");
Printf(builderCode, " \n");
Append(builderCode, builderCode6);
Printf(builderCode, " \n");
Printf(builderCode, "end\n");
}
Printf(builderCode, "ierr = 0;\n");
Printf(builderCode, "if ~isempty(table) then\n");
Printf(builderCode, " ierr = execstr(\"ilib_build(''%s'', table, files, libs, [], ldflags, cflags);\", 'errcatch');\n", gatewayName);
@ -977,7 +933,9 @@ public:
Printf(builderCode, "if ierr <> 0 then\n");
Printf(builderCode, " error(ierr, err_msg);\n");
Printf(builderCode, "end\n");
Printv(builderFile, builderCode, NIL);
Write(builderFile, builderCode, Len(builderCode));
Delete(builderCode);
Delete(builderFile);
}
@ -1049,13 +1007,13 @@ public:
* Add a function in the gateway header
* ----------------------------------------------------------------------- */
void addFunctionInGatewayHeader(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) {
void addFunctionInGatewayHeader(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr scilabSmallFunctionName, const_String_or_char_ptr wrapperFunctionName) {
if (gatewayHeaderV5 == NULL) {
gatewayHeaderV5 = NewString("");
Printf(gatewayHeaderV5, "static GenericTable Tab[] = {\n");
} else
Printf(gatewayHeaderV5, ",\n");
Printf(gatewayHeaderV5, " {(Myinterfun)sci_gateway, (GT)%s, (char *)\"%s\"}", wrapperFunctionName, scilabFunctionName);
Printf(gatewayHeaderV5, " {(Myinterfun)sci_gateway, (GT)%s, (char *)\"%s\"}", wrapperFunctionName, scilabSmallFunctionName);
Printf(gatewayHeaderV6, "if (wcscmp(pwstFuncName, L\"%s\") == 0) { addCStackFunction((wchar_t *)L\"%s\", &%s, (wchar_t *)MODULE_NAME); }\n", scilabFunctionName, scilabFunctionName, wrapperFunctionName);
}
@ -1113,13 +1071,15 @@ public:
emitBanner(loaderFile);
loaderScript = NewString("");
Printf(loaderScript, "%s_path = get_absolute_file_path('loader.sce');\n", gatewayLibraryName);
Printf(loaderScript, "[bOK, ilib] = c_link('%s');\n", gatewayLibraryName);
Printf(loaderScript, "if bOK then\n");
Printf(loaderScript, " ulink(ilib);\n");
Printf(loaderScript, "end\n");
Printf(loaderScript, "list_functions = [..\n");
loaderFunctionCount = 0;
loaderScript = NewString("function loader_function()\n");
Printf(loaderScript, " p = get_absolute_file_path('loader.sce');\n", gatewayLibraryName);
Printf(loaderScript, " [bOK, ilib] = c_link('%s');\n", gatewayLibraryName);
Printf(loaderScript, " if bOK then\n");
Printf(loaderScript, " ulink(ilib);\n");
Printf(loaderScript, " end\n");
loaderScript5 = NewString(" list_functions = [ ..\n");
loaderScript6 = NewString(" list_functions = [ ..\n");
}
/* -----------------------------------------------------------------------
@ -1127,8 +1087,13 @@ public:
* Add a function in the loader script table
* ----------------------------------------------------------------------- */
void addFunctionInLoader(const_String_or_char_ptr scilabFunctionName) {
Printf(loaderScript, " '%s'; ..\n", scilabFunctionName);
void addFunctionInLoader(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr scilabSmallFunctionName) {
if (++loaderFunctionCount % 10 == 0) {
Printf(loaderScript5, " ];\n list_functions = [list_functions; ..\n");
Printf(loaderScript6, " ];\n list_functions = [list_functions; ..\n");
}
Printf(loaderScript5, " '%s'; ..\n", scilabSmallFunctionName);
Printf(loaderScript6, " '%s'; ..\n", scilabFunctionName);
}
/* -----------------------------------------------------------------------
@ -1137,18 +1102,66 @@ public:
* ----------------------------------------------------------------------- */
void saveLoaderFile(String *gatewayLibraryName) {
Printf(loaderScript, "];\n");
Printf(loaderScript, "addinter(fullfile(%s_path, '%s' + getdynlibext()), '%s', list_functions);\n",
gatewayLibraryName, gatewayLibraryName, gatewayLibraryName);
Printf(loaderScript, "clear %s_path;\n", gatewayLibraryName);
Printf(loaderScript, "clear bOK;\n");
Printf(loaderScript, "clear ilib;\n");
Printf(loaderScript, "clear list_functions;\n");
Printf(loaderScript5, " ];\n");
Printf(loaderScript6, " ];\n");
if (Equal(loaderScript5, loaderScript6)) {
Append(loaderScript, loaderScript6);
} else {
Printf(loaderScript, " ver = getversion('scilab');\n");
Printf(loaderScript, " if ver(1) < 6 then\n");
Printf(loaderScript, " // version is less or equal to 5.5.2\n");
Printf(loaderScript, " \n");
Append(loaderScript, loaderScript5);
Delete(loaderScript5);
Printf(loaderScript, " \n");
Printf(loaderScript, " else\n");
Printf(loaderScript, " // version is 6.0.0 or more\n");
Printf(loaderScript, " \n");
Append(loaderScript, loaderScript6);
Delete(loaderScript6);
Printf(loaderScript, " \n");
Printf(loaderScript, " end\n");
}
Printf(loaderScript, " addinter(p + '%s' + getdynlibext(), '%s', list_functions);\n", gatewayLibraryName, gatewayLibraryName);
Printf(loaderScript, "endfunction\n");
Printf(loaderScript, "loader_function();\n");
Printf(loaderScript, "clear loader_function;\n");
Printv(loaderFile, loaderScript, NIL);
Delete(loaderScript);
Delete(loaderFile);
}
/* -----------------------------------------------------------------------
* createSmallIdentifierName()
* Create a Scilab small identifier to be used by Scilab 5
* ----------------------------------------------------------------------- */
String* createSmallIdentifierName(String* name, int outputLen = SCILAB_IDENTIFIER_NAME_CHAR_MAX) {
char* s = Char(name);
int nameLen = Len(s);
// truncate and preserve common suffix
if (outputLen > 4 && nameLen > outputLen) {
String* smallName = NewStringWithSize(name, outputLen);
char* smallNameStr = (char*) Data(smallName);
if (s[nameLen-4] == '_' && s[nameLen - 3] == 'g' && s[nameLen - 2] == 'e' && s[nameLen - 1] == 't') {
// get
memcpy(&smallNameStr[outputLen - 4], &s[nameLen - 4], 4);
} else if (s[nameLen-4] == '_' && s[nameLen - 3] == 's' && s[nameLen - 2] == 'e' && s[nameLen - 1] == 't') {
// set
memcpy(&smallNameStr[outputLen - 4], &s[nameLen - 4], 4);
}
return smallName;
}
return name;
}
};
extern "C" Language *swig_scilab(void) {

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);
@ -909,7 +889,7 @@ public:
// Add methods
if (have_methods) {
Printv(ptrclass, imethods, NIL);
};
}
// Close out the pointer class
Printv(ptrclass, "}\n\n", NIL);
@ -967,7 +947,7 @@ public:
if (!itcl) {
Printv(cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, (ClientData)&_wrap_class_", mangled_classname,
"},\n", NIL);
};
}
Delete(t);
Delete(mangled_classname);
@ -1043,7 +1023,7 @@ public:
Printv(imethods, "{ ", ns_name, "::", class_name, "_", realname, " $swigobj", NIL);
} else {
Printv(imethods, "{ ", class_name, "_", realname, " $swigobj", NIL);
};
}
pnum = 0;
for (p = l; p; p = nextSibling(p)) {

View file

@ -1047,13 +1047,6 @@ class TypePass:private Dispatcher {
|| (Getattr(c, "feature:extend") && !Getattr(c, "code"))
|| GetFlag(c, "feature:ignore"))) {
/* Don't generate a method if the method is overridden in this class,
* for example don't generate another m(bool) should there be a Base::m(bool) :
* struct Derived : Base {
* void m(bool);
* using Base::m;
* };
*/
String *csymname = Getattr(c, "sym:name");
if (!csymname || (Strcmp(csymname, symname) == 0)) {
{
@ -1069,11 +1062,20 @@ class TypePass:private Dispatcher {
over = Getattr(over, "sym:nextSibling");
}
if (match) {
/* Don't generate a method if the method is overridden in this class,
* for example don't generate another m(bool) should there be a Base::m(bool) :
* struct Derived : Base {
* void m(bool);
* using Base::m;
* };
*/
c = Getattr(c, "csym:nextSibling");
continue;
}
}
Node *nn = copyNode(c);
Setfile(nn, Getfile(n));
Setline(nn, Getline(n));
Delattr(nn, "access"); // access might be different from the method in the base class
Setattr(nn, "access", Getattr(n, "access"));
if (!Getattr(nn, "sym:name"))
@ -1117,6 +1119,9 @@ class TypePass:private Dispatcher {
} else {
Delete(nn);
}
} else {
Swig_warning(WARN_LANG_USING_NAME_DIFFERENT, Getfile(n), Getline(n), "Using declaration %s, with name '%s', is not actually using\n", SwigType_namestr(Getattr(n, "uname")), symname);
Swig_warning(WARN_LANG_USING_NAME_DIFFERENT, Getfile(c), Getline(c), "the method from %s, with name '%s', as the names are different.\n", Swig_name_decl(c), csymname);
}
}
}

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();
}