]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/jv-lang.c
* ada-lang.c (ada_decode_symbol): Check and set 'ada_mangled'.
[thirdparty/binutils-gdb.git] / gdb / jv-lang.c
CommitLineData
c906108c 1/* Java language support routines for GDB, the GNU debugger.
dfa52d88 2
28e7fd62 3 Copyright (C) 1997-2013 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
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"
fe898f56 35#include "block.h"
9a3d7dfd 36#include "demangle.h"
de4f826b 37#include "dictionary.h"
c906108c 38#include <ctype.h>
03b4bca2 39#include "gdb_assert.h"
127c81bc
TT
40#include "charset.h"
41#include "valprint.h"
c906108c 42
392a587b
JM
43/* Local functions */
44
a14ed312 45extern void _initialize_java_language (void);
392a587b 46
0d5cff50
DE
47static int java_demangled_signature_length (const char *);
48static void java_demangled_signature_copy (char *, const char *);
c906108c 49
20781792 50static struct symtab *get_java_class_symtab (struct gdbarch *gdbarch);
75c9979e
AC
51static char *get_java_utf8_name (struct obstack *obstack, struct value *name);
52static int java_class_is_primitive (struct value *clas);
75c9979e 53static struct value *java_value_string (char *ptr, int len);
392a587b 54
6c7a06a3
TT
55static void java_emit_char (int c, struct type *type,
56 struct ui_file * stream, int quoter);
c906108c 57
31c27f77
JJ
58static char *java_class_name_from_physname (const char *physname);
59
20781792 60static const struct objfile_data *jv_dynamics_objfile_data_key;
20781792 61
86cc0029
TT
62/* The dynamic objfile is kept per-program-space. This key lets us
63 associate the objfile with the program space. */
c906108c 64
86cc0029 65static const struct program_space_data *jv_dynamics_progspace_key;
20781792 66
0daa2b63
UW
67static struct type *java_link_class_type (struct gdbarch *,
68 struct type *, struct value *);
c906108c 69
30cc903e
TT
70/* An instance of this structure is used to store some data that must
71 be freed. */
72
73struct jv_per_objfile_data
74{
75 /* The expandable dictionary we use. */
76 struct dictionary *dict;
77};
78
20781792
TT
79/* A function called when the dynamics_objfile is freed. We use this
80 to clean up some internal state. */
81static void
30cc903e 82jv_per_objfile_free (struct objfile *objfile, void *data)
20781792 83{
30cc903e 84 struct jv_per_objfile_data *jv_data = data;
86cc0029 85 struct objfile *dynamics_objfile;
30cc903e 86
86cc0029
TT
87 dynamics_objfile = program_space_data (current_program_space,
88 jv_dynamics_progspace_key);
20781792 89 gdb_assert (objfile == dynamics_objfile);
30cc903e
TT
90
91 if (jv_data->dict)
92 dict_free (jv_data->dict);
93 xfree (jv_data);
86cc0029
TT
94
95 set_program_space_data (current_program_space,
96 jv_dynamics_progspace_key,
97 NULL);
20781792
TT
98}
99
eb9a305d
DC
100/* FIXME: carlton/2003-02-04: This is the main or only caller of
101 allocate_objfile with first argument NULL; as a result, this code
102 breaks every so often. Somebody should write a test case that
103 exercises GDB in various ways (e.g. something involving loading a
104 dynamic library) after this code has been called. */
105
c906108c 106static struct objfile *
20781792 107get_dynamics_objfile (struct gdbarch *gdbarch)
c906108c 108{
86cc0029
TT
109 struct objfile *dynamics_objfile;
110
111 dynamics_objfile = program_space_data (current_program_space,
112 jv_dynamics_progspace_key);
113
c906108c
SS
114 if (dynamics_objfile == NULL)
115 {
30cc903e
TT
116 struct jv_per_objfile_data *data;
117
20781792
TT
118 /* Mark it as shared so that it is cleared when the inferior is
119 re-run. */
120 dynamics_objfile = allocate_objfile (NULL, OBJF_SHARED);
121 dynamics_objfile->gdbarch = gdbarch;
30cc903e
TT
122
123 data = XCNEW (struct jv_per_objfile_data);
124 set_objfile_data (dynamics_objfile, jv_dynamics_objfile_data_key, data);
86cc0029
TT
125
126 set_program_space_data (current_program_space,
127 jv_dynamics_progspace_key,
128 dynamics_objfile);
c906108c
SS
129 }
130 return dynamics_objfile;
131}
132
392a587b 133static struct symtab *
20781792 134get_java_class_symtab (struct gdbarch *gdbarch)
c906108c 135{
86cc0029
TT
136 struct objfile *objfile = get_dynamics_objfile (gdbarch);
137 struct symtab *class_symtab = objfile->symtabs;
138
c906108c
SS
139 if (class_symtab == NULL)
140 {
c906108c
SS
141 struct blockvector *bv;
142 struct block *bl;
30cc903e 143 struct jv_per_objfile_data *jv_data;
e0881a8e 144
c906108c
SS
145 class_symtab = allocate_symtab ("<java-classes>", objfile);
146 class_symtab->language = language_java;
147 bv = (struct blockvector *)
4a146b47 148 obstack_alloc (&objfile->objfile_obstack,
de4f826b 149 sizeof (struct blockvector) + sizeof (struct block *));
c906108c
SS
150 BLOCKVECTOR_NBLOCKS (bv) = 1;
151 BLOCKVECTOR (class_symtab) = bv;
152
1777feb0 153 /* Allocate dummy STATIC_BLOCK. */
4a146b47
EZ
154 bl = allocate_block (&objfile->objfile_obstack);
155 BLOCK_DICT (bl) = dict_create_linear (&objfile->objfile_obstack,
de4f826b 156 NULL);
c906108c
SS
157 BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl;
158
5c4e30ca 159 /* Allocate GLOBAL_BLOCK. */
84a146c9 160 bl = allocate_global_block (&objfile->objfile_obstack);
de4f826b 161 BLOCK_DICT (bl) = dict_create_hashed_expandable ();
84a146c9 162 set_block_symtab (bl, class_symtab);
c906108c 163 BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
30cc903e
TT
164
165 /* Arrange to free the dict. */
166 jv_data = objfile_data (objfile, jv_dynamics_objfile_data_key);
167 jv_data->dict = BLOCK_DICT (bl);
c906108c
SS
168 }
169 return class_symtab;
170}
171
172static void
fba45db2 173add_class_symtab_symbol (struct symbol *sym)
c906108c 174{
20781792
TT
175 struct symtab *symtab
176 = get_java_class_symtab (get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile));
c906108c 177 struct blockvector *bv = BLOCKVECTOR (symtab);
e0881a8e 178
de4f826b 179 dict_add_symbol (BLOCK_DICT (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)), sym);
c906108c
SS
180}
181
c906108c 182static struct symbol *
fba45db2 183add_class_symbol (struct type *type, CORE_ADDR addr)
c906108c
SS
184{
185 struct symbol *sym;
86cc0029 186 struct objfile *objfile = get_dynamics_objfile (get_type_arch (type));
e0881a8e 187
e623cf5d 188 sym = allocate_symbol (objfile);
f85f34ed 189 SYMBOL_SET_LANGUAGE (sym, language_java, &objfile->objfile_obstack);
3567439c 190 SYMBOL_SET_LINKAGE_NAME (sym, TYPE_TAG_NAME (type));
f1e6e072 191 SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
c5aa993b 192 /* SYMBOL_VALUE (sym) = valu; */
c906108c 193 SYMBOL_TYPE (sym) = type;
176620f1 194 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
c906108c
SS
195 SYMBOL_VALUE_ADDRESS (sym) = addr;
196 return sym;
197}
de4f826b 198
c906108c 199struct type *
fba45db2 200java_lookup_class (char *name)
c906108c
SS
201{
202 struct symbol *sym;
e0881a8e 203
2570f2b7 204 sym = lookup_symbol (name, expression_context_block, STRUCT_DOMAIN, NULL);
c906108c
SS
205 if (sym != NULL)
206 return SYMBOL_TYPE (sym);
1777feb0 207 /* FIXME - should search inferior's symbol table. */
c906108c 208 return NULL;
c906108c
SS
209}
210
211/* Return a nul-terminated string (allocated on OBSTACK) for
1777feb0 212 a name given by NAME (which has type Utf8Const*). */
c906108c
SS
213
214char *
75c9979e 215get_java_utf8_name (struct obstack *obstack, struct value *name)
c906108c
SS
216{
217 char *chrs;
75c9979e 218 struct value *temp = name;
c906108c
SS
219 int name_length;
220 CORE_ADDR data_addr;
e0881a8e 221
c906108c
SS
222 temp = value_struct_elt (&temp, NULL, "length", NULL, "structure");
223 name_length = (int) value_as_long (temp);
42ae5230 224 data_addr = value_address (temp) + TYPE_LENGTH (value_type (temp));
c5aa993b
JM
225 chrs = obstack_alloc (obstack, name_length + 1);
226 chrs[name_length] = '\0';
c68a6671 227 read_memory (data_addr, (gdb_byte *) chrs, name_length);
c906108c
SS
228 return chrs;
229}
230
75c9979e
AC
231struct value *
232java_class_from_object (struct value *obj_val)
c906108c
SS
233{
234 /* This is all rather inefficient, since the offsets of vtable and
235 class are fixed. FIXME */
75c9979e 236 struct value *vtable_val;
c906108c 237
df407dfe
AC
238 if (TYPE_CODE (value_type (obj_val)) == TYPE_CODE_PTR
239 && TYPE_LENGTH (TYPE_TARGET_TYPE (value_type (obj_val))) == 0)
c906108c 240 obj_val = value_at (get_java_object_type (),
00a4c844 241 value_as_address (obj_val));
c906108c
SS
242
243 vtable_val = value_struct_elt (&obj_val, NULL, "vtable", NULL, "structure");
244 return value_struct_elt (&vtable_val, NULL, "class", NULL, "structure");
245}
246
247/* Check if CLASS_IS_PRIMITIVE(value of clas): */
392a587b 248static int
75c9979e 249java_class_is_primitive (struct value *clas)
c906108c 250{
1777feb0
MS
251 struct value *vtable = value_struct_elt (&clas, NULL, "vtable",
252 NULL, "struct");
1aa20aa8 253 CORE_ADDR i = value_as_address (vtable);
e0881a8e 254
c906108c
SS
255 return (int) (i & 0x7fffffff) == (int) 0x7fffffff;
256}
257
1777feb0 258/* Read a GCJ Class object, and generated a gdb (TYPE_CODE_STRUCT) type. */
c906108c
SS
259
260struct type *
0daa2b63 261type_from_class (struct gdbarch *gdbarch, struct value *clas)
c906108c
SS
262{
263 struct type *type;
264 char *name;
75c9979e 265 struct value *temp;
c906108c 266 struct objfile *objfile;
75c9979e 267 struct value *utf8_name;
c906108c
SS
268 char *nptr;
269 CORE_ADDR addr;
c906108c 270
df407dfe 271 type = check_typedef (value_type (clas));
c906108c
SS
272 if (TYPE_CODE (type) == TYPE_CODE_PTR)
273 {
274 if (value_logical_not (clas))
275 return NULL;
276 clas = value_ind (clas);
277 }
42ae5230 278 addr = value_address (clas);
c906108c 279
20781792 280 objfile = get_dynamics_objfile (gdbarch);
c906108c
SS
281 if (java_class_is_primitive (clas))
282 {
75c9979e 283 struct value *sig;
e0881a8e 284
c906108c
SS
285 temp = clas;
286 sig = value_struct_elt (&temp, NULL, "method_count", NULL, "structure");
0daa2b63 287 return java_primitive_type (gdbarch, value_as_long (sig));
c906108c
SS
288 }
289
1777feb0
MS
290 /* Get Class name. */
291 /* If clasloader non-null, prepend loader address. FIXME */
c906108c
SS
292 temp = clas;
293 utf8_name = value_struct_elt (&temp, NULL, "name", NULL, "structure");
b99607ea 294 name = get_java_utf8_name (&objfile->objfile_obstack, utf8_name);
c5aa993b 295 for (nptr = name; *nptr != 0; nptr++)
c906108c
SS
296 {
297 if (*nptr == '/')
298 *nptr = '.';
299 }
300
301 type = java_lookup_class (name);
302 if (type != NULL)
303 return type;
304
20781792 305 type = alloc_type (objfile);
c906108c
SS
306 TYPE_CODE (type) = TYPE_CODE_STRUCT;
307 INIT_CPLUS_SPECIFIC (type);
308
309 if (name[0] == '[')
310 {
311 char *signature = name;
312 int namelen = java_demangled_signature_length (signature);
e0881a8e 313
c906108c 314 if (namelen > strlen (name))
b99607ea 315 name = obstack_alloc (&objfile->objfile_obstack, namelen + 1);
c906108c
SS
316 java_demangled_signature_copy (name, signature);
317 name[namelen] = '\0';
c906108c 318 temp = clas;
1777feb0 319 /* Set array element type. */
c906108c 320 temp = value_struct_elt (&temp, NULL, "methods", NULL, "structure");
1777feb0
MS
321 deprecated_set_value_type (temp,
322 lookup_pointer_type (value_type (clas)));
0daa2b63 323 TYPE_TARGET_TYPE (type) = type_from_class (gdbarch, temp);
c906108c
SS
324 }
325
326 ALLOCATE_CPLUS_STRUCT_TYPE (type);
327 TYPE_TAG_NAME (type) = name;
328
329 add_class_symtab_symbol (add_class_symbol (type, addr));
0daa2b63 330 return java_link_class_type (gdbarch, type, clas);
c906108c
SS
331}
332
1777feb0 333/* Fill in class TYPE with data from the CLAS value. */
c906108c 334
20781792 335static struct type *
0daa2b63
UW
336java_link_class_type (struct gdbarch *gdbarch,
337 struct type *type, struct value *clas)
c906108c 338{
75c9979e 339 struct value *temp;
0d5cff50
DE
340 const char *unqualified_name;
341 const char *name = TYPE_TAG_NAME (type);
c906108c
SS
342 int ninterfaces, nfields, nmethods;
343 int type_is_object = 0;
344 struct fn_field *fn_fields;
345 struct fn_fieldlist *fn_fieldlists;
75c9979e
AC
346 struct value *fields;
347 struct value *methods;
c65ecaf3
AC
348 struct value *method = NULL;
349 struct value *field = NULL;
c906108c 350 int i, j;
20781792 351 struct objfile *objfile = get_dynamics_objfile (gdbarch);
c906108c
SS
352 struct type *tsuper;
353
03b4bca2 354 gdb_assert (name != NULL);
c906108c
SS
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");
03b4bca2 361 if (strcmp (name, "java.lang.Object") == 0)
c906108c
SS
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
0daa2b63 369 tsuper = type_from_class (gdbarch, temp);
c906108c
SS
370
371#if 1
372 ninterfaces = 0;
373#else
374 temp = clas;
1777feb0
MS
375 ninterfaces = value_as_long (value_struct_elt (&temp, NULL, "interface_len",
376 NULL, "structure"));
c906108c
SS
377#endif
378 TYPE_N_BASECLASSES (type) = (tsuper == NULL ? 0 : 1) + ninterfaces;
379 temp = clas;
1777feb0
MS
380 nfields = value_as_long (value_struct_elt (&temp, NULL, "field_count",
381 NULL, "structure"));
c906108c 382 nfields += TYPE_N_BASECLASSES (type);
1777feb0 383 nfields++; /* Add one for dummy "class" field. */
c906108c
SS
384 TYPE_NFIELDS (type) = nfields;
385 TYPE_FIELDS (type) = (struct field *)
386 TYPE_ALLOC (type, sizeof (struct field) * nfields);
387
388 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
389
390 TYPE_FIELD_PRIVATE_BITS (type) =
391 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
392 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
393
394 TYPE_FIELD_PROTECTED_BITS (type) =
395 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
396 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
397
398 TYPE_FIELD_IGNORE_BITS (type) =
399 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
400 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
401
402 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
403 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
404 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
405
406 if (tsuper != NULL)
407 {
408 TYPE_BASECLASS (type, 0) = tsuper;
409 if (type_is_object)
410 SET_TYPE_FIELD_PRIVATE (type, 0);
411 }
412
413 i = strlen (name);
c5aa993b 414 if (i > 2 && name[i - 1] == ']' && tsuper != NULL)
c906108c
SS
415 {
416 /* FIXME */
1777feb0 417 TYPE_LENGTH (type) = TYPE_LENGTH (tsuper) + 4; /* size with "length" */
c906108c
SS
418 }
419 else
420 {
421 temp = clas;
1777feb0
MS
422 temp = value_struct_elt (&temp, NULL, "size_in_bytes",
423 NULL, "structure");
c906108c
SS
424 TYPE_LENGTH (type) = value_as_long (temp);
425 }
426
427 fields = NULL;
1777feb0 428 nfields--; /* First set up dummy "class" field. */
42ae5230 429 SET_FIELD_PHYSADDR (TYPE_FIELD (type, nfields), value_address (clas));
c906108c 430 TYPE_FIELD_NAME (type, nfields) = "class";
df407dfe 431 TYPE_FIELD_TYPE (type, nfields) = value_type (clas);
c906108c 432 SET_TYPE_FIELD_PRIVATE (type, nfields);
c5aa993b
JM
433
434 for (i = TYPE_N_BASECLASSES (type); i < nfields; i++)
c906108c
SS
435 {
436 int accflags;
437 int boffset;
e0881a8e 438
c906108c
SS
439 if (fields == NULL)
440 {
441 temp = clas;
442 fields = value_struct_elt (&temp, NULL, "fields", NULL, "structure");
443 field = value_ind (fields);
444 }
445 else
1777feb0 446 { /* Re-use field value for next field. */
42ae5230
TT
447 CORE_ADDR addr
448 = value_address (field) + TYPE_LENGTH (value_type (field));
e0881a8e 449
42ae5230 450 set_value_address (field, addr);
dfa52d88 451 set_value_lazy (field, 1);
c906108c
SS
452 }
453 temp = field;
454 temp = value_struct_elt (&temp, NULL, "name", NULL, "structure");
455 TYPE_FIELD_NAME (type, i) =
b99607ea 456 get_java_utf8_name (&objfile->objfile_obstack, temp);
c906108c
SS
457 temp = field;
458 accflags = value_as_long (value_struct_elt (&temp, NULL, "accflags",
459 NULL, "structure"));
460 temp = field;
461 temp = value_struct_elt (&temp, NULL, "info", NULL, "structure");
462 boffset = value_as_long (value_struct_elt (&temp, NULL, "boffset",
c5aa993b
JM
463 NULL, "structure"));
464 if (accflags & 0x0001) /* public access */
c906108c
SS
465 {
466 /* ??? */
467 }
c5aa993b 468 if (accflags & 0x0002) /* private access */
c906108c
SS
469 {
470 SET_TYPE_FIELD_PRIVATE (type, i);
471 }
c5aa993b 472 if (accflags & 0x0004) /* protected access */
c906108c
SS
473 {
474 SET_TYPE_FIELD_PROTECTED (type, i);
475 }
c5aa993b
JM
476 if (accflags & 0x0008) /* ACC_STATIC */
477 SET_FIELD_PHYSADDR (TYPE_FIELD (type, i), boffset);
c906108c 478 else
945b3a32 479 SET_FIELD_BITPOS (TYPE_FIELD (type, i), 8 * boffset);
c5aa993b 480 if (accflags & 0x8000) /* FIELD_UNRESOLVED_FLAG */
c906108c 481 {
c5aa993b 482 TYPE_FIELD_TYPE (type, i) = get_java_object_type (); /* FIXME */
c906108c
SS
483 }
484 else
485 {
486 struct type *ftype;
e0881a8e 487
c906108c
SS
488 temp = field;
489 temp = value_struct_elt (&temp, NULL, "type", NULL, "structure");
0daa2b63 490 ftype = type_from_class (gdbarch, temp);
c906108c
SS
491 if (TYPE_CODE (ftype) == TYPE_CODE_STRUCT)
492 ftype = lookup_pointer_type (ftype);
493 TYPE_FIELD_TYPE (type, i) = ftype;
494 }
495 }
496
497 temp = clas;
498 nmethods = value_as_long (value_struct_elt (&temp, NULL, "method_count",
499 NULL, "structure"));
c906108c 500 j = nmethods * sizeof (struct fn_field);
c5aa993b 501 fn_fields = (struct fn_field *)
86cc0029 502 obstack_alloc (&objfile->objfile_obstack, j);
c906108c 503 memset (fn_fields, 0, j);
c5aa993b 504 fn_fieldlists = (struct fn_fieldlist *)
c906108c
SS
505 alloca (nmethods * sizeof (struct fn_fieldlist));
506
507 methods = NULL;
c5aa993b 508 for (i = 0; i < nmethods; i++)
c906108c 509 {
0d5cff50 510 const char *mname;
c906108c 511 int k;
e0881a8e 512
c906108c
SS
513 if (methods == NULL)
514 {
515 temp = clas;
1777feb0
MS
516 methods = value_struct_elt (&temp, NULL, "methods",
517 NULL, "structure");
c906108c
SS
518 method = value_ind (methods);
519 }
520 else
1777feb0 521 { /* Re-use method value for next method. */
42ae5230
TT
522 CORE_ADDR addr
523 = value_address (method) + TYPE_LENGTH (value_type (method));
e0881a8e 524
42ae5230 525 set_value_address (method, addr);
dfa52d88 526 set_value_lazy (method, 1);
c906108c
SS
527 }
528
1777feb0 529 /* Get method name. */
c906108c
SS
530 temp = method;
531 temp = value_struct_elt (&temp, NULL, "name", NULL, "structure");
b99607ea 532 mname = get_java_utf8_name (&objfile->objfile_obstack, temp);
c906108c
SS
533 if (strcmp (mname, "<init>") == 0)
534 mname = unqualified_name;
535
536 /* Check for an existing method with the same name.
537 * This makes building the fn_fieldslists an O(nmethods**2)
538 * operation. That could be using hashing, but I doubt it
539 * is worth it. Note that we do maintain the order of methods
540 * in the inferior's Method table (as long as that is grouped
541 * by method name), which I think is desirable. --PB */
c5aa993b 542 for (k = 0, j = TYPE_NFN_FIELDS (type);;)
c906108c
SS
543 {
544 if (--j < 0)
1777feb0 545 { /* No match - new method name. */
c5aa993b 546 j = TYPE_NFN_FIELDS (type)++;
c906108c
SS
547 fn_fieldlists[j].name = mname;
548 fn_fieldlists[j].length = 1;
549 fn_fieldlists[j].fn_fields = &fn_fields[i];
550 k = i;
551 break;
552 }
553 if (strcmp (mname, fn_fieldlists[j].name) == 0)
1777feb0 554 { /* Found an existing method with the same name. */
c906108c 555 int l;
e0881a8e 556
c906108c 557 if (mname != unqualified_name)
b99607ea 558 obstack_free (&objfile->objfile_obstack, mname);
c906108c
SS
559 mname = fn_fieldlists[j].name;
560 fn_fieldlists[j].length++;
1777feb0
MS
561 k = i - k; /* Index of new slot. */
562 /* Shift intervening fn_fields (between k and i) down. */
c5aa993b
JM
563 for (l = i; l > k; l--)
564 fn_fields[l] = fn_fields[l - 1];
565 for (l = TYPE_NFN_FIELDS (type); --l > j;)
c906108c
SS
566 fn_fieldlists[l].fn_fields++;
567 break;
568 }
569 k += fn_fieldlists[j].length;
570 }
571 fn_fields[k].physname = "";
572 fn_fields[k].is_stub = 1;
323427d1 573 /* FIXME */
0daa2b63
UW
574 fn_fields[k].type = lookup_function_type
575 (builtin_java_type (gdbarch)->builtin_void);
c906108c
SS
576 TYPE_CODE (fn_fields[k].type) = TYPE_CODE_METHOD;
577 }
578
c5aa993b
JM
579 j = TYPE_NFN_FIELDS (type) * sizeof (struct fn_fieldlist);
580 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
86cc0029 581 obstack_alloc (&objfile->objfile_obstack, j);
c906108c 582 memcpy (TYPE_FN_FIELDLISTS (type), fn_fieldlists, j);
c5aa993b 583
c906108c
SS
584 return type;
585}
586
c906108c 587struct type *
fba45db2 588get_java_object_type (void)
c906108c 589{
86cc0029 590 struct symbol *sym;
e0881a8e 591
86cc0029
TT
592 sym = lookup_symbol ("java.lang.Object", NULL, STRUCT_DOMAIN, NULL);
593 if (sym == NULL)
594 error (_("cannot find java.lang.Object"));
595 return SYMBOL_TYPE (sym);
c906108c
SS
596}
597
598int
45d5d5ca 599get_java_object_header_size (struct gdbarch *gdbarch)
c906108c
SS
600{
601 struct type *objtype = get_java_object_type ();
e0881a8e 602
c906108c 603 if (objtype == NULL)
45d5d5ca 604 return (2 * gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
c906108c
SS
605 else
606 return TYPE_LENGTH (objtype);
607}
608
609int
fba45db2 610is_object_type (struct type *type)
c906108c
SS
611{
612 CHECK_TYPEDEF (type);
613 if (TYPE_CODE (type) == TYPE_CODE_PTR)
614 {
615 struct type *ttype = check_typedef (TYPE_TARGET_TYPE (type));
0d5cff50 616 const char *name;
c906108c
SS
617 if (TYPE_CODE (ttype) != TYPE_CODE_STRUCT)
618 return 0;
619 while (TYPE_N_BASECLASSES (ttype) > 0)
620 ttype = TYPE_BASECLASS (ttype, 0);
621 name = TYPE_TAG_NAME (ttype);
622 if (name != NULL && strcmp (name, "java.lang.Object") == 0)
623 return 1;
1777feb0
MS
624 name
625 = TYPE_NFIELDS (ttype) > 0 ? TYPE_FIELD_NAME (ttype, 0) : (char *) 0;
c906108c 626 if (name != NULL && strcmp (name, "vtable") == 0)
86cc0029 627 return 1;
c906108c
SS
628 }
629 return 0;
630}
631
632struct type *
0daa2b63 633java_primitive_type (struct gdbarch *gdbarch, int signature)
c906108c 634{
0daa2b63
UW
635 const struct builtin_java_type *builtin = builtin_java_type (gdbarch);
636
c906108c
SS
637 switch (signature)
638 {
c5aa993b 639 case 'B':
0daa2b63 640 return builtin->builtin_byte;
c5aa993b 641 case 'S':
0daa2b63 642 return builtin->builtin_short;
c5aa993b 643 case 'I':
0daa2b63 644 return builtin->builtin_int;
c5aa993b 645 case 'J':
0daa2b63 646 return builtin->builtin_long;
c5aa993b 647 case 'Z':
0daa2b63 648 return builtin->builtin_boolean;
c5aa993b 649 case 'C':
0daa2b63 650 return builtin->builtin_char;
c5aa993b 651 case 'F':
0daa2b63 652 return builtin->builtin_float;
c5aa993b 653 case 'D':
0daa2b63 654 return builtin->builtin_double;
c5aa993b 655 case 'V':
0daa2b63 656 return builtin->builtin_void;
c906108c 657 }
8a3fe4f8 658 error (_("unknown signature '%c' for primitive type"), (char) signature);
c906108c
SS
659}
660
661/* If name[0 .. namelen-1] is the name of a primitive Java type,
1777feb0 662 return that type. Otherwise, return NULL. */
c906108c
SS
663
664struct type *
0daa2b63 665java_primitive_type_from_name (struct gdbarch *gdbarch,
0d5cff50 666 const char *name, int namelen)
c906108c 667{
0daa2b63
UW
668 const struct builtin_java_type *builtin = builtin_java_type (gdbarch);
669
c906108c
SS
670 switch (name[0])
671 {
672 case 'b':
673 if (namelen == 4 && memcmp (name, "byte", 4) == 0)
0daa2b63 674 return builtin->builtin_byte;
c906108c 675 if (namelen == 7 && memcmp (name, "boolean", 7) == 0)
0daa2b63 676 return builtin->builtin_boolean;
c906108c
SS
677 break;
678 case 'c':
679 if (namelen == 4 && memcmp (name, "char", 4) == 0)
0daa2b63 680 return builtin->builtin_char;
3ef09ab5 681 break;
c906108c
SS
682 case 'd':
683 if (namelen == 6 && memcmp (name, "double", 6) == 0)
0daa2b63 684 return builtin->builtin_double;
c906108c
SS
685 break;
686 case 'f':
687 if (namelen == 5 && memcmp (name, "float", 5) == 0)
0daa2b63 688 return builtin->builtin_float;
c906108c
SS
689 break;
690 case 'i':
691 if (namelen == 3 && memcmp (name, "int", 3) == 0)
0daa2b63 692 return builtin->builtin_int;
c906108c
SS
693 break;
694 case 'l':
695 if (namelen == 4 && memcmp (name, "long", 4) == 0)
0daa2b63 696 return builtin->builtin_long;
c906108c
SS
697 break;
698 case 's':
699 if (namelen == 5 && memcmp (name, "short", 5) == 0)
0daa2b63 700 return builtin->builtin_short;
c906108c
SS
701 break;
702 case 'v':
703 if (namelen == 4 && memcmp (name, "void", 4) == 0)
0daa2b63 704 return builtin->builtin_void;
c906108c
SS
705 break;
706 }
707 return NULL;
708}
709
0daa2b63
UW
710static char *
711java_primitive_type_name (int signature)
712{
713 switch (signature)
714 {
715 case 'B':
716 return "byte";
717 case 'S':
718 return "short";
719 case 'I':
720 return "int";
721 case 'J':
722 return "long";
723 case 'Z':
724 return "boolean";
725 case 'C':
726 return "char";
727 case 'F':
728 return "float";
729 case 'D':
730 return "double";
731 case 'V':
732 return "void";
733 }
734 error (_("unknown signature '%c' for primitive type"), (char) signature);
735}
736
c906108c 737/* Return the length (in bytes) of demangled name of the Java type
1777feb0 738 signature string SIGNATURE. */
c906108c
SS
739
740static int
0d5cff50 741java_demangled_signature_length (const char *signature)
c906108c
SS
742{
743 int array = 0;
e0881a8e 744
c5aa993b 745 for (; *signature == '['; signature++)
1777feb0 746 array += 2; /* Two chars for "[]". */
c906108c
SS
747 switch (signature[0])
748 {
749 case 'L':
1777feb0 750 /* Subtract 2 for 'L' and ';'. */
c906108c
SS
751 return strlen (signature) - 2 + array;
752 default:
0daa2b63 753 return strlen (java_primitive_type_name (signature[0])) + array;
c906108c
SS
754 }
755}
756
1777feb0
MS
757/* Demangle the Java type signature SIGNATURE, leaving the result in
758 RESULT. */
c906108c
SS
759
760static void
0d5cff50 761java_demangled_signature_copy (char *result, const char *signature)
c906108c
SS
762{
763 int array = 0;
764 char *ptr;
765 int i;
e0881a8e 766
c906108c
SS
767 while (*signature == '[')
768 {
769 array++;
770 signature++;
771 }
772 switch (signature[0])
773 {
774 case 'L':
1777feb0 775 /* Subtract 2 for 'L' and ';', but add 1 for final nul. */
c906108c
SS
776 signature++;
777 ptr = result;
c5aa993b 778 for (; *signature != ';' && *signature != '\0'; signature++)
c906108c
SS
779 {
780 if (*signature == '/')
781 *ptr++ = '.';
782 else
783 *ptr++ = *signature;
784 }
785 break;
786 default:
0daa2b63 787 ptr = java_primitive_type_name (signature[0]);
c906108c
SS
788 i = strlen (ptr);
789 strcpy (result, ptr);
790 ptr = result + i;
791 break;
792 }
793 while (--array >= 0)
794 {
795 *ptr++ = '[';
796 *ptr++ = ']';
797 }
798}
799
800/* Return the demangled name of the Java type signature string SIGNATURE,
1777feb0 801 as a freshly allocated copy. */
c906108c
SS
802
803char *
0d5cff50 804java_demangle_type_signature (const char *signature)
c906108c
SS
805{
806 int length = java_demangled_signature_length (signature);
807 char *result = xmalloc (length + 1);
e0881a8e 808
c906108c
SS
809 java_demangled_signature_copy (result, signature);
810 result[length] = '\0';
811 return result;
812}
813
c906108c 814/* Return the type of TYPE followed by DIMS pairs of [ ].
1777feb0 815 If DIMS == 0, TYPE is returned. */
c906108c
SS
816
817struct type *
fba45db2 818java_array_type (struct type *type, int dims)
c906108c 819{
c906108c
SS
820 while (dims-- > 0)
821 {
1777feb0 822 /* FIXME This is bogus! Java arrays are not gdb arrays! */
e3506a9f 823 type = lookup_array_range_type (type, 0, 0);
c906108c
SS
824 }
825
826 return type;
827}
828
1777feb0 829/* Create a Java string in the inferior from a (Utf8) literal. */
c906108c 830
75c9979e 831static struct value *
fba45db2 832java_value_string (char *ptr, int len)
c906108c 833{
8a3fe4f8 834 error (_("not implemented - java_value_string")); /* FIXME */
c906108c
SS
835}
836
127c81bc
TT
837/* Return the encoding that should be used for the character type
838 TYPE. */
839
840static const char *
841java_get_encoding (struct type *type)
842{
843 struct gdbarch *arch = get_type_arch (type);
844 const char *encoding;
845
846 if (type == builtin_java_type (arch)->builtin_char)
847 {
848 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
849 encoding = "UTF-16BE";
850 else
851 encoding = "UTF-16LE";
852 }
853 else
854 encoding = target_charset (arch);
855
856 return encoding;
857}
858
c906108c
SS
859/* Print the character C on STREAM as part of the contents of a literal
860 string whose delimiter is QUOTER. Note that that format for printing
1777feb0 861 characters and strings is language specific. */
c906108c
SS
862
863static void
6c7a06a3 864java_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
c906108c 865{
127c81bc
TT
866 const char *encoding = java_get_encoding (type);
867
868 generic_emit_char (c, type, stream, quoter, encoding);
869}
870
871/* Implementation of la_printchar method. */
872
873static void
874java_printchar (int c, struct type *type, struct ui_file *stream)
875{
876 fputs_filtered ("'", stream);
877 LA_EMIT_CHAR (c, type, stream, '\'');
878 fputs_filtered ("'", stream);
879}
880
881/* Implementation of la_printstr method. */
882
883static void
884java_printstr (struct ui_file *stream, struct type *type,
885 const gdb_byte *string,
886 unsigned int length, const char *encoding, int force_ellipses,
887 const struct value_print_options *options)
888{
889 const char *type_encoding = java_get_encoding (type);
890
891 if (!encoding || !*encoding)
892 encoding = type_encoding;
893
894 generic_printstr (stream, type, string, length, encoding,
895 force_ellipses, '"', 0, options);
c906108c
SS
896}
897
75c9979e 898static struct value *
f86f5ca3
PH
899evaluate_subexp_java (struct type *expect_type, struct expression *exp,
900 int *pos, enum noside noside)
c906108c
SS
901{
902 int pc = *pos;
903 int i;
0d5cff50 904 const char *name;
c906108c 905 enum exp_opcode op = exp->elts[*pos].opcode;
75c9979e
AC
906 struct value *arg1;
907 struct value *arg2;
c906108c 908 struct type *type;
e0881a8e 909
c906108c
SS
910 switch (op)
911 {
912 case UNOP_IND:
913 if (noside == EVAL_SKIP)
914 goto standard;
915 (*pos)++;
916 arg1 = evaluate_subexp_java (NULL_TYPE, exp, pos, EVAL_NORMAL);
df407dfe 917 if (is_object_type (value_type (arg1)))
c906108c
SS
918 {
919 struct type *type;
920
0daa2b63 921 type = type_from_class (exp->gdbarch, java_class_from_object (arg1));
c906108c
SS
922 arg1 = value_cast (lookup_pointer_type (type), arg1);
923 }
c906108c
SS
924 return value_ind (arg1);
925
926 case BINOP_SUBSCRIPT:
927 (*pos)++;
928 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
929 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
930 if (noside == EVAL_SKIP)
931 goto nosideret;
932 /* If the user attempts to subscript something that is not an
c5aa993b 933 array or pointer type (like a plain int variable for example),
1777feb0 934 then report this as an error. */
c5aa993b 935
994b9211 936 arg1 = coerce_ref (arg1);
df407dfe 937 type = check_typedef (value_type (arg1));
c906108c
SS
938 if (TYPE_CODE (type) == TYPE_CODE_PTR)
939 type = check_typedef (TYPE_TARGET_TYPE (type));
940 name = TYPE_NAME (type);
941 if (name == NULL)
942 name = TYPE_TAG_NAME (type);
943 i = name == NULL ? 0 : strlen (name);
944 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
c5aa993b 945 && i > 2 && name[i - 1] == ']')
c906108c 946 {
e17a4113 947 enum bfd_endian byte_order = gdbarch_byte_order (exp->gdbarch);
c906108c
SS
948 CORE_ADDR address;
949 long length, index;
950 struct type *el_type;
c68a6671 951 gdb_byte buf4[4];
c906108c 952
75c9979e
AC
953 struct value *clas = java_class_from_object (arg1);
954 struct value *temp = clas;
1777feb0 955 /* Get CLASS_ELEMENT_TYPE of the array type. */
c906108c 956 temp = value_struct_elt (&temp, NULL, "methods",
c5aa993b 957 NULL, "structure");
04624583 958 deprecated_set_value_type (temp, value_type (clas));
0daa2b63 959 el_type = type_from_class (exp->gdbarch, temp);
c906108c
SS
960 if (TYPE_CODE (el_type) == TYPE_CODE_STRUCT)
961 el_type = lookup_pointer_type (el_type);
962
963 if (noside == EVAL_AVOID_SIDE_EFFECTS)
964 return value_zero (el_type, VALUE_LVAL (arg1));
1aa20aa8 965 address = value_as_address (arg1);
45d5d5ca 966 address += get_java_object_header_size (exp->gdbarch);
c906108c 967 read_memory (address, buf4, 4);
e17a4113 968 length = (long) extract_signed_integer (buf4, 4, byte_order);
c906108c
SS
969 index = (long) value_as_long (arg2);
970 if (index >= length || index < 0)
8a3fe4f8 971 error (_("array index (%ld) out of bounds (length: %ld)"),
c906108c
SS
972 index, length);
973 address = (address + 4) + index * TYPE_LENGTH (el_type);
00a4c844 974 return value_at (el_type, address);
c906108c
SS
975 }
976 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
977 {
978 if (noside == EVAL_AVOID_SIDE_EFFECTS)
979 return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
980 else
2497b498 981 return value_subscript (arg1, value_as_long (arg2));
c906108c
SS
982 }
983 if (name)
8a3fe4f8 984 error (_("cannot subscript something of type `%s'"), name);
c906108c 985 else
8a3fe4f8 986 error (_("cannot subscript requested type"));
c906108c
SS
987
988 case OP_STRING:
989 (*pos)++;
990 i = longest_to_int (exp->elts[pc + 1].longconst);
991 (*pos) += 3 + BYTES_TO_EXP_ELEM (i + 1);
992 if (noside == EVAL_SKIP)
993 goto nosideret;
994 return java_value_string (&exp->elts[pc + 2].string, i);
995
dc5000e7 996 case STRUCTOP_PTR:
c906108c 997 arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
1777feb0 998 /* Convert object field (such as TYPE.class) to reference. */
df407dfe 999 if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_STRUCT)
c906108c
SS
1000 arg1 = value_addr (arg1);
1001 return arg1;
1002 default:
1003 break;
1004 }
1005standard:
1006 return evaluate_subexp_standard (expect_type, exp, pos, noside);
c5aa993b 1007nosideret:
22601c15 1008 return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
c906108c
SS
1009}
1010
9a3d7dfd
AF
1011static char *java_demangle (const char *mangled, int options)
1012{
1013 return cplus_demangle (mangled, options | DMGL_JAVA);
1014}
1015
31c27f77
JJ
1016/* Find the member function name of the demangled name NAME. NAME
1017 must be a method name including arguments, in order to correctly
1018 locate the last component.
1019
1020 This function return a pointer to the first dot before the
1021 member function name, or NULL if the name was not of the
1022 expected form. */
1023
1024static const char *
1025java_find_last_component (const char *name)
1026{
1027 const char *p;
1028
1029 /* Find argument list. */
1030 p = strchr (name, '(');
1031
1032 if (p == NULL)
1033 return NULL;
1034
1035 /* Back up and find first dot prior to argument list. */
1036 while (p > name && *p != '.')
1037 p--;
1038
1039 if (p == name)
1040 return NULL;
1041
1042 return p;
1043}
1044
1045/* Return the name of the class containing method PHYSNAME. */
1046
1047static char *
1048java_class_name_from_physname (const char *physname)
1049{
1050 char *ret = NULL;
1051 const char *end;
31c27f77
JJ
1052 char *demangled_name = java_demangle (physname, DMGL_PARAMS | DMGL_ANSI);
1053
1054 if (demangled_name == NULL)
1055 return NULL;
1056
1057 end = java_find_last_component (demangled_name);
1058 if (end != NULL)
1059 {
1060 ret = xmalloc (end - demangled_name + 1);
1061 memcpy (ret, demangled_name, end - demangled_name);
1062 ret[end - demangled_name] = '\0';
1063 }
1064
1065 xfree (demangled_name);
1066 return ret;
1067}
9a3d7dfd 1068
c906108c
SS
1069/* Table mapping opcodes into strings for printing operators
1070 and precedences of the operators. */
1071
1072const struct op_print java_op_print_tab[] =
c5aa993b
JM
1073{
1074 {",", BINOP_COMMA, PREC_COMMA, 0},
1075 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1076 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
1077 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
1078 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
1079 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
1080 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
1081 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
1082 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1083 {"<=", BINOP_LEQ, PREC_ORDER, 0},
1084 {">=", BINOP_GEQ, PREC_ORDER, 0},
1085 {">", BINOP_GTR, PREC_ORDER, 0},
1086 {"<", BINOP_LESS, PREC_ORDER, 0},
1087 {">>", BINOP_RSH, PREC_SHIFT, 0},
1088 {"<<", BINOP_LSH, PREC_SHIFT, 0},
c5aa993b
JM
1089 {"+", BINOP_ADD, PREC_ADD, 0},
1090 {"-", BINOP_SUB, PREC_ADD, 0},
1091 {"*", BINOP_MUL, PREC_MUL, 0},
1092 {"/", BINOP_DIV, PREC_MUL, 0},
1093 {"%", BINOP_REM, PREC_MUL, 0},
1094 {"-", UNOP_NEG, PREC_PREFIX, 0},
1095 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
1096 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
1097 {"*", UNOP_IND, PREC_PREFIX, 0},
c5aa993b
JM
1098 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
1099 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
1100 {NULL, 0, 0, 0}
c906108c
SS
1101};
1102
de7b6b47
UW
1103enum java_primitive_types
1104{
1105 java_primitive_type_int,
1106 java_primitive_type_short,
1107 java_primitive_type_long,
1108 java_primitive_type_byte,
1109 java_primitive_type_boolean,
1110 java_primitive_type_char,
1111 java_primitive_type_float,
1112 java_primitive_type_double,
1113 java_primitive_type_void,
1114 nr_java_primitive_types
1115};
1116
2c0b251b 1117static void
de7b6b47
UW
1118java_language_arch_info (struct gdbarch *gdbarch,
1119 struct language_arch_info *lai)
1120{
0daa2b63
UW
1121 const struct builtin_java_type *builtin = builtin_java_type (gdbarch);
1122
1123 lai->string_char_type = builtin->builtin_char;
de7b6b47
UW
1124 lai->primitive_type_vector
1125 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_java_primitive_types + 1,
1126 struct type *);
1127 lai->primitive_type_vector [java_primitive_type_int]
0daa2b63 1128 = builtin->builtin_int;
de7b6b47 1129 lai->primitive_type_vector [java_primitive_type_short]
0daa2b63 1130 = builtin->builtin_short;
de7b6b47 1131 lai->primitive_type_vector [java_primitive_type_long]
0daa2b63 1132 = builtin->builtin_long;
de7b6b47 1133 lai->primitive_type_vector [java_primitive_type_byte]
0daa2b63 1134 = builtin->builtin_byte;
de7b6b47 1135 lai->primitive_type_vector [java_primitive_type_boolean]
0daa2b63 1136 = builtin->builtin_boolean;
de7b6b47 1137 lai->primitive_type_vector [java_primitive_type_char]
0daa2b63 1138 = builtin->builtin_char;
de7b6b47 1139 lai->primitive_type_vector [java_primitive_type_float]
0daa2b63 1140 = builtin->builtin_float;
de7b6b47 1141 lai->primitive_type_vector [java_primitive_type_double]
0daa2b63 1142 = builtin->builtin_double;
de7b6b47 1143 lai->primitive_type_vector [java_primitive_type_void]
0daa2b63 1144 = builtin->builtin_void;
fbb06eb1
UW
1145
1146 lai->bool_type_symbol = "boolean";
0daa2b63 1147 lai->bool_type_default = builtin->builtin_boolean;
de7b6b47
UW
1148}
1149
5f9769d1
PH
1150const struct exp_descriptor exp_descriptor_java =
1151{
1152 print_subexp_standard,
1153 operator_length_standard,
c0201579 1154 operator_check_standard,
5f9769d1
PH
1155 op_name_standard,
1156 dump_subexp_body_standard,
1157 evaluate_subexp_java
1158};
1159
c5aa993b
JM
1160const struct language_defn java_language_defn =
1161{
1162 "java", /* Language name */
c906108c 1163 language_java,
c906108c 1164 range_check_off,
63872f9d 1165 case_sensitive_on,
7ca2d3a3 1166 array_row_major,
9a044a89 1167 macro_expansion_no,
5f9769d1 1168 &exp_descriptor_java,
c906108c
SS
1169 java_parse,
1170 java_error,
e85c3284 1171 null_post_parser,
127c81bc
TT
1172 java_printchar, /* Print a character constant */
1173 java_printstr, /* Function to print string constant */
c906108c 1174 java_emit_char, /* Function to print a single character */
c906108c 1175 java_print_type, /* Print a type using appropriate syntax */
5c6ce71d 1176 default_print_typedef, /* Print a typedef using appropriate syntax */
c906108c
SS
1177 java_val_print, /* Print a value using appropriate syntax */
1178 java_value_print, /* Print a top-level value */
a5ee536b 1179 default_read_var_value, /* la_read_var_value */
f636b87d 1180 NULL, /* Language specific skip_trampoline */
2b2d9e11 1181 "this", /* name_of_this */
5f9a71c3 1182 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 1183 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 1184 java_demangle, /* Language specific symbol demangler */
31c27f77 1185 java_class_name_from_physname,/* Language specific class name */
c906108c
SS
1186 java_op_print_tab, /* expression operators for printing */
1187 0, /* not c-style arrays */
1188 0, /* String lower bound */
6084f43a 1189 default_word_break_characters,
41d27058 1190 default_make_symbol_completion_list,
de7b6b47 1191 java_language_arch_info,
e79af960 1192 default_print_array_index,
41f1b697 1193 default_pass_by_reference,
ae6a3a4c 1194 default_get_string,
1a119f36 1195 NULL, /* la_get_symbol_name_cmp */
f8eba3c6 1196 iterate_over_symbols,
c906108c
SS
1197 LANG_MAGIC
1198};
1199
0daa2b63
UW
1200static void *
1201build_java_types (struct gdbarch *gdbarch)
1202{
1203 struct builtin_java_type *builtin_java_type
1204 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_java_type);
1205
1206 builtin_java_type->builtin_int
e9bb382b 1207 = arch_integer_type (gdbarch, 32, 0, "int");
0daa2b63 1208 builtin_java_type->builtin_short
e9bb382b 1209 = arch_integer_type (gdbarch, 16, 0, "short");
0daa2b63 1210 builtin_java_type->builtin_long
e9bb382b 1211 = arch_integer_type (gdbarch, 64, 0, "long");
0daa2b63 1212 builtin_java_type->builtin_byte
e9bb382b 1213 = arch_integer_type (gdbarch, 8, 0, "byte");
0daa2b63 1214 builtin_java_type->builtin_boolean
e9bb382b 1215 = arch_boolean_type (gdbarch, 8, 0, "boolean");
0daa2b63 1216 builtin_java_type->builtin_char
e9bb382b 1217 = arch_character_type (gdbarch, 16, 1, "char");
0daa2b63 1218 builtin_java_type->builtin_float
e9bb382b 1219 = arch_float_type (gdbarch, 32, "float", NULL);
0daa2b63 1220 builtin_java_type->builtin_double
e9bb382b 1221 = arch_float_type (gdbarch, 64, "double", NULL);
0daa2b63 1222 builtin_java_type->builtin_void
e9bb382b 1223 = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
0daa2b63
UW
1224
1225 return builtin_java_type;
1226}
1227
1228static struct gdbarch_data *java_type_data;
1229
1230const struct builtin_java_type *
1231builtin_java_type (struct gdbarch *gdbarch)
1232{
1233 return gdbarch_data (gdbarch, java_type_data);
1234}
1235
c906108c 1236void
fba45db2 1237_initialize_java_language (void)
c906108c 1238{
20781792
TT
1239 jv_dynamics_objfile_data_key
1240 = register_objfile_data_with_cleanup (NULL, jv_per_objfile_free);
86cc0029 1241 jv_dynamics_progspace_key = register_program_space_data ();
20781792 1242
0daa2b63 1243 java_type_data = gdbarch_data_register_post_init (build_java_types);
c906108c
SS
1244
1245 add_language (&java_language_defn);
1246}