]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Java language support routines for GDB, the GNU debugger. |
b6ba6518 | 2 | Copyright 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
c906108c | 3 | |
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
c906108c | 10 | |
c5aa993b JM |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
c906108c | 15 | |
c5aa993b JM |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "symtab.h" | |
23 | #include "gdbtypes.h" | |
24 | #include "expression.h" | |
25 | #include "parser-defs.h" | |
26 | #include "language.h" | |
27 | #include "gdbtypes.h" | |
28 | #include "symtab.h" | |
29 | #include "symfile.h" | |
30 | #include "objfiles.h" | |
31 | #include "gdb_string.h" | |
32 | #include "value.h" | |
33 | #include "c-lang.h" | |
34 | #include "jv-lang.h" | |
35 | #include "gdbcore.h" | |
36 | #include <ctype.h> | |
37 | ||
38 | struct type *java_int_type; | |
39 | struct type *java_byte_type; | |
40 | struct type *java_short_type; | |
41 | struct type *java_long_type; | |
42 | struct type *java_boolean_type; | |
43 | struct type *java_char_type; | |
44 | struct type *java_float_type; | |
45 | struct type *java_double_type; | |
46 | struct type *java_void_type; | |
47 | ||
392a587b JM |
48 | /* Local functions */ |
49 | ||
a14ed312 | 50 | extern void _initialize_java_language (void); |
392a587b | 51 | |
a14ed312 KB |
52 | static int java_demangled_signature_length (char *); |
53 | static void java_demangled_signature_copy (char *, char *); | |
c906108c | 54 | |
a14ed312 | 55 | static struct symtab *get_java_class_symtab (void); |
75c9979e AC |
56 | static char *get_java_utf8_name (struct obstack *obstack, struct value *name); |
57 | static int java_class_is_primitive (struct value *clas); | |
a14ed312 | 58 | static struct type *java_lookup_type (char *signature); |
75c9979e | 59 | static struct value *java_value_string (char *ptr, int len); |
392a587b | 60 | |
d9fcf2fb | 61 | static void java_emit_char (int c, struct ui_file * stream, int quoter); |
c906108c SS |
62 | |
63 | /* This objfile contains symtabs that have been dynamically created | |
64 | to record dynamically loaded Java classes and dynamically | |
65 | compiled java methods. */ | |
66 | ||
67 | static struct objfile *dynamics_objfile = NULL; | |
68 | ||
75c9979e | 69 | static struct type *java_link_class_type (struct type *, struct value *); |
c906108c SS |
70 | |
71 | static struct objfile * | |
fba45db2 | 72 | get_dynamics_objfile (void) |
c906108c SS |
73 | { |
74 | if (dynamics_objfile == NULL) | |
75 | { | |
2df3850c | 76 | dynamics_objfile = allocate_objfile (NULL, 0); |
c906108c SS |
77 | } |
78 | return dynamics_objfile; | |
79 | } | |
80 | ||
81 | #if 1 | |
82 | /* symtab contains classes read from the inferior. */ | |
83 | ||
84 | static struct symtab *class_symtab = NULL; | |
85 | ||
86 | /* Maximum number of class in class_symtab before relocation is needed. */ | |
87 | ||
88 | static int class_symtab_space; | |
89 | ||
392a587b | 90 | static struct symtab * |
fba45db2 | 91 | get_java_class_symtab (void) |
c906108c SS |
92 | { |
93 | if (class_symtab == NULL) | |
94 | { | |
c5aa993b | 95 | struct objfile *objfile = get_dynamics_objfile (); |
c906108c SS |
96 | struct blockvector *bv; |
97 | struct block *bl; | |
98 | class_symtab = allocate_symtab ("<java-classes>", objfile); | |
99 | class_symtab->language = language_java; | |
100 | bv = (struct blockvector *) | |
101 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct blockvector)); | |
102 | BLOCKVECTOR_NBLOCKS (bv) = 1; | |
103 | BLOCKVECTOR (class_symtab) = bv; | |
104 | ||
105 | /* Allocate dummy STATIC_BLOCK. */ | |
106 | bl = (struct block *) | |
107 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct block)); | |
108 | BLOCK_NSYMS (bl) = 0; | |
109 | BLOCK_START (bl) = 0; | |
110 | BLOCK_END (bl) = 0; | |
111 | BLOCK_FUNCTION (bl) = NULL; | |
112 | BLOCK_SUPERBLOCK (bl) = NULL; | |
113 | BLOCK_GCC_COMPILED (bl) = 0; | |
114 | BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl; | |
115 | ||
116 | /* Allocate GLOBAL_BLOCK. This has to be relocatable. */ | |
117 | class_symtab_space = 128; | |
753edfef AC |
118 | bl = xmmalloc (objfile->md, |
119 | sizeof (struct block) | |
120 | + ((class_symtab_space - 1) * sizeof (struct symbol *))); | |
c906108c SS |
121 | *bl = *BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); |
122 | BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl; | |
123 | class_symtab->free_ptr = (char *) bl; | |
124 | } | |
125 | return class_symtab; | |
126 | } | |
127 | ||
128 | static void | |
fba45db2 | 129 | add_class_symtab_symbol (struct symbol *sym) |
c906108c SS |
130 | { |
131 | struct symtab *symtab = get_java_class_symtab (); | |
132 | struct blockvector *bv = BLOCKVECTOR (symtab); | |
133 | struct block *bl = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
134 | if (BLOCK_NSYMS (bl) >= class_symtab_space) | |
135 | { | |
136 | /* Need to re-allocate. */ | |
137 | class_symtab_space *= 2; | |
4c178295 AC |
138 | bl = xmrealloc (symtab->objfile->md, bl, |
139 | sizeof (struct block) | |
140 | + ((class_symtab_space - 1) * sizeof (struct symbol *))); | |
c906108c SS |
141 | class_symtab->free_ptr = (char *) bl; |
142 | BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl; | |
143 | } | |
c5aa993b | 144 | |
c906108c SS |
145 | BLOCK_SYM (bl, BLOCK_NSYMS (bl)) = sym; |
146 | BLOCK_NSYMS (bl) = BLOCK_NSYMS (bl) + 1; | |
147 | } | |
148 | ||
a14ed312 | 149 | static struct symbol *add_class_symbol (struct type *type, CORE_ADDR addr); |
c906108c SS |
150 | |
151 | static struct symbol * | |
fba45db2 | 152 | add_class_symbol (struct type *type, CORE_ADDR addr) |
c906108c SS |
153 | { |
154 | struct symbol *sym; | |
155 | sym = (struct symbol *) | |
156 | obstack_alloc (&dynamics_objfile->symbol_obstack, sizeof (struct symbol)); | |
157 | memset (sym, 0, sizeof (struct symbol)); | |
158 | SYMBOL_LANGUAGE (sym) = language_java; | |
159 | SYMBOL_NAME (sym) = TYPE_TAG_NAME (type); | |
160 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
c5aa993b | 161 | /* SYMBOL_VALUE (sym) = valu; */ |
c906108c SS |
162 | SYMBOL_TYPE (sym) = type; |
163 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; | |
164 | SYMBOL_VALUE_ADDRESS (sym) = addr; | |
165 | return sym; | |
166 | } | |
167 | #endif | |
168 | ||
169 | struct type * | |
fba45db2 | 170 | java_lookup_class (char *name) |
c906108c SS |
171 | { |
172 | struct symbol *sym; | |
173 | sym = lookup_symbol (name, expression_context_block, STRUCT_NAMESPACE, | |
174 | (int *) 0, (struct symtab **) NULL); | |
175 | if (sym != NULL) | |
176 | return SYMBOL_TYPE (sym); | |
177 | #if 0 | |
178 | CORE_ADDR addr; | |
179 | if (called from parser) | |
180 | { | |
181 | call lookup_class (or similar) in inferior; | |
c5aa993b JM |
182 | if not |
183 | found: | |
c906108c SS |
184 | return NULL; |
185 | addr = found in inferior; | |
186 | } | |
187 | else | |
188 | addr = 0; | |
189 | struct type *type; | |
190 | type = alloc_type (objfile); | |
191 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
192 | INIT_CPLUS_SPECIFIC (type); | |
c5aa993b | 193 | TYPE_TAG_NAME (type) = obsavestring (name, strlen (name), &objfile->type_obstack); |
c906108c SS |
194 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; |
195 | TYPE ? = addr; | |
196 | return type; | |
197 | #else | |
198 | /* FIXME - should search inferior's symbol table. */ | |
199 | return NULL; | |
200 | #endif | |
201 | } | |
202 | ||
203 | /* Return a nul-terminated string (allocated on OBSTACK) for | |
204 | a name given by NAME (which has type Utf8Const*). */ | |
205 | ||
206 | char * | |
75c9979e | 207 | get_java_utf8_name (struct obstack *obstack, struct value *name) |
c906108c SS |
208 | { |
209 | char *chrs; | |
75c9979e | 210 | struct value *temp = name; |
c906108c SS |
211 | int name_length; |
212 | CORE_ADDR data_addr; | |
213 | temp = value_struct_elt (&temp, NULL, "length", NULL, "structure"); | |
214 | name_length = (int) value_as_long (temp); | |
215 | data_addr = VALUE_ADDRESS (temp) + VALUE_OFFSET (temp) | |
216 | + TYPE_LENGTH (VALUE_TYPE (temp)); | |
c5aa993b JM |
217 | chrs = obstack_alloc (obstack, name_length + 1); |
218 | chrs[name_length] = '\0'; | |
d4b2399a | 219 | read_memory (data_addr, chrs, name_length); |
c906108c SS |
220 | return chrs; |
221 | } | |
222 | ||
75c9979e AC |
223 | struct value * |
224 | java_class_from_object (struct value *obj_val) | |
c906108c SS |
225 | { |
226 | /* This is all rather inefficient, since the offsets of vtable and | |
227 | class are fixed. FIXME */ | |
75c9979e | 228 | struct value *vtable_val; |
c906108c SS |
229 | |
230 | if (TYPE_CODE (VALUE_TYPE (obj_val)) == TYPE_CODE_PTR | |
231 | && TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (obj_val))) == 0) | |
232 | obj_val = value_at (get_java_object_type (), | |
1aa20aa8 | 233 | value_as_address (obj_val), NULL); |
c906108c SS |
234 | |
235 | vtable_val = value_struct_elt (&obj_val, NULL, "vtable", NULL, "structure"); | |
236 | return value_struct_elt (&vtable_val, NULL, "class", NULL, "structure"); | |
237 | } | |
238 | ||
239 | /* Check if CLASS_IS_PRIMITIVE(value of clas): */ | |
392a587b | 240 | static int |
75c9979e | 241 | java_class_is_primitive (struct value *clas) |
c906108c | 242 | { |
75c9979e | 243 | struct value *vtable = value_struct_elt (&clas, NULL, "vtable", NULL, "struct"); |
1aa20aa8 | 244 | CORE_ADDR i = value_as_address (vtable); |
c906108c SS |
245 | return (int) (i & 0x7fffffff) == (int) 0x7fffffff; |
246 | } | |
247 | ||
248 | /* Read a GCJ Class object, and generated a gdb (TYPE_CODE_STRUCT) type. */ | |
249 | ||
250 | struct type * | |
75c9979e | 251 | type_from_class (struct value *clas) |
c906108c SS |
252 | { |
253 | struct type *type; | |
254 | char *name; | |
75c9979e | 255 | struct value *temp; |
c906108c | 256 | struct objfile *objfile; |
75c9979e | 257 | struct value *utf8_name; |
c906108c SS |
258 | char *nptr; |
259 | CORE_ADDR addr; | |
260 | struct block *bl; | |
261 | int i; | |
262 | int is_array = 0; | |
263 | ||
264 | type = check_typedef (VALUE_TYPE (clas)); | |
265 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
266 | { | |
267 | if (value_logical_not (clas)) | |
268 | return NULL; | |
269 | clas = value_ind (clas); | |
270 | } | |
271 | addr = VALUE_ADDRESS (clas) + VALUE_OFFSET (clas); | |
272 | ||
273 | #if 0 | |
274 | get_java_class_symtab (); | |
275 | bl = BLOCKVECTOR_BLOCK (BLOCKVECTOR (class_symtab), GLOBAL_BLOCK); | |
c5aa993b | 276 | for (i = BLOCK_NSYMS (bl); --i >= 0;) |
c906108c SS |
277 | { |
278 | struct symbol *sym = BLOCK_SYM (bl, i); | |
279 | if (SYMBOL_VALUE_ADDRESS (sym) == addr) | |
280 | return SYMBOL_TYPE (sym); | |
281 | } | |
282 | #endif | |
283 | ||
c5aa993b | 284 | objfile = get_dynamics_objfile (); |
c906108c SS |
285 | if (java_class_is_primitive (clas)) |
286 | { | |
75c9979e | 287 | struct value *sig; |
c906108c SS |
288 | temp = clas; |
289 | sig = value_struct_elt (&temp, NULL, "method_count", NULL, "structure"); | |
290 | return java_primitive_type (value_as_long (sig)); | |
291 | } | |
292 | ||
293 | /* Get Class name. */ | |
294 | /* if clasloader non-null, prepend loader address. FIXME */ | |
295 | temp = clas; | |
296 | utf8_name = value_struct_elt (&temp, NULL, "name", NULL, "structure"); | |
297 | name = get_java_utf8_name (&objfile->type_obstack, utf8_name); | |
c5aa993b | 298 | for (nptr = name; *nptr != 0; nptr++) |
c906108c SS |
299 | { |
300 | if (*nptr == '/') | |
301 | *nptr = '.'; | |
302 | } | |
303 | ||
304 | type = java_lookup_class (name); | |
305 | if (type != NULL) | |
306 | return type; | |
307 | ||
308 | type = alloc_type (objfile); | |
309 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
310 | INIT_CPLUS_SPECIFIC (type); | |
311 | ||
312 | if (name[0] == '[') | |
313 | { | |
314 | char *signature = name; | |
315 | int namelen = java_demangled_signature_length (signature); | |
316 | if (namelen > strlen (name)) | |
c5aa993b | 317 | name = obstack_alloc (&objfile->type_obstack, namelen + 1); |
c906108c SS |
318 | java_demangled_signature_copy (name, signature); |
319 | name[namelen] = '\0'; | |
320 | is_array = 1; | |
321 | temp = clas; | |
322 | /* Set array element type. */ | |
323 | temp = value_struct_elt (&temp, NULL, "methods", NULL, "structure"); | |
324 | VALUE_TYPE (temp) = lookup_pointer_type (VALUE_TYPE (clas)); | |
325 | TYPE_TARGET_TYPE (type) = type_from_class (temp); | |
326 | } | |
327 | ||
328 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
329 | TYPE_TAG_NAME (type) = name; | |
330 | ||
331 | add_class_symtab_symbol (add_class_symbol (type, addr)); | |
332 | return java_link_class_type (type, clas); | |
333 | } | |
334 | ||
c5aa993b | 335 | /* Fill in class TYPE with data from the CLAS value. */ |
c906108c SS |
336 | |
337 | struct type * | |
75c9979e | 338 | java_link_class_type (struct type *type, struct value *clas) |
c906108c | 339 | { |
75c9979e | 340 | struct value *temp; |
c906108c SS |
341 | char *unqualified_name; |
342 | char *name = TYPE_TAG_NAME (type); | |
343 | int ninterfaces, nfields, nmethods; | |
344 | int type_is_object = 0; | |
345 | struct fn_field *fn_fields; | |
346 | struct fn_fieldlist *fn_fieldlists; | |
75c9979e AC |
347 | struct value *fields; |
348 | struct value *methods; | |
c65ecaf3 AC |
349 | struct value *method = NULL; |
350 | struct value *field = NULL; | |
c906108c | 351 | int i, j; |
c5aa993b | 352 | struct objfile *objfile = get_dynamics_objfile (); |
c906108c SS |
353 | struct type *tsuper; |
354 | ||
355 | unqualified_name = strrchr (name, '.'); | |
356 | if (unqualified_name == NULL) | |
357 | unqualified_name = name; | |
358 | ||
359 | temp = clas; | |
360 | temp = value_struct_elt (&temp, NULL, "superclass", NULL, "structure"); | |
361 | if (name != NULL && strcmp (name, "java.lang.Object") == 0) | |
362 | { | |
363 | tsuper = get_java_object_type (); | |
364 | if (tsuper && TYPE_CODE (tsuper) == TYPE_CODE_PTR) | |
365 | tsuper = TYPE_TARGET_TYPE (tsuper); | |
366 | type_is_object = 1; | |
367 | } | |
368 | else | |
369 | tsuper = type_from_class (temp); | |
370 | ||
371 | #if 1 | |
372 | ninterfaces = 0; | |
373 | #else | |
374 | temp = clas; | |
375 | ninterfaces = value_as_long (value_struct_elt (&temp, NULL, "interface_len", NULL, "structure")); | |
376 | #endif | |
377 | TYPE_N_BASECLASSES (type) = (tsuper == NULL ? 0 : 1) + ninterfaces; | |
378 | temp = clas; | |
379 | nfields = value_as_long (value_struct_elt (&temp, NULL, "field_count", NULL, "structure")); | |
380 | nfields += TYPE_N_BASECLASSES (type); | |
c5aa993b | 381 | nfields++; /* Add one for dummy "class" field. */ |
c906108c SS |
382 | TYPE_NFIELDS (type) = nfields; |
383 | TYPE_FIELDS (type) = (struct field *) | |
384 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
385 | ||
386 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
387 | ||
388 | TYPE_FIELD_PRIVATE_BITS (type) = | |
389 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
390 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
391 | ||
392 | TYPE_FIELD_PROTECTED_BITS (type) = | |
393 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
394 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
395 | ||
396 | TYPE_FIELD_IGNORE_BITS (type) = | |
397 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
398 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
399 | ||
400 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) | |
401 | TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type))); | |
402 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type)); | |
403 | ||
404 | if (tsuper != NULL) | |
405 | { | |
406 | TYPE_BASECLASS (type, 0) = tsuper; | |
407 | if (type_is_object) | |
408 | SET_TYPE_FIELD_PRIVATE (type, 0); | |
409 | } | |
410 | ||
411 | i = strlen (name); | |
c5aa993b | 412 | if (i > 2 && name[i - 1] == ']' && tsuper != NULL) |
c906108c SS |
413 | { |
414 | /* FIXME */ | |
c5aa993b | 415 | TYPE_LENGTH (type) = TYPE_LENGTH (tsuper) + 4; /* size with "length" */ |
c906108c SS |
416 | } |
417 | else | |
418 | { | |
419 | temp = clas; | |
420 | temp = value_struct_elt (&temp, NULL, "size_in_bytes", NULL, "structure"); | |
421 | TYPE_LENGTH (type) = value_as_long (temp); | |
422 | } | |
423 | ||
424 | fields = NULL; | |
c5aa993b | 425 | nfields--; /* First set up dummy "class" field. */ |
c906108c SS |
426 | SET_FIELD_PHYSADDR (TYPE_FIELD (type, nfields), |
427 | VALUE_ADDRESS (clas) + VALUE_OFFSET (clas)); | |
428 | TYPE_FIELD_NAME (type, nfields) = "class"; | |
429 | TYPE_FIELD_TYPE (type, nfields) = VALUE_TYPE (clas); | |
430 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b JM |
431 | |
432 | for (i = TYPE_N_BASECLASSES (type); i < nfields; i++) | |
c906108c SS |
433 | { |
434 | int accflags; | |
435 | int boffset; | |
436 | if (fields == NULL) | |
437 | { | |
438 | temp = clas; | |
439 | fields = value_struct_elt (&temp, NULL, "fields", NULL, "structure"); | |
440 | field = value_ind (fields); | |
441 | } | |
442 | else | |
c5aa993b | 443 | { /* Re-use field value for next field. */ |
c906108c SS |
444 | VALUE_ADDRESS (field) += TYPE_LENGTH (VALUE_TYPE (field)); |
445 | VALUE_LAZY (field) = 1; | |
446 | } | |
447 | temp = field; | |
448 | temp = value_struct_elt (&temp, NULL, "name", NULL, "structure"); | |
449 | TYPE_FIELD_NAME (type, i) = | |
450 | get_java_utf8_name (&objfile->type_obstack, temp); | |
451 | temp = field; | |
452 | accflags = value_as_long (value_struct_elt (&temp, NULL, "accflags", | |
453 | NULL, "structure")); | |
454 | temp = field; | |
455 | temp = value_struct_elt (&temp, NULL, "info", NULL, "structure"); | |
456 | boffset = value_as_long (value_struct_elt (&temp, NULL, "boffset", | |
c5aa993b JM |
457 | NULL, "structure")); |
458 | if (accflags & 0x0001) /* public access */ | |
c906108c SS |
459 | { |
460 | /* ??? */ | |
461 | } | |
c5aa993b | 462 | if (accflags & 0x0002) /* private access */ |
c906108c SS |
463 | { |
464 | SET_TYPE_FIELD_PRIVATE (type, i); | |
465 | } | |
c5aa993b | 466 | if (accflags & 0x0004) /* protected access */ |
c906108c SS |
467 | { |
468 | SET_TYPE_FIELD_PROTECTED (type, i); | |
469 | } | |
c5aa993b JM |
470 | if (accflags & 0x0008) /* ACC_STATIC */ |
471 | SET_FIELD_PHYSADDR (TYPE_FIELD (type, i), boffset); | |
c906108c SS |
472 | else |
473 | TYPE_FIELD_BITPOS (type, i) = 8 * boffset; | |
c5aa993b | 474 | if (accflags & 0x8000) /* FIELD_UNRESOLVED_FLAG */ |
c906108c | 475 | { |
c5aa993b | 476 | TYPE_FIELD_TYPE (type, i) = get_java_object_type (); /* FIXME */ |
c906108c SS |
477 | } |
478 | else | |
479 | { | |
480 | struct type *ftype; | |
481 | temp = field; | |
482 | temp = value_struct_elt (&temp, NULL, "type", NULL, "structure"); | |
483 | ftype = type_from_class (temp); | |
484 | if (TYPE_CODE (ftype) == TYPE_CODE_STRUCT) | |
485 | ftype = lookup_pointer_type (ftype); | |
486 | TYPE_FIELD_TYPE (type, i) = ftype; | |
487 | } | |
488 | } | |
489 | ||
490 | temp = clas; | |
491 | nmethods = value_as_long (value_struct_elt (&temp, NULL, "method_count", | |
492 | NULL, "structure")); | |
493 | TYPE_NFN_FIELDS_TOTAL (type) = nmethods; | |
494 | j = nmethods * sizeof (struct fn_field); | |
c5aa993b | 495 | fn_fields = (struct fn_field *) |
c906108c SS |
496 | obstack_alloc (&dynamics_objfile->symbol_obstack, j); |
497 | memset (fn_fields, 0, j); | |
c5aa993b | 498 | fn_fieldlists = (struct fn_fieldlist *) |
c906108c SS |
499 | alloca (nmethods * sizeof (struct fn_fieldlist)); |
500 | ||
501 | methods = NULL; | |
c5aa993b | 502 | for (i = 0; i < nmethods; i++) |
c906108c SS |
503 | { |
504 | char *mname; | |
505 | int k; | |
506 | if (methods == NULL) | |
507 | { | |
508 | temp = clas; | |
509 | methods = value_struct_elt (&temp, NULL, "methods", NULL, "structure"); | |
510 | method = value_ind (methods); | |
511 | } | |
512 | else | |
c5aa993b | 513 | { /* Re-use method value for next method. */ |
c906108c SS |
514 | VALUE_ADDRESS (method) += TYPE_LENGTH (VALUE_TYPE (method)); |
515 | VALUE_LAZY (method) = 1; | |
516 | } | |
517 | ||
518 | /* Get method name. */ | |
519 | temp = method; | |
520 | temp = value_struct_elt (&temp, NULL, "name", NULL, "structure"); | |
521 | mname = get_java_utf8_name (&objfile->type_obstack, temp); | |
522 | if (strcmp (mname, "<init>") == 0) | |
523 | mname = unqualified_name; | |
524 | ||
525 | /* Check for an existing method with the same name. | |
526 | * This makes building the fn_fieldslists an O(nmethods**2) | |
527 | * operation. That could be using hashing, but I doubt it | |
528 | * is worth it. Note that we do maintain the order of methods | |
529 | * in the inferior's Method table (as long as that is grouped | |
530 | * by method name), which I think is desirable. --PB */ | |
c5aa993b | 531 | for (k = 0, j = TYPE_NFN_FIELDS (type);;) |
c906108c SS |
532 | { |
533 | if (--j < 0) | |
c5aa993b JM |
534 | { /* No match - new method name. */ |
535 | j = TYPE_NFN_FIELDS (type)++; | |
c906108c SS |
536 | fn_fieldlists[j].name = mname; |
537 | fn_fieldlists[j].length = 1; | |
538 | fn_fieldlists[j].fn_fields = &fn_fields[i]; | |
539 | k = i; | |
540 | break; | |
541 | } | |
542 | if (strcmp (mname, fn_fieldlists[j].name) == 0) | |
c5aa993b | 543 | { /* Found an existing method with the same name. */ |
c906108c SS |
544 | int l; |
545 | if (mname != unqualified_name) | |
546 | obstack_free (&objfile->type_obstack, mname); | |
547 | mname = fn_fieldlists[j].name; | |
548 | fn_fieldlists[j].length++; | |
c5aa993b | 549 | k = i - k; /* Index of new slot. */ |
c906108c | 550 | /* Shift intervening fn_fields (between k and i) down. */ |
c5aa993b JM |
551 | for (l = i; l > k; l--) |
552 | fn_fields[l] = fn_fields[l - 1]; | |
553 | for (l = TYPE_NFN_FIELDS (type); --l > j;) | |
c906108c SS |
554 | fn_fieldlists[l].fn_fields++; |
555 | break; | |
556 | } | |
557 | k += fn_fieldlists[j].length; | |
558 | } | |
559 | fn_fields[k].physname = ""; | |
560 | fn_fields[k].is_stub = 1; | |
c5aa993b | 561 | fn_fields[k].type = make_function_type (java_void_type, NULL); /* FIXME */ |
c906108c SS |
562 | TYPE_CODE (fn_fields[k].type) = TYPE_CODE_METHOD; |
563 | } | |
564 | ||
c5aa993b JM |
565 | j = TYPE_NFN_FIELDS (type) * sizeof (struct fn_fieldlist); |
566 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
c906108c SS |
567 | obstack_alloc (&dynamics_objfile->symbol_obstack, j); |
568 | memcpy (TYPE_FN_FIELDLISTS (type), fn_fieldlists, j); | |
c5aa993b | 569 | |
c906108c SS |
570 | return type; |
571 | } | |
572 | ||
573 | static struct type *java_object_type; | |
574 | ||
575 | struct type * | |
fba45db2 | 576 | get_java_object_type (void) |
c906108c SS |
577 | { |
578 | if (java_object_type == NULL) | |
579 | { | |
580 | struct symbol *sym; | |
581 | sym = lookup_symbol ("java.lang.Object", NULL, STRUCT_NAMESPACE, | |
582 | (int *) 0, (struct symtab **) NULL); | |
583 | if (sym == NULL) | |
584 | error ("cannot find java.lang.Object"); | |
585 | java_object_type = SYMBOL_TYPE (sym); | |
586 | } | |
587 | return java_object_type; | |
588 | } | |
589 | ||
590 | int | |
fba45db2 | 591 | get_java_object_header_size (void) |
c906108c SS |
592 | { |
593 | struct type *objtype = get_java_object_type (); | |
594 | if (objtype == NULL) | |
595 | return (2 * TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
596 | else | |
597 | return TYPE_LENGTH (objtype); | |
598 | } | |
599 | ||
600 | int | |
fba45db2 | 601 | is_object_type (struct type *type) |
c906108c SS |
602 | { |
603 | CHECK_TYPEDEF (type); | |
604 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
605 | { | |
606 | struct type *ttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
607 | char *name; | |
608 | if (TYPE_CODE (ttype) != TYPE_CODE_STRUCT) | |
609 | return 0; | |
610 | while (TYPE_N_BASECLASSES (ttype) > 0) | |
611 | ttype = TYPE_BASECLASS (ttype, 0); | |
612 | name = TYPE_TAG_NAME (ttype); | |
613 | if (name != NULL && strcmp (name, "java.lang.Object") == 0) | |
614 | return 1; | |
c5aa993b | 615 | name = TYPE_NFIELDS (ttype) > 0 ? TYPE_FIELD_NAME (ttype, 0) : (char *) 0; |
c906108c SS |
616 | if (name != NULL && strcmp (name, "vtable") == 0) |
617 | { | |
618 | if (java_object_type == NULL) | |
619 | java_object_type = type; | |
620 | return 1; | |
621 | } | |
622 | } | |
623 | return 0; | |
624 | } | |
625 | ||
626 | struct type * | |
fba45db2 | 627 | java_primitive_type (int signature) |
c906108c SS |
628 | { |
629 | switch (signature) | |
630 | { | |
c5aa993b JM |
631 | case 'B': |
632 | return java_byte_type; | |
633 | case 'S': | |
634 | return java_short_type; | |
635 | case 'I': | |
636 | return java_int_type; | |
637 | case 'J': | |
638 | return java_long_type; | |
639 | case 'Z': | |
640 | return java_boolean_type; | |
641 | case 'C': | |
642 | return java_char_type; | |
643 | case 'F': | |
644 | return java_float_type; | |
645 | case 'D': | |
646 | return java_double_type; | |
647 | case 'V': | |
648 | return java_void_type; | |
c906108c SS |
649 | } |
650 | error ("unknown signature '%c' for primitive type", (char) signature); | |
651 | } | |
652 | ||
653 | /* If name[0 .. namelen-1] is the name of a primitive Java type, | |
654 | return that type. Otherwise, return NULL. */ | |
655 | ||
656 | struct type * | |
fba45db2 | 657 | java_primitive_type_from_name (char *name, int namelen) |
c906108c SS |
658 | { |
659 | switch (name[0]) | |
660 | { | |
661 | case 'b': | |
662 | if (namelen == 4 && memcmp (name, "byte", 4) == 0) | |
663 | return java_byte_type; | |
664 | if (namelen == 7 && memcmp (name, "boolean", 7) == 0) | |
665 | return java_boolean_type; | |
666 | break; | |
667 | case 'c': | |
668 | if (namelen == 4 && memcmp (name, "char", 4) == 0) | |
669 | return java_char_type; | |
670 | case 'd': | |
671 | if (namelen == 6 && memcmp (name, "double", 6) == 0) | |
672 | return java_double_type; | |
673 | break; | |
674 | case 'f': | |
675 | if (namelen == 5 && memcmp (name, "float", 5) == 0) | |
676 | return java_float_type; | |
677 | break; | |
678 | case 'i': | |
679 | if (namelen == 3 && memcmp (name, "int", 3) == 0) | |
680 | return java_int_type; | |
681 | break; | |
682 | case 'l': | |
683 | if (namelen == 4 && memcmp (name, "long", 4) == 0) | |
684 | return java_long_type; | |
685 | break; | |
686 | case 's': | |
687 | if (namelen == 5 && memcmp (name, "short", 5) == 0) | |
688 | return java_short_type; | |
689 | break; | |
690 | case 'v': | |
691 | if (namelen == 4 && memcmp (name, "void", 4) == 0) | |
692 | return java_void_type; | |
693 | break; | |
694 | } | |
695 | return NULL; | |
696 | } | |
697 | ||
698 | /* Return the length (in bytes) of demangled name of the Java type | |
699 | signature string SIGNATURE. */ | |
700 | ||
701 | static int | |
fba45db2 | 702 | java_demangled_signature_length (char *signature) |
c906108c SS |
703 | { |
704 | int array = 0; | |
c5aa993b JM |
705 | for (; *signature == '['; signature++) |
706 | array += 2; /* Two chars for "[]". */ | |
c906108c SS |
707 | switch (signature[0]) |
708 | { | |
709 | case 'L': | |
710 | /* Subtract 2 for 'L' and ';'. */ | |
711 | return strlen (signature) - 2 + array; | |
712 | default: | |
713 | return strlen (TYPE_NAME (java_primitive_type (signature[0]))) + array; | |
714 | } | |
715 | } | |
716 | ||
717 | /* Demangle the Java type signature SIGNATURE, leaving the result in RESULT. */ | |
718 | ||
719 | static void | |
fba45db2 | 720 | java_demangled_signature_copy (char *result, char *signature) |
c906108c SS |
721 | { |
722 | int array = 0; | |
723 | char *ptr; | |
724 | int i; | |
725 | while (*signature == '[') | |
726 | { | |
727 | array++; | |
728 | signature++; | |
729 | } | |
730 | switch (signature[0]) | |
731 | { | |
732 | case 'L': | |
733 | /* Subtract 2 for 'L' and ';', but add 1 for final nul. */ | |
734 | signature++; | |
735 | ptr = result; | |
c5aa993b | 736 | for (; *signature != ';' && *signature != '\0'; signature++) |
c906108c SS |
737 | { |
738 | if (*signature == '/') | |
739 | *ptr++ = '.'; | |
740 | else | |
741 | *ptr++ = *signature; | |
742 | } | |
743 | break; | |
744 | default: | |
745 | ptr = TYPE_NAME (java_primitive_type (signature[0])); | |
746 | i = strlen (ptr); | |
747 | strcpy (result, ptr); | |
748 | ptr = result + i; | |
749 | break; | |
750 | } | |
751 | while (--array >= 0) | |
752 | { | |
753 | *ptr++ = '['; | |
754 | *ptr++ = ']'; | |
755 | } | |
756 | } | |
757 | ||
758 | /* Return the demangled name of the Java type signature string SIGNATURE, | |
759 | as a freshly allocated copy. */ | |
760 | ||
761 | char * | |
fba45db2 | 762 | java_demangle_type_signature (char *signature) |
c906108c SS |
763 | { |
764 | int length = java_demangled_signature_length (signature); | |
765 | char *result = xmalloc (length + 1); | |
766 | java_demangled_signature_copy (result, signature); | |
767 | result[length] = '\0'; | |
768 | return result; | |
769 | } | |
770 | ||
771 | struct type * | |
fba45db2 | 772 | java_lookup_type (char *signature) |
c906108c SS |
773 | { |
774 | switch (signature[0]) | |
775 | { | |
776 | case 'L': | |
777 | case '[': | |
778 | error ("java_lookup_type not fully implemented"); | |
779 | default: | |
780 | return java_primitive_type (signature[0]); | |
781 | } | |
782 | } | |
783 | ||
784 | /* Return the type of TYPE followed by DIMS pairs of [ ]. | |
785 | If DIMS == 0, TYPE is returned. */ | |
786 | ||
787 | struct type * | |
fba45db2 | 788 | java_array_type (struct type *type, int dims) |
c906108c SS |
789 | { |
790 | struct type *range_type; | |
791 | ||
792 | while (dims-- > 0) | |
793 | { | |
794 | range_type = create_range_type (NULL, builtin_type_int, 0, 0); | |
795 | /* FIXME This is bogus! Java arrays are not gdb arrays! */ | |
796 | type = create_array_type (NULL, type, range_type); | |
797 | } | |
798 | ||
799 | return type; | |
800 | } | |
801 | ||
802 | /* Create a Java string in the inferior from a (Utf8) literal. */ | |
803 | ||
75c9979e | 804 | static struct value * |
fba45db2 | 805 | java_value_string (char *ptr, int len) |
c906108c | 806 | { |
c5aa993b | 807 | error ("not implemented - java_value_string"); /* FIXME */ |
c906108c SS |
808 | } |
809 | ||
810 | /* Print the character C on STREAM as part of the contents of a literal | |
811 | string whose delimiter is QUOTER. Note that that format for printing | |
812 | characters and strings is language specific. */ | |
813 | ||
814 | static void | |
fba45db2 | 815 | java_emit_char (int c, struct ui_file *stream, int quoter) |
c906108c SS |
816 | { |
817 | switch (c) | |
818 | { | |
819 | case '\\': | |
820 | case '\'': | |
821 | fprintf_filtered (stream, "\\%c", c); | |
822 | break; | |
823 | case '\b': | |
824 | fputs_filtered ("\\b", stream); | |
825 | break; | |
826 | case '\t': | |
827 | fputs_filtered ("\\t", stream); | |
828 | break; | |
829 | case '\n': | |
830 | fputs_filtered ("\\n", stream); | |
831 | break; | |
832 | case '\f': | |
833 | fputs_filtered ("\\f", stream); | |
834 | break; | |
835 | case '\r': | |
836 | fputs_filtered ("\\r", stream); | |
837 | break; | |
838 | default: | |
839 | if (isprint (c)) | |
840 | fputc_filtered (c, stream); | |
841 | else | |
842 | fprintf_filtered (stream, "\\u%.4x", (unsigned int) c); | |
843 | break; | |
844 | } | |
845 | } | |
846 | ||
75c9979e | 847 | static struct value * |
fba45db2 KB |
848 | evaluate_subexp_java (struct type *expect_type, register struct expression *exp, |
849 | register int *pos, enum noside noside) | |
c906108c SS |
850 | { |
851 | int pc = *pos; | |
852 | int i; | |
853 | char *name; | |
854 | enum exp_opcode op = exp->elts[*pos].opcode; | |
75c9979e AC |
855 | struct value *arg1; |
856 | struct value *arg2; | |
c906108c SS |
857 | struct type *type; |
858 | switch (op) | |
859 | { | |
860 | case UNOP_IND: | |
861 | if (noside == EVAL_SKIP) | |
862 | goto standard; | |
863 | (*pos)++; | |
864 | arg1 = evaluate_subexp_java (NULL_TYPE, exp, pos, EVAL_NORMAL); | |
865 | if (is_object_type (VALUE_TYPE (arg1))) | |
866 | { | |
867 | struct type *type; | |
868 | ||
869 | type = type_from_class (java_class_from_object (arg1)); | |
870 | arg1 = value_cast (lookup_pointer_type (type), arg1); | |
871 | } | |
872 | if (noside == EVAL_SKIP) | |
873 | goto nosideret; | |
874 | return value_ind (arg1); | |
875 | ||
876 | case BINOP_SUBSCRIPT: | |
877 | (*pos)++; | |
878 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
879 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
880 | if (noside == EVAL_SKIP) | |
881 | goto nosideret; | |
882 | /* If the user attempts to subscript something that is not an | |
c5aa993b JM |
883 | array or pointer type (like a plain int variable for example), |
884 | then report this as an error. */ | |
885 | ||
c906108c SS |
886 | COERCE_REF (arg1); |
887 | type = check_typedef (VALUE_TYPE (arg1)); | |
888 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
889 | type = check_typedef (TYPE_TARGET_TYPE (type)); | |
890 | name = TYPE_NAME (type); | |
891 | if (name == NULL) | |
892 | name = TYPE_TAG_NAME (type); | |
893 | i = name == NULL ? 0 : strlen (name); | |
894 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
c5aa993b | 895 | && i > 2 && name[i - 1] == ']') |
c906108c SS |
896 | { |
897 | CORE_ADDR address; | |
898 | long length, index; | |
899 | struct type *el_type; | |
900 | char buf4[4]; | |
901 | ||
75c9979e AC |
902 | struct value *clas = java_class_from_object (arg1); |
903 | struct value *temp = clas; | |
c906108c SS |
904 | /* Get CLASS_ELEMENT_TYPE of the array type. */ |
905 | temp = value_struct_elt (&temp, NULL, "methods", | |
c5aa993b | 906 | NULL, "structure"); |
c906108c SS |
907 | VALUE_TYPE (temp) = VALUE_TYPE (clas); |
908 | el_type = type_from_class (temp); | |
909 | if (TYPE_CODE (el_type) == TYPE_CODE_STRUCT) | |
910 | el_type = lookup_pointer_type (el_type); | |
911 | ||
912 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
913 | return value_zero (el_type, VALUE_LVAL (arg1)); | |
1aa20aa8 | 914 | address = value_as_address (arg1); |
c906108c SS |
915 | address += JAVA_OBJECT_SIZE; |
916 | read_memory (address, buf4, 4); | |
917 | length = (long) extract_signed_integer (buf4, 4); | |
918 | index = (long) value_as_long (arg2); | |
919 | if (index >= length || index < 0) | |
920 | error ("array index (%ld) out of bounds (length: %ld)", | |
921 | index, length); | |
922 | address = (address + 4) + index * TYPE_LENGTH (el_type); | |
923 | return value_at (el_type, address, NULL); | |
924 | } | |
925 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
926 | { | |
927 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
928 | return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1)); | |
929 | else | |
930 | return value_subscript (arg1, arg2); | |
931 | } | |
932 | if (name) | |
933 | error ("cannot subscript something of type `%s'", name); | |
934 | else | |
935 | error ("cannot subscript requested type"); | |
936 | ||
937 | case OP_STRING: | |
938 | (*pos)++; | |
939 | i = longest_to_int (exp->elts[pc + 1].longconst); | |
940 | (*pos) += 3 + BYTES_TO_EXP_ELEM (i + 1); | |
941 | if (noside == EVAL_SKIP) | |
942 | goto nosideret; | |
943 | return java_value_string (&exp->elts[pc + 2].string, i); | |
944 | ||
945 | case STRUCTOP_STRUCT: | |
946 | arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside); | |
947 | /* Convert object field (such as TYPE.class) to reference. */ | |
948 | if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_STRUCT) | |
949 | arg1 = value_addr (arg1); | |
950 | return arg1; | |
951 | default: | |
952 | break; | |
953 | } | |
954 | standard: | |
955 | return evaluate_subexp_standard (expect_type, exp, pos, noside); | |
c5aa993b | 956 | nosideret: |
c906108c SS |
957 | return value_from_longest (builtin_type_long, (LONGEST) 1); |
958 | } | |
959 | ||
960 | static struct type * | |
fba45db2 | 961 | java_create_fundamental_type (struct objfile *objfile, int typeid) |
c906108c SS |
962 | { |
963 | switch (typeid) | |
964 | { | |
c5aa993b JM |
965 | case FT_VOID: |
966 | return java_void_type; | |
967 | case FT_BOOLEAN: | |
968 | return java_boolean_type; | |
969 | case FT_CHAR: | |
970 | return java_char_type; | |
971 | case FT_FLOAT: | |
972 | return java_float_type; | |
973 | case FT_DBL_PREC_FLOAT: | |
974 | return java_double_type; | |
975 | case FT_BYTE: | |
976 | case FT_SIGNED_CHAR: | |
977 | return java_byte_type; | |
978 | case FT_SHORT: | |
979 | case FT_SIGNED_SHORT: | |
980 | return java_short_type; | |
981 | case FT_INTEGER: | |
982 | case FT_SIGNED_INTEGER: | |
983 | return java_int_type; | |
984 | case FT_LONG: | |
985 | case FT_SIGNED_LONG: | |
986 | return java_long_type; | |
c906108c SS |
987 | } |
988 | return c_create_fundamental_type (objfile, typeid); | |
989 | } | |
990 | ||
991 | /* Table mapping opcodes into strings for printing operators | |
992 | and precedences of the operators. */ | |
993 | ||
994 | const struct op_print java_op_print_tab[] = | |
c5aa993b JM |
995 | { |
996 | {",", BINOP_COMMA, PREC_COMMA, 0}, | |
997 | {"=", BINOP_ASSIGN, PREC_ASSIGN, 1}, | |
998 | {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0}, | |
999 | {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0}, | |
1000 | {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0}, | |
1001 | {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0}, | |
1002 | {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0}, | |
1003 | {"==", BINOP_EQUAL, PREC_EQUAL, 0}, | |
1004 | {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0}, | |
1005 | {"<=", BINOP_LEQ, PREC_ORDER, 0}, | |
1006 | {">=", BINOP_GEQ, PREC_ORDER, 0}, | |
1007 | {">", BINOP_GTR, PREC_ORDER, 0}, | |
1008 | {"<", BINOP_LESS, PREC_ORDER, 0}, | |
1009 | {">>", BINOP_RSH, PREC_SHIFT, 0}, | |
1010 | {"<<", BINOP_LSH, PREC_SHIFT, 0}, | |
c906108c | 1011 | #if 0 |
c5aa993b | 1012 | {">>>", BINOP_ ? ? ?, PREC_SHIFT, 0}, |
c906108c | 1013 | #endif |
c5aa993b JM |
1014 | {"+", BINOP_ADD, PREC_ADD, 0}, |
1015 | {"-", BINOP_SUB, PREC_ADD, 0}, | |
1016 | {"*", BINOP_MUL, PREC_MUL, 0}, | |
1017 | {"/", BINOP_DIV, PREC_MUL, 0}, | |
1018 | {"%", BINOP_REM, PREC_MUL, 0}, | |
1019 | {"-", UNOP_NEG, PREC_PREFIX, 0}, | |
1020 | {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0}, | |
1021 | {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0}, | |
1022 | {"*", UNOP_IND, PREC_PREFIX, 0}, | |
c906108c | 1023 | #if 0 |
c5aa993b | 1024 | {"instanceof", ? ? ?, ? ? ?, 0}, |
c906108c | 1025 | #endif |
c5aa993b JM |
1026 | {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0}, |
1027 | {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0}, | |
1028 | {NULL, 0, 0, 0} | |
c906108c SS |
1029 | }; |
1030 | ||
c5aa993b JM |
1031 | const struct language_defn java_language_defn = |
1032 | { | |
1033 | "java", /* Language name */ | |
c906108c SS |
1034 | language_java, |
1035 | c_builtin_types, | |
1036 | range_check_off, | |
1037 | type_check_off, | |
63872f9d | 1038 | case_sensitive_on, |
c906108c SS |
1039 | java_parse, |
1040 | java_error, | |
1041 | evaluate_subexp_java, | |
1042 | c_printchar, /* Print a character constant */ | |
1043 | c_printstr, /* Function to print string constant */ | |
1044 | java_emit_char, /* Function to print a single character */ | |
1045 | java_create_fundamental_type, /* Create fundamental type in this language */ | |
1046 | java_print_type, /* Print a type using appropriate syntax */ | |
1047 | java_val_print, /* Print a value using appropriate syntax */ | |
1048 | java_value_print, /* Print a top-level value */ | |
c5aa993b JM |
1049 | {"", "", "", ""}, /* Binary format info */ |
1050 | {"0%lo", "0", "o", ""}, /* Octal format info */ | |
1051 | {"%ld", "", "d", ""}, /* Decimal format info */ | |
1052 | {"0x%lx", "0x", "x", ""}, /* Hex format info */ | |
c906108c SS |
1053 | java_op_print_tab, /* expression operators for printing */ |
1054 | 0, /* not c-style arrays */ | |
1055 | 0, /* String lower bound */ | |
c5aa993b | 1056 | &builtin_type_char, /* Type of string elements */ |
c906108c SS |
1057 | LANG_MAGIC |
1058 | }; | |
1059 | ||
1060 | void | |
fba45db2 | 1061 | _initialize_java_language (void) |
c906108c SS |
1062 | { |
1063 | ||
c5aa993b JM |
1064 | java_int_type = init_type (TYPE_CODE_INT, 4, 0, "int", NULL); |
1065 | java_short_type = init_type (TYPE_CODE_INT, 2, 0, "short", NULL); | |
1066 | java_long_type = init_type (TYPE_CODE_INT, 8, 0, "long", NULL); | |
1067 | java_byte_type = init_type (TYPE_CODE_INT, 1, 0, "byte", NULL); | |
1068 | java_boolean_type = init_type (TYPE_CODE_BOOL, 1, 0, "boolean", NULL); | |
1069 | java_char_type = init_type (TYPE_CODE_CHAR, 2, TYPE_FLAG_UNSIGNED, "char", NULL); | |
1070 | java_float_type = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL); | |
1071 | java_double_type = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL); | |
1072 | java_void_type = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL); | |
c906108c SS |
1073 | |
1074 | add_language (&java_language_defn); | |
1075 | } | |
1076 | ||
1077 | /* Cleanup code that should be run on every "run". | |
1078 | We should use make_run_cleanup to have this be called. | |
1079 | But will that mess up values in value histry? FIXME */ | |
1080 | ||
a14ed312 | 1081 | extern void java_rerun_cleanup (void); |
392a587b | 1082 | void |
fba45db2 | 1083 | java_rerun_cleanup (void) |
c906108c SS |
1084 | { |
1085 | if (class_symtab != NULL) | |
1086 | { | |
c5aa993b | 1087 | free_symtab (class_symtab); /* ??? */ |
c906108c SS |
1088 | class_symtab = NULL; |
1089 | } | |
1090 | if (dynamics_objfile != NULL) | |
1091 | { | |
1092 | free_objfile (dynamics_objfile); | |
1093 | dynamics_objfile = NULL; | |
1094 | } | |
1095 | ||
1096 | java_object_type = NULL; | |
1097 | } |