Merge branch 'master' into C

This commit is contained in:
Vadim Zeitlin 2016-04-08 15:35:32 +02:00
commit 7c402ad148
2760 changed files with 114689 additions and 39303 deletions

View file

@ -11,8 +11,6 @@
* ALLEGROCL language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_allegrocl_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>
@ -22,7 +20,7 @@ char cvsroot_allegrocl_cxx[] = "$Id$";
// #define ALLEGROCL_TYPE_DEBUG
// #define ALLEGROCL_CLASS_DEBUG
static const char *usage = (char *) "\
static const char *usage = "\
Allegro CL Options (available with -allegrocl)\n\
-identifier-converter <type or funcname> - \n\
Specifies the type of conversion to do on C identifiers to convert\n\
@ -48,7 +46,7 @@ static File *f_cxx_wrapper = 0;
static String *module_name = 0;
static String *swig_package = 0;
const char *identifier_converter = "identifier-convert-null";
static String *identifier_converter = NewString("identifier-convert-null");
static bool CWrap = true; // generate wrapper file for C code by default. most correct.
static bool Generate_Wrapper = false;
@ -162,51 +160,12 @@ String *namespaced_name(Node *n, String *ns = current_namespace) {
// "Namespace::Nested::Class2::Baz" -> "Baz"
static String *strip_namespaces(String *str) {
SwigType *new_type = Copy(str);
SwigType *leading_type = SwigType_pop(new_type);
char *result = Char(leading_type);
if(SwigType_istemplate(leading_type)) {
result = Char(SwigType_templateprefix(leading_type));
} else {
if (!SwigType_issimple(leading_type))
return NewString(str);
}
String *stripped_one;
while ((stripped_one = Strstr(result, "::")))
result = Char(stripped_one) + 2;
if(SwigType_istemplate(leading_type)) {
SwigType_push(new_type, NewStringf("%s%s%s", result, SwigType_templateargs(leading_type),
SwigType_templatesuffix(leading_type)));
return new_type;
}
return NewString(result);
}
static String *namespace_of(String *str) {
char *p = Char(str);
char *start = Char(str);
char *result = 0;
String *stripped_one;
while ((stripped_one = Strstr(p, "::"))) {
p = Char(stripped_one) + 2;
}
if (p > start) {
int len = p - start - 1;
result = (char *) malloc(len);
strncpy(result, start, len - 1);
result[len - 1] = 0;
}
return Char(result);
return Swig_scopename_last(str);
}
void add_linked_type(Node *n) {
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "Adding linked node of type: %s(%s) %s(%x)\n\n", nodeType(n), Getattr(n, "storage"), Getattr(n, "name"), n);
Printf(stderr, "Adding linked node of type: %s(%s) %s(%p)\n\n", nodeType(n), Getattr(n, "storage"), Getattr(n, "name"), n);
// Swig_print_node(n);
#endif
if (!first_linked_type) {
@ -300,13 +259,13 @@ Node *get_primary_synonym_of(Node *n) {
Node *p = Getattr(n, "allegrocl:synonym-of");
Node *prim = n;
// Printf(stderr, "getting primary synonym of %x\n", n);
// Printf(stderr, "getting primary synonym of %p\n", n);
while (p) {
// Printf(stderr, " found one! %x\n", p);
// Printf(stderr, " found one! %p\n", p);
prim = p;
p = Getattr(p, "allegrocl:synonym-of");
}
// Printf(stderr,"get_primary_syn: DONE. returning %s(%x)\n", Getattr(prim,"name"),prim);
// Printf(stderr,"get_primary_syn: DONE. returning %s(%p)\n", Getattr(prim,"name"),prim);
return prim;
}
@ -331,7 +290,7 @@ void add_forward_referenced_type(Node *n, int overwrite = 0) {
// , name);
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "Linking forward reference type = %s(%x)\n", k, n);
Printf(stderr, "Linking forward reference type = %s(%p)\n", k, n);
#endif
add_linked_type(n);
}
@ -346,8 +305,8 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
String *cDeclName = n ? Getattr(n, "name") : 0;
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "IN A-D-F-T. (n=%x, ow=%d, k=%s, name=%s, ns=%s\n", n, overwrite, k, name, ns);
Printf(stderr, " templated = '%x', classDecl = '%x'\n", templated, cDeclName);
Printf(stderr, "IN A-D-F-T. (n=%p, ow=%d, k=%s, name=%s, ns=%s\n", n, overwrite, k, name, ns);
Printf(stderr, " templated = '%p', classDecl = '%p'\n", templated, cDeclName);
#endif
if (n) {
if (!name)
@ -456,11 +415,12 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
}
}
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "looking to add %s/%s(%x) to linked_type_list...\n", k, name, n);
Printf(stderr, "looking to add %s/%s(%p) to linked_type_list...\n", k, name, n);
#endif
if (is_fwd_ref) {
// Printf(stderr,"*** 1\n");
add_linked_type(n);
if (n)
add_linked_type(n);
} else {
// Printf(stderr,"*** 1-a\n");
if (SwigType_istemplate(k)) {
@ -509,7 +469,7 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
Setattr(new_node, "allegrocl:synonym:is-primary", "1");
} else {
// a synonym type was found (held in variable 'match')
// Printf(stderr, "setting primary synonym of %x to %x\n", new_node, match);
// Printf(stderr, "setting primary synonym of %p to %p\n", new_node, match);
if (new_node == match)
Printf(stderr, "Hey-4 * - '%s' is a synonym of iteself!\n", Getattr(new_node, "name"));
Setattr(new_node, "allegrocl:synonym-of", match);
@ -556,8 +516,8 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
Setattr(n, "allegrocl:synonym-of", match);
Setattr(n, "real-name", Copy(lookup_type));
// Printf(stderr, "*** pre-5: found match of '%s'(%x)\n", Getattr(match,"name"),match);
// if(n == match) Printf(stderr, "Hey-5 *** setting synonym of %x to %x\n", n, match);
// Printf(stderr, "*** pre-5: found match of '%s'(%p)\n", Getattr(match,"name"),match);
// if(n == match) Printf(stderr, "Hey-5 *** setting synonym of %p to %p\n", n, match);
// Printf(stderr,"*** 5\n");
add_linked_type(n);
} else {
@ -615,7 +575,7 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
match = find_linked_type_by_name(resolved);
if (!match) {
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "found no implicit instantiation of %%template node %s(%x)\n", Getattr(n, "name"), n);
Printf(stderr, "found no implicit instantiation of %%template node %s(%p)\n", Getattr(n, "name"), n);
#endif
add_linked_type(n);
} else {
@ -624,14 +584,14 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
Setattr(n, "allegrocl:synonym:is-primary", "1");
Delattr(primary, "allegrocl:synonym:is-primary");
if (n == match)
Printf(stderr, "Hey-7 * setting synonym of %x to %x\n (match = %x)", primary, n, match);
Printf(stderr, "Hey-7 * setting synonym of %p to %p\n (match = %p)", primary, n, match);
Setattr(primary, "allegrocl:synonym-of", n);
// Printf(stderr,"*** 7\n");
add_linked_type(n);
}
} else {
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "linking type '%s'(%x)\n", k, n);
Printf(stderr, "linking type '%s'(%p)\n", k, n);
#endif
// Printf(stderr,"*** 8\n");
add_linked_type(n);
@ -663,7 +623,7 @@ void note_implicit_template_instantiation(SwigType *t) {
#endif
SwigType *type = Copy(t);
SwigType *tok = SwigType_pop(type);
String *implicit_ns = SwigType_istemplate(tok) ? namespace_of(SwigType_templateprefix(tok)) : 0;
String *implicit_ns = SwigType_istemplate(tok) ? Swig_scopename_prefix(SwigType_templateprefix(tok)) : 0;
add_defined_foreign_type(0, 0, t, t, implicit_ns ? implicit_ns : current_namespace);
Delete(type);
@ -821,7 +781,7 @@ String *compose_foreign_type(Node *n, SwigType *ty, String * /*id*/ = 0) {
Printf(stderr, "compose_foreign_type: ENTER (%s)...\n ", ty);
// Printf(stderr, "compose_foreign_type: ENTER (%s)(%s)...\n ", ty, (id ? id : 0));
/* String *id_ref = SwigType_str(ty, id);
Printf(stderr, "looking up typemap for %s, found '%s'(%x)\n",
Printf(stderr, "looking up typemap for %s, found '%s'(%p)\n",
id_ref, lookup_res ? Getattr(lookup_res, "code") : 0, lookup_res);
if (lookup_res) Swig_print_node(lookup_res);
*/
@ -860,7 +820,7 @@ void update_package_if_needed(Node *n, File *f = f_clwrap) {
Printf(stderr, "update_package: ENTER... \n");
Printf(stderr, " current_package = '%s'\n", current_package);
Printf(stderr, " node_package = '%s'\n", Getattr(n, "allegrocl:package"));
Printf(stderr, " node(%x) = '%s'\n", n, Getattr(n, "name"));
Printf(stderr, " node(%p) = '%s'\n", n, Getattr(n, "name"));
#endif
String *node_package = Getattr(n, "allegrocl:package");
if (Strcmp(current_package, node_package)) {
@ -1119,7 +1079,7 @@ String *convert_literal(String *literal, String *type, bool try_to_split) {
void emit_stub_class(Node *n) {
#ifdef ALLEGROCL_WRAP_DEBUG
Printf(stderr, "emit_stub_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n);
Printf(stderr, "emit_stub_class: ENTER... '%s'(%p)\n", Getattr(n, "sym:name"), n);
Swig_print_node(n);
#endif
@ -1157,7 +1117,7 @@ void emit_synonym(Node *synonym) {
Printf(stderr, "emit_synonym: ENTER... \n");
#endif
// Printf(stderr,"in emit_synonym for %s(%x)\n", Getattr(synonym,"name"),synonym);
// Printf(stderr,"in emit_synonym for %s(%p)\n", Getattr(synonym,"name"),synonym);
int is_tempInst = !Strcmp(nodeType(synonym), "templateInst");
String *synonym_type;
@ -1181,13 +1141,14 @@ void emit_synonym(Node *synonym) {
String *of_name = namespaced_name(of, of_ns);
if (CPlusPlus && !Strcmp(nodeType(synonym), "cdecl")) {
syn_ltype = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)",
strip_namespaces(Getattr(synonym, "real-name")), synonym_ns);
syn_type = NewStringf("#.(swig-insert-id \"%s\" %s :type :type)",
strip_namespaces(Getattr(synonym, "real-name")), synonym_ns);
String *real_name = Getattr(synonym, "real-name");
if (!real_name)
real_name = NewString("Unknown"); // TODO: fix
syn_ltype = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", strip_namespaces(real_name), synonym_ns);
syn_type = NewStringf("#.(swig-insert-id \"%s\" %s :type :type)", strip_namespaces(real_name), synonym_ns);
} else {
syn_ltype = lookup_defined_foreign_ltype(synonym_type);
syn_type = lookup_defined_foreign_type(synonym_type);
syn_ltype = lookup_defined_foreign_ltype(synonym_type);
syn_type = lookup_defined_foreign_type(synonym_type);
}
of_ltype = lookup_defined_foreign_ltype(of_name);
@ -1214,7 +1175,7 @@ void emit_full_class(Node *n) {
String *name = Getattr(n, "sym:name");
String *kind = Getattr(n, "kind");
// Printf(stderr,"in emit_full_class: '%s'(%x).", Getattr(n,"name"),n);
// Printf(stderr,"in emit_full_class: '%s'(%p).", Getattr(n,"name"),n);
if (Getattr(n, "allegrocl:synonym-of")) {
// Printf(stderr,"but it's a synonym of something.\n");
update_package_if_needed(n, f_clhead);
@ -1262,7 +1223,7 @@ void emit_full_class(Node *n) {
// hack. why would decl have a value of "variableHandler" and now "0"?
String *childDecl = Getattr(c, "decl");
// Printf(stderr,"childDecl = '%s' (%s)\n", childDecl, Getattr(c,"view"));
if (!Strcmp(childDecl, "0"))
if (!childDecl || !Strcmp(childDecl, "0"))
childDecl = NewString("");
SwigType *childType;
@ -1314,7 +1275,7 @@ void emit_full_class(Node *n) {
void emit_class(Node *n) {
#ifdef ALLEGROCL_WRAP_DEBUG
Printf(stderr, "emit_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n);
Printf(stderr, "emit_class: ENTER... '%s'(%p)\n", Getattr(n, "sym:name"), n);
#endif
int is_tempInst = !Strcmp(nodeType(n), "templateInst");
@ -1373,7 +1334,7 @@ void emit_typedef(Node *n) {
Delete(type);
Node *in_class = Getattr(n, "allegrocl:typedef:in-class");
// Printf(stderr,"in emit_typedef: '%s'(%x).",Getattr(n,"name"),n);
// Printf(stderr,"in emit_typedef: '%s'(%p).",Getattr(n,"name"),n);
if (Getattr(n, "allegrocl:synonym-of")) {
// Printf(stderr," but it's a synonym of something.\n");
emit_synonym(n);
@ -1536,11 +1497,11 @@ void dump_linked_types(File *f) {
Node *n = first_linked_type;
int i = 0;
while (n) {
Printf(f, "%d: (%x) node '%s' name '%s'\n", i++, n, nodeType(n), Getattr(n, "sym:name"));
Printf(f, "%d: (%p) node '%s' name '%s'\n", i++, n, nodeType(n), Getattr(n, "sym:name"));
Node *t = Getattr(n, "allegrocl:synonym-of");
if (t)
Printf(f, " synonym-of %s(%x)\n", Getattr(t, "name"), t);
Printf(f, " synonym-of %s(%p)\n", Getattr(t, "name"), t);
n = Getattr(n, "allegrocl:next_linked_type");
}
}
@ -1556,7 +1517,7 @@ void emit_linked_types() {
while (n) {
String *node_type = nodeType(n);
// Printf(stderr,"emitting node %s(%x) of type %s.", Getattr(n,"name"),n, nodeType(n));
// Printf(stderr,"emitting node %s(%p) of type %s.", Getattr(n,"name"),n, nodeType(n));
if (!Strcmp(node_type, "class") || !Strcmp(node_type, "templateInst")) {
// may need to emit a stub, so it will update the package itself.
// Printf(stderr," Passing to emit_class.");
@ -1604,14 +1565,15 @@ void ALLEGROCL::main(int argc, char *argv[]) {
/* check for built-ins */
if (!strcmp(conv, "lispify")) {
identifier_converter = "identifier-convert-lispify";
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-lispify");
} else if (!strcmp(conv, "null")) {
identifier_converter = "identifier-convert-null";
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-null");
} else {
/* Must be user defined */
char *idconv = new char[strlen(conv) + 1];
strcpy(idconv, conv);
identifier_converter = idconv;
Delete(identifier_converter);
identifier_converter = NewString(conv);
}
} else if (!strcmp(argv[i], "-cwrap")) {
CWrap = true;
@ -1653,7 +1615,6 @@ int ALLEGROCL::top(Node *n) {
if (Generate_Wrapper) {
f_begin = NewFile(cxx_filename, "w", SWIG_output_files());
if (!f_begin) {
Close(f_cl);
Delete(f_cl);
Printf(stderr, "Unable to open %s for writing\n", cxx_filename);
SWIG_exit(EXIT_FAILURE);
@ -1674,9 +1635,7 @@ int ALLEGROCL::top(Node *n) {
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGALLEGROCL\n");
Printf(f_runtime, "\n");
Printf(f_runtime, "\n\n#ifndef SWIGALLEGROCL\n#define SWIGALLEGROCL\n#endif\n\n");
Swig_banner_target_lang(f_cl, ";;");
@ -1710,15 +1669,13 @@ int ALLEGROCL::top(Node *n) {
Printf(f_cl, "%s\n", f_clhead);
Printf(f_cl, "%s\n", f_clwrap);
Close(f_cl);
Delete(f_cl); // Delete the handle, not the file
Delete(f_cl);
Delete(f_clhead);
Delete(f_clwrap);
Dump(f_runtime, f_begin);
Printf(f_begin, "%s\n", f_cxx_wrapper);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
Delete(f_cxx_wrapper);
@ -1835,12 +1792,12 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
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 (no type checking rule for '%s').\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 (no type checking rule for '%s').\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;
}
@ -2049,7 +2006,7 @@ int emit_num_lin_arguments(ParmList *parms) {
int nargs = 0;
while (p) {
// Printf(stderr,"enla: '%s' lin='%x' numinputs='%s'\n", Getattr(p,"name"), Getattr(p,"tmap:lin"), Getattr(p,"tmap:lin:numinputs"));
// Printf(stderr,"enla: '%s' lin='%p' numinputs='%s'\n", Getattr(p,"name"), Getattr(p,"tmap:lin"), Getattr(p,"tmap:lin:numinputs"));
if (Getattr(p, "tmap:lin")) {
nargs += GetInt(p, "tmap:lin:numinputs");
p = Getattr(p, "tmap:lin:next");
@ -2283,7 +2240,7 @@ IDargs *id_converter_arguments(Node *n) {
result->arity = NewStringf("%d",
// emit_num_arguments(Getattr(n, "wrap:parms")));
emit_num_lin_arguments(Getattr(n, "wrap:parms")));
// Printf(stderr, "got arity of '%s' node '%s' '%x'\n", result->arity, Getattr(n,"name"), Getattr(n,"wrap:parms"));
// Printf(stderr, "got arity of '%s' node '%s' '%p'\n", result->arity, Getattr(n,"name"), Getattr(n,"wrap:parms"));
}
SetVoid(n, "allegrocl:id-converter-args", result);
@ -2361,7 +2318,7 @@ int ALLEGROCL::emit_dispatch_defun(Node *n) {
#endif
List *overloads = Swig_overload_rank(n, true);
// Printf(stderr,"\ndispatch node=%x\n\n", n);
// Printf(stderr,"\ndispatch node=%p\n\n", n);
// Swig_print_node(n);
Node *overloaded_from = Getattr(n,"sym:overloaded");
@ -2669,7 +2626,7 @@ int ALLEGROCL::functionWrapper(Node *n) {
if (Getattr(n, "overload:ignore")) {
// if we're the last overload, make sure to force the emit
// of the rest of the overloads before we leave.
// Printf(stderr, "ignored overload %s(%x)\n", name, Getattr(n, "sym:nextSibling"));
// Printf(stderr, "ignored overload %s(%p)\n", name, Getattr(n, "sym:nextSibling"));
if (!Getattr(n, "sym:nextSibling")) {
update_package_if_needed(n);
emit_buffered_defuns(n);
@ -2749,7 +2706,7 @@ int ALLEGROCL::functionWrapper(Node *n) {
String *actioncode = emit_action(n);
String *tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode);
if (!is_void_return && tm) {
if (!is_void_return) {
if (tm) {
Replaceall(tm, "$result", "lresult");
Printf(f->code, "%s\n", tm);
@ -2798,7 +2755,7 @@ int ALLEGROCL::functionWrapper(Node *n) {
int ALLEGROCL::namespaceDeclaration(Node *n) {
#ifdef ALLEGROCL_DEBUG
Printf(stderr, "namespaceDecl: '%s'(0x%x) (fc=0x%x)\n", Getattr(n, "sym:name"), n, firstChild(n));
Printf(stderr, "namespaceDecl: '%s'(%p) (fc=%p)\n", Getattr(n, "sym:name"), n, firstChild(n));
#endif
/* don't wrap a namespace with no contents. package bloat.
@ -3018,7 +2975,7 @@ int ALLEGROCL::typedefHandler(Node *n) {
if (in_class) {
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, " typedef in class '%s'(%x)\n", Getattr(in_class, "sym:name"), in_class);
Printf(stderr, " typedef in class '%s'(%p)\n", Getattr(in_class, "sym:name"), in_class);
#endif
Setattr(n, "allegrocl:typedef:in-class", in_class);
@ -3036,7 +2993,7 @@ int ALLEGROCL::typedefHandler(Node *n) {
String *lookup = lookup_defined_foreign_type(typedef_type);
#ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "** lookup='%s'(%x), typedef_type='%s', strcmp = '%d' strstr = '%d'\n", lookup, lookup, typedef_type, Strcmp(typedef_type,"void"), Strstr(ff_type,"__SWIGACL_FwdReference"));
Printf(stderr, "** lookup='%s'(%p), typedef_type='%s', strcmp = '%d' strstr = '%d'\n", lookup, lookup, typedef_type, Strcmp(typedef_type,"void"), Strstr(ff_type,"__SWIGACL_FwdReference"));
#endif
if(lookup || (!lookup && Strcmp(typedef_type,"void")) ||
@ -3162,7 +3119,7 @@ int ALLEGROCL::cppClassHandler(Node *n) {
SwigType *childType = NewStringf("%s%s", Getattr(c, "decl"),
Getattr(c, "type"));
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "looking at child '%x' of type '%s' '%d'\n", c, childType, SwigType_isfunction(childType));
Printf(stderr, "looking at child '%p' of type '%s' '%d'\n", c, childType, SwigType_isfunction(childType));
// Swig_print_node(c);
#endif
if (!SwigType_isfunction(childType))
@ -3209,6 +3166,9 @@ int ALLEGROCL::enumDeclaration(Node *n) {
Printf(stderr, "enumDeclaration %s\n", Getattr(n, "name"));
#endif
if (getCurrentClass() && (cplus_mode != PUBLIC))
return SWIG_NOWRAP;
if (Getattr(n, "sym:name")) {
add_defined_foreign_type(n);
}

View file

@ -15,8 +15,6 @@
* Doc/Manual/SWIGPlus.html for details.
* ----------------------------------------------------------------------------- */
char cvsroot_allocate_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
@ -43,7 +41,7 @@ extern "C" {
SwigType *decl1 = SwigType_typedef_resolve_all(decl);
SwigType *decl2 = SwigType_pop_function(decl1);
if (Strcmp(decl2, search_decl) == 0) {
if (!Getattr(n, "abstract")) {
if (!GetFlag(n, "abstract")) {
Delete(decl1);
Delete(decl2);
return 1;
@ -327,38 +325,36 @@ class Allocate:public Dispatcher {
Swig_symbol_setscope(oldtab);
return ret;
}
List *abstract = Getattr(base, "abstract");
if (abstract) {
List *abstracts = Getattr(base, "abstracts");
if (abstracts) {
int dabstract = 0;
int len = Len(abstract);
int len = Len(abstracts);
for (int i = 0; i < len; i++) {
Node *nn = Getitem(abstract, i);
Node *nn = Getitem(abstracts, i);
String *name = Getattr(nn, "name");
if (!name)
continue;
if (Strchr(name, '~'))
continue; /* Don't care about destructors */
String *base_decl = Getattr(nn, "decl");
if (base_decl)
base_decl = SwigType_typedef_resolve_all(base_decl);
if (Strchr(name, '~'))
continue; /* Don't care about destructors */
if (SwigType_isfunction(base_decl)) {
if (SwigType_isfunction(base_decl))
search_decl = SwigType_pop_function(base_decl);
}
Node *dn = Swig_symbol_clookup_local_check(name, 0, check_implemented);
Delete(search_decl);
Delete(base_decl);
if (!dn) {
List *nabstract = Getattr(n, "abstract");
if (!nabstract) {
nabstract = NewList();
Setattr(n, "abstract", nabstract);
Delete(nabstract);
List *nabstracts = Getattr(n, "abstracts");
if (!nabstracts) {
nabstracts = NewList();
Setattr(n, "abstracts", nabstracts);
Delete(nabstracts);
}
Append(nabstract, nn);
if (!Getattr(n, "abstract:firstnode")) {
Setattr(n, "abstract:firstnode", nn);
Append(nabstracts, nn);
if (!Getattr(n, "abstracts:firstnode")) {
Setattr(n, "abstracts:firstnode", nn);
}
dabstract = base != n;
}
@ -415,7 +411,7 @@ class Allocate:public Dispatcher {
match = 1;
break;
}
if ((!symname || (!Getattr(e, "sym:name"))) && (Cmp(name, Getattr(e, "name")) == 0)) {
if (!Getattr(e, "sym:name") && (Cmp(name, Getattr(e, "name")) == 0)) {
match = 1;
break;
}
@ -425,7 +421,7 @@ class Allocate:public Dispatcher {
while (cc) {
Node *cp = cc;
if (classname) {
Setattr(cp, "classname", classname);
Setattr(cp, "extendsmartclassname", classname);
}
Setattr(cp, "allocate:smartpointeraccess", "1");
/* If constant, we have to be careful */
@ -563,7 +559,11 @@ Allocate():
virtual int classDeclaration(Node *n) {
Symtab *symtab = Swig_symbol_current();
Swig_symbol_setscope(Getattr(n, "symtab"));
save_value<Node*> oldInclass(inclass);
save_value<AccessMode> oldAcessMode(cplus_mode);
save_value<int> oldExtendMode(extendmode);
if (Getattr(n, "template"))
extendmode = 0;
if (!CPlusPlus) {
/* Always have default constructors/destructors in C */
Setattr(n, "allocate:default_constructor", "1");
@ -584,7 +584,6 @@ Allocate():
}
}
}
inclass = n;
String *kind = Getattr(n, "kind");
if (Strcmp(kind, "class") == 0) {
@ -598,19 +597,19 @@ Allocate():
/* Check if the class is abstract via inheritance. This might occur if a class didn't have
any pure virtual methods of its own, but it didn't implement all of the pure methods in
a base class */
if (!Getattr(n, "abstract") && is_abstract_inherit(n)) {
if (!Getattr(n, "abstracts") && is_abstract_inherit(n)) {
if (((Getattr(n, "allocate:public_constructor") || (!GetFlag(n, "feature:nodefault") && !Getattr(n, "allocate:has_constructor"))))) {
if (!GetFlag(n, "feature:notabstract")) {
Node *na = Getattr(n, "abstract:firstnode");
Node *na = Getattr(n, "abstracts:firstnode");
if (na) {
Swig_warning(WARN_TYPE_ABSTRACT, Getfile(n), Getline(n),
"Class '%s' might be abstract, " "no constructors generated,\n", SwigType_namestr(Getattr(n, "name")));
Swig_warning(WARN_TYPE_ABSTRACT, Getfile(na), Getline(na), "Method %s might not be implemented.\n", Swig_name_decl(na));
if (!Getattr(n, "abstract")) {
List *abstract = NewList();
Append(abstract, na);
Setattr(n, "abstract", abstract);
Delete(abstract);
if (!Getattr(n, "abstracts")) {
List *abstracts = NewList();
Append(abstracts, na);
Setattr(n, "abstracts", abstracts);
Delete(abstracts);
}
}
}
@ -620,7 +619,7 @@ Allocate():
if (!Getattr(n, "allocate:has_constructor")) {
/* No constructor is defined. We need to check a few things */
/* If class is abstract. No default constructor. Sorry */
if (Getattr(n, "abstract")) {
if (Getattr(n, "abstracts")) {
Delattr(n, "allocate:default_constructor");
}
if (!Getattr(n, "allocate:default_constructor")) {
@ -641,7 +640,7 @@ Allocate():
}
}
if (!Getattr(n, "allocate:has_copy_constructor")) {
if (Getattr(n, "abstract")) {
if (Getattr(n, "abstracts")) {
Delattr(n, "allocate:copy_constructor");
}
if (!Getattr(n, "allocate:copy_constructor")) {
@ -663,7 +662,7 @@ Allocate():
}
if (!Getattr(n, "allocate:has_destructor")) {
/* No destructor was defined. We need to check a few things here too */
/* No destructor was defined */
List *bases = Getattr(n, "allbases");
int allows_destruct = 1;
@ -680,13 +679,13 @@ Allocate():
}
if (!Getattr(n, "allocate:has_assign")) {
/* No destructor was defined. We need to check a few things here too */
/* No assignment operator was defined */
List *bases = Getattr(n, "allbases");
int allows_assign = 1;
for (int i = 0; i < Len(bases); i++) {
Node *n = Getitem(bases, i);
/* If base class does not allow default destructor, we don't allow it either */
/* If base class does not allow assignment, we don't allow it either */
if (Getattr(n, "allocate:has_assign")) {
allows_assign = !Getattr(n, "allocate:noassign");
}
@ -697,13 +696,13 @@ Allocate():
}
if (!Getattr(n, "allocate:has_new")) {
/* No destructor was defined. We need to check a few things here too */
/* No new operator was defined */
List *bases = Getattr(n, "allbases");
int allows_new = 1;
for (int i = 0; i < Len(bases); i++) {
Node *n = Getitem(bases, i);
/* If base class does not allow default destructor, we don't allow it either */
/* If base class does not allow new operator, we don't allow it either */
if (Getattr(n, "allocate:has_new")) {
allows_new = !Getattr(n, "allocate:nonew");
}
@ -715,7 +714,7 @@ Allocate():
/* Check if base classes allow smart pointers, but might be hidden */
if (!Getattr(n, "allocate:smartpointer")) {
Node *sp = Swig_symbol_clookup((char *) "operator ->", 0);
Node *sp = Swig_symbol_clookup("operator ->", 0);
if (sp) {
/* Look for parent */
Node *p = parentNode(sp);
@ -730,9 +729,10 @@ Allocate():
}
}
Swig_interface_propagate_methods(n);
/* Only care about default behavior. Remove temporary values */
Setattr(n, "allocate:visit", "1");
inclass = 0;
Swig_symbol_setscope(symtab);
return SWIG_OK;
}
@ -775,7 +775,7 @@ Allocate():
/* Check to see if this is a static member or not. If so, we add an attribute
cplus:staticbase that saves the current class */
if (checkAttribute(n, "storage", "static")) {
if (Swig_storage_isstatic(n)) {
Setattr(n, "cplus:staticbase", inclass);
}
@ -783,18 +783,26 @@ Allocate():
if (cplus_mode != PUBLIC) {
if (Strcmp(name, "operator =") == 0) {
/* Look for a private assignment operator */
Setattr(inclass, "allocate:has_assign", "1");
if (!GetFlag(n, "deleted"))
Setattr(inclass, "allocate:has_assign", "1");
Setattr(inclass, "allocate:noassign", "1");
} else if (Strcmp(name, "operator new") == 0) {
/* Look for a private new operator */
Setattr(inclass, "allocate:has_new", "1");
if (!GetFlag(n, "deleted"))
Setattr(inclass, "allocate:has_new", "1");
Setattr(inclass, "allocate:nonew", "1");
}
} else {
if (Strcmp(name, "operator =") == 0) {
Setattr(inclass, "allocate:has_assign", "1");
if (!GetFlag(n, "deleted"))
Setattr(inclass, "allocate:has_assign", "1");
else
Setattr(inclass, "allocate:noassign", "1");
} else if (Strcmp(name, "operator new") == 0) {
Setattr(inclass, "allocate:has_new", "1");
if (!GetFlag(n, "deleted"))
Setattr(inclass, "allocate:has_new", "1");
else
Setattr(inclass, "allocate:nonew", "1");
}
/* Look for smart pointer operator */
if ((Strcmp(name, "operator ->") == 0) && (!GetFlag(n, "feature:ignore"))) {
@ -821,13 +829,13 @@ Allocate():
}
List *methods = smart_pointer_methods(sc, 0, isconst);
Setattr(inclass, "allocate:smartpointer", methods);
Setattr(inclass, "allocate:smartpointerbase", base);
Setattr(inclass, "allocate:smartpointerpointeeclassname", Getattr(sc, "name"));
} else {
/* Hmmm. The return value is not a pointer. If the type is a value
or reference. We're going to chase it to see if another operator->()
can be found */
if ((SwigType_check_decl(type, "")) || (SwigType_check_decl(type, "r."))) {
Node *nn = Swig_symbol_clookup((char *) "operator ->", Getattr(sc, "symtab"));
Node *nn = Swig_symbol_clookup("operator ->", Getattr(sc, "symtab"));
if (nn) {
Delete(base);
Delete(type);
@ -935,6 +943,8 @@ Allocate():
Setattr(inclass, "allocate:default_destructor", "1");
} else if (cplus_mode == PROTECTED) {
Setattr(inclass, "allocate:default_base_destructor", "1");
} else if (cplus_mode == PRIVATE) {
Setattr(inclass, "allocate:private_destructor", "1");
}
} else {
Setattr(inclass, "allocate:has_destructor", "1");

View file

@ -12,8 +12,6 @@
* feature that's normally disabled.
* ----------------------------------------------------------------------------- */
char cvsroot_browser_cxx[] = "$Id$";
#include "swigmod.h"
#ifdef SWIG_SWILL
@ -29,9 +27,9 @@ class Browser:public Dispatcher {
v = 1;
}
if (v) {
Printf(out, "<a name=\"n%x\"></a>[<a href=\"hide.html?node=0x%x&hn=0x%x#n%x\">-</a>] ", n, t, n, n);
Printf(out, "<a name=\"n%p\"></a>[<a href=\"hide.html?node=%p&hn=%p#n%p\">-</a>] ", n, t, n, n);
} else {
Printf(out, "<a name=\"n%x\"></a>[<a href=\"show.html?node=0x%x&hn=0x%x#n%x\">+</a>] ", n, t, n, n);
Printf(out, "<a name=\"n%p\"></a>[<a href=\"show.html?node=%p&hn=%p#n%p\">+</a>] ", n, t, n, n);
}
}
void show_attributes(Node *obj) {
@ -52,7 +50,7 @@ class Browser:public Dispatcher {
Replaceall(o, "&", "&amp;");
Replaceall(o, "<", "&lt;");
Replaceall(o, ">", "&gt;");
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - %s\n", Getattr(obj, k), k, o);
Printf(os, "<a href=\"data.html?n=%p\">?</a> %-12s - %s\n", Getattr(obj, k), k, o);
Delete(o);
} else {
DOH *o;
@ -64,10 +62,10 @@ class Browser:public Dispatcher {
}
Replaceall(o, "&", "&amp;");
Replaceall(o, "<", "&lt;");
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Printf(os, "<a href=\"data.html?n=%p\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Delete(o);
} else {
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
Printf(os, "<a href=\"data.html?n=%p\">?</a> %-12s - %p\n", Getattr(obj, k), k, Getattr(obj, k));
}
}
ki = Next(ki);
@ -84,7 +82,7 @@ public:
char *name = GetChar(n, "name");
show_checkbox(view_top, n);
Printf(out, "<b><a href=\"index.html?node=0x%x\">%s</a></b>", n, tag);
Printf(out, "<b><a href=\"index.html?node=%p\">%s</a></b>", n, tag);
if (name) {
Printf(out, " (%s)", name);
}
@ -138,6 +136,12 @@ public:
return SWIG_OK;
}
virtual int lambdaDeclaration(Node *n) {
show_attributes(n);
emit_children(n);
return SWIG_OK;
}
virtual int enumDeclaration(Node *n) {
show_attributes(n);
emit_children(n);
@ -184,9 +188,9 @@ static void display(FILE *f, Node *n) {
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", Swig_package_version());
Printf(f, "<b>SWIG-%s</b><br>\n", Swig_package_version());
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, " [ <a href=\"index.html?node=%p\">Top</a> ]", tree_top);
if (n != tree_top) {
Printf(f, " [ <a href=\"index.html?node=0x%x\">Up</a> ]", parentNode(n));
Printf(f, " [ <a href=\"index.html?node=%p\">Up</a> ]", parentNode(n));
}
Printf(f, " [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f, "<br><hr><p>\n");
@ -255,10 +259,10 @@ void raw_data(FILE *out, Node *obj) {
trunc = "...";
}
Replaceall(o, "<", "&lt;");
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Printf(os, " <a href=\"data.html?n=%p\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Delete(o);
} else {
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
Printf(os, " <a href=\"data.html?n=%p\">?</a> %-12s - %p\n", Getattr(obj, k), k, Getattr(obj, k));
}
ki = Next(ki);
}
@ -283,10 +287,10 @@ void raw_data(FILE *out, Node *obj) {
trunc = "...";
}
Replaceall(o, "<", "&lt;");
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc);
Printf(os, " <a href=\"data.html?n=%p\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc);
Delete(s);
} else {
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> [%d] - 0x%x\n", o, i, o);
Printf(os, " <a href=\"data.html?n=%p\">?</a> [%d] - %p\n", o, i, o);
}
}
Printf(os, "\n]\n");
@ -303,7 +307,7 @@ void data_handler(FILE *f) {
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", Swig_package_version());
Printf(f, "<b>SWIG-%s</b><br>\n", Swig_package_version());
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, " [ <a href=\"index.html?node=%p\">Top</a> ]", tree_top);
Printf(f, "<br><hr><p>\n");
if (n) {
raw_data(f, n);
@ -319,7 +323,7 @@ void symbol_handler(FILE *f) {
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", Swig_package_version());
Printf(f, "<b>SWIG-%s</b><br>\n", Swig_package_version());
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, " [ <a href=\"index.html?node=%p\">Top</a> ]", tree_top);
Printf(f, " [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f, "<br><hr><p>\n");
@ -343,7 +347,7 @@ void symbol_handler(FILE *f) {
fprintf(f, "<p><form action=\"symbol.html\" method=GET>\n");
fprintf(f, "Symbol lookup: <input type=text name=name size=40></input><br>\n");
fprintf(f, "<input type=hidden name=sym value=\"0x%x\">\n", sym);
fprintf(f, "<input type=hidden name=sym value=\"%p\">\n", sym);
fprintf(f, "Submit : <input type=submit></input>\n");
fprintf(f, "</form>");
@ -365,7 +369,7 @@ void symbol_handler(FILE *f) {
Hash *h;
h = firstChild(sym);
while (h) {
Printf(f, "<a href=\"symbol.html?sym=0x%x\">%s</a>\n", h, Getattr(h, "name"));
Printf(f, "<a href=\"symbol.html?sym=%p\">%s</a>\n", h, Getattr(h, "name"));
h = nextSibling(h);
}
}

View file

@ -442,8 +442,8 @@ public:
Printv(f_proxy_c, f_proxy_code_init, "\n", NIL);
Printv(f_proxy_c, f_proxy_code_body, "\n", NIL);
Printv(f_proxy_h, f_proxy_header, "\n#endif /* _", Char(module), "_proxy_H_ */\n", NIL);
Close(f_proxy_c);
Close(f_proxy_h);
Delete(f_proxy_c);
Delete(f_proxy_h);
Delete(f_proxy_code_init);
Delete(f_proxy_header);
}
@ -459,7 +459,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_runtime);
Delete(f_runtime);
return SWIG_OK;

View file

@ -11,8 +11,6 @@
* cffi language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_cffi_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>
@ -20,7 +18,7 @@ char cvsroot_cffi_cxx[] = "$Id$";
//#define CFFI_DEBUG
//#define CFFI_WRAP_DEBUG
static const char *usage = (char *) "\
static const char *usage = "\
CFFI Options (available with -cffi)\n\
-generate-typedef - Use defctype to generate shortcuts according to the\n\
typedefs in the input.\n\
@ -63,6 +61,11 @@ public:
virtual int classHandler(Node *n);
private:
static void checkConstraints(ParmList *parms, Wrapper *f);
static void argout(ParmList *parms, Wrapper *f);
static String *freearg(ParmList *parms);
static void cleanupFunction(Node *n, Wrapper *f, ParmList *parms);
void emit_defun(Node *n, String *name);
void emit_defmethod(Node *n);
void emit_initialize_instance(Node *n);
@ -137,7 +140,6 @@ int CFFI::top(Node *n) {
if (CPlusPlus || CWrap) {
f_begin = NewFile(cxx_filename, "w", SWIG_output_files());
if (!f_begin) {
Close(f_lisp);
Delete(f_lisp);
Printf(stderr, "Unable to open %s for writing\n", cxx_filename);
SWIG_exit(EXIT_FAILURE);
@ -147,7 +149,6 @@ int CFFI::top(Node *n) {
Printf(clos_filename, "%s%s-clos.lisp", SWIG_output_directory(), module);
f_clos = NewFile(clos_filename, "w", SWIG_output_files());
if (!f_clos) {
Close(f_lisp);
Delete(f_lisp);
Printf(stderr, "Unable to open %s for writing\n", cxx_filename);
SWIG_exit(EXIT_FAILURE);
@ -173,9 +174,7 @@ int CFFI::top(Node *n) {
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGCFFI\n");
Printf(f_runtime, "\n");
Printf(f_runtime, "\n\n#ifndef SWIGCFFI\n#define SWIGCFFI\n#endif\n\n");
Swig_banner_target_lang(f_lisp, ";;;");
@ -184,13 +183,11 @@ int CFFI::top(Node *n) {
Printf(f_lisp, "%s\n", f_cl);
Printf(f_lisp, "%s\n", f_clwrap);
Close(f_lisp);
Delete(f_lisp); // Deletes the handle, not the file
Delete(f_lisp);
Delete(f_cl);
Delete(f_clhead);
Delete(f_clwrap);
Dump(f_runtime, f_begin);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
Delete(f_cxx_wrapper);
@ -326,7 +323,7 @@ void CFFI::emit_initialize_instance(Node *n) {
else
Printf(args_placeholder, " %s", argname);
if (Strcmp(ffitype, lispify_name(parent, lispy_name(Char(Getattr(parent, "sym:name"))), "'classname")) == 0)
if (ffitype && Strcmp(ffitype, lispify_name(parent, lispy_name(Char(Getattr(parent, "sym:name"))), "'classname")) == 0)
Printf(args_call, " (ff-pointer %s)", argname);
else
Printf(args_call, " %s", argname);
@ -370,6 +367,77 @@ int CFFI::membervariableHandler(Node *n) {
return Language::membervariableHandler(n);
}
void CFFI::checkConstraints(ParmList *parms, Wrapper *f) {
Parm *p = parms;
while (p) {
String *tm = Getattr(p, "tmap:check");
if (!tm) {
p = nextSibling(p);
} else {
tm = Copy(tm);
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(f->code, tm, "\n\n", NULL);
Delete(tm);
p = Getattr(p, "tmap:check:next");
}
}
}
void CFFI::argout(ParmList *parms, Wrapper *f) {
Parm *p = parms;
while (p) {
String *tm = Getattr(p, "tmap:argout");
if (!tm) {
p = nextSibling(p);
} else {
tm = Copy(tm);
Replaceall(tm, "$result", Swig_cresult_name());
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(f->code, tm, "\n", NULL);
Delete(tm);
p = Getattr(p, "tmap:argout:next");
}
}
}
String *CFFI::freearg(ParmList *parms) {
String *ret = NewString("");
Parm *p = parms;
while (p) {
String *tm = Getattr(p, "tmap:freearg");
if (!tm) {
p = nextSibling(p);
} else {
tm = Copy(tm);
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(ret, tm, "\n", NULL);
Delete(tm);
p = Getattr(p, "tmap:freearg:next");
}
}
return ret;
}
void CFFI::cleanupFunction(Node *n, Wrapper *f, ParmList *parms) {
String *cleanup = freearg(parms);
Printv(f->code, cleanup, NULL);
if (GetFlag(n, "feature:new")) {
String *tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0);
if (tm) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NULL);
Delete(tm);
}
}
Replaceall(f->code, "$cleanup", cleanup);
Delete(cleanup);
Replaceall(f->code, "$symname", Getattr(n, "sym:name"));
}
int CFFI::functionWrapper(Node *n) {
ParmList *parms = Getattr(n, "parms");
@ -457,15 +525,28 @@ int CFFI::functionWrapper(Node *n) {
// Emit the function definition
String *signature = SwigType_str(return_type, name_and_parms);
Printf(f->def, "EXPORT %s {", signature);
checkConstraints(parms, f);
Printf(f->code, " try {\n");
String *actioncode = emit_action(n);
String *result_convert = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode);
Replaceall(result_convert, "$result", "lresult");
Printf(f->code, "%s\n", result_convert);
if(!is_void_return) Printf(f->code, " return lresult;\n");
if (result_convert) {
Replaceall(result_convert, "$result", "lresult");
Printf(f->code, "%s\n", result_convert);
}
Delete(result_convert);
argout(parms, f);
cleanupFunction(n, f, parms);
if (!is_void_return) {
Printf(f->code, " return lresult;\n");
}
emit_return_variable(n, Getattr(n, "type"), f);
Printf(f->code, " } catch (...) {\n");
@ -510,11 +591,6 @@ int CFFI::functionWrapper(Node *n) {
void CFFI::emit_defun(Node *n, String *name) {
// String *storage=Getattr(n,"storage");
// if(!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc")))
// return SWIG_OK;
String *func_name = Getattr(n, "sym:name");
ParmList *pl = Getattr(n, "parms");
@ -567,7 +643,13 @@ void CFFI::emit_defun(Node *n, String *name) {
int CFFI::constantWrapper(Node *n) {
String *type = Getattr(n, "type");
String *converted_value = convert_literal(Getattr(n, "value"), type);
String *converted_value;
if (SwigType_type(type) == T_STRING) {
converted_value = NewString(Getattr(n, "rawval"));
} else {
converted_value = convert_literal(Getattr(n, "value"), type);
}
String *name = lispify_name(n, Getattr(n, "sym:name"), "'constant");
if (Strcmp(name, "t") == 0 || Strcmp(name, "T") == 0)
@ -581,12 +663,6 @@ int CFFI::constantWrapper(Node *n) {
}
int CFFI::variableWrapper(Node *n) {
// String *storage=Getattr(n,"storage");
// Printf(stdout,"\"%s\" %s)\n",storage,Getattr(n, "sym:name"));
// if(!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc")))
// return SWIG_OK;
String *var_name = Getattr(n, "sym:name");
String *lisp_type = Swig_typemap_lookup("cin", n, "", 0);
String *lisp_name = lispify_name(n, var_name, "'variable");
@ -612,6 +688,9 @@ int CFFI::typedefHandler(Node *n) {
}
int CFFI::enumDeclaration(Node *n) {
if (getCurrentClass() && (cplus_mode != PUBLIC))
return SWIG_NOWRAP;
String *name = Getattr(n, "sym:name");
bool slot_name_keywords;
String *lisp_name = 0;
@ -671,7 +750,7 @@ int CFFI::enumDeclaration(Node *n) {
void CFFI::emit_class(Node *n) {
#ifdef CFFI_WRAP_DEBUG
Printf(stderr, "emit_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n);
Printf(stderr, "emit_class: ENTER... '%s'(%p)\n", Getattr(n, "sym:name"), n);
#endif
String *name = Getattr(n, "sym:name");
@ -685,7 +764,7 @@ void CFFI::emit_class(Node *n) {
if (!first)
Printf(supers, " ");
String *s = Getattr(i.item, "name");
Printf(supers, "%s", lispify_name(i.item, s, "'classname"));
Printf(supers, "%s", lispify_name(i.item, lispy_name(Char(s)), "'classname"));
}
} else {
// Printf(supers,"ff:foreign-pointer");
@ -837,10 +916,15 @@ void CFFI::emit_struct_union(Node *n, bool un = false) {
String *typespec = tm ? NewString(tm) : NewString("");
String *slot_name = lispify_name(c, Getattr(c, "sym:name"), "'slotname");
if (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0)
if (slot_name && (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0))
slot_name = NewStringf("t_var");
Printf(f_cl, "\n\t(%s %s)", slot_name, typespec);
if (SwigType_isarray(childType) && SwigType_array_ndim(childType) == 1) {
String *dim = SwigType_array_getdim(childType, 0);
Printf(f_cl, "\n\t(%s %s :count %s)", slot_name, typespec, dim);
Delete(dim);
} else
Printf(f_cl, "\n\t(%s %s)", slot_name, typespec);
Delete(node);
Delete(childType);
@ -864,8 +948,11 @@ void CFFI::emit_struct_union(Node *n, bool un = false) {
}
void CFFI::emit_export(Node *n, String *name) {
if (GetInt(n, "feature:export"))
Printf(f_cl, "\n(cl:export '%s)\n", name);
if (GetInt(n, "feature:export")) {
String* package = Getattr(n, "feature:export:package");
Printf(f_cl, "\n(cl:export '%s%s%s)\n", name, package ? " " : "",
package ? package : "");
}
}
void CFFI::emit_inline(Node *n, String *name) {
@ -1023,9 +1110,8 @@ String *CFFI::convert_literal(String *literal, String *type, bool try_to_split)
return num;
} else if (SwigType_type(type) == T_CHAR) {
/* Use CL syntax for character literals */
String* result = NewStringf("#\\%c", s[2]);
String* result = NewStringf("#\\%s", s);
Delete(num);
// Printf(stderr, "%s %c %d", s, s[2], s);
return result;
} else if (SwigType_type(type) == T_STRING) {
/* Use CL syntax for string literals */
@ -1034,10 +1120,14 @@ String *CFFI::convert_literal(String *literal, String *type, bool try_to_split)
return result;
} else if (SwigType_type(type) == T_INT || SwigType_type(type) == T_UINT) {
// Printf(stderr, "Is a T_INT or T_UINT %s, before replaceall\n", s);
Replaceall(num, "u", "");
Replaceall(num, "U", "");
Replaceall(num, "l", "");
Replaceall(num, "L", "");
const char *num_start = Char(num);
bool is_literal = isdigit(*num_start) || (*num_start == '.') || (*num_start == '+') || (*num_start == '-');
if (is_literal) {
Replaceall(num, "u", "");
Replaceall(num, "U", "");
Replaceall(num, "l", "");
Replaceall(num, "L", "");
}
int i, j;
if (sscanf(s, "%d >> %d", &i, &j) == 2) {
@ -1053,10 +1143,10 @@ String *CFFI::convert_literal(String *literal, String *type, bool try_to_split)
if (Len(num) >= 2 && s[0] == '0') { /* octal or hex */
if (s[1] == 'x'){
DohReplace(num,"0","#",DOH_REPLACE_FIRST);
Replace(num,"0","#",DOH_REPLACE_FIRST);
}
else{
DohReplace(num,"0","#o",DOH_REPLACE_FIRST);
Replace(num,"0","#o",DOH_REPLACE_FIRST);
}
}
return num;

View file

@ -11,13 +11,11 @@
* CHICKEN language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_chicken_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
static const char *usage = (char *) "\
static const char *usage = "\
\
CHICKEN Options (available with -chicken)\n\
-closprefix <prefix> - Prepend <prefix> to all clos identifiers\n\
@ -31,7 +29,7 @@ CHICKEN Options (available with -chicken)\n\
\n";
static char *module = 0;
static char *chicken_path = (char *) "chicken";
static const char *chicken_path = "chicken";
static int num_methods = 0;
static File *f_begin = 0;
@ -224,8 +222,7 @@ int CHICKEN::top(Node *n) {
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGCHICKEN\n");
Printf(f_runtime, "\n\n#ifndef SWIGCHICKEN\n#define SWIGCHICKEN\n#endif\n\n");
if (no_collection)
Printf(f_runtime, "#define SWIG_CHICKEN_NO_COLLECTION 1\n");
@ -290,8 +287,6 @@ int CHICKEN::top(Node *n) {
Printf(f_scm, "%s\n", chickentext);
Close(f_scm);
Delete(f_scm);
char buftmp[20];
@ -324,7 +319,6 @@ int CHICKEN::top(Node *n) {
Delete(f_wrappers);
Delete(f_sym_size);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -625,7 +619,7 @@ int CHICKEN::functionWrapper(Node *n) {
if (in_class)
clos_name = NewString(member_name);
else
clos_name = chickenNameMapping(scmname, (char *) "");
clos_name = chickenNameMapping(scmname, "");
if (!any_specialized_arg) {
method_def = NewString("");
@ -780,7 +774,7 @@ int CHICKEN::variableWrapper(Node *n) {
if (in_class)
clos_name = NewString(member_name);
else
clos_name = chickenNameMapping(scmname, (char *) "");
clos_name = chickenNameMapping(scmname, "");
Node *class_node = classLookup(t);
String *clos_code = Getattr(n, "tmap:varin:closcode");
@ -947,7 +941,7 @@ int CHICKEN::constantWrapper(Node *n) {
if (in_class)
clos_name = NewString(member_name);
else
clos_name = chickenNameMapping(scmname, (char *) "");
clos_name = chickenNameMapping(scmname, "");
if (GetFlag(n, "feature:constasvar")) {
Printv(clos_methods, "(define ", clos_name, " (", chickenPrimitiveName(scmname), "))\n", NIL);
Printv(scm_const_defs, "(set! ", scmname, " (", scmname, "))\n", NIL);
@ -1377,7 +1371,7 @@ void CHICKEN::dispatchFunction(Node *n) {
} else if (in_class)
clos_name = NewString(member_name);
else
clos_name = chickenNameMapping(scmname, (char *) "");
clos_name = chickenNameMapping(scmname, "");
Iterator f;
List *prev = 0;

View file

@ -11,11 +11,9 @@
* clisp language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_clisp_cxx[] = "$Id$";
#include "swigmod.h"
static const char *usage = (char *) "\
static const char *usage = "\
CLISP Options (available with -clisp)\n\
-extern-all - Create clisp definitions for all the functions and\n\
global variables otherwise only definitions for\n\
@ -78,13 +76,13 @@ int CLISP::top(Node *n) {
/* Get the output file name */
String *outfile = Getattr(n, "outfile");
if (!outfile)
output_filename = outfile;
else {
output_filename = NewString("");
Printf(output_filename, "%s%s.lisp", SWIG_output_directory(), module);
if (!outfile) {
Printf(stderr, "Unable to determine outfile\n");
SWIG_exit(EXIT_FAILURE);
}
output_filename = NewStringf("%s%s.lisp", SWIG_output_directory(), module);
f_cl = NewFile(output_filename, "w+", SWIG_output_files());
if (!f_cl) {
FileErrorDisplay(output_filename);
@ -132,17 +130,16 @@ int CLISP::top(Node *n) {
for (len--; len >= 0; len--) {
end--;
Seek(f_cl, len, SEEK_SET);
(void)Seek(f_cl, len, SEEK_SET);
int ch = Getc(f_cl);
Seek(f_cl, end, SEEK_SET);
(void)Seek(f_cl, end, SEEK_SET);
Putc(ch, f_cl);
}
Seek(f_cl, 0, SEEK_SET);
Write(f_cl, Char(header), Len(header));
Close(f_cl);
Delete(f_cl); // Deletes the handle, not the file
Delete(f_cl);
return SWIG_OK;
}
@ -151,7 +148,7 @@ int CLISP::top(Node *n) {
int CLISP::functionWrapper(Node *n) {
is_function = 1;
String *storage = Getattr(n, "storage");
if (!extern_all_flag && (!storage || (Strcmp(storage, "extern") && Strcmp(storage, "externc"))))
if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && !Swig_storage_isexternc(n))))
return SWIG_OK;
String *func_name = Getattr(n, "sym:name");
@ -220,10 +217,9 @@ int CLISP::constantWrapper(Node *n) {
int CLISP::variableWrapper(Node *n) {
is_function = 0;
// SwigType *type=;
String *storage = Getattr(n, "storage");
if (!extern_all_flag && (!storage || (Strcmp(storage, "extern") && Strcmp(storage, "externc"))))
if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && !Swig_storage_isexternc(n))))
return SWIG_OK;
String *var_name = Getattr(n, "sym:name");
@ -246,6 +242,9 @@ int CLISP::typedefHandler(Node *n) {
}
int CLISP::enumDeclaration(Node *n) {
if (getCurrentClass() && (cplus_mode != PUBLIC))
return SWIG_NOWRAP;
is_function = 0;
String *name = Getattr(n, "sym:name");

View file

@ -11,8 +11,6 @@
* Support for Wrap by Contract in SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_contract_cxx[] = "$Id$";
#include "swigmod.h"
/* Contract structure. This holds rules about the different kinds of contract sections
@ -309,7 +307,7 @@ int Contracts::cDeclaration(Node *n) {
return SWIG_OK;
if (Getattr(n, "feature:contract"))
ret = emit_contract(n, (InClass && !checkAttribute(n, "storage", "static")));
ret = emit_contract(n, InClass && !Swig_storage_isstatic(n));
return ret;
}
@ -344,11 +342,13 @@ int Contracts::namespaceDeclaration(Node *n) {
int Contracts::classDeclaration(Node *n) {
int ret = SWIG_OK;
int oldInClass = InClass;
Node *oldClass = CurrentClass;
InClass = 1;
CurrentClass = n;
emit_children(n);
InClass = 0;
CurrentClass = 0;
InClass = oldInClass;
CurrentClass = oldClass;
return ret;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -13,8 +13,6 @@
* in SWIG. --MR
* ----------------------------------------------------------------------------- */
char cvsroot_directors_cxx[] = "$Id";
#include "swigmod.h"
/* Swig_csuperclass_call()
@ -78,9 +76,10 @@ String *Swig_class_name(Node *n) {
String *Swig_director_declaration(Node *n) {
String *classname = Swig_class_name(n);
String *directorname = NewStringf("SwigDirector_%s", classname);
String *directorname = Language::instance()->directorClassName(n);
String *base = Getattr(n, "classtype");
String *declaration = Swig_class_declaration(n, directorname);
Printf(declaration, " : public %s, public Swig::Director {\n", base);
Delete(classname);
Delete(directorname);
@ -132,7 +131,7 @@ String *Swig_method_call(const_String_or_char_ptr name, ParmList *parms) {
*
*/
String *Swig_method_decl(SwigType *returntype, SwigType *decl, const_String_or_char_ptr id, List *args, int strip, int values) {
String *Swig_method_decl(SwigType *rettype, SwigType *decl, const_String_or_char_ptr id, List *args, int strip, int values) {
String *result;
List *elements;
String *element = 0, *nextelement;
@ -203,7 +202,7 @@ String *Swig_method_decl(SwigType *returntype, SwigType *decl, const_String_or_c
Append(result, ", ");
}
Append(result, ")");
} else if (returntype) { // This check is intended for conversion operators to a pointer/reference which needs the pointer/reference ignoring in the declaration
} else if (rettype) { // This check is intended for conversion operators to a pointer/reference which needs the pointer/reference ignoring in the declaration
if (SwigType_ispointer(element)) {
Insert(result, 0, "*");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
@ -256,9 +255,9 @@ String *Swig_method_decl(SwigType *returntype, SwigType *decl, const_String_or_c
Chop(result);
if (returntype) {
if (rettype) {
Insert(result, 0, " ");
String *rtype = SwigType_str(returntype, 0);
String *rtype = SwigType_str(rettype, 0);
Insert(result, 0, rtype);
Delete(rtype);
}
@ -276,13 +275,14 @@ String *Swig_method_decl(SwigType *returntype, SwigType *decl, const_String_or_c
void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f) {
// TODO: why is the storage element removed in staticmemberfunctionHandler ??
if ((!is_public(n) && (is_member_director(n) || GetFlag(n, "explicitcall"))) ||
(is_non_virtual_protected_access(n) && !(checkAttribute(n, "staticmemberfunctionHandler:storage", "static") ||
checkAttribute(n, "storage", "static"))
(is_non_virtual_protected_access(n) && !(Swig_storage_isstatic_custom(n, "staticmemberfunctionHandler:storage") ||
Swig_storage_isstatic(n))
&& !Equal(nodeType(n), "constructor"))) {
Node *parent = Getattr(n, "parentNode");
String *symname = Getattr(parent, "sym:name");
String *dirname = NewStringf("SwigDirector_%s", symname);
String *dirdecl = NewStringf("%s *darg = 0", dirname);
String *dirname;
String *dirdecl;
dirname = Language::instance()->directorClassName(parent);
dirdecl = NewStringf("%s *darg = 0", dirname);
Wrapper_add_local(f, "darg", dirdecl);
Printf(f->code, "darg = dynamic_cast<%s *>(arg1);\n", dirname);
Delete(dirname);

View file

@ -11,8 +11,6 @@
* Useful functions for emitting various pieces of code.
* ----------------------------------------------------------------------------- */
char cvsroot_emit_cxx[] = "$Id$";
#include "swigmod.h"
/* -----------------------------------------------------------------------------
@ -363,24 +361,9 @@ int emit_action_code(Node *n, String *wrappercode, String *eaction) {
tm = Copy(tm);
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
if (Strstr(tm, "$")) {
Replaceall(tm, "$name", Getattr(n, "name"));
Replaceall(tm, "$symname", Getattr(n, "sym:name"));
Swig_replace_special_variables(n, parentNode(n), tm);
Replaceall(tm, "$function", eaction); // deprecated
Replaceall(tm, "$action", eaction);
Replaceall(tm, "$wrapname", Getattr(n, "wrap:name"));
String *overloaded = Getattr(n, "sym:overloaded");
Replaceall(tm, "$overname", overloaded ? Char(Getattr(n, "sym:overname")) : "");
if (Strstr(tm, "$decl")) {
String *decl = Swig_name_decl(n);
Replaceall(tm, "$decl", decl);
Delete(decl);
}
if (Strstr(tm, "$fulldecl")) {
String *fulldecl = Swig_name_fulldecl(n);
Replaceall(tm, "$fulldecl", fulldecl);
Delete(fulldecl);
}
}
Printv(wrappercode, tm, "\n", NIL);
Delete(tm);
@ -470,6 +453,7 @@ String *emit_action(Node *n) {
if (catchlist) {
int unknown_catch = 0;
int has_varargs = 0;
Printf(eaction, "}\n");
for (Parm *ep = catchlist; ep; ep = nextSibling(ep)) {
String *em = Swig_typemap_lookup("throws", ep, "_e", 0);
@ -480,6 +464,7 @@ String *emit_action(Node *n) {
Printf(eaction, "catch(%s) {", SwigType_str(et, "_e"));
} else if (SwigType_isvarargs(etr)) {
Printf(eaction, "catch(...) {");
has_varargs = 1;
} else {
Printf(eaction, "catch(%s) {", SwigType_str(et, "&_e"));
}
@ -490,8 +475,8 @@ String *emit_action(Node *n) {
unknown_catch = 1;
}
}
if (unknown_catch) {
Printf(eaction, "catch(...) { throw; }\n");
if (unknown_catch && !has_varargs) {
Printf(eaction, "catch(...) { throw; }\n");
}
}

File diff suppressed because it is too large Load diff

View file

@ -11,23 +11,20 @@
* Guile language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_guile_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
// Note string broken in half for compilers that can't handle long strings
static const char *usage = (char *) "\
static const char *usage = "\
Guile Options (available with -guile)\n\
-emitsetters - Emit procedures-with-setters for variables\n\
and structure slots.\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\
-Linkage <lstyle> - Use linkage protocol <lstyle> (default `simple')\n\
Use `module' for native Guile module linking\n\
(requires Guile >= 1.5.0). Use `passive' for\n\
passive linking (no C-level module-handling code),\n\
@ -46,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\
@ -59,9 +55,9 @@ static File *f_wrappers = 0;
static File *f_init = 0;
static char *prefix = (char *) "gswig_";
static String *prefix = NewString("gswig_");
static char *module = 0;
static char *package = 0;
static String *package = 0;
static enum {
GUILE_LSTYLE_SIMPLE, // call `SWIG_init()'
GUILE_LSTYLE_PASSIVE, // passive linking (no module code)
@ -96,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;
@ -127,7 +122,7 @@ public:
* ------------------------------------------------------------ */
virtual void main(int argc, char *argv[]) {
int i, orig_len;
int i;
SWIG_library_directory("guile");
SWIG_typemap_lang("guile");
@ -140,8 +135,7 @@ public:
SWIG_exit(EXIT_SUCCESS);
} else if (strcmp(argv[i], "-prefix") == 0) {
if (argv[i + 1]) {
prefix = new char[strlen(argv[i + 1]) + 2];
strcpy(prefix, argv[i + 1]);
prefix = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
@ -150,8 +144,7 @@ public:
}
} else if (strcmp(argv[i], "-package") == 0) {
if (argv[i + 1]) {
package = new char[strlen(argv[i + 1]) + 2];
strcpy(package, argv[i + 1]);
package = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
@ -220,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]) {
@ -278,21 +271,18 @@ public:
// should use Swig_warning() ?
Printf(stderr, "guile: Warning: -exportprimitive only makes sense with passive linkage without a scmstub.\n");
}
// Make sure `prefix' ends in an underscore
orig_len = strlen(prefix);
if (prefix[orig_len - 1] != '_') {
prefix[1 + orig_len] = 0;
prefix[orig_len] = '_';
// Make sure `prefix' ends in an underscore
if (prefix) {
const char *px = Char(prefix);
if (px[Len(prefix) - 1] != '_')
Printf(prefix, "_");
}
/* 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();
}
@ -332,15 +322,7 @@ public:
Swig_banner(f_begin);
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");
}
Printf(f_runtime, "\n\n#ifndef SWIGGUILE\n#define SWIGGUILE\n#endif\n\n");
/* Write out directives and declarations */
@ -409,7 +391,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -856,7 +837,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"));
@ -873,14 +854,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");
@ -963,11 +938,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);
@ -978,19 +949,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));
@ -998,19 +963,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);
@ -1018,15 +975,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")) {
@ -1049,11 +1002,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);
@ -1068,7 +1017,7 @@ public:
if (in_class)
goops_name = NewString(memberfunction_name);
else
goops_name = goopsNameMapping(proc_name, (char *) "");
goops_name = goopsNameMapping(proc_name, "");
String *primitive_name = NewString("");
if (primRenamer)
Printv(primitive_name, "primitive:", proc_name, NIL);
@ -1226,36 +1175,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);
@ -1263,7 +1203,7 @@ public:
// export wrapper into goops file
if (!in_class) { // only if the variable is not part of a class
String *class_name = SwigType_typedef_resolve_all(SwigType_base(t));
String *goops_name = goopsNameMapping(proc_name, (char *) "");
String *goops_name = goopsNameMapping(proc_name, "");
String *primitive_name = NewString("");
if (primRenamer)
Printv(primitive_name, "primitive:", NIL);
@ -1359,13 +1299,13 @@ public:
char *name = GetChar(n, "name");
char *iname = GetChar(n, "sym:name");
SwigType *type = Getattr(n, "type");
String *value = Getattr(n, "value");
String *rawval = Getattr(n, "rawval");
String *value = rawval ? rawval : Getattr(n, "value");
int constasvar = GetFlag(n, "feature:constasvar");
String *proc_name;
String *var_name;
String *rvalue;
Wrapper *f;
SwigType *nctype;
String *tm;
@ -1393,23 +1333,14 @@ public:
}
// See if there's a typemap
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
if (SwigType_type(nctype) == T_STRING) {
rvalue = NewStringf("\"%s\"", value);
} else if (SwigType_type(nctype) == T_CHAR && !is_enum_item) {
rvalue = NewStringf("\'%s\'", value);
} else {
rvalue = NewString(value);
}
if ((tm = Swig_typemap_lookup("constant", n, name, 0))) {
Replaceall(tm, "$source", rvalue);
Replaceall(tm, "$value", rvalue);
Replaceall(tm, "$source", value);
Replaceall(tm, "$value", value);
Replaceall(tm, "$target", name);
Printv(f_header, tm, "\n", NIL);
} else {
// Create variable and assign it a value
Printf(f_header, "static %s = %s;\n", SwigType_lstr(nctype, var_name), rvalue);
Printf(f_header, "static %s = (%s)(%s);\n", SwigType_str(type, var_name), SwigType_str(type, 0), value);
}
{
/* Hack alert: will cleanup later -- Dave */
@ -1429,7 +1360,6 @@ public:
Delete(var_name);
Delete(nctype);
Delete(proc_name);
Delete(rvalue);
DelWrapper(f);
return SWIG_OK;
}
@ -1489,12 +1419,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 */
@ -1730,28 +1658,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

@ -0,0 +1,183 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* interface.cxx
*
* This module contains support for the interface feature.
* This feature is used in language modules where the target language does not
* naturally support C++ style multiple inheritance, but does support inheritance
* from multiple interfaces.
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
static bool interface_feature_enabled = false;
/* -----------------------------------------------------------------------------
* collect_interface_methods()
*
* Create a list of all the methods from the base classes of class n that are
* marked as an interface. The resulting list is thus the list of methods that
* need to be implemented in order for n to be non-abstract.
* ----------------------------------------------------------------------------- */
static List *collect_interface_methods(Node *n) {
List *methods = NewList();
if (Hash *bases = Getattr(n, "interface:bases")) {
List *keys = Keys(bases);
for (Iterator base = First(keys); base.item; base = Next(base)) {
Node *cls = Getattr(bases, base.item);
if (cls == n)
continue;
for (Node *child = firstChild(cls); child; child = nextSibling(child)) {
if (Cmp(nodeType(child), "cdecl") == 0) {
if (GetFlag(child, "feature:ignore") || Getattr(child, "interface:owner"))
continue; // skip methods propagated to bases
Node *m = Copy(child);
set_nextSibling(m, NIL);
set_previousSibling(m, NIL);
Setattr(m, "interface:owner", cls);
Append(methods, m);
}
}
}
Delete(keys);
}
return methods;
}
/* -----------------------------------------------------------------------------
* collect_interface_bases
* ----------------------------------------------------------------------------- */
static void collect_interface_bases(Hash *bases, Node *n) {
if (Getattr(n, "feature:interface")) {
String *name = Getattr(n, "interface:name");
if (!Getattr(bases, name))
Setattr(bases, name, n);
}
if (List *baselist = Getattr(n, "bases")) {
for (Iterator base = First(baselist); base.item; base = Next(base)) {
if (!GetFlag(base.item, "feature:ignore")) {
if (Getattr(base.item, "feature:interface"))
collect_interface_bases(bases, base.item);
}
}
}
}
/* -----------------------------------------------------------------------------
* collect_interface_base_classes()
*
* Create a hash containing all the classes up the inheritance hierarchy
* marked with feature:interface (including this class n).
* Stops going up the inheritance chain as soon as a class is found without
* feature:interface.
* The idea is to find all the base interfaces that a class must implement.
* ----------------------------------------------------------------------------- */
static void collect_interface_base_classes(Node *n) {
if (Getattr(n, "feature:interface")) {
// check all bases are also interfaces
if (List *baselist = Getattr(n, "bases")) {
for (Iterator base = First(baselist); base.item; base = Next(base)) {
if (!GetFlag(base.item, "feature:ignore")) {
if (!Getattr(base.item, "feature:interface")) {
Swig_error(Getfile(n), Getline(n), "Base class '%s' of '%s' is not similarly marked as an interface.\n", SwigType_namestr(Getattr(base.item, "name")), SwigType_namestr(Getattr(n, "name")));
SWIG_exit(EXIT_FAILURE);
}
}
}
}
}
Hash *interface_bases = NewHash();
collect_interface_bases(interface_bases, n);
if (Len(interface_bases) == 0)
Delete(interface_bases);
else
Setattr(n, "interface:bases", interface_bases);
}
/* -----------------------------------------------------------------------------
* process_interface_name()
* ----------------------------------------------------------------------------- */
static void process_interface_name(Node *n) {
if (Getattr(n, "feature:interface")) {
String *interface_name = Getattr(n, "feature:interface:name");
if (!Len(interface_name)) {
Swig_error(Getfile(n), Getline(n), "The interface feature for '%s' is missing the name attribute.\n", SwigType_namestr(Getattr(n, "name")));
SWIG_exit(EXIT_FAILURE);
}
if (Strchr(interface_name, '%')) {
String *name = NewStringf(interface_name, Getattr(n, "sym:name"));
Setattr(n, "interface:name", name);
} else {
Setattr(n, "interface:name", interface_name);
}
}
}
/* -----------------------------------------------------------------------------
* Swig_interface_propagate_methods()
*
* Find all the base classes marked as an interface (with feature:interface) for
* class node n. For each of these, add all of its methods as methods of n so that
* n is not abstract. If class n is also marked as an interface, it will remain
* abstract and not have any methods added.
* ----------------------------------------------------------------------------- */
void Swig_interface_propagate_methods(Node *n) {
if (interface_feature_enabled) {
process_interface_name(n);
collect_interface_base_classes(n);
List *methods = collect_interface_methods(n);
bool is_interface = Getattr(n, "feature:interface") != 0;
for (Iterator mi = First(methods); mi.item; mi = Next(mi)) {
if (!is_interface && GetFlag(mi.item, "abstract"))
continue;
String *this_decl = Getattr(mi.item, "decl");
String *this_decl_resolved = SwigType_typedef_resolve_all(this_decl);
bool identically_overloaded_method = false; // true when a base class' method is implemented in n
if (SwigType_isfunction(this_decl_resolved)) {
String *name = Getattr(mi.item, "name");
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;
}
}
}
Delete(this_decl_resolved);
if (!identically_overloaded_method) {
// TODO: Fix if the method is overloaded with different arguments / has default args
appendChild(n, mi.item);
} else {
Delete(mi.item);
}
}
Delete(methods);
}
}
/* -----------------------------------------------------------------------------
* Swig_interface_feature_enable()
*
* Turn on interface feature support
* ----------------------------------------------------------------------------- */
void Swig_interface_feature_enable() {
interface_feature_enabled = true;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -11,8 +11,6 @@
* Main entry point to the SWIG core.
* ----------------------------------------------------------------------------- */
char cvsroot_main_cxx[] = "$Id$";
#include "swigconfig.h"
#if defined(_WIN32)
@ -51,6 +49,8 @@ int SwigRuntime = 0; // 0 = no option, 1 = -runtime, 2 = -noruntime
extern "C" {
extern String *ModuleName;
extern int ignore_nested_classes;
extern int kwargs_supported;
}
/* usage string split into multiple parts otherwise string is too big for some compilers */
@ -63,6 +63,8 @@ static const char *usage1 = (const char *) "\
-co <file> - Check <file> out of the SWIG library\n\
-copyctor - Automatically generate copy constructors wherever possible\n\
-cpperraswarn - Treat the preprocessor #error statement as #warning (default)\n\
-cppext <ext> - Change file extension of generated C++ files to <ext>\n\
(default is cxx, except for PHP which uses cpp)\n\
-copyright - Display copyright notices\n\
-debug-classes - Display information about the classes found in the interface\n\
-debug-module <n>- Display module parse tree at stages 1-4, <n> is a csv list of stages\n\
@ -80,6 +82,9 @@ static const char *usage1 = (const char *) "\
-directors - Turn on director mode for all the classes, mainly for testing\n\
-dirprot - Turn on wrapping of protected members for director classes (default)\n\
-D<symbol> - Define a symbol <symbol> (for conditional compilation)\n\
";
static const char *usage2 = (const char *) "\
-E - Preprocess only, does not generate wrapper code\n\
-external-runtime [file] - Export the SWIG runtime stack\n\
-fakeversion <v>- Make SWIG fake the program version number to <v>\n\
@ -87,9 +92,6 @@ static const char *usage1 = (const char *) "\
-features <list>- Set global features, where <list> is a comma separated list of\n\
features, eg -features directors,autodoc=1\n\
If no explicit value is given to the feature, a default of 1 is used\n\
";
static const char *usage2 = (const char *) "\
-fastdispatch - Enable fast dispatch mode to produce faster overload dispatcher code\n\
-Fmicrosoft - Display error/warning messages in Microsoft format\n\
-Fstandard - Display error/warning messages in commonly used format\n\
@ -101,6 +103,9 @@ static const char *usage2 = (const char *) "\
-importall - Follow all #include statements as imports\n\
-includeall - Follow all #include statements\n\
-l<ifile> - Include SWIG library file <ifile>\n\
";
static const char *usage3 = (const char *) "\
-macroerrors - Report errors inside macros\n\
-makedefault - Create default constructors/destructors (the default)\n\
-M - List all dependencies\n\
@ -109,6 +114,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\
@ -119,14 +125,14 @@ static const char *usage2 = (const char *) "\
-noexcept - Do not wrap exception specifiers\n\
-nofastdispatch - Disable fast dispatch mode (default)\n\
-nopreprocess - Skip the preprocessor step\n\
-notemplatereduce - Disable reduction of the typedefs in templates\n\
";
static const char *usage3 = (const char *) "\
-notemplatereduce - Disable reduction of the typedefs in templates\n\
static const char *usage4 = (const char *) "\
-O - Enable the optimization options: \n\
-fastdispatch -fvirtual \n\
-o <outfile> - Set name of the output file to <outfile>\n\
-oh <headfile> - Set name of the output header file to <headfile>\n\
-o <outfile> - Set name of C/C++ output file to <outfile>\n\
-oh <headfile> - Set name of C++ output header file for directors to <headfile>\n\
-outcurrentdir - Set default output dir to current dir instead of input file's path\n\
-outdir <dir> - Set language specific files output directory to <dir>\n\
-pcreversion - Display PCRE version information\n\
@ -160,9 +166,9 @@ static String *SwigLib = 0; // Library directory
static String *SwigLibWinUnix = 0; // Extra library directory on Windows
static int freeze = 0;
static String *lang_config = 0;
static char *hpp_extension = (char *) "h";
static char *cpp_extension = (char *) "cxx";
static char *depends_extension = (char *) "d";
static const char *hpp_extension = "h";
static const char *cpp_extension = "cxx";
static const char *depends_extension = "d";
static String *outdir = 0;
static String *xmlout = 0;
static int outcurrentdir = 0;
@ -187,6 +193,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;
@ -199,22 +206,24 @@ static List *libfiles = 0;
static List *all_output_files = 0;
/* -----------------------------------------------------------------------------
* check_suffix()
* check_extension()
*
* Checks the suffix of a file to see if we should emit extern declarations.
* Checks the extension of a file to see if we should emit extern declarations.
* ----------------------------------------------------------------------------- */
static int check_suffix(String *filename) {
static bool check_extension(String *filename) {
bool wanted = false;
const char *name = Char(filename);
const char *c;
if (!name)
return 0;
c = Swig_file_suffix(name);
String *extension = Swig_file_extension(name);
const char *c = Char(extension);
if ((strcmp(c, ".c") == 0) ||
(strcmp(c, ".C") == 0) || (strcmp(c, ".cc") == 0) || (strcmp(c, ".cxx") == 0) || (strcmp(c, ".c++") == 0) || (strcmp(c, ".cpp") == 0)) {
return 1;
wanted = true;
}
return 0;
Delete(extension);
return wanted;
}
/* -----------------------------------------------------------------------------
@ -283,15 +292,16 @@ static unsigned int decode_numbers_list(String *numlist) {
}
/* -----------------------------------------------------------------------------
* Sets the output directory for language specific (proxy) files if not set and
* corrects the directory name and adds trailing file separator if necessary.
* Sets the output directory for language specific (proxy) files from the
* C wrapper file if not set and corrects the directory name and adds a trailing
* file separator if necessary.
* ----------------------------------------------------------------------------- */
static void configure_outdir(const String *c_wrapper_file_dir) {
static void configure_outdir(const String *c_wrapper_outfile) {
// Use the C wrapper file's directory if the output directory has not been set by user
if (!outdir || Len(outdir) == 0)
outdir = NewString(c_wrapper_file_dir);
outdir = Swig_file_dirname(c_wrapper_outfile);
Swig_filename_correct(outdir);
@ -320,7 +330,7 @@ const String *SWIG_output_directory() {
}
void SWIG_config_cppext(const char *ext) {
cpp_extension = (char *) ext;
cpp_extension = ext;
}
List *SWIG_output_files() {
@ -403,7 +413,7 @@ static void SWIG_dump_runtime() {
s = Swig_include_sys("swiglabels.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'swiglabels.swg'\n");
Close(runtime);
Delete(runtime);
SWIG_exit(EXIT_FAILURE);
}
Printf(runtime, "%s", s);
@ -412,7 +422,7 @@ static void SWIG_dump_runtime() {
s = Swig_include_sys("swigerrors.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'swigerrors.swg'\n");
Close(runtime);
Delete(runtime);
SWIG_exit(EXIT_FAILURE);
}
Printf(runtime, "%s", s);
@ -421,7 +431,7 @@ static void SWIG_dump_runtime() {
s = Swig_include_sys("swigrun.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'swigrun.swg'\n");
Close(runtime);
Delete(runtime);
SWIG_exit(EXIT_FAILURE);
}
Printf(runtime, "%s", s);
@ -434,13 +444,12 @@ static void SWIG_dump_runtime() {
s = Swig_include_sys("runtime.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'runtime.swg'\n");
Close(runtime);
Delete(runtime);
SWIG_exit(EXIT_FAILURE);
}
Printf(runtime, "%s", s);
Delete(s);
Close(runtime);
Delete(runtime);
SWIG_exit(EXIT_SUCCESS);
}
@ -462,7 +471,7 @@ void SWIG_getoptions(int argc, char *argv[]) {
Swig_mark_arg(i);
} else if (strncmp(argv[i], "-D", 2) == 0) {
String *d = NewString(argv[i] + 2);
Replace(d, (char *) "=", (char *) " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Replace(d, "=", " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Preprocessor_define((DOH *) d, 0);
Delete(d);
// Create a symbol
@ -481,6 +490,10 @@ void SWIG_getoptions(int argc, char *argv[]) {
Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
Swig_cparse_cplusplus(1);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-c++out") == 0) {
// Undocumented
Swig_cparse_cplusplusout(1);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-fcompact") == 0) {
Wrapper_compact_print_mode_set(1);
Swig_mark_arg(i);
@ -496,9 +509,6 @@ void SWIG_getoptions(int argc, char *argv[]) {
} else if (strcmp(argv[i], "-naturalvar") == 0) {
Wrapper_naturalvar_mode_set(1);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nonaturalvar") == 0) {
Wrapper_naturalvar_mode_set(0);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-directors") == 0) {
SWIG_setfeature("feature:director", "1");
Wrapper_director_mode_set(1);
@ -585,7 +595,7 @@ void SWIG_getoptions(int argc, char *argv[]) {
Swig_filename_correct(outfile_name);
if (!outfile_name_h || !dependencies_file) {
char *ext = strrchr(Char(outfile_name), '.');
String *basename = ext ? NewStringWithSize(Char(outfile_name), Char(ext) - Char(outfile_name)) : NewString(outfile_name);
String *basename = ext ? NewStringWithSize(Char(outfile_name), (int)(Char(ext) - Char(outfile_name))) : NewString(outfile_name);
if (!dependencies_file) {
dependencies_file = NewStringf("%s.%s", basename, depends_extension);
}
@ -673,6 +683,15 @@ void SWIG_getoptions(int argc, char *argv[]) {
} else if (strcmp(argv[i], "-nocpperraswarn") == 0) {
Preprocessor_error_as_warning(0);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-cppext") == 0) {
Swig_mark_arg(i);
if (argv[i + 1]) {
SWIG_config_cppext(argv[i + 1]);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if ((strcmp(argv[i], "-debug-typemap") == 0) || (strcmp(argv[i], "-debug_typemap") == 0) || (strcmp(argv[i], "-tm_debug") == 0)) {
tm_debug = 1;
Swig_mark_arg(i);
@ -712,6 +731,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]) {
@ -843,6 +865,7 @@ void SWIG_getoptions(int argc, char *argv[]) {
fputs(usage1, stdout);
fputs(usage2, stdout);
fputs(usage3, stdout);
fputs(usage4, stdout);
Swig_mark_arg(i);
help = 1;
}
@ -850,10 +873,6 @@ void SWIG_getoptions(int argc, char *argv[]) {
}
}
int SWIG_main(int argc, char *argv[], Language *l) {
char *c;
@ -880,7 +899,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
String *vers = NewString("SWIG_VERSION 0x");
int count = 0;
while (token) {
int len = strlen(token);
int len = (int)strlen(token);
assert(len == 1 || len == 2);
Printf(vers, "%s%s", (len == 1) ? "0" : "", token);
token = strtok(NULL, ".");
@ -898,6 +917,11 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Wrapper_director_mode_set(0);
Wrapper_director_protected_mode_set(1);
// Inform the parser if the nested classes should be ignored unless explicitly told otherwise via feature:flatnested
ignore_nested_classes = l->nestedClassesSupport() == Language::NCS_Unknown ? 1 : 0;
kwargs_supported = l->kwargsSupport() ? 1 : 0;
// Create Library search directories
// Check for SWIG_LIB environment variable
@ -942,6 +966,11 @@ int SWIG_main(int argc, char *argv[], Language *l) {
// Don't check for an input file if -external-runtime is passed
Swig_check_options(external_runtime ? 0 : 1);
if (CPlusPlus && cparse_cplusplusout) {
Printf(stderr, "The -c++out option is for C input but C++ input has been requested via -c++\n");
SWIG_exit(EXIT_FAILURE);
}
install_opts(argc, argv);
// Add language dependent directory to the search path
@ -1009,7 +1038,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (Verbose)
Printf(stdout, "'%s' checked out from the SWIG library.\n", outfile);
Printv(f_outfile, s, NIL);
Close(f_outfile);
Delete(f_outfile);
}
}
}
@ -1069,7 +1098,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
String *outfile;
File *f_dependencies_file = 0;
char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(input_file): Char(input_file));
String *inputfile_filename = outcurrentdir ? Swig_file_filename(input_file): Copy(input_file);
String *basename = Swig_file_basename(inputfile_filename);
if (!outfile_name) {
if (CPlusPlus || lang->cplus_runtime_mode()) {
outfile = NewStringf("%s_wrap.%s", basename, cpp_extension);
@ -1100,20 +1130,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)
Close(f_dependencies_file);
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
@ -1142,6 +1185,12 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Printf(stdout, "debug-module stage 1\n");
Swig_print_tree(Getattr(top, "module"));
}
if (!CPlusPlus) {
if (Verbose)
Printf(stdout, "Processing unnamed structs...\n");
Swig_nested_name_unnamed_c_structs(top);
}
Swig_extend_unused_check();
if (Verbose) {
Printf(stdout, "Processing types...\n");
@ -1162,11 +1211,17 @@ int SWIG_main(int argc, char *argv[], Language *l) {
}
Swig_default_allocators(top);
if (CPlusPlus) {
if (Verbose)
Printf(stdout, "Processing nested classes...\n");
Swig_nested_process_classes(top);
}
if (dump_top & STAGE3) {
Printf(stdout, "debug-top stage 3\n");
Swig_print_tree(top);
}
if (dump_module & STAGE3) {
if (top && (dump_module & STAGE3)) {
Printf(stdout, "debug-module stage 3\n");
Swig_print_tree(Getattr(top, "module"));
}
@ -1175,7 +1230,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Printf(stdout, "Generating wrappers...\n");
}
if (dump_classes) {
if (top && dump_classes) {
Hash *classes = Getattr(top, "classes");
if (classes) {
Printf(stdout, "Classes\n");
@ -1221,7 +1276,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Setattr(top, "infile", infile); // Note: if nopreprocess then infile is the original input file, otherwise input_file
Setattr(top, "inputfile", input_file);
char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(infile): Char(infile));
String *infile_filename = outcurrentdir ? Swig_file_filename(infile): Copy(infile);
String *basename = Swig_file_basename(infile_filename);
if (!outfile_name) {
if (CPlusPlus || lang->cplus_runtime_mode()) {
Setattr(top, "outfile", NewStringf("%s_wrap.%s", basename, cpp_extension));
@ -1236,19 +1292,21 @@ int SWIG_main(int argc, char *argv[], Language *l) {
} else {
Setattr(top, "outfile_h", outfile_name_h);
}
configure_outdir(Swig_file_dirname(Getattr(top, "outfile")));
configure_outdir(Getattr(top, "outfile"));
if (Swig_contract_mode_get()) {
Swig_contracts(top);
}
// Check the suffix for a c/c++ file. If so, we're going to declare everything we see as "extern"
ForceExtern = check_suffix(input_file);
// Check the extension for a c/c++ file. If so, we're going to declare everything we see as "extern"
ForceExtern = check_extension(input_file);
lang->top(top);
if (browse) {
Swig_browser(top, 0);
}
Delete(infile_filename);
Delete(basename);
}
}
if (dump_lang_symbols) {
@ -1285,7 +1343,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
int i;
for (i = 0; i < Len(all_output_files); i++)
Printf(f_outfiles, "%s\n", Getitem(all_output_files, i));
Close(f_outfiles);
Delete(f_outfiles);
}
}

View file

@ -11,8 +11,6 @@
* Modula3 language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_modula3_cxx[] = "$Id$";
/*
Text formatted with
indent -sob -br -ce -nut -npsl
@ -206,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'
@ -270,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),
@ -835,7 +827,7 @@ MODULA3():
scanConstant(file, n);
Printf(file, " return 0;\n");
Printf(file, "}\n");
Close(file);
Delete(file);
return SWIG_OK;
}
@ -870,7 +862,7 @@ MODULA3():
by SWIG with option -generaterename. */\n\
\n", input_file);
scanRename(file, n);
Close(file);
Delete(file);
return SWIG_OK;
}
@ -900,7 +892,7 @@ MODULA3():
by SWIG with option -generatetypemap. */\n\
\n", input_file);
scanTypemap(file, n);
Close(file);
Delete(file);
return SWIG_OK;
}
@ -966,9 +958,7 @@ MODULA3():
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGMODULA3\n");
Printf(f_runtime, "\n");
Printf(f_runtime, "\n\n#ifndef SWIGMODULA3\n#define SWIGMODULA3\n#endif\n\n");
Swig_name_register("wrapper", "Modula3_%f");
if (old_variable_names) {
@ -991,7 +981,7 @@ MODULA3():
// Generate m3makefile
// This will be unnecessary if SWIG is invoked from Quake.
{
File *file = openWriteFile(NewStringf("%sm3makefile", Swig_file_dirname(outfile)));
File *file = openWriteFile(NewStringf("%sm3makefile", SWIG_output_directory()));
Printf(file, "%% automatically generated quake file for %s\n\n", name);
@ -1009,12 +999,12 @@ MODULA3():
} else {
Printf(file, "library(\"m3%s\")\n", name);
}
Close(file);
Delete(file);
}
// Generate the raw interface
{
File *file = openWriteFile(NewStringf("%s%s.i3", Swig_file_dirname(outfile), m3raw_name));
File *file = openWriteFile(NewStringf("%s%s.i3", SWIG_output_directory(), m3raw_name));
emitBanner(file);
@ -1027,12 +1017,12 @@ MODULA3():
Printv(file, m3raw_intf.f, NIL);
Printf(file, "\nEND %s.\n", m3raw_name);
Close(file);
Delete(file);
}
// Generate the raw module
{
File *file = openWriteFile(NewStringf("%s%s.m3", Swig_file_dirname(outfile), m3raw_name));
File *file = openWriteFile(NewStringf("%s%s.m3", SWIG_output_directory(), m3raw_name));
emitBanner(file);
@ -1045,12 +1035,12 @@ MODULA3():
Printv(file, m3raw_impl.f, NIL);
Printf(file, "BEGIN\nEND %s.\n", m3raw_name);
Close(file);
Delete(file);
}
// Generate the interface for the comfort wrappers
{
File *file = openWriteFile(NewStringf("%s%s.i3", Swig_file_dirname(outfile), m3wrap_name));
File *file = openWriteFile(NewStringf("%s%s.i3", SWIG_output_directory(), m3wrap_name));
emitBanner(file);
@ -1075,12 +1065,12 @@ MODULA3():
// Finish off the class
Printf(file, "\nEND %s.\n", m3wrap_name);
Close(file);
Delete(file);
}
// Generate the wrapper routines implemented in Modula 3
{
File *file = openWriteFile(NewStringf("%s%s.m3", Swig_file_dirname(outfile), m3wrap_name));
File *file = openWriteFile(NewStringf("%s%s.m3", SWIG_output_directory(), m3wrap_name));
emitBanner(file);
@ -1096,7 +1086,7 @@ MODULA3():
Printv(file, m3wrap_impl.f, NIL);
Printf(file, "\nBEGIN\nEND %s.\n", m3wrap_name);
Close(file);
Delete(file);
}
if (upcasts_code)
@ -1162,7 +1152,6 @@ MODULA3():
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -1416,25 +1405,12 @@ MODULA3():
}
}
if (Cmp(nodeType(n), "constant") == 0) {
// Wrapping a constant hack
Swig_save("functionWrapper", n, "wrap:action", NIL);
// below based on Swig_VargetToFunction()
SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n));
Setattr(n, "wrap:action", NewStringf("%s = (%s)(%s);", Swig_cresult_name(), SwigType_lstr(ty, 0), Getattr(n, "value")));
}
Setattr(n, "wrap:name", wname);
// Now write code to make the function call
if (!native_function_flag) {
String *actioncode = emit_action(n);
if (Cmp(nodeType(n), "constant") == 0) {
Swig_restore(n);
}
/* Return value if necessary */
String *tm;
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
@ -1787,19 +1763,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;
@ -2030,7 +1993,7 @@ MODULA3():
if (oldname != NIL) {
Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "The value <%s> is already assigned to <%s>.\n", value, oldname);
}
//printf("items %lx, set %s = %s\n", (long) items, Char(newvalue), Char(m3name));
//printf("items %p, set %s = %s\n", items, Char(newvalue), Char(m3name));
Setattr(items, newvalue, m3name);
if (max < numvalue) {
max = numvalue;
@ -2097,7 +2060,7 @@ MODULA3():
stem += Len(pat.prefix);
}
String *newname;
if (Strcmp(srcstyle, "underscore") == 0) {
if (srcstyle && Strcmp(srcstyle, "underscore") == 0) {
if (newprefix != NIL) {
String *newstem = nameToModula3(stem, true);
newname = NewStringf("%s%s", newprefix, newstem);
@ -2213,18 +2176,24 @@ MODULA3():
/* Deal with inheritance */
List *baselist = Getattr(n, "bases");
if (baselist != NIL) {
if (baselist) {
Iterator base = First(baselist);
c_baseclassname = Getattr(base.item, "name");
baseclass = Copy(getProxyName(c_baseclassname));
if (baseclass) {
c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
}
base = Next(base);
if (base.item != NIL) {
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n",
name, Getattr(base.item, "name"));
while (base.item) {
if (!GetFlag(base.item, "feature:ignore")) {
String *baseclassname = Getattr(base.item, "name");
if (!c_baseclassname) {
c_baseclassname = baseclassname;
baseclass = Copy(getProxyName(baseclassname));
if (baseclass)
c_baseclass = SwigType_namestr(baseclassname);
} else {
/* Warn about multiple inheritance for additional base class(es) */
String *proxyclassname = Getattr(n, "classtypeobj");
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s, base %s ignored. Multiple inheritance is not supported in Modula 3.\n", SwigType_namestr(proxyclassname), SwigType_namestr(baseclassname));
}
}
base = Next(base);
}
}
@ -2236,7 +2205,7 @@ MODULA3():
const String *pure_baseclass = typemapLookup(n, "m3base", name, WARN_NONE);
if (hasContent(pure_baseclass) && hasContent(baseclass)) {
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", name, pure_baseclass);
"Warning for %s, base %s ignored. Multiple inheritance is not supported in Modula 3.\n", name, pure_baseclass);
}
// Pure Modula 3 interfaces
const String *pure_interfaces = typemapLookup(n, derived ? "m3interfaces_derived" : "m3interfaces",
@ -2388,7 +2357,7 @@ MODULA3():
SWIG_exit(EXIT_FAILURE);
}
String *filen = NewStringf("%s%s.m3", Swig_file_dirname(outfile), proxy_class_name);
String *filen = NewStringf("%s%s.m3", SWIG_output_directory(), proxy_class_name);
f_proxy = NewFile(filen, "w", SWIG_output_files());
if (!f_proxy) {
FileErrorDisplay(filen);
@ -2461,12 +2430,14 @@ MODULA3():
/* Look for the first (principal?) base class -
Modula 3 does not support multiple inheritance */
Iterator base = First(baselist);
Append(baseclassname, Getattr(base.item, "sym:name"));
base = Next(base);
if (base.item != NIL) {
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n",
proxy_class_name, Getattr(base.item, "name"));
if (base.item) {
Append(baseclassname, Getattr(base.item, "sym:name"));
base = Next(base);
if (base.item) {
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s, base %s ignored. Multiple inheritance is not supported in Modula 3.\n",
proxy_class_name, Getattr(base.item, "name"));
}
}
}
}
@ -2555,7 +2526,7 @@ MODULA3():
Printv(f_proxy, proxy_class_def, proxy_class_code, NIL);
Printf(f_proxy, "}\n");
Close(f_proxy);
Delete(f_proxy);
f_proxy = NULL;
Delete(proxy_class_name);
@ -3528,6 +3499,7 @@ MODULA3():
m3wrap_impl.enterBlock(no_block);
if (proxy_flag && global_variable_flag) {
setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(NSPACE_TODO, variable_name)) == 0);
// Properties
if (setter_flag) {
// Setter method
@ -3638,35 +3610,6 @@ MODULA3():
return substitution_performed;
}
/* -----------------------------------------------------------------------------
* makeParameterName()
*
* Inputs:
* n - Node
* p - parameter node
* arg_num - parameter argument number
* Return:
* arg - a unique parameter name
* ----------------------------------------------------------------------------- */
String *makeParameterName(Node *n, Parm *p, int arg_num) {
// Use C parameter name unless it is a duplicate or an empty parameter name
String *pn = Getattr(p, "name");
int count = 0;
ParmList *plist = Getattr(n, "parms");
while (plist) {
if ((Cmp(pn, Getattr(plist, "name")) == 0))
count++;
plist = nextSibling(plist);
}
String *arg = (!pn || (count > 1)) ? NewStringf("arg%d",
arg_num) : Copy(Getattr(p,
"name"));
return arg;
}
/* -----------------------------------------------------------------------------
* attachParameterNames()
*
@ -3781,7 +3724,7 @@ MODULA3():
Setfile(n, input_file);
Setline(n, line_number);
String *filen = NewStringf("%s%s.m3", Swig_file_dirname(outfile), classname);
String *filen = NewStringf("%s%s.m3", SWIG_output_directory(), classname);
File *f_swigtype = NewFile(filen, "w", SWIG_output_files());
if (!f_swigtype) {
FileErrorDisplay(filen);
@ -3811,7 +3754,7 @@ MODULA3():
Replaceall(swigtype, "$m3classname", classname);
Printv(f_swigtype, swigtype, NIL);
Close(f_swigtype);
Delete(f_swigtype);
Delete(filen);
Delete(swigtype);
}
@ -3973,7 +3916,7 @@ extern "C" Language *swig_modula3(void) {
* Static member variables
* ----------------------------------------------------------------------------- */
const char *MODULA3::usage = (char *) "\
const char *MODULA3::usage = "\
Modula 3 Options (available with -modula3)\n\
-generateconst <file> - Generate code for computing numeric values of constants\n\
-generaterename <file> - Generate suggestions for %rename\n\

View file

@ -11,8 +11,6 @@
* This file is responsible for the module system.
* ----------------------------------------------------------------------------- */
char cvsroot_module_cxx[] = "$Id$";
#include "swigmod.h"
struct Module {

View file

@ -11,13 +11,11 @@
* Mzscheme language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_mzscheme_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
static const char *usage = (char *) "\
static const char *usage = "\
Mzscheme Options (available with -mzscheme)\n\
-declaremodule - Create extension that declares a module\n\
-dynamic-load <library>,[library,...] - Do not link with these libraries, dynamic load\n\
@ -33,14 +31,12 @@ static String *convert_proto_tab = 0;
static String *struct_name = 0;
static String *mangled_struct_name = 0;
static char *prefix = 0;
static String *prefix = 0;
static bool declaremodule = false;
static bool noinit = false;
//DLOPEN PATCH
static char *load_libraries = NULL;
//DLOPEN PATCH
static String *load_libraries = NULL;
static String *module = 0;
static char *mzscheme_path = (char *) "mzscheme";
static const char *mzscheme_path = "mzscheme";
static String *init_func_def = 0;
static File *f_begin = 0;
@ -75,8 +71,7 @@ public:
SWIG_exit(0);
} else if (strcmp(argv[i], "-prefix") == 0) {
if (argv[i + 1]) {
prefix = new char[strlen(argv[i + 1]) + 2];
strcpy(prefix, argv[i + 1]);
prefix = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
@ -90,26 +85,26 @@ public:
noinit = true;
Swig_mark_arg(i);
}
// DLOPEN PATCH
else if (strcmp(argv[i], "-dynamic-load") == 0) {
load_libraries = new char[strlen(argv[i + 1]) + 2];
strcpy(load_libraries, argv[i + 1]);
Swig_mark_arg(i++);
Swig_mark_arg(i);
if (argv[i + 1]) {
Delete(load_libraries);
load_libraries = NewString(argv[i + 1]);
Swig_mark_arg(i++);
Swig_mark_arg(i);
} else {
Swig_arg_error();
}
}
// DLOPEN PATCH
}
}
// If a prefix has been specified make sure it ends in a '_'
// If a prefix has been specified make sure it ends in a '_' (not actually used!)
if (prefix) {
if (prefix[strlen(prefix)] != '_') {
prefix[strlen(prefix) + 1] = 0;
prefix[strlen(prefix)] = '_';
}
const char *px = Char(prefix);
if (px[Len(prefix) - 1] != '_')
Printf(prefix, "_");
} else
prefix = (char *) "swig_";
prefix = NewString("swig_");
// Add a symbol for this module
@ -155,9 +150,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGMZSCHEME\n");
Printf(f_runtime, "\n");
Printf(f_runtime, "\n\n#ifndef SWIGMZSCHEME\n#define SWIGMZSCHEME\n#endif\n\n");
module = Getattr(n, "name");
@ -177,11 +170,9 @@ public:
Printf(f_init, "\treturn scheme_void;\n}\n");
Printf(f_init, "Scheme_Object *scheme_initialize(Scheme_Env *env) {\n");
// DLOPEN PATCH
if (load_libraries) {
Printf(f_init, "mz_set_dlopen_libraries(\"%s\");\n", load_libraries);
}
// DLOPEN PATCH
Printf(f_init, "\treturn scheme_reload(env);\n");
Printf(f_init, "}\n");
@ -203,7 +194,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -245,14 +235,12 @@ public:
int numreq;
String *overname = 0;
// PATCH DLOPEN
if (load_libraries) {
ParmList *parms = Getattr(n, "parms");
SwigType *type = Getattr(n, "type");
String *name = NewString("caller");
Setattr(n, "wrap:action", Swig_cresult(type, Swig_cresult_name(), Swig_cfunction_call(name, parms)));
}
// PATCH DLOPEN
// Make a wrapper name for this
String *wname = Swig_name_wrapper(iname);
@ -292,7 +280,6 @@ public:
numargs = emit_num_arguments(l);
numreq = emit_num_required(l);
// DLOPEN PATCH
/* Add the holder for the pointer to the function to be opened */
if (load_libraries) {
Wrapper_add_local(f, "_function_loaded", "static int _function_loaded=(1==0)");
@ -303,19 +290,16 @@ public:
Wrapper_add_local(f, "caller", SwigType_lstr(d, func)); /*"(*caller)()")); */
}
}
// DLOPEN PATCH
// adds local variables
Wrapper_add_local(f, "lenv", "int lenv = 1");
Wrapper_add_local(f, "values", "Scheme_Object *values[MAXVALUES]");
// DLOPEN PATCH
if (load_libraries) {
Printf(f->code, "if (!_function_loaded) { _the_function=mz_load_function(\"%s\");_function_loaded=(1==1); }\n", iname);
Printf(f->code, "if (!_the_function) { scheme_signal_error(\"Cannot load C function '%s'\"); }\n", iname);
Printf(f->code, "caller=_the_function;\n");
}
// DLOPEN PATCH
// Now write code to extract the parameters (this is super ugly)

453
Source/Modules/nested.cxx Normal file
View file

@ -0,0 +1,453 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* nested.cxx
*
* Nested structs support
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
#include "cparse.h"
// Nested classes processing section
static Hash *classhash = 0;
static String *make_name(Node *n, String *name, SwigType *decl) {
int destructor = name && (*(Char(name)) == '~');
if (String *yyrename = Getattr(n, "class_rename")) {
String *s = NewString(yyrename);
Delattr(n, "class_rename");
if (destructor && (*(Char(s)) != '~')) {
Insert(s, 0, "~");
}
return s;
}
if (!name)
return 0;
return Swig_name_make(n, 0, name, decl, 0);
}
// C version of add_symbols()
static void add_symbols_c(Node *n) {
String *decl;
String *wrn = 0;
String *symname = 0;
int iscdecl = Cmp(nodeType(n), "cdecl") == 0;
Setattr(n, "ismember", "1");
Setattr(n, "access", "public");
if (Getattr(n, "sym:name"))
return;
decl = Getattr(n, "decl");
if (!SwigType_isfunction(decl)) {
String *name = Getattr(n, "name");
String *makename = Getattr(n, "parser:makename");
if (iscdecl) {
String *storage = Getattr(n, "storage");
if (Cmp(storage, "typedef") == 0) {
Setattr(n, "kind", "typedef");
} else {
SwigType *type = Getattr(n, "type");
String *value = Getattr(n, "value");
Setattr(n, "kind", "variable");
if (value && Len(value)) {
Setattr(n, "hasvalue", "1");
}
if (type) {
SwigType *ty;
SwigType *tmp = 0;
if (decl) {
ty = tmp = Copy(type);
SwigType_push(ty, decl);
} else {
ty = type;
}
if (!SwigType_ismutable(ty)) {
SetFlag(n, "hasconsttype");
SetFlag(n, "feature:immutable");
}
if (tmp)
Delete(tmp);
}
if (!type) {
Printf(stderr, "notype name %s\n", name);
}
}
}
Swig_features_get(Swig_cparse_features(), 0, name, 0, n);
if (makename) {
symname = make_name(n, makename, 0);
Delattr(n, "parser:makename"); /* temporary information, don't leave it hanging around */
} else {
makename = name;
symname = make_name(n, makename, 0);
}
if (!symname) {
symname = Copy(Getattr(n, "unnamed"));
}
if (symname) {
wrn = Swig_name_warning(n, 0, symname, 0);
}
} else {
String *name = Getattr(n, "name");
SwigType *fdecl = Copy(decl);
SwigType *fun = SwigType_pop_function(fdecl);
if (iscdecl) {
Setattr(n, "kind", "function");
}
Swig_features_get(Swig_cparse_features(), 0, name, fun, n);
symname = make_name(n, name, fun);
wrn = Swig_name_warning(n, 0, symname, fun);
Delete(fdecl);
Delete(fun);
}
if (!symname)
return;
if (GetFlag(n, "feature:ignore")) {
/* Only add to C symbol table and continue */
Swig_symbol_add(0, n);
} else if (strncmp(Char(symname), "$ignore", 7) == 0) {
char *c = Char(symname) + 7;
SetFlag(n, "feature:ignore");
if (strlen(c)) {
SWIG_WARN_NODE_BEGIN(n);
Swig_warning(0, Getfile(n), Getline(n), "%s\n", c + 1);
SWIG_WARN_NODE_END(n);
}
Swig_symbol_add(0, n);
} else {
Node *c;
if ((wrn) && (Len(wrn))) {
String *metaname = symname;
if (!Getmeta(metaname, "already_warned")) {
SWIG_WARN_NODE_BEGIN(n);
Swig_warning(0, Getfile(n), Getline(n), "%s\n", wrn);
SWIG_WARN_NODE_END(n);
Setmeta(metaname, "already_warned", "1");
}
}
c = Swig_symbol_add(symname, n);
if (c != n) {
/* symbol conflict attempting to add in the new symbol */
if (Getattr(n, "sym:weak")) {
Setattr(n, "sym:name", symname);
} else {
String *e = NewStringEmpty();
String *en = NewStringEmpty();
String *ec = NewStringEmpty();
int redefined = Swig_need_redefined_warn(n, c, true);
if (redefined) {
Printf(en, "Identifier '%s' redefined (ignored)", symname);
Printf(ec, "previous definition of '%s'", symname);
} else {
Printf(en, "Redundant redeclaration of '%s'", symname);
Printf(ec, "previous declaration of '%s'", symname);
}
if (Cmp(symname, Getattr(n, "name"))) {
Printf(en, " (Renamed from '%s')", SwigType_namestr(Getattr(n, "name")));
}
Printf(en, ",");
if (Cmp(symname, Getattr(c, "name"))) {
Printf(ec, " (Renamed from '%s')", SwigType_namestr(Getattr(c, "name")));
}
Printf(ec, ".");
SWIG_WARN_NODE_BEGIN(n);
if (redefined) {
Swig_warning(WARN_PARSE_REDEFINED, Getfile(n), Getline(n), "%s\n", en);
Swig_warning(WARN_PARSE_REDEFINED, Getfile(c), Getline(c), "%s\n", ec);
} else {
Swig_warning(WARN_PARSE_REDUNDANT, Getfile(n), Getline(n), "%s\n", en);
Swig_warning(WARN_PARSE_REDUNDANT, Getfile(c), Getline(c), "%s\n", ec);
}
SWIG_WARN_NODE_END(n);
Printf(e, "%s:%d:%s\n%s:%d:%s\n", Getfile(n), Getline(n), en, Getfile(c), Getline(c), ec);
Setattr(n, "error", e);
Delete(e);
Delete(en);
Delete(ec);
}
}
}
Delete(symname);
}
/* Strips C-style and C++-style comments from string in-place. */
static void strip_comments(char *string) {
int state = 0;
/*
* 0 - not in comment
* 1 - in c-style comment
* 2 - in c++-style comment
* 3 - in string
* 4 - after reading / not in comments
* 5 - after reading * in c-style comments
* 6 - after reading \ in strings
*/
char *c = string;
while (*c) {
switch (state) {
case 0:
if (*c == '\"')
state = 3;
else if (*c == '/')
state = 4;
break;
case 1:
if (*c == '*')
state = 5;
*c = ' ';
break;
case 2:
if (*c == '\n')
state = 0;
else
*c = ' ';
break;
case 3:
if (*c == '\"')
state = 0;
else if (*c == '\\')
state = 6;
break;
case 4:
if (*c == '/') {
*(c - 1) = ' ';
*c = ' ';
state = 2;
} else if (*c == '*') {
*(c - 1) = ' ';
*c = ' ';
state = 1;
} else
state = 0;
break;
case 5:
if (*c == '/')
state = 0;
else
state = 1;
*c = ' ';
break;
case 6:
state = 3;
break;
}
++c;
}
}
// Create a %insert with a typedef to make a new name visible to C
static Node *create_insert(Node *n, bool noTypedef = false) {
// format a typedef
String *ccode = Getattr(n, "code");
Push(ccode, " ");
if (noTypedef) {
Push(ccode, Getattr(n, "name"));
Push(ccode, " ");
Push(ccode, Getattr(n, "kind"));
} else {
Push(ccode, Getattr(n, "kind"));
Push(ccode, "typedef ");
Append(ccode, " ");
Append(ccode, Getattr(n, "tdname"));
}
Append(ccode, ";");
/* Strip comments - further code may break in presence of comments. */
strip_comments(Char(ccode));
/* Make all SWIG created typedef structs/unions/classes unnamed else
redefinition errors occur - nasty hack alert. */
if (!noTypedef) {
const char *types_array[3] = { "struct", "union", "class" };
for (int i = 0; i < 3; i++) {
char *code_ptr = Char(ccode);
while (code_ptr) {
/* Replace struct name (as in 'struct name {...}' ) with whitespace
name will be between struct and opening brace */
code_ptr = strstr(code_ptr, types_array[i]);
if (code_ptr) {
char *open_bracket_pos;
code_ptr += strlen(types_array[i]);
open_bracket_pos = strchr(code_ptr, '{');
if (open_bracket_pos) {
/* Make sure we don't have something like struct A a; */
char *semi_colon_pos = strchr(code_ptr, ';');
if (!(semi_colon_pos && (semi_colon_pos < open_bracket_pos)))
while (code_ptr < open_bracket_pos)
*code_ptr++ = ' ';
}
}
}
}
}
{
/* Remove SWIG directive %constant which may be left in the SWIG created typedefs */
char *code_ptr = Char(ccode);
while (code_ptr) {
code_ptr = strstr(code_ptr, "%constant");
if (code_ptr) {
char *directive_end_pos = strchr(code_ptr, ';');
if (directive_end_pos) {
while (code_ptr <= directive_end_pos)
*code_ptr++ = ' ';
}
}
}
}
Node *newnode = NewHash();
set_nodeType(newnode, "insert");
Setfile(newnode, Getfile(n));
Setline(newnode, Getline(n));
String *code = NewStringEmpty();
Wrapper_pretty_print(ccode, code);
Setattr(newnode, "code", code);
Delete(code);
Delattr(n, "code");
return newnode;
}
static void insertNodeAfter(Node *n, Node *c) {
Node *g = parentNode(n);
set_parentNode(c, g);
Node *ns = nextSibling(n);
if (Node *outer = Getattr(c, "nested:outer")) {
while (ns && outer == Getattr(ns, "nested:outer")) {
n = ns;
ns = nextSibling(n);
}
}
if (!ns) {
set_lastChild(g, c);
} else {
set_nextSibling(c, ns);
set_previousSibling(ns, c);
}
set_nextSibling(n, c);
set_previousSibling(c, n);
}
void Swig_nested_name_unnamed_c_structs(Node *n) {
if (!n)
return;
if (!classhash)
classhash = Getattr(n, "classes");
Node *c = firstChild(n);
while (c) {
Node *next = nextSibling(c);
if (String *declName = Getattr(c, "nested:unnamed")) {
if (Node *outer = Getattr(c, "nested:outer")) {
// generate a name
String *name = NewStringf("%s_%s", Getattr(outer, "name"), declName);
Delattr(c, "nested:unnamed");
// set the name to the class and symbol table
Setattr(c, "tdname", name);
Setattr(c, "name", name);
Swig_symbol_setscope(Getattr(c, "symtab"));
Swig_symbol_setscopename(name);
// now that we have a name - gather base symbols
if (List *publicBases = Getattr(c, "baselist")) {
List *bases = Swig_make_inherit_list(name, publicBases, 0);
Swig_inherit_base_symbols(bases);
Delete(bases);
}
Setattr(classhash, name, c);
// Merge the extension into the symbol table
if (Node *am = Getattr(Swig_extend_hash(), name)) {
Swig_extend_merge(c, am);
Swig_extend_append_previous(c, am);
Delattr(Swig_extend_hash(), name);
}
Swig_symbol_popscope();
// process declarations following this type (assign correct new type)
SwigType *ty = Copy(name);
Node *decl = nextSibling(c);
List *declList = NewList();
while (decl && Getattr(decl, "nested:unnamedtype") == c) {
Setattr(decl, "type", ty);
Append(declList, decl);
Delattr(decl, "nested:unnamedtype");
SetFlag(decl, "feature:immutable");
add_symbols_c(decl);
decl = nextSibling(decl);
}
Delete(ty);
Swig_symbol_setscope(Swig_symbol_global_scope());
add_symbols_c(c);
Node *ins = create_insert(c);
insertNodeAfter(c, ins);
removeNode(c);
insertNodeAfter(n, c);
Delete(ins);
Delattr(c, "nested:outer");
} else {
// global unnamed struct - ignore it and it's instances
SetFlag(c, "feature:ignore");
while (next && Getattr(next, "nested:unnamedtype") == c) {
SetFlag(next, "feature:ignore");
next = nextSibling(next);
}
c = next;
continue;
}
} else if (cparse_cplusplusout) {
if (Getattr(c, "nested:outer")) {
Node *ins = create_insert(c, true);
insertNodeAfter(c, ins);
Delete(ins);
Delattr(c, "nested:outer");
}
}
// process children
Swig_nested_name_unnamed_c_structs(c);
c = next;
}
}
static void remove_outer_class_reference(Node *n) {
for (Node *c = firstChild(n); c; c = nextSibling(c)) {
if (GetFlag(c, "feature:flatnested") || Language::instance()->nestedClassesSupport() == Language::NCS_None) {
Delattr(c, "nested:outer");
remove_outer_class_reference(c);
}
}
}
void Swig_nested_process_classes(Node *n) {
if (!n)
return;
Node *c = firstChild(n);
while (c) {
Node *next = nextSibling(c);
if (!Getattr(c, "templatetype")) {
if (GetFlag(c, "nested") && (GetFlag(c, "feature:flatnested") || Language::instance()->nestedClassesSupport() == Language::NCS_None)) {
removeNode(c);
if (!checkAttribute(c, "access", "public"))
SetFlag(c, "feature:ignore");
else if (Strcmp(nodeType(n),"extend") == 0 && Strcmp(nodeType(parentNode(n)),"class") == 0)
insertNodeAfter(parentNode(n), c);
else
insertNodeAfter(n, c);
}
Swig_nested_process_classes(c);
}
c = next;
}
remove_outer_class_reference(n);
}

View file

@ -11,17 +11,15 @@
* Ocaml language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_ocaml_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
static const char *usage = (char *) "\
static const char *usage = "\
Ocaml Options (available with -ocaml)\n\
-oldvarnames - Old intermediary method names for variable wrappers\n\
-prefix <name> - Set a prefix <name> to be prepended to all names\n\
-suffix <name> - Change .cxx to something else\n\
-suffix <name> - Deprecated alias for general option -cppext\n\
-where - Emit library location\n\
\n";
@ -30,8 +28,8 @@ static int in_constructor = 0, in_destructor = 0, in_copyconst = 0;
static int const_enum = 0;
static int static_member_function = 0;
static int generate_sizeof = 0;
static char *prefix = 0;
static char *ocaml_path = (char *) "ocaml";
static String *prefix = 0;
static const char *ocaml_path = "ocaml";
static bool old_variable_names = false;
static String *classname = 0;
static String *module = 0;
@ -107,8 +105,7 @@ public:
SWIG_exit(0);
} else if (strcmp(argv[i], "-prefix") == 0) {
if (argv[i + 1]) {
prefix = new char[strlen(argv[i + 1]) + 2];
strcpy(prefix, argv[i + 1]);
prefix = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
@ -117,6 +114,7 @@ public:
}
} else if (strcmp(argv[i], "-suffix") == 0) {
if (argv[i + 1]) {
Printf(stderr, "swig: warning: -suffix option deprecated. SWIG 3.0.4 and later provide a -cppext option which should be used instead.\n");
SWIG_config_cppext(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
@ -130,15 +128,13 @@ public:
}
}
// If a prefix has been specified make sure it ends in a '_'
// If a prefix has been specified make sure it ends in a '_' (not actually used!)
if (prefix) {
if (prefix[strlen(prefix)] != '_') {
prefix[strlen(prefix) + 1] = 0;
prefix[strlen(prefix)] = '_';
}
const char *px = Char(prefix);
if (px[Len(prefix) - 1] != '_')
Printf(prefix, "_");
} else
prefix = (char *) "swig_";
prefix = NewString("swig_");
// Add a symbol for this module
@ -273,8 +269,8 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGOCAML\n");
Printf(f_runtime, "\n\n#ifndef SWIGOCAML\n#define SWIGOCAML\n#endif\n\n");
Printf(f_runtime, "#define SWIG_MODULE \"%s\"\n", module);
/* Module name */
Printf(f_mlbody, "let module_name = \"%s\"\n", module);
@ -329,6 +325,7 @@ public:
if (directorsEnabled()) {
// Insert director runtime into the f_runtime file (make it occur before %header section)
Swig_insert_file("director_common.swg", f_runtime);
Swig_insert_file("director.swg", f_runtime);
}
@ -343,7 +340,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -357,14 +353,12 @@ public:
Dump(f_class_ctors, f_mlout);
Dump(f_class_ctors_end, f_mlout);
Dump(f_mltail, f_mlout);
Close(f_mlout);
Delete(f_mlout);
Dump(f_enumtypes_type, f_mliout);
Dump(f_enumtypes_value, f_mliout);
Dump(f_mlibody, f_mliout);
Dump(f_mlitail, f_mliout);
Close(f_mliout);
Delete(f_mliout);
return SWIG_OK;
@ -626,9 +620,9 @@ public:
}
/* if the object is a director, and the method call originated from its
* underlying python object, resolve the call by going up the c++
* inheritance chain. otherwise try to resolve the method in python.
* without this check an infinite loop is set up between the director and
* underlying ocaml object, resolve the call by going up the c++
* inheritance chain. otherwise try to resolve the method in ocaml.
* without this check an infinite loop is set up between the director and
* shadow class method calls.
*/
@ -996,7 +990,7 @@ public:
find_marker += strlen("(*Stream:");
if (next) {
int num_chars = next - find_marker;
int num_chars = (int)(next - find_marker);
String *stream_name = NewString(find_marker);
Delslice(stream_name, num_chars, Len(stream_name));
File *fout = Swig_filebyname(stream_name);
@ -1007,7 +1001,7 @@ public:
if (!following)
following = next + strlen(next);
String *chunk = NewString(next);
Delslice(chunk, following - next, Len(chunk));
Delslice(chunk, (int)(following - next), Len(chunk));
Printv(fout, chunk, NIL);
}
}
@ -1261,13 +1255,12 @@ public:
Printv(qtype, name, NIL);
}
if (const_enum && name && !Getattr(seen_enumvalues, name)) {
if (const_enum && qtype && name && !Getattr(seen_enumvalues, name)) {
Setattr(seen_enumvalues, name, "true");
SetFlag(n, "feature:immutable");
Setattr(n, "feature:enumvalue", "1"); // this does not appear to be used
if (qtype)
Setattr(n, "qualified:name", SwigType_namestr(qtype));
Setattr(n, "qualified:name", SwigType_namestr(qtype));
String *evname = SwigType_manglestr(qtype);
Insert(evname, 0, "SWIG_ENUM_");
@ -1294,6 +1287,9 @@ public:
* typedef enum and enum are handled. I need to produce consistent names,
* which means looking up and registering by typedef and enum name. */
int enumDeclaration(Node *n) {
if (getCurrentClass() && (cplus_mode != PUBLIC))
return SWIG_NOWRAP;
String *name = Getattr(n, "name");
if (name) {
String *oname = NewString(name);
@ -1359,9 +1355,6 @@ public:
/*
* Modified polymorphism code for Ocaml language module.
* Original:
* C++/Python polymorphism demo code, copyright (C) 2002 Mark Rose
* <mrose@stm.lbl.gov>
*
* TODO
*
@ -1380,63 +1373,41 @@ public:
int classDirectorMethod(Node *n, Node *parent, String *super) {
int is_void = 0;
int is_pointer = 0;
String *storage;
String *value;
String *decl;
String *type;
String *name;
String *classname;
String *storage = Getattr(n, "storage");
String *value = Getattr(n, "value");
String *decl = Getattr(n, "decl");
String *returntype = Getattr(n, "type");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *symname = Getattr(n, "sym:name");
String *declaration;
ParmList *l;
Wrapper *w;
String *declaration = NewString("");
ParmList *l = Getattr(n, "parms");
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewString("");
String *return_type;
int status = SWIG_OK;
int idx;
bool pure_virtual = false;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
storage = Getattr(n, "storage");
value = Getattr(n, "value");
classname = Getattr(parent, "sym:name");
type = Getattr(n, "type");
name = Getattr(n, "name");
if (Cmp(storage, "virtual") == 0) {
if (Cmp(value, "0") == 0) {
pure_virtual = true;
}
}
w = NewWrapper();
declaration = NewString("");
Wrapper_add_local(w, "swig_result", "CAMLparam0();\n" "SWIG_CAMLlocal2(swig_result,args)");
/* determine if the method returns a pointer */
decl = Getattr(n, "decl");
is_pointer = SwigType_ispointer_return(decl);
is_void = (!Cmp(type, "void") && !is_pointer);
/* form complete return type */
return_type = Copy(type);
{
SwigType *t = Copy(decl);
SwigType *f = 0;
f = SwigType_pop_function(t);
SwigType_push(return_type, t);
Delete(f);
Delete(t);
}
is_void = (!Cmp(returntype, "void") && !is_pointer);
/* virtual method definition */
l = Getattr(n, "parms");
String *target;
String *pclassname = NewStringf("SwigDirector_%s", classname);
String *qualified_name = NewStringf("%s::%s", pclassname, name);
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s {", target);
Delete(qualified_name);
@ -1452,7 +1423,7 @@ public:
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL);
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
}
}
@ -1534,7 +1505,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,
@ -1614,18 +1585,7 @@ public:
String *cleanup = NewString("");
String *outarg = NewString("");
idx = 0;
/* this seems really silly. the node's type excludes
* qualifier/pointer/reference markers, which have to be retrieved
* from the decl field to construct return_type. but the typemap
* lookup routine uses the node's type, so we have to swap in and
* out the correct type. it's not just me, similar silliness also
* occurs in Language::cDeclaration().
*/
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, "c_result", w);
Setattr(n, "type", type);
if (tm != 0) {
Replaceall(tm, "$input", "swig_result");
/* TODO check this */
@ -1660,15 +1620,15 @@ public:
if (!(ignored_method && !pure_virtual)) {
/* A little explanation:
* The director_enum test case makes a method whose return type
* is an enum type. return_type here is "int". gcc complains
* is an enum type. returntype here is "int". gcc complains
* about an implicit enum conversion, and although i don't strictly
* agree with it, I'm working on fixing the error:
*
* Below is what I came up with. It's not great but it should
* always essentially work.
*/
if (!SwigType_isreference(return_type)) {
Printf(w->code, "CAMLreturn_type((%s)c_result);\n", SwigType_lstr(return_type, ""));
if (!SwigType_isreference(returntype)) {
Printf(w->code, "CAMLreturn_type((%s)c_result);\n", SwigType_lstr(returntype, ""));
} else {
Printf(w->code, "CAMLreturn_type(*c_result);\n");
}
@ -1704,7 +1664,6 @@ public:
/* clean up */
Delete(wrap_args);
Delete(return_type);
Delete(pclassname);
DelWrapper(w);
return status;
@ -1783,7 +1742,6 @@ public:
p = NewParm(type, NewString("self"), n);
q = Copy(p);
set_nextSibling(p, parms);
parms = p;
{
Wrapper *w = NewWrapper();

File diff suppressed because it is too large Load diff

View file

@ -13,8 +13,6 @@
* building a dispatch function.
* ----------------------------------------------------------------------------- */
char cvsroot_overload_cxx[] = "$Id$";
#include "swigmod.h"
#define MAX_OVERLOAD 4096
@ -28,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;
@ -42,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()
*
@ -87,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");
@ -130,12 +158,12 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
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 (no type checking rule for '%s').\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 (no type checking rule for '%s').\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;
}
@ -289,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;
@ -304,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;
@ -717,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")) {
@ -751,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++;
}
@ -775,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

@ -11,15 +11,11 @@
* Perl5 language module for SWIG.
* ------------------------------------------------------------------------- */
char cvsroot_perl5_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
static int treduce = SWIG_cparse_template_reduce(0);
#include <ctype.h>
static const char *usage = (char *) "\
static const char *usage = "\
Perl5 Options (available with -perl5)\n\
-compat - Compatibility mode\n\
-const - Wrap constants as constants and not variables (implies -proxy)\n\
@ -81,8 +77,11 @@ static String *variable_tab = 0;
static File *f_begin = 0;
static File *f_runtime = 0;
static File *f_runtime_h = 0;
static File *f_header = 0;
static File *f_wrappers = 0;
static File *f_directors = 0;
static File *f_directors_h = 0;
static File *f_init = 0;
static File *f_pm = 0;
static String *pm; /* Package initialization code */
@ -126,13 +125,14 @@ public:
Printv(argc_template_string, "items", NIL);
Clear(argv_template_string);
Printv(argv_template_string, "ST(%d)", NIL);
director_language = 1;
}
/* Test to see if a type corresponds to something wrapped with a shadow class */
Node *is_shadow(SwigType *t) {
Node *n;
n = classLookup(t);
/* Printf(stdout,"'%s' --> '%x'\n", t, n); */
/* Printf(stdout,"'%s' --> '%p'\n", t, n); */
if (n) {
if (!Getattr(n, "perl5:proxy")) {
setclassname(n);
@ -221,9 +221,63 @@ public:
* ------------------------------------------------------------ */
virtual int top(Node *n) {
/* check if directors are enabled for this module. note: this
* is a "master" switch, without which no director code will be
* emitted. %feature("director") statements are also required
* to enable directors for individual classes or methods.
*
* use %module(directors="1") modulename at the start of the
* interface file to enable director generation.
*
* TODO: directors are disallowed in conjunction with many command
* line options. Some of them are probably safe, but it will take
* some effort to validate each one.
*/
{
Node *mod = Getattr(n, "module");
if (mod) {
Node *options = Getattr(mod, "options");
if (options) {
int dirprot = 0;
if (Getattr(options, "dirprot"))
dirprot = 1;
if (Getattr(options, "nodirprot"))
dirprot = 0;
if (Getattr(options, "directors")) {
int allow = 1;
if (export_all) {
Printv(stderr, "*** directors are not supported with -exportall\n", NIL);
allow = 0;
}
if (staticoption) {
Printv(stderr, "*** directors are not supported with -static\n", NIL);
allow = 0;
}
if (!blessed) {
Printv(stderr, "*** directors are not supported with -noproxy\n", NIL);
allow = 0;
}
if (no_pmfile) {
Printv(stderr, "*** directors are not supported with -nopm\n", NIL);
allow = 0;
}
if (compat) {
Printv(stderr, "*** directors are not supported with -compat\n", NIL);
allow = 0;
}
if (allow) {
allow_directors();
if (dirprot)
allow_dirprot();
}
}
}
}
}
/* Initialize all of the output files */
String *outfile = Getattr(n, "outfile");
String *outfile_h = Getattr(n, "outfile_h");
f_begin = NewFile(outfile, "w", SWIG_output_files());
if (!f_begin) {
@ -234,6 +288,16 @@ public:
f_init = NewString("");
f_header = NewString("");
f_wrappers = NewString("");
f_directors_h = NewString("");
f_directors = NewString("");
if (directorsEnabled()) {
f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files());
if (!f_runtime_h) {
FileErrorDisplay(outfile_h);
SWIG_exit(EXIT_FAILURE);
}
}
/* Register file targets with the SWIG file handler */
Swig_register_filebyname("header", f_header);
@ -241,6 +305,8 @@ public:
Swig_register_filebyname("begin", f_begin);
Swig_register_filebyname("runtime", f_runtime);
Swig_register_filebyname("init", f_init);
Swig_register_filebyname("director", f_directors);
Swig_register_filebyname("director_h", f_directors_h);
classlist = NewList();
@ -259,8 +325,11 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGPERL\n");
Printf(f_runtime, "\n\n#ifndef SWIGPERL\n#define SWIGPERL\n#endif\n\n");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");
}
Printf(f_runtime, "#define SWIG_CASTRANK_MODE\n");
Printf(f_runtime, "\n");
@ -271,6 +340,34 @@ public:
Node *options = Getattr(mod, "options");
module = Copy(Getattr(n,"name"));
String *underscore_module = Copy(module);
Replaceall(underscore_module,":","_");
if (verbose > 0) {
fprintf(stdout, "top: using namespace_module: %s\n", Char(namespace_module));
}
if (directorsEnabled()) {
Swig_banner(f_directors_h);
Printf(f_directors_h, "\n");
Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", underscore_module);
Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", underscore_module);
if (dirprot_mode()) {
Printf(f_directors_h, "#include <map>\n");
Printf(f_directors_h, "#include <string>\n\n");
}
Printf(f_directors, "\n\n");
Printf(f_directors, "/* ---------------------------------------------------\n");
Printf(f_directors, " * C++ director class methods\n");
Printf(f_directors, " * --------------------------------------------------- */\n\n");
if (outfile_h) {
String *filename = Swig_file_filename(outfile_h);
Printf(magic, "#include \"%s\"\n\n", filename);
Delete(filename);
}
}
if (verbose > 0) {
fprintf(stdout, "top: using module: %s\n", Char(module));
}
@ -287,13 +384,6 @@ public:
fprintf(stdout, "top: No package found\n");
}
}
String *underscore_module = Copy(module);
Replaceall(underscore_module,":","_");
if (verbose > 0) {
fprintf(stdout, "top: using namespace_module: %s\n", Char(namespace_module));
}
/* If we're in blessed mode, change the package name to "packagec" */
if (blessed) {
@ -376,6 +466,12 @@ public:
/* emit wrappers */
Language::top(n);
if (directorsEnabled()) {
// Insert director runtime into the f_runtime file (make it occur before %header section)
Swig_insert_file("director_common.swg", f_runtime);
Swig_insert_file("director.swg", f_runtime);
}
String *base = NewString("");
/* Dump out variable wrappers */
@ -520,7 +616,6 @@ public:
Printf(f_pm, "%s", additional_perl_code);
Printf(f_pm, "1;\n");
Close(f_pm);
Delete(f_pm);
Delete(base);
Delete(dest_package);
@ -529,12 +624,21 @@ public:
/* Close all of the files */
Dump(f_runtime, f_begin);
Dump(f_header, f_begin);
if (directorsEnabled()) {
Dump(f_directors_h, f_runtime_h);
Printf(f_runtime_h, "\n");
Printf(f_runtime_h, "#endif\n");
Dump(f_directors, f_begin);
}
Dump(f_wrappers, f_begin);
Wrapper_pretty_print(f_init, f_begin);
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_directors);
Delete(f_directors_h);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -564,6 +668,7 @@ public:
SwigType *d = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
String *overname = 0;
int director_method = 0;
Parm *p;
int i;
@ -614,7 +719,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 */
@ -725,11 +829,36 @@ public:
Wrapper_add_localv(f, "_saved", "SV *", temp, NIL);
}
director_method = is_member_director(n) && !is_smart_pointer() && 0 != Cmp(nodeType(n), "destructor");
if (director_method) {
Wrapper_add_local(f, "director", "Swig::Director *director = 0");
Append(f->code, "director = SWIG_DIRECTOR_CAST(arg1);\n");
if (dirprot_mode() && !is_public(n)) {
Printf(f->code, "if (!director || !(director->swig_get_inner(\"%s\"))) {\n", name);
Printf(f->code, "SWIG_exception_fail(SWIG_RuntimeError, \"accessing protected member %s\");\n", name);
Append(f->code, "}\n");
}
Wrapper_add_local(f, "upcall", "bool upcall = false");
Printf(f->code, "upcall = director && SvSTASH(SvRV(ST(0))) == gv_stashpv(director->swig_get_class(), 0);\n");
}
/* Emit the function call */
if (director_method) {
Append(f->code, "try {\n");
}
/* Now write code to make the function call */
Swig_director_emit_dynamic_cast(n, f);
String *actioncode = emit_action(n);
if (director_method) {
Append(actioncode, "} catch (Swig::DirectorException& swig_err) {\n");
Append(actioncode, " sv_setsv(ERRSV, swig_err.getNative());\n");
Append(actioncode, " SWIG_fail;\n");
Append(actioncode, "}\n");
}
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
SwigType *t = Getattr(n, "type");
Replaceall(tm, "$source", Swig_cresult_name());
@ -870,6 +999,8 @@ public:
emit_action_code(n, setf->code, tm);
} else {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0));
DelWrapper(setf);
DelWrapper(getf);
return SWIG_NOWRAP;
}
Printf(setf->code, "fail:\n");
@ -914,21 +1045,9 @@ public:
String *tt = Getattr(n, "tmap:varout:type");
if (tt) {
String *tm = NewStringf("&SWIGTYPE%s", SwigType_manglestr(t));
if (Replaceall(tt, "$1_descriptor", tm)) {
SwigType_remember(t);
}
Delete(tm);
SwigType *st = Copy(t);
SwigType_add_pointer(st);
tm = NewStringf("&SWIGTYPE%s", SwigType_manglestr(st));
if (Replaceall(tt, "$&1_descriptor", tm)) {
SwigType_remember(st);
}
Delete(tm);
Delete(st);
tt = NewStringf("&%s", tt);
} else {
tt = (String *) "0";
tt = NewString("0");
}
/* Now add symbol to the PERL interpreter */
if (GetFlag(n, "feature:immutable")) {
@ -956,6 +1075,7 @@ public:
if (export_all)
Printf(exported, "$%s ", iname);
Delete(tt);
DelWrapper(setf);
DelWrapper(getf);
Delete(getname);
@ -1338,17 +1458,67 @@ public:
/* Output methods for managing ownership */
String *director_disown;
if (Getattr(n, "perl5:directordisown")) {
director_disown = NewStringf("%s%s($self);\n", tab4, Getattr(n, "perl5:directordisown"));
} else {
director_disown = NewString("");
}
Printv(pm,
"sub DISOWN {\n",
tab4, "my $self = shift;\n",
director_disown,
tab4, "my $ptr = tied(%$self);\n",
tab4, "delete $OWNER{$ptr};\n",
"}\n\n", "sub ACQUIRE {\n", tab4, "my $self = shift;\n", tab4, "my $ptr = tied(%$self);\n", tab4, "$OWNER{$ptr} = 1;\n", "}\n\n", NIL);
Delete(director_disown);
/* Only output the following methods if a class has member data */
Delete(operators);
operators = 0;
if (Swig_directorclass(n)) {
/* director classes need a way to recover subclass instance attributes */
Node *get_attr = NewHash();
String *mrename;
String *symname = Getattr(n, "sym:name");
mrename = Swig_name_disown(NSPACE_TODO, symname);
Replaceall(mrename, "disown", "swig_get_attr");
String *type = NewString(getClassType());
String *name = NewString("self");
SwigType_add_pointer(type);
Parm *p = NewParm(type, name, n);
Delete(name);
Delete(type);
type = NewString("SV");
SwigType_add_pointer(type);
String *action = NewString("");
Printv(action, "{\n", " Swig::Director *director = SWIG_DIRECTOR_CAST(arg1);\n",
" result = sv_newmortal();\n" " if (director) sv_setsv(result, director->swig_get_self());\n", "}\n", NIL);
Setfile(get_attr, Getfile(n));
Setline(get_attr, Getline(n));
Setattr(get_attr, "wrap:action", action);
Setattr(get_attr, "name", mrename);
Setattr(get_attr, "sym:name", mrename);
Setattr(get_attr, "type", type);
Setattr(get_attr, "parms", p);
Delete(action);
Delete(type);
Delete(p);
member_func = 1;
functionWrapper(get_attr);
member_func = 0;
Delete(get_attr);
Printv(pm, "sub FETCH {\n", tab4, "my ($self,$field) = @_;\n", tab4, "my $member_func = \"swig_${field}_get\";\n", tab4,
"if (not $self->can($member_func)) {\n", tab8, "my $h = ", cmodule, "::", mrename, "($self);\n", tab8, "return $h->{$field} if $h;\n",
tab4, "}\n", tab4, "return $self->$member_func;\n", "}\n", "\n", "sub STORE {\n", tab4, "my ($self,$field,$newval) = @_;\n", tab4,
"my $member_func = \"swig_${field}_set\";\n", tab4, "if (not $self->can($member_func)) {\n", tab8, "my $h = ", cmodule, "::", mrename,
"($self);\n", tab8, "return $h->{$field} = $newval if $h;\n", tab4, "}\n", tab4, "return $self->$member_func($newval);\n", "}\n", NIL);
Delete(mrename);
}
}
return SWIG_OK;
}
@ -1497,7 +1667,37 @@ public:
String *symname = Getattr(n, "sym:name");
member_func = 1;
Swig_save("perl5:constructorHandler", n, "parms", NIL);
if (Swig_directorclass(n)) {
Parm *parms = Getattr(n, "parms");
Parm *self;
String *name = NewString("self");
String *type = NewString("SV");
SwigType_add_pointer(type);
self = NewParm(type, name, n);
Delete(type);
Delete(name);
Setattr(self, "lname", "O");
if (parms)
set_nextSibling(self, parms);
Setattr(n, "parms", self);
Setattr(n, "wrap:self", "1");
Setattr(n, "hidden", "1");
Delete(self);
}
String *saved_nc = none_comparison;
none_comparison = NewStringf("strcmp(SvPV_nolen(ST(0)), \"%s::%s\") != 0", module, class_name);
String *saved_director_prot_ctor_code = director_prot_ctor_code;
director_prot_ctor_code = NewStringf("if ($comparison) { /* subclassed */\n" " $director_new\n" "} else {\n"
"SWIG_exception_fail(SWIG_RuntimeError, \"accessing abstract class or protected constructor\");\n" "}\n");
Language::constructorHandler(n);
Delete(none_comparison);
none_comparison = saved_nc;
Delete(director_prot_ctor_code);
director_prot_ctor_code = saved_director_prot_ctor_code;
Swig_restore(n);
if ((blessed) && (!Getattr(n, "sym:nextSibling"))) {
if (Getattr(n, "feature:shadow")) {
@ -1515,8 +1715,9 @@ public:
Printv(pcode, "sub ", Swig_name_construct(NSPACE_TODO, symname), " {\n", NIL);
}
const char *pkg = getCurrentClass() && Swig_directorclass(getCurrentClass())? "$_[0]" : "shift";
Printv(pcode,
tab4, "my $pkg = shift;\n",
tab4, "my $pkg = ", pkg, ";\n",
tab4, "my $self = ", cmodule, "::", Swig_name_construct(NSPACE_TODO, symname), "(@_);\n", tab4, "bless $self, $pkg if defined($self);\n", "}\n\n", NIL);
have_constructor = 1;
@ -1638,8 +1839,8 @@ public:
while (fgets(buffer, 4095, f)) {
Printf(pragma_include, "%s", buffer);
}
fclose(f);
}
fclose(f);
}
} else {
Swig_error(input_file, line_number, "Unrecognized pragma.\n");
@ -1669,7 +1870,7 @@ public:
}
/* Split the input text into lines */
List *clist = DohSplitLines(temp);
List *clist = SplitLines(temp);
Delete(temp);
int initial = 0;
String *s = 0;
@ -1755,6 +1956,543 @@ public:
String *defaultExternalRuntimeFilename() {
return NewString("swigperlrun.h");
}
virtual int classDirectorInit(Node *n) {
String *declaration = Swig_director_declaration(n);
Printf(f_directors_h, "\n");
Printf(f_directors_h, "%s\n", declaration);
Printf(f_directors_h, "public:\n");
Delete(declaration);
return Language::classDirectorInit(n);
}
virtual int classDirectorEnd(Node *n) {
if (dirprot_mode()) {
/*
This implementation uses a std::map<std::string,int>.
It should be possible to rewrite it using a more elegant way,
like copying the Java approach for the 'override' array.
But for now, this seems to be the least intrusive way.
*/
Printf(f_directors_h, "\n");
Printf(f_directors_h, "/* Internal director utilities */\n");
Printf(f_directors_h, "public:\n");
Printf(f_directors_h, " bool swig_get_inner(const char *swig_protected_method_name) const {\n");
Printf(f_directors_h, " std::map<std::string, bool>::const_iterator iv = swig_inner.find(swig_protected_method_name);\n");
Printf(f_directors_h, " return (iv != swig_inner.end() ? iv->second : false);\n");
Printf(f_directors_h, " }\n");
Printf(f_directors_h, " void swig_set_inner(const char *swig_protected_method_name, bool swig_val) const {\n");
Printf(f_directors_h, " swig_inner[swig_protected_method_name] = swig_val;\n");
Printf(f_directors_h, " }\n");
Printf(f_directors_h, "private:\n");
Printf(f_directors_h, " mutable std::map<std::string, bool> swig_inner;\n");
}
Printf(f_directors_h, "};\n");
return Language::classDirectorEnd(n);
}
virtual int classDirectorConstructor(Node *n) {
Node *parent = Getattr(n, "parentNode");
String *sub = NewString("");
String *decl = Getattr(n, "decl");
String *supername = Swig_class_name(parent);
String *classname = NewString("");
Printf(classname, "SwigDirector_%s", supername);
/* insert self parameter */
Parm *p;
ParmList *superparms = Getattr(n, "parms");
ParmList *parms = CopyParmList(superparms);
String *type = NewString("SV");
SwigType_add_pointer(type);
p = NewParm(type, NewString("self"), n);
set_nextSibling(p, parms);
parms = p;
if (!Getattr(n, "defaultargs")) {
/* constructor */
{
Wrapper *w = NewWrapper();
String *call;
String *basetype = Getattr(parent, "classtype");
String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
call = Swig_csuperclass_call(0, basetype, superparms);
Printf(w->def, "%s::%s: %s, Swig::Director(self) { \n", classname, target, call);
Printf(w->def, " SWIG_DIRECTOR_RGTR((%s *)this, this); \n", basetype);
Append(w->def, "}\n");
Delete(target);
Wrapper_print(w, f_directors);
Delete(call);
DelWrapper(w);
}
/* constructor header */
{
String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
Printf(f_directors_h, " %s;\n", target);
Delete(target);
}
}
Delete(sub);
Delete(classname);
Delete(supername);
Delete(parms);
return Language::classDirectorConstructor(n);
}
virtual int classDirectorMethod(Node *n, Node *parent, String *super) {
int is_void = 0;
int is_pointer = 0;
String *decl = Getattr(n, "decl");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *symname = Getattr(n, "sym:name");
String *declaration = NewString("");
ParmList *l = Getattr(n, "parms");
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewString("");
String *returntype = Getattr(n, "type");
String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage");
bool pure_virtual = false;
int status = SWIG_OK;
int idx;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
if (Cmp(storage, "virtual") == 0) {
if (Cmp(value, "0") == 0) {
pure_virtual = true;
}
}
/* determine if the method returns a pointer */
is_pointer = SwigType_ispointer_return(decl);
is_void = (!Cmp(returntype, "void") && !is_pointer);
/* virtual method definition */
String *target;
String *pclassname = NewStringf("SwigDirector_%s", classname);
String *qualified_name = NewStringf("%s::%s", pclassname, name);
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s", target);
Delete(qualified_name);
Delete(target);
/* header declaration */
target = Swig_method_decl(rtype, decl, name, l, 0, 1);
Printf(declaration, " virtual %s", target);
Delete(target);
// Get any exception classes in the throws typemap
ParmList *throw_parm_list = 0;
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
Parm *p;
int gencomma = 0;
Append(w->def, " throw(");
Append(declaration, " throw(");
if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if (Getattr(p, "tmap:throws")) {
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
}
String *str = SwigType_str(Getattr(p, "type"), 0);
Append(w->def, str);
Append(declaration, str);
Delete(str);
}
}
Append(w->def, ")");
Append(declaration, ")");
}
Append(w->def, " {");
Append(declaration, ";\n");
/* 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);
String *pres = NewStringf("SV *%s", Swig_cresult_name());
Wrapper_add_local(w, Swig_cresult_name(), pres);
Delete(pres);
}
}
if (ignored_method) {
if (!pure_virtual) {
if (!is_void)
Printf(w->code, "return ");
String *super_call = Swig_method_call(super, l);
Printf(w->code, "%s;\n", super_call);
Delete(super_call);
} else {
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname),
SwigType_namestr(name));
}
} else {
/* attach typemaps to arguments (C/C++ -> Perl) */
String *parse_args = NewString("");
String *pstack = NewString("");
Swig_director_parms_fixup(l);
/* remove the wrapper 'w' since it was producing spurious temps */
Swig_typemap_attach_parms("in", l, 0);
Swig_typemap_attach_parms("directorin", l, 0);
Swig_typemap_attach_parms("directorargout", l, w);
Wrapper_add_local(w, "SP", "dSP");
{
String *ptype = Copy(getClassType());
SwigType_add_pointer(ptype);
String *mangle = SwigType_manglestr(ptype);
Wrapper_add_local(w, "swigself", "SV *swigself");
Printf(w->code, "swigself = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE%s, SWIG_SHADOW);\n", mangle);
Printf(w->code, "sv_bless(swigself, gv_stashpv(swig_get_class(), 0));\n");
Delete(mangle);
Delete(ptype);
Append(pstack, "XPUSHs(swigself);\n");
}
Parm *p;
char source[256];
int outputs = 0;
if (!is_void)
outputs++;
/* build argument list and type conversion string */
idx = 0;
p = l;
while (p) {
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
continue;
}
/* old style? caused segfaults without the p!=0 check
in the for() condition, and seems dangerous in the
while loop as well.
while (Getattr(p, "tmap:ignore")) {
p = Getattr(p, "tmap:ignore:next");
}
*/
if (Getattr(p, "tmap:directorargout") != 0)
outputs++;
String *pname = Getattr(p, "name");
String *ptype = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:directorin")) != 0) {
sprintf(source, "obj%d", idx++);
String *input = NewString(source);
Setattr(p, "emit:directorinput", input);
Replaceall(tm, "$input", input);
Delete(input);
Replaceall(tm, "$owner", "0");
Replaceall(tm, "$shadow", "0");
/* Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); */
Printv(wrap_args, "SV *", source, ";\n", NIL);
Printv(wrap_args, tm, "\n", NIL);
Putc('O', parse_args);
Printv(pstack, "XPUSHs(", source, ");\n", NIL);
p = Getattr(p, "tmap:directorin:next");
continue;
} else if (Cmp(ptype, "void")) {
/* special handling for pointers to other C++ director classes.
* ideally this would be left to a typemap, but there is currently no
* way to selectively apply the dynamic_cast<> to classes that have
* directors. in other words, the type "SwigDirector_$1_lname" only exists
* for classes with directors. we avoid the problem here by checking
* module.wrap::directormap, but it's not clear how to get a typemap to
* do something similar. perhaps a new default typemap (in addition
* to SWIGTYPE) called DIRECTORTYPE?
*/
if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) {
Node *module = Getattr(parent, "module");
Node *target = Swig_directormap(module, ptype);
sprintf(source, "obj%d", idx++);
String *nonconst = 0;
/* strip pointer/reference --- should move to Swig/stype.c */
String *nptype = NewString(Char(ptype) + 2);
/* name as pointer */
String *ppname = Copy(pname);
if (SwigType_isreference(ptype)) {
Insert(ppname, 0, "&");
}
/* if necessary, cast away const since Perl 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);
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,
"Target language argument '%s' discards const in director method %s::%s.\n",
SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name));
} else {
nonconst = Copy(ppname);
}
Delete(nptype);
Delete(ppname);
String *mangle = SwigType_manglestr(ptype);
if (target) {
String *director = NewStringf("director_%s", mangle);
Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL);
Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst);
Printf(wrap_args, "if (!%s) {\n", director);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
Append(wrap_args, "} else {\n");
Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
Printf(wrap_args, "SvREFCNT_inc((SV *)%s);\n", source);
Append(wrap_args, "}\n");
Delete(director);
} else {
Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
Printf(pstack, "XPUSHs(sv_2mortal(%s));\n", source);
}
Putc('O', parse_args);
Delete(mangle);
Delete(nonconst);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
"Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0),
SwigType_namestr(c_classname), SwigType_namestr(name));
status = SWIG_NOWRAP;
break;
}
}
p = nextSibling(p);
}
/* add the method name as a PyString */
String *pyname = Getattr(n, "sym:name");
/* wrap complex arguments to PyObjects */
Printv(w->code, wrap_args, NIL);
/* pass the method call on to the Python object */
if (dirprot_mode() && !is_public(n)) {
Printf(w->code, "swig_set_inner(\"%s\", true);\n", name);
}
Append(w->code, "ENTER;\n");
Append(w->code, "SAVETMPS;\n");
Append(w->code, "PUSHMARK(SP);\n");
Append(w->code, pstack);
Delete(pstack);
Append(w->code, "PUTBACK;\n");
Printf(w->code, "call_method(\"%s\", G_EVAL | G_SCALAR);\n", pyname);
if (dirprot_mode() && !is_public(n))
Printf(w->code, "swig_set_inner(\"%s\", false);\n", name);
/* exception handling */
tm = Swig_typemap_lookup("director:except", n, Swig_cresult_name(), 0);
if (!tm) {
tm = Getattr(n, "feature:director:except");
if (tm)
tm = Copy(tm);
}
Append(w->code, "if (SvTRUE(ERRSV)) {\n");
Append(w->code, " PUTBACK;\n FREETMPS;\n LEAVE;\n");
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
Replaceall(tm, "$error", "ERRSV");
Printv(w->code, Str(tm), "\n", NIL);
} else {
Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n", classname, pyname);
}
Append(w->code, "}\n");
Delete(tm);
/*
* Python method may return a simple object, or a tuple.
* for in/out aruments, we have to extract the appropriate PyObjects from the tuple,
* then marshal everything back to C/C++ (return value and output arguments).
*
*/
/* marshal return value and other outputs (if any) from PyObject to C/C++ type */
String *cleanup = NewString("");
String *outarg = NewString("");
if (outputs > 1) {
Wrapper_add_local(w, "output", "SV *output");
Printf(w->code, "if (count != %d) {\n", outputs);
Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Perl method %s.%sfailed to return a list.\");\n", classname, pyname);
Append(w->code, "}\n");
}
idx = 0;
/* marshal return value */
if (!is_void) {
Append(w->code, "SPAGAIN;\n");
Printf(w->code, "%s = POPs;\n", Swig_cresult_name());
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
if (tm != 0) {
if (outputs > 1) {
Printf(w->code, "output = POPs;\n");
Replaceall(tm, "$input", "output");
} else {
Replaceall(tm, "$input", Swig_cresult_name());
}
char temp[24];
sprintf(temp, "%d", idx);
Replaceall(tm, "$argnum", temp);
/* TODO check this */
if (Getattr(n, "wrap:disown")) {
Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
} else {
Replaceall(tm, "$disown", "0");
}
Replaceall(tm, "$result", "c_result");
Printv(w->code, tm, "\n", NIL);
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0),
SwigType_namestr(c_classname), SwigType_namestr(name));
status = SWIG_ERROR;
}
}
/* marshal outputs */
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:directorargout")) != 0) {
if (outputs > 1) {
Printf(w->code, "output = POPs;\n");
Replaceall(tm, "$result", "output");
} else {
Replaceall(tm, "$result", Swig_cresult_name());
}
Replaceall(tm, "$input", Getattr(p, "emit:directorinput"));
Printv(w->code, tm, "\n", NIL);
p = Getattr(p, "tmap:directorargout:next");
} else {
p = nextSibling(p);
}
}
Delete(parse_args);
Delete(cleanup);
Delete(outarg);
}
if (!ignored_method) {
Append(w->code, "PUTBACK;\n");
Append(w->code, "FREETMPS;\n");
Append(w->code, "LEAVE;\n");
}
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *rettype = SwigType_str(returntype, 0);
if (!SwigType_isreference(returntype)) {
Printf(w->code, "return (%s) c_result;\n", rettype);
} else {
Printf(w->code, "return (%s) *c_result;\n", rettype);
}
Delete(rettype);
}
}
Append(w->code, "}\n");
// We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
String *inline_extra_method = NewString("");
if (dirprot_mode() && !is_public(n) && !pure_virtual) {
Printv(inline_extra_method, declaration, NIL);
String *extra_method_name = NewStringf("%sSwigPublic", name);
Replaceall(inline_extra_method, name, extra_method_name);
Replaceall(inline_extra_method, ";\n", " {\n ");
if (!is_void)
Printf(inline_extra_method, "return ");
String *methodcall = Swig_method_call(super, l);
Printv(inline_extra_method, methodcall, ";\n }\n", NIL);
Delete(methodcall);
Delete(extra_method_name);
}
/* emit the director method */
if (status == SWIG_OK) {
if (!Getattr(n, "defaultargs")) {
Replaceall(w->code, "$symname", symname);
Wrapper_print(w, f_directors);
Printv(f_directors_h, declaration, NIL);
Printv(f_directors_h, inline_extra_method, NIL);
}
}
/* clean up */
Delete(wrap_args);
Delete(pclassname);
DelWrapper(w);
return status;
}
int classDirectorDisown(Node *n) {
int rv;
member_func = 1;
rv = Language::classDirectorDisown(n);
member_func = 0;
if (rv == SWIG_OK && Swig_directorclass(n)) {
String *symname = Getattr(n, "sym:name");
String *disown = Swig_name_disown(NSPACE_TODO, symname);
Setattr(n, "perl5:directordisown", NewStringf("%s::%s", cmodule, disown));
}
return rv;
}
int classDirectorDestructor(Node *n) {
/* TODO: it would be nice if this didn't have to copy the body of Language::classDirectorDestructor() */
String *DirectorClassName = directorClassName(getCurrentClass());
String *body = NewString("\n");
String *ptype = Copy(getClassType());
SwigType_add_pointer(ptype);
String *mangle = SwigType_manglestr(ptype);
Printv(body, tab4, "dSP;\n", tab4, "SV *self = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE", mangle, ", SWIG_SHADOW);\n", tab4, "\n", tab4,
"sv_bless(self, gv_stashpv(swig_get_class(), 0));\n", tab4, "ENTER;\n", tab4, "SAVETMPS;\n", tab4, "PUSHMARK(SP);\n", tab4,
"XPUSHs(self);\n", tab4, "XPUSHs(&PL_sv_yes);\n", tab4, "PUTBACK;\n", tab4, "call_method(\"DESTROY\", G_EVAL | G_VOID);\n", tab4,
"FREETMPS;\n", tab4, "LEAVE;\n", NIL);
Delete(mangle);
Delete(ptype);
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 {
Printf(f_directors_h, " virtual ~%s();\n", DirectorClassName);
Printf(f_directors, "%s::~%s() {%s}\n\n", DirectorClassName, DirectorClassName, body);
}
return SWIG_OK;
}
};
/* -----------------------------------------------------------------------------

View file

@ -37,16 +37,13 @@
* (may need to add more WARN_PHP_xxx codes...)
*/
char cvsroot_php_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
#include <errno.h>
static const char *usage = (char *) "\
static const char *usage = "\
PHP Options (available with -php)\n\
-cppext <ext> - Change C++ file extension to <ext> (default is cpp)\n\
-noproxy - Don't generate proxy classes.\n\
-prefix <prefix> - Prepend <prefix> to all class names in PHP wrappers\n\
\n";
@ -92,6 +89,7 @@ static String *s_vinit; // varinit initialization code.
static String *s_vdecl;
static String *s_cinit; // consttab initialization code.
static String *s_oinit;
static String *s_arginfo;
static String *s_entry;
static String *cs_entry;
static String *all_cs_entry;
@ -192,7 +190,7 @@ class PHP : public Language {
p = strchr(p, '"');
if (p) {
++p;
Insert(action, p - Char(action), " TSRMLS_CC");
Insert(action, (int)(p - Char(action)), " TSRMLS_CC");
}
}
}
@ -222,15 +220,6 @@ public:
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-cppext") == 0) {
if (argv[i + 1]) {
SWIG_config_cppext(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if ((strcmp(argv[i], "-noshadow") == 0) || (strcmp(argv[i], "-noproxy") == 0)) {
shadow = 0;
Swig_mark_arg(i);
@ -331,9 +320,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGPHP\n");
Printf(f_runtime, "\n");
Printf(f_runtime, "\n\n#ifndef SWIGPHP\n#define SWIGPHP\n#endif\n\n");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");
@ -354,7 +341,9 @@ public:
Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", cap_module);
Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", cap_module);
Printf(f_directors, "\n#include \"%s\"\n\n", Swig_file_filename(outfile_h));
String *filename = Swig_file_filename(outfile_h);
Printf(f_directors, "\n#include \"%s\"\n\n", filename);
Delete(filename);
}
/* PHP module file */
@ -409,11 +398,19 @@ public:
Printf(s_header, "#define SWIG_ErrorCode() (%s_globals.error_code)\n", module);
Printf(s_header, "#endif\n\n");
Printf(s_header, "// Allow the user to workaround a PHP bug on some platforms/architectures by\n");
Printf(s_header, "// compiling with -DSWIG_ZEND_ERROR_NORETURN=zend_error\n");
Printf(s_header, "#ifndef SWIG_ZEND_ERROR_NORETURN\n");
Printf(s_header, "# define SWIG_ZEND_ERROR_NORETURN zend_error_noreturn\n");
Printf(s_header, "#endif\n\n");
/* The following can't go in Lib/php/phprun.swg as it uses SWIG_ErrorMsg(), etc
* which has to be dynamically generated as it depends on the module name.
*/
Append(s_header, "#ifdef __GNUC__\n");
Append(s_header, "static void SWIG_FAIL(TSRMLS_D) __attribute__ ((__noreturn__));\n");
Append(s_header, "#endif\n\n");
Append(s_header, "static void SWIG_FAIL(TSRMLS_D) {\n");
Append(s_header, " zend_error(SWIG_ErrorCode(), \"%s\", SWIG_ErrorMsg());\n");
// zend_error() should never return with the parameters we pass, but if it
// does, we really don't want to let SWIG_FAIL() return. This also avoids
// a warning about returning from a function marked as "__noreturn__".
Append(s_header, " abort();\n");
Append(s_header, "}\n\n");
Printf(s_header, "static void %s_init_globals(zend_%s_globals *globals ) {\n", module, module);
Printf(s_header, " globals->error_msg = default_error_msg;\n");
@ -423,8 +420,7 @@ public:
Printf(s_header, "static void %s_destroy_globals(zend_%s_globals * globals) { (void)globals; }\n", module, module);
Printf(s_header, "\n");
Printf(s_header, "static void SWIG_ResetError() {\n");
Printf(s_header, " TSRMLS_FETCH();\n");
Printf(s_header, "static void SWIG_ResetError(TSRMLS_D) {\n");
Printf(s_header, " SWIG_ErrorMsg() = default_error_msg;\n");
Printf(s_header, " SWIG_ErrorCode() = default_error_code;\n");
Printf(s_header, "}\n");
@ -434,9 +430,8 @@ public:
Append(s_header, " zval **args[2];\n");
Append(s_header, " swig_object_wrapper *value;\n");
Append(s_header, " int type;\n");
Append(s_header, " int thisown;\n");
Append(s_header, "\n");
Append(s_header, " SWIG_ResetError();\n");
Append(s_header, " SWIG_ResetError(TSRMLS_C);\n");
Append(s_header, " if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_array_ex(2, args) != SUCCESS) {\n");
Append(s_header, " WRONG_PARAM_COUNT;\n");
Append(s_header, " }\n");
@ -451,7 +446,7 @@ public:
Append(s_header, " swig_object_wrapper *value;\n");
Append(s_header, " int type;\n");
Append(s_header, "\n");
Append(s_header, " SWIG_ResetError();\n");
Append(s_header, " SWIG_ResetError(TSRMLS_C);\n");
Append(s_header, " if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_array_ex(1, args) != SUCCESS) {\n");
Append(s_header, " WRONG_PARAM_COUNT;\n");
Append(s_header, " }\n");
@ -463,10 +458,6 @@ public:
Append(s_header, "}\n");
Printf(s_header, "#define SWIG_name \"%s\"\n", module);
/* Printf(s_header,"#ifdef HAVE_CONFIG_H\n");
Printf(s_header,"#include \"config.h\"\n");
Printf(s_header,"#endif\n\n");
*/
Printf(s_header, "#ifdef __cplusplus\n");
Printf(s_header, "extern \"C\" {\n");
Printf(s_header, "#endif\n");
@ -480,6 +471,7 @@ public:
if (directorsEnabled()) {
// Insert director runtime
Swig_insert_file("director_common.swg", s_header);
Swig_insert_file("director.swg", s_header);
}
@ -513,6 +505,9 @@ public:
Printf(f_h, "PHP_RSHUTDOWN_FUNCTION(%s);\n", module);
Printf(f_h, "PHP_MINFO_FUNCTION(%s);\n\n", module);
/* start the arginfo section */
s_arginfo = NewString("/* arginfo subsection */\n");
/* start the function entry section */
s_entry = NewString("/* entry subsection */\n");
@ -528,7 +523,8 @@ public:
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");
Append(s_init, "#endif\n");
Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n" "#if ZEND_MODULE_API_NO > 20010900\n" " STANDARD_MODULE_HEADER,\n" "#endif\n", NIL);
Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n", NIL);
Printf(s_init, " STANDARD_MODULE_HEADER,\n");
Printf(s_init, " (char*)\"%s\",\n", module);
Printf(s_init, " %s_functions,\n", module);
Printf(s_init, " PHP_MINIT(%s),\n", module);
@ -536,9 +532,7 @@ 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, "#if ZEND_MODULE_API_NO > 20010900\n");
Printf(s_init, " NO_VERSION_YET,\n");
Printf(s_init, "#endif\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);
@ -612,7 +606,7 @@ public:
Printf(f_h, "#endif /* PHP_%s_H */\n", cap_module);
Close(f_h);
Delete(f_h);
String *type_table = NewStringEmpty();
SwigType_emit_type_table(f_runtime, type_table);
@ -627,7 +621,7 @@ public:
Dump(f_directors_h, f_runtime_h);
Printf(f_runtime_h, "\n");
Printf(f_runtime_h, "#endif\n");
Close(f_runtime_h);
Delete(f_runtime_h);
}
Printf(s_header, "/* end header section */\n");
@ -640,10 +634,10 @@ public:
Dump(f_directors, f_begin);
}
Printv(f_begin, s_vdecl, s_wrappers, NIL);
Printv(f_begin, all_cs_entry, "\n\n", s_entry,
Printv(f_begin, all_cs_entry, "\n\n", s_arginfo, "\n\n", s_entry,
" SWIG_ZEND_NAMED_FE(swig_", module, "_alter_newobject,_wrap_swig_", module, "_alter_newobject,NULL)\n"
" SWIG_ZEND_NAMED_FE(swig_", module, "_get_newobject,_wrap_swig_", module, "_get_newobject,NULL)\n"
"{NULL, NULL, NULL}\n};\n\n", NIL);
" ZEND_FE_END\n};\n\n", NIL);
Printv(f_begin, s_init, NIL);
Delete(s_header);
Delete(s_wrappers);
@ -651,7 +645,7 @@ public:
Delete(s_vdecl);
Delete(all_cs_entry);
Delete(s_entry);
Close(f_begin);
Delete(s_arginfo);
Delete(f_runtime);
Delete(f_begin);
@ -664,18 +658,31 @@ public:
s_fakeoowrappers = NULL;
}
Printf(f_phpcode, "%s\n?>\n", s_phpclasses);
Close(f_phpcode);
Delete(f_phpcode);
return SWIG_OK;
}
/* Just need to append function names to function table to register with PHP. */
void create_command(String *cname, String *iname) {
void create_command(String *cname, String *iname, Node *n) {
// This is for the single main zend_function_entry record
Printf(f_h, "ZEND_NAMED_FUNCTION(%s);\n", iname);
String * s = cs_entry;
if (!s) s = s_entry;
Printf(s, " SWIG_ZEND_NAMED_FE(%(lower)s,%s,NULL)\n", cname, iname);
Printf(s, " SWIG_ZEND_NAMED_FE(%(lower)s,%s,swig_arginfo_%(lower)s)\n", cname, iname, cname);
// This is the above referenced arginfo structure.
ParmList *l = Getattr(n, "parms");
Printf(s_arginfo, "ZEND_BEGIN_ARG_INFO_EX(swig_arginfo_%(lower)s, 0, 0, 0)\n", cname);
for (Parm *p = l; p; p = Getattr(p, "tmap:in:next")) {
/* Ignored parameters */
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
continue;
}
int byref = GetFlag(p, "tmap:in:byref");
Printf(s_arginfo, " ZEND_ARG_PASS_INFO(%d)\n", byref);
}
Printf(s_arginfo, "ZEND_END_ARG_INFO()\n");
}
/* ------------------------------------------------------------
@ -698,7 +705,7 @@ public:
String *symname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(symname);
create_command(symname, wname);
create_command(symname, wname, n);
Printv(f->def, "ZEND_NAMED_FUNCTION(", wname, ") {\n", NIL);
Wrapper_add_local(f, "argc", "int argc");
@ -716,7 +723,7 @@ public:
Printf(f->code, "SWIG_ErrorCode() = E_ERROR;\n");
Printf(f->code, "SWIG_ErrorMsg() = \"No matching function for overloaded '%s'\";\n", symname);
Printv(f->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n", NIL);
Printv(f->code, "SWIG_FAIL(TSRMLS_C);\n", NIL);
Printv(f->code, "}\n", NIL);
Wrapper_print(f, s_wrappers);
@ -784,21 +791,20 @@ public:
}
f = NewWrapper();
numopt = 0;
String *outarg = NewStringEmpty();
String *cleanup = NewStringEmpty();
// Not issued for overloaded functions.
if (!overloaded) {
create_command(iname, wname);
}
Printv(f->def, "ZEND_NAMED_FUNCTION(", wname, ") {\n", NIL);
emit_parameter_variables(l, f);
/* Attach standard typemaps */
emit_attach_parmmaps(l, f);
// Not issued for overloaded functions.
if (!overloaded) {
create_command(iname, wname, n);
}
// wrap:parms is used by overload resolution.
Setattr(n, "wrap:parms", l);
@ -819,13 +825,6 @@ public:
Delete(args);
args = NULL;
}
if (is_member_director(n)) {
Wrapper_add_local(f, "director", "Swig::Director *director = 0");
Printf(f->code, "director = dynamic_cast<Swig::Director*>(arg1);\n");
Wrapper_add_local(f, "upcall", "bool upcall = false");
Printf(f->code, "upcall = !director->swig_is_overridden_method((char *)\"%s%s\", (char *)\"%s\");\n",
prefix, Swig_class_name(Swig_methodclass(n)), name);
}
// This generated code may be called:
// 1) as an object method, or
@ -835,7 +834,7 @@ public:
// NOTE: possible we ignore this_ptr as a param for native constructor
Printf(f->code, "SWIG_ResetError();\n");
Printf(f->code, "SWIG_ResetError(TSRMLS_C);\n");
if (numopt > 0) { // membervariable wrappers do not have optional args
Wrapper_add_local(f, "arg_count", "int arg_count");
@ -914,6 +913,12 @@ public:
Delete(source);
}
if (is_member_director(n)) {
Wrapper_add_local(f, "upcall", "bool upcall = false");
Printf(f->code, "upcall = !Swig::Director::swig_is_overridden_method((char *)\"%s%s\", (char *)\"%s\" TSRMLS_CC);\n",
prefix, Swig_class_name(Swig_methodclass(n)), name);
}
Swig_director_emit_dynamic_cast(n, f);
/* Insert constraint checking code */
@ -1000,11 +1005,7 @@ public:
/* Error handling code */
Printf(f->code, "fail:\n");
Printv(f->code, cleanup, NIL);
/* This could be zend_error_noreturn(), but that's buggy in PHP ~5.3 and
* using zend_error() here shouldn't generate a warning, so just use that.
* At worst this may result in slightly less good code.
*/
Printv(f->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());", NIL);
Append(f->code, "SWIG_FAIL(TSRMLS_C);\n");
Printf(f->code, "}\n");
@ -1033,7 +1034,7 @@ public:
p += strlen(p) - 4;
String *varname = Getattr(n, "membervariableHandler:sym:name");
if (strcmp(p, "_get") == 0) {
Setattr(shadow_get_vars, varname, iname);
Setattr(shadow_get_vars, varname, Getattr(n, "type"));
} else if (strcmp(p, "_set") == 0) {
Setattr(shadow_set_vars, varname, iname);
}
@ -1091,9 +1092,6 @@ public:
int min_num_of_arguments = emit_num_required(l);
int max_num_of_arguments = emit_num_arguments(l);
// For a function with default arguments, we end up with the fullest
// parmlist in full_parmlist.
ParmList *full_parmlist = l;
Hash *ret_types = NewHash();
Setattr(ret_types, d, d);
@ -1126,7 +1124,6 @@ public:
if (num_arguments > max_num_of_arguments) {
max_num_of_arguments = num_arguments;
full_parmlist = l2;
}
o = Getattr(o, "sym:nextSibling");
}
@ -1177,11 +1174,6 @@ public:
if (!o) {
// This "overloaded method" is really just one with default args.
really_overloaded = false;
if (l != full_parmlist) {
l = full_parmlist;
if (wrapperType == memberfn)
l = nextSibling(l);
}
}
}
@ -1274,7 +1266,7 @@ public:
break;
char *p;
errno = 0;
int n = strtol(Char(value), &p, 0);
long n = strtol(Char(value), &p, 0);
Clear(value);
if (errno || *p) {
Append(value, "?");
@ -1289,10 +1281,11 @@ public:
case T_SCHAR:
case T_SHORT:
case T_INT:
case T_LONG: {
case T_LONG:
case T_LONGLONG: {
char *p;
errno = 0;
unsigned int n = strtol(Char(value), &p, 0);
long n = strtol(Char(value), &p, 0);
(void) n;
if (errno || *p) {
Clear(value);
@ -1303,7 +1296,8 @@ public:
case T_UCHAR:
case T_USHORT:
case T_UINT:
case T_ULONG: {
case T_ULONG:
case T_ULONGLONG: {
char *p;
errno = 0;
unsigned int n = strtoul(Char(value), &p, 0);
@ -1315,7 +1309,8 @@ public:
break;
}
case T_FLOAT:
case T_DOUBLE:{
case T_DOUBLE:
case T_LONGDOUBLE: {
char *p;
errno = 0;
/* FIXME: strtod is locale dependent... */
@ -1334,12 +1329,6 @@ public:
}
break;
}
case T_REFERENCE:
case T_USER:
case T_ARRAY:
Clear(value);
Append(value, "?");
break;
case T_STRING:
if (Len(value) < 2) {
// How can a string (including "" be less than 2 characters?)
@ -1377,6 +1366,7 @@ public:
}
}
if (Strcmp(value, "NULL") == 0 ||
Strcmp(value, "nullptr") == 0 ||
Strcmp(value, "0") == 0 ||
Strcmp(value, "0L") == 0) {
Clear(value);
@ -1387,6 +1377,11 @@ public:
}
break;
}
default:
/* Safe default */
Clear(value);
Append(value, "?");
break;
}
if (!arg_values[argno]) {
@ -1582,7 +1577,8 @@ public:
while (i.item) {
Node *j = firstChild(i.item);
while (j) {
if (Strcmp(Getattr(j, "name"), Getattr(n, "name")) != 0) {
String *jname = Getattr(j, "name");
if (!jname || Strcmp(jname, Getattr(n, "name")) != 0) {
j = nextSibling(j);
continue;
}
@ -1703,9 +1699,9 @@ public:
Printf(output, "\t\t$r=%s;\n", invoke);
if (Len(ret_types) == 1) {
/* If d is abstract we can't create a new wrapper type d. */
Node * d_class = classLookup(d);
Node *d_class = classLookup(d);
int is_abstract = 0;
if (Getattr(d_class, "abstract")) {
if (Getattr(d_class, "abstracts")) {
is_abstract = 1;
}
if (newobject || !is_abstract) {
@ -1724,7 +1720,7 @@ public:
Printf(output, "\t\t\treturn new %s%s($r);\n", prefix, Getattr(classLookup(d), "sym:name"));
} else {
Printf(output, "\t\t\t$c = new stdClass();\n");
Printf(output, "\t\t\t$c->"SWIG_PTR" = $r;\n");
Printf(output, "\t\t\t$c->" SWIG_PTR " = $r;\n");
Printf(output, "\t\t\treturn $c;\n");
}
Printf(output, "\t\t}\n\t\treturn $r;\n");
@ -1734,7 +1730,8 @@ public:
}
} else {
Printf(output, "\t\tif (!is_resource($r)) return $r;\n");
Printf(output, "\t\tswitch (get_resource_type($r)) {\n");
String *wrapobj = NULL;
String *common = NULL;
Iterator i = First(ret_types);
while (i.item) {
SwigType *ret_type = i.item;
@ -1745,7 +1742,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);
@ -1755,22 +1751,43 @@ public:
continue;
}
}
Printf(output, "\t\t");
if (i.item) {
Printf(output, "case '%s': ", mangled);
} else {
Printf(output, "default: ");
}
const char *classname = GetChar(class_node, "sym:name");
if (!classname)
classname = GetChar(class_node, "name");
String * action = NewStringEmpty();
if (classname)
Printf(output, "return new %s%s($r);\n", prefix, classname);
Printf(action, "return new %s%s($r);\n", prefix, classname);
else
Printf(output, "return $r;\n");
Printf(action, "return $r;\n");
if (!wrapobj) {
wrapobj = NewString("\t\tswitch (get_resource_type($r)) {\n");
common = action;
} else {
if (common && Cmp(common, action) != 0) {
Delete(common);
common = NULL;
}
}
Printf(wrapobj, "\t\t");
if (i.item) {
Printf(wrapobj, "case '%s': ", mangled);
} else {
Printf(wrapobj, "default: ");
}
Printv(wrapobj, action, NIL);
if (action != common) Delete(action);
Delete(mangled);
}
Printf(output, "\t\t}\n");
Printf(wrapobj, "\t\t}\n");
if (common) {
// All cases have the same action, so eliminate the switch
// wrapper.
Printf(output, "\t\t%s", common);
Delete(common);
} else {
Printv(output, wrapobj, NIL);
}
Delete(wrapobj);
}
} else {
if (non_void_return) {
@ -1887,7 +1904,7 @@ done:
enumvalue = GetChar(n, "enumvalueex");
}
if (enumvalue) {
if (enumvalue && *Char(enumvalue)) {
// Check for a simple constant expression which is valid in PHP.
// If we find one, initialise the const member with it; otherwise
// we initialise it using the C/C++ wrapped constant.
@ -1899,7 +1916,8 @@ done:
break;
}
}
if (!*p) set_to = enumvalue;
if (!*p)
set_to = enumvalue;
}
if (wrapping_member_constant) {
@ -2001,7 +2019,7 @@ done:
String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
Swig_warning(WARN_PHP_MULTIPLE_INHERITANCE, input_file, line_number,
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in PHP.\n", proxyclassname, baseclassname);
"Warning for %s, base %s ignored. Multiple inheritance is not supported in PHP.\n", proxyclassname, baseclassname);
base = Next(base);
}
}
@ -2013,7 +2031,6 @@ done:
classnode = 0;
if (shadow) {
DOH *key;
List *baselist = Getattr(n, "bases");
Iterator ki, base;
@ -2026,7 +2043,7 @@ done:
base.item = NULL;
}
if (Getattr(n, "abstract") && !GetFlag(n, "feature:notabstract")) {
if (Getattr(n, "abstracts") && !GetFlag(n, "feature:notabstract")) {
Printf(s_phpclasses, "abstract ");
}
@ -2040,6 +2057,17 @@ done:
} else if (GetFlag(n, "feature:exceptionclass")) {
Append(s_phpclasses, "extends Exception ");
}
{
Node *node = NewHash();
Setattr(node, "type", Getattr(n, "name"));
Setfile(node, Getfile(n));
Setline(node, Getline(n));
String * interfaces = Swig_typemap_lookup("phpinterfaces", node, "", 0);
if (interfaces) {
Printf(s_phpclasses, "implements %s ", interfaces);
}
Delete(node);
}
Printf(s_phpclasses, "{\n\tpublic $%s=null;\n", SWIG_PTR);
if (!baseclass) {
// Only store this in the base class (NB !baseclass means we *are*
@ -2049,17 +2077,16 @@ done:
// Write property SET handlers
ki = First(shadow_set_vars);
if (ki.key) {
// This class has setters.
Printf(s_phpclasses, "\n\tfunction __set($var,$value) {\n");
// FIXME: tune this threshold...
if (Len(shadow_set_vars) <= 2) {
// Not many setters, so avoid call_user_func.
while (ki.key) {
key = ki.key;
Printf(s_phpclasses, "\t\tif ($var === '%s') return %s($this->%s,$value);\n", key, ki.item, SWIG_PTR);
ki = Next(ki);
for (; ki.key; ki = Next(ki)) {
DOH *key = ki.key;
String *iname = ki.item;
Printf(s_phpclasses, "\t\tif ($var === '%s') return %s($this->%s,$value);\n", key, iname, SWIG_PTR);
}
} else {
Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_set';\n", shadow_classname);
@ -2072,17 +2099,6 @@ done:
Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
/* Create __isset for PHP 5.1 and later; PHP 5.0 will just ignore it. */
Printf(s_phpclasses, "\n\tfunction __isset($var) {\n");
Printf(s_phpclasses, "\t\tif (function_exists('%s_'.$var.'_set')) return true;\n", shadow_classname);
Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n");
if (baseclass) {
Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass);
} else {
Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
} else {
Printf(s_phpclasses, "\n\tfunction __set($var,$value) {\n");
Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_alter_newobject($this->%s,$value);\n", module, SWIG_PTR);
@ -2092,36 +2108,37 @@ done:
Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
Printf(s_phpclasses, "\n\tfunction __isset($var) {\n");
Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n");
if (baseclass) {
Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass);
} else {
Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
}
// Write property GET handlers
ki = First(shadow_get_vars);
if (ki.key) {
// This class has getters.
Printf(s_phpclasses, "\n\tfunction __get($var) {\n");
// FIXME: Currently we always use call_user_func for __get, so we can
// check and wrap the result. This is needless if all the properties
// are primitive types. Also this doesn't handle all the cases which
// a method returning an object does.
Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname);
Printf(s_phpclasses, "\t\tif (function_exists($func)) {\n");
Printf(s_phpclasses, "\t\t\t$r = call_user_func($func,$this->%s);\n", SWIG_PTR);
Printf(s_phpclasses, "\t\t\tif (!is_resource($r)) return $r;\n");
if (Len(prefix) == 0) {
Printf(s_phpclasses, "\t\t\t$c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n");
} else {
Printf(s_phpclasses, "\t\t\t$c='%s'.substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n", prefix);
int non_class_getters = 0;
for (; ki.key; ki = Next(ki)) {
DOH *key = ki.key;
SwigType *d = ki.item;
if (!is_class(d)) {
++non_class_getters;
continue;
}
Printv(s_phpclasses, "\t\tif ($var === '", key, "') return new ", prefix, Getattr(classLookup(d), "sym:name"), "(", shadow_classname, "_", key, "_get($this->", SWIG_PTR, "));\n", NIL);
}
// FIXME: tune this threshold...
if (non_class_getters <= 2) {
// Not many non-class getters, so avoid call_user_func.
for (ki = First(shadow_get_vars); non_class_getters && ki.key; ki = Next(ki)) {
DOH *key = ki.key;
SwigType *d = ki.item;
if (is_class(d)) continue;
Printv(s_phpclasses, "\t\tif ($var === '", key, "') return ", shadow_classname, "_", key, "_get($this->", SWIG_PTR, ");\n", NIL);
--non_class_getters;
}
} else {
Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname);
Printf(s_phpclasses, "\t\tif (function_exists($func)) return call_user_func($func,$this->%s);\n", SWIG_PTR);
}
Printf(s_phpclasses, "\t\t\treturn new $c($r);\n");
Printf(s_phpclasses, "\t\t}\n");
Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR);
if (baseclass) {
Printf(s_phpclasses, "\t\treturn %s%s::__get($var);\n", prefix, baseclass);
@ -2130,6 +2147,19 @@ done:
Printf(s_phpclasses, "\t\treturn $this->%s[$var];\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
/* Create __isset for PHP 5.1 and later; PHP 5.0 will just ignore it. */
/* __isset() should return true for read-only properties, so check for
* *_get() not *_set(). */
Printf(s_phpclasses, "\n\tfunction __isset($var) {\n");
Printf(s_phpclasses, "\t\tif (function_exists('%s_'.$var.'_get')) return true;\n", shadow_classname);
Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n");
if (baseclass) {
Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass);
} else {
Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
} else {
Printf(s_phpclasses, "\n\tfunction __get($var) {\n");
Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR);
@ -2139,6 +2169,14 @@ done:
Printf(s_phpclasses, "\t\treturn $this->%s[$var];\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
Printf(s_phpclasses, "\n\tfunction __isset($var) {\n");
Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n");
if (baseclass) {
Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass);
} else {
Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
}
if (!class_has_ctor) {
@ -2258,8 +2296,8 @@ done:
if (i) {
Insert(args, 0, ", ");
}
Printf(director_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0%s TSRMLS_CC);\n}\n", Swig_cresult_name(), ctype, sname, args);
Printf(director_prot_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0%s TSRMLS_CC);\n}\n", Swig_cresult_name(), ctype, sname, args);
Printf(director_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0 TSRMLS_CC%s);\n}\n", Swig_cresult_name(), ctype, sname, args);
Printf(director_prot_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0 TSRMLS_CC%s);\n}\n", Swig_cresult_name(), ctype, sname, args);
Delete(args);
wrapperType = directorconstructor;
@ -2320,14 +2358,11 @@ done:
Append(f->code, "return;\n");
Append(f->code, "fail:\n");
/* This could be zend_error_noreturn(), but that's buggy in PHP ~5.3 and
* using zend_error() here shouldn't generate a warning, so just use that.
* At worst this may result in slightly less good code.
*/
Append(f->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n");
Append(f->code, "SWIG_FAIL(TSRMLS_C);\n");
Printf(f->code, "}\n");
Wrapper_print(f, s_wrappers);
DelWrapper(f);
return SWIG_OK;
}
@ -2374,17 +2409,23 @@ done:
parms = p;
if (!Getattr(n, "defaultargs")) {
// There should always be a "self" parameter first.
assert(ParmList_len(parms) > 0);
/* constructor */
{
Wrapper *w = NewWrapper();
String *call;
String *basetype = Getattr(parent, "classtype");
// We put TSRMLS_DC after the self parameter in order to cope with
// any default parameters.
String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
if (((const char *)Char(target))[Len(target) - 2] == '(') {
Insert(target, Len(target) - 1, "TSRMLS_D");
} else {
Insert(target, Len(target) - 1, " TSRMLS_DC");
}
const char * p = Char(target);
const char * comma = strchr(p, ',');
int ins = comma ? (int)(comma - p) : Len(target) - 1;
Insert(target, ins, " TSRMLS_DC");
call = Swig_csuperclass_call(0, basetype, superparms);
Printf(w->def, "%s::%s: %s, Swig::Director(self TSRMLS_CC) {", classname, target, call);
Append(w->def, "}");
@ -2396,12 +2437,14 @@ done:
/* constructor header */
{
// We put TSRMLS_DC after the self parameter in order to cope with
// any default parameters.
String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
if (((const char *)Char(target))[Len(target) - 2] == '(') {
Insert(target, Len(target) - 1, "TSRMLS_D");
} else {
Insert(target, Len(target) - 1, " TSRMLS_DC");
}
const char * p = Char(target);
const char * comma = strchr(p, ',');
int ins = comma ? (int)(comma - p) : Len(target) - 1;
Insert(target, ins, " TSRMLS_DC");
Printf(f_directors_h, " %s;\n", target);
Delete(target);
}
@ -2412,18 +2455,17 @@ done:
int classDirectorMethod(Node *n, Node *parent, String *super) {
int is_void = 0;
int is_pointer = 0;
String *decl;
String *type;
String *name;
String *classname;
String *decl = Getattr(n, "decl");
String *returntype = Getattr(n, "type");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *symname = Getattr(n, "sym:name");
String *declaration;
ParmList *l;
Wrapper *w;
String *declaration = NewStringEmpty();
ParmList *l = Getattr(n, "parms");
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewStringEmpty();
String *return_type;
String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage");
bool pure_virtual = false;
@ -2437,34 +2479,15 @@ done:
}
}
classname = Getattr(parent, "sym:name");
type = Getattr(n, "type");
name = Getattr(n, "name");
w = NewWrapper();
declaration = NewStringEmpty();
/* determine if the method returns a pointer */
decl = Getattr(n, "decl");
is_pointer = SwigType_ispointer_return(decl);
is_void = (Cmp(type, "void") == 0 && !is_pointer);
/* form complete return type */
return_type = Copy(type);
{
SwigType *t = Copy(decl);
SwigType *f = SwigType_pop_function(t);
SwigType_push(return_type, t);
Delete(f);
Delete(t);
}
is_void = (Cmp(returntype, "void") == 0 && !is_pointer);
/* virtual method definition */
l = Getattr(n, "parms");
String *target;
String *pclassname = NewStringf("SwigDirector_%s", classname);
String *qualified_name = NewStringf("%s::%s", pclassname, name);
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s", target);
Delete(qualified_name);
@ -2487,7 +2510,7 @@ done:
if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
@ -2514,7 +2537,7 @@ done:
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *cres = SwigType_lstr(return_type, "c_result");
String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
@ -2575,6 +2598,7 @@ done:
Replaceall(tm, "$owner", "0");
Printv(wrap_args, "zval ", source, ";\n", NIL);
Printf(wrap_args, "args[%d] = &%s;\n", idx - 1, source);
Printv(wrap_args, "INIT_ZVAL(", source, ");\n", NIL);
Printv(wrap_args, tm, "\n", NIL);
Putc('O', parse_args);
@ -2616,22 +2640,23 @@ 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"));
Append(w->code, "if (!swig_self) {\n");
Append(w->code, " SWIG_PHP_Error(E_ERROR, \"this pointer is NULL\");");
Append(w->code, "}\n\n");
Printf(w->code, "MAKE_STD_ZVAL(%s);\n", Swig_cresult_name());
const char * funcname = GetChar(n, "sym:name");
Printf(w->code, "ZVAL_STRINGL(&funcname, (char *)\"%s\", %d, 0);\n", funcname, strlen(funcname));
/* 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);
@ -2647,19 +2672,9 @@ done:
/* marshal return value */
if (!is_void) {
/* this seems really silly. the node's type excludes
* qualifier/pointer/reference markers, which have to be retrieved
* from the decl field to construct return_type. but the typemap
* lookup routine uses the node's type, so we have to swap in and
* out the correct type. it's not just me, similar silliness also
* occurs in Language::cDeclaration().
*/
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
Setattr(n, "type", type);
if (tm != 0) {
static const String *amp_result = NewStringf("&%s", Swig_cresult_name());
Replaceall(tm, "$input", amp_result);
Replaceall(tm, "$input", Swig_cresult_name());
char temp[24];
sprintf(temp, "%d", idx);
Replaceall(tm, "$argnum", temp);
@ -2675,7 +2690,7 @@ done:
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname),
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname),
SwigType_namestr(name));
status = SWIG_ERROR;
}
@ -2702,8 +2717,8 @@ done:
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *rettype = SwigType_str(return_type, 0);
if (!SwigType_isreference(return_type)) {
String *rettype = SwigType_str(returntype, 0);
if (!SwigType_isreference(returntype)) {
Printf(w->code, "return (%s) c_result;\n", rettype);
} else {
Printf(w->code, "return (%s) *c_result;\n", rettype);
@ -2715,15 +2730,7 @@ done:
}
Append(w->code, "fail:\n");
if (!is_void) {
Append(w->code, "SWIG_ZEND_ERROR_NORETURN(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n");
} else {
/* This could be zend_error_noreturn(), but that's buggy in PHP ~5.3 and
* using zend_error() here shouldn't generate a warning, so just use that.
* At worst this may result in slightly less good code.
*/
Append(w->code, "zend_error(SWIG_ErrorCode(),\"%s\",SWIG_ErrorMsg());\n");
}
Append(w->code, "SWIG_FAIL(TSRMLS_C);\n");
Append(w->code, "}\n");
// We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
@ -2753,7 +2760,6 @@ done:
/* clean up */
Delete(wrap_args);
Delete(return_type);
Delete(pclassname);
DelWrapper(w);
return status;

View file

@ -29,13 +29,11 @@
*
*/
char cvsroot_pike_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h> // for isalnum()
static const char *usage = (char *) "\
static const char *usage = "\
Pike Options (available with -pike)\n\
[no additional options]\n\
\n";
@ -151,9 +149,7 @@ public:
/* Standard stuff for the SWIG runtime section */
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGPIKE\n");
Printf(f_runtime, "\n");
Printf(f_runtime, "\n\n#ifndef SWIGPIKE\n#define SWIGPIKE\n#endif\n\n");
Printf(f_header, "#define SWIG_init pike_module_init\n");
Printf(f_header, "#define SWIG_name \"%s\"\n\n", module);
@ -182,8 +178,6 @@ public:
Delete(f_wrappers);
Delete(f_init);
Delete(f_classInit);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);

File diff suppressed because it is too large Load diff

View file

@ -11,12 +11,9 @@
* R language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_r_cxx[] = "$Id$";
#include "swigmod.h"
static const double DEFAULT_NUMBER = .0000123456712312312323;
static const int MAX_OVERLOAD_ARGS = 5;
static String* replaceInitialDash(const String *name)
{
@ -208,7 +205,7 @@ static void writeListByLine(List *l, File *out, bool quote = 0) {
}
static const char *usage = (char *)"\
static const char *usage = "\
R Options (available with -r)\n\
-copystruct - Emit R code to copy C structs (on by default)\n\
-cppcast - Enable C++ casting operators (default) \n\
@ -284,6 +281,7 @@ public:
void dispatchFunction(Node *n);
int functionWrapper(Node *n);
int constantWrapper(Node *n);
int variableWrapper(Node *n);
int classDeclaration(Node *n);
@ -572,7 +570,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
Parm *p = parms;
for (i = 0; p; p = nextSibling(p), ++i) {
String *arg = Getattr(p, "name");
String *lname = NewString("");
String *lname;
if (!arg && Cmp(Getattr(p, "type"), "void")) {
lname = NewStringf("s_arg%d", i+1);
@ -682,7 +680,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
XXX Have to be a little more clever so that we can deal with struct A * - the * is getting lost.
Is this still true? If so, will a SwigType_push() solve things?
*/
Parm *bbase = NewParm(rettype, Swig_cresult_name(), n);
Parm *bbase = NewParmNode(rettype, n);
String *returnTM = Swig_typemap_lookup("in", bbase, Swig_cresult_name(), f);
if(returnTM) {
String *tm = returnTM;
@ -726,6 +724,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
Delete(rtype);
Delete(rettype);
Delete(funcparams);
DelWrapper(f);
return funName;
}
@ -794,9 +793,7 @@ int R::top(Node *n) {
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGR\n");
Printf(f_runtime, "\n");
Printf(f_runtime, "\n\n#ifndef SWIGR\n#define SWIGR\n#endif\n\n");
Swig_banner_target_lang(s_init, "#");
@ -837,7 +834,6 @@ int R::top(Node *n) {
Delete(f_init);
Delete(s_header);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -871,8 +867,7 @@ int R::DumpCode(Node *n) {
Printf(scode, "%s\n\n", s_classes);
Printf(scode, "%s\n", sfile);
Close(scode);
// Delete(scode);
Delete(scode);
String *outfile = Getattr(n,"outfile");
File *runtime = NewFile(outfile,"w", SWIG_output_files());
if (!runtime) {
@ -886,7 +881,6 @@ int R::DumpCode(Node *n) {
Printf(runtime, "%s\n", f_wrapper);
Printf(runtime, "%s\n", f_init);
Close(runtime);
Delete(runtime);
if(outputNamespaceInfo) {
@ -907,7 +901,6 @@ int R::DumpCode(Node *n) {
Printf(ns, "\nexportMethods(\n");
writeListByLine(namespaceFunctions, ns, 1);
Printf(ns, ")\n");
Close(ns);
Delete(ns);
Delete(s_namespace);
}
@ -1186,6 +1179,9 @@ int R::OutputArrayMethod(String *className, List *el, File *out) {
tdname is the typedef of the enumeration, i.e. giving its name.
*************************************************************/
int R::enumDeclaration(Node *n) {
if (getCurrentClass() && (cplus_mode != PUBLIC))
return SWIG_NOWRAP;
String *name = Getattr(n, "name");
String *tdname = Getattr(n, "tdname");
@ -1387,12 +1383,12 @@ List * R::Swig_overload_rank(Node *n,
}
if ((!t1) && (!nodes[i].error)) {
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n),
"Overloaded method %s not supported (no type checking rule for '%s').\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),
"xx Overloaded method %s not supported (no type checking rule for '%s').\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;
}
@ -1612,7 +1608,6 @@ void R::dispatchFunction(Node *n) {
String *tmcheck = Swig_typemap_lookup("rtypecheck", p, "", 0);
if (tmcheck) {
String *tmp = NewString("");
Printf(tmp, "argv[[%d]]", j+1);
Replaceall(tmcheck, "$arg", tmp);
@ -1629,32 +1624,34 @@ void R::dispatchFunction(Node *n) {
tmcheck);
p = Getattr(p, "tmap:in:next");
continue;
}
if (DohStrcmp(tm,"numeric")==0) {
}
if (tm) {
if (Strcmp(tm,"numeric")==0) {
Printf(f->code, "%sis.numeric(argv[[%d]])",
j == 0 ? "" : " && ",
j+1);
j == 0 ? "" : " && ",
j+1);
}
else if (DohStrcmp(tm,"integer")==0) {
else if (Strcmp(tm,"integer")==0) {
Printf(f->code, "%s(is.integer(argv[[%d]]) || is.numeric(argv[[%d]]))",
j == 0 ? "" : " && ",
j+1, j+1);
j == 0 ? "" : " && ",
j+1, j+1);
}
else if (DohStrcmp(tm,"character")==0) {
else if (Strcmp(tm,"character")==0) {
Printf(f->code, "%sis.character(argv[[%d]])",
j == 0 ? "" : " && ",
j+1);
j == 0 ? "" : " && ",
j+1);
}
else {
Printf(f->code, "%sextends(argtypes[%d], '%s')",
j == 0 ? "" : " && ",
j+1,
tm);
}
if (!SwigType_ispointer(Getattr(p, "type"))) {
Printf(f->code, " && length(argv[[%d]]) == 1",
j+1);
j == 0 ? "" : " && ",
j+1,
tm);
}
}
if (!SwigType_ispointer(Getattr(p, "type"))) {
Printf(f->code, " && length(argv[[%d]]) == 1",
j+1);
}
p = Getattr(p, "tmap:in:next");
}
Printf(f->code, ") { f <- %s%s; }\n", sfname, overname);
@ -1848,18 +1845,21 @@ int R::functionWrapper(Node *n) {
String *lname = Getattr(p,"lname");
// R keyword renaming
if (name && Swig_name_warning(p, 0, name, 0))
name = 0;
/* If we have a :: in the parameter name because we are accessing a static member of a class, say, then
we need to remove that prefix. */
while (Strstr(name, "::")) {
//XXX need to free.
name = NewStringf("%s", Strchr(name, ':') + 2);
if (debugMode)
Printf(stdout, "+++ parameter name with :: in it %s\n", name);
if (name) {
if (Swig_name_warning(p, 0, name, 0)) {
name = 0;
} else {
/* If we have a :: in the parameter name because we are accessing a static member of a class, say, then
we need to remove that prefix. */
while (Strstr(name, "::")) {
//XXX need to free.
name = NewStringf("%s", Strchr(name, ':') + 2);
if (debugMode)
Printf(stdout, "+++ parameter name with :: in it %s\n", name);
}
}
}
if (Len(name) == 0)
if (!name || Len(name) == 0)
name = NewStringf("s_arg%d", i+1);
name = replaceInitialDash(name);
@ -1903,6 +1903,8 @@ int R::functionWrapper(Node *n) {
"\n};\n",
"if(is(", name, ", \"NativeSymbolInfo\")) {\n",
name, " = ", name, "$address", ";\n}\n",
"if(is(", name, ", \"ExternalReference\")) {\n",
name, " = ", name, "@ref;\n}\n",
"}; \n",
NIL);
} else {
@ -2112,7 +2114,7 @@ int R::functionWrapper(Node *n) {
{
String *finalizer = NewString(iname);
Replace(finalizer, "new_", "", DOH_REPLACE_FIRST);
Printf(sfun->code, "reg.finalizer(ans, delete_%s)\n", finalizer);
Printf(sfun->code, "reg.finalizer(ans@ref, delete_%s)\n", finalizer);
}
Printf(sfun->code, "ans\n");
}
@ -2160,7 +2162,7 @@ int R::functionWrapper(Node *n) {
/* If we are dealing with a method in an C++ class, then
add the name of the R function and its definition.
XXX need to figure out how to store the Wrapper if possible in the hash/list.
Would like to be able to do this so that we can potentialy insert
Would like to be able to do this so that we can potentially insert
*/
if(processing_member_access_function || processing_class_member_function) {
addAccessor(member_name, sfun, iname);
@ -2181,6 +2183,16 @@ int R::functionWrapper(Node *n) {
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* R::constantWrapper()
* ---------------------------------------------------------------------- */
int R::constantWrapper(Node *n) {
(void) n;
// TODO
return SWIG_OK;
}
/*****************************************************
Add the specified routine name to the collection of
generated routines that are called from R functions.
@ -2298,7 +2310,7 @@ int R::classDeclaration(Node *n) {
/* If we have a typedef union { ... } U, then we never get to see the typedef
via a regular call to typedefHandler. Instead, */
if(Getattr(n, "unnamed") && Strcmp(Getattr(n, "storage"), "typedef") == 0
if(Getattr(n, "unnamed") && Getattr(n, "storage") && Strcmp(Getattr(n, "storage"), "typedef") == 0
&& Getattr(n, "tdname") && Strcmp(Getattr(n, "tdname"), name) == 0) {
if (debugMode)
Printf(stdout, "Typedef in the class declaration for %s\n", name);
@ -2348,7 +2360,7 @@ int R::classDeclaration(Node *n) {
elName = Getattr(c, "name");
String *elKind = Getattr(c, "kind");
if (Strcmp(elKind, "variable") != 0) {
if (!Equal(elKind, "variable")) {
c = nextSibling(c);
continue;
}
@ -2450,8 +2462,7 @@ int R::generateCopyRoutines(Node *n) {
continue;
}
String *elKind = Getattr(c, "kind");
if (Strcmp(elKind, "variable") != 0) {
Delete(elKind);
if (!Equal(elKind, "variable")) {
continue;
}

View file

@ -11,18 +11,14 @@
* Ruby language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_ruby_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
static int treduce = SWIG_cparse_template_reduce(0);
#define SWIG_PROTECTED_TARGET_METHODS 1
#include <ctype.h>
#include <string.h>
#include <limits.h> /* for INT_MAX */
#define SWIG_PROTECTED_TARGET_METHODS 1
class RClass {
private:
String *temp;
@ -128,10 +124,11 @@ enum autodoc_t {
AUTODOC_FUNC,
AUTODOC_METHOD,
AUTODOC_GETTER,
AUTODOC_SETTER
AUTODOC_SETTER,
AUTODOC_NONE
};
static const char *usage = (char *) "\
static const char *usage = "\
Ruby Options (available with -ruby)\n\
-autorename - Enable renaming of classes and methods to follow Ruby coding standards\n\
-cppcast - Enable C++ casting operators (default)\n\
@ -203,13 +200,11 @@ private:
autodoc_t last_mode;
String* last_autodoc;
autodoc_l autodoc_level(String *autodoc) {
autodoc_l dlevel = NO_AUTODOC;
if (autodoc) {
char *c = Char(autodoc);
if (c && isdigit(c[0])) {
char *c = Char(autodoc);
if (c) {
if (isdigit(c[0])) {
dlevel = (autodoc_l) atoi(c);
} else {
if (strcmp(c, "extended") == 0) {
@ -237,7 +232,7 @@ private:
/* ------------------------------------------------------------
* docstring()
* Get the docstring text, stripping off {} if neccessary,
* Get the docstring text, stripping off {} if necessary,
* and enclose in triple double quotes. If autodoc is also
* set then it will build a combined docstring.
* ------------------------------------------------------------ */
@ -496,7 +491,7 @@ private:
String* full_name;
if ( module ) {
full_name = NewString(module);
if (class_name && Len(class_name) > 0)
if (Len(class_name) > 0)
Append(full_name, "::");
}
else
@ -602,6 +597,8 @@ private:
case AUTODOC_SETTER:
Printf(doc, " Document-method: %s.%s=\n\n", full_name, symname);
break;
case AUTODOC_NONE:
break;
}
}
@ -689,6 +686,8 @@ private:
Printf(doc, " -> %s", type_str);
break;
}
case AUTODOC_NONE:
break;
}
}
@ -723,6 +722,8 @@ private:
case AUTODOC_SETTER:
Printf(doc, "Set new value for attribute.\n");
break;
case AUTODOC_NONE:
break;
}
}
@ -732,10 +733,6 @@ private:
String *autodoc = Getattr(n, "feature:autodoc");
autodoc_l dlevel = autodoc_level(autodoc);
symname = Getattr(n, "sym:name");
if ( Getattr( special_methods, symname ) )
symname = Getattr( special_methods, symname );
switch (dlevel) {
case NO_AUTODOC:
case NAMES_AUTODOC:
@ -789,13 +786,9 @@ private:
else
return v;
}
if (Strcmp(v, "NULL") == 0)
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");
@ -810,33 +803,38 @@ public:
*
* Initialize member data
* --------------------------------------------------------------------- */
RUBY() {
module = 0;
modvar = 0;
feature = 0;
prefix = 0;
last_autodoc = NewString("");
current = NO_CPP;
classes = 0;
klass = 0;
special_methods = 0;
f_begin = 0;
f_runtime = 0;
f_header = 0;
f_wrappers = 0;
f_init = 0;
f_initbeforefunc = 0;
useGlobalModule = false;
multipleInheritance = false;
director_prot_ctor_code = NewString("");
Printv(director_prot_ctor_code,
"if ( $comparison ) { /* subclassed */\n",
" $director_new \n",
"} else {\n", " rb_raise(rb_eRuntimeError,\"accessing abstract class or protected constructor\"); \n", " return Qnil;\n", "}\n", NIL);
director_multiple_inheritance = 0;
director_language = 1;
}
RUBY() :
module(0),
modvar(0),
feature(0),
prefix(0),
current(0),
classes(0),
klass(0),
special_methods(0),
f_directors(0),
f_directors_h(0),
f_directors_helpers(0),
f_begin(0),
f_runtime(0),
f_runtime_h(0),
f_header(0),
f_wrappers(0),
f_init(0),
f_initbeforefunc(0),
useGlobalModule(false),
multipleInheritance(false),
last_mode(AUTODOC_NONE),
last_autodoc(NewString("")) {
current = NO_CPP;
director_prot_ctor_code = NewString("");
Printv(director_prot_ctor_code,
"if ( $comparison ) { /* subclassed */\n",
" $director_new \n",
"} else {\n", " rb_raise(rb_eRuntimeError,\"accessing abstract class or protected constructor\"); \n", " return Qnil;\n", "}\n", NIL);
director_multiple_inheritance = 0;
director_language = 1;
}
/* ---------------------------------------------------------------------
* main()
@ -1099,8 +1097,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGRUBY\n");
Printf(f_runtime, "\n\n#ifndef SWIGRUBY\n#define SWIGRUBY\n#endif\n\n");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");
@ -1111,7 +1108,7 @@ public:
/* typedef void *VALUE */
SwigType *value = NewSwigType(T_VOID);
SwigType_add_pointer(value);
SwigType_typedef(value, (char *) "VALUE");
SwigType_typedef(value, "VALUE");
Delete(value);
/* Set module name */
@ -1138,8 +1135,11 @@ public:
Printf(f_directors, "/* ---------------------------------------------------\n");
Printf(f_directors, " * C++ director class methods\n");
Printf(f_directors, " * --------------------------------------------------- */\n\n");
if (outfile_h)
Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h));
if (outfile_h) {
String *filename = Swig_file_filename(outfile_h);
Printf(f_directors, "#include \"%s\"\n\n", filename);
Delete(filename);
}
Delete(module_macro);
}
@ -1168,6 +1168,7 @@ public:
if (directorsEnabled()) {
// Insert director runtime into the f_runtime file (make it occur before %header section)
Swig_insert_file("director_common.swg", f_runtime);
Swig_insert_file("director.swg", f_runtime);
}
@ -1185,7 +1186,7 @@ public:
Dump(f_directors_h, f_runtime_h);
Printf(f_runtime_h, "\n");
Printf(f_runtime_h, "#endif\n");
Close(f_runtime_h);
Delete(f_runtime_h);
}
Dump(f_wrappers, f_begin);
@ -1196,7 +1197,6 @@ public:
Delete(f_wrappers);
Delete(f_init);
Delete(f_initbeforefunc);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
@ -1271,13 +1271,15 @@ public:
}
m = Next(m);
}
if (feature == 0) {
feature = Copy(last);
if (last) {
if (feature == 0) {
feature = Copy(last);
}
(Char(last))[0] = (char)toupper((Char(last))[0]);
modvar = NewStringf("m%s", last);
}
(Char(last))[0] = (char)toupper((Char(last))[0]);
modvar = NewStringf("m%s", last);
Delete(modules);
}
Delete(modules);
}
Delete(mod_name);
}
@ -1737,11 +1739,13 @@ public:
/* Now write the wrapper function itself */
if (current == CONSTRUCTOR_ALLOCATE) {
Printv(f->def, "SWIGINTERN VALUE\n", NIL);
Printf(f->def, "#ifdef HAVE_RB_DEFINE_ALLOC_FUNC\n");
Printv(f->def, "SWIGINTERN VALUE\n", wname, "(VALUE self) {", NIL);
Printv(f->def, wname, "(VALUE self)\n", NIL);
Printf(f->def, "#else\n");
Printv(f->def, "SWIGINTERN VALUE\n", wname, "(int argc, VALUE *argv, VALUE self) {", NIL);
Printv(f->def, wname, "(int argc, VALUE *argv, VALUE self)\n", NIL);
Printf(f->def, "#endif\n");
Printv(f->def, "{\n", NIL);
} else if (current == CONSTRUCTOR_INITIALIZE) {
Printv(f->def, "SWIGINTERN VALUE\n", wname, "(int argc, VALUE *argv, VALUE self) {", NIL);
if (!varargs) {
@ -1790,8 +1794,8 @@ public:
/* if the object is a director, and the method call originated from its
* underlying Ruby object, resolve the call by going up the c++
* inheritance chain. otherwise try to resolve the method in python.
* without this check an infinite loop is set up between the director and
* inheritance chain. otherwise try to resolve the method in Ruby.
* without this check an infinite loop is set up between the director and
* shadow class method calls.
*/
@ -1827,10 +1831,19 @@ public:
Wrapper_add_local(f, "classname", classname);
}
if (action) {
Printf(action, "\nDATA_PTR(self) = %s;", Swig_cresult_name());
if (GetFlag(pn, "feature:trackobjects")) {
Printf(action, "\nSWIG_RubyAddTracking(%s, self);", Swig_cresult_name());
SwigType *smart = Swig_cparse_smartptr(pn);
String *result_name = NewStringf("%s%s", smart ? "smart" : "", Swig_cresult_name());
if (smart) {
String *result_var = NewStringf("%s *%s = 0", SwigType_namestr(smart), result_name);
Wrapper_add_local(f, result_name, result_var);
Printf(action, "\n%s = new %s(%s);", result_name, SwigType_namestr(smart), Swig_cresult_name());
}
Printf(action, "\nDATA_PTR(self) = %s;", result_name);
if (GetFlag(pn, "feature:trackobjects")) {
Printf(action, "\nSWIG_RubyAddTracking(%s, self);", result_name);
}
Delete(result_name);
Delete(smart);
}
}
@ -1918,11 +1931,17 @@ public:
/* Extra code needed for new and initialize methods */
if (current == CONSTRUCTOR_ALLOCATE) {
Node *pn = Swig_methodclass(n);
SwigType *smart = Swig_cparse_smartptr(pn);
if (smart)
SwigType_add_pointer(smart);
String *classtype = smart ? smart : t;
need_result = 1;
Printf(f->code, "VALUE vresult = SWIG_NewClassInstance(self, SWIGTYPE%s);\n", Char(SwigType_manglestr(t)));
Printf(f->code, "VALUE vresult = SWIG_NewClassInstance(self, SWIGTYPE%s);\n", Char(SwigType_manglestr(classtype)));
Printf(f->code, "#ifndef HAVE_RB_DEFINE_ALLOC_FUNC\n");
Printf(f->code, "rb_obj_call_init(vresult, argc, argv);\n");
Printf(f->code, "#endif\n");
Delete(smart);
} else if (current == CONSTRUCTOR_INITIALIZE) {
need_result = 1;
}
@ -2421,19 +2440,23 @@ public:
SwigType *btype = NewString(basename);
SwigType_add_pointer(btype);
SwigType_remember(btype);
SwigType *smart = Swig_cparse_smartptr(base.item);
if (smart) {
SwigType_add_pointer(smart);
SwigType_remember(smart);
}
String *bmangle = SwigType_manglestr(smart ? smart : btype);
if (multipleInheritance) {
String *bmangle = SwigType_manglestr(btype);
Insert(bmangle, 0, "((swig_class *) SWIGTYPE");
Append(bmangle, "->clientdata)->mImpl");
Printv(klass->init, "rb_include_module(", klass->mImpl, ", ", bmangle, ");\n", NIL);
Delete(bmangle);
} else {
String *bmangle = SwigType_manglestr(btype);
Insert(bmangle, 0, "((swig_class *) SWIGTYPE");
Append(bmangle, "->clientdata)->klass");
Replaceall(klass->init, "$super", bmangle);
Delete(bmangle);
}
Delete(bmangle);
Delete(smart);
Delete(btype);
}
base = Next(base);
@ -2450,7 +2473,7 @@ public:
String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
Swig_warning(WARN_RUBY_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Ruby.\n", proxyclassname, baseclassname);
"Warning for %s, base %s ignored. Multiple inheritance is not supported in Ruby.\n", proxyclassname, baseclassname);
base = Next(base);
}
}
@ -2534,9 +2557,15 @@ public:
SwigType *tt = NewString(name);
SwigType_add_pointer(tt);
SwigType_remember(tt);
String *tm = SwigType_manglestr(tt);
SwigType *smart = Swig_cparse_smartptr(n);
if (smart) {
SwigType_add_pointer(smart);
SwigType_remember(smart);
}
String *tm = SwigType_manglestr(smart ? smart : tt);
Printf(klass->init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) &SwigClass%s);\n", tm, valid_name);
Delete(tm);
Delete(smart);
Delete(tt);
Delete(valid_name);
@ -2715,7 +2744,9 @@ public:
String *pname0 = Swig_cparm_name(0, 0);
Printv(freefunc, "free_", klass->mname, NIL);
Printv(freebody, "SWIGINTERN void\n", freefunc, "(", klass->type, " *", pname0, ") {\n", tab4, NIL);
Printv(freebody, "SWIGINTERN void\n", freefunc, "(void *self) {\n", NIL);
Printv(freebody, tab4, klass->type, " *", pname0, " = (", klass->type, " *)self;\n", NIL);
Printv(freebody, tab4, NIL);
/* Check to see if object tracking is activated for the class
that owns this destructor. */
@ -2968,6 +2999,7 @@ public:
Printf(rescue->code, "if (%s == 0) ", depthCountName);
Printv(rescue->code, Str(tm), "\n", NIL);
Printv(rescue->code, "rb_exc_raise(error);\n", NIL);
Printv(rescue->code, "return Qnil;\n", NIL);
Printv(rescue->code, "}", NIL);
}
@ -3017,18 +3049,17 @@ public:
virtual int classDirectorMethod(Node *n, Node *parent, String *super) {
int is_void = 0;
int is_pointer = 0;
String *decl;
String *type;
String *name;
String *classname;
String *decl = Getattr(n, "decl");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");
String *symname = Getattr(n, "sym:name");
String *declaration;
ParmList *l;
Wrapper *w;
String *declaration = NewString("");
ParmList *l = Getattr(n, "parms");
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewString("");
String *return_type;
String *returntype = Getattr(n, "type");
Parm *p;
String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage");
@ -3049,35 +3080,15 @@ public:
Printf(overnametmp, "::%s", Getattr(n, "sym:overname"));
}
classname = Getattr(parent, "sym:name");
type = Getattr(n, "type");
name = Getattr(n, "name");
w = NewWrapper();
declaration = NewString("");
/* determine if the method returns a pointer */
decl = Getattr(n, "decl");
is_pointer = SwigType_ispointer_return(decl);
is_void = (!Cmp(type, "void") && !is_pointer);
/* form complete return type */
return_type = Copy(type);
{
SwigType *t = Copy(decl);
SwigType *f = 0;
f = SwigType_pop_function(t);
SwigType_push(return_type, t);
Delete(f);
Delete(t);
}
is_void = (!Cmp(returntype, "void") && !is_pointer);
/* virtual method definition */
l = Getattr(n, "parms");
String *target;
String *pclassname = NewStringf("SwigDirector_%s", classname);
String *qualified_name = NewStringf("%s::%s", pclassname, name);
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
Printf(w->def, "%s", target);
Delete(qualified_name);
@ -3100,7 +3111,7 @@ public:
if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if ((tm = Getattr(p, "tmap:throws"))) {
if (Getattr(p, "tmap:throws")) {
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
@ -3128,7 +3139,7 @@ public:
*/
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL);
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
}
}
@ -3218,7 +3229,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,
@ -3295,14 +3306,7 @@ public:
/* Marshal return value */
if (!is_void) {
/* This seems really silly. The node's type excludes qualifier/pointer/reference markers,
* which have to be retrieved from the decl field to construct return_type. But the typemap
* lookup routine uses the node's type, so we have to swap in and out the correct type.
* It's not just me, similar silliness also occurs in Language::cDeclaration().
*/
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
Setattr(n, "type", type);
if (tm != 0) {
if (outputs > 1 && !asvoid ) {
Printf(w->code, "output = rb_ary_entry(%s, %d);\n", Swig_cresult_name(), idx++);
@ -3320,7 +3324,7 @@ public:
Printv(w->code, tm, "\n", NIL);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0),
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0),
SwigType_namestr(c_classname), SwigType_namestr(name));
status = SWIG_ERROR;
}
@ -3351,8 +3355,8 @@ public:
/* any existing helper functions to handle this? */
if (!is_void) {
if (!(ignored_method && !pure_virtual)) {
String *rettype = SwigType_str(return_type, 0);
if (!SwigType_isreference(return_type)) {
String *rettype = SwigType_str(returntype, 0);
if (!SwigType_isreference(returntype)) {
Printf(w->code, "return (%s) c_result;\n", rettype);
} else {
Printf(w->code, "return (%s) *c_result;\n", rettype);
@ -3390,7 +3394,6 @@ public:
/* clean up */
Delete(wrap_args);
Delete(return_type);
Delete(pclassname);
DelWrapper(w);
return status;
@ -3451,6 +3454,14 @@ public:
String *defaultExternalRuntimeFilename() {
return NewString("swigrubyrun.h");
}
/*----------------------------------------------------------------------
* kwargsSupport()
*--------------------------------------------------------------------*/
bool kwargsSupport() const {
return true;
}
}; /* class RUBY */
/* -----------------------------------------------------------------------------

View file

@ -11,8 +11,6 @@
* A parse tree represented as Lisp s-expressions.
* ----------------------------------------------------------------------------- */
char cvsroot_s_exp_cxx[] = "$Id$";
#include "swigmod.h"
#include "dohint.h"
@ -24,9 +22,21 @@ S-Exp Options (available with -sexp)\n\
static File *out = 0;
class Sexp:public Language {
public:
int indent_level;
Sexp():indent_level(0) {
DOHHash *print_circle_hash;
int print_circle_count;
int hanging_parens;
bool need_whitespace;
bool need_newline;
public:
Sexp():
indent_level(0),
print_circle_hash(0),
print_circle_count(0),
hanging_parens(0),
need_whitespace(0),
need_newline(0) {
}
virtual ~ Sexp() {
@ -51,12 +61,6 @@ public:
}
}
DOHHash *print_circle_hash;
int print_circle_count;
int hanging_parens;
bool need_whitespace;
bool need_newline;
/* Top of the parse tree */
virtual int top(Node *n) {
if (out == 0) {
@ -81,7 +85,7 @@ public:
Language::top(n);
Printf(out, "\n");
Printf(out, ";;; Lisp parse tree produced by SWIG\n");
print_circle_hash = DohNewHash();
print_circle_hash = NewHash();
print_circle_count = 0;
hanging_parens = 0;
need_whitespace = 0;
@ -310,7 +314,7 @@ public:
close_paren();
} else {
// What is it?
Printf(out, "#<DOH %s %x>", ObjType(obj)->objname, obj);
Printf(out, "#<DOH %s %p>", ObjType(obj)->objname, obj);
}
}
}

1125
Source/Modules/scilab.cxx Normal file

File diff suppressed because it is too large Load diff

View file

@ -16,8 +16,6 @@
* to SWIG, you would modify this file.
* ----------------------------------------------------------------------------- */
char cvsroot_swigmain_cxx[] = "$Id$";
#include "swigmod.h"
#include <ctype.h>
@ -52,8 +50,10 @@ extern "C" {
Language *swig_uffi(void);
Language *swig_r(void);
Language *swig_c(void);
Language *swig_scilab(void);
Language *swig_go(void);
Language *swig_d(void);
Language *swig_javascript(void);
}
struct swig_module {
@ -77,6 +77,7 @@ static swig_module modules[] = {
{"-go", swig_go, "Go"},
{"-guile", swig_guile, "Guile"},
{"-java", swig_java, "Java"},
{"-javascript", swig_javascript, "Javascript"},
{"-lua", swig_lua, "Lua"},
{"-modula3", swig_modula3, "Modula 3"},
{"-mzscheme", swig_mzscheme, "Mzscheme"},
@ -91,6 +92,7 @@ static swig_module modules[] = {
{"-python", swig_python, "Python"},
{"-r", swig_r, "R (aka GNU S)"},
{"-ruby", swig_ruby, "Ruby"},
{"-scilab", swig_scilab, "Scilab"},
{"-sexp", swig_sexp, "Lisp S-Expressions"},
{"-tcl", swig_tcl, "Tcl"},
{"-tcl8", swig_tcl, 0},
@ -182,11 +184,6 @@ int main(int margc, char **margv) {
} else if (strcmp(argv[i], "-nolang") == 0) {
dl = new Language;
Swig_mark_arg(i);
} else if ((strcmp(argv[i], "-dnone") == 0) ||
(strcmp(argv[i], "-dhtml") == 0) ||
(strcmp(argv[i], "-dlatex") == 0) || (strcmp(argv[i], "-dascii") == 0) || (strcmp(argv[i], "-stat") == 0)) {
Printf(stderr, "swig: Warning. %s option deprecated.\n", argv[i]);
Swig_mark_arg(i);
} else if ((strcmp(argv[i], "-help") == 0) || (strcmp(argv[i], "--help") == 0)) {
if (strcmp(argv[i], "--help") == 0)
strcpy(argv[i], "-help");

View file

@ -18,12 +18,6 @@
#include "preprocessor.h"
#include "swigwarn.h"
#if !defined(HAVE_BOOL)
typedef int bool;
#define true ((bool)1)
#define false ((bool)0)
#endif
#define NOT_VIRTUAL 0
#define PLAIN_VIRTUAL 1
#define PURE_VIRTUAL 2
@ -99,6 +93,7 @@ public:
virtual int usingDeclaration(Node *n);
virtual int namespaceDeclaration(Node *n);
virtual int templateDeclaration(Node *n);
virtual int lambdaDeclaration(Node *n);
enum AccessMode { PUBLIC, PRIVATE, PROTECTED };
@ -120,6 +115,8 @@ public:
virtual ~Language();
virtual int emit_one(Node *n);
String *directorClassName(Node *n);
/* Parse command line options */
virtual void main(int argc, char *argv[]);
@ -211,9 +208,13 @@ public:
/* Miscellaneous */
virtual int validIdentifier(String *s); /* valid identifier? */
virtual int addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope = ""); /* Add symbol */
virtual int addInterfaceSymbol(const String *interface_name, Node *n, const_String_or_char_ptr scope = "");
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 *symbolLookup(const String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */
virtual Hash* symbolAddScope(const_String_or_char_ptr scope);
virtual Hash* symbolScopeLookup(const_String_or_char_ptr scope);
virtual Hash* symbolScopePseudoSymbolLookup(const_String_or_char_ptr scope);
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? */
@ -285,15 +286,47 @@ protected:
/* Return the current class prefix */
String *getClassPrefix() const;
/* Return the current enum class prefix */
String *getEnumClassPrefix() const;
/* Fully qualified type name to use */
String *getClassType() const;
/* Return true if the current method is part of a smart-pointer */
int is_smart_pointer() const;
/* Return the name to use for the given parameter. */
virtual String *makeParameterName(Node *n, Parm *p, int arg_num, bool setter = false) const;
/* Some language modules require additional wrappers for virtual methods not declared in sub-classes */
virtual bool extraDirectorProtectedCPPMethodsRequired() const;
public:
enum NestedClassSupport {
NCS_None, // Target language does not have an equivalent to nested classes
NCS_Full, // Target language does have an equivalent to nested classes and is fully implemented
NCS_Unknown // Target language may or may not have an equivalent to nested classes. If it does, it has not been implemented yet.
};
/* Does target language support nested classes? Default is NCS_Unknown.
If NCS_Unknown is returned, then the nested classes will be ignored unless
%feature "flatnested" is applied to them, in which case they will appear in global space.
If the target language does not support the notion of class
nesting, the language module should return NCS_None from this function, and
the nested classes will be moved to the global scope (like implicit global %feature "flatnested").
*/
virtual NestedClassSupport nestedClassesSupport() const;
/* Returns true if the target language supports key word arguments (kwargs) */
virtual bool kwargsSupport() const;
protected:
/* Identifies if a protected members that are generated when the allprotected option is used.
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;
@ -374,7 +407,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);
@ -391,15 +423,34 @@ extern "C" {
}
/* Contracts */
void Swig_contracts(Node *n);
void Swig_contract_mode_set(int flag);
int Swig_contract_mode_get();
/* Browser */
void Swig_browser(Node *n, int);
void Swig_default_allocators(Node *n);
void Swig_process_types(Node *n);
/* Nested classes */
void Swig_nested_process_classes(Node *n);
void Swig_nested_name_unnamed_c_structs(Node *n);
/* Interface feature */
void Swig_interface_feature_enable();
void Swig_interface_propagate_methods(Node *n);
/* Miscellaneous */
template <class T> class save_value {
T _value;
T& _value_ptr;
save_value(const save_value&);
save_value& operator=(const save_value&);
public:
save_value(T& value) : _value(value), _value_ptr(value) {}
save_value(T& value, T new_val) : _value(value), _value_ptr(value) { value = new_val; }
~save_value() { _value_ptr = _value; }
};
#endif

View file

@ -11,13 +11,10 @@
* Tcl8 language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_tcl8_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
static int treduce = SWIG_cparse_template_reduce(0);
static const char *usage = (char *) "\
static const char *usage = "\
Tcl 8 Options (available with -tcl)\n\
-itcl - Enable ITcl support\n\
-nosafe - Leave out SafeInit module function.\n\
@ -168,9 +165,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGTCL\n");
Printf(f_runtime, "\n");
Printf(f_runtime, "\n\n#ifndef SWIGTCL\n#define SWIGTCL\n#endif\n\n");
/* Set the module name, namespace, and prefix */
@ -185,7 +180,7 @@ public:
/* If shadow classing is enabled, we're going to change the module name to "_module" */
if (itcl) {
String *filen;
filen = NewStringf("%s%s.itcl", Swig_file_dirname(outfile), module);
filen = NewStringf("%s%s.itcl", SWIG_output_directory(), module);
Insert(module, 0, "_");
@ -248,7 +243,6 @@ public:
if (itcl) {
Printv(f_shadow, f_shadow_stubs, "\n", NIL);
Close(f_shadow);
Delete(f_shadow);
}
@ -259,7 +253,6 @@ public:
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
return SWIG_OK;
@ -748,6 +741,7 @@ public:
have_constructor = 0;
have_destructor = 0;
destructor_action = 0;
constructor_name = 0;
if (itcl) {
constructor = NewString("");
@ -944,7 +938,7 @@ public:
Printv(f_shadow, " constructor { } {\n", NIL);
Printv(f_shadow, " # This constructor will fail if called directly\n", NIL);
Printv(f_shadow, " if { [info class] == \"::", class_name, "\" } {\n", NIL);
Printv(f_shadow, " error \"No constructor for class ", class_name, (Getattr(n, "abstract") ? " - class is abstract" : ""), "\"\n", NIL);
Printv(f_shadow, " error \"No constructor for class ", class_name, (Getattr(n, "abstracts") ? " - class is abstract" : ""), "\"\n", NIL);
Printv(f_shadow, " }\n", NIL);
Printv(f_shadow, " }\n", NIL);
}
@ -972,7 +966,7 @@ public:
Printf(f_wrappers, ",0");
}
Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname, "_bases,",
"swig_", mangled_classname, "_base_names, &swig_module };\n", NIL);
"swig_", mangled_classname, "_base_names, &swig_module, SWIG_TCL_HASHTABLE_INIT };\n", NIL);
if (!itcl) {
Printv(cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, (ClientData)&_wrap_class_", mangled_classname,
@ -1206,7 +1200,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;
}

View file

@ -16,8 +16,6 @@
* and other information needed for compilation.
* ----------------------------------------------------------------------------- */
char cvsroot_typepass_cxx[] = "$Id$";
#include "swigmod.h"
#include "cparse.h"
@ -40,7 +38,14 @@ class TypePass:private Dispatcher {
Hash *classhash;
List *normalize;
TypePass() {
TypePass() :
inclass(0),
module(0),
importmode(0),
nsname(0),
nssymname(0),
classhash(0),
normalize(0) {
}
/* Normalize a type. Replaces type with fully qualified version */
@ -173,6 +178,20 @@ class TypePass:private Dispatcher {
}
continue;
}
// A case when both outer and nested classes inherit from the same parent. Constructor may be found instead of the class itself.
} else if (GetFlag(cls, "nested") && checkAttribute(bcls, "nodeType", "constructor")) {
bcls = Getattr(bcls, "parentNode");
if (Getattr(bcls, "typepass:visit")) {
if (!Getattr(bcls, "feature:onlychildren")) {
if (!ilist)
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));
}
}
break;
}
if (Strcmp(nodeType(bcls), "classforward") != 0) {
Swig_error(Getfile(bname), Getline(bname), "'%s' is not a valid base class.\n", SwigType_namestr(bname));
@ -185,9 +204,14 @@ class TypePass:private Dispatcher {
bcls = 0;
} else {
if (Getattr(bcls, "typepass:visit")) {
if (!ilist)
ilist = alist = NewList();
Append(ilist, bcls);
if (!Getattr(bcls, "feature:onlychildren")) {
if (!ilist)
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));
}
} else {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' undefined.\n", SwigType_namestr(bname));
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "'%s' must be defined before it is used as a base class.\n", SwigType_namestr(bname));
@ -230,41 +254,38 @@ class TypePass:private Dispatcher {
Node *bclass = n; /* Getattr(n,"class"); */
Hash *scopes = Getattr(bclass, "typescope");
SwigType_inherit(clsname, bname, cast, 0);
String *smartptr = Getattr(first, "feature:smartptr");
if (smartptr) {
SwigType *smart = 0;
SwigType *spt = Swig_cparse_type(smartptr);
if (spt) {
smart = SwigType_typedef_resolve_all(spt);
Delete(spt);
/* Record a (fake) inheritance relationship between smart pointer
and smart pointer to base class, so that smart pointer upcasts
are automatically generated. */
SwigType *bsmart = Copy(smart);
SwigType *rclsname = SwigType_typedef_resolve_all(clsname);
SwigType *rbname = SwigType_typedef_resolve_all(bname);
Replaceall(bsmart, rclsname, rbname);
Delete(rclsname);
Delete(rbname);
String *smartnamestr = SwigType_namestr(smart);
String *bsmartnamestr = SwigType_namestr(bsmart);
/* construct casting code */
String *convcode = NewStringf("\n *newmemory = SWIG_CAST_NEW_MEMORY;\n return (void *) new %s(*(%s *)$from);\n", bsmartnamestr, smartnamestr);
Delete(bsmartnamestr);
Delete(smartnamestr);
/* setup inheritance relationship between smart pointer templates */
SwigType_inherit(smart, bsmart, 0, convcode);
if (!GetFlag(bclass, "feature:smartptr"))
Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Base class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(bclass, "name")), SwigType_namestr(Getattr(first, "name")));
Delete(convcode);
Delete(bsmart);
if (ispublic && !GetFlag(bclass, "feature:ignore")) {
String *smartptr = Getattr(first, "feature:smartptr");
if (smartptr) {
SwigType *smart = Swig_cparse_smartptr(first);
if (smart) {
/* Record a (fake) inheritance relationship between smart pointer
and smart pointer to base class, so that smart pointer upcasts
are automatically generated. */
SwigType *bsmart = Copy(smart);
SwigType *rclsname = SwigType_typedef_resolve_all(clsname);
SwigType *rbname = SwigType_typedef_resolve_all(bname);
Replaceall(bsmart, rclsname, rbname);
Delete(rclsname);
Delete(rbname);
String *smartnamestr = SwigType_namestr(smart);
String *bsmartnamestr = SwigType_namestr(bsmart);
/* construct casting code */
String *convcode = NewStringf("\n *newmemory = SWIG_CAST_NEW_MEMORY;\n return (void *) new %s(*(%s *)$from);\n", bsmartnamestr, smartnamestr);
Delete(bsmartnamestr);
Delete(smartnamestr);
/* setup inheritance relationship between smart pointer templates */
SwigType_inherit(smart, bsmart, 0, convcode);
if (!GetFlag(bclass, "feature:smartptr"))
Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Base class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(bclass, "name")), SwigType_namestr(Getattr(first, "name")));
Delete(convcode);
Delete(bsmart);
}
Delete(smart);
} else {
Swig_error(Getfile(first), Getline(first), "Invalid type (%s) in 'smartptr' feature for class %s.\n", SwigType_namestr(smartptr), SwigType_namestr(clsname));
if (GetFlag(bclass, "feature:smartptr"))
Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Derived class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(first, "name")), SwigType_namestr(Getattr(bclass, "name")));
}
} else {
if (GetFlag(bclass, "feature:smartptr"))
Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Derived class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(first, "name")), SwigType_namestr(Getattr(bclass, "name")));
}
if (!importmode) {
String *btype = Copy(bname);
@ -393,7 +414,7 @@ class TypePass:private Dispatcher {
String *unnamed = Getattr(n, "unnamed");
String *storage = Getattr(n, "storage");
String *kind = Getattr(n, "kind");
Node *oldinclass = inclass;
save_value<Node*> oldinclass(inclass);
List *olist = normalize;
Symtab *symtab;
String *nname = 0;
@ -452,6 +473,17 @@ class TypePass:private Dispatcher {
if (unnamed && tdname && (Cmp(storage, "typedef") == 0)) {
SwigType_typedef(unnamed, tdname);
}
// name of the outer class should already be patched to contain its outer classes names, but not to contain namespaces
// namespace name (if present) is added after processing child nodes
if (Getattr(n, "nested:outer") && name) {
String *outerName = Getattr(Getattr(n, "nested:outer"), "name");
name = NewStringf("%s::%s", outerName, name);
Setattr(n, "name", name);
if (tdname) {
tdname = NewStringf("%s::%s", outerName, tdname);
Setattr(n, "tdname", tdname);
}
}
if (nsname && name) {
nname = NewStringf("%s::%s", nsname, name);
@ -469,7 +501,8 @@ class TypePass:private Dispatcher {
SwigType_attach_symtab(Getattr(n, "symtab"));
/* Inherit type definitions into the class */
if (name) {
if (name && !(GetFlag(n, "nested") && !checkAttribute(n, "access", "public") &&
(GetFlag(n, "feature:flatnested") || Language::instance()->nestedClassesSupport() == Language::NCS_None))) {
cplus_inherit_types(n, 0, nname ? nname : (fname ? fname : name));
}
@ -502,8 +535,6 @@ class TypePass:private Dispatcher {
normalize = olist;
inclass = oldinclass;
/* If in a namespace, patch the class name */
if (nname) {
Setattr(n, "name", nname);
@ -514,7 +545,7 @@ class TypePass:private Dispatcher {
}
/* ------------------------------------------------------------
* namespaceDeclaration()
* templateDeclaration()
* ------------------------------------------------------------ */
virtual int templateDeclaration(Node *n) {
@ -533,6 +564,14 @@ class TypePass:private Dispatcher {
return SWIG_OK;
}
/* ------------------------------------------------------------
* lambdaDeclaration()
* ------------------------------------------------------------ */
virtual int lambdaDeclaration(Node *) {
return SWIG_OK;
}
/* ------------------------------------------------------------
* classforwardDeclaration()
* ------------------------------------------------------------ */
@ -560,12 +599,9 @@ class TypePass:private Dispatcher {
if (alias) {
Typetab *ts = Getattr(n, "typescope");
if (!ts) {
Node *ns;
/* Create a empty scope for the alias */
ns = Getattr(n, "namespace");
if (ns) {
SwigType_scope_alias(name, Getattr(ns, "typescope"));
}
/* Create an empty scope for the alias */
Node *ns = Getattr(n, "namespace");
SwigType_scope_alias(name, Getattr(ns, "typescope"));
ts = Getattr(ns, "typescope");
Setattr(n, "typescope", ts);
}
@ -628,6 +664,9 @@ class TypePass:private Dispatcher {
/* Normalize types. */
SwigType *ty = Getattr(n, "type");
if (!ty) {
return SWIG_OK;
}
normalize_type(ty);
SwigType *decl = Getattr(n, "decl");
if (decl) {
@ -638,7 +677,7 @@ class TypePass:private Dispatcher {
if (GetFlag(n, "conversion_operator")) {
/* The call to the operator in the generated wrapper must be fully qualified in order to compile */
SwigType *name = Getattr(n, "name");
SwigType *qualifiedname = Swig_symbol_string_qualify(name,0);
SwigType *qualifiedname = Swig_symbol_string_qualify(name, 0);
Clear(name);
Append(name, qualifiedname);
Delete(qualifiedname);
@ -697,11 +736,6 @@ class TypePass:private Dispatcher {
normalize_parms(Getattr(n, "parms"));
normalize_parms(Getattr(n, "throws"));
/* If in a namespace, patch the class name */
if (nsname) {
String *nname = NewStringf("%s::%s", nsname, Getattr(n, "name"));
Setattr(n, "name", nname);
}
clean_overloaded(n);
return SWIG_OK;
}
@ -710,12 +744,7 @@ class TypePass:private Dispatcher {
* destructorDeclaration()
* ------------------------------------------------------------ */
virtual int destructorDeclaration(Node *n) {
/* If in a namespace, patch the class name */
if (nsname) {
String *nname = NewStringf("%s::%s", nsname, Getattr(n, "name"));
Setattr(n, "name", nname);
}
virtual int destructorDeclaration(Node *) {
return SWIG_OK;
}
@ -847,16 +876,17 @@ class TypePass:private Dispatcher {
virtual int enumvalueDeclaration(Node *n) {
String *name = Getattr(n, "name");
String *value = Getattr(n, "value");
String *scopedenum = Getattr(parentNode(n), "scopedenum");
if (!value)
value = name;
if (Strcmp(value, name) == 0) {
String *new_value;
if ((nsname || inclass) && cparse_cplusplus) {
if ((nsname || inclass || scopedenum) && cparse_cplusplus) {
new_value = NewStringf("%s::%s", SwigType_namestr(Swig_symbol_qualified(n)), value);
} else {
new_value = NewString(value);
}
if ((nsname || inclass) && !cparse_cplusplus) {
if ((nsname || inclass || scopedenum) && !cparse_cplusplus) {
String *cppvalue = NewStringf("%s::%s", SwigType_namestr(Swig_symbol_qualified(n)), value);
Setattr(n, "cppvalue", cppvalue); /* for target languages that always generate C++ code even when wrapping C code */
}
@ -886,7 +916,22 @@ class TypePass:private Dispatcher {
// Use enumDeclaration() to do all the hard work.
// Note that no children can be emitted in a forward declaration as there aren't any.
return enumDeclaration(n);
int result = enumDeclaration(n);
if (result == SWIG_OK) {
// Detect when the real enum matching the forward enum declaration has not been parsed/declared
SwigType *ty = SwigType_typedef_resolve_all(Getattr(n, "type"));
Replaceall(ty, "enum ", "");
Node *nn = Swig_symbol_clookup(ty, 0);
String *nodetype = nn ? nodeType(nn) : 0;
if (nodetype) {
if (Equal(nodetype, "enumforward")) {
SetFlag(nn, "enumMissing");
} // if a real enum was declared this would be an "enum" node type
}
Delete(ty);
}
return result;
}
#ifdef DEBUG_OVERLOADED
@ -974,7 +1019,7 @@ class TypePass:private Dispatcher {
String *symname = Getattr(n, "sym:name");
while (c) {
if (Strcmp(nodeType(c), "cdecl") == 0) {
if (!(checkAttribute(c, "storage", "static")
if (!(Swig_storage_isstatic(c)
|| checkAttribute(c, "storage", "typedef")
|| checkAttribute(c, "storage", "friend")
|| (Getattr(c, "feature:extend") && !Getattr(c, "code"))
@ -1069,8 +1114,7 @@ class TypePass:private Dispatcher {
* list of overloaded methods we have just added in as child nodes to the "using" node.
* The node will still exist, it is just the symbol table linked list of overloaded methods
* which is hacked. */
if (Getattr(n, "sym:overloaded"))
{
if (Getattr(n, "sym:overloaded")) {
int cnt = 0;
#ifdef DEBUG_OVERLOADED
Node *debugnode = n;
@ -1133,7 +1177,7 @@ class TypePass:private Dispatcher {
#ifdef DEBUG_OVERLOADED
show_overloaded(debugnode);
#endif
clean_overloaded(n); // Needed?
clean_overloaded(n); // Needed?
}
}
}
@ -1144,6 +1188,11 @@ class TypePass:private Dispatcher {
SwigType_typedef_using(uname);
} 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"));
*/
}
}
}
@ -1232,3 +1281,4 @@ void Swig_process_types(Node *n) {
return;
TypePass::pass(n);
}

View file

@ -13,11 +13,9 @@
// TODO: remove remnants of lisptype
char cvsroot_uffi_cxx[] = "$Id$";
#include "swigmod.h"
static const char *usage = (char *) "\
static const char *usage = "\
UFFI Options (available with -uffi)\n\
-identifier-converter <type or funcname> - \n\
Specifies the type of conversion to do on C identifiers\n\
@ -47,7 +45,7 @@ static struct {
String **entries;
} defined_foreign_types;
static const char *identifier_converter = "identifier-convert-null";
static String *identifier_converter = NewString("identifier-convert-null");
static int any_varargs(ParmList *pl) {
Parm *p;
@ -221,14 +219,15 @@ void UFFI::main(int argc, char *argv[]) {
/* check for built-ins */
if (!strcmp(conv, "lispify")) {
identifier_converter = "identifier-convert-lispify";
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-lispify");
} else if (!strcmp(conv, "null")) {
identifier_converter = "identifier-convert-null";
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-null");
} else {
/* Must be user defined */
char *idconv = new char[strlen(conv) + 1];
strcpy(idconv, conv);
identifier_converter = idconv;
Delete(identifier_converter);
identifier_converter = NewString(conv);
}
}
@ -266,9 +265,7 @@ int UFFI::top(Node *n) {
Language::top(n);
Close(f_cl);
Delete(f_cl); // Delete the handle, not the file
Close(f_null);
Delete(f_null);
return SWIG_OK;

View file

@ -11,8 +11,6 @@
* Various utility functions.
* ----------------------------------------------------------------------------- */
char cvsroot_utils_cxx[] = "$Id$";
#include <swigmod.h>
int is_public(Node *n) {

View file

@ -11,8 +11,6 @@
* An Xml parse tree generator.
* ----------------------------------------------------------------------------- */
char cvsroot_xml_cxx[] = "$Id$";
#include "swigmod.h"
static const char *usage = "\
@ -118,7 +116,7 @@ public:
String *k;
indent_level += 4;
print_indent(0);
Printf(out, "<attributelist id=\"%ld\" addr=\"%x\" >\n", ++id, obj);
Printf(out, "<attributelist id=\"%ld\" addr=\"%p\" >\n", ++id, obj);
indent_level += 4;
Iterator ki;
ki = First(obj);
@ -160,14 +158,14 @@ public:
Replaceall(o, "\"", "&quot;");
Replaceall(o, "\\", "\\\\");
Replaceall(o, "\n", "&#10;");
Printf(out, "<attribute name=\"%s\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o);
Printf(out, "<attribute name=\"%s\" value=\"%s\" id=\"%ld\" addr=\"%p\" />\n", ck, o, ++id, o);
Delete(o);
Delete(ck);
} else {
o = Getattr(obj, k);
String *ck = NewString(k);
Replaceall(ck, ":", "_");
Printf(out, "<attribute name=\"%s\" value=\"%x\" id=\"%ld\" addr=\"%x\" />\n", ck, o, ++id, o);
Printf(out, "<attribute name=\"%s\" value=\"%p\" id=\"%ld\" addr=\"%p\" />\n", ck, o, ++id, o);
Delete(ck);
}
}
@ -183,7 +181,7 @@ public:
Node *cobj;
print_indent(0);
Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", nodeType(obj), ++id, obj);
Printf(out, "<%s id=\"%ld\" addr=\"%p\" >\n", nodeType(obj), ++id, obj);
Xml_print_attributes(obj);
cobj = firstChild(obj);
if (cobj) {
@ -203,7 +201,7 @@ public:
void Xml_print_parmlist(ParmList *p, const char* markup = "parmlist") {
print_indent(0);
Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p);
Printf(out, "<%s id=\"%ld\" addr=\"%p\" >\n", markup, ++id, p);
indent_level += 4;
while (p) {
print_indent(0);
@ -221,13 +219,13 @@ public:
void Xml_print_baselist(List *p) {
print_indent(0);
Printf(out, "<baselist id=\"%ld\" addr=\"%x\" >\n", ++id, p);
Printf(out, "<baselist id=\"%ld\" addr=\"%p\" >\n", ++id, p);
indent_level += 4;
Iterator s;
for (s = First(p); s.item; s = Next(s)) {
print_indent(0);
String *item_name = Xml_escape_string(s.item);
Printf(out, "<base name=\"%s\" id=\"%ld\" addr=\"%x\" />\n", item_name, ++id, s.item);
Printf(out, "<base name=\"%s\" id=\"%ld\" addr=\"%p\" />\n", item_name, ++id, s.item);
Delete(item_name);
}
indent_level -= 4;
@ -251,7 +249,7 @@ public:
void Xml_print_module(Node *p) {
print_indent(0);
Printf(out, "<attribute name=\"module\" value=\"%s\" id=\"%ld\" addr=\"%x\" />\n", Getattr(p, "name"), ++id, p);
Printf(out, "<attribute name=\"module\" value=\"%s\" id=\"%ld\" addr=\"%p\" />\n", Getattr(p, "name"), ++id, p);
}
void Xml_print_kwargs(Hash *p) {
@ -272,13 +270,13 @@ public:
void Xml_print_hash(Hash *p, const char *markup) {
print_indent(0);
Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p);
Printf(out, "<%s id=\"%ld\" addr=\"%p\" >\n", markup, ++id, p);
Xml_print_attributes(p);
indent_level += 4;
Iterator n = First(p);
while (n.key) {
print_indent(0);
Printf(out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n.item);
Printf(out, "<%ssitem id=\"%ld\" addr=\"%p\" >\n", markup, ++id, n.item);
Xml_print_attributes(n.item);
print_indent(0);
Printf(out, "</%ssitem >\n", markup);