Merge remote-tracking branch 'origin/master' into gsoc2012-scilab

This commit is contained in:
Sylvestre Ledru 2013-09-13 09:18:06 +02:00
commit 9c5bac9887
83 changed files with 2913 additions and 7441 deletions

View file

@ -4028,7 +4028,7 @@ public:
Delete(director_ctor_code);
director_ctor_code = NewString("$director_new");
Java_director_declaration(n);
directorDeclaration(n);
Printf(f_directors_h, "%s {\n", Getattr(n, "director:decl"));
Printf(f_directors_h, "\npublic:\n");
@ -4148,13 +4148,13 @@ public:
}
/*----------------------------------------------------------------------
* Java_director_declaration()
* directorDeclaration()
*
* Generate the director class's declaration
* e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {"
*--------------------------------------------------------------------*/
void Java_director_declaration(Node *n) {
void directorDeclaration(Node *n) {
String *base = Getattr(n, "classtype");
String *class_ctor = NewString("Swig::Director()");

View file

@ -4221,7 +4221,7 @@ public:
Delete(director_ctor_code);
director_ctor_code = NewString("$director_new");
Java_director_declaration(n);
directorDeclaration(n);
Printf(f_directors_h, "%s {\n", Getattr(n, "director:decl"));
Printf(f_directors_h, "\npublic:\n");
@ -4405,13 +4405,13 @@ public:
}
/*----------------------------------------------------------------------
* Java_director_declaration()
* directorDeclaration()
*
* Generate the director class's declaration
* e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {"
*--------------------------------------------------------------------*/
void Java_director_declaration(Node *n) {
void directorDeclaration(Node *n) {
String *base = Getattr(n, "classtype");
String *class_ctor = NewString("Swig::Director(jenv)");

View file

@ -45,6 +45,7 @@
*/
#include "swigmod.h"
#include "cparse.h"
/**** Diagnostics:
With the #define REPORT(), you can change the amount of diagnostics given
@ -111,6 +112,9 @@ private:
String *s_const_tab; // table of global constants
String *s_methods_tab; // table of class methods
String *s_attr_tab; // table of class attributes
String *s_cls_attr_tab; // table of class static attributes
String *s_cls_methods_tab; // table of class static methods
String *s_cls_const_tab; // tables of class constants(including enums)
String *s_luacode; // luacode to be called during init
String *s_dot_get; // table of variable 'get' functions
String *s_dot_set; // table of variable 'set' functions
@ -154,6 +158,9 @@ public:
s_const_tab(0),
s_methods_tab(0),
s_attr_tab(0),
s_cls_attr_tab(0),
s_cls_methods_tab(0),
s_cls_const_tab(0),
s_luacode(0),
s_dot_get(0),
s_dot_set(0),
@ -736,13 +743,18 @@ public:
NEW LANGUAGE NOTE:END ************************************************/
/* Now register the function with the interpreter. */
if (!Getattr(n, "sym:overloaded")) {
//REPORT("dispatchFunction", n);
// add_method(n, iname, wname, description);
if (current==NO_CPP || current==STATIC_FUNC) { // emit normal fns & static fns
String *wrapname = Swig_name_wrapper(iname);
if(elua_ltr || eluac_ltr)
Printv(s_cmd_tab, tab4, "{LSTRKEY(\"", iname, "\")", ", LFUNCVAL(", Swig_name_wrapper(iname), ")", "},\n", NIL);
else
Printv(s_cmd_tab, tab4, "{ \"", iname, "\", ", Swig_name_wrapper(iname), "},\n", NIL);
// Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", Swig_name_wrapper(iname), "},\n", NIL);
if (getCurrentClass()) {
Setattr(n,"luaclassobj:wrap:name", wrapname);
}
}
} else {
if (!Getattr(n, "sym:nextSibling")) {
@ -775,6 +787,7 @@ public:
look for %typecheck(SWIG_TYPECHECK_*) in the .swg file
NEW LANGUAGE NOTE:END ************************************************/
void dispatchFunction(Node *n) {
//REPORT("dispatchFunction", n);
/* Last node in overloaded chain */
int maxargs;
@ -811,7 +824,7 @@ public:
Printf(protoTypes, "\n\" %s\\n\"", fulldecl);
Delete(fulldecl);
} while ((sibl = Getattr(sibl, "sym:nextSibling")));
Printf(f->code, "lua_pushstring(L,\"Wrong arguments for overloaded function '%s'\\n\"\n"
Printf(f->code, "SWIG_Lua_pusherrstring(L,\"Wrong arguments for overloaded function '%s'\\n\"\n"
"\" Possible C/C++ prototypes are:\\n\"%s);\n",symname,protoTypes);
Delete(protoTypes);
@ -822,10 +835,14 @@ public:
if (current==NO_CPP || current==STATIC_FUNC) // emit normal fns & static fns
Printv(s_cmd_tab, tab4, "{ \"", symname, "\",", wname, "},\n", NIL);
if (getCurrentClass())
Setattr(n,"luaclassobj:wrap:name", wname);
else
Delete(wname);
DelWrapper(f);
Delete(dispatch);
Delete(tmp);
Delete(wname);
}
@ -878,8 +895,13 @@ public:
} else {
Printf(s_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, iname, getName, setName);
}
Delete(getName);
Delete(setName);
if (getCurrentClass()) {
Setattr(n, "luaclassobj:wrap:get", getName);
Setattr(n, "luaclassobj:wrap:set", setName);
} else {
Delete(getName);
Delete(setName);
}
return result;
}
@ -887,7 +909,7 @@ public:
* constantWrapper()
* ------------------------------------------------------------ */
virtual int constantWrapper(Node *n) {
// REPORT("constantWrapper", n);
REPORT("constantWrapper", n);
String *name = Getattr(n, "name");
String *iname = Getattr(n, "sym:name");
String *nsname = Copy(iname);
@ -923,6 +945,20 @@ public:
Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n");
return SWIG_NOWRAP;
}
if (cparse_cplusplus && getCurrentClass()) {
// Additionally add to class constants
Swig_require("luaclassobj_constantWrapper", n, "*sym:name", "luaclassobj:symname", NIL);
Setattr(n, "sym:name", Getattr(n, "luaclassobj:symname"));
String *cls_nsname = Getattr(n, "sym:name");
if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
Replaceall(tm, "$nsname", cls_nsname);
Printf(s_cls_const_tab, " %s,\n", tm);
}
Swig_restore(n);
}
Delete(nsname);
return SWIG_OK;
}
@ -1009,6 +1045,19 @@ public:
Printf(s_methods_tab, "static swig_lua_method swig_");
Printv(s_methods_tab, mangled_classname, "_methods[] = {\n", NIL);
s_cls_methods_tab = NewString("");
Printf(s_cls_methods_tab, "static swig_lua_method swig_");
Printv(s_cls_methods_tab, mangled_classname, "_cls_methods[] = {\n", NIL);
s_cls_attr_tab = NewString("");
Printf(s_cls_attr_tab, "static swig_lua_attribute swig_");
Printv(s_cls_attr_tab, mangled_classname, "_cls_attributes[] = {\n", NIL);
s_cls_const_tab = NewString("");
Printf(s_cls_const_tab, "static swig_lua_const_info swig_");
Printv(s_cls_const_tab, mangled_classname, "_cls_constants[] = {\n", NIL);
// Generate normal wrappers
Language::classHandler(n);
@ -1047,8 +1096,21 @@ public:
Printf(s_attr_tab, " {0,0,0}\n};\n");
Printv(f_wrappers, s_attr_tab, NIL);
Printf(s_cls_attr_tab, " {0,0,0}\n};\n");
Printv(f_wrappers, s_cls_attr_tab, NIL);
Printf(s_cls_methods_tab, " {0,0}\n};\n");
Printv(f_wrappers, s_cls_methods_tab, NIL);
Printf(s_cls_const_tab, " {0,0,0,0,0,0}\n};\n");
Printv(f_wrappers, s_cls_const_tab, NIL);
Delete(s_methods_tab);
Delete(s_attr_tab);
Delete(s_cls_methods_tab);
Delete(s_cls_attr_tab);
Delete(s_cls_const_tab);
// Handle inheritance
// note: with the idea of class hierarchies spread over multiple modules
@ -1122,7 +1184,10 @@ public:
} else {
Printf(f_wrappers, ",0");
}
Printf(f_wrappers, ", swig_%s_methods, swig_%s_attributes, swig_%s_bases, swig_%s_base_names };\n\n", mangled_classname, mangled_classname, mangled_classname, mangled_classname);
Printf(f_wrappers, ", swig_%s_methods, swig_%s_attributes, { \"%s\", swig_%s_cls_methods, swig_%s_cls_attributes, swig_%s_cls_constants }, swig_%s_bases, swig_%s_base_names };\n\n",
mangled_classname, mangled_classname,
class_name, mangled_classname, mangled_classname, mangled_classname,
mangled_classname, mangled_classname);
// Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname, "_bases };\n\n", NIL);
// Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, &_wrap_class_", mangled_classname, "},\n", NIL);
@ -1232,8 +1297,30 @@ public:
* ---------------------------------------------------------------------- */
virtual int staticmemberfunctionHandler(Node *n) {
REPORT("staticmemberfunctionHandler", n);
current = STATIC_FUNC;
return Language::staticmemberfunctionHandler(n);
String *symname = Getattr(n, "sym:name");
int result = Language::staticmemberfunctionHandler(n);
if (cparse_cplusplus && getCurrentClass()) {
Swig_restore(n);
}
current = NO_CPP;
if (result != SWIG_OK)
return result;
if (Getattr(n, "sym:nextSibling"))
return SWIG_OK;
Swig_require("luaclassobj_staticmemberfunctionHandler", n, "luaclassobj:wrap:name", NIL);
String *name = Getattr(n, "name");
String *rname, *realname;
realname = symname ? symname : name;
rname = Getattr(n, "luaclassobj:wrap:name");
Printv(s_cls_methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL);
Swig_restore(n);
return SWIG_OK;
}
/* ------------------------------------------------------------
@ -1243,8 +1330,17 @@ public:
* ------------------------------------------------------------ */
virtual int memberconstantHandler(Node *n) {
// REPORT("memberconstantHandler",n);
return Language::memberconstantHandler(n);
REPORT("memberconstantHandler",n);
String *symname = Getattr(n, "sym:name");
if (cparse_cplusplus && getCurrentClass()) {
Swig_save("luaclassobj_memberconstantHandler", n, "luaclassobj:symname", NIL);
Setattr(n, "luaclassobj:symname", symname);
}
int result = Language::memberconstantHandler(n);
if (cparse_cplusplus && getCurrentClass())
Swig_restore(n);
return result;
}
/* ---------------------------------------------------------------------
@ -1252,9 +1348,22 @@ public:
* --------------------------------------------------------------------- */
virtual int staticmembervariableHandler(Node *n) {
// REPORT("staticmembervariableHandler",n);
REPORT("staticmembervariableHandler",n);
current = STATIC_VAR;
return Language::staticmembervariableHandler(n);
String *symname = Getattr(n, "sym:name");
int result = Language::staticmembervariableHandler(n);
if (result != SWIG_OK)
return result;
if (Getattr(n, "wrappedasconstant"))
return SWIG_OK;
Swig_require("luaclassobj_staticmembervariableHandler", n, "luaclassobj:wrap:get", "luaclassobj:wrap:set", NIL);
Printf(s_cls_attr_tab,"%s{ \"%s\", %s, %s},\n",tab4,symname,Getattr(n,"luaclassobj:wrap:get"), Getattr(n,"luaclassobj:wrap:set"));
Swig_restore(n);
return SWIG_OK;
}
/* ---------------------------------------------------------------------

View file

@ -1503,7 +1503,7 @@ public:
/* if necessary, cast away const since Python doesn't support it! */
if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", pname);
String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,

