From 0c0384198a747748ba58c2dda43b0b425b54009b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 11 Sep 2017 23:17:30 +0100 Subject: [PATCH 01/12] Fix testcase symbol name conflict FF1 is also defined in /usr/include/sys/termio.h on cygwin and used by Python.h. --- .../cpp11_ref_qualifiers_typemaps.i | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Examples/test-suite/cpp11_ref_qualifiers_typemaps.i b/Examples/test-suite/cpp11_ref_qualifiers_typemaps.i index e9cce4bfb..0e1c3fe53 100644 --- a/Examples/test-suite/cpp11_ref_qualifiers_typemaps.i +++ b/Examples/test-suite/cpp11_ref_qualifiers_typemaps.i @@ -5,30 +5,30 @@ %} // typemaps to completely ignore the input parm and override it -%typemap(in) short (Funcs::*ff)(bool) const %{ $1 = &Funcs::FF2; %} -%typemap(in) short (Funcs::*cc)(bool) & %{ $1 = &Funcs::CC5; %} -%typemap(in) short (Funcs::*gg)(bool) const & %{ $1 = &Funcs::GG8; %} -%typemap(in) short (Funcs::*hh)(bool) && %{ $1 = &Funcs::HH11; %} +%typemap(in) short (Funcs::*ff)(bool) const %{ $1 = &Funcs::FFF2; %} +%typemap(in) short (Funcs::*cc)(bool) & %{ $1 = &Funcs::CCC5; %} +%typemap(in) short (Funcs::*gg)(bool) const & %{ $1 = &Funcs::GGG8; %} +%typemap(in) short (Funcs::*hh)(bool) && %{ $1 = &Funcs::HHH11; %} -%typemap(in) short (Funcs::*)(bool) const %{ $1 = &Funcs::FF3; %} -%typemap(in) short (Funcs::*)(bool) & %{ $1 = &Funcs::CC6; %} -%typemap(in) short (Funcs::*)(bool) const & %{ $1 = &Funcs::GG9; %} -%typemap(in) short (Funcs::*)(bool) && %{ $1 = &Funcs::HH12; %} +%typemap(in) short (Funcs::*)(bool) const %{ $1 = &Funcs::FFF3; %} +%typemap(in) short (Funcs::*)(bool) & %{ $1 = &Funcs::CCC6; %} +%typemap(in) short (Funcs::*)(bool) const & %{ $1 = &Funcs::GGG9; %} +%typemap(in) short (Funcs::*)(bool) && %{ $1 = &Funcs::HHH12; %} %inline %{ struct Funcs { - short FF1(bool) const { return 1; } - short FF2(bool) const { return 2; } - short FF3(bool) const { return 3; } - short CC4(bool) & { return 4; } - short CC5(bool) & { return 5; } - short CC6(bool) & { return 6; } - short GG7(bool) const & { return 7; } - short GG8(bool) const & { return 8; } - short GG9(bool) const & { return 9; } - short HH10(bool) && { return 10; } - short HH11(bool) && { return 11; } - short HH12(bool) && { return 12; } + short FFF1(bool) const { return 1; } + short FFF2(bool) const { return 2; } + short FFF3(bool) const { return 3; } + short CCC4(bool) & { return 4; } + short CCC5(bool) & { return 5; } + short CCC6(bool) & { return 6; } + short GGG7(bool) const & { return 7; } + short GGG8(bool) const & { return 8; } + short GGG9(bool) const & { return 9; } + short HHH10(bool) && { return 10; } + short HHH11(bool) && { return 11; } + short HHH12(bool) && { return 12; } }; struct TypemapsNamedParms { @@ -68,7 +68,7 @@ struct TypemapsUnnamedParms }; %} -%constant short (Funcs::*FF1_MFP)(bool) const = &Funcs::FF1; -%constant short (Funcs::*CC4_MFP)(bool) & = &Funcs::CC4; -%constant short (Funcs::*GG7_MFP)(bool) const & = &Funcs::GG7; -%constant short (Funcs::*HH10_MFP)(bool) && = &Funcs::HH10; +%constant short (Funcs::*FF1_MFP)(bool) const = &Funcs::FFF1; +%constant short (Funcs::*CC4_MFP)(bool) & = &Funcs::CCC4; +%constant short (Funcs::*GG7_MFP)(bool) const & = &Funcs::GGG7; +%constant short (Funcs::*HH10_MFP)(bool) && = &Funcs::HHH10; From 6077b808f737c1d05df158e31ce50f9189bf9506 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 11 Sep 2017 23:18:55 +0100 Subject: [PATCH 02/12] Remove code duplication of Swig_overload_rank Allegrocl and R versions were also out of date --- Source/Modules/allegrocl.cxx | 279 ----------------------------------- Source/Modules/r.cxx | 256 -------------------------------- 2 files changed, 535 deletions(-) diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index 77f1319c7..f32d34976 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -1685,285 +1685,6 @@ int ALLEGROCL::top(Node *n) { return SWIG_OK; } -/* very shamelessly 'borrowed' from overload.cxx, which - keeps the below Swig_overload_rank() code to itself. - We don't need a dispatch function in the C++ wrapper - code; we want it over on the lisp side. */ - -#define Swig_overload_rank Allegrocl_swig_overload_rank - -#define MAX_OVERLOAD 256 - -/* Overload "argc" and "argv" */ -// String *argv_template_string; -// String *argc_template_string; - -struct Overloaded { - Node *n; /* Node */ - int argc; /* Argument count */ - ParmList *parms; /* Parameters used for overload check */ - int error; /* Ambiguity error */ -}; - -/* ----------------------------------------------------------------------------- - * Swig_overload_rank() - * - * This function takes an overloaded declaration and creates a list that ranks - * all overloaded methods in an order that can be used to generate a dispatch - * function. - * Slight difference in the way this function is used by scripting languages and - * statically typed languages. The script languages call this method via - * Swig_overload_dispatch() - where wrappers for all overloaded methods are generated, - * however sometimes the code can never be executed. The non-scripting languages - * call this method via Swig_overload_check() for each overloaded method in order - * to determine whether or not the method should be wrapped. Note the slight - * difference when overloading methods that differ by const only. The - * scripting languages will ignore the const method, whereas the non-scripting - * languages ignore the first method parsed. - * ----------------------------------------------------------------------------- */ - -static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) { - Overloaded nodes[MAX_OVERLOAD]; - int nnodes = 0; - Node *o = Getattr(n, "sym:overloaded"); - Node *c; - - if (!o) - return 0; - - c = o; - while (c) { - if (Getattr(c, "error")) { - c = Getattr(c, "sym:nextSibling"); - continue; - } - /* if (SmartPointer && Getattr(c,"cplus:staticbase")) { - c = Getattr(c,"sym:nextSibling"); - continue; - } */ - - /* Make a list of all the declarations (methods) that are overloaded with - * this one particular method name */ - if (Getattr(c, "wrap:name")) { - nodes[nnodes].n = c; - nodes[nnodes].parms = Getattr(c, "wrap:parms"); - nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms); - nodes[nnodes].error = 0; - nnodes++; - } - c = Getattr(c, "sym:nextSibling"); - } - - /* Sort the declarations by required argument count */ - { - int i, j; - for (i = 0; i < nnodes; i++) { - for (j = i + 1; j < nnodes; j++) { - if (nodes[i].argc > nodes[j].argc) { - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - } - } - } - } - - /* Sort the declarations by argument types */ - { - int i, j; - for (i = 0; i < nnodes - 1; i++) { - if (nodes[i].argc == nodes[i + 1].argc) { - for (j = i + 1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) { - Parm *p1 = nodes[i].parms; - Parm *p2 = nodes[j].parms; - int differ = 0; - int num_checked = 0; - while (p1 && p2 && (num_checked < nodes[i].argc)) { - // Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type")); - if (checkAttribute(p1, "tmap:in:numinputs", "0")) { - p1 = Getattr(p1, "tmap:in:next"); - continue; - } - if (checkAttribute(p2, "tmap:in:numinputs", "0")) { - p2 = Getattr(p2, "tmap:in:next"); - continue; - } - String *t1 = Getattr(p1, "tmap:typecheck:precedence"); - String *t2 = Getattr(p2, "tmap:typecheck:precedence"); - if ((!t1) && (!nodes[i].error)) { - Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n), - "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n", - Swig_name_decl(nodes[i].n), SwigType_str(Getattr(p1, "type"), 0)); - nodes[i].error = 1; - } else if ((!t2) && (!nodes[j].error)) { - Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n", - Swig_name_decl(nodes[j].n), SwigType_str(Getattr(p2, "type"), 0)); - nodes[j].error = 1; - } - if (t1 && t2) { - int t1v, t2v; - t1v = atoi(Char(t1)); - t2v = atoi(Char(t2)); - differ = t1v - t2v; - } else if (!t1 && t2) - differ = 1; - else if (t1 && !t2) - differ = -1; - else if (!t1 && !t2) - differ = -1; - num_checked++; - if (differ > 0) { - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - break; - } else if ((differ == 0) && (Strcmp(t1, "0") == 0)) { - t1 = Getattr(p1, "ltype"); - if (!t1) { - t1 = SwigType_ltype(Getattr(p1, "type")); - if (Getattr(p1, "tmap:typecheck:SWIGTYPE")) { - SwigType_add_pointer(t1); - } - Setattr(p1, "ltype", t1); - } - t2 = Getattr(p2, "ltype"); - if (!t2) { - t2 = SwigType_ltype(Getattr(p2, "type")); - if (Getattr(p2, "tmap:typecheck:SWIGTYPE")) { - SwigType_add_pointer(t2); - } - Setattr(p2, "ltype", t2); - } - - /* Need subtype check here. If t2 is a subtype of t1, then we need to change the - order */ - - if (SwigType_issubtype(t2, t1)) { - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - } - - if (Strcmp(t1, t2) != 0) { - differ = 1; - break; - } - } else if (differ) { - break; - } - if (Getattr(p1, "tmap:in:next")) { - p1 = Getattr(p1, "tmap:in:next"); - } else { - p1 = nextSibling(p1); - } - if (Getattr(p2, "tmap:in:next")) { - p2 = Getattr(p2, "tmap:in:next"); - } else { - p2 = nextSibling(p2); - } - } - if (!differ) { - /* See if declarations differ by const only */ - String *d1 = Getattr(nodes[i].n, "decl"); - String *d2 = Getattr(nodes[j].n, "decl"); - if (d1 && d2) { - String *dq1 = Copy(d1); - String *dq2 = Copy(d2); - if (SwigType_isconst(d1)) { - Delete(SwigType_pop(dq1)); - } - if (SwigType_isconst(d2)) { - Delete(SwigType_pop(dq2)); - } - if (Strcmp(dq1, dq2) == 0) { - - if (SwigType_isconst(d1) && !SwigType_isconst(d2)) { - if (script_lang_wrapping) { - // Swap nodes so that the const method gets ignored (shadowed by the non-const method) - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - } - differ = 1; - if (!nodes[j].error) { - if (script_lang_wrapping) { - Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n), - "using non-const method %s instead.\n", Swig_name_decl(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) { - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n), - "using %s instead.\n", Swig_name_decl(nodes[i].n)); - } - } - } - nodes[j].error = 1; - } else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) { - differ = 1; - if (!nodes[j].error) { - if (script_lang_wrapping) { - Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n), - "using non-const method %s instead.\n", Swig_name_decl(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) { - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n), - "using %s instead.\n", Swig_name_decl(nodes[i].n)); - } - } - } - nodes[j].error = 1; - } - } - Delete(dq1); - Delete(dq2); - } - } - if (!differ) { - if (!nodes[j].error) { - if (script_lang_wrapping) { - Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s effectively ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[i].n), Getline(nodes[i].n), - "as it is shadowed by %s.\n", Swig_name_decl(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) { - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n), - "using %s instead.\n", Swig_name_decl(nodes[i].n)); - } - } - nodes[j].error = 1; - } - } - } - } - } - } - List *result = NewList(); - { - int i; - 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); - } - } - return result; -} - -/* end shameless borrowing */ - int any_varargs(ParmList *pl) { Parm *p; diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 6a326206f..db94ec934 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -290,8 +290,6 @@ public: int membervariableHandler(Node *n); int typedefHandler(Node *n); - static List *Swig_overload_rank(Node *n, - bool script_lang_wrapping); int memberfunctionHandler(Node *n) { if (debugMode) @@ -1314,260 +1312,6 @@ void R::addAccessor(String *memberName, Wrapper *wrapper, String *name, Printf(stdout, "Adding accessor: %s (%s) => %s\n", memberName, name, tmp); } -#define MAX_OVERLOAD 256 - -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) { - Overloaded nodes[MAX_OVERLOAD]; - int nnodes = 0; - Node *o = Getattr(n,"sym:overloaded"); - - - if (!o) return 0; - - Node *c = o; - while (c) { - if (Getattr(c,"error")) { - c = Getattr(c,"sym:nextSibling"); - continue; - } - /* if (SmartPointer && Getattr(c,"cplus:staticbase")) { - c = Getattr(c,"sym:nextSibling"); - continue; - } */ - - /* Make a list of all the declarations (methods) that are overloaded with - * this one particular method name */ - - if (Getattr(c,"wrap:name")) { - nodes[nnodes].n = c; - nodes[nnodes].parms = Getattr(c,"wrap:parms"); - nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms); - nodes[nnodes].error = 0; - nnodes++; - } - c = Getattr(c,"sym:nextSibling"); - } - - /* Sort the declarations by required argument count */ - { - int i,j; - for (i = 0; i < nnodes; i++) { - for (j = i+1; j < nnodes; j++) { - if (nodes[i].argc > nodes[j].argc) { - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - } - } - } - } - - /* Sort the declarations by argument types */ - { - int i,j; - for (i = 0; i < nnodes-1; i++) { - if (nodes[i].argc == nodes[i+1].argc) { - for (j = i+1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) { - Parm *p1 = nodes[i].parms; - Parm *p2 = nodes[j].parms; - int differ = 0; - int num_checked = 0; - while (p1 && p2 && (num_checked < nodes[i].argc)) { - if (debugMode) { - Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type")); - } - if (checkAttribute(p1,"tmap:in:numinputs","0")) { - p1 = Getattr(p1,"tmap:in:next"); - continue; - } - if (checkAttribute(p2,"tmap:in:numinputs","0")) { - p2 = Getattr(p2,"tmap:in:next"); - continue; - } - String *t1 = Getattr(p1,"tmap:typecheck:precedence"); - String *t2 = Getattr(p2,"tmap:typecheck:precedence"); - if (debugMode) { - Printf(stdout,"t1 = '%s', t2 = '%s'\n", t1, t2); - } - if ((!t1) && (!nodes[i].error)) { - Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n), - "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n", - Swig_name_decl(nodes[i].n), SwigType_str(Getattr(p1, "type"), 0)); - nodes[i].error = 1; - } else if ((!t2) && (!nodes[j].error)) { - Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n", - Swig_name_decl(nodes[j].n), SwigType_str(Getattr(p2, "type"), 0)); - nodes[j].error = 1; - } - if (t1 && t2) { - int t1v, t2v; - t1v = atoi(Char(t1)); - t2v = atoi(Char(t2)); - differ = t1v-t2v; - } - else if (!t1 && t2) differ = 1; - else if (t1 && !t2) differ = -1; - else if (!t1 && !t2) differ = -1; - num_checked++; - if (differ > 0) { - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - break; - } else if ((differ == 0) && (Strcmp(t1,"0") == 0)) { - t1 = Getattr(p1,"ltype"); - if (!t1) { - t1 = SwigType_ltype(Getattr(p1,"type")); - if (Getattr(p1,"tmap:typecheck:SWIGTYPE")) { - SwigType_add_pointer(t1); - } - Setattr(p1,"ltype",t1); - } - t2 = Getattr(p2,"ltype"); - if (!t2) { - t2 = SwigType_ltype(Getattr(p2,"type")); - if (Getattr(p2,"tmap:typecheck:SWIGTYPE")) { - SwigType_add_pointer(t2); - } - Setattr(p2,"ltype",t2); - } - - /* Need subtype check here. If t2 is a subtype of t1, then we need to change the - order */ - - if (SwigType_issubtype(t2,t1)) { - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - } - - if (Strcmp(t1,t2) != 0) { - differ = 1; - break; - } - } else if (differ) { - break; - } - if (Getattr(p1,"tmap:in:next")) { - p1 = Getattr(p1,"tmap:in:next"); - } else { - p1 = nextSibling(p1); - } - if (Getattr(p2,"tmap:in:next")) { - p2 = Getattr(p2,"tmap:in:next"); - } else { - p2 = nextSibling(p2); - } - } - if (!differ) { - /* See if declarations differ by const only */ - String *d1 = Getattr(nodes[i].n, "decl"); - String *d2 = Getattr(nodes[j].n, "decl"); - if (d1 && d2) { - String *dq1 = Copy(d1); - String *dq2 = Copy(d2); - if (SwigType_isconst(d1)) { - Delete(SwigType_pop(dq1)); - } - if (SwigType_isconst(d2)) { - Delete(SwigType_pop(dq2)); - } - if (Strcmp(dq1, dq2) == 0) { - - if (SwigType_isconst(d1) && !SwigType_isconst(d2)) { - if (script_lang_wrapping) { - // Swap nodes so that the const method gets ignored (shadowed by the non-const method) - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - } - differ = 1; - if (!nodes[j].error) { - if (script_lang_wrapping) { - Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n), - "using non-const method %s instead.\n", Swig_name_decl(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) { - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n), - "using %s instead.\n", Swig_name_decl(nodes[i].n)); - } - } - } - nodes[j].error = 1; - } else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) { - differ = 1; - if (!nodes[j].error) { - if (script_lang_wrapping) { - Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[i].n), Getline(nodes[i].n), - "using non-const method %s instead.\n", Swig_name_decl(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) { - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n), - "using %s instead.\n", Swig_name_decl(nodes[i].n)); - } - } - } - nodes[j].error = 1; - } - } - Delete(dq1); - Delete(dq2); - } - } - if (!differ) { - if (!nodes[j].error) { - if (script_lang_wrapping) { - Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s effectively ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[i].n), Getline(nodes[i].n), - "as it is shadowed by %s.\n", Swig_name_decl(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) { - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s ignored,\n", Swig_name_decl(nodes[j].n)); - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[i].n), Getline(nodes[i].n), - "using %s instead.\n", Swig_name_decl(nodes[i].n)); - } - } - nodes[j].error = 1; - } - } - } - } - } - } - List *result = NewList(); - { - int i; - 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); - } - } - return result; -} - void R::dispatchFunction(Node *n) { Wrapper *f = NewWrapper(); String *symname = Getattr(n, "sym:name"); From 065c06159ee51e5babce59b542b75c2467449eef Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 12 Sep 2017 07:48:25 +0100 Subject: [PATCH 03/12] Travis fix for pip install pep8 Fix for recent Travis image cleanup. Issue https://github.com/travis-ci/travis-ci/issues/8378 --- .travis.yml | 1 - Tools/travis-linux-install.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 05681a110..5cf93628e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: cpp -group: deprecated-2017Q3 # workaround for failing: pip install pep8 matrix: include: - compiler: clang diff --git a/Tools/travis-linux-install.sh b/Tools/travis-linux-install.sh index 43bdb77bc..5e93d995f 100755 --- a/Tools/travis-linux-install.sh +++ b/Tools/travis-linux-install.sh @@ -88,7 +88,7 @@ case "$SWIGLANG" in travis_retry sudo apt-get -qq install php$VER-cli php$VER-dev ;; "python") - pip install pep8 + pip install --user pep8 if [[ "$PY3" ]]; then travis_retry sudo apt-get install -qq python3-dev fi From cac396eb56991651eea8613d773590857d4b3357 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 12 Sep 2017 08:32:49 +0100 Subject: [PATCH 04/12] Restore node testing on Travis (for Ubuntu Trusty) --- .travis.yml | 9 +++++---- Tools/travis-linux-install.sh | 5 +---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5cf93628e..a82b2bc47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,10 +49,11 @@ matrix: env: SWIGLANG=java sudo: required dist: trusty -# - compiler: gcc -# os: linux -# env: SWIGLANG=javascript ENGINE=node -# dist: trusty + - compiler: gcc + os: linux + env: SWIGLANG=javascript ENGINE=node + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=javascript ENGINE=jsc diff --git a/Tools/travis-linux-install.sh b/Tools/travis-linux-install.sh index 5e93d995f..4a958dfb8 100755 --- a/Tools/travis-linux-install.sh +++ b/Tools/travis-linux-install.sh @@ -33,10 +33,7 @@ case "$SWIGLANG" in "javascript") case "$ENGINE" in "node") - travis_retry sudo add-apt-repository -y ppa:chris-lea/node.js - travis_retry sudo apt-get -qq update - travis_retry sudo apt-get install -qq nodejs rlwrap - travis_retry sudo npm install -g node-gyp + travis_retry sudo apt-get install -qq nodejs node-gyp ;; "jsc") travis_retry sudo apt-get install -qq libwebkitgtk-dev From b41fdba9ef483969f6641b94a75b14c0f12a5fde Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 12 Sep 2017 08:36:53 +0100 Subject: [PATCH 05/12] Cosmetic changes for Java std::array wrappers --- Lib/java/std_array.i | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/java/std_array.i b/Lib/java/std_array.i index f75857e21..0944d932f 100644 --- a/Lib/java/std_array.i +++ b/Lib/java/std_array.i @@ -8,13 +8,13 @@ namespace std { template class array { public: - typedef T& reference; - typedef const T& const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T value_type; - typedef T* pointer; - typedef const T* const_pointer; + typedef T &reference; + typedef const T &const_reference; + typedef T *pointer; + typedef const T *const_pointer; array(); array(const array& other); size_type size() const; From 8a168795d35c5157474d046cf248118b905cf5ae Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 12 Sep 2017 08:47:10 +0100 Subject: [PATCH 06/12] Cosmetic formatting fixes in generated code for exception handlers --- Source/Modules/emit.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx index 7c2607fc8..813a30924 100644 --- a/Source/Modules/emit.cxx +++ b/Source/Modules/emit.cxx @@ -454,7 +454,7 @@ String *emit_action(Node *n) { if (catchlist) { int unknown_catch = 0; int has_varargs = 0; - Printf(eaction, "}\n"); + Printf(eaction, "} "); for (Parm *ep = catchlist; ep; ep = nextSibling(ep)) { String *em = Swig_typemap_lookup("throws", ep, "_e", 0); if (em) { From 2fee7c96cc86516671c24e5895619922122a11a8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 28 Oct 2016 07:04:33 +0100 Subject: [PATCH 07/12] Remove C casts in PyTypeObject for Python builtin type declarations Choose compile time failures over runtime errors. This change highlighted a problem in the constructor wrappers for tp_init where the kwargs parameter was missing in the generated wrapper function. Leave casts in for 0 initialization. --- Source/Modules/python.cxx | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 9039f07ca..4e9053395 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -177,7 +177,7 @@ static String *getSlot(Node *n = NULL, const char *key = NULL, String *default_s static void printSlot(File *f, String *slotval, const char *slotname, const char *functype = NULL) { String *slotval_override = 0; - if (functype) + if (functype && Strcmp(slotval, "0") == 0) slotval = slotval_override = NewStringf("(%s) %s", functype, slotval); int len = Len(slotval); int fieldwidth = len > 41 ? (len > 61 ? 0 : 61 - len) : 41 - len; @@ -2501,7 +2501,8 @@ public: String *tmp = NewString(""); String *dispatch; - const char *dispatch_code = funpack ? "return %s(self, argc, argv);" : "return %s(self, args);"; + const char *dispatch_code = funpack ? "return %s(self, argc, argv);" : + (builtin_ctor ? "return %s(self, args, NULL);" : "return %s(self, args);"); if (castmode) { dispatch = Swig_overload_dispatch_cast(n, dispatch_code, &maxargs); @@ -2515,7 +2516,8 @@ public: String *symname = Getattr(n, "sym:name"); String *wname = Swig_name_wrapper(symname); - Printv(f->def, linkage, builtin_ctor ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL); + const char *builtin_kwargs = builtin_ctor ? ", PyObject *SWIGUNUSEDPARM(kwargs)" : ""; + Printv(f->def, linkage, builtin_ctor ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL); Wrapper_add_local(f, "argc", "Py_ssize_t argc"); Printf(tmp, "PyObject *argv[%d] = {0}", maxargs + 1); @@ -2729,9 +2731,10 @@ public: Append(wname, overname); } + const char *builtin_kwargs = builtin_ctor ? ", PyObject *SWIGUNUSEDPARM(kwargs)" : ""; if (!allow_kwargs || overname) { if (!varargs) { - Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL); } else { Printv(f->def, linkage, wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL); } @@ -2933,11 +2936,7 @@ public: } Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments); } else { - if (noargs) { - Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); - } else { - Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); - } + Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL); if (onearg && !builtin_ctor) { Printf(parse_args, "if (!args) SWIG_fail;\n"); Append(parse_args, "swig_obj[0] = args;\n"); @@ -3241,7 +3240,7 @@ public: // 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); } else { - Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL); } Wrapper_add_local(f, "resultobj", builtin_ctor ? "int resultobj" : "PyObject *resultobj"); Wrapper_add_local(f, "varargs", "PyObject *varargs"); @@ -3351,7 +3350,7 @@ public: closure_name = Copy(wrapper_name); } if (func_type) { - String *s = NewStringf("(%s) %s", func_type, closure_name); + String *s = NewStringf("%s", closure_name); Delete(closure_name); closure_name = s; } From 169738011c7ee2f12aaf5d5fcbabd18045f5c30b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 14 Sep 2017 07:39:16 +0100 Subject: [PATCH 08/12] Update version number to 4.0 in docs --- Doc/Manual/Sections.html | 4 ++-- Doc/Manual/index.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 739170745..c17f9e84e 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -1,11 +1,11 @@ -SWIG-3.0 Documentation +SWIG-4.0 Documentation -

