Added exceptions (again) since the exceptions.[ch] stuff does not work as
authortwisti <none@none>
Thu, 12 May 2005 23:55:10 +0000 (23:55 +0000)
committertwisti <none@none>
Thu, 12 May 2005 23:55:10 +0000 (23:55 +0000)
it should for cacaoh.

src/cacaoh/headers.c
src/cacaoh/headers.h

index 325405cca55414780ce6b24f95157d98a15bf0cd..79c3274156494a1d502e07fc6ee7aac433318bb6 100644 (file)
             Philipp Tomsich
             Christian Thalinger
 
-   $Id: headers.c 2447 2005-05-11 12:55:06Z twisti $
+   $Id: headers.c 2464 2005-05-12 23:55:10Z twisti $
 
 */
 
 
+#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include "native/include/java_lang_Throwable.h"
 #include "toolbox/chain.h"
 #include "toolbox/logging.h"
+#include "vm/builtin.h"
 #include "vm/class.h"
 #include "vm/global.h"
 #include "vm/method.h"
 #include "vm/tables.h"
 #include "vm/loader.h"
 #include "vm/options.h"
-#include "vm/builtin.h"
+#include "vm/stringlocal.h"
 #include "vm/jit/asmpart.h"
 
 
@@ -156,11 +158,122 @@ typeinfo_is_assignable_to_class(typeinfo *value,classref_or_classinfo dest)
        return true;
 }
 
+
+/* exception functions ********************************************************/
+
+/* these should not be called */
+
+void throw_exception(void) { assert(0); }
+void throw_exception_exit(void) { assert(0); }
+java_objectheader *new_verifyerror(methodinfo *m, const char *message) { assert(0); }
+java_objectheader *new_exception_throwable(const char *classname, java_lang_Throwable *throwable) { assert(0); }
+
+
+void throw_cacao_exception_exit(const char *exception, const char *message, ...)
+{
+       va_list ap;
+
+       fprintf(stderr, "%s: ", exception);
+
+       va_start(ap, message);
+       vfprintf(stderr, message, ap);
+       va_end(ap);
+
+       exit(1);
+}
+
+
+java_objectheader *new_exception(const char *classname)
+{
+       fprintf(stderr, "%s\n", classname);
+       exit(1);
+}
+
+
+java_objectheader *new_exception_message(const char *classname, const char *message)
+{
+       fprintf(stderr, "%s: %s\n", classname, message);
+       exit(1);
+}
+
+
+java_objectheader *new_exception_utfmessage(const char *classname, utf *message)
+{
+       fprintf(stderr, "%s: ", classname);
+       utf_display(message);
+       fputc('\n', stderr);
+
+       exit(1);
+}
+
+
+java_objectheader *new_classformaterror(classinfo *c, const char *message, ...)
+{
+       va_list ap;
+
+       utf_display(c->name);
+       fprintf(stderr, ": ");
+
+       va_start(ap, message);
+       vfprintf(stderr, message, ap);
+       va_end(ap);
+
+       fputc('\n', stderr);
+
+       exit(1);
+}
+
+
+java_objectheader *new_internalerror(const char *message, ...)
+{
+       va_list ap;
+
+       fprintf(stderr, "%s: ", string_java_lang_InternalError);
+
+       va_start(ap, message);
+       vfprintf(stderr, message, ap);
+       va_end(ap);
+
+       exit(1);
+}
+
+
+java_objectheader *new_unsupportedclassversionerror(classinfo *c, const char *message, ...)
+{
+       va_list ap;
+
+       fprintf(stderr, "%s: ", string_java_lang_UnsupportedClassVersionError);
+
+       utf_display(c->name);
+       fprintf(stderr, ": ");
+
+       va_start(ap, message);
+       vfprintf(stderr, message, ap);
+       va_end(ap);
+
+       exit(1);
+}
+
+
+java_objectheader *new_negativearraysizeexception(void)
+{
+       fprintf(stderr, "%s", string_java_lang_NegativeArraySizeException);
+       exit(1);
+}
+
+
+java_objectheader *new_nullpointerexception(void)
+{
+       fprintf(stderr, "%s", string_java_lang_NullPointerException);
+       exit(1);
+}
+
+
 /************************ global variables **********************/
 
 chain *nativemethod_chain;              /* chain with native methods          */
 chain *nativeclass_chain;               /* chain with processed classes       */
-static chain *ident_chain; /* chain with method and field names in current class */
+chain *ident_chain;     /* chain with method and field names in current class */
 FILE *file = NULL;
 static u4 outputsize;
 static bool dopadding;
