Typemap API changes to facilitate more uniform typemap handling across language modules - in particular some typemaps usage did not respect the warning attribute and other warning handling and $typemap special variable (which will be refined in future commit) as well as local typemap variable handling:

- remove Swig_typemap_search, Swig_typemap_search_multi and Swig_typemap_attach_kwargs from access outside of typemaps.c (made static)
  - all static methods in typemap.c renamed dropping Swig_ prefix


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11380 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2009-07-08 12:17:45 +00:00
commit 224c83ef09
9 changed files with 304 additions and 280 deletions

View file

@ -626,7 +626,7 @@ void note_implicit_template_instantiation(SwigType *t) {
add_defined_foreign_type(0, 0, t, t, implicit_ns ? implicit_ns : current_namespace); add_defined_foreign_type(0, 0, t, t, implicit_ns ? implicit_ns : current_namespace);
} }
String *get_ffi_type(SwigType *ty, const_String_or_char_ptr name) { String *get_ffi_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
/* lookup defined foreign type. /* lookup defined foreign type.
if it exists, it will return a form suitable for placing if it exists, it will return a form suitable for placing
into lisp code to generate the def-foreign-type name */ into lisp code to generate the def-foreign-type name */
@ -641,18 +641,20 @@ String *get_ffi_type(SwigType *ty, const_String_or_char_ptr name) {
#ifdef ALLEGROCL_TYPE_DEBUG #ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "found_type '%s'\n", found_type); Printf(stderr, "found_type '%s'\n", found_type);
#endif #endif
return (Strcmp(found_type, "forward-reference") ? Copy(found_type) : return (Strcmp(found_type, "forward-reference") ? Copy(found_type) : get_ffi_type(n, fwdref_ffi_type, ""));
get_ffi_type(fwdref_ffi_type, ""));
} else { } else {
Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0); Node *node = NewHash();
Setattr(node, "type", ty);
if (typemap) { Setfile(node, Getfile(n));
String *typespec = Getattr(typemap, "code"); Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("ffitype", node, name, 0);
Delete(node);
if (tm) {
#ifdef ALLEGROCL_TYPE_DEBUG #ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "g-f-t: found ffitype typemap '%s'\n%s\n", typespec, typemap); Printf(stderr, "g-f-t: found ffitype typemap '%s'\n", tm);
#endif #endif
return NewString(typespec); return NewString(tm);
} }
if (SwigType_istemplate(ty)) { if (SwigType_istemplate(ty)) {
@ -673,7 +675,7 @@ String *lookup_defined_foreign_ltype(String *l) {
/* walk type and return string containing lisp version. /* walk type and return string containing lisp version.
recursive. */ recursive. */
String *internal_compose_foreign_type(SwigType *ty) { String *internal_compose_foreign_type(Node *n, SwigType *ty) {
SwigType *tok; SwigType *tok;
String *ffiType = NewString(""); String *ffiType = NewString("");
@ -691,18 +693,18 @@ String *internal_compose_foreign_type(SwigType *ty) {
Printf(ffiType, "("); // start parm list Printf(ffiType, "("); // start parm list
for (Iterator i = First(pl); i.item; i = Next(i)) { for (Iterator i = First(pl); i.item; i = Next(i)) {
SwigType *f_arg = SwigType_strip_qualifiers(i.item); SwigType *f_arg = SwigType_strip_qualifiers(i.item);
Printf(ffiType, "%s ", internal_compose_foreign_type(f_arg)); Printf(ffiType, "%s ", internal_compose_foreign_type(n, f_arg));
Delete(f_arg); Delete(f_arg);
} }
Printf(ffiType, ")"); // end parm list. Printf(ffiType, ")"); // end parm list.
// do function return type. // do function return type.
Printf(ffiType, " %s)", internal_compose_foreign_type(ty)); Printf(ffiType, " %s)", internal_compose_foreign_type(n, ty));
break; break;
} else if (SwigType_ispointer(tok) || SwigType_isreference(tok)) { } else if (SwigType_ispointer(tok) || SwigType_isreference(tok)) {
Printf(ffiType, "(* %s)", internal_compose_foreign_type(ty)); Printf(ffiType, "(* %s)", internal_compose_foreign_type(n, ty));
} else if (SwigType_isarray(tok)) { } else if (SwigType_isarray(tok)) {
Printf(ffiType, "(:array %s", internal_compose_foreign_type(ty)); Printf(ffiType, "(:array %s", internal_compose_foreign_type(n, ty));
String *atype = NewString("int"); String *atype = NewString("int");
String *dim = convert_literal(SwigType_array_getdim(tok, 0), atype); String *dim = convert_literal(SwigType_array_getdim(tok, 0), atype);
Delete(atype); Delete(atype);
@ -713,18 +715,18 @@ String *internal_compose_foreign_type(SwigType *ty) {
} }
} else if (SwigType_ismemberpointer(tok)) { } else if (SwigType_ismemberpointer(tok)) {
// temp // temp
Printf(ffiType, "(* %s)", internal_compose_foreign_type(ty)); Printf(ffiType, "(* %s)", internal_compose_foreign_type(n, ty));
} else { } else {
String *res = get_ffi_type(tok, ""); String *res = get_ffi_type(n, tok, "");
if (res) { if (res) {
Printf(ffiType, "%s", res); Printf(ffiType, "%s", res);
} else { } else {
SwigType *resolved_type = SwigType_typedef_resolve(tok); SwigType *resolved_type = SwigType_typedef_resolve(tok);
if (resolved_type) { if (resolved_type) {
res = get_ffi_type(resolved_type, ""); res = get_ffi_type(n, resolved_type, "");
if (res) { if (res) {
} else { } else {
res = internal_compose_foreign_type(resolved_type); res = internal_compose_foreign_type(n, resolved_type);
} }
if (res) if (res)
Printf(ffiType, "%s", res); Printf(ffiType, "%s", res);
@ -762,7 +764,7 @@ String *internal_compose_foreign_type(SwigType *ty) {
add_forward_referenced_type(nn, 0); add_forward_referenced_type(nn, 0);
// tok_name is dangling here, unused. ouch. why? // tok_name is dangling here, unused. ouch. why?
Printf(ffiType, "%s", get_ffi_type(tok, ""), tok_name); Printf(ffiType, "%s", get_ffi_type(n, tok, ""), tok_name);
} }
} }
} }
@ -770,9 +772,7 @@ String *internal_compose_foreign_type(SwigType *ty) {
return ffiType; return ffiType;
} }
String *compose_foreign_type(SwigType *ty, String * /*id*/ = 0) { String *compose_foreign_type(Node *n, SwigType *ty, String * /*id*/ = 0) {
/* Hash *lookup_res = Swig_typemap_search("ffitype", ty, id, 0); */
#ifdef ALLEGROCL_TYPE_DEBUG #ifdef ALLEGROCL_TYPE_DEBUG
Printf(stderr, "compose_foreign_type: ENTER (%s)...\n ", ty); Printf(stderr, "compose_foreign_type: ENTER (%s)...\n ", ty);
@ -802,7 +802,7 @@ String *compose_foreign_type(SwigType *ty, String * /*id*/ = 0) {
*/ */
SwigType *temp = SwigType_strip_qualifiers(ty); SwigType *temp = SwigType_strip_qualifiers(ty);
String *res = internal_compose_foreign_type(temp); String *res = internal_compose_foreign_type(n, temp);
Delete(temp); Delete(temp);
#ifdef ALLEGROCL_TYPE_DEBUG #ifdef ALLEGROCL_TYPE_DEBUG
@ -1239,7 +1239,7 @@ void emit_full_class(Node *n) {
#ifdef ALLEGROCL_WRAP_DEBUG #ifdef ALLEGROCL_WRAP_DEBUG
Printf(stderr, "slot name = '%s' ns = '%s' class-of '%s' and type = '%s'\n", cname, ns, name, childType); Printf(stderr, "slot name = '%s' ns = '%s' class-of '%s' and type = '%s'\n", cname, ns, name, childType);
#endif #endif
Printf(slotdefs, "(#.(swig-insert-id \"%s\" %s :type :slot :class \"%s\") %s)", cname, ns, name, compose_foreign_type(childType)); Printf(slotdefs, "(#.(swig-insert-id \"%s\" %s :type :slot :class \"%s\") %s)", cname, ns, name, compose_foreign_type(n, childType));
Delete(ns); Delete(ns);
if (access && Strcmp(access, "public")) if (access && Strcmp(access, "public"))
Printf(slotdefs, " ;; %s member", access); Printf(slotdefs, " ;; %s member", access);
@ -1322,7 +1322,7 @@ void emit_typedef(Node *n) {
String *name; String *name;
String *sym_name = Getattr(n, "sym:name"); String *sym_name = Getattr(n, "sym:name");
String *type = NewStringf("%s%s", Getattr(n, "decl"), Getattr(n, "type")); String *type = NewStringf("%s%s", Getattr(n, "decl"), Getattr(n, "type"));
String *lisp_type = compose_foreign_type(type); String *lisp_type = compose_foreign_type(n, type);
Delete(type); Delete(type);
Node *in_class = Getattr(n, "allegrocl:typedef:in-class"); Node *in_class = Getattr(n, "allegrocl:typedef:in-class");
@ -1371,9 +1371,13 @@ void emit_enum_type_no_wrap(Node *n) {
name = unnamed ? Getattr(n, "allegrocl:name") : Getattr(n, "sym:name"); name = unnamed ? Getattr(n, "allegrocl:name") : Getattr(n, "sym:name");
SwigType *tmp = NewStringf("enum %s", unnamed ? unnamed : name); SwigType *tmp = NewStringf("enum %s", unnamed ? unnamed : name);
Hash *typemap = Swig_typemap_search("ffitype", tmp, 0, 0); Node *node = NewHash();
String *enumtype = Getattr(typemap, "code"); Setattr(node, "type", tmp);
// enumtype = compose_foreign_type(tmp); Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *enumtype = Swig_typemap_lookup("ffitype", node, "", 0);
Delete(node);
Delete(tmp); Delete(tmp);
if (name) { if (name) {
@ -1427,12 +1431,14 @@ void emit_enum_type(Node *n) {
name = unnamed ? Getattr(n, "allegrocl:name") : Getattr(n, "sym:name"); name = unnamed ? Getattr(n, "allegrocl:name") : Getattr(n, "sym:name");
SwigType *tmp = NewStringf("enum %s", unnamed ? unnamed : name); SwigType *tmp = NewStringf("enum %s", unnamed ? unnamed : name);
// SwigType *tmp = NewStringf("enum ACL_SWIG_ENUM_NAME");
Hash *typemap = Swig_typemap_search("ffitype", tmp, 0, 0); Node *node = NewHash();
String *enumtype = Getattr(typemap, "code"); Setattr(node, "type", tmp);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *enumtype = Swig_typemap_lookup("ffitype", node, "", 0);
Delete(node);
// enumtype = compose_foreign_type(tmp);
Delete(tmp); Delete(tmp);
if (name) { if (name) {
@ -1979,14 +1985,16 @@ int any_varargs(ParmList *pl) {
return 0; return 0;
} }
String *get_lisp_type(SwigType *ty, const_String_or_char_ptr name) { String *get_lisp_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
Hash *typemap = Swig_typemap_search("lisptype", ty, name, 0); Node *node = NewHash();
if (typemap) { Setattr(node, "type", ty);
String *typespec = Getattr(typemap, "code"); Setattr(node, "name", name);
return NewString(typespec); Setfile(node, Getfile(n));
} else { Setline(node, Getline(n));
return NewString(""); const String *tm = Swig_typemap_lookup("lisptype", node, "", 0);
} Delete(node);
return tm ? NewString(tm) : NewString("");
} }
Node *parent_node_skipping_extends(Node *n) { Node *parent_node_skipping_extends(Node *n) {
@ -2274,18 +2282,21 @@ int ALLEGROCL::emit_buffered_defuns(Node *n) {
return SWIG_OK; return SWIG_OK;
} }
String *dispatching_type(Parm *p) { String *dispatching_type(Node *n, Parm *p) {
String *result = 0; String *result = 0;
String *parsed = Getattr(p, "type"); //Swig_cparse_type(Getattr(p,"tmap:ctype")); String *parsed = Getattr(p, "type"); //Swig_cparse_type(Getattr(p,"tmap:ctype"));
String *cl_t = SwigType_typedef_resolve_all(parsed); String *cl_t = SwigType_typedef_resolve_all(parsed);
Hash *typemap = Swig_typemap_search("lispclass", parsed, Getattr(p, "name"), 0); Node *node = NewHash();
// Printf(stderr,"inspecting type '%s' for class\n", parsed); Setattr(node, "type", parsed);
// Printf(stderr," cfcocr = '%s' res_all = '%s'\n", Setfile(node, Getfile(n));
// class_from_class_or_class_ref(parsed), cl_t); Setline(node, Getline(n));
if (typemap) { const String *tm = Swig_typemap_lookup("lispclass", node, Getattr(p, "name"), 0);
result = Copy(Getattr(typemap, "code")); Delete(node);
if (tm) {
result = Copy(tm);
} else { } else {
String *lookup_type = class_from_class_or_class_ref(parsed); String *lookup_type = class_from_class_or_class_ref(parsed);
if (lookup_type) if (lookup_type)
@ -2305,24 +2316,6 @@ String *dispatching_type(Parm *p) {
return result; return result;
} }
String *defmethod_lambda_list(Node *overload) {
String *result = NewString("");
ParmList *parms = Getattr(overload, "wrap:parms");
Parm *p;
int a;
for (a = 0, p = parms; p; p = nextSibling(p), ++a) {
if (a != 0)
Printf(result, " ");
Printf(result, "(arg%d ", a);
Printf(result, "%s", dispatching_type(p));
Printf(result, ")");
}
return result;
}
int ALLEGROCL::emit_dispatch_defun(Node *n) { int ALLEGROCL::emit_dispatch_defun(Node *n) {
#ifdef ALLEGROCL_WRAP_DEBUG #ifdef ALLEGROCL_WRAP_DEBUG
Printf(stderr, "emit_dispatch_defun: ENTER... "); Printf(stderr, "emit_dispatch_defun: ENTER... ");
@ -2429,9 +2422,9 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
String *argname = NewStringf("PARM%d_%s", largnum, Getattr(p, "name")); String *argname = NewStringf("PARM%d_%s", largnum, Getattr(p, "name"));
// Printf(stderr,"%s\n", Getattr(p,"tmap:lin")); // Printf(stderr,"%s\n", Getattr(p,"tmap:lin"));
String *ffitype = compose_foreign_type(argtype, Getattr(p,"name")); String *ffitype = compose_foreign_type(n, argtype, Getattr(p,"name"));
String *deref_ffitype = dereference_ffitype(ffitype); String *deref_ffitype = dereference_ffitype(ffitype);
String *lisptype = get_lisp_type(parmtype, Getattr(p, "name")); String *lisptype = get_lisp_type(n, parmtype, Getattr(p, "name"));
#ifdef ALLEGROCL_DEBUG #ifdef ALLEGROCL_DEBUG
Printf(stderr, "lisptype of '%s' '%s' = '%s'\n", parmtype, Printf(stderr, "lisptype of '%s' '%s' = '%s'\n", parmtype,
@ -2454,7 +2447,7 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
Replaceall(wrap->code, "$body", parm_code); Replaceall(wrap->code, "$body", parm_code);
} }
String *dispatchtype = Getattr(n, "sym:overloaded") ? dispatching_type(p) : NewString(""); String *dispatchtype = Getattr(n, "sym:overloaded") ? dispatching_type(n, p) : NewString("");
// if this parameter has been removed from the C/++ wrapper // if this parameter has been removed from the C/++ wrapper
// it shouldn't be in the lisp wrapper either. // it shouldn't be in the lisp wrapper either.
@ -2485,13 +2478,13 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
SwigType *parsed = Swig_cparse_type(Getattr(n, "tmap:ctype")); SwigType *parsed = Swig_cparse_type(Getattr(n, "tmap:ctype"));
// SwigType *cl_t = SwigType_typedef_resolve_all(parsed); // SwigType *cl_t = SwigType_typedef_resolve_all(parsed);
SwigType *cl_t = class_from_class_or_class_ref(parsed); SwigType *cl_t = class_from_class_or_class_ref(parsed);
String *out_ffitype = compose_foreign_type(parsed); String *out_ffitype = compose_foreign_type(n, parsed);
String *deref_out_ffitype; String *deref_out_ffitype;
String *out_temp = Copy(parsed); String *out_temp = Copy(parsed);
if (SwigType_ispointer(out_temp)) { if (SwigType_ispointer(out_temp)) {
SwigType_pop(out_temp); SwigType_pop(out_temp);
deref_out_ffitype = compose_foreign_type(out_temp); deref_out_ffitype = compose_foreign_type(n, out_temp);
} else { } else {
deref_out_ffitype = Copy(out_ffitype); deref_out_ffitype = Copy(out_ffitype);
} }
@ -2547,7 +2540,7 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) {
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
// Lisp foreign call return type and optimizations // // Lisp foreign call return type and optimizations //
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
Printf(fcl, " (:returning (%s %s)", compose_foreign_type(result_type), get_lisp_type(Getattr(n, "type"), "result")); Printf(fcl, " (:returning (%s %s)", compose_foreign_type(n, result_type), get_lisp_type(n, Getattr(n, "type"), "result"));
for (Iterator option = First(n); option.item; option = Next(option)) { for (Iterator option = First(n); option.item; option = Next(option)) {
if (Strncmp("feature:ffargs:", option.key, 15)) if (Strncmp("feature:ffargs:", option.key, 15))
@ -2926,10 +2919,6 @@ int ALLEGROCL::variableWrapper(Node *n) {
Printf(f_runtime, "EXPORT %s %s;\n%s %s = %s%s;\n", ctype, mangled_name, ctype, mangled_name, (pointer_added ? "&" : ""), name); Printf(f_runtime, "EXPORT %s %s;\n%s %s = %s%s;\n", ctype, mangled_name, ctype, mangled_name, (pointer_added ? "&" : ""), name);
Printf(f_cl, "(swig-defvar \"%s\" :type %s)\n", mangled_name, ((SwigType_isconst(type)) ? ":constant" : ":variable")); Printf(f_cl, "(swig-defvar \"%s\" :type %s)\n", mangled_name, ((SwigType_isconst(type)) ? ":constant" : ":variable"));
/*
Printf(f_runtime, "// swigtype: %s\n", SwigType_typedef_resolve_all(Getattr(n,"type")));
Printf(f_runtime, "// vwrap: %s\n", compose_foreign_type(SwigType_strip_qualifiers(Copy(rtype))));
*/
Printf(stderr,"***\n"); Printf(stderr,"***\n");
Delete(mangled_name); Delete(mangled_name);
@ -2971,7 +2960,7 @@ int ALLEGROCL::typedefHandler(Node *n) {
SwigType *typedef_type = Getattr(n,"type"); SwigType *typedef_type = Getattr(n,"type");
// has the side-effect of noting any implicit // has the side-effect of noting any implicit
// template instantiations in type. // template instantiations in type.
String *ff_type = compose_foreign_type(typedef_type); String *ff_type = compose_foreign_type(n, typedef_type);
String *sym_name = Getattr(n, "sym:name"); String *sym_name = Getattr(n, "sym:name");
@ -3132,7 +3121,7 @@ int ALLEGROCL::cppClassHandler(Node *n) {
Printf(stderr, "looking at child '%x' of type '%s'\n", c, childType); Printf(stderr, "looking at child '%x' of type '%s'\n", c, childType);
#endif #endif
if (!SwigType_isfunction(childType)) if (!SwigType_isfunction(childType))
Delete(compose_foreign_type(childType)); Delete(compose_foreign_type(n, childType));
Delete(childType); Delete(childType);
} }

View file

@ -819,14 +819,15 @@ void CFFI::emit_struct_union(Node *n, bool un = false) {
// Getattr(c, "type")); // Getattr(c, "type"));
// SWIG_exit(EXIT_FAILURE); // SWIG_exit(EXIT_FAILURE);
} else { } else {
SwigType *childType = NewStringf("%s%s", Getattr(c, "decl"), SwigType *childType = NewStringf("%s%s", Getattr(c, "decl"), Getattr(c, "type"));
Getattr(c, "type"));
Hash *typemap = Swig_typemap_search("cin", childType, "", 0); Node *node = NewHash();
String *typespec = NewString(""); Setattr(node, "type", childType);
if (typemap) { Setfile(node, Getfile(n));
typespec = NewString(Getattr(typemap, "code")); Setline(node, Getline(n));
} const String *tm = Swig_typemap_lookup("cin", node, "", 0);
String *typespec = tm ? NewString(tm) : NewString("");
String *slot_name = lispify_name(c, Getattr(c, "sym:name"), "'slotname"); String *slot_name = lispify_name(c, Getattr(c, "sym:name"), "'slotname");
if (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0) if (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0)
@ -834,6 +835,8 @@ void CFFI::emit_struct_union(Node *n, bool un = false) {
Printf(f_cl, "\n\t(%s %s)", slot_name, typespec); Printf(f_cl, "\n\t(%s %s)", slot_name, typespec);
Delete(node);
Delete(childType);
Delete(typespec); Delete(typespec);
} }
} }

View file

@ -25,7 +25,7 @@ public:
virtual int typedefHandler(Node *n); virtual int typedefHandler(Node *n);
List *entries; List *entries;
private: private:
String *get_ffi_type(SwigType *ty); String *get_ffi_type(Node *n, SwigType *ty);
String *convert_literal(String *num_param, String *type); String *convert_literal(String *num_param, String *type);
String *strip_parens(String *string); String *strip_parens(String *string);
int extern_all_flag; int extern_all_flag;
@ -167,7 +167,7 @@ int CLISP::functionWrapper(Node *n) {
String *argname = Getattr(p, "name"); String *argname = Getattr(p, "name");
// SwigType *argtype; // SwigType *argtype;
String *ffitype = get_ffi_type(Getattr(p, "type")); String *ffitype = get_ffi_type(n, Getattr(p, "type"));
int tempargname = 0; int tempargname = 0;
@ -190,7 +190,7 @@ int CLISP::functionWrapper(Node *n) {
if (ParmList_len(pl) != 0) { if (ParmList_len(pl) != 0) {
Printf(f_cl, ")\n"); /* finish arg list */ Printf(f_cl, ")\n"); /* finish arg list */
} }
String *ffitype = get_ffi_type(Getattr(n, "type")); String *ffitype = get_ffi_type(n, Getattr(n, "type"));
if (Strcmp(ffitype, "NIL")) { //when return type is not nil if (Strcmp(ffitype, "NIL")) { //when return type is not nil
Printf(f_cl, "\t(:return-type %s)\n", ffitype); Printf(f_cl, "\t(:return-type %s)\n", ffitype);
} }
@ -222,7 +222,7 @@ int CLISP::variableWrapper(Node *n) {
return SWIG_OK; return SWIG_OK;
String *var_name = Getattr(n, "sym:name"); String *var_name = Getattr(n, "sym:name");
String *lisp_type = get_ffi_type(Getattr(n, "type")); String *lisp_type = get_ffi_type(n, Getattr(n, "type"));
Printf(f_cl, "\n(ffi:def-c-var %s\n (:name \"%s\")\n (:type %s)\n", var_name, var_name, lisp_type); Printf(f_cl, "\n(ffi:def-c-var %s\n (:name \"%s\")\n (:type %s)\n", var_name, var_name, lisp_type);
Printf(f_cl, "\t(:library +library-name+))\n"); Printf(f_cl, "\t(:library +library-name+))\n");
Append(entries, var_name); Append(entries, var_name);
@ -234,7 +234,7 @@ int CLISP::variableWrapper(Node *n) {
int CLISP::typedefHandler(Node *n) { int CLISP::typedefHandler(Node *n) {
if (generate_typedef_flag) { if (generate_typedef_flag) {
is_function = 0; is_function = 0;
Printf(f_cl, "\n(ffi:def-c-type %s %s)\n", Getattr(n, "name"), get_ffi_type(Getattr(n, "type"))); Printf(f_cl, "\n(ffi:def-c-type %s %s)\n", Getattr(n, "name"), get_ffi_type(n, Getattr(n, "type")));
} }
return Language::typedefHandler(n); return Language::typedefHandler(n);
@ -290,7 +290,7 @@ int CLISP::classDeclaration(Node *n) {
String *temp = Copy(Getattr(c, "decl")); String *temp = Copy(Getattr(c, "decl"));
Append(temp, Getattr(c, "type")); //appending type to the end, otherwise wrong type Append(temp, Getattr(c, "type")); //appending type to the end, otherwise wrong type
String *lisp_type = get_ffi_type(temp); String *lisp_type = get_ffi_type(n, temp);
Delete(temp); Delete(temp);
String *slot_name = Getattr(c, "sym:name"); String *slot_name = Getattr(c, "sym:name");
@ -371,15 +371,20 @@ String *CLISP::convert_literal(String *num_param, String *type) {
return res; return res;
} }
String *CLISP::get_ffi_type(SwigType *ty) { String *CLISP::get_ffi_type(Node *n, SwigType *ty) {
Hash *typemap = Swig_typemap_search("in", ty, "", 0); Node *node = NewHash();
if (typemap) { Setattr(node, "type", ty);
String *typespec = Getattr(typemap, "code"); Setfile(node, Getfile(n));
return NewString(typespec); Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("in", node, "", 0);
Delete(node);
if (tm) {
return NewString(tm);
} else if (SwigType_ispointer(ty)) { } else if (SwigType_ispointer(ty)) {
SwigType *cp = Copy(ty); SwigType *cp = Copy(ty);
SwigType_del_pointer(cp); SwigType_del_pointer(cp);
String *inner_type = get_ffi_type(cp); String *inner_type = get_ffi_type(n, cp);
if (SwigType_isfunction(cp)) { if (SwigType_isfunction(cp)) {
return inner_type; return inner_type;
@ -409,12 +414,12 @@ String *CLISP::get_ffi_type(SwigType *ty) {
Delete(array_dim); Delete(array_dim);
SwigType_del_array(cp); SwigType_del_array(cp);
SwigType_add_pointer(cp); SwigType_add_pointer(cp);
String *str = get_ffi_type(cp); String *str = get_ffi_type(n, cp);
Delete(cp); Delete(cp);
return str; return str;
} else { } else {
SwigType_pop_arrays(cp); SwigType_pop_arrays(cp);
String *inner_type = get_ffi_type(cp); String *inner_type = get_ffi_type(n, cp);
Delete(cp); Delete(cp);
int ndim = SwigType_array_ndim(ty); int ndim = SwigType_array_ndim(ty);
@ -455,7 +460,7 @@ String *CLISP::get_ffi_type(SwigType *ty) {
for (Parm *p = pl; p; p = nextSibling(p), argnum++) { for (Parm *p = pl; p; p = nextSibling(p), argnum++) {
String *argname = Getattr(p, "name"); String *argname = Getattr(p, "name");
SwigType *argtype = Getattr(p, "type"); SwigType *argtype = Getattr(p, "type");
String *ffitype = get_ffi_type(argtype); String *ffitype = get_ffi_type(n, argtype);
int tempargname = 0; int tempargname = 0;
@ -475,7 +480,7 @@ String *CLISP::get_ffi_type(SwigType *ty) {
if (ParmList_len(pl) != 0) { if (ParmList_len(pl) != 0) {
Printf(args, ")\n"); /* finish arg list */ Printf(args, ")\n"); /* finish arg list */
} }
String *ffitype = get_ffi_type(cp); String *ffitype = get_ffi_type(n, cp);
String *str = NewStringf("(ffi:c-function %s \t\t\t\t(:return-type %s))", args, ffitype); String *str = NewStringf("(ffi:c-function %s \t\t\t\t(:return-type %s))", args, ffitype);
Delete(fn); Delete(fn);
Delete(args); Delete(args);

View file

@ -1115,16 +1115,16 @@ public:
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum
// Pure C# baseclass and interfaces // Pure C# baseclass and interfaces
const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE); const String *pure_baseclass = typemapLookup(n, "csbase", typemap_lookup_type, WARN_NONE);
const String *pure_interfaces = typemapLookup("csinterfaces", typemap_lookup_type, WARN_NONE); const String *pure_interfaces = typemapLookup(n, "csinterfaces", typemap_lookup_type, WARN_NONE);
// Class attributes // Class attributes
const String *csattributes = typemapLookup("csattributes", typemap_lookup_type, WARN_NONE); const String *csattributes = typemapLookup(n, "csattributes", typemap_lookup_type, WARN_NONE);
if (csattributes && *Char(csattributes)) if (csattributes && *Char(csattributes))
Printf(enum_code, "%s\n", csattributes); Printf(enum_code, "%s\n", csattributes);
// Emit the enum // Emit the enum
Printv(enum_code, typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really) Printv(enum_code, typemapLookup(n, "csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really)
" ", symname, (*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass, ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces " ", symname, (*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass, ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces
", " : "", pure_interfaces, " {\n", NIL); ", " : "", pure_interfaces, " {\n", NIL);
} else { } else {
@ -1140,8 +1140,8 @@ public:
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum
// Finish the enum declaration // Finish the enum declaration
// Typemaps are used to generate the enum definition in a similar manner to proxy classes. // Typemaps are used to generate the enum definition in a similar manner to proxy classes.
Printv(enum_code, (enum_feature == ProperEnum) ? "\n" : typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class Printv(enum_code, (enum_feature == ProperEnum) ? "\n" : typemapLookup(n, "csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code typemapLookup(n, "cscode", typemap_lookup_type, WARN_NONE), // extra C# code
"}", NIL); "}", NIL);
Replaceall(enum_code, "$csclassname", symname); Replaceall(enum_code, "$csclassname", symname);
@ -1177,7 +1177,7 @@ public:
addOpenNamespace(namespce, f_enum); addOpenNamespace(namespce, f_enum);
Printv(f_enum, typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements Printv(f_enum, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements
"\n", enum_code, "\n", NIL); "\n", enum_code, "\n", NIL);
addCloseNamespace(namespce, f_enum); addCloseNamespace(namespce, f_enum);
@ -1243,7 +1243,7 @@ public:
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern // Wrap C/C++ enums with constant integers or use the typesafe enum pattern
const String *parent_name = Getattr(parentNode(n), "name"); const String *parent_name = Getattr(parentNode(n), "name");
String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int"); String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int");
const String *tm = typemapLookup("cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF); const String *tm = typemapLookup(n, "cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF);
String *return_type = Copy(tm); String *return_type = Copy(tm);
Delete(typemap_lookup_type); Delete(typemap_lookup_type);
typemap_lookup_type = NULL; typemap_lookup_type = NULL;
@ -1490,12 +1490,12 @@ public:
String *c_baseclass = NULL; String *c_baseclass = NULL;
String *baseclass = NULL; String *baseclass = NULL;
String *c_baseclassname = NULL; String *c_baseclassname = NULL;
String *typemap_lookup_type = Getattr(n, "classtypeobj"); SwigType *typemap_lookup_type = Getattr(n, "classtypeobj");
bool feature_director = Swig_directorclass(n) ? true : false; bool feature_director = Swig_directorclass(n) ? true : false;
// Inheritance from pure C# classes // Inheritance from pure C# classes
Node *attributes = NewHash(); Node *attributes = NewHash();
const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE, attributes); const String *pure_baseclass = typemapLookup(n, "csbase", typemap_lookup_type, WARN_NONE, attributes);
bool purebase_replace = GetFlag(attributes, "tmap:csbase:replace") ? true : false; bool purebase_replace = GetFlag(attributes, "tmap:csbase:replace") ? true : false;
bool purebase_notderived = GetFlag(attributes, "tmap:csbase:notderived") ? true : false; bool purebase_notderived = GetFlag(attributes, "tmap:csbase:notderived") ? true : false;
Delete(attributes); Delete(attributes);
@ -1549,21 +1549,21 @@ public:
} }
// Pure C# interfaces // Pure C# interfaces
const String *pure_interfaces = typemapLookup(derived ? "csinterfaces_derived" : "csinterfaces", typemap_lookup_type, WARN_NONE); const String *pure_interfaces = typemapLookup(n, derived ? "csinterfaces_derived" : "csinterfaces", typemap_lookup_type, WARN_NONE);
// Start writing the proxy class // Start writing the proxy class
Printv(proxy_class_def, typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements Printv(proxy_class_def, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements
"\n", NIL); "\n", NIL);
// Class attributes // Class attributes
const String *csattributes = typemapLookup("csattributes", typemap_lookup_type, WARN_NONE); const String *csattributes = typemapLookup(n, "csattributes", typemap_lookup_type, WARN_NONE);
if (csattributes && *Char(csattributes)) if (csattributes && *Char(csattributes))
Printf(proxy_class_def, "%s\n", csattributes); Printf(proxy_class_def, "%s\n", csattributes);
Printv(proxy_class_def, typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers Printv(proxy_class_def, typemapLookup(n, "csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" $csclassname", // Class name and base class " $csclassname", // Class name and base class
(*Char(wanted_base) || *Char(pure_interfaces)) ? " : " : "", wanted_base, (*Char(wanted_base) && *Char(pure_interfaces)) ? // Interfaces (*Char(wanted_base) || *Char(pure_interfaces)) ? " : " : "", wanted_base, (*Char(wanted_base) && *Char(pure_interfaces)) ? // Interfaces
", " : "", pure_interfaces, " {", derived ? typemapLookup("csbody_derived", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF) : // main body of class ", " : "", pure_interfaces, " {", derived ? typemapLookup(n, "csbody_derived", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF) : // main body of class
typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class typemapLookup(n, "csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
NIL); NIL);
// C++ destructor is wrapped by the Dispose method // C++ destructor is wrapped by the Dispose method
@ -1574,11 +1574,11 @@ public:
String *destruct_methodname = NULL; String *destruct_methodname = NULL;
String *destruct_methodmodifiers = NULL; String *destruct_methodmodifiers = NULL;
if (derived) { if (derived) {
tm = typemapLookup("csdestruct_derived", typemap_lookup_type, WARN_NONE, attributes); tm = typemapLookup(n, "csdestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:csdestruct_derived:methodname"); destruct_methodname = Getattr(attributes, "tmap:csdestruct_derived:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct_derived:methodmodifiers"); destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct_derived:methodmodifiers");
} else { } else {
tm = typemapLookup("csdestruct", typemap_lookup_type, WARN_NONE, attributes); tm = typemapLookup(n, "csdestruct", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:csdestruct:methodname"); destruct_methodname = Getattr(attributes, "tmap:csdestruct:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct:methodmodifiers"); destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct:methodmodifiers");
} }
@ -1595,7 +1595,7 @@ public:
if (tm) { if (tm) {
// Finalize method // Finalize method
if (*Char(destructor_call)) { if (*Char(destructor_call)) {
Printv(proxy_class_def, typemapLookup("csfinalize", typemap_lookup_type, WARN_NONE), NIL); Printv(proxy_class_def, typemapLookup(n, "csfinalize", typemap_lookup_type, WARN_NONE), NIL);
} }
// Dispose method // Dispose method
Printv(destruct, tm, NIL); Printv(destruct, tm, NIL);
@ -1690,7 +1690,7 @@ public:
Delete(destruct); Delete(destruct);
// Emit extra user code // Emit extra user code
Printv(proxy_class_def, typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code Printv(proxy_class_def, typemapLookup(n, "cscode", typemap_lookup_type, WARN_NONE), // extra C# code
"\n", NIL); "\n", NIL);
// Substitute various strings into the above template // Substitute various strings into the above template
@ -2355,7 +2355,7 @@ public:
/* Insert the csconstruct typemap, doing the replacement for $directorconnect, as needed */ /* Insert the csconstruct typemap, doing the replacement for $directorconnect, as needed */
Hash *attributes = NewHash(); Hash *attributes = NewHash();
String *construct_tm = Copy(typemapLookup("csconstruct", Getattr(n, "name"), String *construct_tm = Copy(typemapLookup(n, "csconstruct", Getattr(n, "name"),
WARN_CSHARP_TYPEMAP_CSCONSTRUCT_UNDEF, attributes)); WARN_CSHARP_TYPEMAP_CSCONSTRUCT_UNDEF, attributes));
if (construct_tm) { if (construct_tm) {
if (!feature_director) { if (!feature_director) {
@ -2972,6 +2972,10 @@ public:
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void emitTypeWrapperClass(String *classname, SwigType *type) { void emitTypeWrapperClass(String *classname, SwigType *type) {
Node *n = NewHash();
Setfile(n, input_file);
Setline(n, line_number);
String *swigtype = NewString(""); String *swigtype = NewString("");
String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), classname); String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), classname);
File *f_swigtype = NewFile(filen, "w", SWIG_output_files()); File *f_swigtype = NewFile(filen, "w", SWIG_output_files());
@ -2989,23 +2993,23 @@ public:
addOpenNamespace(namespce, f_swigtype); addOpenNamespace(namespce, f_swigtype);
// Pure C# baseclass and interfaces // Pure C# baseclass and interfaces
const String *pure_baseclass = typemapLookup("csbase", type, WARN_NONE); const String *pure_baseclass = typemapLookup(n, "csbase", type, WARN_NONE);
const String *pure_interfaces = typemapLookup("csinterfaces", type, WARN_NONE); const String *pure_interfaces = typemapLookup(n, "csinterfaces", type, WARN_NONE);
// Emit the class // Emit the class
Printv(swigtype, typemapLookup("csimports", type, WARN_NONE), // Import statements Printv(swigtype, typemapLookup(n, "csimports", type, WARN_NONE), // Import statements
"\n", NIL); "\n", NIL);
// Class attributes // Class attributes
const String *csattributes = typemapLookup("csattributes", type, WARN_NONE); const String *csattributes = typemapLookup(n, "csattributes", type, WARN_NONE);
if (csattributes && *Char(csattributes)) if (csattributes && *Char(csattributes))
Printf(swigtype, "%s\n", csattributes); Printf(swigtype, "%s\n", csattributes);
Printv(swigtype, typemapLookup("csclassmodifiers", type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers Printv(swigtype, typemapLookup(n, "csclassmodifiers", type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" $csclassname", // Class name and base class " $csclassname", // Class name and base class
(*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass, ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces (*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass, ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces
", " : "", pure_interfaces, " {", typemapLookup("csbody", type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class ", " : "", pure_interfaces, " {", typemapLookup(n, "csbody", type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
typemapLookup("cscode", type, WARN_NONE), // extra C# code typemapLookup(n, "cscode", type, WARN_NONE), // extra C# code
"}\n", NIL); "}\n", NIL);
Replaceall(swigtype, "$csclassname", classname); Replaceall(swigtype, "$csclassname", classname);
@ -3019,29 +3023,34 @@ public:
Close(f_swigtype); Close(f_swigtype);
Delete(swigtype); Delete(swigtype);
Delete(n);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* typemapLookup() * typemapLookup()
* n - for input only and must contain info for Getfile(n) and Getline(n) to work
* op - typemap method name
* type - typemap type to lookup
* warning - warning number to issue if no typemaps found
* typemap_attributes - the typemap attributes are attached to this node and will
* also be used for temporary storage if non null
* return is never NULL, unlike Swig_typemap_lookup()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes = NULL) { const String *typemapLookup(Node *n, const_String_or_char_ptr op, SwigType *type, int warning, Node *typemap_attributes = 0) {
String *tm = NULL; Node *node = !typemap_attributes ? NewHash() : typemap_attributes;
const String *code = NULL; Setattr(node, "type", type);
Setfile(node, Getfile(n));
if ((tm = Swig_typemap_search(op, type, NULL, NULL))) { Setline(node, Getline(n));
code = Getattr(tm, "code"); const String *tm = Swig_typemap_lookup(op, node, "", 0);
if (typemap_attributes) if (!tm) {
Swig_typemap_attach_kwargs(tm, op, typemap_attributes); tm = empty_string;
}
if (!code) {
code = empty_string;
if (warning != WARN_NONE) if (warning != WARN_NONE)
Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type); Swig_warning(warning, Getfile(n), Getline(n), "No %s typemap defined for %s\n", op, SwigType_str(type, 0));
} }
if (!typemap_attributes)
return code ? code : empty_string; Delete(node);
return tm;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -3820,7 +3829,7 @@ public:
Node *disconn_attr = NewHash(); Node *disconn_attr = NewHash();
String *disconn_methodname = NULL; String *disconn_methodname = NULL;
disconn_tm = typemapLookup("directordisconnect", full_classname, WARN_NONE, disconn_attr); disconn_tm = typemapLookup(n, "directordisconnect", full_classname, WARN_NONE, disconn_attr);
disconn_methodname = Getattr(disconn_attr, "tmap:directordisconnect:methodname"); disconn_methodname = Getattr(disconn_attr, "tmap:directordisconnect:methodname");
Printv(w->code, "}\n", NIL); Printv(w->code, "}\n", NIL);

View file

@ -1171,11 +1171,11 @@ public:
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum
// Pure Java baseclass and interfaces // Pure Java baseclass and interfaces
const String *pure_baseclass = typemapLookup("javabase", typemap_lookup_type, WARN_NONE); const String *pure_baseclass = typemapLookup(n, "javabase", typemap_lookup_type, WARN_NONE);
const String *pure_interfaces = typemapLookup("javainterfaces", typemap_lookup_type, WARN_NONE); const String *pure_interfaces = typemapLookup(n, "javainterfaces", typemap_lookup_type, WARN_NONE);
// Emit the enum // Emit the enum
Printv(enum_code, typemapLookup("javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really) Printv(enum_code, typemapLookup(n, "javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really)
" ", symname, *Char(pure_baseclass) ? // Bases " ", symname, *Char(pure_baseclass) ? // Bases
" extends " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces " extends " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces
" implements " : "", pure_interfaces, " {\n", NIL); " implements " : "", pure_interfaces, " {\n", NIL);
@ -1196,8 +1196,8 @@ public:
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum
// Finish the enum declaration // Finish the enum declaration
// Typemaps are used to generate the enum definition in a similar manner to proxy classes. // Typemaps are used to generate the enum definition in a similar manner to proxy classes.
Printv(enum_code, (enum_feature == ProperEnum) ? ";\n" : "", typemapLookup("javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class Printv(enum_code, (enum_feature == ProperEnum) ? ";\n" : "", typemapLookup(n, "javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class
typemapLookup("javacode", typemap_lookup_type, WARN_NONE), // extra Java code typemapLookup(n, "javacode", typemap_lookup_type, WARN_NONE), // extra Java code
"}", NIL); "}", NIL);
Replaceall(enum_code, "$javaclassname", symname); Replaceall(enum_code, "$javaclassname", symname);
@ -1234,7 +1234,7 @@ public:
if (Len(package) > 0) if (Len(package) > 0)
Printf(f_enum, "package %s;\n", package); Printf(f_enum, "package %s;\n", package);
Printv(f_enum, typemapLookup("javaimports", typemap_lookup_type, WARN_NONE), // Import statements Printv(f_enum, typemapLookup(n, "javaimports", typemap_lookup_type, WARN_NONE), // Import statements
"\n", enum_code, "\n", NIL); "\n", enum_code, "\n", NIL);
Printf(f_enum, "\n"); Printf(f_enum, "\n");
@ -1295,7 +1295,7 @@ public:
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern // Wrap C/C++ enums with constant integers or use the typesafe enum pattern
const String *parent_name = Getattr(parentNode(n), "name"); const String *parent_name = Getattr(parentNode(n), "name");
String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int"); String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int");
const String *tm = typemapLookup("jstype", typemap_lookup_type, WARN_JAVA_TYPEMAP_JSTYPE_UNDEF); const String *tm = typemapLookup(n, "jstype", typemap_lookup_type, WARN_JAVA_TYPEMAP_JSTYPE_UNDEF);
String *return_type = Copy(tm); String *return_type = Copy(tm);
Delete(typemap_lookup_type); Delete(typemap_lookup_type);
typemap_lookup_type = NULL; typemap_lookup_type = NULL;
@ -1560,12 +1560,12 @@ public:
String *c_baseclass = NULL; String *c_baseclass = NULL;
String *baseclass = NULL; String *baseclass = NULL;
String *c_baseclassname = NULL; String *c_baseclassname = NULL;
String *typemap_lookup_type = Getattr(n, "classtypeobj"); SwigType *typemap_lookup_type = Getattr(n, "classtypeobj");
bool feature_director = Swig_directorclass(n) ? true : false; bool feature_director = Swig_directorclass(n) ? true : false;
// Inheritance from pure Java classes // Inheritance from pure Java classes
Node *attributes = NewHash(); Node *attributes = NewHash();
const String *pure_baseclass = typemapLookup("javabase", typemap_lookup_type, WARN_NONE, attributes); const String *pure_baseclass = typemapLookup(n, "javabase", typemap_lookup_type, WARN_NONE, attributes);
bool purebase_replace = GetFlag(attributes, "tmap:javabase:replace") ? true : false; bool purebase_replace = GetFlag(attributes, "tmap:javabase:replace") ? true : false;
bool purebase_notderived = GetFlag(attributes, "tmap:javabase:notderived") ? true : false; bool purebase_notderived = GetFlag(attributes, "tmap:javabase:notderived") ? true : false;
Delete(attributes); Delete(attributes);
@ -1619,15 +1619,15 @@ public:
} }
// Pure Java interfaces // Pure Java interfaces
const String *pure_interfaces = typemapLookup("javainterfaces", typemap_lookup_type, WARN_NONE); const String *pure_interfaces = typemapLookup(n, "javainterfaces", typemap_lookup_type, WARN_NONE);
// Start writing the proxy class // Start writing the proxy class
Printv(proxy_class_def, typemapLookup("javaimports", typemap_lookup_type, WARN_NONE), // Import statements Printv(proxy_class_def, typemapLookup(n, "javaimports", typemap_lookup_type, WARN_NONE), // Import statements
"\n", typemapLookup("javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers "\n", typemapLookup(n, "javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" $javaclassname", // Class name and bases " $javaclassname", // Class name and bases
(*Char(wanted_base)) ? " extends " : "", wanted_base, *Char(pure_interfaces) ? // Pure Java interfaces (*Char(wanted_base)) ? " extends " : "", wanted_base, *Char(pure_interfaces) ? // Pure Java interfaces
" implements " : "", pure_interfaces, " {", derived ? typemapLookup("javabody_derived", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF) : // main body of class " implements " : "", pure_interfaces, " {", derived ? typemapLookup(n, "javabody_derived", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF) : // main body of class
typemapLookup("javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class typemapLookup(n, "javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class
NIL); NIL);
// C++ destructor is wrapped by the delete method // C++ destructor is wrapped by the delete method
@ -1638,11 +1638,11 @@ public:
String *destruct_methodname = NULL; String *destruct_methodname = NULL;
String *destruct_methodmodifiers = NULL; String *destruct_methodmodifiers = NULL;
if (derived) { if (derived) {
tm = typemapLookup("javadestruct_derived", typemap_lookup_type, WARN_NONE, attributes); tm = typemapLookup(n, "javadestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:javadestruct_derived:methodname"); destruct_methodname = Getattr(attributes, "tmap:javadestruct_derived:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:javadestruct_derived:methodmodifiers"); destruct_methodmodifiers = Getattr(attributes, "tmap:javadestruct_derived:methodmodifiers");
} else { } else {
tm = typemapLookup("javadestruct", typemap_lookup_type, WARN_NONE, attributes); tm = typemapLookup(n, "javadestruct", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:javadestruct:methodname"); destruct_methodname = Getattr(attributes, "tmap:javadestruct:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:javadestruct:methodmodifiers"); destruct_methodmodifiers = Getattr(attributes, "tmap:javadestruct:methodmodifiers");
} }
@ -1660,7 +1660,7 @@ public:
if (tm) { if (tm) {
// Finalize method // Finalize method
if (*Char(destructor_call)) { if (*Char(destructor_call)) {
Printv(proxy_class_def, typemapLookup("javafinalize", typemap_lookup_type, WARN_NONE), NIL); Printv(proxy_class_def, typemapLookup(n, "javafinalize", typemap_lookup_type, WARN_NONE), NIL);
} }
// delete method // delete method
Printv(destruct, tm, NIL); Printv(destruct, tm, NIL);
@ -1681,9 +1681,9 @@ public:
release_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, false)", imclass_name, proxy_class_name); release_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, false)", imclass_name, proxy_class_name);
take_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, true)", imclass_name, proxy_class_name); take_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, true)", imclass_name, proxy_class_name);
emitCodeTypemap(false, typemap_lookup_type, "directordisconnect", "methodname", destruct_jnicall); emitCodeTypemap(n, false, typemap_lookup_type, "directordisconnect", "methodname", destruct_jnicall);
emitCodeTypemap(false, typemap_lookup_type, "directorowner_release", "methodname", release_jnicall); emitCodeTypemap(n, false, typemap_lookup_type, "directorowner_release", "methodname", release_jnicall);
emitCodeTypemap(false, typemap_lookup_type, "directorowner_take", "methodname", take_jnicall); emitCodeTypemap(n, false, typemap_lookup_type, "directorowner_take", "methodname", take_jnicall);
Delete(destruct_jnicall); Delete(destruct_jnicall);
Delete(release_jnicall); Delete(release_jnicall);
@ -1694,7 +1694,7 @@ public:
Delete(destruct); Delete(destruct);
// Emit extra user code // Emit extra user code
Printv(proxy_class_def, typemapLookup("javacode", typemap_lookup_type, WARN_NONE), // extra Java code Printv(proxy_class_def, typemapLookup(n, "javacode", typemap_lookup_type, WARN_NONE), // extra Java code
"\n", NIL); "\n", NIL);
// Substitute various strings into the above template // Substitute various strings into the above template
@ -2285,7 +2285,7 @@ public:
/* Insert the javaconstruct typemap, doing the replacement for $directorconnect, as needed */ /* Insert the javaconstruct typemap, doing the replacement for $directorconnect, as needed */
Hash *attributes = NewHash(); Hash *attributes = NewHash();
String *construct_tm = Copy(typemapLookup("javaconstruct", Getattr(n, "name"), String *construct_tm = Copy(typemapLookup(n, "javaconstruct", Getattr(n, "name"),
WARN_JAVA_TYPEMAP_JAVACONSTRUCT_UNDEF, attributes)); WARN_JAVA_TYPEMAP_JAVACONSTRUCT_UNDEF, attributes));
if (construct_tm) { if (construct_tm) {
if (!feature_director) { if (!feature_director) {
@ -2815,6 +2815,10 @@ public:
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void emitTypeWrapperClass(String *classname, SwigType *type) { void emitTypeWrapperClass(String *classname, SwigType *type) {
Node *n = NewHash();
Setfile(n, input_file);
Setline(n, line_number);
String *swigtype = NewString(""); String *swigtype = NewString("");
String *filen = NewStringf("%s%s.java", SWIG_output_directory(), classname); String *filen = NewStringf("%s%s.java", SWIG_output_directory(), classname);
File *f_swigtype = NewFile(filen, "w", SWIG_output_files()); File *f_swigtype = NewFile(filen, "w", SWIG_output_files());
@ -2833,16 +2837,16 @@ public:
Printf(f_swigtype, "package %s;\n", package); Printf(f_swigtype, "package %s;\n", package);
// Pure Java baseclass and interfaces // Pure Java baseclass and interfaces
const String *pure_baseclass = typemapLookup("javabase", type, WARN_NONE); const String *pure_baseclass = typemapLookup(n, "javabase", type, WARN_NONE);
const String *pure_interfaces = typemapLookup("javainterfaces", type, WARN_NONE); const String *pure_interfaces = typemapLookup(n, "javainterfaces", type, WARN_NONE);
// Emit the class // Emit the class
Printv(swigtype, typemapLookup("javaimports", type, WARN_NONE), // Import statements Printv(swigtype, typemapLookup(n, "javaimports", type, WARN_NONE), // Import statements
"\n", typemapLookup("javaclassmodifiers", type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers "\n", typemapLookup(n, "javaclassmodifiers", type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" $javaclassname", // Class name and bases " $javaclassname", // Class name and bases
*Char(pure_baseclass) ? " extends " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces *Char(pure_baseclass) ? " extends " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces
" implements " : "", pure_interfaces, " {", typemapLookup("javabody", type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class " implements " : "", pure_interfaces, " {", typemapLookup(n, "javabody", type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class
typemapLookup("javacode", type, WARN_NONE), // extra Java code typemapLookup(n, "javacode", type, WARN_NONE), // extra Java code
"}\n", "\n", NIL); "}\n", "\n", NIL);
Replaceall(swigtype, "$javaclassname", classname); Replaceall(swigtype, "$javaclassname", classname);
@ -2852,29 +2856,34 @@ public:
Close(f_swigtype); Close(f_swigtype);
Delete(swigtype); Delete(swigtype);
Delete(n);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* typemapLookup() * typemapLookup()
* n - for input only and must contain info for Getfile(n) and Getline(n) to work
* op - typemap method name
* type - typemap type to lookup
* warning - warning number to issue if no typemaps found
* typemap_attributes - the typemap attributes are attached to this node and will
* also be used for temporary storage if non null
* return is never NULL, unlike Swig_typemap_lookup()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes = NULL) { const String *typemapLookup(Node *n, const_String_or_char_ptr op, SwigType *type, int warning, Node *typemap_attributes = 0) {
String *tm = NULL; Node *node = !typemap_attributes ? NewHash() : typemap_attributes;
const String *code = NULL; Setattr(node, "type", type);
Setfile(node, Getfile(n));
if ((tm = Swig_typemap_search(op, type, NULL, NULL))) { Setline(node, Getline(n));
code = Getattr(tm, "code"); const String *tm = Swig_typemap_lookup(op, node, "", 0);
if (typemap_attributes) if (!tm) {
Swig_typemap_attach_kwargs(tm, op, typemap_attributes); tm = empty_string;
}
if (!code) {
code = empty_string;
if (warning != WARN_NONE) if (warning != WARN_NONE)
Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type); Swig_warning(warning, Getfile(n), Getline(n), "No %s typemap defined for %s\n", op, SwigType_str(type, 0));
} }
if (!typemap_attributes)
return code ? code : empty_string; Delete(node);
return tm;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -3183,8 +3192,7 @@ public:
* typemaps. * typemaps.
*--------------------------------------------------------------------*/ *--------------------------------------------------------------------*/
void void emitCodeTypemap(Node *n, bool derived, SwigType *lookup_type, const String *typemap, const String *methodname, const String *jnicall) {
emitCodeTypemap(bool derived, String *lookup_type, const String *typemap, const String *methodname, const String *jnicall) {
const String *tm = NULL; const String *tm = NULL;
Node *tmattrs = NewHash(); Node *tmattrs = NewHash();
String *lookup_tmname = NewString(typemap); String *lookup_tmname = NewString(typemap);
@ -3195,7 +3203,7 @@ public:
Append(lookup_tmname, "_derived"); Append(lookup_tmname, "_derived");
} }
tm = typemapLookup(lookup_tmname, lookup_type, WARN_NONE, tmattrs); tm = typemapLookup(n, lookup_tmname, lookup_type, WARN_NONE, tmattrs);
method_attr_name = NewStringf("tmap:%s:%s", lookup_tmname, methodname); method_attr_name = NewStringf("tmap:%s:%s", lookup_tmname, methodname);
method_attr = Getattr(tmattrs, method_attr_name); method_attr = Getattr(tmattrs, method_attr_name);
@ -3979,7 +3987,7 @@ public:
Node *disconn_attr = NewHash(); Node *disconn_attr = NewHash();
String *disconn_methodname = NULL; String *disconn_methodname = NULL;
disconn_tm = typemapLookup("directordisconnect", full_classname, WARN_NONE, disconn_attr); disconn_tm = typemapLookup(n, "directordisconnect", full_classname, WARN_NONE, disconn_attr);
disconn_methodname = Getattr(disconn_attr, "tmap:directordisconnect:methodname"); disconn_methodname = Getattr(disconn_attr, "tmap:directordisconnect:methodname");
Printv(w->code, " swig_disconnect_director_self(\"", disconn_methodname, "\");\n", "}\n", NIL); Printv(w->code, " swig_disconnect_director_self(\"", disconn_methodname, "\");\n", "}\n", NIL);

View file

@ -2230,23 +2230,23 @@ MODULA3():
baseclass = NewString(""); baseclass = NewString("");
// Inheritance from pure Modula 3 classes // Inheritance from pure Modula 3 classes
const String *pure_baseclass = typemapLookup("m3base", classDeclarationName, WARN_NONE); const String *pure_baseclass = typemapLookup(n, "m3base", classDeclarationName, WARN_NONE);
if (hasContent(pure_baseclass) && hasContent(baseclass)) { if (hasContent(pure_baseclass) && hasContent(baseclass)) {
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, input_file,
line_number, line_number,
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", classDeclarationName, pure_baseclass); "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", classDeclarationName, pure_baseclass);
} }
// Pure Modula 3 interfaces // Pure Modula 3 interfaces
const String *pure_interfaces = typemapLookup(derived ? "m3interfaces_derived" : "m3interfaces", const String *pure_interfaces = typemapLookup(n, derived ? "m3interfaces_derived" : "m3interfaces",
classDeclarationName, WARN_NONE); classDeclarationName, WARN_NONE);
// Start writing the proxy class // Start writing the proxy class
Printv(proxy_class_def, typemapLookup("m3imports", classDeclarationName, WARN_NONE), // Import statements Printv(proxy_class_def, typemapLookup(n, "m3imports", classDeclarationName, WARN_NONE), // Import statements
"\n", typemapLookup("m3classmodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers "\n", typemapLookup(n, "m3classmodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" class $m3classname", // Class name and bases " class $m3classname", // Class name and bases
(derived || *Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", baseclass, pure_baseclass, ((derived || *Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces (derived || *Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", baseclass, pure_baseclass, ((derived || *Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces
", " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", // Member variables for memory handling ", " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", // Member variables for memory handling
derived ? "" : " protected bool swigCMemOwn;\n", "\n", " ", typemapLookup("m3ptrconstructormodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers derived ? "" : " protected bool swigCMemOwn;\n", "\n", " ", typemapLookup(n, "m3ptrconstructormodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers
" $m3classname(IntPtr cPtr, bool cMemoryOwn) ", // Constructor used for wrapping pointers " $m3classname(IntPtr cPtr, bool cMemoryOwn) ", // Constructor used for wrapping pointers
derived ? derived ?
": base($imclassname.$m3classnameTo$baseclass(cPtr), cMemoryOwn) {\n" ": base($imclassname.$m3classnameTo$baseclass(cPtr), cMemoryOwn) {\n"
@ -2262,10 +2262,10 @@ MODULA3():
Node *attributes = NewHash(); Node *attributes = NewHash();
String *destruct_methodname = NULL; String *destruct_methodname = NULL;
if (derived) { if (derived) {
tm = typemapLookup("m3destruct_derived", classDeclarationName, WARN_NONE, attributes); tm = typemapLookup(n, "m3destruct_derived", classDeclarationName, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:m3destruct_derived:methodname"); destruct_methodname = Getattr(attributes, "tmap:m3destruct_derived:methodname");
} else { } else {
tm = typemapLookup("m3destruct", classDeclarationName, WARN_NONE, attributes); tm = typemapLookup(n, "m3destruct", classDeclarationName, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:m3destruct:methodname"); destruct_methodname = Getattr(attributes, "tmap:m3destruct:methodname");
} }
if (!destruct_methodname) { if (!destruct_methodname) {
@ -2275,7 +2275,7 @@ MODULA3():
if (tm) { if (tm) {
// Finalize method // Finalize method
if (*Char(destructor_call)) { if (*Char(destructor_call)) {
Printv(proxy_class_def, typemapLookup("m3finalize", classDeclarationName, WARN_NONE), NIL); Printv(proxy_class_def, typemapLookup(n, "m3finalize", classDeclarationName, WARN_NONE), NIL);
} }
// Dispose method // Dispose method
Printv(destruct, tm, NIL); Printv(destruct, tm, NIL);
@ -2290,8 +2290,8 @@ MODULA3():
Delete(destruct); Delete(destruct);
// Emit various other methods // Emit various other methods
Printv(proxy_class_def, typemapLookup("m3getcptr", classDeclarationName, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method Printv(proxy_class_def, typemapLookup(n, "m3getcptr", classDeclarationName, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method
typemapLookup("m3code", classDeclarationName, WARN_NONE), // extra Modula 3 code typemapLookup(n, "m3code", classDeclarationName, WARN_NONE), // extra Modula 3 code
"\n", NIL); "\n", NIL);
// Substitute various strings into the above template // Substitute various strings into the above template
@ -3765,6 +3765,10 @@ MODULA3():
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void emitTypeWrapperClass(String *classname, SwigType *type) { void emitTypeWrapperClass(String *classname, SwigType *type) {
Node *n = NewHash();
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_file_dirname(outfile), classname);
File *f_swigtype = NewFile(filen, "w", SWIG_output_files()); File *f_swigtype = NewFile(filen, "w", SWIG_output_files());
if (!f_swigtype) { if (!f_swigtype) {
@ -3777,19 +3781,19 @@ MODULA3():
emitBanner(f_swigtype); emitBanner(f_swigtype);
// Pure Modula 3 baseclass and interfaces // Pure Modula 3 baseclass and interfaces
const String *pure_baseclass = typemapLookup("m3base", type, WARN_NONE); const String *pure_baseclass = typemapLookup(n, "m3base", type, WARN_NONE);
const String *pure_interfaces = typemapLookup("m3interfaces", type, WARN_NONE); const String *pure_interfaces = typemapLookup(n, "m3interfaces", type, WARN_NONE);
// Emit the class // Emit the class
Printv(swigtype, typemapLookup("m3imports", type, WARN_NONE), // Import statements Printv(swigtype, typemapLookup(n, "m3imports", type, WARN_NONE), // Import statements
"\n", typemapLookup("m3classmodifiers", type, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers "\n", typemapLookup(n, "m3classmodifiers", type, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
" class $m3classname", // Class name and bases " class $m3classname", // Class name and bases
*Char(pure_baseclass) ? " : " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces *Char(pure_baseclass) ? " : " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces
" : " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", "\n", " ", typemapLookup("m3ptrconstructormodifiers", type, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers " : " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", "\n", " ", typemapLookup(n, "m3ptrconstructormodifiers", type, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers
" $m3classname(IntPtr cPtr, bool bFutureUse) {\n", // Constructor used for wrapping pointers " $m3classname(IntPtr cPtr, bool bFutureUse) {\n", // Constructor used for wrapping pointers
" swigCPtr = cPtr;\n", " }\n", "\n", " protected $m3classname() {\n", // Default constructor " swigCPtr = cPtr;\n", " }\n", "\n", " protected $m3classname() {\n", // Default constructor
" swigCPtr = IntPtr.Zero;\n", " }\n", typemapLookup("m3getcptr", type, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method " swigCPtr = IntPtr.Zero;\n", " }\n", typemapLookup(n, "m3getcptr", type, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method
typemapLookup("m3code", type, WARN_NONE), // extra Modula 3 code typemapLookup(n, "m3code", type, WARN_NONE), // extra Modula 3 code
"}\n", "\n", NIL); "}\n", "\n", NIL);
Replaceall(swigtype, "$m3classname", classname); Replaceall(swigtype, "$m3classname", classname);
@ -3802,25 +3806,29 @@ MODULA3():
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* typemapLookup() * typemapLookup()
* n - for input only and must contain info for Getfile(n) and Getline(n) to work
* op - typemap method name
* type - typemap type to lookup
* warning - warning number to issue if no typemaps found
* typemap_attributes - the typemap attributes are attached to this node and will
* also be used for temporary storage if non null
* return is never NULL, unlike Swig_typemap_lookup()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes = NULL) { const String *typemapLookup(Node *n, const_String_or_char_ptr op, SwigType *type, int warning, Node *typemap_attributes = 0) {
String *tm = NULL; Node *node = !typemap_attributes ? NewHash() : typemap_attributes;
const String *code = NULL; Setattr(node, "type", type);
Setfile(node, Getfile(n));
if ((tm = Swig_typemap_search(op, type, NULL, NULL))) { Setline(node, Getline(n));
code = Getattr(tm, "code"); const String *tm = Swig_typemap_lookup(op, node, "", 0);
if (typemap_attributes) if (!tm) {
Swig_typemap_attach_kwargs(tm, op, typemap_attributes); tm = empty_string;
}
if (!code) {
code = empty_string;
if (warning != WARN_NONE) if (warning != WARN_NONE)
Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type); Swig_warning(warning, Getfile(n), Getline(n), "No %s typemap defined for %s\n", op, SwigType_str(type, 0));
} }
if (!typemap_attributes)
return code ? code : empty_string; Delete(node);
return tm;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------

View file

@ -131,11 +131,17 @@ static void add_defined_foreign_type(String *type) {
} }
static String *get_ffi_type(SwigType *ty, const_String_or_char_ptr name) { static String *get_ffi_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0); Node *node = NewHash();
if (typemap) { Setattr(node, "type", ty);
String *typespec = Getattr(typemap, "code"); Setattr(node, "name", name);
return NewString(typespec); Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("ffitype", node, "", 0);
Delete(node);
if (tm) {
return NewString(tm);
} else { } else {
SwigType *tr = SwigType_typedef_resolve_all(ty); SwigType *tr = SwigType_typedef_resolve_all(ty);
char *type_reduced = Char(tr); char *type_reduced = Char(tr);
@ -167,14 +173,16 @@ static String *get_ffi_type(SwigType *ty, const_String_or_char_ptr name) {
return 0; return 0;
} }
static String *get_lisp_type(SwigType *ty, const_String_or_char_ptr name) { static String *get_lisp_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
Hash *typemap = Swig_typemap_search("lisptype", ty, name, 0); Node *node = NewHash();
if (typemap) { Setattr(node, "type", ty);
String *typespec = Getattr(typemap, "code"); Setattr(node, "name", name);
return NewString(typespec); Setfile(node, Getfile(n));
} else { Setline(node, Getline(n));
return NewString(""); const String *tm = Swig_typemap_lookup("lisptype", node, "", 0);
} Delete(node);
return tm ? NewString(tm) : NewString("");
} }
void UFFI::main(int argc, char *argv[]) { void UFFI::main(int argc, char *argv[]) {
@ -280,8 +288,8 @@ int UFFI::functionWrapper(Node *n) {
for (p = pl; p; p = nextSibling(p), argnum++) { for (p = pl; p; p = nextSibling(p), argnum++) {
String *argname = Getattr(p, "name"); String *argname = Getattr(p, "name");
SwigType *argtype = Getattr(p, "type"); SwigType *argtype = Getattr(p, "type");
String *ffitype = get_ffi_type(argtype, argname); String *ffitype = get_ffi_type(n, argtype, argname);
String *lisptype = get_lisp_type(argtype, argname); String *lisptype = get_lisp_type(n, argtype, argname);
int tempargname = 0; int tempargname = 0;
if (!argname) { if (!argname) {
@ -307,7 +315,7 @@ int UFFI::functionWrapper(Node *n) {
//" :strings-convert t\n" //" :strings-convert t\n"
//" :call-direct %s\n" //" :call-direct %s\n"
//" :optimize-for-space t" //" :optimize-for-space t"
")\n", get_ffi_type(Getattr(n, "type"), "result") ")\n", get_ffi_type(n, Getattr(n, "type"), "result")
//,varargs ? "nil" : "t" //,varargs ? "nil" : "t"
); );
@ -361,7 +369,7 @@ int UFFI::classHandler(Node *n) {
/* Printf(stdout, "Converting %s in %s\n", type, name); */ /* Printf(stdout, "Converting %s in %s\n", type, name); */
lisp_type = get_ffi_type(type, Getattr(c, "sym:name")); lisp_type = get_ffi_type(n, type, Getattr(c, "sym:name"));
Printf(f_cl, " (#.(%s \"%s\" :type :slot) %s)\n", identifier_converter, Getattr(c, "sym:name"), lisp_type); Printf(f_cl, " (#.(%s \"%s\" :type :slot) %s)\n", identifier_converter, Getattr(c, "sym:name"), lisp_type);

View file

@ -370,11 +370,8 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern void Swig_typemap_clear_apply(ParmList *pattern); extern void Swig_typemap_clear_apply(ParmList *pattern);
extern void Swig_typemap_debug(void); extern void Swig_typemap_debug(void);
extern Hash *Swig_typemap_search(const_String_or_char_ptr op, SwigType *type, const_String_or_char_ptr pname, SwigType **matchtype);
extern Hash *Swig_typemap_search_multi(const_String_or_char_ptr op, ParmList *parms, int *nmatch);
extern String *Swig_typemap_lookup(const_String_or_char_ptr op, Node *n, const_String_or_char_ptr lname, Wrapper *f); extern String *Swig_typemap_lookup(const_String_or_char_ptr op, Node *n, const_String_or_char_ptr lname, Wrapper *f);
extern String *Swig_typemap_lookup_out(const_String_or_char_ptr op, Node *n, const_String_or_char_ptr lname, Wrapper *f, String *actioncode); extern String *Swig_typemap_lookup_out(const_String_or_char_ptr op, Node *n, const_String_or_char_ptr lname, Wrapper *f, String *actioncode);
extern void Swig_typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr op, Parm *p);
extern void Swig_typemap_new_scope(void); extern void Swig_typemap_new_scope(void);
extern Hash *Swig_typemap_pop_scope(void); extern Hash *Swig_typemap_pop_scope(void);

View file

@ -114,7 +114,7 @@ static String *tmop_name(const_String_or_char_ptr op) {
we have to make sure that we only intern strings without object we have to make sure that we only intern strings without object
identity into the hash table. identity into the hash table.
(Swig_typemap_attach_kwargs calls tmop_name several times with (typemap_attach_kwargs calls tmop_name several times with
the "same" String *op (i.e., same object identity) but differing the "same" String *op (i.e., same object identity) but differing
string values.) string values.)
@ -134,6 +134,7 @@ static String *tmop_name(const_String_or_char_ptr op) {
return s; return s;
} }
#if 0
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_typemap_new_scope() * Swig_typemap_new_scope()
* *
@ -157,6 +158,7 @@ Hash *Swig_typemap_pop_scope() {
} }
return 0; return 0;
} }
#endif
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_typemap_register() * Swig_typemap_register()
@ -265,12 +267,12 @@ void Swig_typemap_register(const_String_or_char_ptr op, ParmList *parms, const_S
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_typemap_get() * typemap_get()
* *
* Retrieve typemap information from current scope. * Retrieve typemap information from current scope.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static Hash *Swig_typemap_get(SwigType *type, const_String_or_char_ptr name, int scope) { static Hash *typemap_get(SwigType *type, const_String_or_char_ptr name, int scope) {
Hash *tm, *tm1; Hash *tm, *tm1;
/* See if this type has been seen before */ /* See if this type has been seen before */
if ((scope < 0) || (scope > tm_scope)) if ((scope < 0) || (scope > tm_scope))
@ -312,7 +314,7 @@ int Swig_typemap_copy(const_String_or_char_ptr op, ParmList *srcparms, ParmList
pname = Getattr(p, "name"); pname = Getattr(p, "name");
/* Lookup the type */ /* Lookup the type */
tm = Swig_typemap_get(ptype, pname, ts); tm = typemap_get(ptype, pname, ts);
if (!tm) if (!tm)
break; break;
@ -360,7 +362,7 @@ void Swig_typemap_clear(const_String_or_char_ptr op, ParmList *parms) {
while (p) { while (p) {
type = Getattr(p, "type"); type = Getattr(p, "type");
name = Getattr(p, "name"); name = Getattr(p, "name");
tm = Swig_typemap_get(type, name, tm_scope); tm = typemap_get(type, name, tm_scope);
if (!tm) if (!tm)
return; return;
p = nextSibling(p); p = nextSibling(p);
@ -385,8 +387,7 @@ void Swig_typemap_clear(const_String_or_char_ptr op, ParmList *parms) {
* it works. * it works.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static static int count_args(String *s) {
int count_args(String *s) {
/* Count up number of arguments */ /* Count up number of arguments */
int na = 0; int na = 0;
char *c = Char(s); char *c = Char(s);
@ -456,7 +457,7 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
while (ts >= 0) { while (ts >= 0) {
/* See if there is a matching typemap in this scope */ /* See if there is a matching typemap in this scope */
sm = Swig_typemap_get(type, name, ts); sm = typemap_get(type, name, ts);
/* if there is not matching, look for a typemap in the /* if there is not matching, look for a typemap in the
original typedef, if any, like in: original typedef, if any, like in:
@ -468,7 +469,7 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
if (!sm) { if (!sm) {
SwigType *ntype = SwigType_typedef_resolve(type); SwigType *ntype = SwigType_typedef_resolve(type);
if (ntype && (Cmp(ntype, type) != 0)) { if (ntype && (Cmp(ntype, type) != 0)) {
sm = Swig_typemap_get(ntype, name, ts); sm = typemap_get(ntype, name, ts);
} }
Delete(ntype); Delete(ntype);
} }
@ -584,13 +585,13 @@ static SwigType *strip_arrays(SwigType *type) {
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_typemap_search() * typemap_search()
* *
* Search for a typemap match. Tries to find the most specific typemap * Search for a typemap match. Tries to find the most specific typemap
* that includes a 'code' attribute. * that includes a 'code' attribute.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
Hash *Swig_typemap_search(const_String_or_char_ptr op, SwigType *type, const_String_or_char_ptr name, SwigType **matchtype) { static Hash *typemap_search(const_String_or_char_ptr op, SwigType *type, const_String_or_char_ptr name, SwigType **matchtype) {
Hash *result = 0, *tm, *tm1, *tma; Hash *result = 0, *tm, *tm1, *tma;
Hash *backup = 0; Hash *backup = 0;
SwigType *noarrays = 0; SwigType *noarrays = 0;
@ -732,12 +733,12 @@ ret_result:
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_typemap_search_multi() * typemap_search_multi()
* *
* Search for a multi-valued typemap. * Search for a multi-valued typemap.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
Hash *Swig_typemap_search_multi(const_String_or_char_ptr op, ParmList *parms, int *nmatch) { static Hash *typemap_search_multi(const_String_or_char_ptr op, ParmList *parms, int *nmatch) {
SwigType *type; SwigType *type;
SwigType *mtype = 0; SwigType *mtype = 0;
String *name; String *name;
@ -752,14 +753,14 @@ Hash *Swig_typemap_search_multi(const_String_or_char_ptr op, ParmList *parms, in
name = Getattr(parms, "name"); name = Getattr(parms, "name");
/* Try to find a match on the first type */ /* Try to find a match on the first type */
tm = Swig_typemap_search(op, type, name, &mtype); tm = typemap_search(op, type, name, &mtype);
if (tm) { if (tm) {
if (mtype && SwigType_isarray(mtype)) { if (mtype && SwigType_isarray(mtype)) {
Setattr(parms, "tmap:match", mtype); Setattr(parms, "tmap:match", mtype);
} }
Delete(mtype); Delete(mtype);
newop = NewStringf("%s-%s+%s:", op, type, name); newop = NewStringf("%s-%s+%s:", op, type, name);
tm1 = Swig_typemap_search_multi(newop, nextSibling(parms), nmatch); tm1 = typemap_search_multi(newop, nextSibling(parms), nmatch);
if (tm1) if (tm1)
tm = tm1; tm = tm1;
if (Getattr(tm, "code")) { if (Getattr(tm, "code")) {
@ -780,8 +781,7 @@ Hash *Swig_typemap_search_multi(const_String_or_char_ptr op, ParmList *parms, in
* type and pname are the type and parameter name. * type and pname are the type and parameter name.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static static void replace_local_types(ParmList *p, const String *name, const String *rep) {
void replace_local_types(ParmList *p, const String *name, const String *rep) {
SwigType *t; SwigType *t;
while (p) { while (p) {
t = Getattr(p, "type"); t = Getattr(p, "type");
@ -790,8 +790,7 @@ void replace_local_types(ParmList *p, const String *name, const String *rep) {
} }
} }
static static int check_locals(ParmList *p, const char *s) {
int check_locals(ParmList *p, const char *s) {
while (p) { while (p) {
char *c = GetChar(p, "type"); char *c = GetChar(p, "type");
if (strstr(c, s)) if (strstr(c, s))
@ -801,8 +800,7 @@ int check_locals(ParmList *p, const char *s) {
return 0; return 0;
} }
static static int typemap_replace_vars(String *s, ParmList *locals, SwigType *type, SwigType *rtype, String *pname, String *lname, int index) {
int typemap_replace_vars(String *s, ParmList *locals, SwigType *type, SwigType *rtype, String *pname, String *lname, int index) {
char var[512]; char var[512];
char *varname; char *varname;
SwigType *ftype; SwigType *ftype;
@ -1216,7 +1214,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr op, Node *node,
String *qsn = st ? Swig_symbol_string_qualify(pname, st) : 0; String *qsn = st ? Swig_symbol_string_qualify(pname, st) : 0;
if (qsn) { if (qsn) {
if (Len(qsn) && !Equal(qsn, pname)) { if (Len(qsn) && !Equal(qsn, pname)) {
tm = Swig_typemap_search(op, type, qsn, &mtype); tm = typemap_search(op, type, qsn, &mtype);
if (tm && (!Getattr(tm, "pname") || strstr(Char(Getattr(tm, "type")), "SWIGTYPE"))) { if (tm && (!Getattr(tm, "pname") || strstr(Char(Getattr(tm, "type")), "SWIGTYPE"))) {
tm = 0; tm = 0;
} }
@ -1226,7 +1224,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr op, Node *node,
} }
if (!tm) if (!tm)
#endif #endif
tm = Swig_typemap_search(op, type, pname, &mtype); tm = typemap_search(op, type, pname, &mtype);
if (!tm) if (!tm)
return sdef; return sdef;
@ -1394,9 +1392,8 @@ String *Swig_typemap_lookup(const_String_or_char_ptr op, Node *node, const_Strin
return Swig_typemap_lookup_impl(op, node, lname, f, 0); return Swig_typemap_lookup_impl(op, node, lname, f, 0);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_typemap_attach_kwargs() * typemap_attach_kwargs()
* *
* If this hash (tm) contains a linked list of parameters under its "kwargs" * If this hash (tm) contains a linked list of parameters under its "kwargs"
* attribute, add keys for each of those named keyword arguments to this * attribute, add keys for each of those named keyword arguments to this
@ -1406,7 +1403,7 @@ String *Swig_typemap_lookup(const_String_or_char_ptr op, Node *node, const_Strin
* A new attribute called "tmap:in:foo" with value "xyz" is attached to p. * A new attribute called "tmap:in:foo" with value "xyz" is attached to p.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void Swig_typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr op, Parm *p) { static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr op, Parm *p) {
String *temp = NewStringEmpty(); String *temp = NewStringEmpty();
Parm *kw = Getattr(tm, "kwargs"); Parm *kw = Getattr(tm, "kwargs");
while (kw) { while (kw) {
@ -1432,13 +1429,13 @@ void Swig_typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr op, Parm *p)
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_typemap_warn() * typemap_warn()
* *
* If any warning message is attached to this parameter's "tmap:op:warning" * If any warning message is attached to this parameter's "tmap:op:warning"
* attribute, print that warning message. * attribute, print that warning message.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static void Swig_typemap_warn(const_String_or_char_ptr op, Parm *p) { static void typemap_warn(const_String_or_char_ptr op, Parm *p) {
String *temp = NewStringf("%s:warning", op); String *temp = NewStringf("%s:warning", op);
String *w = Getattr(p, tmop_name(temp)); String *w = Getattr(p, tmop_name(temp));
Delete(temp); Delete(temp);
@ -1447,7 +1444,7 @@ static void Swig_typemap_warn(const_String_or_char_ptr op, Parm *p) {
} }
} }
static void Swig_typemap_emit_code_fragments(const_String_or_char_ptr op, Parm *p) { static void typemap_emit_code_fragments(const_String_or_char_ptr op, Parm *p) {
String *temp = NewStringf("%s:fragment", op); String *temp = NewStringf("%s:fragment", op);
String *f = Getattr(p, tmop_name(temp)); String *f = Getattr(p, tmop_name(temp));
if (f) { if (f) {
@ -1467,7 +1464,7 @@ static void Swig_typemap_emit_code_fragments(const_String_or_char_ptr op, Parm *
* given typemap type * given typemap type
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
String *Swig_typemap_get_option(Hash *tm, const_String_or_char_ptr name) { static String *typemap_get_option(Hash *tm, const_String_or_char_ptr name) {
Parm *kw = Getattr(tm, "kwargs"); Parm *kw = Getattr(tm, "kwargs");
while (kw) { while (kw) {
String *kname = Getattr(kw, "name"); String *kname = Getattr(kw, "name");
@ -1502,7 +1499,7 @@ void Swig_typemap_attach_parms(const_String_or_char_ptr op, ParmList *parms, Wra
#ifdef SWIG_DEBUG #ifdef SWIG_DEBUG
Printf(stdout, "parms: %s %s %s\n", op, Getattr(p, "name"), Getattr(p, "type")); Printf(stdout, "parms: %s %s %s\n", op, Getattr(p, "name"), Getattr(p, "type"));
#endif #endif
tm = Swig_typemap_search_multi(op, p, &nmatch); tm = typemap_search_multi(op, p, &nmatch);
#ifdef SWIG_DEBUG #ifdef SWIG_DEBUG
if (tm) if (tm)
Printf(stdout, "found: %s\n", tm); Printf(stdout, "found: %s\n", tm);
@ -1521,7 +1518,7 @@ void Swig_typemap_attach_parms(const_String_or_char_ptr op, ParmList *parms, Wra
here, the freearg typemap requires the "in" typemap to match, here, the freearg typemap requires the "in" typemap to match,
or the 'var$argnum' variable will not exist. or the 'var$argnum' variable will not exist.
*/ */
kwmatch = Swig_typemap_get_option(tm, "match"); kwmatch = typemap_get_option(tm, "match");
if (kwmatch) { if (kwmatch) {
String *tmname = NewStringf("tmap:%s", kwmatch); String *tmname = NewStringf("tmap:%s", kwmatch);
String *tmin = Getattr(p, tmname); String *tmin = Getattr(p, tmname);
@ -1547,7 +1544,7 @@ void Swig_typemap_attach_parms(const_String_or_char_ptr op, ParmList *parms, Wra
continue; continue;
} else { } else {
int nnmatch; int nnmatch;
Hash *tmapin = Swig_typemap_search_multi(kwmatch, p, &nnmatch); Hash *tmapin = typemap_search_multi(kwmatch, p, &nnmatch);
String *tmname = Getattr(tm, "pname"); String *tmname = Getattr(tm, "pname");
String *tnname = Getattr(tmapin, "pname"); String *tnname = Getattr(tmapin, "pname");
if (!(tmname && tnname && Equal(tmname, tnname)) && !(!tmname && !tnname)) { if (!(tmname && tnname && Equal(tmname, tnname)) && !(!tmname && !tnname)) {
@ -1640,13 +1637,13 @@ void Swig_typemap_attach_parms(const_String_or_char_ptr op, ParmList *parms, Wra
Setattr(firstp, tmop_name(temp), p); Setattr(firstp, tmop_name(temp), p);
/* Attach kwargs */ /* Attach kwargs */
Swig_typemap_attach_kwargs(tm, op, firstp); typemap_attach_kwargs(tm, op, firstp);
/* Print warnings, if any */ /* Print warnings, if any */
Swig_typemap_warn(op, firstp); typemap_warn(op, firstp);
/* Look for code fragments */ /* Look for code fragments */
Swig_typemap_emit_code_fragments(op, firstp); typemap_emit_code_fragments(op, firstp);
/* increase argnum to consider numinputs */ /* increase argnum to consider numinputs */
argnum += nmatch - 1; argnum += nmatch - 1;