Home | History | Annotate | Download | only in modula3
      1 /* -----------------------------------------------------------------------------
      2  * modula3head.swg
      3  *
      4  * Modula3 support code
      5  * ----------------------------------------------------------------------------- */
      6 
      7 %insert(runtime) %{
      8 
      9 #include <stdlib.h>
     10 #include <string.h>
     11 #include <stdio.h>
     12 %}
     13 
     14 #if 0
     15 %insert(runtime) %{
     16 /* Support for throwing Modula3 exceptions */
     17 typedef enum {
     18   SWIG_JavaOutOfMemoryError = 1,
     19   SWIG_JavaIOException,
     20   SWIG_JavaRuntimeException,
     21   SWIG_JavaIndexOutOfBoundsException,
     22   SWIG_JavaArithmeticException,
     23   SWIG_JavaIllegalArgumentException,
     24   SWIG_JavaNullPointerException,
     25   SWIG_JavaUnknownError
     26 } SWIG_JavaExceptionCodes;
     27 
     28 typedef struct {
     29   SWIG_JavaExceptionCodes code;
     30   const char *java_exception;
     31 } SWIG_JavaExceptions_t;
     32 
     33 #if defined(SWIG_NOINCLUDE)
     34 void SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg);
     35 #else
     36 %}
     37 %insert(runtime) {
     38 void SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
     39   jclass excep;
     40   static const SWIG_JavaExceptions_t java_exceptions[] = {
     41     { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" },
     42     { SWIG_JavaIOException, "java/io/IOException" },
     43     { SWIG_JavaRuntimeException, "java/lang/RuntimeException" },
     44     { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" },
     45     { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" },
     46     { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" },
     47     { SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
     48     { SWIG_JavaUnknownError,  "java/lang/UnknownError" },
     49     { (SWIG_JavaExceptionCodes)0,  "java/lang/UnknownError" } };
     50   const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
     51 
     52   while (except_ptr->code != code && except_ptr->code)
     53     except_ptr++;
     54 
     55   JCALL0(ExceptionClear, jenv);
     56   excep = JCALL1(FindClass, jenv, except_ptr->java_exception);
     57   if (excep)
     58     JCALL2(ThrowNew, jenv, excep, msg);
     59 }
     60 }
     61 %insert(runtime) %{
     62 #endif
     63 %}
     64 #endif
     65