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