director:except tweaks Recode whitespace handling, remove unnecessary comments in generated code.

This commit is contained in:
William S Fulton 2013-10-24 07:06:55 +01:00
commit 88678ed492

View file

@ -4160,20 +4160,18 @@ public:
* directorExceptHandler() * directorExceptHandler()
* *
* Emit code to map Java exceptions back to C++ exceptions when * Emit code to map Java exceptions back to C++ exceptions when
* feature("director:except") is applied to a method node * feature("director:except") is applied to a method node.
* This is generated after the Java method upcall.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
void directorExceptHandler(Node *n, ParmList *throw_parm_list, Wrapper *w, String *c_classname, String *name) { void directorExceptHandler(Node *n, ParmList *throw_parm_list, Wrapper *w, String *c_classname, String *name) {
// After director Java method call, allow code for director method exception to be added
// Look for director:exceptfeature
String *featdirexcp = Getattr(n, "feature:director:except"); String *featdirexcp = Getattr(n, "feature:director:except");
if (!featdirexcp) { if (!featdirexcp) {
featdirexcp = NewString(""); featdirexcp = NewString("");
Printf(featdirexcp, "jthrowable $error = jenv->ExceptionOccurred();\n"); Printf(featdirexcp, "jthrowable $error = jenv->ExceptionOccurred();\n");
Printf(featdirexcp, "if ($error) {\n"); Printf(featdirexcp, "if ($error) {\n");
Printf(featdirexcp, " jenv->ExceptionClear();\n"); Printf(featdirexcp, " jenv->ExceptionClear();$directorthrowshandlers\n");
Printf(featdirexcp, " $directorthrowshandlers\n");
Printf(featdirexcp, " throw Swig::DirectorException(jenv, $error);\n"); Printf(featdirexcp, " throw Swig::DirectorException(jenv, $error);\n");
Printf(featdirexcp, "}\n"); Printf(featdirexcp, "}\n");
} else { } else {
@ -4181,7 +4179,7 @@ public:
} }
// Can explicitly disable director:except by setting to "" or "0" // Can explicitly disable director:except by setting to "" or "0"
if (Len(featdirexcp) != 0 && Cmp(featdirexcp, "0") != 0) { if (Len(featdirexcp) > 0 && Cmp(featdirexcp, "0") != 0) {
// Replace $packagepath // Replace $packagepath
substitutePackagePath(featdirexcp, 0); substitutePackagePath(featdirexcp, 0);
@ -4202,22 +4200,14 @@ public:
// replace $packagepath // replace $packagepath
tmapdirthrows = Copy(tmapdirthrows); tmapdirthrows = Copy(tmapdirthrows);
substituteClassnameAndPackagePath(excptype, tmapdirthrows, true, p); substituteClassnameAndPackagePath(excptype, tmapdirthrows, true, p);
Printv(directorthrowshandlers_code, tmapdirthrows, NIL);
Printf(directorthrowshandlers_code, "// Handle exception %s using directorthrows typemap\n" "%s", excptype, tmapdirthrows);
Delete(tmapdirthrows); Delete(tmapdirthrows);
} }
} }
// Delete extra new line if no handlers. Replaceall(featdirexcp, "$directorthrowshandlers", directorthrowshandlers_code);
while (Replaceall(featdirexcp, "$directorthrowshandlers ", "$directorthrowshandlers")) {
}
if (Len(directorthrowshandlers_code) == 0)
Replaceall(featdirexcp, "$directorthrowshandlers\n", "");
else
Replaceall(featdirexcp, "$directorthrowshandlers", directorthrowshandlers_code);
Delete(directorthrowshandlers_code); Delete(directorthrowshandlers_code);
} }
// Replace all occurrences of $error with common var name.
Replaceall(featdirexcp, "$error", "swigerror"); Replaceall(featdirexcp, "$error", "swigerror");
Printf(w->code, " %s\n", featdirexcp); Printf(w->code, " %s\n", featdirexcp);
} }