@@ -168,17 +281,17 @@ static bool dopadding;
 
 static void printIDpart(int c)
 {
-       if ((c >= 'a' && c <= 'z')
-               || (c >= 'A' && c <= 'Z')
-               || (c >= '0' && c <= '9')
-               || (c == '_'))
+       if ((c >= 'a' && c <= 'z') ||
+               (c >= 'A' && c <= 'Z') ||
+               (c >= '0' && c <= '9') ||
+               (c == '_'))
                putc(c, file);
        else
                putc('_', file);
 }
 
 
-static void printID(utf *u)
+void printID(utf *u)
 {
        char *utf_ptr = u->text;
        int i;
@@ -200,36 +313,39 @@ static void addoutputsize (int len)
 }
 
 
-static void printOverloadPart(utf *desc)
+void printOverloadPart(utf *desc)
 {
        char *utf_ptr=desc->text;
        u2 c;
 
-       fprintf(file,"__");
-       while ((c=utf_nextu2(&utf_ptr))!=')') {
+       fprintf(file, "__");
+
+       while ((c = utf_nextu2(&utf_ptr)) != ')') {
                switch (c) {
-                       case 'I':
-                       case 'S':
-                       case 'B':
-                       case 'C':
-                       case 'Z':
-                       case 'J':
-                       case 'F':
-                       case 'D': 
-                               fprintf (file, "%c",(char)c);
-                               break;
-                       case '[':
-                               fprintf(file,"_3");
-                               break;
-                       case 'L':
-                               putc('L',file);
-                               while ( (c=utf_nextu2(&utf_ptr)) != ';')
-                                       printIDpart (c);
-                               fprintf(file,"_2");
-                               break;
-                       case '(':
-                               break;
-                       default: panic ("invalid method descriptor");
+               case 'I':
+               case 'S':
+               case 'B':
+               case 'C':
+               case 'Z':
+               case 'J':
+               case 'F':
+               case 'D': 
+                       fprintf(file, "%c", (char) c);
+                       break;
+               case '[':
+                       fprintf(file, "_3");
+                       break;
+               case 'L':
+                       putc('L', file);
+                       while ((c = utf_nextu2(&utf_ptr)) != ';')
+                               printIDpart(c);
+                       fprintf(file, "_2");
+                       break;
+               case '(':
+                       break;
+               default: 
+                       log_text("invalid method descriptor");
+                       assert(0);
                }
        }
 }
@@ -366,15 +482,15 @@ void printmethod(methodinfo *m)
        utf_fprint(file, m->name);
        fprintf(file, "\n * Signature: ");
        utf_fprint(file, m->descriptor);
-       fprintf(file, "\n */\n");       
+       fprintf(file, "\n */\n");
 
        /* create prototype */                  
-       fprintf(file, "JNIEXPORT ");                            
+       fprintf(file, "JNIEXPORT ");
        printtype(utf_ptr);
        fprintf(file, " JNICALL Java_");
-       printID(m->class->name);           
+       printID(m->class->name);
 
-       chain_addlast(ident_chain, m->name);    
+       chain_addlast(ident_chain, m->name);
 
        fprintf(file, "_");
        printID(m->name);
@@ -536,12 +652,10 @@ void print_classname(classinfo *clazz)
        u2 c;
 
     while (utf_ptr < endpos) {
-               if ((c = utf_nextu2(&utf_ptr)) == '_') {
+               if ((c = utf_nextu2(&utf_ptr)) == '_')
                        putc('$', file);
-
-               } else {
+               else
                        putc(c, file);
-               }
        }
 } 
 
index 43f23ce2b61665244e0cf7c34644a28af047b67f..63d768d82e6b843bb52857012d6f84e30a531709 100644 (file)
@@ -26,7 +26,7 @@
 
    Authors: Christian Thalinger
 
-   $Id: headers.h 2194 2005-04-03 16:13:27Z twisti $
+   $Id: headers.h 2464 2005-05-12 23:55:10Z twisti $
 
 */
 
 extern THREADSPECIFIC java_objectheader *_exceptionptr;
 extern chain *nativemethod_chain;
 extern chain *nativeclass_chain;
+extern chain *ident_chain;
 extern FILE *file;
 
 
 /* function prototypes ********************************************************/
 
+void printID(utf *u);
+void printOverloadPart(utf *desc);
 void literalstring_free(java_objectheader *o);
 void printmethod(methodinfo *m);
 void gen_header_filename(char *buffer, utf *u);
 void headerfile_generate(classinfo *c, char *opt_directory);
+void print_classname(classinfo *clazz);
 
 #endif /* _HEADERS_H */