SWIG-3.0 Documentation

+

SWIG-4.0 Documentation

Last update : SWIG-4.0.0 (in progress) diff --git a/Doc/Manual/index.html b/Doc/Manual/index.html index 26cc81ea1..e720e70d0 100644 --- a/Doc/Manual/index.html +++ b/Doc/Manual/index.html @@ -1,11 +1,11 @@ -SWIG-3.0 Documentation +SWIG-4.0 Documentation -

SWIG-3.0 Documentation

+

SWIG-4.0 Documentation

The SWIG documentation is available in one of the following formats.
    From ff52610dc58bec838d7298a9d9bd45d2770515b5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 14 Sep 2017 07:49:06 +0100 Subject: [PATCH 09/12] Move C++ 'Default arguments' section in manual --- Doc/Manual/Contents.html | 2 +- Doc/Manual/SWIGPlus.html | 228 +++++++++++++++++++-------------------- 2 files changed, 115 insertions(+), 115 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index b879eaa04..e3478ae91 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -228,7 +228,6 @@
  • Static members
  • Member data
-
  • Default arguments
  • Protection
  • Enums and constants
  • Friends @@ -236,6 +235,7 @@
  • Pass and return by value
  • Inheritance
  • A brief discussion of multiple inheritance, pointers, and type checking +
  • Default arguments
  • Wrapping Overloaded Functions and Methods -
  • Default arguments
  • Protection
  • Enums and constants
  • Friends @@ -39,6 +38,7 @@
  • Pass and return by value
  • Inheritance
  • A brief discussion of multiple inheritance, pointers, and type checking +
  • Default arguments
  • Wrapping Overloaded Functions and Methods
    • Dispatch function generation @@ -1104,113 +1104,7 @@ a few problems related to structure wrapping and some of SWIG's customization features.

      -

      6.7 Default arguments

      - - -

      -SWIG will wrap all types of functions that have default arguments. For example member functions: -

      - -
      -
      -class Foo {
      -public:
      -  void bar(int x, int y = 3, int z = 4);
      -};
      -
      -
      - -

      -SWIG handles default arguments by generating an extra overloaded method for each defaulted argument. -SWIG is effectively handling methods with default arguments as if it was wrapping the equivalent overloaded methods. -Thus for the example above, it is as if we had instead given the following to SWIG: -

      - -
      -
      -class Foo {
      -public:
      -  void bar(int x, int y, int z);
      -  void bar(int x, int y);
      -  void bar(int x);
      -};
      -
      -
      - -

      -The wrappers produced are exactly the same as if the above code was instead fed into SWIG. -Details of this are covered later in the Wrapping Overloaded Functions and Methods section. -This approach allows SWIG to wrap all possible default arguments, but can be verbose. -For example if a method has ten default arguments, then eleven wrapper methods are generated. -

      - -

      -Please see the Features and default arguments -section for more information on using %feature with functions with default arguments. -The Ambiguity resolution and renaming section -also deals with using %rename and %ignore on methods with default arguments. -If you are writing your own typemaps for types used in methods with default arguments, you may also need to write a typecheck typemap. -See the Typemaps and overloading section for details or otherwise -use the compactdefaultargs feature flag as mentioned below. -

      - -

      -Compatibility note: Versions of SWIG prior to SWIG-1.3.23 wrapped default arguments slightly differently. -Instead a single wrapper method was generated and the default values were copied into the C++ wrappers -so that the method being wrapped was then called with all the arguments specified. -If the size of the wrappers are a concern then this approach to wrapping methods with default arguments -can be re-activated by using the compactdefaultargs -feature flag. -

      - -
      -
      -%feature("compactdefaultargs") Foo::bar;
      -class Foo {
      -public:
      -  void bar(int x, int y = 3, int z = 4);
      -};
      -
      -
      - - -

      -This is great for reducing the size of the wrappers, but the caveat is it does not work for the statically typed languages, -such as C# and Java, -which don't have optional arguments in the language, -Another restriction of this feature is that it cannot handle default arguments that are not public. -The following example illustrates this: -

      - -
      -
      -class Foo {
      -private:
      -  static const int spam;
      -public:
      -  void bar(int x, int y = spam);   // Won't work with %feature("compactdefaultargs") -
      -                                   // private default value
      -};
      -
      -
      - -

      -This produces uncompilable wrapper code because default values in C++ are -evaluated in the same scope as the member function whereas SWIG -evaluates them in the scope of a wrapper function (meaning that the -values have to be public). -

      - -

      -The compactdefaultargs feature is automatically turned on when wrapping C code with default arguments. -Some target languages will also automatically turn on this feature -if the keyword arguments feature (kwargs) is specified for either C or C++ functions, and the target language supports kwargs, -the compactdefaultargs feature is also automatically turned on. -Keyword arguments are a language feature of some scripting languages, for example Ruby and Python. -SWIG is unable to support kwargs when wrapping overloaded methods, so the default approach cannot be used. -

      - -

      6.8 Protection

      +

      6.7 Protection

      @@ -1230,7 +1124,7 @@ until you explicitly give a `public:' declaration (This is the same convention used by C++).

      -

      6.9 Enums and constants

      +

      6.8 Enums and constants

      @@ -1260,7 +1154,7 @@ Swig_STOUT = Swig::STOUT Members declared as const are wrapped as read-only members and do not create constants.

      -

      6.10 Friends

      +

      6.9 Friends

      @@ -1321,7 +1215,7 @@ namespace bar { and a wrapper for the method 'blah' will not be generated.

      -

      6.11 References and pointers

      +

      6.10 References and pointers

      @@ -1421,7 +1315,7 @@ templates and the STL. This was first added in SWIG-1.3.12.

      -

      6.12 Pass and return by value

      +

      6.11 Pass and return by value

      @@ -1525,7 +1419,7 @@ classes that don't define a default constructor. It is not used for C++ pointers or references.

      -

      6.13 Inheritance

      +

      6.12 Inheritance

      @@ -1711,7 +1605,7 @@ functions for virtual members that are already defined in a base class.

      -

      6.14 A brief discussion of multiple inheritance, pointers, and type checking

      +

      6.13 A brief discussion of multiple inheritance, pointers, and type checking

      @@ -1843,6 +1737,112 @@ int y = B_function((B *) pB); In practice, the pointer is held as an integral number in the target language proxy class.

      +

      6.14 Default arguments

      + + +

      +SWIG will wrap all types of functions that have default arguments. For example member functions: +

      + +
      +
      +class Foo {
      +public:
      +  void bar(int x, int y = 3, int z = 4);
      +};
      +
      +
      + +

      +SWIG handles default arguments by generating an extra overloaded method for each defaulted argument. +SWIG is effectively handling methods with default arguments as if it was wrapping the equivalent overloaded methods. +Thus for the example above, it is as if we had instead given the following to SWIG: +

      + +
      +
      +class Foo {
      +public:
      +  void bar(int x, int y, int z);
      +  void bar(int x, int y);
      +  void bar(int x);
      +};
      +
      +
      + +

      +The wrappers produced are exactly the same as if the above code was instead fed into SWIG. +Details of this are covered later in the Wrapping Overloaded Functions and Methods section. +This approach allows SWIG to wrap all possible default arguments, but can be verbose. +For example if a method has ten default arguments, then eleven wrapper methods are generated. +

      + +

      +Please see the Features and default arguments +section for more information on using %feature with functions with default arguments. +The Ambiguity resolution and renaming section +also deals with using %rename and %ignore on methods with default arguments. +If you are writing your own typemaps for types used in methods with default arguments, you may also need to write a typecheck typemap. +See the Typemaps and overloading section for details or otherwise +use the compactdefaultargs feature flag as mentioned below. +

      + +

      +Compatibility note: Versions of SWIG prior to SWIG-1.3.23 wrapped default arguments slightly differently. +Instead a single wrapper method was generated and the default values were copied into the C++ wrappers +so that the method being wrapped was then called with all the arguments specified. +If the size of the wrappers are a concern then this approach to wrapping methods with default arguments +can be re-activated by using the compactdefaultargs +feature flag. +

      + +
      +
      +%feature("compactdefaultargs") Foo::bar;
      +class Foo {
      +public:
      +  void bar(int x, int y = 3, int z = 4);
      +};
      +
      +
      + + +

      +This is great for reducing the size of the wrappers, but the caveat is it does not work for the statically typed languages, +such as C# and Java, +which don't have optional arguments in the language, +Another restriction of this feature is that it cannot handle default arguments that are not public. +The following example illustrates this: +

      + +
      +
      +class Foo {
      +private:
      +  static const int spam;
      +public:
      +  void bar(int x, int y = spam);   // Won't work with %feature("compactdefaultargs") -
      +                                   // private default value
      +};
      +
      +
      + +

      +This produces uncompilable wrapper code because default values in C++ are +evaluated in the same scope as the member function whereas SWIG +evaluates them in the scope of a wrapper function (meaning that the +values have to be public). +

      + +

      +The compactdefaultargs feature is automatically turned on when wrapping C code with default arguments. +Some target languages will also automatically turn on this feature +if the keyword arguments feature (kwargs) is specified for either C or C++ functions, and the target language supports kwargs, +the compactdefaultargs feature is also automatically turned on. +Keyword arguments are a language feature of some scripting languages, for example Ruby and Python. +SWIG is unable to support kwargs when wrapping overloaded methods, so the default approach cannot be used. +

      +

      6.15 Wrapping Overloaded Functions and Methods

      From d5d97a406927ebf6bd86ce2c4c7723e76fb8252b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 14 Sep 2017 07:58:24 +0100 Subject: [PATCH 10/12] Overloaded methods section renamed slightly in docs --- Doc/Manual/Contents.html | 4 ++-- Doc/Manual/Php.html | 3 +-- Doc/Manual/SWIGPlus.html | 10 +++++----- Doc/Manual/Scilab.html | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index e3478ae91..4211d8ab8 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -236,14 +236,14 @@
    • Inheritance
    • A brief discussion of multiple inheritance, pointers, and type checking
    • Default arguments -
    • Wrapping Overloaded Functions and Methods +
    • Overloaded functions and methods -
    • Wrapping overloaded operators +
    • Overloaded operators
    • Class extension
    • Templates
        diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 9a1178abf..9fbfd75c0 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -390,8 +390,7 @@ Although PHP does not support overloading functions natively, swig will generate dispatch functions which will use %typecheck typemaps to allow overloading. This dispatch function's operation and precedence is described in Wrapping -Overloaded Functions and Methods. +href="SWIGPlus.html#SWIGPlus_overloaded_methods">Overloaded functions and methods.