New source tree.
[cacao.git] / src / native / native.h
1 /* native/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 1621 2004-11-30 13:06:55Z 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 #endif /* _NATIVE_H */
175
176
177 /*
178  * These are local overrides for various environment variables in Emacs.
179  * Please do not remove this and leave it at the end of the file, where
180  * Emacs will automagically detect them.
181  * ---------------------------------------------------------------------
182  * Local variables:
183  * mode: c
184  * indent-tabs-mode: t
185  * c-basic-offset: 4
186  * tab-width: 4
187  * End:
188  */