directorout typemaps added (patch from Scott Michel)

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7111 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2005-03-29 20:53:36 +00:00
commit e683b3c7f7

View file

@ -2843,7 +2843,7 @@ class JAVA : public Language {
String *declaration = NewString(""); String *declaration = NewString("");
String *tm; String *tm;
Parm *p; Parm *p;
int i, num_arguments, num_required; int i;
Wrapper *w = NewWrapper(); Wrapper *w = NewWrapper();
ParmList *l = Getattr(n, "parms"); ParmList *l = Getattr(n, "parms");
bool is_void = !(Cmp(returntype, "void")); bool is_void = !(Cmp(returntype, "void"));
@ -2867,7 +2867,7 @@ class JAVA : public Language {
int classmeth_off = curr_class_dmethod - first_class_dmethod; int classmeth_off = curr_class_dmethod - first_class_dmethod;
// This is a kludge: functionWrapper has sym:overload set properly, but it // Kludge Alert: functionWrapper sets sym:overload properly, but it
// isn't at this point, so we have to manufacture it ourselves. At least // isn't at this point, so we have to manufacture it ourselves. At least
// we're consistent with the sym:overload name in functionWrapper. (?? when // we're consistent with the sym:overload name in functionWrapper. (?? when
// does the overloaded method name get set?) // does the overloaded method name get set?)
@ -2889,8 +2889,9 @@ class JAVA : public Language {
Wrapper_add_localv(w, "result", SwigType_lstr(returntype, "result"), NIL); Wrapper_add_localv(w, "result", SwigType_lstr(returntype, "result"), NIL);
} else { } else {
String *base_typename = SwigType_base(returntype); String *base_typename = SwigType_base(returntype);
String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
Symtab *symtab = Getattr(n, "sym:symtab"); Symtab *symtab = Getattr(n, "sym:symtab");
Node *typenode = Swig_symbol_clookup(base_typename, symtab); Node *typenode = Swig_symbol_clookup(resolved_typename, symtab);
if (SwigType_ispointer(returntype) || (typenode != NULL && Getattr(typenode, "abstract"))) { if (SwigType_ispointer(returntype) || (typenode != NULL && Getattr(typenode, "abstract"))) {
/* initialize pointers to something sane. Same for abstract /* initialize pointers to something sane. Same for abstract
@ -2898,7 +2899,8 @@ class JAVA : public Language {
Wrapper_add_localv(w, "result", SwigType_lstr(returntype, "result"), "= 0", NIL); Wrapper_add_localv(w, "result", SwigType_lstr(returntype, "result"), "= 0", NIL);
} else { } else {
/* If returning a reference, initialize the pointer to a sane /* If returning a reference, initialize the pointer to a sane
default */ default - if a Java exception occurs, then the pointer returns
something other than a NULL-initialized reference. */
String *non_ref_type = Copy(returntype); String *non_ref_type = Copy(returntype);
/* Remove reference and const qualifiers */ /* Remove reference and const qualifiers */
@ -2910,6 +2912,9 @@ class JAVA : public Language {
Delete(non_ref_type); Delete(non_ref_type);
} }
Delete(base_typename);
Delete(resolved_typename);
} }
} else { } else {
SwigType *vt; SwigType *vt;
@ -2981,7 +2986,9 @@ class JAVA : public Language {
&& (jdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor")) != NULL) { && (jdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor")) != NULL) {
String *jnidesc_canon; String *jnidesc_canon;
// Note that in the case of polymorphic (covariant) return types, the method's return type is changed to be the base of the C++ return type // Note that in the case of polymorphic (covariant) return types, the
// method's return type is changed to be the base of the C++ return
// type
jnidesc_canon = canonicalizeJNIDescriptor(jdesc, adjustedreturntypeparm); jnidesc_canon = canonicalizeJNIDescriptor(jdesc, adjustedreturntypeparm);
Append(classret_desc, jnidesc_canon); Append(classret_desc, jnidesc_canon);
Delete(jnidesc_canon); Delete(jnidesc_canon);
@ -3010,8 +3017,6 @@ class JAVA : public Language {
} }
/* Attach the standard typemaps */ /* Attach the standard typemaps */
emit_attach_parmmaps(l, w);
Swig_typemap_attach_parms("in", l, w);
Swig_typemap_attach_parms("out", l, w); Swig_typemap_attach_parms("out", l, w);
Swig_typemap_attach_parms("jni", l, w); Swig_typemap_attach_parms("jni", l, w);
Swig_typemap_attach_parms("jtype", l, w); Swig_typemap_attach_parms("jtype", l, w);
@ -3019,16 +3024,13 @@ class JAVA : public Language {
Swig_typemap_attach_parms("javadirectorin", l, 0); Swig_typemap_attach_parms("javadirectorin", l, 0);
/* Add Java environment pointer to wrapper */ /* Add Java environment pointer to wrapper */
{
String *jenvstr = NewString("jenv"); String *jenvstr = NewString("jenv");
Wrapper_add_localv(w, jenvstr, "JNIEnv *", jenvstr, "= (JNIEnv *) NULL", NIL); Wrapper_add_localv(w, jenvstr, "JNIEnv *", jenvstr, "= (JNIEnv *) NULL", NIL);
Delete(jenvstr); Delete(jenvstr);
}
/* Preamble code */ /* Preamble code */
Printf(w->code, "jenv = swig_acquire_jenv();\n");
Printf(w->code, "if (!swig_override[%d]) {\n", classmeth_off); Printf(w->code, "if (!swig_override[%d]) {\n", classmeth_off);
if (!pure_virtual) { if (!pure_virtual) {
@ -3054,9 +3056,9 @@ class JAVA : public Language {
} }
Printf(w->code, "}\n"); Printf(w->code, "}\n");
Printf(w->code, "jenv = swig_acquire_jenv();\n");
/* Start the Java field descriptor for the intermediate class's upcall (insert self object) */ /* Start the Java field descriptor for the intermediate class's upcall (insert self object) */
{
Parm *tp = NewParm(c_classname, empty_str); Parm *tp = NewParm(c_classname, empty_str);
String *jdesc; String *jdesc;
@ -3075,16 +3077,12 @@ class JAVA : public Language {
} }
Delete(tp); Delete(tp);
}
/* Get number of required and total arguments */
num_arguments = emit_num_arguments(l);
num_required = emit_num_required(l);
/* Go through argument list, convert from native to Java */ /* Go through argument list, convert from native to Java */
for (i = 0, p=l; i < num_arguments; i++) { for (p=l; p != NULL; /* empty */) {
while (checkAttribute(p,"tmap:in:numinputs","0")) { /* Is this superfluous? */
p = Getattr(p,"tmap:in:next"); while (checkAttribute(p,"tmap:directorin:numinputs","0")) {
p = Getattr(p,"tmap:directorin:next");
} }
SwigType *pt = Getattr(p,"type"); SwigType *pt = Getattr(p,"type");
@ -3096,7 +3094,7 @@ class JAVA : public Language {
Printf(arg, "j%s", ln); Printf(arg, "j%s", ln);
/* Add various typemap's 'throws' clauses */ /* Add various typemap's 'throws' clauses */
addThrows(n, "tmap:in", p); addThrows(n, "tmap:directorin", p);
addThrows(n, "tmap:out", p); addThrows(n, "tmap:out", p);
/* And add to the upcall args */ /* And add to the upcall args */
@ -3105,7 +3103,7 @@ class JAVA : public Language {
/* Get parameter's JNI C type */ /* Get parameter's JNI C type */
if ((c_param_type = Getattr(p, "tmap:jni")) != NULL) { if ((c_param_type = Getattr(p, "tmap:jni")) != NULL) {
Parm *tp = NewParm(c_param_type, empty_str); Parm *tp = NewParm(c_param_type, empty_str);
String *desc_tm, *jdesc, *cdesc; String *desc_tm = NULL, *jdesc = NULL, *cdesc = NULL;
/* Add to local variables */ /* Add to local variables */
Printf(c_decl, "%s %s", c_param_type, arg); Printf(c_decl, "%s %s", c_param_type, arg);
@ -3113,8 +3111,8 @@ class JAVA : public Language {
/* Add input marshalling code and update JNI field descriptor */ /* Add input marshalling code and update JNI field descriptor */
if ((desc_tm = Swig_typemap_lookup_new("directorin", tp, "", 0)) != NULL if ((desc_tm = Swig_typemap_lookup_new("directorin", tp, "", 0)) != NULL
&& (jdesc = Getattr(tp, "tmap:directorin:descriptor")) != NULL) { && (jdesc = Getattr(tp, "tmap:directorin:descriptor")) != NULL
if ((tm = Getattr(p, "tmap:directorin")) != NULL && (tm = Getattr(p, "tmap:directorin")) != NULL
&& (cdesc = Getattr(p, "tmap:directorin:descriptor")) != NULL) { && (cdesc = Getattr(p, "tmap:directorin:descriptor")) != NULL) {
String *jni_canon; String *jni_canon;
@ -3164,20 +3162,30 @@ class JAVA : public Language {
output_director = false; output_director = false;
} }
p = Getattr(p, "tmap:in:next"); p = Getattr(p, "tmap:directorin:next");
} else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap defined for %s\n", SwigType_str(pt, 0));
output_director = false;
p = nextSibling(p);
}
Delete(desc_tm); Delete(desc_tm);
} else { } else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, if (desc_tm == NULL) {
Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap defined for %s\n", SwigType_str(c_param_type, 0)); "No or improper directorin typemap defined for %s\n", SwigType_str(c_param_type, 0));
output_director = false;
p = nextSibling(p); p = nextSibling(p);
} else if (jdesc == NULL) {
Swig_warning(WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC, input_file, line_number,
"Missing JNI descriptor in directorin typemap defined for %s\n",
SwigType_str(c_param_type, 0));
p = Getattr(p, "tmap:directorin:next");
} else if (tm == NULL) {
Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number,
"No or improper directorin typemap defined for argument %s\n", SwigType_str(pt, 0));
p = nextSibling(p);
} else if (cdesc == NULL) {
Swig_warning(WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC, input_file, line_number,
"Missing JNI descriptor in directorin typemap defined for %s\n", SwigType_str(pt, 0));
p = Getattr(p, "tmap:directorin:next");
}
output_director = false;
} }
Delete(tp); Delete(tp);
@ -3294,16 +3302,16 @@ class JAVA : public Language {
Parm *tp = NewParm(returntype, result_str); Parm *tp = NewParm(returntype, result_str);
/* Copy jresult into result... */ /* Copy jresult into result... */
if ((tm = Swig_typemap_lookup_new("in", tp, result_str, w))) { if ((tm = Swig_typemap_lookup_new("directorout", tp, result_str, w))) {
addThrows(n, "tmap:in", tp); addThrows(n, "tmap:directorout", tp);
Replaceall(tm,"$source", jresult_str); /* deprecated */ Replaceall(tm,"$source", jresult_str); /* deprecated */
Replaceall(tm,"$target", result_str); /* deprecated */ Replaceall(tm,"$target", result_str); /* deprecated */
Replaceall(tm,"$arg", jresult_str); /* deprecated? */ Replaceall(tm,"$arg", jresult_str); /* deprecated? */
Replaceall(tm,"$input", jresult_str); Replaceall(tm,"$input", jresult_str);
Printf(w->code, "%s\n", tm); Printf(w->code, "%s\n", tm);
} else { } else {
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use type %s as a function argument.\n",SwigType_str(tp,0)); "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(tp, 0), classname, name);
output_director = false; output_director = false;
} }