GNU header update.
[cacao.git] / src / native / native.h
1 /* native/native.h - table of native functions
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
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 1735 2004-12-07 14:33:27Z twisti $
30
31 */
32
33
34 #ifndef _NATIVE_H
35 #define _NATIVE_H
36
37
38 #include "native/jni.h"
39 #include "native/include/java_lang_String.h"
40 #include "native/include/java_lang_ClassLoader.h"
41 #include "native/include/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 extern classinfo *class_java_lang_Class;
69 extern classinfo *class_java_lang_VMClass;
70 extern classinfo *class_java_lang_System;
71 extern classinfo *class_java_lang_ClassLoader;
72 extern classinfo *class_java_lang_Double;
73 extern classinfo *class_java_lang_Float;
74 extern classinfo *class_java_lang_Long;
75 extern classinfo *class_java_lang_Byte;
76 extern classinfo *class_java_lang_Short;
77 extern classinfo *class_java_lang_Boolean;
78 extern classinfo *class_java_lang_Void;
79 extern classinfo *class_java_lang_Character;
80 extern classinfo *class_java_lang_Integer;
81
82
83 /* the system classloader object */
84 extern java_lang_ClassLoader *SystemClassLoader;
85
86 /* for raising exceptions from native methods */
87 /* extern java_objectheader* exceptionptr; */
88
89 /* javastring-hashtable */
90 extern hashtable string_hash; 
91
92 void use_class_as_object(classinfo *c);
93
94 /* load classes required for native methods */
95 void native_loadclasses();
96
97 /* find native function */
98 functionptr native_findfunction(utf *cname, utf *mname, 
99                                                                 utf *desc, bool isstatic);
100
101 /* creates a new object of type java/lang/String from a utf-text */
102 /*  java_objectheader *javastring_new(utf *text); */
103 java_lang_String *javastring_new(utf *text);
104
105 /* creates a new object of type java/lang/String from a c-string */
106 /*  java_objectheader *javastring_new_char(char *text); */
107 java_lang_String *javastring_new_char(char *text);
108
109 /* make c-string from a javastring (debugging) */
110 char *javastring_tochar(java_objectheader *s);
111
112 /* create new object on the heap and call the initializer */
113 java_objectheader *native_new_and_init(classinfo *c);
114
115 /* create new object on the heap and call the initializer 
116    mainly used for exceptions with a message */
117 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s);
118
119 /* create new object on the heap and call the initializer 
120    mainly used for exceptions with an index */
121 java_objectheader *native_new_and_init_int(classinfo *c, s4 i);
122
123 /* create new object on the heap and call the initializer 
124    mainly used for exceptions with cause */
125 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t);
126
127 /* add property to temporary property list -- located in nat/VMRuntime.c */
128 void create_property(char *key, char *value);
129
130 /* correct vftbl-entries of javastring-hash */
131 void stringtable_update();
132
133
134 /* make utf symbol from javastring */
135 utf *javastring_toutf(java_lang_String *string, bool isclassname);
136
137 /* make utf symbol from u2 array */
138 utf *utf_new_u2(u2 *unicodedata, u4 unicodelength, bool isclassname);
139
140 /* determine utf length in bytes of a u2 array */
141 u4 u2_utflength(u2 *text, u4 u2_length);
142
143 /* create systemclassloader object and initialize its instance fields  */
144 void init_systemclassloader();
145
146 /* search 'classinfo'-structure for a field with the specified name */
147 fieldinfo *class_findfield_approx(classinfo *c, utf *name);
148 s4 class_findfield_index_approx(classinfo *c, utf *name);
149
150 /* creates a new javastring with the text of the utf-symbol */
151 java_objectheader *literalstring_new(utf *u);
152
153 /* creates a new javastring with the text of the u2-array */
154 java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
155                                                                         bool copymode);
156
157 /* dispose a javastring */
158 void literalstring_free(java_objectheader*);
159
160 void copy_vftbl(vftbl_t **dest, vftbl_t *src);
161
162 utf *create_methodsig(java_objectarray* types, char *retType);
163 classinfo *get_type(char **utf_ptr,char *desc_end, bool skip);
164 java_objectarray* get_parametertypes(methodinfo *m);
165 java_objectarray* get_exceptiontypes(methodinfo *m);
166 classinfo *get_returntype(methodinfo *m);
167
168
169
170
171 java_objectarray *builtin_asm_createclasscontextarray(classinfo **end,classinfo **start);
172 java_lang_ClassLoader *builtin_asm_getclassloader(classinfo **end,classinfo **start);
173
174 /*----- For Static Analysis of Natives by parseRT -----*/
175
176 /*---------- global variables ---------------------------*/
177 typedef struct classMeth classMeth;
178 typedef struct nativeCall   nativeCall;
179 typedef struct methodCall   methodCall;
180 typedef struct nativeMethod nativeMethod;
181
182 typedef struct nativeCompCall   nativeCompCall;
183 typedef struct methodCompCall   methodCompCall;
184 typedef struct nativeCompMethod nativeCompMethod;
185
186 /*---------- Define Constants ---------------------------*/
187 #define MAXCALLS 30 
188
189 struct classMeth {
190         int i_class;
191         int j_method;
192         int methCnt;
193 };
194
195 struct  methodCall{
196         char *classname;
197         char *methodname;
198         char *descriptor;
199 };
200
201 struct  nativeMethod  {
202         char *methodname;
203         char *descriptor;
204         struct methodCall methodCalls[MAXCALLS];
205 };
206
207
208 struct nativeCall {
209         char *classname;
210         struct nativeMethod methods[MAXCALLS];
211         int methCnt;
212         int callCnt[MAXCALLS];
213 };
214
215
216 struct methodCompCall {
217         utf *classname;
218         utf *methodname;
219         utf *descriptor;
220 };
221
222
223 struct nativeCompMethod {
224         utf *methodname;
225         utf *descriptor;
226         struct methodCompCall methodCalls[MAXCALLS];
227 };
228
229
230 struct nativeCompCall {
231         utf *classname;
232         struct nativeCompMethod methods[MAXCALLS];
233         int methCnt;
234         int callCnt[MAXCALLS];
235 };
236
237
238 bool natcall2utf(bool);
239 void printNativeCall(nativeCall);
240 void markNativeMethodsRT(utf *, utf* , utf* ); 
241
242 #endif /* _NATIVE_H */
243
244
245 /*
246  * These are local overrides for various environment variables in Emacs.
247  * Please do not remove this and leave it at the end of the file, where
248  * Emacs will automagically detect them.
249  * ---------------------------------------------------------------------
250  * Local variables:
251  * mode: c
252  * indent-tabs-mode: t
253  * c-basic-offset: 4
254  * tab-width: 4
255  * End:
256  */