implement the 'allowexcept' feature for global variables

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8576 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2006-01-28 02:36:13 +00:00
commit ccee08ce43
7 changed files with 51 additions and 29 deletions

View file

@ -339,6 +339,23 @@ void replace_contract_args(Parm *cp, Parm *rp, String *s) {
*
* Emits action code for a wrapper and checks for exception handling
* ----------------------------------------------------------------------------- */
int emit_action_code(Node *n, Wrapper *f, String *eaction) {
/* Look for except feature */
String *tm = GetFlagAttr(n,"feature:except");
if (tm) tm = Copy(tm);
if ((tm) && Len(tm) && (Strcmp(tm,"1") != 0)) {
Replaceall(tm,"$name",Getattr(n,"name"));
Replaceall(tm,"$symname", Getattr(n,"sym:name"));
Replaceall(tm,"$function", eaction);
Replaceall(tm,"$action", eaction);
Printv(f->code,tm,"\n", NIL);
Delete(tm);
return 1;
} else {
Printv(f->code,eaction,"\n", NIL);
return 0;
}
}
void emit_action(Node *n, Wrapper *f) {
String *tm;
@ -458,22 +475,14 @@ void emit_action(Node *n, Wrapper *f) {
/* Look for except typemap (Deprecated) */
tm = Swig_typemap_lookup_new("except",n,"result",0);
/* Look for except feature */
if (!tm) {
tm = GetFlagAttr(n,"feature:except");
if (tm) tm = Copy(tm);
}
if ((tm) && Len(tm) && (Strcmp(tm,"1") != 0)) {
Replaceall(tm,"$name",Getattr(n,"name"));
Replaceall(tm,"$symname", Getattr(n,"sym:name"));
Replaceall(tm,"$function", eaction);
Replaceall(tm,"$action", eaction);
Printv(f->code,tm,"\n", NIL);
Delete(tm);
} else {
Printv(f->code,eaction,"\n",NIL);
if (tm) {
Setattr(n,"feature:except", tm);
tm = 0;
}
/* emit the except feature code */
emit_action_code(n, f, eaction);
Delete(eaction);
/* Emit contract code (if any) */
@ -486,3 +495,5 @@ void emit_action(Node *n, Wrapper *f) {
}
}

View file

@ -1261,7 +1261,8 @@ public:
Replaceall(tm,"$source","s_0");
Replaceall(tm,"$input","s_0");
Replaceall(tm,"$target",name);
Printv(f->code,tm,"\n",NIL);
/* Printv(f->code,tm,"\n",NIL); */
emit_action_code(n, f, tm);
}
else {
throw_unhandled_guile_type_error (t);
@ -1276,7 +1277,8 @@ public:
Replaceall(tm,"$source",name);
Replaceall(tm,"$target","gswig_result");
Replaceall(tm,"$result", "gswig_result");
Printv(f->code,tm,"\n",NIL);
/* Printv(f->code,tm,"\n",NIL); */
emit_action_code(n, f, tm);
}
else {
throw_unhandled_guile_type_error (t);

View file

@ -506,7 +506,8 @@ public:
Replaceall(tm,"$source","argv[0]");
Replaceall(tm,"$target",name);
Replaceall(tm,"$input","argv[0]");
Printv(f->code, tm, "\n",NIL);
/* Printv(f->code, tm, "\n",NIL); */
emit_action_code(n, f, tm);
}
else {
throw_unhandled_mzscheme_type_error (t);
@ -521,7 +522,8 @@ public:
Replaceall(tm,"$source",name);
Replaceall(tm,"$target","swig_result");
Replaceall(tm,"$result","swig_result");
Printf (f->code, "%s\n", tm);
/* Printf (f->code, "%s\n", tm); */
emit_action_code(n, f, tm);
}
else {
throw_unhandled_mzscheme_type_error (t);

View file

@ -886,7 +886,8 @@ public:
Replaceall(tm,"$source","args");
Replaceall(tm,"$target",name);
Replaceall(tm,"$input","args");
Printv(f->code, tm, "\n",NIL);
/* Printv(f->code, tm, "\n",NIL); */
emit_action_code(n, f, tm);
} else if ((tm = Swig_typemap_lookup_new("in",n,name,0))) {
Replaceall(tm,"$source","args");
Replaceall(tm,"$target",name);
@ -905,7 +906,8 @@ public:
Replaceall(tm,"$source",name);
Replaceall(tm,"$target","swig_result");
Replaceall(tm,"$result","swig_result");
Printf (f->code, "%s\n", tm);
/* Printf (f->code, "%s\n", tm); */
emit_action_code(n, f, tm);
} else if ((tm = Swig_typemap_lookup_new("out",n,name,0))) {
Replaceall(tm,"$source",name);
Replaceall(tm,"$target","swig_result");

View file

@ -831,7 +831,8 @@ public:
Replaceall(tm,"$source","sv");
Replaceall(tm,"$target",name);
Replaceall(tm,"$input","sv");
Printf(setf->code,"%s\n", tm);
/* Printf(setf->code,"%s\n", tm); */
emit_action_code(n, setf, tm);
} else {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number,
"Unable to set variable of type %s.\n", SwigType_str(t,0));
@ -860,7 +861,8 @@ public:
} else {
Replaceall(tm, "$shadow", "0");
}
Printf(getf->code,"%s\n", tm);
/* Printf(getf->code,"%s\n", tm);*/
emit_action_code(n, getf, tm);
} else {
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number,
"Unable to read variable of type %s\n", SwigType_str(t,0));

