b60111dc4ed9885b1bb27f4e080d006bd30f0e68
[cacao.git] / src / vm / utf8.h
1 /* src/vm/utf8.h - utf8 string functions
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _UTF_H
27 #define _UTF_H
28
29 /* forward typedefs ***********************************************************/
30
31 typedef struct utf utf;
32
33 #include "config.h"
34
35 #include <stdio.h>
36
37 #include "vm/types.h"
38
39 #include "vm/global.h"
40
41
42 /* data structure for utf8 symbols ********************************************/
43
44 struct utf {
45         utf  *hashlink;                     /* link for external hash chain       */
46         s4    blength;                      /* text length in bytes               */
47         char *text;                         /* pointer to text                    */
48 };
49
50 /* to determine the end of utf strings */
51
52 #define UTF_END(u)    ((char *) u->text + u->blength)
53
54
55 /* utf-symbols for pointer comparison of frequently used strings **************/
56
57 extern utf *utf_java_lang_Object;
58
59 extern utf *utf_java_lang_Class;
60 extern utf *utf_java_lang_ClassLoader;
61 extern utf *utf_java_lang_Cloneable;
62 extern utf *utf_java_lang_SecurityManager;
63 extern utf *utf_java_lang_String;
64 extern utf *utf_java_lang_ThreadGroup;
65 extern utf *utf_java_lang_ref_SoftReference;
66 extern utf *utf_java_lang_ref_WeakReference;
67 extern utf *utf_java_lang_ref_PhantomReference;
68 extern utf *utf_java_io_Serializable;
69
70 extern utf *utf_java_lang_Throwable;
71 extern utf *utf_java_lang_Error;
72
73 extern utf *utf_java_lang_AbstractMethodError;
74 extern utf *utf_java_lang_ClassCircularityError;
75 extern utf *utf_java_lang_ClassFormatError;
76 extern utf *utf_java_lang_ExceptionInInitializerError;
77 extern utf *utf_java_lang_IncompatibleClassChangeError;
78 extern utf *utf_java_lang_InstantiationError;
79 extern utf *utf_java_lang_InternalError;
80 extern utf *utf_java_lang_LinkageError;
81 extern utf *utf_java_lang_NoClassDefFoundError;
82 extern utf *utf_java_lang_NoSuchFieldError;
83 extern utf *utf_java_lang_NoSuchMethodError;
84 extern utf *utf_java_lang_OutOfMemoryError;
85 extern utf *utf_java_lang_UnsatisfiedLinkError;
86 extern utf *utf_java_lang_UnsupportedClassVersionError;
87 extern utf *utf_java_lang_VerifyError;
88 extern utf *utf_java_lang_VirtualMachineError;
89
90 extern utf *utf_java_lang_Exception;
91
92 extern utf *utf_java_lang_ArithmeticException;
93 extern utf *utf_java_lang_ArrayIndexOutOfBoundsException;
94 extern utf *utf_java_lang_ArrayStoreException;
95 extern utf *utf_java_lang_ClassCastException;
96 extern utf *utf_java_lang_ClassNotFoundException;
97 extern utf *utf_java_lang_CloneNotSupportedException;
98 extern utf *utf_java_lang_IllegalAccessException;
99 extern utf *utf_java_lang_IllegalArgumentException;
100 extern utf *utf_java_lang_IllegalMonitorStateException;
101 extern utf *utf_java_lang_InstantiationException;
102 extern utf *utf_java_lang_InterruptedException;
103 extern utf *utf_java_lang_NegativeArraySizeException;
104 extern utf *utf_java_lang_NullPointerException;
105 extern utf *utf_java_lang_RuntimeException;
106 extern utf *utf_java_lang_StringIndexOutOfBoundsException;
107
108 extern utf *utf_java_lang_reflect_InvocationTargetException;
109
110 extern utf *utf_java_security_PrivilegedActionException;
111
112 #if defined(ENABLE_JAVASE)
113 extern utf* utf_java_lang_Void;
114 #endif
115
116 extern utf* utf_java_lang_Boolean;
117 extern utf* utf_java_lang_Byte;
118 extern utf* utf_java_lang_Character;
119 extern utf* utf_java_lang_Short;
120 extern utf* utf_java_lang_Integer;
121 extern utf* utf_java_lang_Long;
122 extern utf* utf_java_lang_Float;
123 extern utf* utf_java_lang_Double;
124
125 #if defined(ENABLE_JAVASE)
126 extern utf *utf_java_lang_StackTraceElement;
127 extern utf *utf_java_lang_reflect_Constructor;
128 extern utf *utf_java_lang_reflect_Field;
129 extern utf *utf_java_lang_reflect_Method;
130
131 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
132 extern utf *utf_java_lang_reflect_VMConstructor;
133 extern utf *utf_java_lang_reflect_VMField;
134 extern utf *utf_java_lang_reflect_VMMethod;
135 # endif
136
137 extern utf *utf_java_util_Vector;
138 #endif
139
140 extern utf *utf_InnerClasses;
141 extern utf *utf_ConstantValue;
142 extern utf *utf_Code;
143 extern utf *utf_Exceptions;
144 extern utf *utf_LineNumberTable;
145 extern utf *utf_SourceFile;
146
147 #if defined(ENABLE_JAVASE)
148 extern utf *utf_EnclosingMethod;
149 extern utf *utf_Signature;
150 extern utf *utf_StackMapTable;
151
152 # if defined(ENABLE_JVMTI)
153 extern utf *utf_LocalVariableTable;
154 # endif
155
156 # if defined(ENABLE_ANNOTATIONS)
157 extern utf *utf_RuntimeVisibleAnnotations;
158 extern utf *utf_RuntimeInvisibleAnnotations;
159 extern utf *utf_RuntimeVisibleParameterAnnotations;
160 extern utf *utf_RuntimeInvisibleParameterAnnotations;
161 extern utf *utf_AnnotationDefault;
162 # endif
163 #endif
164
165 extern utf *utf_init;
166 extern utf *utf_clinit;
167 extern utf *utf_clone;
168 extern utf *utf_finalize;
169 extern utf *utf_invoke;
170 extern utf *utf_main;
171 extern utf *utf_run;
172
173 extern utf *utf_add;
174 extern utf *utf_dispatch;
175 extern utf *utf_remove;
176 extern utf *utf_addThread;
177 extern utf *utf_removeThread;
178 extern utf *utf_put;
179 extern utf *utf_get;
180 extern utf *utf_uncaughtException;
181 extern utf *utf_value;
182
183 extern utf *utf_fillInStackTrace;
184 extern utf *utf_findNative;
185 extern utf *utf_getSystemClassLoader;
186 extern utf *utf_initCause;
187 extern utf *utf_loadClass;
188 extern utf *utf_loadClassInternal;
189 extern utf *utf_printStackTrace;
190
191 extern utf *utf_division_by_zero;
192
193 extern utf *utf_Z;
194 extern utf *utf_B;
195 extern utf *utf_C;
196 extern utf *utf_S;
197 extern utf *utf_I;
198 extern utf *utf_J;
199 extern utf *utf_F;
200 extern utf *utf_D;
201
202 extern utf *utf_void__void;
203 extern utf *utf_boolean__void;
204 extern utf *utf_byte__void;
205 extern utf *utf_char__void;
206 extern utf *utf_short__void;
207 extern utf *utf_int__void;
208 extern utf *utf_long__void;
209 extern utf *utf_float__void;
210 extern utf *utf_double__void;
211
212 extern utf *utf_void__java_lang_ClassLoader;
213 extern utf *utf_void__java_lang_Object;
214 extern utf *utf_void__java_lang_Throwable;
215 extern utf *utf_java_lang_ClassLoader_java_lang_String__J;
216 extern utf *utf_java_lang_Exception__V;
217 extern utf *utf_java_lang_Object__java_lang_Object;
218 extern utf *utf_java_lang_String__void;
219 extern utf *utf_java_lang_String__java_lang_Class;
220 extern utf *utf_java_lang_Thread__V;
221 extern utf *utf_java_lang_Thread_java_lang_Throwable__V;
222 extern utf *utf_Ljava_lang_ThreadGroup_Ljava_lang_String__V;
223 extern utf *utf_java_lang_Throwable__void;
224 extern utf *utf_java_lang_Throwable__java_lang_Throwable;
225
226 extern utf *utf_not_named_yet;
227 extern utf *utf_null;
228 extern utf *array_packagename;
229
230
231 /* function prototypes ********************************************************/
232
233 #ifdef __cplusplus
234 extern "C" {
235 #endif
236
237 /* initialize the utf8 subsystem */
238 void utf8_init(void);
239
240 u4 utf_hashkey(const char *text, u4 length);
241 u4 utf_full_hashkey(const char *text, u4 length);
242
243 /* determine hashkey of a unicode-symbol */
244 u4 unicode_hashkey(u2 *text, u2 length);
245
246 /* create new utf-symbol */
247 utf *utf_new(const char *text, u2 length);
248
249 /* make utf symbol from u2 array */
250 utf *utf_new_u2(u2 *unicodedata, u4 unicodelength, bool isclassname);
251
252 utf *utf_new_char(const char *text);
253 utf *utf_new_char_classname(const char *text);
254
255 /* get number of bytes */
256 u4 utf_bytes(utf *u);
257
258 /* get next unicode character of a utf-string */
259 u2 utf_nextu2(char **utf);
260
261 /* get (number of) unicode characters of a utf string (safe) */
262 s4 utf8_safe_number_of_u2s(const char *text, s4 nbytes);
263 void utf8_safe_convert_to_u2s(const char *text, s4 nbytes, u2 *buffer);
264
265 /* get (number of) unicode characters of a utf string (UNSAFE!) */
266 u4 utf_get_number_of_u2s(utf *u);
267 u4 utf_get_number_of_u2s_for_buffer(const char *buffer, u4 blength);
268
269 /* determine utf length in bytes of a u2 array */
270 u4 u2_utflength(u2 *text, u4 u2_length);
271
272 void utf_copy(char *buffer, utf *u);
273 void utf_cat(char *buffer, utf *u);
274 void utf_copy_classname(char *buffer, utf *u);
275 void utf_cat_classname(char *buffer, utf *u);
276
277 /* write utf symbol to file/buffer */
278 void utf_display_printable_ascii(utf *u);
279 void utf_display_printable_ascii_classname(utf *u);
280
281 void utf_sprint_convert_to_latin1(char *buffer, utf *u);
282 void utf_sprint_convert_to_latin1_classname(char *buffer, utf *u);
283
284 void utf_strcat_convert_to_latin1(char *buffer, utf *u);
285 void utf_strcat_convert_to_latin1_classname(char *buffer, utf *u);
286
287 void utf_fprint_printable_ascii(FILE *file, utf *u);
288 void utf_fprint_printable_ascii_classname(FILE *file, utf *u);
289
290 /* check if a UTF-8 string is valid */
291 bool is_valid_utf(char *utf_ptr, char *end_pos);
292
293 /* check if a UTF-8 string may be used as a class/field/method name */
294 bool is_valid_name(char *utf_ptr, char *end_pos);
295 bool is_valid_name_utf(utf *u);
296
297 /* show utf-table */
298 void utf_show(void);
299
300 #ifdef __cplusplus
301 }
302 #endif
303
304 #endif /* _UTF_H */
305
306
307 /*
308  * These are local overrides for various environment variables in Emacs.
309  * Please do not remove this and leave it at the end of the file, where
310  * Emacs will automagically detect them.
311  * ---------------------------------------------------------------------
312  * Local variables:
313  * mode: c
314  * indent-tabs-mode: t
315  * c-basic-offset: 4
316  * tab-width: 4
317  * End:
318  * vim:noexpandtab:sw=4:ts=4:
319  */