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