Merge branch 'master' into doxygen

Fix the usual conflicts in autodoc unit test due to fixing the
divergences in autodoc generation between builtin and default cases in
this branch.
This commit is contained in:
Vadim Zeitlin 2017-09-19 13:54:41 +02:00
commit db65ae5aea
371 changed files with 9815 additions and 3191 deletions

View file

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

View file

@ -2207,37 +2207,6 @@ public:
--nesting_depth;
}
/* Output the downcast method, if necessary. Note: There's no other really
good place to put this code, since Abstract Base Classes (ABCs) can and should have
downcasts, making the constructorHandler() a bad place (because ABCs don't get to
have constructors emitted.) */
if (GetFlag(n, "feature:csdowncast")) {
String *downcast_method = Swig_name_member(getNSpace(), proxy_class_name, "SWIGDowncast");
String *wname = Swig_name_wrapper(downcast_method);
String *norm_name = SwigType_namestr(Getattr(n, "name"));
Printf(imclass_class_code, " public final static native %s %s(long cPtrBase, boolean cMemoryOwn);\n", proxy_class_name, downcast_method);
Wrapper *dcast_wrap = NewWrapper();
Printf(dcast_wrap->def, "SWIGEXPORT jobject SWIGSTDCALL %s(JNIEnv *jenv, jclass jcls, jlong jCPtrBase, jboolean cMemoryOwn) {", wname);
Printf(dcast_wrap->code, " Swig::Director *director = (Swig::Director *) 0;\n");
Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n");
Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name);
Printf(dcast_wrap->code, " if (obj) director = dynamic_cast<Swig::Director *>(obj);\n");
Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self(jenv);\n");
Printf(dcast_wrap->code, " return jresult;\n");
Printf(dcast_wrap->code, "}\n");
Wrapper_print(dcast_wrap, f_wrappers);
DelWrapper(dcast_wrap);
Delete(norm_name);
Delete(wname);
Delete(downcast_method);
}
if (f_interface) {
Printv(f_interface, interface_class_code, "}\n", NIL);
addCloseNamespace(nspace, f_interface);
@ -3734,16 +3703,13 @@ public:
Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", smartptr, smartptr);
Printf(code_wrap->code, " // Keep a local instance of the smart pointer around while we are using the raw pointer\n");
Printf(code_wrap->code, " // Avoids using smart pointer specific API.\n");
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName);
}
else {
Printf(code_wrap->code, " %s *director = static_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName);
} else {
Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name);
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName);
Printf(code_wrap->code, " %s *director = static_cast<%s *>(obj);\n", dirClassName, dirClassName);
}
// TODO: if statement not needed?? - Java too
Printf(code_wrap->code, " if (director) {\n");
Printf(code_wrap->code, " director->swig_connect_director(");
Printf(code_wrap->code, " director->swig_connect_director(");
for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) {
UpcallData *udata = Getitem(dmethods_seq, i);
@ -3760,7 +3726,6 @@ public:
Printf(code_wrap->def, ") {\n");
Printf(code_wrap->code, ");\n");
Printf(imclass_class_code, ");\n");
Printf(code_wrap->code, " }\n");
Printf(code_wrap->code, "}\n");
Wrapper_print(code_wrap, f_wrappers);
@ -3826,7 +3791,7 @@ public:
qualified_return = SwigType_rcaststr(returntype, "c_result");
if (!is_void && !ignored_method) {
if (!is_void && (!ignored_method || pure_virtual)) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
@ -3935,7 +3900,11 @@ public:
}
Delete(super_call);
} else {
Printf(w->code, " throw Swig::DirectorPureVirtualException(\"%s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name));
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"%s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name));
if (!is_void)
Printf(w->code, "return %s;", qualified_return);
else if (!ignored_method)
Printf(w->code, "return;\n");
}
if (!ignored_method)
@ -4102,6 +4071,10 @@ public:
Delete(target);
// Add any exception specifications to the methods in the director class
if (Getattr(n, "noexcept")) {
Append(w->def, " noexcept");
Append(declaration, " noexcept");
}
ParmList *throw_parm_list = NULL;
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
int gencomma = 0;
@ -4419,7 +4392,10 @@ public:
String *dirclassname = directorClassName(current_class);
Wrapper *w = NewWrapper();
if (Getattr(n, "throw")) {
if (Getattr(n, "noexcept")) {
Printf(f_directors_h, " virtual ~%s() noexcept;\n", dirclassname);
Printf(w->def, "%s::~%s() noexcept {\n", dirclassname, dirclassname);
} else if (Getattr(n, "throw")) {
Printf(f_directors_h, " virtual ~%s() throw ();\n", dirclassname);
Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname);
} else {

View file

@ -1975,7 +1975,7 @@ public:
qualified_return = SwigType_rcaststr(returntype, "c_result");
if (!is_void && !ignored_method) {
if (!is_void && (!ignored_method || pure_virtual)) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
@ -2077,7 +2077,11 @@ public:
}
Delete(super_call);
} else {
Printf(w->code, " throw Swig::DirectorPureVirtualException(\"%s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name));
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"%s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name));
if (!is_void)
Printf(w->code, "return %s;", qualified_return);
else if (!ignored_method)
Printf(w->code, "return;\n");
}
if (!ignored_method)
@ -2217,6 +2221,10 @@ public:
Delete(target);
// Add any exception specifications to the methods in the director class
if (Getattr(n, "noexcept")) {
Append(w->def, " noexcept");
Append(declaration, " noexcept");
}
ParmList *throw_parm_list = NULL;
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
int gencomma = 0;
@ -2483,7 +2491,10 @@ public:
String *dirclassname = directorClassName(current_class);
Wrapper *w = NewWrapper();
if (Getattr(n, "throw")) {
if (Getattr(n, "noexcept")) {
Printf(f_directors_h, " virtual ~%s() noexcept;\n", dirclassname);
Printf(w->def, "%s::~%s() noexcept {\n", dirclassname, dirclassname);
} else if (Getattr(n, "throw")) {
Printf(f_directors_h, " virtual ~%s() throw ();\n", dirclassname);
Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname);
} else {
@ -3556,10 +3567,9 @@ private:
Printf(code_wrap->def, "SWIGEXPORT void D_%s(void *objarg, void *dobj", connect_name);
Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name);
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName);
Printf(code_wrap->code, " %s *director = static_cast<%s *>(obj);\n", dirClassName, dirClassName);
Printf(code_wrap->code, " if (director) {\n");
Printf(code_wrap->code, " director->swig_connect_director(dobj");
Printf(code_wrap->code, " director->swig_connect_director(dobj");
for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) {
UpcallData *udata = Getitem(dmethods_seq, i);
@ -3573,7 +3583,6 @@ private:
Printf(code_wrap->def, ") {\n");
Printf(code_wrap->code, ");\n");
Printf(im_dmodule_code, ") %s;\n", connect_name);
Printf(code_wrap->code, " }\n");
Printf(code_wrap->code, "}\n");
Wrapper_print(code_wrap, f_wrappers);

View file

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

View file

@ -990,7 +990,7 @@ private:
* overname: The overload string for overloaded function.
* wname: The SWIG wrapped name--the name of the C function.
* base: A list of the names of base classes, in the case where this
* is is a vritual method not defined in the current class.
* is a virtual method not defined in the current class.
* parms: The parameters.
* result: The result type.
* is_static: Whether this is a static method or member.
@ -2806,17 +2806,25 @@ private:
return SWIG_NOWRAP;
}
String *get = NewString("");
Printv(get, Swig_cresult_name(), " = ", NULL);
String *rawval = Getattr(n, "rawval");
if (rawval && Len(rawval)) {
if (SwigType_type(type) == T_STRING) {
Printv(get, "(char *)", NULL);
// Based on Swig_VargetToFunction
String *nname = NewStringf("(%s)", rawval);
String *call;
if (SwigType_isclass(type)) {
call = NewStringf("%s", nname);
} else {
call = SwigType_lcaststr(type, nname);
}
Printv(get, rawval, NULL);
String *cres = Swig_cresult(type, Swig_cresult_name(), call);
Setattr(n, "wrap:action", cres);
Delete(nname);
Delete(call);
Delete(cres);
} else {
String *get = NewString("");
Printv(get, Swig_cresult_name(), " = ", NULL);
char quote;
if (Getattr(n, "wrappedasconstant")) {
quote = '\0';
@ -2838,12 +2846,13 @@ private:
if (quote != '\0') {
Printf(get, "%c", quote);
}
Printv(get, ";\n", NULL);
Setattr(n, "wrap:action", get);
Delete(get);
}
Printv(get, ";\n", NULL);
Setattr(n, "wrap:action", get);
String *sname = Copy(symname);
if (class_name) {
Append(sname, "_");
@ -5049,7 +5058,19 @@ private:
Printv(w->def, " {\n", NULL);
if (SwigType_type(result) != T_VOID) {
Wrapper_add_local(w, "c_result", SwigType_lstr(result, "c_result"));
if (!SwigType_isclass(result)) {
if (!(SwigType_ispointer(result) || SwigType_isreference(result))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(result, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(result, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(result, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(result, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
}
if (!is_ignored) {
@ -5483,6 +5504,8 @@ private:
*--------------------------------------------------------------------*/
String *buildThrow(Node *n) {
if (Getattr(n, "noexcept"))
return NewString("noexcept");
ParmList *throw_parm_list = Getattr(n, "throws");
if (!throw_parm_list && !Getattr(n, "throw"))
return NULL;
@ -6232,9 +6255,9 @@ private:
Setattr(undefined_enum_types, t, ret);
Delete(tt);
}
} else if (SwigType_isfunctionpointer(type) || SwigType_isfunction(type)) {
} else if (SwigType_isfunctionpointer(t) || SwigType_isfunction(t)) {
ret = NewString("_swig_fnptr");
} else if (SwigType_ismemberpointer(type)) {
} else if (SwigType_ismemberpointer(t)) {
ret = NewString("_swig_memberptr");
} else if (SwigType_issimple(t)) {
Node *cn = classLookup(t);

View file

@ -151,12 +151,14 @@ void Swig_interface_propagate_methods(Node *n) {
for (Node *child = firstChild(n); child; child = nextSibling(child)) {
if (Getattr(child, "interface:owner"))
break; // at the end of the list are newly appended methods
if (checkAttribute(child, "name", name)) {
String *decl = SwigType_typedef_resolve_all(Getattr(child, "decl"));
identically_overloaded_method = Strcmp(decl, this_decl_resolved) == 0;
Delete(decl);
if (identically_overloaded_method)
break;
if (Cmp(nodeType(child), "cdecl") == 0) {
if (checkAttribute(child, "name", name)) {
String *decl = SwigType_typedef_resolve_all(Getattr(child, "decl"));
identically_overloaded_method = Strcmp(decl, this_decl_resolved) == 0;
Delete(decl);
if (identically_overloaded_method)
break;
}
}
}
}

View file

@ -2379,39 +2379,6 @@ public:
--nesting_depth;
}
/* Output the downcast method, if necessary. Note: There's no other really
good place to put this code, since Abstract Base Classes (ABCs) can and should have
downcasts, making the constructorHandler() a bad place (because ABCs don't get to
have constructors emitted.) */
if (GetFlag(n, "feature:javadowncast")) {
String *downcast_method = Swig_name_member(getNSpace(), getClassPrefix(), "SWIGDowncast");
String *jniname = makeValidJniName(downcast_method);
String *wname = Swig_name_wrapper(jniname);
String *norm_name = SwigType_namestr(Getattr(n, "name"));
Printf(imclass_class_code, " public final static native %s %s(long cPtrBase, boolean cMemoryOwn);\n", proxy_class_name, downcast_method);
Wrapper *dcast_wrap = NewWrapper();
Printf(dcast_wrap->def, "SWIGEXPORT jobject JNICALL %s(JNIEnv *jenv, jclass jcls, jlong jCPtrBase, jboolean cMemoryOwn) {", wname);
Printf(dcast_wrap->code, " Swig::Director *director = (Swig::Director *) 0;\n");
Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n");
Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name);
Printf(dcast_wrap->code, " if (obj) director = dynamic_cast<Swig::Director *>(obj);\n");
Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self(jenv);\n");
Printf(dcast_wrap->code, " return jresult;\n");
Printf(dcast_wrap->code, "}\n");
Wrapper_print(dcast_wrap, f_wrappers);
DelWrapper(dcast_wrap);
Delete(norm_name);
Delete(wname);
Delete(jniname);
Delete(downcast_method);
}
if (f_interface) {
Printv(f_interface, interface_class_code, "}\n", NIL);
Delete(f_interface);
@ -3895,18 +3862,16 @@ public:
Printf(code_wrap->code, " (void)jcls;\n");
Printf(code_wrap->code, " // Keep a local instance of the smart pointer around while we are using the raw pointer\n");
Printf(code_wrap->code, " // Avoids using smart pointer specific API.\n");
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName);
Printf(code_wrap->code, " %s *director = static_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName);
}
else {
Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name);
Printf(code_wrap->code, " (void)jcls;\n");
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName);
Printf(code_wrap->code, " %s *director = static_cast<%s *>(obj);\n", dirClassName, dirClassName);
}
Printf(code_wrap->code, " if (director) {\n");
Printf(code_wrap->code, " director->swig_connect_director(jenv, jself, jenv->GetObjectClass(jself), "
Printf(code_wrap->code, " director->swig_connect_director(jenv, jself, jenv->GetObjectClass(jself), "
"(jswig_mem_own == JNI_TRUE), (jweak_global == JNI_TRUE));\n");
Printf(code_wrap->code, " }\n");
Printf(code_wrap->code, "}\n");
Wrapper_print(code_wrap, f_wrappers);
@ -3925,12 +3890,20 @@ public:
Printf(code_wrap->def,
"SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jtake_or_release) {\n",
jnipackage, jni_imclass_name, changeown_jnimethod_name);
Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name);
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName);
if (Len(smartptr)) {
Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", smartptr, smartptr);
Printf(code_wrap->code, " // Keep a local instance of the smart pointer around while we are using the raw pointer\n");
Printf(code_wrap->code, " // Avoids using smart pointer specific API.\n");
Printf(code_wrap->code, " %s *director = static_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName);
}
else {
Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name);
Printf(code_wrap->code, " %s *director = static_cast<%s *>(obj);\n", dirClassName, dirClassName);
}
Printf(code_wrap->code, " (void)jcls;\n");
Printf(code_wrap->code, " if (director) {\n");
Printf(code_wrap->code, " director->swig_java_change_ownership(jenv, jself, jtake_or_release ? true : false);\n");
Printf(code_wrap->code, " }\n");
Printf(code_wrap->code, " director->swig_java_change_ownership(jenv, jself, jtake_or_release ? true : false);\n");
Printf(code_wrap->code, "}\n");
Wrapper_print(code_wrap, f_wrappers);
@ -4428,6 +4401,10 @@ public:
}
}
if (Getattr(n, "noexcept")) {
Append(w->def, " noexcept");
Append(declaration, " noexcept");
}
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
int gencomma = 0;
@ -4621,7 +4598,7 @@ public:
Printf(directorexcept, "jthrowable $error = jenv->ExceptionOccurred();\n");
Printf(directorexcept, "if ($error) {\n");
Printf(directorexcept, " jenv->ExceptionClear();$directorthrowshandlers\n");
Printf(directorexcept, " throw Swig::DirectorException(jenv, $error);\n");
Printf(directorexcept, " Swig::DirectorException::raise(jenv, $error);\n");
Printf(directorexcept, "}\n");
} else {
directorexcept = Copy(directorexcept);
@ -4806,7 +4783,10 @@ public:
String *dirClassName = directorClassName(current_class);
Wrapper *w = NewWrapper();
if (Getattr(n, "throw")) {
if (Getattr(n, "noexcept")) {
Printf(f_directors_h, " virtual ~%s() noexcept;\n", dirClassName);
Printf(w->def, "%s::~%s() noexcept {\n", dirClassName, dirClassName);
} else if (Getattr(n, "throw")) {
Printf(f_directors_h, " virtual ~%s() throw ();\n", dirClassName);
Printf(w->def, "%s::~%s() throw () {\n", dirClassName, dirClassName);
} else {

View file

@ -462,10 +462,10 @@ int JAVASCRIPT::fragmentDirective(Node *n) {
// and register them at the emitter.
String *section = Getattr(n, "section");
if (Equal(section, "templates")) {
if (Equal(section, "templates") && !ImportMode) {
emitter->registerTemplate(Getattr(n, "value"), Getattr(n, "code"));
} else {
Swig_fragment_register(n);
return Language::fragmentDirective(n);
}
return SWIG_OK;

View file

@ -81,7 +81,6 @@ extern int AddExtern;
/* import modes */
#define IMPORT_MODE 1
#define IMPORT_MODULE 2
/* ----------------------------------------------------------------------
* Dispatcher::emit_one()
@ -628,7 +627,8 @@ int Language::constantDirective(Node *n) {
* ---------------------------------------------------------------------- */
int Language::fragmentDirective(Node *n) {
Swig_fragment_register(n);
if (!(Getattr(n, "emitonly") && ImportMode))
Swig_fragment_register(n);
return SWIG_OK;
}
@ -1952,7 +1952,7 @@ int Language::unrollVirtualMethods(Node *n, Node *parent, List *vm, int default_
generation of 'empty' director classes.
But this has to be done outside the previous 'for'
an the recursive loop!.
and the recursive loop!.
*/
if (n == parent) {
int len = Len(vm);
@ -2081,7 +2081,7 @@ int Language::classDirectorConstructors(Node *n) {
needed, since there is a public constructor already defined.
(scottm) This code is needed here to make the director_abstract +
test generate compilable code (Example2 in director_abastract.i).
test generate compilable code (Example2 in director_abstract.i).
(mmatus) This is very strange, since swig compiled with gcc3.2.3
doesn't need it here....
@ -3325,7 +3325,7 @@ Node *Language::classLookup(const SwigType *s) {
}
if (n) {
/* Found a match. Look at the prefix. We only allow
the cases where where we want a proxy class for the particular type */
the cases where we want a proxy class for the particular type */
bool acceptable_prefix =
(Len(prefix) == 0) || // simple type (pass by value)
(Strcmp(prefix, "p.") == 0) || // pointer

View file

@ -1755,7 +1755,7 @@ public:
*
* This is to convert the string of Lua code into a proper string, which can then be
* emitted into the C/C++ code.
* Basically is is a lot of search & replacing of odd sequences
* Basically it is a lot of search & replacing of odd sequences
* ---------------------------------------------------------------------------- */
void escapeCode(String *str) {
@ -1770,7 +1770,7 @@ public:
/* -----------------------------------------------------------------------------
* rawGetCArraysHash(String *name)
*
* A small helper to hide impelementation of how CArrays hashes are stored
* A small helper to hide implementation of how CArrays hashes are stored
* ---------------------------------------------------------------------------- */
Hash *rawGetCArraysHash(const_String_or_char_ptr name) {

View file

@ -38,14 +38,15 @@ int NoExcept = 0;
int SwigRuntime = 0; // 0 = no option, 1 = -runtime, 2 = -noruntime
/* Suppress warning messages for private inheritance, preprocessor evaluation etc...
WARN_PP_EVALUATION 202
WARN_PARSE_PRIVATE_INHERIT 309
WARN_TYPE_ABSTRACT 403
WARN_LANG_OVERLOAD_CONST 512
WARN_PARSE_BUILTIN_NAME 321
WARN_PARSE_REDUNDANT 322
WARN_PP_EVALUATION 202
WARN_PARSE_PRIVATE_INHERIT 309
WARN_PARSE_BUILTIN_NAME 321
WARN_PARSE_REDUNDANT 322
WARN_TYPE_ABSTRACT 403
WARN_TYPE_RVALUE_REF_QUALIFIER_IGNORED 405
WARN_LANG_OVERLOAD_CONST 512
*/
#define EXTRA_WARNINGS "202,309,403,512,321,322"
#define EXTRA_WARNINGS "202,309,403,405,512,321,322"
extern "C" {
extern String *ModuleName;

View file

@ -1429,9 +1429,19 @@ public:
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
if (!is_void && (!ignored_method || pure_virtual)) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
}

View file

@ -1321,6 +1321,10 @@ public:
Delete(target);
// Get any exception classes in the throws typemap
if (Getattr(n, "noexcept")) {
Append(w->def, " noexcept");
Append(declaration, " noexcept");
}
ParmList *throw_parm_list = 0;
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
@ -1355,11 +1359,19 @@ public:
// declare method return value
// if the return value is a reference or const reference, a specialized typemap must
// handle it, including declaration of c_result ($result).
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
if (!is_void && (!ignored_method || pure_virtual)) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
}

View file

@ -231,9 +231,21 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
}
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 *decl1 = Getattr(nodes[i].n, "decl");
String *decl2 = Getattr(nodes[j].n, "decl");
if (decl1 && decl2) {
/* Remove ref-qualifiers. Note that rvalue ref-qualifiers are already ignored and
* it is illegal to overload a function with and without ref-qualifiers. So with
* all the combinations of ref-qualifiers and cv-qualifiers, we just detect
* the cv-qualifier (const) overloading. */
String *d1 = Copy(decl1);
String *d2 = Copy(decl2);
if (SwigType_isreference(d1) || SwigType_isrvalue_reference(d1)) {
Delete(SwigType_pop(d1));
}
if (SwigType_isreference(d2) || SwigType_isrvalue_reference(d2)) {
Delete(SwigType_pop(d2));
}
String *dq1 = Copy(d1);
String *dq2 = Copy(d2);
if (SwigType_isconst(d1)) {

View file

@ -2090,6 +2090,10 @@ public:
Delete(target);
// Get any exception classes in the throws typemap
if (Getattr(n, "noexcept")) {
Append(w->def, " noexcept");
Append(declaration, " noexcept");
}
ParmList *throw_parm_list = 0;
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
@ -2126,10 +2130,20 @@ public:
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
if (!ignored_method || pure_virtual) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
}
if (!ignored_method) {
String *pres = NewStringf("SV *%s", Swig_cresult_name());
@ -2486,7 +2500,10 @@ public:
Delete(mangle);
Delete(ptype);
if (Getattr(n, "throw")) {
if (Getattr(n, "noexcept")) {
Printf(f_directors_h, " virtual ~%s() noexcept;\n", DirectorClassName);
Printf(f_directors, "%s::~%s() noexcept {%s}\n\n", DirectorClassName, DirectorClassName, body);
} else if (Getattr(n, "throw")) {
Printf(f_directors_h, " virtual ~%s() throw ();\n", DirectorClassName);
Printf(f_directors, "%s::~%s() throw () {%s}\n\n", DirectorClassName, DirectorClassName, body);
} else {

View file

@ -96,6 +96,7 @@ static String *all_cs_entry;
static String *pragma_incl;
static String *pragma_code;
static String *pragma_phpinfo;
static String *pragma_version;
static String *s_oowrappers;
static String *s_fakeoowrappers;
static String *s_phpclasses;
@ -359,6 +360,7 @@ public:
/* sub-sections of the php file */
pragma_code = NewStringEmpty();
pragma_incl = NewStringEmpty();
pragma_version = NULL;
/* Initialize the rest of the module */
@ -515,7 +517,11 @@ public:
} else {
Printf(s_init, " NULL, /* No MINFO code */\n");
}
Printf(s_init, " NO_VERSION_YET,\n");
if (Len(pragma_version) > 0) {
Printf(s_init, " \"%s\",\n", pragma_version);
} else {
Printf(s_init, " NO_VERSION_YET,\n");
}
Printf(s_init, " STANDARD_MODULE_PROPERTIES\n");
Printf(s_init, "};\n");
Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module);
@ -1835,7 +1841,7 @@ public:
Delete(wrapobj);
}
} else {
if (non_void_return) {
if (non_void_return || hasargout) {
Printf(output, "\t\treturn %s;\n", invoke);
} else if (Cmp(invoke, "$r") != 0) {
Printf(output, "\t\t%s;\n", invoke);
@ -2007,6 +2013,10 @@ done:
if (value) {
Printf(pragma_phpinfo, "%s\n", value);
}
} else if (Strcmp(type, "version") == 0) {
if (value) {
pragma_version = value;
}
} else {
Swig_warning(WARN_PHP_UNKNOWN_PRAGMA, input_file, line_number, "Unrecognized pragma <%s>.\n", type);
}
@ -2530,6 +2540,10 @@ done:
Delete(target);
// Get any exception classes in the throws typemap
if (Getattr(n, "noexcept")) {
Append(w->def, " noexcept");
Append(declaration, " noexcept");
}
ParmList *throw_parm_list = 0;
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
@ -2565,8 +2579,16 @@ done:
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
if (!is_void && (!ignored_method || pure_virtual)) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);

View file

@ -96,6 +96,7 @@ static String *all_cs_entry;
static String *pragma_incl;
static String *pragma_code;
static String *pragma_phpinfo;
static String *pragma_version;
static String *s_oowrappers;
static String *s_fakeoowrappers;
static String *s_phpclasses;
@ -294,7 +295,7 @@ public:
f_runtime = NewStringEmpty();
/* sections of the output file */
s_init = NewString("/* init section */\n");
s_init = NewStringEmpty();
r_init = NewString("/* rinit section */\n");
s_shutdown = NewString("/* shutdown section */\n");
r_shutdown = NewString("/* rshutdown section */\n");
@ -391,6 +392,7 @@ public:
/* sub-sections of the php file */
pragma_code = NewStringEmpty();
pragma_incl = NewStringEmpty();
pragma_version = NULL;
/* Initialize the rest of the module */
@ -528,7 +530,14 @@ public:
Printf(s_entry, "/* Every non-class user visible function must have an entry here */\n");
Printf(s_entry, "static zend_function_entry %s_functions[] = {\n", module);
/* Emit all of the code */
Language::top(n);
SwigPHP_emit_resource_registrations();
/* start the init section */
String * s_init_old = s_init;
s_init = NewString("/* init section */\n");
Append(s_init, "#if ZEND_MODULE_API_NO <= 20090626\n");
Append(s_init, "#undef ZEND_MODULE_BUILD_ID\n");
Append(s_init, "#define ZEND_MODULE_BUILD_ID (char*)\"API\" ZEND_TOSTR(ZEND_MODULE_API_NO) ZEND_BUILD_TS ZEND_BUILD_DEBUG ZEND_BUILD_SYSTEM ZEND_BUILD_EXTRA\n");
@ -542,7 +551,11 @@ public:
Printf(s_init, " PHP_RINIT(%s),\n", module);
Printf(s_init, " PHP_RSHUTDOWN(%s),\n", module);
Printf(s_init, " PHP_MINFO(%s),\n", module);
Printf(s_init, " NO_VERSION_YET,\n");
if (Len(pragma_version) > 0) {
Printf(s_init, " \"%s\",\n", pragma_version);
} else {
Printf(s_init, " NO_VERSION_YET,\n");
}
Printf(s_init, " STANDARD_MODULE_PROPERTIES\n");
Printf(s_init, "};\n");
Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module);
@ -562,11 +575,9 @@ public:
* things are being called in the wrong order
*/
Printf(s_init, "#define SWIG_php_minit PHP_MINIT_FUNCTION(%s)\n", module);
Printv(s_init, s_init_old, NIL);
Delete(s_init_old);
/* Emit all of the code */
Language::top(n);
SwigPHP_emit_resource_registrations();
// Printv(s_init,s_resourcetypes,NIL);
/* We need this after all classes written out by ::top */
Printf(s_oinit, "CG(active_class_entry) = NULL;\n");
@ -1816,7 +1827,7 @@ public:
Delete(wrapobj);
}
} else {
if (non_void_return) {
if (non_void_return || hasargout) {
Printf(output, "\t\treturn %s;\n", invoke);
} else if (Cmp(invoke, "$r") != 0) {
Printf(output, "\t\t%s;\n", invoke);
@ -1988,6 +1999,10 @@ done:
if (value) {
Printf(pragma_phpinfo, "%s\n", value);
}
} else if (Strcmp(type, "version") == 0) {
if (value) {
pragma_version = value;
}
} else {
Swig_warning(WARN_PHP_UNKNOWN_PRAGMA, input_file, line_number, "Unrecognized pragma <%s>.\n", type);
}
@ -2525,6 +2540,10 @@ done:
Delete(target);
// Get any exception classes in the throws typemap
if (Getattr(n, "noexcept")) {
Append(w->def, " noexcept");
Append(declaration, " noexcept");
}
ParmList *throw_parm_list = 0;
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
@ -2562,8 +2581,16 @@ done:
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
if (!is_void && (!ignored_method || pure_virtual)) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);

View file

@ -183,7 +183,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;
@ -1946,6 +1946,7 @@ public:
String *new_value = convertValue(value, Getattr(p, "type"));
if (new_value)
Printf(doc, "=%s", new_value);
Delete(new_value);
}
Delete(type_str);
Delete(made_name);
@ -2031,9 +2032,9 @@ public:
Delete(rname);
} else {
if (CPlusPlus) {
Printf(doc, "Proxy of C++ %s class.", real_classname);
Printf(doc, "Proxy of C++ %s class.", SwigType_namestr(real_classname));
} else {
Printf(doc, "Proxy of C %s struct.", real_classname);
Printf(doc, "Proxy of C %s struct.", SwigType_namestr(real_classname));
}
}
}
@ -2044,7 +2045,7 @@ public:
String *paramList = make_autodocParmList(n, showTypes);
Printf(doc, "__init__(");
if (showTypes)
Printf(doc, "%s ", getClassName());
Printf(doc, "%s ", class_name);
if (Len(paramList))
Printf(doc, "self, %s) -> %s", paramList, class_name);
else
@ -2055,7 +2056,7 @@ public:
case AUTODOC_DTOR:
if (showTypes)
Printf(doc, "__del__(%s self)", getClassName());
Printf(doc, "__del__(%s self)", class_name);
else
Printf(doc, "__del__(self)");
break;
@ -2109,6 +2110,70 @@ public:
return doc;
}
/* ------------------------------------------------------------
* convertIntegerValue()
*
* Check if string v is an integer and can be represented in
* Python. If so, return an appropriate Python representation,
* otherwise (or if we are unsure), return NIL.
* ------------------------------------------------------------ */
String *convertIntegerValue(String *v, SwigType *resolved_type) {
const char *const s = Char(v);
char *end;
String *result = NIL;
// Check if this is an integer number in any base.
long value = strtol(s, &end, 0);
if (errno == ERANGE || end == s)
return NIL;
if (*end != '\0') {
// If there is a suffix after the number, we can safely ignore "l"
// and (provided the number is unsigned) "u", and also combinations of
// these, but not anything else.
for (char *p = end; *p != '\0'; ++p) {
switch (*p) {
case 'l':
case 'L':
break;
case 'u':
case 'U':
if (value < 0)
return NIL;
break;
default:
return NIL;
}
}
}
// So now we are certain that we are indeed dealing with an integer
// that has a representation as long given by value.
if (Cmp(resolved_type, "bool") == 0)
// Allow integers as the default value for a bool parameter.
return NewString(value ? "True" : "False");
if (value == 0)
return NewString(SwigType_ispointer(resolved_type) ? "None" : "0");
// v may still be octal or hexadecimal:
const char *p = s;
if (*p == '+' || *p == '-')
++p;
if (*p == '0' && *(p+1) != 'x' && *(p+1) != 'X') {
// This must have been an octal number. This is the only case we
// cannot use in Python directly, since Python 2 and 3 use non-
// compatible representations.
result = NewString(*s == '-' ? "int('-" : "int('");
String *octal_string = NewStringWithSize(p, (int) (end - p));
Append(result, octal_string);
Append(result, "', 8)");
Delete(octal_string);
return result;
}
result = *end == '\0' ? Copy(v) : NewStringWithSize(s, (int) (end - s));
return result;
}
/* ------------------------------------------------------------
* convertDoubleValue()
*
@ -2147,7 +2212,7 @@ public:
// Avoid unnecessary string allocation in the common case when we don't
// need to remove any suffix.
return *end == '\0' ? v : NewStringWithSize(s, (int)(end - s));
return *end == '\0' ? Copy(v) : NewStringWithSize(s, (int)(end - s));
}
return NIL;
@ -2157,109 +2222,24 @@ public:
* convertValue()
*
* Check if string v can be a Python value literal or a
* constant. Return NIL if it isn't.
* constant. Return an equivalent Python representation,
* or NIL if it isn't, or we are unsure.
* ------------------------------------------------------------ */
String *convertValue(String *v, SwigType *type) {
const char *const s = Char(v);
char *end;
String *result = NIL;
bool fail = false;
SwigType *resolved_type = 0;
SwigType *resolved_type = SwigType_typedef_resolve_all(type);
// Check if this is a number in any base.
long value = strtol(s, &end, 0);
(void) value;
if (end != s) {
if (errno == ERANGE) {
// There was an overflow, we could try representing the value as Python
// long integer literal, but for now don't bother with it.
fail = true;
} else {
if (*end != '\0') {
// If there is a suffix after the number, we can safely ignore any
// combination of "l" and "u", but not anything else (again, stuff like
// "LL" could be handled, but we don't bother to do it currently).
bool seen_long = false;
for (char * p = end; *p != '\0'; ++p) {
switch (*p) {
case 'l':
case 'L':
// Bail out on "LL".
if (seen_long) {
fail = true;
break;
}
seen_long = true;
break;
case 'u':
case 'U':
break;
default:
// Except that our suffix could actually be the fractional part of
// a floating point number, so we still have to check for this.
result = convertDoubleValue(v);
}
}
}
if (!fail) {
// Allow integers as the default value for a bool parameter.
resolved_type = SwigType_typedef_resolve_all(type);
if (Cmp(resolved_type, "bool") == 0) {
result = NewString(value ? "True" : "False");
} else {
// Deal with the values starting with 0 first as they can be octal or
// hexadecimal numbers or even pointers.
if (s[0] == '0') {
if (Len(v) == 1) {
// This is just a lone 0, but it needs to be represented differently
// in Python depending on whether it's a zero or a null pointer.
if (SwigType_ispointer(resolved_type))
result = NewString("None");
else
result = v;
} else if (s[1] == 'x' || s[1] == 'X') {
// This must have been a hex number, we can use it directly in Python,
// so nothing to do here.
} else {
// This must have been an octal number, we have to change its prefix
// to be "0o" in Python 3 only (and as long as we still support Python
// 2.5, this can't be done unconditionally).
if (py3) {
if (end - s > 1) {
result = NewString("0o");
Append(result, NewStringWithSize(s + 1, (int)(end - s - 1)));
}
}
}
}
// Avoid unnecessary string allocation in the common case when we don't
// need to remove any suffix.
if (!result)
result = *end == '\0' ? v : NewStringWithSize(s, (int)(end - s));
}
}
}
}
// Check if this is a floating point number (notice that it wasn't
// necessarily parsed as a long above, consider e.g. ".123").
if (!fail && !result) {
result = convertIntegerValue(v, resolved_type);
if (!result) {
result = convertDoubleValue(v);
if (!result) {
if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
if (Strcmp(v, "true") == 0)
result = NewString("True");
else if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
else if (Strcmp(v, "false") == 0)
result = NewString("False");
else if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0) {
if (!resolved_type)
resolved_type = SwigType_typedef_resolve_all(type);
else if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0)
result = SwigType_ispointer(resolved_type) ? NewString("None") : NewString("0");
}
// This could also be an enum type, default value of which could be
// representable in Python if it doesn't include any scope (which could,
// but currently is not, translated).
@ -2267,7 +2247,7 @@ public:
Node *lookup = Swig_symbol_clookup(v, 0);
if (lookup) {
if (Cmp(Getattr(lookup, "nodeType"), "enumitem") == 0)
result = Getattr(lookup, "sym:name");
result = Copy(Getattr(lookup, "sym:name"));
}
}
}
@ -2314,10 +2294,12 @@ public:
if (Getattr(p, "tmap:default"))
return false;
if (String *value = Getattr(p, "value")) {
String *type = Getattr(p, "type");
if (!convertValue(value, type))
String *value = Getattr(p, "value");
if (value) {
String *convertedValue = convertValue(value, Getattr(p, "type"));
if (!convertedValue)
return false;
Delete(convertedValue);
}
}
@ -2598,7 +2580,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);
@ -2612,7 +2595,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);
@ -2620,9 +2604,14 @@ public:
if (!fastunpack) {
Wrapper_add_local(f, "ii", "Py_ssize_t ii");
if (maxargs - (add_self ? 1 : 0) > 0)
Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
Append(f->code, "argc = args ? PyObject_Length(args) : 0;\n");
if (maxargs - (add_self ? 1 : 0) > 0) {
Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
Append(f->code, "argc = PyObject_Length(args);\n");
} else {
Append(f->code, "argc = args ? PyObject_Length(args) : 0;\n");
}
if (add_self)
Append(f->code, "argv[0] = self;\n");
Printf(f->code, "for (ii = 0; (ii < %d) && (ii < argc); ii++) {\n", add_self ? maxargs - 1 : maxargs);
@ -2645,8 +2634,8 @@ public:
if (GetFlag(n, "feature:python:maybecall")) {
Append(f->code, "fail:\n");
Append(f->code, "Py_INCREF(Py_NotImplemented);\n");
Append(f->code, "return Py_NotImplemented;\n");
Append(f->code, " Py_INCREF(Py_NotImplemented);\n");
Append(f->code, " return Py_NotImplemented;\n");
} else {
Node *sibl = n;
while (Getattr(sibl, "sym:previousSibling"))
@ -2658,7 +2647,7 @@ public:
Delete(fulldecl);
} while ((sibl = Getattr(sibl, "sym:nextSibling")));
Append(f->code, "fail:\n");
Printf(f->code, "SWIG_SetErrorMsg(PyExc_NotImplementedError,"
Printf(f->code, " SWIG_SetErrorMsg(PyExc_NotImplementedError,"
"\"Wrong number or type of arguments for overloaded function '%s'.\\n\"" "\n\" Possible C/C++ prototypes are:\\n\"%s);\n", symname, protoTypes);
Printf(f->code, "return %s;\n", builtin_ctor ? "-1" : "0");
Delete(protoTypes);
@ -2821,9 +2810,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);
}
@ -3019,17 +3009,13 @@ public:
Clear(f->def);
if (overname) {
if (noargs) {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
} else {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
}
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");
@ -3283,10 +3269,17 @@ public:
if (need_cleanup) {
Printv(f->code, cleanup, NIL);
}
if (builtin_ctor)
if (builtin_ctor) {
Printv(f->code, " return -1;\n", NIL);
else
Printv(f->code, " return NULL;\n", NIL);
} else {
if (GetFlag(n, "feature:python:maybecall")) {
Append(f->code, " PyErr_Clear();\n");
Append(f->code, " Py_INCREF(Py_NotImplemented);\n");
Append(f->code, " return Py_NotImplemented;\n");
} else {
Printv(f->code, " return NULL;\n", NIL);
}
}
if (funpack) {
@ -3323,9 +3316,10 @@ public:
DelWrapper(f);
f = NewWrapper();
if (funpack) {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL);
// 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");
@ -3435,7 +3429,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;
}
@ -5119,7 +5113,7 @@ public:
Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL);
if (!have_pythonprepend(n) && !have_pythonappend(n)) {
if (proxydel) {
Printv(f_shadow, tab4, "__del__ = lambda self: None\n", NIL);
Printv(f_shadow, tab4, "def __del__(self):\n", tab8, "return None\n", NIL);
}
return SWIG_OK;
}
@ -5454,8 +5448,11 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Delete(target);
// Get any exception classes in the throws typemap
if (Getattr(n, "noexcept")) {
Append(w->def, " noexcept");
Append(declaration, " noexcept");
}
ParmList *throw_parm_list = 0;
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
Parm *p;
int gencomma = 0;
@ -5489,8 +5486,16 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
if (!is_void && (!ignored_method || pure_virtual)) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);

View file

@ -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)
@ -573,7 +571,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
String *lname;
if (!arg && Cmp(Getattr(p, "type"), "void")) {
lname = NewStringf("s_arg%d", i+1);
lname = NewStringf("arg%d", i+1);
Setattr(p, "name", lname);
} else
lname = arg;
@ -616,19 +614,25 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
for(i = 0; p; i++) {
SwigType *tt = Getattr(p, "type");
SwigType *name = Getattr(p, "name");
SwigType *swig_parm_name = NewStringf("swigarg_%s", name);
String *tm = Getattr(p, "tmap:out");
Printf(f->def, "%s %s", SwigType_str(tt, 0), name);
if(tm) {
Replaceall(tm, "$1", name);
if (SwigType_isreference(tt)) {
String *tmp = NewString("");
Append(tmp, "*");
Append(tmp, name);
Replaceall(tm, tmp, name);
bool isVoidParm = Strcmp(tt, "void") == 0;
if (isVoidParm)
Printf(f->def, "%s", SwigType_str(tt, 0));
else
Printf(f->def, "%s %s", SwigType_str(tt, 0), swig_parm_name);
if (tm) {
String *lstr = SwigType_lstr(tt, 0);
if (SwigType_isreference(tt) || SwigType_isrvalue_reference(tt)) {
Printf(f->code, "%s = (%s) &%s;\n", Getattr(p, "lname"), lstr, swig_parm_name);
} else if (!isVoidParm) {
Printf(f->code, "%s = (%s) %s;\n", Getattr(p, "lname"), lstr, swig_parm_name);
}
Replaceall(tm, "$1", name);
Replaceall(tm, "$result", "r_tmp");
replaceRClass(tm, Getattr(p,"type"));
Replaceall(tm,"$owner", "R_SWIG_EXTERNAL");
Delete(lstr);
}
Printf(setExprElements, "%s\n", tm);
@ -697,10 +701,13 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
Printv(f->code, "R_SWIG_popCallbackFunctionData(1);\n", NIL);
Printv(f->code, "\n", UnProtectWrapupCode, NIL);
if (SwigType_isreference(rettype)) {
if (SwigType_isreference(rettype)) {
Printv(f->code, "return *", Swig_cresult_name(), ";\n", NIL);
} else if(!isVoidType)
} else if (SwigType_isrvalue_reference(rettype)) {
Printv(f->code, "return std::move(*", Swig_cresult_name(), ");\n", NIL);
} else if (!isVoidType) {
Printv(f->code, "return ", Swig_cresult_name(), ";\n", NIL);
}
Printv(f->code, "\n}\n", NIL);
Replaceall(f->code, "SWIG_exception_fail", "SWIG_exception_noreturn");
@ -709,7 +716,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
function that handles the scoerceout.
We need to check if any of the argument types have an entry in
that map. If none do, the ignore and call the function straight.
Otherwise, generate the a marshalling function.
Otherwise, generate a marshalling function.
Need to be able to find it in S. Or use an entirely generic one
that evaluates the expressions.
Handle errors in the evaluation of the function by restoring
@ -1305,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");

View file

@ -3112,6 +3112,10 @@ public:
Delete(target);
// Get any exception classes in the throws typemap
if (Getattr(n, "noexcept")) {
Append(w->def, " noexcept");
Append(declaration, " noexcept");
}
ParmList *throw_parm_list = 0;
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
@ -3150,9 +3154,19 @@ public:
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
if (!is_void && (!ignored_method || pure_virtual)) {
if (!SwigType_isclass(returntype)) {
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
Delete(construct_result);
} else {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
}

View file

@ -18,13 +18,14 @@ static const int SCILAB_VARIABLE_NAME_CHAR_MAX = SCILAB_IDENTIFIER_NAME_CHAR_MAX
static const char *usage = (char *) " \
Scilab options (available with -scilab)\n \
-builder - Generate a Scilab builder script\n \
-buildercflags <cflags> - Add <cflags> to the builder compiler flags\n \
-builderflagscript <file> - Set the Scilab script <file> to use by builder to configure the build flags\n \
-builderldflags <ldflags> - Add <ldflags> to the builder linker flags\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 \
-builder - Generate a Scilab builder script\n \
-buildercflags <cflags> - Add <cflags> to the builder compiler flags\n \
-builderflagscript <file> - Set the Scilab script <file> to use by builder to configure the build flags\n \
-builderldflags <ldflags> - Add <ldflags> to the builder linker flags\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";
@ -39,6 +40,8 @@ protected:
String *variablesCode;
int targetVersion;
bool generateBuilder;
File *builderFile;
String *builderCode;
@ -71,6 +74,7 @@ public:
* ----------------------------------------------------------------------*/
virtual void main(int argc, char *argv[]) {
targetVersion = 5;
generateBuilder = false;
sourceFileList = NewList();
@ -95,48 +99,54 @@ 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) {
Swig_mark_arg(argIndex);
if (argv[argIndex + 1] != NULL) {
Insert(cflags, Len(cflags), argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
}
} else if (strcmp(argv[argIndex], "-builderldflags") == 0) {
Swig_mark_arg(argIndex);
if (argv[argIndex + 1] != NULL) {
Insert(ldflags, Len(ldflags), argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
}
} else if (strcmp(argv[argIndex], "-builderverbositylevel") == 0) {
Swig_mark_arg(argIndex);
verboseBuildLevel = NewString(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
} else if (strcmp(argv[argIndex], "-builderflagscript") == 0) {
Swig_mark_arg(argIndex);
buildFlagsScript = NewString(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
} else if (strcmp(argv[argIndex], "-gatewayxml") == 0) {
Swig_mark_arg(argIndex);
createGatewayXML = true;
gatewayID = NewString(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
}
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]);
Swig_mark_arg(argIndex + 1);
}
} else if (strcmp(argv[argIndex], "-builderldflags") == 0) {
Swig_mark_arg(argIndex);
if (argv[argIndex + 1] != NULL) {
Insert(ldflags, Len(ldflags), argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
}
} else if (strcmp(argv[argIndex], "-builderverbositylevel") == 0) {
Swig_mark_arg(argIndex);
verboseBuildLevel = NewString(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
} else if (strcmp(argv[argIndex], "-builderflagscript") == 0) {
Swig_mark_arg(argIndex);
buildFlagsScript = NewString(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
} else if (strcmp(argv[argIndex], "-gatewayxml") == 0) {
Swig_mark_arg(argIndex);
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);
}
}
}
}
@ -784,57 +794,61 @@ public:
/* -----------------------------------------------------------------------
* checkIdentifierName()
* Truncates (and displays a warning) for too long identifier names
* (applies on functions, variables, constants...)
* (Scilab identifiers names are limited to 24 chars max)
* 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 (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
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;
return scilabIdentifierName;
} else {
scilabIdentifierName = DohNewString(name);
}
return scilabIdentifierName;
}
/* -----------------------------------------------------------------------
* checkMemberIdentifierName()
* Truncates (and displays a warning) too long member identifier names
* (applies on members of structs, classes...)
* (Scilab identifiers names are limited to 24 chars max)
* 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);
String *memberName = Getattr(node, "sym:name");
if (lenContainerName + lenMemberName + 1 > char_size_max) {
int lenScilabMemberName = char_size_max - lenContainerName - 1;
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);
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()
* ----------------------------------------------------------------------- */
@ -1013,8 +1027,14 @@ public:
Printf(gatewayHeader, "\n");
gatewayHeaderV6 = NewString("");
Printf(gatewayHeaderV6, "#ifdef __cplusplus\n");
Printf(gatewayHeaderV6, "extern \"C\" {\n");
Printf(gatewayHeaderV6, "#endif\n");
Printf(gatewayHeaderV6, "#include \"c_gateway_prototype.h\"\n");
Printf(gatewayHeaderV6, "#include \"addfunction.h\"\n");
Printf(gatewayHeaderV6, "#ifdef __cplusplus\n");
Printf(gatewayHeaderV6, "}\n");
Printf(gatewayHeaderV6, "#endif\n");
Printf(gatewayHeaderV6, "\n");
Printf(gatewayHeaderV6, "#define MODULE_NAME L\"%s\"\n", gatewayLibraryName);
Printf(gatewayHeaderV6, "#ifdef __cplusplus\n");

View file

@ -187,8 +187,10 @@ class TypePass:private Dispatcher {
ilist = alist = NewList();
Append(ilist, bcls);
} else {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname));
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname));
if (!GetFlag(bcls, "feature:ignore")) {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname));
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname));
}
}
}
break;
@ -209,8 +211,10 @@ class TypePass:private Dispatcher {
ilist = alist = NewList();
Append(ilist, bcls);
} else {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname));
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname));
if (!GetFlag(bcls, "feature:ignore")) {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname));
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname));
}
}
} else {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' undefined.\n", SwigType_namestr(bname));
@ -1199,10 +1203,7 @@ class TypePass:private Dispatcher {
} else if (Strcmp(ntype, "enum") == 0) {
SwigType_typedef_using(Getattr(n, "uname"));
} else if (Strcmp(ntype, "template") == 0) {
/*
Printf(stdout, "usingDeclaration template %s --- %s\n", Getattr(n, "name"), Getattr(n, "uname"));
SwigType_typedef_using(Getattr(n, "uname"));
*/
}
}
}

View file

@ -59,7 +59,7 @@ int is_non_virtual_protected_access(Node *n) {
// When vtable is empty, the director class does not get emitted, so a check for an empty vtable should be done.
// However, vtable is set in Language and so is not yet set when methods in Typepass call clean_overloaded()
// which calls is_non_virtual_protected_access. So commented out below.
// Moving the director vtable creation into into Typepass should solve this problem.
// Moving the director vtable creation into Typepass should solve this problem.
if (is_member_director_helper(parentNode, n) /* && Getattr(parentNode, "vtable")*/)
result = 1;
}