View file

@ -288,7 +288,7 @@ public:
String *escaped_doc_str = texinfo_escape(doc_str);
if (Len(doc_str)>0) {
Printf(f_doc,"const char* %s_texinfo = ",wrap_name);
Printf(f_doc,"static const char* %s_texinfo = ",wrap_name);
Printf(f_doc,"\"-*- texinfo -*-\\n\\\n%s", escaped_doc_str);
if (Len(decl_info))
Printf(f_doc,"\\n\\\n@end deftypefn");

View file

@ -26,6 +26,7 @@ struct Overloaded {
int argc; /* Argument count */
ParmList *parms; /* Parameters used for overload check */
int error; /* Ambiguity error */
bool implicitconv_function; /* For ordering implicitconv functions*/
};
static int fast_dispatch_mode = 0;
@ -40,6 +41,32 @@ void Wrapper_cast_dispatch_mode_set(int flag) {
cast_dispatch_mode = flag;
}
/* -----------------------------------------------------------------------------
* mark_implicitconv_function()
*
* Mark function if it contains an implicitconv type in the parameter list
* ----------------------------------------------------------------------------- */
static void mark_implicitconv_function(Overloaded& onode) {
Parm *parms = onode.parms;
if (parms) {
bool is_implicitconv_function = false;
Parm *p = parms;
while (p) {
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
continue;
}
if (GetFlag(p, "implicitconv")) {
is_implicitconv_function = true;
break;
}
p = nextSibling(p);
}
if (is_implicitconv_function)
onode.implicitconv_function = true;
}
}
/* -----------------------------------------------------------------------------
* Swig_overload_rank()
*
@ -85,6 +112,9 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
nodes[nnodes].parms = Getattr(c, "wrap:parms");
nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms);
nodes[nnodes].error = 0;
nodes[nnodes].implicitconv_function = false;
mark_implicitconv_function(nodes[nnodes]);
nnodes++;
}
c = Getattr(c, "sym:nextSibling");
@ -287,12 +317,30 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
List *result = NewList();
{
int i;
int argc_changed_index = -1;
for (i = 0; i < nnodes; i++) {
if (nodes[i].error)
Setattr(nodes[i].n, "overload:ignore", "1");
Append(result, nodes[i].n);
// Printf(stdout,"[ %d ] %s\n", i, ParmList_errorstr(nodes[i].parms));
// Swig_print_node(nodes[i].n);
// Printf(stdout,"[ %d ] %d %s\n", i, nodes[i].implicitconv_function, ParmList_errorstr(nodes[i].parms));
// Swig_print_node(nodes[i].n);
if (i == nnodes-1 || nodes[i].argc != nodes[i+1].argc) {
if (argc_changed_index+2 < nnodes && (nodes[argc_changed_index+1].argc == nodes[argc_changed_index+2].argc)) {
// Add additional implicitconv functions in same order as already ranked.
// Consider overloaded functions by argument count... only add additional implicitconv functions if
// the number of functions with the same arg count > 1, ie, only if overloaded by same argument count.
int j;
for (j = argc_changed_index + 1; j <= i; j++) {
if (nodes[j].implicitconv_function) {
SetFlag(nodes[j].n, "implicitconvtypecheckoff");
Append(result, nodes[j].n);
// Printf(stdout,"[ %d ] %d + %s\n", j, nodes[j].implicitconv_function, ParmList_errorstr(nodes[j].parms));
// Swig_print_node(nodes[j].n);
}
}
}
argc_changed_index = i;
}
}
}
return result;
@ -302,20 +350,22 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
// * print_typecheck()
// * ----------------------------------------------------------------------------- */
static bool print_typecheck(String *f, int j, Parm *pj) {
static bool print_typecheck(String *f, int j, Parm *pj, bool implicitconvtypecheckoff) {
char tmp[256];
sprintf(tmp, Char(argv_template_string), j);
String *tm = Getattr(pj, "tmap:typecheck");
if (tm) {
tm = Copy(tm);
Replaceid(tm, Getattr(pj, "lname"), "_v");
String *conv = Getattr(pj, "implicitconv");
if (conv) {
if (conv && !implicitconvtypecheckoff) {
Replaceall(tm, "$implicitconv", conv);
} else {
Replaceall(tm, "$implicitconv", "0");
}
Replaceall(tm, "$input", tmp);
Printv(f, tm, "\n", NIL);
Delete(tm);
return true;
} else
return false;
@ -715,6 +765,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar
for (i = 0; i < nfunc; i++) {
Node *ni = Getitem(dispatch, i);
Parm *pi = Getattr(ni, "wrap:parms");
bool implicitconvtypecheckoff = GetFlag(ni, "implicitconvtypecheckoff") != 0;
int num_required = emit_num_required(pi);
int num_arguments = emit_num_arguments(pi);
if (GetFlag(n, "wrap:this")) {
@ -749,7 +800,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar
Printf(f, "}\n");
Delete(lfmt);
}
if (print_typecheck(f, (GetFlag(n, "wrap:this") ? j + 1 : j), pj)) {
if (print_typecheck(f, (GetFlag(n, "wrap:this") ? j + 1 : j), pj, implicitconvtypecheckoff)) {
Printf(f, "if (_v) {\n");
num_braces++;
}
@ -773,6 +824,8 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar
for ( /* empty */ ; num_braces > 0; num_braces--)
Printf(f, "}\n");
Printf(f, "}\n"); /* braces closes "if" for this method */
if (implicitconvtypecheckoff)
Delattr(ni, "implicitconvtypecheckoff");
}
Delete(dispatch);
return f;

View file

@ -42,6 +42,7 @@ static File *f_directors_h = 0;
static File *f_init = 0;
static File *f_shadow_py = 0;
static String *f_shadow = 0;
static String *f_shadow_begin = 0;
static Hash *f_shadow_imports = 0;
static String *f_shadow_builtin_imports = 0;
static String *f_shadow_stubs = 0;
@ -784,6 +785,7 @@ public:
filen = NULL;
f_shadow = NewString("");
f_shadow_begin = NewString("");
f_shadow_imports = NewHash();
f_shadow_builtin_imports = NewString("");
f_shadow_stubs = NewString("");
@ -977,6 +979,7 @@ public:
if (!modern) {
Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
}
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
Printv(f_shadow_py, "\n", f_shadow_builtin_imports, "\n", NIL);
Printv(f_shadow_py, f_shadow, "\n", NIL);
Printv(f_shadow_py, f_shadow_stubs, "\n", NIL);
@ -3398,7 +3401,7 @@ public:
printSlot(f, getSlot(n, "feature:python:tp_dict"), "tp_dict");
printSlot(f, getSlot(n, "feature:python:tp_descr_get"), "tp_descr_get", "descrgetfunc");
printSlot(f, getSlot(n, "feature:python:tp_descr_set"), "tp_descr_set", "descrsetfunc");
Printf(f, " (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */\n");
Printf(f, " (Py_ssize_t)offsetof(SwigPyObject, dict), /* tp_dictoffset */\n");
printSlot(f, tp_init, "tp_init", "initproc");
printSlot(f, getSlot(n, "feature:python:tp_alloc"), "tp_alloc", "allocfunc");
printSlot(f, "0", "tp_new", "newfunc");
@ -4451,12 +4454,16 @@ public:
String *code = Getattr(n, "code");
String *section = Getattr(n, "section");
if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) {
if (!ImportMode && (Cmp(section, "python") == 0 || Cmp(section, "shadow") == 0)) {
if (shadow) {
String *pycode = pythoncode(code, shadow_indent);
Printv(f_shadow, pycode, NIL);
Delete(pycode);
}
} else if (!ImportMode && (Cmp(section, "pythonbegin") == 0)) {
String *pycode = pythoncode(code, "");
Printv(f_shadow_begin, pycode, NIL);
Delete(pycode);
} else {
Language::insertDirective(n);
}
@ -4724,7 +4731,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
/* if necessary, cast away const since Python doesn't support it! */
if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", pname);
String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,

View file

@ -3201,7 +3201,7 @@ public:
/* if necessary, cast away const since Ruby doesn't support it! */
if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", parameterName);
String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(parameterType, 0), ppname);
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(parameterType, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(parameterType, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,