- new_exception functions for dynamic exceptions
[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 934 2004-03-05 23:20:53Z 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
42
43 /* searchpath for classfiles */
44 extern char *classpath;
45
46 extern classinfo *class_java_lang_Class;
47 extern classinfo *class_java_lang_VMClass;
48 extern methodinfo *method_vmclass_init;
49 /* extern classinfo *class_java_lang_Cloneable=0; */ /* now in global.h */
50 extern classinfo *class_java_lang_CloneNotSupportedException;
51 extern classinfo *class_java_lang_System;
52 extern classinfo *class_java_lang_ClassLoader;
53 extern classinfo *class_java_lang_NoClassDefFoundError;
54 extern classinfo *class_java_lang_ClassNotFoundException;
55 extern classinfo *class_java_lang_LinkageError;
56 extern classinfo *class_java_lang_InstantiationException;
57 extern classinfo *class_java_lang_NoSuchMethodError;   
58 extern classinfo *class_java_lang_NoSuchFieldError;
59 extern classinfo *class_java_lang_ClassFormatError;
60 extern classinfo *class_java_lang_IllegalArgumentException;
61 extern classinfo *class_java_lang_ArrayIndexOutOfBoundsException;
62 extern classinfo *class_java_lang_NoSuchFieldException;
63 extern classinfo *class_java_io_SyncFailedException;
64 extern classinfo *class_java_io_IOException;
65 extern classinfo *class_java_io_FileNotFoundException;
66 extern classinfo *class_java_io_UnixFileSystem;
67 extern classinfo *class_java_security_PrivilegedActionException;
68 extern classinfo *class_java_net_UnknownHostException;
69 extern classinfo *class_java_net_SocketException;
70 extern classinfo *class_java_lang_NoSuchMethodException;
71 extern classinfo *class_java_lang_Double;
72 extern classinfo *class_java_lang_Float;
73 extern classinfo *class_java_lang_Long;
74 extern classinfo *class_java_lang_Byte;
75 extern classinfo *class_java_lang_Short;
76 extern classinfo *class_java_lang_Boolean;
77 extern classinfo *class_java_lang_Void;
78 extern classinfo *class_java_lang_Character;
79 extern classinfo *class_java_lang_Integer;
80
81 /* specify some exception strings for code generation */
82 extern char *string_java_lang_NoClassDefFoundError;
83 extern char *string_java_lang_LinkageError;
84 extern char *string_java_lang_ArrayIndexOutOfBoundsException;
85 extern char *string_java_lang_NegativeArraySizeException;
86 extern char *string_java_lang_ClassCastException;
87 extern char *string_java_lang_ArithmeticException;
88 extern char *string_java_lang_ArithmeticException_message;
89 extern char *string_java_lang_NullPointerException;
90 extern char *string_java_lang_ArrayStoreException;
91
92 /* the system classloader object */
93 extern struct java_lang_ClassLoader *SystemClassLoader;
94
95 /* for raising exceptions from native methods */
96 /* extern java_objectheader* exceptionptr; */
97
98 /* javastring-hashtable */
99 extern hashtable string_hash; 
100
101
102 /* throw classnotfoundexcetion with detail message */
103 void throw_noclassdeffounderror_message(utf* classname);
104
105 /* throw linkageerror with detail message */
106 void throw_linkageerror_message(utf* classname);
107
108 /* throw exception with detail message */
109 java_objectheader *new_exception(char *classname);
110 java_objectheader *new_exception_message(char *classname, char *message);
111 java_objectheader *new_exception_int(char *classname, s4 i);
112
113 void use_class_as_object(classinfo *c);
114
115 /* load classes required for native methods */
116 void native_loadclasses();
117
118 /* set searchpath for classfiles */
119 void native_setclasspath(char *path);
120
121 /* find native function */
122 functionptr native_findfunction(utf *cname, utf *mname, 
123                                                                 utf *desc, bool isstatic);
124
125 /* creates a new object of type java/lang/String from a utf-text */
126 /*  java_objectheader *javastring_new(utf *text); */
127 java_lang_String *javastring_new(utf *text);
128
129 /* creates a new object of type java/lang/String from a c-string */
130 /*  java_objectheader *javastring_new_char(char *text); */
131 java_lang_String *javastring_new_char(char *text);
132
133 /* make c-string from a javastring (debugging) */
134 char *javastring_tochar(java_objectheader *s);
135
136 /* create new object on the heap and call the initializer */
137 java_objectheader *native_new_and_init(classinfo *c);
138
139 /* 
140    create new object on the heap and call the initializer 
141    mainly used for exceptions with a message
142 */
143 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s);
144
145 /* add property to system-property vector */
146 void attach_property(char *name, char *value);
147
148 /* correct vftbl-entries of javastring-hash */
149 void stringtable_update();
150
151
152 /* make utf symbol from javastring */
153 utf *javastring_toutf(struct java_lang_String *string, bool isclassname);
154
155 /* make utf symbol from u2 array */
156 utf *utf_new_u2(u2 *unicodedata, u4 unicodelength, bool isclassname);
157
158 /* determine utf length in bytes of a u2 array */
159 u4 u2_utflength(u2 *text, u4 u2_length);
160
161 /* create systemclassloader object and initialize its instance fields  */
162 void init_systemclassloader();
163
164 /* search 'classinfo'-structure for a field with the specified name */
165 fieldinfo *class_findfield_approx(classinfo *c, utf *name);
166 s4 class_findfield_index_approx(classinfo *c, utf *name);
167
168 /* creates a new javastring with the text of the utf-symbol */
169 java_objectheader *literalstring_new(utf *u);
170
171 /* creates a new javastring with the text of the u2-array */
172 java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
173                                                                         bool copymode);
174
175 /* dispose a javastring */
176 void literalstring_free(java_objectheader*);
177
178 void systemclassloader_addlibname(java_objectheader *o);
179 void systemclassloader_addlibrary(java_objectheader *o);
180
181 void copy_vftbl(vftbl **dest, vftbl *src);
182
183 utf *create_methodsig(java_objectarray* types, char *retType);
184 classinfo *get_type(char **utf_ptr,char *desc_end, bool skip);
185 java_objectarray* get_parametertypes(methodinfo *m);
186 java_objectarray* get_exceptiontypes(methodinfo *m);
187 classinfo *get_returntype(methodinfo *m);
188
189
190
191
192 java_objectarray *builtin_asm_createclasscontextarray(classinfo **end,classinfo **start);
193 java_lang_ClassLoader *builtin_asm_getclassloader(classinfo **end,classinfo **start);
194
195 #endif /* _NATIVE_H */
196
197
198 /*
199  * These are local overrides for various environment variables in Emacs.
200  * Please do not remove this and leave it at the end of the file, where
201  * Emacs will automagically detect them.
202  * ---------------------------------------------------------------------
203  * Local variables:
204  * mode: c
205  * indent-tabs-mode: t
206  * c-basic-offset: 4
207  * tab-width: 4
208  * End:
209  */