View file

@ -1437,7 +1437,8 @@ public:
Replaceall(tm,"$result","_val");
Replaceall(tm,"$target","_val");
Replaceall(tm,"$source",name);
Printv(getf->code,tm, NIL);
/* Printv(getf->code,tm, NIL); */
emit_action_code(n, getf, tm);
} else {
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number,
"Unable to read variable of type %s\n", SwigType_str(t,0));
@ -1451,14 +1452,14 @@ public:
/* create setter */
setfname = Swig_name_set(iname);
Printv(setf->def, "SWIGINTERN VALUE\n", setfname, "(VALUE self, ", NIL);
Printf(setf->def, "VALUE _val) {");
Printf(setf->def, "VALUE _val) {");
tm = Swig_typemap_lookup_new("varin",n,name,0);
if (tm) {
Replaceall(tm,"$input","_val");
Replaceall(tm,"$source","_val");
Replaceall(tm,"$target",name);
Printv(setf->code,tm,"\n",NIL);
/* Printv(setf->code,tm,"\n",NIL); */
emit_action_code(n, setf, tm);
} else {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number,
"Unable to set variable of type %s\n", SwigType_str(t,0));

View file

@ -583,7 +583,8 @@ public:
Replaceall(tm,"$source", name);
Replaceall(tm,"$target","value");
Replaceall(tm,"$result", "value");
Printf(getf->code, "%s\n",tm);
/* Printf(getf->code, "%s\n",tm); */
emit_action_code(n, getf, tm);
Printf(getf->code, "if (value) {\n");
Printf(getf->code, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n");
Printf(getf->code, "Tcl_DecrRefCount(value);\n");
@ -615,7 +616,8 @@ public:
Printf(setf->code,"value = Tcl_ObjGetVar2(interp, name1o, 0, flags);\n");
Printf(setf->code,"Tcl_DecrRefCount(name1o);\n");
Printf(setf->code,"if (!value) SWIG_fail;\n");
Printf(setf->code,"%s\n", tm);
/* Printf(setf->code,"%s\n", tm);*/
emit_action_code(n, setf, tm);
Printf(setf->code,"return NULL;\n");
Printf(setf->code,"fail:\n");
Printf(setf->code,"return \"%s\";\n", iname);