fix: dependencies in header files
[cacao.git] / 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 1296 2004-07-10 17:02:15Z stefan $
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 /* table for locating native methods */
45
46 typedef struct nativeref nativeref;
47 typedef struct nativecompref nativecompref;
48
49 struct nativeref {
50         char       *classname;
51         char       *methodname;
52         char       *descriptor;
53         bool        isstatic;
54         functionptr func;
55 };
56
57 /* table for fast string comparison */
58
59 struct nativecompref {
60         utf        *classname;
61         utf        *methodname;
62         utf        *descriptor;
63         bool        isstatic;
64         functionptr func;
65 };
66
67
68 /* searchpath for classfiles */
69
70 extern char *classpath;
71
72 extern classinfo *class_java_lang_Class;
73 extern classinfo *class_java_lang_VMClass;
74 extern classinfo *class_java_lang_System;
75 extern classinfo *class_java_lang_ClassLoader;
76 extern classinfo *class_java_lang_Double;
77 extern classinfo *class_java_lang_Float;
78 extern classinfo *class_java_lang_Long;
79 extern classinfo *class_java_lang_Byte;
80 extern classinfo *class_java_lang_Short;
81 extern classinfo *class_java_lang_Boolean;
82 extern classinfo *class_java_lang_Void;
83 extern classinfo *class_java_lang_Character;
84 extern classinfo *class_java_lang_Integer;
85
86
87 /* system exception classes required in cacao */
88
89 extern classinfo *class_java_lang_Throwable;
90 extern classinfo *class_java_lang_Exception;
91 extern classinfo *class_java_lang_Error;
92
93
94 /* exception/error super class */
95
96 extern char *string_java_lang_Throwable;
97
98
99 /* specify some exception strings for code generation */
100
101 extern char *string_java_lang_ArithmeticException;
102 extern char *string_java_lang_ArithmeticException_message;
103 extern char *string_java_lang_ArrayIndexOutOfBoundsException;
104 extern char *string_java_lang_ArrayStoreException;
105 extern char *string_java_lang_ClassCastException;
106 extern char *string_java_lang_ClassNotFoundException;
107 extern char *string_java_lang_CloneNotSupportedException;
108 extern char *string_java_lang_Exception;
109 extern char *string_java_lang_IllegalArgumentException;
110 extern char *string_java_lang_IllegalMonitorStateException;
111 extern char *string_java_lang_NegativeArraySizeException;
112 extern char *string_java_lang_NoSuchFieldException;
113 extern char *string_java_lang_NoSuchMethodException;
114 extern char *string_java_lang_NullPointerException;
115
116
117 /* specify some error strings for code generation */
118
119 extern char *string_java_lang_AbstractMethodError;
120 extern char *string_java_lang_ClassCircularityError;
121 extern char *string_java_lang_ClassFormatError;
122 extern char *string_java_lang_Error;
123 extern char *string_java_lang_ExceptionInInitializerError;
124 extern char *string_java_lang_IncompatibleClassChangeError;
125 extern char *string_java_lang_InternalError;
126 extern char *string_java_lang_LinkageError;
127 extern char *string_java_lang_NoClassDefFoundError;
128 extern char *string_java_lang_NoSuchFieldError;
129 extern char *string_java_lang_NoSuchMethodError;
130 extern char *string_java_lang_OutOfMemoryError;
131 extern char *string_java_lang_VerifyError;
132
133
134 /* the system classloader object */
135 extern java_lang_ClassLoader *SystemClassLoader;
136
137 /* for raising exceptions from native methods */
138 /* extern java_objectheader* exceptionptr; */
139
140 /* javastring-hashtable */
141 extern hashtable string_hash; 
142
143 /* load, link and compile exceptions used in the system */
144 void init_system_exceptions();
145 void compile_all_class_methods(classinfo *c);
146
147 /* exception throwing functions */
148 void throw_exception();
149 void throw_exception_exit();
150
151 void throw_main_exception();
152 void throw_main_exception_exit();
153
154 void throw_cacao_exception_exit(char *exception, char *message);
155
156 /* initialize new exceptions */
157 java_objectheader *new_exception(char *classname);
158 java_objectheader *new_exception_message(char *classname, char *message);
159 java_objectheader *new_exception_throwable(char *classname, java_lang_Throwable *cause);
160 java_objectheader *new_exception_utfmessage(char *classname, utf *message);
161 java_objectheader *new_exception_javastring(char *classname, java_lang_String *message);
162 java_objectheader *new_exception_int(char *classname, s4 i);
163
164 void use_class_as_object(classinfo *c);
165
166 /* load classes required for native methods */
167 void native_loadclasses();
168
169 /* set searchpath for classfiles */
170 void native_setclasspath(char *path);
171
172 /* find native function */
173 functionptr native_findfunction(utf *cname, utf *mname, 
174                                                                 utf *desc, bool isstatic);
175
176 /* creates a new object of type java/lang/String from a utf-text */
177 /*  java_objectheader *javastring_new(utf *text); */
178 java_lang_String *javastring_new(utf *text);
179
180 /* creates a new object of type java/lang/String from a c-string */
181 /*  java_objectheader *javastring_new_char(char *text); */
182 java_lang_String *javastring_new_char(char *text);
183
184 /* make c-string from a javastring (debugging) */
185 char *javastring_tochar(java_objectheader *s);
186
187 /* create new object on the heap and call the initializer */
188 java_objectheader *native_new_and_init(classinfo *c);
189
190 /* create new object on the heap and call the initializer 
191    mainly used for exceptions with a message */
192 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s);
193
194 /* create new object on the heap and call the initializer 
195    mainly used for exceptions with an index */
196 java_objectheader *native_new_and_init_int(classinfo *c, s4 i);
197
198 /* create new object on the heap and call the initializer 
199    mainly used for exceptions with cause */
200 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t);
201
202 /* add property to system-property vector */
203 void attach_property(char *name, char *value);
204
205 /* correct vftbl-entries of javastring-hash */
206 void stringtable_update();
207
208
209 /* make utf symbol from javastring */
210 utf *javastring_toutf(struct java_lang_String *string, bool isclassname);
211
212 /* make utf symbol from u2 array */
213 utf *utf_new_u2(u2 *unicodedata, u4 unicodelength, bool isclassname);
214
215 /* determine utf length in bytes of a u2 array */
216 u4 u2_utflength(u2 *text, u4 u2_length);
217
218 /* create systemclassloader object and initialize its instance fields  */
219 void init_systemclassloader();
220
221 /* search 'classinfo'-structure for a field with the specified name */
222 fieldinfo *class_findfield_approx(classinfo *c, utf *name);
223 s4 class_findfield_index_approx(classinfo *c, utf *name);
224
225 /* creates a new javastring with the text of the utf-symbol */
226 java_objectheader *literalstring_new(utf *u);
227
228 /* creates a new javastring with the text of the u2-array */
229 java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
230                                                                         bool copymode);
231
232 /* dispose a javastring */
233 void literalstring_free(java_objectheader*);
234
235 void copy_vftbl(vftbl_t **dest, vftbl_t *src);
236
237 utf *create_methodsig(java_objectarray* types, char *retType);
238 classinfo *get_type(char **utf_ptr,char *desc_end, bool skip);
239 java_objectarray* get_parametertypes(methodinfo *m);
240 java_objectarray* get_exceptiontypes(methodinfo *m);
241 classinfo *get_returntype(methodinfo *m);
242
243
244
245
246 java_objectarray *builtin_asm_createclasscontextarray(classinfo **end,classinfo **start);
247 java_lang_ClassLoader *builtin_asm_getclassloader(classinfo **end,classinfo **start);
248
249 #endif /* _NATIVE_H */
250
251
252 /*
253  * These are local overrides for various environment variables in Emacs.
254  * Please do not remove this and leave it at the end of the file, where
255  * Emacs will automagically detect them.
256  * ---------------------------------------------------------------------
257  * Local variables:
258  * mode: c
259  * indent-tabs-mode: t
260  * c-basic-offset: 4
261  * tab-width: 4
262  * End:
263  */