- more exception strings defined
[cacao.git] / src / native / native.h
1 /* native.h - table of native functions
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Reinhard Grafl
28
29    $Id: native.h 1089 2004-05-27 15:41:37Z twisti $
30
31 */
32
33
34 #ifndef _NATIVE_H
35 #define _NATIVE_H
36
37
38 #include "jni.h"
39 #include "nat/java_lang_String.h"
40 #include "nat/java_lang_ClassLoader.h"
41 #include "nat/java_lang_Throwable.h"
42
43
44 /* searchpath for classfiles */
45 extern char *classpath;
46
47 extern classinfo *class_java_lang_Class;
48 extern classinfo *class_java_lang_VMClass;
49 extern classinfo *class_java_lang_System;
50 extern classinfo *class_java_lang_ClassLoader;
51 extern classinfo *class_java_lang_Double;
52 extern classinfo *class_java_lang_Float;
53 extern classinfo *class_java_lang_Long;
54 extern classinfo *class_java_lang_Byte;
55 extern classinfo *class_java_lang_Short;
56 extern classinfo *class_java_lang_Boolean;
57 extern classinfo *class_java_lang_Void;
58 extern classinfo *class_java_lang_Character;
59 extern classinfo *class_java_lang_Integer;
60
61
62 /* system exception classes required while compiling                          */
63
64 extern classinfo *class_java_lang_Throwable;
65
66
67 /* exception/error super class */
68
69 extern char *string_java_lang_Throwable;
70
71
72 /* specify some exception strings for code generation */
73
74 extern char *string_java_lang_ArithmeticException;
75 extern char *string_java_lang_ArithmeticException_message;
76 extern char *string_java_lang_ArrayIndexOutOfBoundsException;
77 extern char *string_java_lang_ArrayStoreException;
78 extern char *string_java_lang_ClassCastException;
79 extern char *string_java_lang_ClassNotFoundException;
80 extern char *string_java_lang_CloneNotSupportedException;
81 extern char *string_java_lang_Exception;
82 extern char *string_java_lang_IllegalArgumentException;
83 extern char *string_java_lang_IllegalMonitorStateException;
84 extern char *string_java_lang_NegativeArraySizeException;
85 extern char *string_java_lang_NoSuchFieldException;
86 extern char *string_java_lang_NoSuchMethodException;
87 extern char *string_java_lang_NullPointerException;
88
89
90 /* specify some error strings for code generation */
91
92 extern char *string_java_lang_AbstractMethodError;
93 extern char *string_java_lang_ClassCircularityError;
94 extern char *string_java_lang_ClassFormatError;
95 extern char *string_java_lang_Error;
96 extern char *string_java_lang_ExceptionInInitializerError;
97 extern char *string_java_lang_IncompatibleClassChangeError;
98 extern char *string_java_lang_InternalError;
99 extern char *string_java_lang_LinkageError;
100 extern char *string_java_lang_NoClassDefFoundError;
101 extern char *string_java_lang_NoSuchFieldError;
102 extern char *string_java_lang_NoSuchMethodError;
103 extern char *string_java_lang_OutOfMemoryError;
104 extern char *string_java_lang_VerifyError;
105
106
107 /* the system classloader object */
108 extern java_lang_ClassLoader *SystemClassLoader;
109
110 /* for raising exceptions from native methods */
111 /* extern java_objectheader* exceptionptr; */
112
113 /* javastring-hashtable */
114 extern hashtable string_hash; 
115
116 /* load, link and compile exceptions used in the system */
117 void init_system_exceptions();
118 void compile_all_class_methods(classinfo *c);
119
120 /* throw an exception and exit */
121 void throw_exception_exit();
122
123 void throw_cacao_exception_exit(char *exception, char *message);
124
125 /* initialize new exceptions */
126 java_objectheader *new_exception(char *classname);
127 java_objectheader *new_exception_message(char *classname, char *message);
128 java_objectheader *new_exception_throwable(char *classname, java_lang_Throwable *cause);
129 java_objectheader *new_exception_utfmessage(char *classname, utf *message);
130 java_objectheader *new_exception_javastring(char *classname, java_lang_String *message);
131 java_objectheader *new_exception_int(char *classname, s4 i);
132
133 void use_class_as_object(classinfo *c);
134
135 /* load classes required for native methods */
136 void native_loadclasses();
137
138 /* set searchpath for classfiles */
139 void native_setclasspath(char *path);
140
141 /* find native function */
142 functionptr native_findfunction(utf *cname, utf *mname, 
143                                                                 utf *desc, bool isstatic);
144
145 /* creates a new object of type java/lang/String from a utf-text */
146 /*  java_objectheader *javastring_new(utf *text); */
147 java_lang_String *javastring_new(utf *text);
148
149 /* creates a new object of type java/lang/String from a c-string */
150 /*  java_objectheader *javastring_new_char(char *text); */
151 java_lang_String *javastring_new_char(char *text);
152
153 /* make c-string from a javastring (debugging) */
154 char *javastring_tochar(java_objectheader *s);
155
156 /* create new object on the heap and call the initializer */
157 java_objectheader *native_new_and_init(classinfo *c);
158
159 /* create new object on the heap and call the initializer 
160    mainly used for exceptions with a message */
161 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s);
162
163 /* create new object on the heap and call the initializer 
164    mainly used for exceptions with an index */
165 java_objectheader *native_new_and_init_int(classinfo *c, s4 i);
166
167 /* create new object on the heap and call the initializer 
168    mainly used for exceptions with cause */
169 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t);
170
171 /* add property to system-property vector */
172 void attach_property(char *name, char *value);
173
174 /* correct vftbl-entries of javastring-hash */
175 void stringtable_update();
176
177
178 /* make utf symbol from javastring */
179 utf *javastring_toutf(struct java_lang_String *string, bool isclassname);
180
181 /* make utf symbol from u2 array */
182 utf *utf_new_u2(u2 *unicodedata, u4 unicodelength, bool isclassname);
183
184 /* determine utf length in bytes of a u2 array */
185 u4 u2_utflength(u2 *text, u4 u2_length);
186
187 /* create systemclassloader object and initialize its instance fields  */
188 void init_systemclassloader();
189
190 /* search 'classinfo'-structure for a field with the specified name */
191 fieldinfo *class_findfield_approx(classinfo *c, utf *name);
192 s4 class_findfield_index_approx(classinfo *c, utf *name);
193
194 /* creates a new javastring with the text of the utf-symbol */
195 java_objectheader *literalstring_new(utf *u);
196
197 /* creates a new javastring with the text of the u2-array */
198 java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
199                                                                         bool copymode);
200
201 /* dispose a javastring */
202 void literalstring_free(java_objectheader*);
203
204 void copy_vftbl(vftbl **dest, vftbl *src);
205
206 utf *create_methodsig(java_objectarray* types, char *retType);
207 classinfo *get_type(char **utf_ptr,char *desc_end, bool skip);
208 java_objectarray* get_parametertypes(methodinfo *m);
209 java_objectarray* get_exceptiontypes(methodinfo *m);
210 classinfo *get_returntype(methodinfo *m);
211
212
213
214
215 java_objectarray *builtin_asm_createclasscontextarray(classinfo **end,classinfo **start);
216 java_lang_ClassLoader *builtin_asm_getclassloader(classinfo **end,classinfo **start);
217
218 #endif /* _NATIVE_H */
219
220
221 /*
222  * These are local overrides for various environment variables in Emacs.
223  * Please do not remove this and leave it at the end of the file, where
224  * Emacs will automagically detect them.
225  * ---------------------------------------------------------------------
226  * Local variables:
227  * mode: c
228  * indent-tabs-mode: t
229  * c-basic-offset: 4
230  * tab-width: 4
231  * End:
232  */