Merge branch 'master' into gsoc2009-matevz

Conflicts:
	Examples/Makefile.in
	Examples/guile/Makefile.in
	Lib/php/php.swg
	Makefile.in
	Source/CParse/parser.y
	configure.ac
This commit is contained in:
William S Fulton 2013-10-10 07:26:09 +01:00
commit bcb7aee022
585 changed files with 9528 additions and 12959 deletions

View file

@ -630,23 +630,14 @@ public:
*----------------------------------------------------------------------*/
UpcallData *addUpcallMethod(String *imclass_method, String *class_method, String *decl, String *overloaded_name) {
UpcallData *udata;
String *class_methodidx;
Hash *new_udata;
String *key = NewStringf("%s|%s", imclass_method, decl);
++curr_class_dmethod;
/* Do we know about this director class already? */
if ((udata = Getattr(dmethods_table, key))) {
Delete(key);
return Getattr(udata, "methodoff");
}
class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
n_dmethods++;
new_udata = NewHash();
Hash *new_udata = NewHash();
Append(dmethods_seq, new_udata);
Setattr(dmethods_table, key, new_udata);
@ -3391,6 +3382,7 @@ public:
String *qualified_classname = Copy(sym_name);
String *nspace = getNSpace();
String *dirClassName = directorClassName(n);
String *smartptr = Getattr(n, "feature:smartptr");
if (nspace)
Insert(qualified_classname, 0, NewStringf("%s.", nspace));
@ -3401,8 +3393,17 @@ public:
Wrapper *code_wrap = NewWrapper();
Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL %s(void *objarg", wname);
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 = dynamic_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);
}
// TODO: if statement not needed?? - Java too
Printf(code_wrap->code, " if (director) {\n");
Printf(code_wrap->code, " director->swig_connect_director(");
@ -3670,7 +3671,7 @@ public:
Replaceall(pre, "$iminput", ln);
if (Len(pre_code) > 0)
Printf(pre_code, "\n");
Printv(pre_code, pre, NIL);
Printv(pre_code, pre, NIL);
}
String *post = Getattr(p, "tmap:csdirectorin:post");
if (post) {
@ -4027,7 +4028,7 @@ public:
Delete(director_ctor_code);
director_ctor_code = NewString("$director_new");
Java_director_declaration(n);
directorDeclaration(n);
Printf(f_directors_h, "%s {\n", Getattr(n, "director:decl"));
Printf(f_directors_h, "\npublic:\n");
@ -4147,13 +4148,13 @@ public:
}
/*----------------------------------------------------------------------
* Java_director_declaration()
* directorDeclaration()
*
* Generate the director class's declaration
* e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {"
*--------------------------------------------------------------------*/
void Java_director_declaration(Node *n) {
void directorDeclaration(Node *n) {
String *base = Getattr(n, "classtype");
String *class_ctor = NewString("Swig::Director()");

View file

@ -3704,23 +3704,14 @@ private:
UpcallData *addUpcallMethod(String *imclass_method, String *class_method,
String *decl, String *overloaded_name, String *return_type, String *param_list) {
UpcallData *udata;
String *class_methodidx;
Hash *new_udata;
String *key = NewStringf("%s|%s", imclass_method, decl);
++curr_class_dmethod;
/* Do we know about this director class already? */
if ((udata = Getattr(dmethods_table, key))) {
Delete(key);
return Getattr(udata, "methodoff");
}
class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
n_dmethods++;
new_udata = NewHash();
Hash *new_udata = NewHash();
Append(dmethods_seq, new_udata);
Setattr(dmethods_table, key, new_udata);
@ -3752,7 +3743,7 @@ private:
String *nspace = getNSpace();
if (nspace) {
// Check the root package/outermost namespace (a class A in module
// A.B leads to problems if another module A.C is also imported)
// A.B leads to problems if another module A.C is also imported)
if (Len(package) > 0) {
String *dotless_package = NewStringWithSize(package, Len(package) - 1);
if (Cmp(class_name, dotless_package) == 0) {

View file

@ -23,7 +23,6 @@ Guile Options (available with -guile)\n\
-emitslotaccessors - Emit accessor methods for all GOOPS slots\n" "\
-exportprimitive - Add the (export ...) code from scmstub into the\n\
GOOPS file.\n\
-gh - Use the gh_ Guile API. (Guile <= 1.8) \n\
-goopsprefix <prefix> - Prepend <prefix> to all goops identifiers\n\
-linkage <lstyle> - Use linkage protocol <lstyle> (default `simple')\n\
Use `module' for native Guile module linking\n\
@ -44,7 +43,6 @@ Guile Options (available with -guile)\n\
-proxy - Export GOOPS class definitions\n\
-primsuffix <suffix> - Name appended to primitive module when exporting\n\
GOOPS classes. (default = \"primitive\")\n\
-scm - Use the scm Guile API. (Guile >= 1.6, default) \n\
-scmstub - Output Scheme file with module declaration and\n\
exports; only with `passive' and `simple' linkage\n\
-useclassprefix - Prepend the class name to all goops identifiers\n\
@ -94,7 +92,6 @@ static String *return_multi_doc = 0;
static String *exported_symbols = 0;
static int use_scm_interface = 1;
static int exporting_destructor = 0;
static String *swigtype_ptr = 0;
@ -216,10 +213,10 @@ public:
goops = true;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-gh") == 0) {
use_scm_interface = 0;
Printf(stderr, "Deprecated command line option: -gh. Wrappers are always generated for the SCM interface. See documentation for more information regarding the deprecated GH interface.\n");
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-scm") == 0) {
use_scm_interface = 1;
Printf(stderr, "Deprecated command line option: -scm. Wrappers are always generated for the SCM interface. See documentation for more information regarding the deprecated GH interface.\n");
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-primsuffix") == 0) {
if (argv[i + 1]) {
@ -285,10 +282,7 @@ public:
/* Add a symbol for this module */
Preprocessor_define("SWIGGUILE 1", 0);
/* Read in default typemaps */
if (use_scm_interface)
SWIG_config_file("guile_scm.swg");
else
SWIG_config_file("guile_gh.swg");
SWIG_config_file("guile_scm.swg");
allow_overloading();
}
@ -331,13 +325,6 @@ public:
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGGUILE\n");
if (!use_scm_interface) {
if (SwigRuntime == 1)
Printf(f_runtime, "#define SWIG_GLOBAL\n");
if (SwigRuntime == 2)
Printf(f_runtime, "#define SWIG_NOINCLUDE\n");
}
/* Write out directives and declarations */
module = Swig_copy_string(Char(Getattr(n, "name")));
@ -851,7 +838,7 @@ public:
}
}
if (use_scm_interface && exporting_destructor) {
if (exporting_destructor) {
/* Mark the destructor's argument as destroyed. */
String *tm = NewString("SWIG_Guile_MarkPointerDestroyed($input);");
Replaceall(tm, "$input", Getattr(l, "emit:input"));
@ -868,14 +855,8 @@ public:
Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL);
// Now write code to make the function call
if (!use_scm_interface)
Printv(f->code, tab4, "gh_defer_ints();\n", NIL);
String *actioncode = emit_action(n);
if (!use_scm_interface)
Printv(actioncode, tab4, "gh_allow_ints();\n", NIL);
// Now have return value, figure out what to do with it.
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$result", "gswig_result");
@ -958,11 +939,7 @@ public:
Printv(f_wrappers, ");\n", NIL);
Printv(f_wrappers, "}\n", NIL);
/* Register it */
if (use_scm_interface) {
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s_rest);\n", proc_name, wname);
} else {
Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s_rest, 0, 0, 1);\n", proc_name, wname);
}
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s_rest);\n", proc_name, wname);
} else if (emit_setters && struct_member && strlen(Char(proc_name)) > 3) {
int len = Len(proc_name);
const char *pc = Char(proc_name);
@ -973,19 +950,13 @@ public:
struct_member = 2; /* have a setter */
} else
Printf(f_init, "SCM getter = ");
if (use_scm_interface) {
/* GOOPS support uses the MEMBER-set and MEMBER-get functions,
so ignore only_setters in this case. */
if (only_setters && !goops)
Printf(f_init, "scm_c_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
else
Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
} else {
if (only_setters && !goops)
Printf(f_init, "scm_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
else
Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, %d, %d, 0);\n", proc_name, wname, numreq, numargs - numreq);
}
/* GOOPS support uses the MEMBER-set and MEMBER-get functions,
so ignore only_setters in this case. */
if (only_setters && !goops)
Printf(f_init, "scm_c_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
else
Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
if (!is_setter) {
/* Strip off "-get" */
char *pws_name = (char *) malloc(sizeof(char) * (len - 3));
@ -993,19 +964,11 @@ public:
pws_name[len - 4] = 0;
if (struct_member == 2) {
/* There was a setter, so create a procedure with setter */
if (use_scm_interface) {
Printf(f_init, "scm_c_define");
} else {
Printf(f_init, "gh_define");
}
Printf(f_init, "scm_c_define");
Printf(f_init, "(\"%s\", " "scm_make_procedure_with_setter(getter, setter));\n", pws_name);
} else {
/* There was no setter, so make an alias to the getter */
if (use_scm_interface) {
Printf(f_init, "scm_c_define");
} else {
Printf(f_init, "gh_define");
}
Printf(f_init, "scm_c_define");
Printf(f_init, "(\"%s\", getter);\n", pws_name);
}
Printf(exported_symbols, "\"%s\", ", pws_name);
@ -1013,15 +976,11 @@ public:
}
} else {
/* Register the function */
if (use_scm_interface) {
if (exporting_destructor) {
Printf(f_init, "((swig_guile_clientdata *)(SWIGTYPE%s->clientdata))->destroy = (guile_destructor) %s;\n", swigtype_ptr, wname);
//Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) %s);\n", swigtype_ptr, wname);
}
Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
} else {
Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, %d, %d, 0);\n", proc_name, wname, numreq, numargs - numreq);
if (exporting_destructor) {
Printf(f_init, "((swig_guile_clientdata *)(SWIGTYPE%s->clientdata))->destroy = (guile_destructor) %s;\n", swigtype_ptr, wname);
//Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) %s);\n", swigtype_ptr, wname);
}
Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname);
}
} else { /* overloaded function; don't export the single methods */
if (!Getattr(n, "sym:nextSibling")) {
@ -1044,11 +1003,7 @@ public:
Printf(df->code, "#undef FUNC_NAME\n");
Printv(df->code, "}\n", NIL);
Wrapper_print(df, f_wrappers);
if (use_scm_interface) {
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s);\n", proc_name, dname);
} else {
Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, 0, 1);\n", proc_name, dname);
}
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s);\n", proc_name, dname);
DelWrapper(df);
Delete(dispatch);
Delete(dname);
@ -1221,36 +1176,27 @@ public:
/* Read-only variables become a simple procedure returning the
value; read-write variables become a simple procedure with
an optional argument. */
if (use_scm_interface) {
if (!goops && GetFlag(n, "feature:constasvar")) {
/* need to export this function as a variable instead of a procedure */
if (scmstub) {
/* export the function in the wrapper, and (set!) it in scmstub */
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", proc_name, !GetFlag(n, "feature:immutable"), var_name);
Printf(scmtext, "(set! %s (%s))\n", proc_name, proc_name);
} else {
/* export the variable directly */
Printf(f_init, "scm_c_define(\"%s\", %s(SCM_UNDEFINED));\n", proc_name, var_name);
}
} else {
/* Export the function as normal */
if (!goops && GetFlag(n, "feature:constasvar")) {
/* need to export this function as a variable instead of a procedure */
if (scmstub) {
/* export the function in the wrapper, and (set!) it in scmstub */
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", proc_name, !GetFlag(n, "feature:immutable"), var_name);
Printf(scmtext, "(set! %s (%s))\n", proc_name, proc_name);
} else {
/* export the variable directly */
Printf(f_init, "scm_c_define(\"%s\", %s(SCM_UNDEFINED));\n", proc_name, var_name);
}
} else {
Printf(f_init, "\t gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, %d, 0);\n", proc_name, var_name, !GetFlag(n, "feature:immutable"));
/* Export the function as normal */
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", proc_name, !GetFlag(n, "feature:immutable"), var_name);
}
} else {
/* Read/write variables become a procedure with setter. */
if (use_scm_interface) {
Printf(f_init, "{ SCM p = scm_c_define_gsubr(\"%s\", 0, 1, 0, (swig_guile_proc) %s);\n", proc_name, var_name);
Printf(f_init, "scm_c_define");
} else {
Printf(f_init, "\t{ SCM p = gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, 1, 0);\n", proc_name, var_name);
Printf(f_init, "gh_define");
}
Printf(f_init, "{ SCM p = scm_c_define_gsubr(\"%s\", 0, 1, 0, (swig_guile_proc) %s);\n", proc_name, var_name);
Printf(f_init, "scm_c_define");
Printf(f_init, "(\"%s\", " "scm_make_procedure_with_setter(p, p)); }\n", proc_name);
}
Printf(exported_symbols, "\"%s\", ", proc_name);
@ -1484,12 +1430,10 @@ public:
String *mangled_classname = Swig_name_mangle(Getattr(n, "sym:name"));
/* Export clientdata structure */
if (use_scm_interface) {
Printf(f_runtime, "static swig_guile_clientdata _swig_guile_clientdata%s = { NULL, SCM_EOL };\n", mangled_classname);
Printf(f_runtime, "static swig_guile_clientdata _swig_guile_clientdata%s = { NULL, SCM_EOL };\n", mangled_classname);
Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", swigtype_ptr, ", (void *) &_swig_guile_clientdata", mangled_classname, ");\n", NIL);
SwigType_remember(ct);
}
Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", swigtype_ptr, ", (void *) &_swig_guile_clientdata", mangled_classname, ");\n", NIL);
SwigType_remember(ct);
Delete(ct);
/* Emit all of the members */
@ -1725,28 +1669,16 @@ public:
String *runtimeCode() {
String *s;
if (use_scm_interface) {
s = Swig_include_sys("guile_scm_run.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'guile_scm_run.swg");
s = NewString("");
}
} else {
s = Swig_include_sys("guile_gh_run.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'guile_gh_run.swg");
s = NewString("");
}
s = Swig_include_sys("guile_scm_run.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'guile_scm_run.swg");
s = NewString("");
}
return s;
}
String *defaultExternalRuntimeFilename() {
if (use_scm_interface) {
return NewString("swigguilerun.h");
} else {
return NewString("swigguileghrun.h");
}
return NewString("swigguilerun.h");
}
};

View file

@ -138,6 +138,7 @@ public:
imclass_imports(NULL),
module_imports(NULL),
imclass_baseclass(NULL),
imclass_package(NULL),
module_baseclass(NULL),
imclass_interfaces(NULL),
module_interfaces(NULL),
@ -741,25 +742,15 @@ public:
*----------------------------------------------------------------------*/
UpcallData *addUpcallMethod(String *imclass_method, String *class_method, String *imclass_desc, String *class_desc, String *decl) {
UpcallData *udata;
String *imclass_methodidx;
String *class_methodidx;
Hash *new_udata;
String *key = NewStringf("%s|%s", imclass_method, decl);
++curr_class_dmethod;
/* Do we know about this director class already? */
if ((udata = Getattr(dmethods_table, key))) {
Delete(key);
return Getattr(udata, "methodoff");
}
imclass_methodidx = NewStringf("%d", n_dmethods);
class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
String *imclass_methodidx = NewStringf("%d", n_dmethods);
String *class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
n_dmethods++;
new_udata = NewHash();
Hash *new_udata = NewHash();
Append(dmethods_seq, new_udata);
Setattr(dmethods_table, key, new_udata);
@ -3399,7 +3390,7 @@ public:
String *norm_name = SwigType_namestr(Getattr(n, "name"));
String *swig_director_connect = Swig_name_member(getNSpace(), proxy_class_name, "director_connect");
String *swig_director_connect_jni = makeValidJniName(swig_director_connect);
String *smartptr_feature = Getattr(n, "feature:smartptr");
String *smartptr = Getattr(n, "feature:smartptr");
String *dirClassName = directorClassName(n);
Wrapper *code_wrap;
@ -3411,15 +3402,11 @@ public:
"SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, "
"jboolean jweak_global) {\n", jnipackage, jni_imclass_name, swig_director_connect_jni);
if (Len(smartptr_feature)) {
Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", smartptr_feature, smartptr_feature);
if (Len(smartptr)) {
Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", smartptr, smartptr);
Printf(code_wrap->code, " (void)jcls;\n");
Printf(code_wrap->code, " // NOTE: Pulling the raw pointer out of the smart pointer as the following code does\n");
Printf(code_wrap->code, " // is generally a bad idea. However, in this case we keep a local instance of the\n");
Printf(code_wrap->code, " // smart pointer around while we are using the raw pointer, which should keep the\n");
Printf(code_wrap->code, " // raw pointer alive. This is done instead of using the smart pointer's dynamic cast\n");
Printf(code_wrap->code, " // feature since different smart pointer implementations have differently named dynamic\n");
Printf(code_wrap->code, " // cast mechanisms.\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);
}
else {
@ -3527,7 +3514,7 @@ public:
String *pkg_path = Swig_typemap_lookup("javapackage", p, "", 0);
SwigType *type = Getattr(p, "type");
if (pkg_path || Len(pkg_path) == 0)
if (!pkg_path || Len(pkg_path) == 0)
pkg_path = package_path;
String *descriptor_out = Copy(descriptor_in);
@ -4234,7 +4221,7 @@ public:
Delete(director_ctor_code);
director_ctor_code = NewString("$director_new");
Java_director_declaration(n);
directorDeclaration(n);
Printf(f_directors_h, "%s {\n", Getattr(n, "director:decl"));
Printf(f_directors_h, "\npublic:\n");
@ -4418,13 +4405,13 @@ public:
}
/*----------------------------------------------------------------------
* Java_director_declaration()
* directorDeclaration()
*
* Generate the director class's declaration
* e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {"
*--------------------------------------------------------------------*/
void Java_director_declaration(Node *n) {
void directorDeclaration(Node *n) {
String *base = Getattr(n, "classtype");
String *class_ctor = NewString("Swig::Director(jenv)");

View file

@ -88,7 +88,6 @@ extern int AddExtern;
* ---------------------------------------------------------------------- */
int Dispatcher::emit_one(Node *n) {
String *wrn;
int ret = SWIG_OK;
char *tag = Char(nodeType(n));
@ -104,10 +103,9 @@ int Dispatcher::emit_one(Node *n) {
return SWIG_OK;
/* Look for warnings */
wrn = Getattr(n, "feature:warnfilter");
if (wrn) {
String *wrn = Getattr(n, "feature:warnfilter");
if (wrn)
Swig_warnfilter(wrn, 1);
}
/* ============================================================
* C/C++ parsing
@ -183,9 +181,8 @@ int Dispatcher::emit_one(Node *n) {
Swig_error(input_file, line_number, "Unrecognized parse tree node type '%s'\n", tag);
ret = SWIG_ERROR;
}
if (wrn) {
if (wrn)
Swig_warnfilter(wrn, 0);
}
return ret;
}
@ -475,9 +472,9 @@ void swig_pragma(char *lang, char *name, char *value) {
}
/* --------------------------------------------------------------------------
* use_naturalvar_mode()
* Language::use_naturalvar_mode()
* -------------------------------------------------------------------------- */
int use_naturalvar_mode(Node *n) {
int Language::use_naturalvar_mode(Node *n) const {
if (Getattr(n, "unnamed"))
return 0;
int nvar = naturalvar_mode || GetFlag(n, "feature:naturalvar");
@ -486,12 +483,16 @@ int use_naturalvar_mode(Node *n) {
SwigType *ty = Getattr(n, "type");
SwigType *fullty = SwigType_typedef_resolve_all(ty);
if (SwigType_isclass(fullty)) {
Node *m = Copy(n);
SwigType *tys = SwigType_strip_qualifiers(fullty);
Swig_features_get(Swig_cparse_features(), 0, tys, 0, m);
nvar = GetFlag(m, "feature:naturalvar");
if (!CPlusPlus) {
Replaceall(tys, "struct ", "");
Replaceall(tys, "union ", "");
Replaceall(tys, "class ", "");
}
Node *typenode = Swig_symbol_clookup(tys, 0);
if (typenode)
nvar = GetFlag(typenode, "feature:naturalvar");
Delete(tys);
Delete(m);
}
Delete(fullty);
}
@ -1448,6 +1449,7 @@ int Language::membervariableHandler(Node *n) {
tm = Swig_typemap_lookup("memberin", nin, target, 0);
Delete(nin);
}
int flags = Extend | SmartPointer | use_naturalvar_mode(n);
if (isNonVirtualProtectedAccess(n))
flags = flags | CWRAP_ALL_PROTECTED_ACCESS;
@ -1999,6 +2001,9 @@ int Language::classDirectorConstructors(Node *n) {
for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) {
nodeType = Getattr(ni, "nodeType");
if (Cmp(nodeType, "constructor") == 0) {
if (GetFlag(ni, "feature:ignore"))
continue;
Parm *parms = Getattr(ni, "parms");
if (is_public(ni)) {
/* emit public constructor */
@ -2064,6 +2069,10 @@ int Language::classDirectorMethods(Node *n) {
if (GetFlag(method, "feature:nodirector"))
continue;
String *wrn = Getattr(method, "feature:warnfilter");
if (wrn)
Swig_warnfilter(wrn, 1);
String *type = Getattr(method, "nodeType");
if (!Cmp(type, "destructor")) {
classDirectorDestructor(method);
@ -2075,6 +2084,8 @@ int Language::classDirectorMethods(Node *n) {
SetFlag(item, "director");
Swig_restore(method);
}
if (wrn)
Swig_warnfilter(wrn, 0);
}
return SWIG_OK;
@ -2511,7 +2522,7 @@ int Language::classHandler(Node *n) {
Setattr(m, "parentNode", n);
/*
* There is a bug that needs fixing still...
* This area of code is creating methods which have not been overidden in a derived class (director methods that are protected in the base)
* This area of code is creating methods which have not been overridden in a derived class (director methods that are protected in the base)
* If the method is overloaded, then Swig_overload_dispatch() incorrectly generates a call to the base wrapper, _wrap_xxx method
* See director_protected_overloaded.i - Possibly sym:overname needs correcting here.
Printf(stdout, "new method: %s::%s(%s)\n", Getattr(parentNode(m), "name"), Getattr(m, "name"), ParmList_str_defaultargs(Getattr(m, "parms")));
@ -2632,10 +2643,22 @@ int Language::constructorDeclaration(Node *n) {
if (!Equal(actual_name, expected_name) && !(Getattr(n, "template"))) {
bool illegal_name = true;
if (Extend) {
// SWIG extension - allow typedef names as destructor name in %extend - an unnamed struct declared with a typedef can thus be given a 'destructor'.
// Check for typedef names used as a constructor name in %extend. This is deprecated except for anonymous
// typedef structs which have had their symbol names adjusted to the typedef name in the parser.
SwigType *name_resolved = SwigType_typedef_resolve_all(actual_name);
SwigType *expected_name_resolved = SwigType_typedef_resolve_all(expected_name);
if (!CPlusPlus) {
if (Strncmp(name_resolved, "struct ", 7) == 0)
Replace(name_resolved, "struct ", "", DOH_REPLACE_FIRST);
else if (Strncmp(name_resolved, "union ", 6) == 0)
Replace(name_resolved, "union ", "", DOH_REPLACE_FIRST);
}
illegal_name = !Equal(name_resolved, expected_name_resolved);
if (!illegal_name)
Swig_warning(WARN_LANG_EXTEND_CONSTRUCTOR, input_file, line_number, "Use of an illegal constructor name '%s' in %%extend is deprecated, the constructor name should be '%s'.\n",
SwigType_str(Swig_scopename_last(actual_name), 0), SwigType_str(Swig_scopename_last(expected_name), 0));
Delete(name_resolved);
Delete(expected_name_resolved);
}
@ -2771,10 +2794,22 @@ int Language::destructorDeclaration(Node *n) {
if (!Equal(actual_name, expected_name) && !(Getattr(n, "template"))) {
bool illegal_name = true;
if (Extend) {
// SWIG extension - allow typedef names as destructor name in %extend - an unnamed struct declared with a typedef can thus be given a 'destructor'.
// Check for typedef names used as a destructor name in %extend. This is deprecated except for anonymous
// typedef structs which have had their symbol names adjusted to the typedef name in the parser.
SwigType *name_resolved = SwigType_typedef_resolve_all(actual_name);
SwigType *expected_name_resolved = SwigType_typedef_resolve_all(expected_name);
if (!CPlusPlus) {
if (Strncmp(name_resolved, "struct ", 7) == 0)
Replace(name_resolved, "struct ", "", DOH_REPLACE_FIRST);
else if (Strncmp(name_resolved, "union ", 6) == 0)
Replace(name_resolved, "union ", "", DOH_REPLACE_FIRST);
}
illegal_name = !Equal(name_resolved, expected_name_resolved);
if (!illegal_name)
Swig_warning(WARN_LANG_EXTEND_DESTRUCTOR, input_file, line_number, "Use of an illegal destructor name '%s' in %%extend is deprecated, the destructor name should be '%s'.\n",
SwigType_str(Swig_scopename_last(actual_name), 0), SwigType_str(Swig_scopename_last(expected_name), 0));
Delete(name_resolved);
Delete(expected_name_resolved);
}
@ -3065,7 +3100,7 @@ Node *Language::symbolLookup(String *s, const_String_or_char_ptr scope) {
* Tries to locate a class from a type definition
* ----------------------------------------------------------------------------- */
Node *Language::classLookup(const SwigType *s) {
Node *Language::classLookup(const SwigType *s) const {
Node *n = 0;
/* Look in hash of cached values */

View file

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

View file

@ -107,6 +107,7 @@ static const char *usage2 = (const char *) "\
-MM - List dependencies, but omit files in SWIG library\n\
-MMD - Like `-MD', but omit files in SWIG library\n\
-module <name> - Set module name to <name>\n\
-MP - Generate phony targets for all dependencies\n\
-MT <target> - Set the target of the rule emitted by dependency generation\n\
-nocontract - Turn off contract checking\n\
-nocpperraswarn - Do not treat the preprocessor #error statement as #warning\n\
@ -185,6 +186,7 @@ static int dump_classes = 0;
static int werror = 0;
static int depend = 0;
static int depend_only = 0;
static int depend_phony = 0;
static int memory_debug = 0;
static int allkw = 0;
static DOH *cpps = 0;
@ -712,6 +714,9 @@ void SWIG_getoptions(int argc, char *argv[]) {
} else if (strcmp(argv[i], "-MMD") == 0) {
depend = 2;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-MP") == 0) {
depend_phony = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-MT") == 0) {
Swig_mark_arg(i);
if (argv[i + 1]) {
@ -1101,22 +1106,33 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Printf(f_dependencies_file, "%s: ", outfile);
}
List *files = Preprocessor_depend();
List *phony_targets = NewList();
for (int i = 0; i < Len(files); i++) {
int use_file = 1;
if (depend == 2) {
if ((Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) == 0) || (SwigLibWinUnix && (Strncmp(Getitem(files, i), SwigLibWinUnix, Len(SwigLibWinUnix)) == 0)))
use_file = 0;
}
if (use_file)
Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
if (use_file) {
Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
if (depend_phony)
Append(phony_targets, Getitem(files, i));
}
}
Printf(f_dependencies_file, "\n");
if (depend_phony) {
for (int i = 0; i < Len(phony_targets); i++) {
Printf(f_dependencies_file, "\n%s:\n", Getitem(phony_targets, i));
}
}
if (f_dependencies_file != stdout)
Delete(f_dependencies_file);
if (depend_only)
SWIG_exit(EXIT_SUCCESS);
Delete(inputfile_filename);
Delete(basename);
Delete(phony_targets);
} else {
Printf(stderr, "Cannot generate dependencies with -nopreprocess\n");
// Actually we could but it would be inefficient when just generating dependencies, as it would be done after Swig_cparse

View file

@ -204,9 +204,6 @@ private:
String *proxy_class_name;
String *variable_name; //Name of a variable being wrapped
String *variable_type; //Type of this variable
String *enumeration_name; //Name of the current enumeration type
Hash *enumeration_items; //and its members
int enumeration_max;
Hash *enumeration_coll; //Collection of all enumerations.
/* The items are nodes with members:
"items" - hash of with key 'itemname' and content 'itemvalue'
@ -268,9 +265,6 @@ MODULA3():
proxy_class_name(NULL),
variable_name(NULL),
variable_type(NULL),
enumeration_name(NULL),
enumeration_items(NULL),
enumeration_max(0),
enumeration_coll(NULL),
constant_values(NULL),
constantfilename(NULL),
@ -1784,19 +1778,6 @@ MODULA3():
}
}
#if 0
void generateEnumerationItem(const String *name, const String *value, int numvalue) {
String *oldsymname = Getattr(enumeration_items, value);
if (oldsymname != NIL) {
Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "The value <%s> is already assigned to <%s>.\n", value, oldsymname);
}
Setattr(enumeration_items, value, name);
if (enumeration_max < numvalue) {
enumeration_max = numvalue;
}
}
#endif
void emitEnumeration(File *file, String *name, Node *n) {
Printf(file, "%s = {", name);
int i;

View file

@ -1503,7 +1503,7 @@ public:
/* if necessary, cast away const since Python doesn't support it! */
if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", pname);
String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
@ -1583,8 +1583,6 @@ public:
String *cleanup = NewString("");
String *outarg = NewString("");
idx = 0;
tm = Swig_typemap_lookup("directorout", n, "c_result", w);
if (tm != 0) {
Replaceall(tm, "$input", "swig_result");
@ -1742,7 +1740,6 @@ public:
p = NewParm(type, NewString("self"), n);
q = Copy(p);
set_nextSibling(p, parms);
parms = p;
{
Wrapper *w = NewWrapper();

View file

@ -288,7 +288,7 @@ public:
String *escaped_doc_str = texinfo_escape(doc_str);
if (Len(doc_str)>0) {
Printf(f_doc,"const char* %s_texinfo = ",wrap_name);
Printf(f_doc,"static const char* %s_texinfo = ",wrap_name);
Printf(f_doc,"\"-*- texinfo -*-\\n\\\n%s", escaped_doc_str);
if (Len(decl_info))
Printf(f_doc,"\\n\\\n@end deftypefn");
@ -355,14 +355,10 @@ public:
SwigType *type = Getattr(n, "type");
if (type && Strcmp(type, "void")) {
type = SwigType_base(type);
Node *lookup = Swig_symbol_clookup(type, 0);
if (lookup)
type = Getattr(lookup, "sym:name");
Node *nn = classLookup(Getattr(n, "type"));
String *type_str = nn ? Copy(Getattr(nn, "sym:name")) : SwigType_str(type, 0);
Append(decl_info, "@var{retval} = ");
String *type_str = NewString("");
Printf(type_str, "@var{retval} is of type %s. ", type);
Append(args_str, type_str);
Printf(args_str, "%s@var{retval} is of type %s. ", args_str, type_str);
Delete(type_str);
}
@ -524,11 +520,7 @@ public:
}
if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0)
return SwigType_ispointer(t) ? NewString("nil") : NewString("0");
else if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
return NewString("true");
else if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("false");
if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0)
if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
return NewString("true");
if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("false");
@ -752,10 +744,15 @@ public:
Delete(tm);
}
Printf(f->code, "fail:\n"); // we should free locals etc if this happens
Printf(f->code, "return _out;\n");
Printf(f->code, "fail:\n"); // we should free locals etc if this happens
Printv(f->code, cleanup, NIL);
Printf(f->code, "return octave_value_list();\n");
Printf(f->code, "}\n");
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
Replaceall(f->code, "$symname", iname);
Wrapper_print(f, f_wrappers);
DelWrapper(f);
@ -1375,7 +1372,6 @@ public:
outputs++;
// build argument list and type conversion string
idx = 0;
p = l;
while (p) {
if (checkAttribute(p, "tmap:in:numinputs", "0")) {

View file

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

View file

@ -610,7 +610,6 @@ public:
Printf(f->code, "}\n");
/* Write code to extract parameters. */
i = 0;
for (i = 0, p = l; i < num_arguments; i++) {
/* Skip ignored arguments */

View file

@ -787,7 +787,6 @@ public:
}
f = NewWrapper();
numopt = 0;
String *outarg = NewStringEmpty();
String *cleanup = NewStringEmpty();
@ -1738,7 +1737,6 @@ public:
if (!class_node) {
/* This is needed when we're returning a pointer to a type
* rather than returning the type by value or reference. */
class_node = current_class;
Delete(mangled);
mangled = NewString(SwigType_manglestr(ret_type));
class_node = Getattr(zend_types, mangled);
@ -2595,13 +2593,14 @@ done:
}
if (!idx) {
Printf(w->code, "zval **args = NULL;\n", idx);
Printf(w->code, "zval **args = NULL;\n");
} else {
Printf(w->code, "zval *args[%d];\n", idx);
}
Printf(w->code, "zval *%s, funcname;\n", Swig_cresult_name());
Printf(w->code, "MAKE_STD_ZVAL(%s);\n", Swig_cresult_name());
Printf(w->code, "ZVAL_STRING(&funcname, (char *)\"%s\", 0);\n", GetChar(n, "sym:name"));
const char * funcname = GetChar(n, "sym:name");
Printf(w->code, "ZVAL_STRINGL(&funcname, (char *)\"%s\", %d, 0);\n", funcname, strlen(funcname));
Append(w->code, "if (!swig_self) {\n");
Append(w->code, " SWIG_PHP_Error(E_ERROR, \"this pointer is NULL\");");
Append(w->code, "}\n\n");
@ -2609,8 +2608,8 @@ done:
/* wrap complex arguments to zvals */
Printv(w->code, wrap_args, NIL);
Append(w->code, "call_user_function(EG(function_table), (zval**)&swig_self, &funcname,\n");
Printf(w->code, " %s, %d, args TSRMLS_CC);\n", Swig_cresult_name(), idx);
Append(w->code, "call_user_function(EG(function_table), (zval**)&swig_self, &funcname,");
Printf(w->code, " %s, %d, args TSRMLS_CC);\n", Swig_cresult_name(), idx);
if (tm) {
Printv(w->code, Str(tm), "\n", NIL);

View file

@ -42,6 +42,7 @@ static File *f_directors_h = 0;
static File *f_init = 0;
static File *f_shadow_py = 0;
static String *f_shadow = 0;
static String *f_shadow_begin = 0;
static Hash *f_shadow_imports = 0;
static String *f_shadow_builtin_imports = 0;
static String *f_shadow_stubs = 0;
@ -784,6 +785,7 @@ public:
filen = NULL;
f_shadow = NewString("");
f_shadow_begin = NewString("");
f_shadow_imports = NewHash();
f_shadow_builtin_imports = NewString("");
f_shadow_stubs = NewString("");
@ -977,6 +979,7 @@ public:
if (!modern) {
Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
}
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
Printv(f_shadow_py, "\n", f_shadow_builtin_imports, "\n", NIL);
Printv(f_shadow_py, f_shadow, "\n", NIL);
Printv(f_shadow_py, f_shadow_stubs, "\n", NIL);
@ -1556,7 +1559,7 @@ public:
else
return v;
}
if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0)
if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
return NewString("True");
if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("False");
@ -2614,7 +2617,7 @@ public:
Printf(f->code, "}\n");
} else {
Printf(f->code, "newargs = PyTuple_GetSlice(args,0,%d);\n", num_fixed_arguments);
Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", num_fixed_arguments);
Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args));\n", num_fixed_arguments);
}
Printf(f->code, "resultobj = %s__varargs__(%s,newargs,varargs);\n", wname, builtin ? "self" : "NULL");
Append(f->code, "Py_XDECREF(newargs);\n");
@ -3398,7 +3401,7 @@ public:
printSlot(f, getSlot(n, "feature:python:tp_dict"), "tp_dict");
printSlot(f, getSlot(n, "feature:python:tp_descr_get"), "tp_descr_get", "descrgetfunc");
printSlot(f, getSlot(n, "feature:python:tp_descr_set"), "tp_descr_set", "descrsetfunc");
Printf(f, " (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */\n");
Printf(f, " (Py_ssize_t)offsetof(SwigPyObject, dict), /* tp_dictoffset */\n");
printSlot(f, tp_init, "tp_init", "initproc");
printSlot(f, getSlot(n, "feature:python:tp_alloc"), "tp_alloc", "allocfunc");
printSlot(f, "0", "tp_new", "newfunc");
@ -3725,7 +3728,7 @@ public:
if (builtin)
builtin_pre_decl(n);
/* Overide the shadow file so we can capture its methods */
/* Override the shadow file so we can capture its methods */
f_shadow = NewString("");
// Set up type check for director class constructor
@ -4451,12 +4454,16 @@ public:
String *code = Getattr(n, "code");
String *section = Getattr(n, "section");
if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) {
if (!ImportMode && (Cmp(section, "python") == 0 || Cmp(section, "shadow") == 0)) {
if (shadow) {
String *pycode = pythoncode(code, shadow_indent);
Printv(f_shadow, pycode, NIL);
Delete(pycode);
}
} else if (!ImportMode && (Cmp(section, "pythonbegin") == 0)) {
String *pycode = pythoncode(code, "");
Printv(f_shadow_begin, pycode, NIL);
Delete(pycode);
} else {
Language::insertDirective(n);
}
@ -4724,7 +4731,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
/* if necessary, cast away const since Python doesn't support it! */
if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", pname);
String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,

View file

@ -790,11 +790,7 @@ private:
}
if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0)
return SwigType_ispointer(t) ? NewString("nil") : NewString("0");
else if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
return NewString("true");
else if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("false");
if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0)
if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
return NewString("True");
if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("False");
@ -3205,7 +3201,7 @@ public:
/* if necessary, cast away const since Ruby doesn't support it! */
if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", parameterName);
String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(parameterType, 0), ppname);
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(parameterType, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(parameterType, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,

View file

@ -216,7 +216,7 @@ public:
virtual int addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope = ""); /* Add symbol */
virtual void dumpSymbols();
virtual Node *symbolLookup(String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */
virtual Node *classLookup(const SwigType *s); /* Class lookup */
virtual Node *classLookup(const SwigType *s) const; /* Class lookup */
virtual Node *enumLookup(SwigType *s); /* Enum lookup */
virtual int abstractClassTest(Node *n); /* Is class really abstract? */
virtual int is_assignable(Node *n); /* Is variable assignable? */
@ -301,6 +301,9 @@ protected:
This does not include protected virtual methods as they are turned on with the dirprot option. */
bool isNonVirtualProtectedAccess(Node *n) const;
/* Identify if a wrapped global or member variable n should use the naturalvar feature */
int use_naturalvar_mode(Node *n) const;
/* Director subclass comparison test */
String *none_comparison;
@ -381,7 +384,6 @@ int is_protected(Node *n);
int is_member_director(Node *parentnode, Node *member);
int is_member_director(Node *member);
int is_non_virtual_protected_access(Node *n); /* Check if the non-virtual protected members are required (for directors) */
int use_naturalvar_mode(Node *n);
void Wrapper_virtual_elimination_mode_set(int);
void Wrapper_fast_dispatch_mode_set(int);

View file

@ -744,6 +744,7 @@ public:
have_constructor = 0;
have_destructor = 0;
destructor_action = 0;
constructor_name = 0;
if (itcl) {
constructor = NewString("");
@ -1202,7 +1203,8 @@ public:
}
}
constructor_name = NewString(Getattr(n, "sym:name"));
if (!have_constructor)
constructor_name = NewString(Getattr(n, "sym:name"));
have_constructor = 1;
return SWIG_OK;
}