* java-*: Renamed to jv-*, to make fit within 14 characters.
[binutils-gdb.git] / gdb / jv-lang.c
1 /* Java language support routines for GDB, the GNU debugger.
2 Copyright 1997 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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, Boston, MA 02111-1307, USA. */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "gdbtypes.h"
23 #include "expression.h"
24 #include "parser-defs.h"
25 #include "language.h"
26 #include "gdbtypes.h"
27 #include "symtab.h"
28 #include "symfile.h"
29 #include "objfiles.h"
30 #include "gdb_string.h"
31 #include "value.h"
32 #include "c-lang.h"
33 #include "jv-lang.h"
34 #include "gdbcore.h"
35
36 struct type *java_int_type;
37 struct type *java_byte_type;
38 struct type *java_short_type;
39 struct type *java_long_type;
40 struct type *java_boolean_type;
41 struct type *java_char_type;
42 struct type *java_float_type;
43 struct type *java_double_type;
44 struct type *java_void_type;
45
46 struct type *java_object_type;
47
48 /* This objfile contains symtabs that have been dynamically created
49 to record dynamically loaded Java classes and dynamically
50 compiled java methods. */
51 struct objfile *dynamics_objfile = NULL;
52
53 struct type *java_link_class_type PARAMS((struct type*, value_ptr));
54
55 struct objfile *
56 get_dynamics_objfile ()
57 {
58 if (dynamics_objfile == NULL)
59 {
60 dynamics_objfile = allocate_objfile (NULL, 0);
61 }
62 return dynamics_objfile;
63 }
64
65 #if 1
66 /* symtab contains classes read from the inferior. */
67
68 static struct symtab *class_symtab = NULL;
69
70 /* Maximum number of class in class_symtab before relocation is needed. */
71
72 static int class_symtab_space;
73
74 struct symtab *
75 get_java_class_symtab ()
76 {
77 if (class_symtab == NULL)
78 {
79 struct objfile *objfile = get_dynamics_objfile();
80 struct blockvector *bv;
81 struct block *bl;
82 class_symtab = allocate_symtab ("<java-classes>", objfile);
83 class_symtab->language = language_java;
84 bv = (struct blockvector *)
85 obstack_alloc (&objfile->symbol_obstack, sizeof (struct blockvector));
86 BLOCKVECTOR_NBLOCKS (bv) = 1;
87 BLOCKVECTOR (class_symtab) = bv;
88
89 /* Allocate dummy STATIC_BLOCK. */
90 bl = (struct block *)
91 obstack_alloc (&objfile->symbol_obstack, sizeof (struct block));
92 BLOCK_NSYMS (bl) = 0;
93 BLOCK_START (bl) = 0;
94 BLOCK_END (bl) = 0;
95 BLOCK_FUNCTION (bl) = NULL;
96 BLOCK_SUPERBLOCK (bl) = NULL;
97 BLOCK_GCC_COMPILED (bl) = 0;
98 BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl;
99
100 /* Allocate GLOBAL_BLOCK. This has to be relocatable. */
101 class_symtab_space = 128;
102 bl = (struct block *)
103 mmalloc (objfile->md,
104 sizeof (struct block)
105 + ((class_symtab_space - 1) * sizeof (struct symbol *)));
106 *bl = *BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
107 BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
108 class_symtab->free_ptr = (char *) bl;
109 }
110 return class_symtab;
111 }
112
113 static void
114 add_class_symtab_symbol (sym)
115 struct symbol *sym;
116 {
117 struct symtab *symtab = get_java_class_symtab ();
118 struct blockvector *bv = BLOCKVECTOR (symtab);
119 struct block *bl = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
120 if (BLOCK_NSYMS (bl) >= class_symtab_space)
121 {
122 /* Need to re-allocate. */
123 class_symtab_space *= 2;
124 bl = (struct block *)
125 mrealloc (symtab->objfile->md, bl,
126 sizeof (struct block)
127 + ((class_symtab_space - 1) * sizeof (struct symbol *)));
128 class_symtab->free_ptr = (char *) bl;
129 BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
130 }
131
132 BLOCK_SYM (bl, BLOCK_NSYMS (bl)) = sym;
133 BLOCK_NSYMS (bl) = BLOCK_NSYMS (bl) + 1;
134 }
135
136 struct symbol *
137 add_class_symbol (type, addr)
138 struct type *type;
139 CORE_ADDR addr;
140 {
141 struct symbol *sym;
142 sym = (struct symbol *)
143 obstack_alloc (&dynamics_objfile->symbol_obstack, sizeof (struct symbol));
144 memset (sym, 0, sizeof (struct symbol));
145 SYMBOL_LANGUAGE (sym) = language_java;
146 SYMBOL_NAME (sym) = TYPE_NAME (type);
147 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
148 /* SYMBOL_VALUE (sym) = valu;*/
149 SYMBOL_TYPE (sym) = type;
150 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
151 SYMBOL_VALUE_ADDRESS (sym) = addr;
152 return sym;
153 }
154 #endif
155
156 struct type *
157 java_lookup_class (name)
158 char *name;
159 {
160 struct symbol *sym;
161 sym = lookup_symbol (name, expression_context_block, STRUCT_NAMESPACE,
162 (int *) 0, (struct symtab **) NULL);
163 if (sym != NULL)
164 return SYMBOL_TYPE (sym);
165 #if 0
166 CORE_ADDR addr;
167 if (called from parser)
168 {
169 call lookup_class (or similar) in inferior;
170 if not found:
171 return NULL;
172 addr = found in inferior;
173 }
174 else
175 addr = 0;
176 struct type *type;
177 type = alloc_type (objfile);
178 TYPE_CODE (type) = TYPE_CODE_STRUCT;
179 INIT_CPLUS_SPECIFIC (type);
180 TYPE_NAME (type) = obsavestring (name, strlen(name), &objfile->type_obstack);
181 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
182 TYPE ? = addr;
183 return type;
184 #else
185 /* FIXME - should search inferior's symbol table. */
186 return NULL;
187 #endif
188 }
189
190 /* Return a nul-terminated string (allocated on OBSTACK) for
191 a name given by NAME (which has type Utf8Const*). */
192
193 char *
194 get_java_utf8_name (obstack, name)
195 struct obstack *obstack;
196 value_ptr name;
197 {
198 char *chrs;
199 value_ptr temp = name;
200 int name_length = (int) value_as_long
201 (value_struct_elt (&temp, NULL, "length", NULL, "structure"));
202 temp = name;
203 temp = value_struct_elt (&temp, NULL, "data", NULL, "structure");
204 chrs = obstack_alloc (obstack, name_length+1);
205 chrs [name_length] = '\0';
206 read_memory_section (VALUE_ADDRESS (temp) + VALUE_OFFSET (temp),
207 chrs, name_length, NULL);
208 return chrs;
209 }
210
211 value_ptr
212 java_class_from_object (obj_val)
213 value_ptr obj_val;
214 {
215 value_ptr dtable_val = value_struct_elt (&obj_val, NULL, "dtable", NULL, "structure");
216 return value_struct_elt (&dtable_val, NULL, "class", NULL, "structure");
217 }
218
219 /* Check if CLASS_IS_PRIMITIVE(value of clas): */
220 int
221 java_class_is_primitive (clas)
222 value_ptr clas;
223 {
224 value_ptr dtable = value_struct_elt (&clas, NULL, "dtable", NULL, "struct");
225 CORE_ADDR i = value_as_pointer (dtable);
226 return (int) (i & 0x7fffffff) == (int) 0x7fffffff;
227 }
228
229 /* Read a Kaffe Class object, and generated a gdb (TYPE_CODE_STRUCT) type. */
230
231 struct type *
232 type_from_class (clas)
233 value_ptr clas;
234 {
235 struct type *type;
236 char *name;
237 value_ptr temp;
238 struct objfile *objfile = get_dynamics_objfile();
239 value_ptr utf8_name;
240 char *nptr;
241 CORE_ADDR addr;
242 struct block *bl;
243 int i;
244 int is_array = 0;
245
246 type = check_typedef (VALUE_TYPE (clas));
247 if (TYPE_CODE (type) == TYPE_CODE_PTR)
248 {
249 if (value_logical_not (clas))
250 return NULL;
251 clas = value_ind (clas);
252 }
253 addr = VALUE_ADDRESS (clas) + VALUE_OFFSET (clas);
254
255 get_java_class_symtab ();
256 bl = BLOCKVECTOR_BLOCK (BLOCKVECTOR (class_symtab), GLOBAL_BLOCK);
257 for (i = BLOCK_NSYMS (bl); --i >= 0; )
258 {
259 struct symbol *sym = BLOCK_SYM (bl, i);
260 if (SYMBOL_VALUE_ADDRESS (sym) == addr)
261 return SYMBOL_TYPE (sym);
262 }
263
264 if (java_class_is_primitive (clas))
265 {
266 value_ptr sig;
267 temp = clas;
268 sig = value_struct_elt (&temp, NULL, "msize", NULL, "structure");
269 return java_primitive_type (value_as_long (sig));
270 }
271
272 /* Get Class name. */
273 /* if clasloader non-null, prepend loader address. FIXME */
274 temp = clas;
275 utf8_name = value_struct_elt (&temp, NULL, "name", NULL, "structure");
276 name = get_java_utf8_name (&objfile->type_obstack, utf8_name);
277
278 type = alloc_type (objfile);
279 TYPE_CODE (type) = TYPE_CODE_STRUCT;
280 INIT_CPLUS_SPECIFIC (type);
281
282 if (name[0] == '[')
283 {
284 is_array = 1;
285 temp = clas;
286 /* Set array element type. */
287 temp = value_struct_elt (&temp, NULL, "methods", NULL, "structure");
288 VALUE_TYPE (temp) = lookup_pointer_type (VALUE_TYPE (clas));
289 TYPE_TARGET_TYPE (type) = type_from_class (temp);
290 }
291 for (nptr = name; *nptr != 0; nptr++)
292 {
293 if (*nptr == '/')
294 *nptr = '.';
295 }
296
297 ALLOCATE_CPLUS_STRUCT_TYPE (type);
298 TYPE_NAME (type) = name;
299
300 add_class_symtab_symbol (add_class_symbol (type, addr));
301 return java_link_class_type (type, clas);
302 }
303
304 /* Fill in class TYPE with data from the CLAS value. */
305
306 struct type *
307 java_link_class_type (type, clas)
308 struct type *type;
309 value_ptr clas;
310 {
311 value_ptr temp;
312 char *unqualified_name;
313 char *name = TYPE_NAME (type);
314 int ninterfaces, nfields, nmethods;
315 int type_is_object = 0;
316 struct fn_field *fn_fields;
317 struct fn_fieldlist *fn_fieldlists;
318 value_ptr fields, field, method, methods;
319 int i, j;
320 struct objfile *objfile = get_dynamics_objfile();
321 struct type *tsuper;
322
323 unqualified_name = strrchr (name, '.');
324 if (unqualified_name == NULL)
325 unqualified_name = name;
326
327 temp = clas;
328 temp = value_struct_elt (&temp, NULL, "superclass", NULL, "structure");
329 if (name != NULL && strcmp (name, "java.lang.Object") == 0)
330 {
331 tsuper = get_java_object_type ();
332 if (tsuper && TYPE_CODE (tsuper) == TYPE_CODE_PTR)
333 tsuper = TYPE_TARGET_TYPE (tsuper);
334 type_is_object = 1;
335 }
336 else
337 tsuper = type_from_class (temp);
338
339 #if 1
340 ninterfaces = 0;
341 #else
342 temp = clas;
343 ninterfaces = value_as_long (value_struct_elt (&temp, NULL, "interface_len", NULL, "structure"));
344 #endif
345 TYPE_N_BASECLASSES (type) = (tsuper == NULL ? 0 : 1) + ninterfaces;
346 temp = clas;
347 nfields = value_as_long (value_struct_elt (&temp, NULL, "nfields", NULL, "structure"));
348 nfields += TYPE_N_BASECLASSES (type);
349 TYPE_NFIELDS (type) = nfields;
350 TYPE_FIELDS (type) = (struct field *)
351 TYPE_ALLOC (type, sizeof (struct field) * nfields);
352
353 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
354
355 TYPE_FIELD_PRIVATE_BITS (type) =
356 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
357 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
358
359 TYPE_FIELD_PROTECTED_BITS (type) =
360 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
361 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
362
363 TYPE_FIELD_IGNORE_BITS (type) =
364 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
365 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
366
367 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
368 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
369 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
370
371 if (tsuper != NULL)
372 {
373 TYPE_BASECLASS (type, 0) = tsuper;
374 if (type_is_object)
375 SET_TYPE_FIELD_PRIVATE (type, 0);
376 }
377
378
379 temp = clas;
380 temp = value_struct_elt (&temp, NULL, "bfsize", NULL, "structure");
381 TYPE_LENGTH (type) = JAVA_OBJECT_SIZE + value_as_long (temp);
382
383 fields = NULL;
384 for (i = TYPE_N_BASECLASSES (type); i < nfields; i++)
385 {
386 int accflags;
387 int boffset;
388 if (fields == NULL)
389 {
390 temp = clas;
391 fields = value_struct_elt (&temp, NULL, "fields", NULL, "structure");
392 field = value_ind (fields);
393 }
394 else
395 { /* Re-use field value for next field. */
396 VALUE_ADDRESS (field) += TYPE_LENGTH (VALUE_TYPE (field));
397 VALUE_LAZY (field) = 1;
398 }
399 temp = field;
400 temp = value_struct_elt (&temp, NULL, "name", NULL, "structure");
401 TYPE_FIELD_NAME (type, i) =
402 get_java_utf8_name (&objfile->type_obstack, temp);
403 temp = field;
404 accflags = value_as_long (value_struct_elt (&temp, NULL, "accflags",
405 NULL, "structure"));
406 boffset = value_as_long (value_struct_elt (&temp, NULL, "boffset",
407 NULL, "structure"));
408 if (accflags & 0x0001) /* public access */
409 {
410 /* ??? */
411 }
412 if (accflags & 0x0002) /* private access */
413 {
414 SET_TYPE_FIELD_PRIVATE (type, i);
415 }
416 if (accflags & 0x0004) /* protected access */
417 {
418 SET_TYPE_FIELD_PROTECTED (type, i);
419 }
420 if (accflags & 0x0008) /* ACC_STATIC */
421 {
422 TYPE_FIELD_BITPOS (type, i) = -1;
423 /* Hack for TYPE_FIELD_STATIC_PHYSNAME to prevent a crash. FIXME. */
424 type->fields[i].bitsize = (long) "???";
425 }
426 else
427 TYPE_FIELD_BITPOS (type, i) = 8 * (JAVA_OBJECT_SIZE + boffset);
428 if (accflags & 0x8000) /* FIELD_UNRESOLVED_FLAG */
429 {
430 TYPE_FIELD_TYPE (type, i) = get_java_object_type (); /* FIXME */
431 }
432 else
433 {
434 struct type *ftype;
435 temp = field;
436 temp = value_struct_elt (&temp, NULL, "type", NULL, "structure");
437 ftype = type_from_class (temp);
438 if (TYPE_CODE (ftype) == TYPE_CODE_STRUCT)
439 ftype = lookup_pointer_type (ftype);
440 TYPE_FIELD_TYPE (type, i) = ftype;
441 }
442 }
443
444 temp = clas;
445 nmethods = value_as_long (value_struct_elt (&temp, NULL, "nmethods",
446 NULL, "structure"));
447 TYPE_NFN_FIELDS_TOTAL (type) = nmethods;
448 j = nmethods * sizeof (struct fn_field);
449 fn_fields = (struct fn_field*)
450 obstack_alloc (&dynamics_objfile->symbol_obstack, j);
451 memset (fn_fields, 0, j);
452 fn_fieldlists = (struct fn_fieldlist*)
453 alloca (nmethods * sizeof (struct fn_fieldlist));
454
455 methods = NULL;
456 for (i = 0; i < nmethods; i++)
457 {
458 char *mname;
459 int k;
460 if (methods == NULL)
461 {
462 temp = clas;
463 methods = value_struct_elt (&temp, NULL, "methods", NULL, "structure");
464 method = value_ind (methods);
465 }
466 else
467 { /* Re-use method value for next method. */
468 VALUE_ADDRESS (method) += TYPE_LENGTH (VALUE_TYPE (method));
469 VALUE_LAZY (method) = 1;
470 }
471
472 /* Get method name. */
473 temp = method;
474 temp = value_struct_elt (&temp, NULL, "name", NULL, "structure");
475 mname = get_java_utf8_name (&objfile->type_obstack, temp);
476 if (strcmp (mname, "<init>") == 0)
477 mname = unqualified_name;
478
479 /* Check for an existing method with the same name.
480 * This makes building the fn_fieldslists an O(nmethods**2)
481 * operation. That could be using hashing, but I doubt it
482 * is worth it. Note that we do maintain the order of methods
483 * in the inferior's Method table (as long as that is grouped
484 * by method name), which I think is desirable. --PB */
485 for (k = 0, j = TYPE_NFN_FIELDS (type); ; )
486 {
487 if (--j < 0)
488 { /* No match - new method name. */
489 j = TYPE_NFN_FIELDS(type)++;
490 fn_fieldlists[j].name = mname;
491 fn_fieldlists[j].length = 1;
492 fn_fieldlists[j].fn_fields = &fn_fields[i];
493 k = i;
494 break;
495 }
496 if (strcmp (mname, fn_fieldlists[j].name) == 0)
497 { /* Found an existing method with the same name. */
498 int l;
499 if (mname != unqualified_name)
500 obstack_free (&objfile->type_obstack, mname);
501 mname = fn_fieldlists[j].name;
502 fn_fieldlists[j].length++;
503 k = i - k; /* Index of new slot. */
504 /* Shift intervening fn_fields (between k and i) down. */
505 for (l = i; l > k; l--) fn_fields[l] = fn_fields[l-1];
506 for (l = TYPE_NFN_FIELDS (type); --l > j; )
507 fn_fieldlists[l].fn_fields++;
508 break;
509 }
510 k += fn_fieldlists[j].length;
511 }
512 fn_fields[k].physname = "";
513 fn_fields[k].is_stub = 1;
514 fn_fields[k].type = make_function_type (java_void_type, NULL); /* FIXME*/
515 TYPE_CODE (fn_fields[k].type) = TYPE_CODE_METHOD;
516 }
517
518 j = TYPE_NFN_FIELDS(type) * sizeof (struct fn_fieldlist);
519 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist*)
520 obstack_alloc (&dynamics_objfile->symbol_obstack, j);
521 memcpy (TYPE_FN_FIELDLISTS (type), fn_fieldlists, j);
522
523 return type;
524 }
525
526 struct type*
527 get_java_object_type ()
528 {
529 return java_object_type;
530 }
531
532 int
533 is_object_type (type)
534 struct type *type;
535 {
536 CHECK_TYPEDEF (type);
537 if (TYPE_CODE (type) == TYPE_CODE_PTR)
538 {
539 struct type *ttype = check_typedef (TYPE_TARGET_TYPE (type));
540 char *name;
541 if (TYPE_CODE (ttype) != TYPE_CODE_STRUCT)
542 return 0;
543 while (TYPE_N_BASECLASSES (ttype) > 0)
544 ttype = TYPE_BASECLASS (ttype, 0);
545 name = TYPE_NAME (ttype);
546 if (name != NULL && strcmp (name, "java.lang.Object") == 0)
547 return 1;
548 name = TYPE_NFIELDS (ttype) > 0 ? TYPE_FIELD_NAME (ttype, 0) : (char*)0;
549 if (name != NULL && strcmp (name, "dtable") == 0)
550 {
551 if (java_object_type == NULL)
552 java_object_type = type;
553 return 1;
554 }
555 }
556 return 0;
557 }
558
559 struct type*
560 java_primitive_type (signature)
561 int signature;
562 {
563 switch (signature)
564 {
565 case 'B': return java_byte_type;
566 case 'S': return java_short_type;
567 case 'I': return java_int_type;
568 case 'J': return java_long_type;
569 case 'Z': return java_boolean_type;
570 case 'C': return java_char_type;
571 case 'F': return java_float_type;
572 case 'D': return java_double_type;
573 case 'V': return java_void_type;
574 }
575 error ("unknown signature '%c' for primitive type", (char) signature);
576 }
577
578 /* Return the type of TYPE followed by DIMS pairs of [ ].
579 If DIMS == 0, TYPE is returned. */
580
581 struct type *
582 java_array_type (type, dims)
583 struct type *type;
584 int dims;
585 {
586 if (dims == 0)
587 return type;
588 error ("array types not implemented");
589 }
590
591 /* Create a Java string in the inferior from a (Utf8) literal. */
592
593 value_ptr
594 java_value_string (ptr, len)
595 char *ptr;
596 int len;
597 {
598 error ("not implemented - java_value_string"); /* FIXME */
599 }
600
601 static value_ptr
602 evaluate_subexp_java (expect_type, exp, pos, noside)
603 struct type *expect_type;
604 register struct expression *exp;
605 register int *pos;
606 enum noside noside;
607 {
608 int pc = *pos;
609 int i;
610 enum exp_opcode op = exp->elts[*pos].opcode;
611 value_ptr arg1;
612 switch (op)
613 {
614 case UNOP_IND:
615 if (noside == EVAL_SKIP)
616 goto standard;
617 (*pos)++;
618 arg1 = evaluate_subexp_standard (expect_type, exp, pos, EVAL_NORMAL);
619 if (is_object_type (VALUE_TYPE (arg1)))
620 {
621 struct type *type = type_from_class (java_class_from_object (arg1));
622 arg1 = value_cast (lookup_pointer_type (type), arg1);
623 }
624 if (noside == EVAL_SKIP)
625 goto nosideret;
626 return value_ind (arg1);
627 case OP_STRING:
628 (*pos)++;
629 i = longest_to_int (exp->elts[pc + 1].longconst);
630 (*pos) += 3 + BYTES_TO_EXP_ELEM (i + 1);
631 if (noside == EVAL_SKIP)
632 goto nosideret;
633 return java_value_string (&exp->elts[pc + 2].string, i);
634 default:
635 break;
636 }
637 standard:
638 return evaluate_subexp_standard (expect_type, exp, pos, noside);
639 nosideret:
640 return value_from_longest (builtin_type_long, (LONGEST) 1);
641 }
642
643 static struct type *
644 java_create_fundamental_type (objfile, typeid)
645 struct objfile *objfile;
646 int typeid;
647 {
648 switch (typeid)
649 {
650 case FT_VOID: return java_void_type;
651 case FT_BOOLEAN: return java_boolean_type;
652 case FT_CHAR: return java_char_type;
653 case FT_FLOAT: return java_float_type;
654 case FT_DBL_PREC_FLOAT: return java_double_type;
655 case FT_BYTE: case FT_SIGNED_CHAR: return java_byte_type;
656 case FT_SHORT: case FT_SIGNED_SHORT: return java_short_type;
657 case FT_INTEGER: case FT_SIGNED_INTEGER: return java_int_type;
658 case FT_LONG: case FT_SIGNED_LONG: return java_long_type;
659 }
660 return c_create_fundamental_type (objfile, typeid);
661 }
662
663 /* Table mapping opcodes into strings for printing operators
664 and precedences of the operators. */
665
666 const struct op_print java_op_print_tab[] =
667 {
668 {",", BINOP_COMMA, PREC_COMMA, 0},
669 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
670 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
671 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
672 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
673 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
674 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
675 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
676 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
677 {"<=", BINOP_LEQ, PREC_ORDER, 0},
678 {">=", BINOP_GEQ, PREC_ORDER, 0},
679 {">", BINOP_GTR, PREC_ORDER, 0},
680 {"<", BINOP_LESS, PREC_ORDER, 0},
681 {">>", BINOP_RSH, PREC_SHIFT, 0},
682 {"<<", BINOP_LSH, PREC_SHIFT, 0},
683 #if 0
684 {">>>", BINOP_???, PREC_SHIFT, 0},
685 #endif
686 {"+", BINOP_ADD, PREC_ADD, 0},
687 {"-", BINOP_SUB, PREC_ADD, 0},
688 {"*", BINOP_MUL, PREC_MUL, 0},
689 {"/", BINOP_DIV, PREC_MUL, 0},
690 {"%", BINOP_REM, PREC_MUL, 0},
691 {"-", UNOP_NEG, PREC_PREFIX, 0},
692 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
693 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
694 {"*", UNOP_IND, PREC_PREFIX, 0},
695 #if 0
696 {"instanceof", ???, ???, 0},
697 #endif
698 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
699 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
700 {NULL, 0, 0, 0}
701 };
702
703 const struct language_defn java_language_defn = {
704 "java", /* Language name */
705 language_java,
706 c_builtin_types,
707 range_check_off,
708 type_check_off,
709 java_parse,
710 java_error,
711 evaluate_subexp_java,
712 c_printchar, /* Print a character constant */
713 c_printstr, /* Function to print string constant */
714 java_create_fundamental_type, /* Create fundamental type in this language */
715 java_print_type, /* Print a type using appropriate syntax */
716 java_val_print, /* Print a value using appropriate syntax */
717 java_value_print, /* Print a top-level value */
718 {"", "", "", ""}, /* Binary format info */
719 {"0%lo", "0", "o", ""}, /* Octal format info */
720 {"%ld", "", "d", ""}, /* Decimal format info */
721 {"0x%lx", "0x", "x", ""}, /* Hex format info */
722 java_op_print_tab, /* expression operators for printing */
723 1, /* c-style arrays */
724 0, /* String lower bound */
725 &builtin_type_char, /* Type of string elements */
726 LANG_MAGIC
727 };
728
729 void
730 _initialize_jave_language ()
731 {
732
733 java_int_type = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
734 java_short_type = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
735 java_long_type = init_type (TYPE_CODE_INT, 8, 0, "long", NULL);
736 java_byte_type = init_type (TYPE_CODE_INT, 1, 0, "byte", NULL);
737 java_boolean_type= init_type (TYPE_CODE_BOOL, 1, 0, "boolean", NULL);
738 java_char_type = init_type (TYPE_CODE_CHAR, 2, 0, "char", NULL);
739 java_float_type = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
740 java_double_type = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
741 java_void_type = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
742
743 add_language (&java_language_defn);
744 }
745
746 /* Cleanup code that should be urn on every "run".
747 We need some hook to have this actually be called ... FIXME */
748
749 void java_rerun_cleanup ()
750 {
751 if (class_symtab != NULL)
752 {
753 free_symtab (class_symtab); /* ??? */
754 class_symtab = NULL;
755 }
756 if (dynamics_objfile != NULL)
757 {
758 free_objfile (dynamics_objfile);
759 dynamics_objfile = NULL;
760 }
761
762 java_object_type = NULL;
763 }