]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/java/lang.c
Merge from pch-branch up to tag pch-commit-20020603.
[thirdparty/gcc.git] / gcc / java / lang.c
CommitLineData
e04a16fb 1/* Java(TM) language-specific utility routines.
a5a4ce3c
NB
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
e04a16fb
AG
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA.
21
22Java and all Java-based marks are trademarks or registered trademarks
23of Sun Microsystems, Inc. in the United States and other countries.
24The Free Software Foundation is independent of Sun Microsystems, Inc. */
25
26/* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
27
e04a16fb 28#include "config.h"
1f43f4b4 29#include "system.h"
e04a16fb
AG
30#include "tree.h"
31#include "input.h"
49f48c71
KG
32#include "rtl.h"
33#include "expr.h"
e04a16fb
AG
34#include "java-tree.h"
35#include "jcf.h"
1f43f4b4 36#include "toplev.h"
c83303d8 37#include "langhooks.h"
d23c55c2 38#include "langhooks-def.h"
fc45c7ef 39#include "flags.h"
235acd35 40#include "xref.h"
19e223db 41#include "ggc.h"
46f018e1 42#include "diagnostic.h"
e04a16fb 43
b7436b72
TT
44struct string_option
45{
0b5826ac
KG
46 const char *const string;
47 int *const variable;
48 const int on_value;
b7436b72
TT
49};
50
f5e99456 51static const char *java_init PARAMS ((const char *));
22703ccc 52static void java_finish PARAMS ((void));
ee811cfd
NB
53static void java_init_options PARAMS ((void));
54static int java_decode_option PARAMS ((int, char **));
df32d2ce
KG
55static void put_decl_string PARAMS ((const char *, int));
56static void put_decl_node PARAMS ((tree));
7cb32822
NB
57static void java_print_error_function PARAMS ((diagnostic_context *,
58 const char *));
0b5826ac
KG
59static int process_option_with_no PARAMS ((const char *,
60 const struct string_option *,
b7436b72 61 int));
c8e7d2e6 62
45936a85
DD
63#ifndef TARGET_OBJECT_SUFFIX
64# define TARGET_OBJECT_SUFFIX ".o"
8603f9c5
TT
65#endif
66
e4de5a10
PB
67/* Table indexed by tree code giving a string containing a character
68 classifying the tree code. Possibilities are
69 t, d, s, c, r, <, 1 and 2. See java/java-tree.def for details. */
70
71#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
72
2f9834e8
KG
73const char tree_code_type[] = {
74#include "tree.def"
e4de5a10
PB
75 'x',
76#include "java-tree.def"
77};
78#undef DEFTREECODE
79
80/* Table indexed by tree code giving number of expression
81 operands beyond the fixed part of the node structure.
82 Not used for types or decls. */
83
84#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
85
2f9834e8
KG
86const unsigned char tree_code_length[] = {
87#include "tree.def"
e4de5a10
PB
88 0,
89#include "java-tree.def"
90};
91#undef DEFTREECODE
92
93/* Names of tree components.
94 Used for printing out the tree and error messages. */
95#define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
96
2f9834e8
KG
97const char *const tree_code_name[] = {
98#include "tree.def"
e4de5a10
PB
99 "@@dummy",
100#include "java-tree.def"
101};
102#undef DEFTREECODE
103
7cb32822
NB
104/* Used to avoid printing error messages with bogus function
105 prototypes. Starts out false. */
106static bool inhibit_error_function_printing;
107
e04a16fb
AG
108int compiling_from_source;
109
7be5b0e5
AG
110char * resource_name;
111
e04a16fb
AG
112int flag_emit_class_files = 0;
113
fea2d5da
PB
114/* Nonzero if input file is a file with a list of filenames to compile. */
115
116int flag_filelist_file = 0;
117
235acd35
APB
118/* When non zero, we emit xref strings. Values of the flag for xref
119 backends are defined in xref_flag_table, xref.c. */
120
121int flag_emit_xref = 0;
122
c877974e
APB
123/* When non zero, -Wall was turned on. */
124int flag_wall = 0;
125
5f1c312a 126/* When non zero, check for redundant modifier uses. */
c877974e
APB
127int flag_redundant = 0;
128
aa4759c1
AH
129/* When non zero, call a library routine to do integer divisions. */
130int flag_use_divide_subroutine = 1;
131
5830574a
TT
132/* When non zero, generate code for the Boehm GC. */
133int flag_use_boehm_gc = 0;
134
64aa33dd
TT
135/* When non zero, assume the runtime uses a hash table to map an
136 object to its synchronization structure. */
137int flag_hash_synchronization;
138
7145d9fe
TT
139/* When non zero, assume all native functions are implemented with
140 JNI, not CNI. */
141int flag_jni = 0;
142
b7436b72
TT
143/* When non zero, warn when source file is newer than matching class
144 file. */
145int flag_newer = 1;
146
4ff17c6a
AH
147/* When non zero, generate checks for references to NULL. */
148int flag_check_references = 0;
149
d19cbcb5 150/* The encoding of the source file. */
a93eddcf 151const char *current_encoding = NULL;
d19cbcb5 152
5f1c312a
APB
153/* When non zero, report the now deprecated empty statements. */
154int flag_extraneous_semicolon;
155
b124f72e
APB
156/* When non zero, always check for a non gcj generated classes archive. */
157int flag_force_classes_archive_check;
158
4009bb7d
APB
159/* When zero, don't optimize static class initialization. This flag shouldn't
160 be tested alone, use STATIC_CLASS_INITIALIZATION_OPTIMIZATION_P instead. */
161int flag_optimize_sci = 1;
162
861ef928
BM
163/* When non zero, use offset tables for virtual method calls
164 in order to improve binary compatibility. */
165int flag_indirect_dispatch = 0;
166
022dcc46
BM
167/* When zero, don't generate runtime array store checks. */
168int flag_store_check = 1;
169
4266d0b2
TT
170/* When non zero, print extra version information. */
171static int version_flag = 0;
172
e04a16fb
AG
173/* Table of language-dependent -f options.
174 STRING is the option name. VARIABLE is the address of the variable.
175 ON_VALUE is the value to store in VARIABLE
176 if `-fSTRING' is seen as an option.
177 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
178
0b5826ac 179static const struct string_option
4bcde32e 180lang_f_options[] =
e04a16fb 181{
e04a16fb
AG
182 {"emit-class-file", &flag_emit_class_files, 1},
183 {"emit-class-files", &flag_emit_class_files, 1},
fea2d5da 184 {"filelist-file", &flag_filelist_file, 1},
aa4759c1 185 {"use-divide-subroutine", &flag_use_divide_subroutine, 1},
64aa33dd 186 {"use-boehm-gc", &flag_use_boehm_gc, 1},
7145d9fe 187 {"hash-synchronization", &flag_hash_synchronization, 1},
4ff17c6a
AH
188 {"jni", &flag_jni, 1},
189 {"check-references", &flag_check_references, 1},
8f25dc28 190 {"force-classes-archive-check", &flag_force_classes_archive_check, 1},
861ef928 191 {"optimize-static-class-initialization", &flag_optimize_sci, 1 },
022dcc46
BM
192 {"indirect-dispatch", &flag_indirect_dispatch, 1},
193 {"store-check", &flag_store_check, 1}
e04a16fb
AG
194};
195
0b5826ac 196static const struct string_option
b7436b72
TT
197lang_W_options[] =
198{
b7436b72
TT
199 { "redundant-modifiers", &flag_redundant, 1 },
200 { "extraneous-semicolon", &flag_extraneous_semicolon, 1 },
201 { "out-of-date", &flag_newer, 1 }
202};
203
e04a16fb
AG
204JCF *current_jcf;
205
fc45c7ef 206/* Variable controlling how dependency tracking is enabled in
f5e99456 207 java_init. */
fc45c7ef
TT
208static int dependency_tracking = 0;
209
210/* Flag values for DEPENDENCY_TRACKING. */
211#define DEPEND_SET_FILE 1
212#define DEPEND_ENABLE 2
316a06a1
TT
213#define DEPEND_TARGET_SET 4
214#define DEPEND_FILE_ALREADY_SET 8
fc45c7ef 215
e2500fed
GK
216struct language_function GTY(())
217{
218 int unused;
219};
220
3ac88239
NB
221#undef LANG_HOOKS_NAME
222#define LANG_HOOKS_NAME "GNU Java"
c83303d8
APB
223#undef LANG_HOOKS_INIT
224#define LANG_HOOKS_INIT java_init
22703ccc
NB
225#undef LANG_HOOKS_FINISH
226#define LANG_HOOKS_FINISH java_finish
c83303d8
APB
227#undef LANG_HOOKS_INIT_OPTIONS
228#define LANG_HOOKS_INIT_OPTIONS java_init_options
229#undef LANG_HOOKS_DECODE_OPTION
230#define LANG_HOOKS_DECODE_OPTION java_decode_option
52dabb6c
NB
231#undef LANG_HOOKS_PARSE_FILE
232#define LANG_HOOKS_PARSE_FILE java_parse_file
dffd7eb6
NB
233#undef LANG_HOOKS_MARK_ADDRESSABLE
234#define LANG_HOOKS_MARK_ADDRESSABLE java_mark_addressable
c9d892a8
NB
235#undef LANG_HOOKS_EXPAND_EXPR
236#define LANG_HOOKS_EXPAND_EXPR java_expand_expr
78ef5b89
NB
237#undef LANG_HOOKS_TRUTHVALUE_CONVERSION
238#define LANG_HOOKS_TRUTHVALUE_CONVERSION java_truthvalue_conversion
63e1b1c4
NB
239#undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
240#define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL java_dup_lang_specific_decl
7afff7cf
NB
241#undef LANG_HOOKS_DECL_PRINTABLE_NAME
242#define LANG_HOOKS_DECL_PRINTABLE_NAME lang_printable_name
7cb32822
NB
243#undef LANG_HOOKS_PRINT_ERROR_FUNCTION
244#define LANG_HOOKS_PRINT_ERROR_FUNCTION java_print_error_function
ceef8ce4 245
b0c48229
NB
246#undef LANG_HOOKS_TYPE_FOR_MODE
247#define LANG_HOOKS_TYPE_FOR_MODE java_type_for_mode
248#undef LANG_HOOKS_TYPE_FOR_SIZE
249#define LANG_HOOKS_TYPE_FOR_SIZE java_type_for_size
ceef8ce4
NB
250#undef LANG_HOOKS_SIGNED_TYPE
251#define LANG_HOOKS_SIGNED_TYPE java_signed_type
252#undef LANG_HOOKS_UNSIGNED_TYPE
253#define LANG_HOOKS_UNSIGNED_TYPE java_unsigned_type
254#undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
255#define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE java_signed_or_unsigned_type
c83303d8 256
cd2a3ba2 257/* Each front end provides its own. */
3ac88239 258const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
cd2a3ba2 259
b7436b72
TT
260/* Process an option that can accept a `no-' form.
261 Return 1 if option found, 0 otherwise. */
262static int
263process_option_with_no (p, table, table_size)
0b5826ac
KG
264 const char *p;
265 const struct string_option *table;
b7436b72
TT
266 int table_size;
267{
268 int j;
269
270 for (j = 0; j < table_size; j++)
271 {
272 if (!strcmp (p, table[j].string))
273 {
274 *table[j].variable = table[j].on_value;
275 return 1;
276 }
277 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
278 && ! strcmp (p+3, table[j].string))
279 {
280 *table[j].variable = ! table[j].on_value;
281 return 1;
282 }
283 }
284
285 return 0;
286}
287
e04a16fb
AG
288/*
289 * process java-specific compiler command-line options
03d32d1a 290 * return 0, but do not complain if the option is not recognised.
e04a16fb 291 */
ee811cfd
NB
292static int
293java_decode_option (argc, argv)
0a2138e2 294 int argc __attribute__ ((__unused__));
e04a16fb
AG
295 char **argv;
296{
297 char *p = argv[0];
71f6a8e2 298
2a85660d
PB
299 jcf_path_init ();
300
4266d0b2
TT
301 if (strcmp (p, "-version") == 0)
302 {
303 version_flag = 1;
304 /* We return 0 so that the caller can process this. */
305 return 0;
306 }
307
7be5b0e5
AG
308#define CLARG "-fcompile-resource="
309 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
310 {
311 resource_name = p + sizeof (CLARG) - 1;
312 return 1;
313 }
314#undef CLARG
48aedbca
AG
315#define CLARG "-fassume-compiled="
316 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
317 {
318 add_assume_compiled (p + sizeof (CLARG) - 1, 0);
319 return 1;
320 }
321#undef CLARG
322#define CLARG "-fno-assume-compiled="
323 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
324 {
325 add_assume_compiled (p + sizeof (CLARG) - 1, 1);
326 return 1;
327 }
328#undef CLARG
329#define CLARG "-fassume-compiled"
330 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
331 {
332 add_assume_compiled ("", 0);
333 return 1;
334 }
335#undef CLARG
336#define CLARG "-fno-assume-compiled"
337 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
338 {
339 add_assume_compiled ("", 1);
340 return 1;
341 }
342#undef CLARG
db444fbe 343#define CLARG "-fCLASSPATH="
71f6a8e2
TT
344 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
345 {
2a85660d 346 jcf_path_classpath_arg (p + sizeof (CLARG) - 1);
71f6a8e2
TT
347 return 1;
348 }
349#undef CLARG
db444fbe 350#define CLARG "-fclasspath="
48aedbca 351 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
71f6a8e2 352 {
db444fbe 353 jcf_path_classpath_arg (p + sizeof (CLARG) - 1);
71f6a8e2
TT
354 return 1;
355 }
2a85660d
PB
356#undef CLARG
357#define CLARG "-fbootclasspath="
358 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
359 {
360 jcf_path_bootclasspath_arg (p + sizeof (CLARG) - 1);
361 return 1;
362 }
9fef1fe3
AG
363#undef CLARG
364#define CLARG "-fextdirs="
365 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
366 {
367 jcf_path_extdirs_arg (p + sizeof (CLARG) - 1);
368 return 1;
369 }
71f6a8e2
TT
370#undef CLARG
371 else if (strncmp (p, "-I", 2) == 0)
372 {
373 jcf_path_include_arg (p + 2);
374 return 1;
375 }
376
df66b566
TT
377#define ARG "-foutput-class-dir="
378 if (strncmp (p, ARG, sizeof (ARG) - 1) == 0)
379 {
380 jcf_write_base_directory = p + sizeof (ARG) - 1;
381 return 1;
382 }
383#undef ARG
d19cbcb5
TT
384#define ARG "-fencoding="
385 if (strncmp (p, ARG, sizeof (ARG) - 1) == 0)
386 {
387 current_encoding = p + sizeof (ARG) - 1;
388 return 1;
389 }
390#undef ARG
df66b566 391
e04a16fb
AG
392 if (p[0] == '-' && p[1] == 'f')
393 {
394 /* Some kind of -f option.
395 P's value is the option sans `-f'.
396 Search for it in the table of options. */
e04a16fb 397 p += 2;
12cfb4fc
TT
398 if (process_option_with_no (p, lang_f_options,
399 ARRAY_SIZE (lang_f_options)))
400 return 1;
401 return dump_switch_p (p);
e04a16fb
AG
402 }
403
c877974e
APB
404 if (strcmp (p, "-Wall") == 0)
405 {
406 flag_wall = 1;
407 flag_redundant = 1;
5f1c312a 408 flag_extraneous_semicolon = 1;
ae23f3ed
TT
409 /* When -Wall given, enable -Wunused. We do this because the C
410 compiler does it, and people expect it. */
078721e1 411 set_Wunused (1);
7f10c2e2
APB
412 return 1;
413 }
414
b7436b72 415 if (p[0] == '-' && p[1] == 'W')
7f10c2e2 416 {
b7436b72
TT
417 /* Skip `-W' and see if we accept the option or its `no-' form. */
418 p += 2;
419 return process_option_with_no (p, lang_W_options,
420 ARRAY_SIZE (lang_W_options));
5f1c312a
APB
421 }
422
fc45c7ef
TT
423 if (strcmp (p, "-MD") == 0)
424 {
425 jcf_dependency_init (1);
426 dependency_tracking |= DEPEND_SET_FILE | DEPEND_ENABLE;
427 return 1;
428 }
429 else if (strcmp (p, "-MMD") == 0)
430 {
431 jcf_dependency_init (0);
432 dependency_tracking |= DEPEND_SET_FILE | DEPEND_ENABLE;
433 return 1;
434 }
435 else if (strcmp (p, "-M") == 0)
436 {
437 jcf_dependency_init (1);
438 dependency_tracking |= DEPEND_ENABLE;
439 return 1;
440 }
441 else if (strcmp (p, "-MM") == 0)
442 {
443 jcf_dependency_init (0);
444 dependency_tracking |= DEPEND_ENABLE;
445 return 1;
446 }
a5a4ce3c 447 else if (strcmp (p, "-MP") == 0)
316a06a1
TT
448 {
449 jcf_dependency_print_dummies ();
450 return 1;
451 }
452 else if (strcmp (p, "-MT") == 0)
453 {
454 jcf_dependency_set_target (argv[1]);
455 dependency_tracking |= DEPEND_TARGET_SET;
456 return 2;
457 }
458 else if (strcmp (p, "-MF") == 0)
459 {
460 jcf_dependency_set_dep_file (argv[1]);
461 dependency_tracking |= DEPEND_FILE_ALREADY_SET;
462 return 2;
463 }
fc45c7ef 464
e04a16fb
AG
465 return 0;
466}
467
d19cbcb5 468/* Global open file. */
e04a16fb 469FILE *finput;
d19cbcb5 470
f5e99456
NB
471static const char *
472java_init (filename)
3b304f5b 473 const char *filename;
e04a16fb 474{
f5e99456
NB
475#if 0
476 extern int flag_minimal_debug;
477 flag_minimal_debug = 0;
478#endif
479
e04a16fb
AG
480 /* Open input file. */
481
482 if (filename == 0 || !strcmp (filename, "-"))
483 {
484 finput = stdin;
485 filename = "stdin";
fc45c7ef
TT
486
487 if (dependency_tracking)
488 error ("can't do dependency tracking with input from stdin");
e04a16fb
AG
489 }
490 else
fc45c7ef
TT
491 {
492 if (dependency_tracking)
493 {
494 char *dot;
316a06a1
TT
495
496 /* If the target is set and the output filename is set, then
497 there's no processing to do here. Otherwise we must
498 compute one or the other. */
499 if (! ((dependency_tracking & DEPEND_TARGET_SET)
500 && (dependency_tracking & DEPEND_FILE_ALREADY_SET)))
fc45c7ef 501 {
316a06a1
TT
502 dot = strrchr (filename, '.');
503 if (dot == NULL)
504 error ("couldn't determine target name for dependency tracking");
fc45c7ef
TT
505 else
506 {
316a06a1 507 char *buf = (char *) xmalloc (dot - filename +
45936a85 508 3 + sizeof (TARGET_OBJECT_SUFFIX));
316a06a1
TT
509 strncpy (buf, filename, dot - filename);
510
511 /* If emitting class files, we might have multiple
512 targets. The class generation code takes care of
513 registering them. Otherwise we compute the
514 target name here. */
515 if ((dependency_tracking & DEPEND_TARGET_SET))
516 ; /* Nothing. */
517 else if (flag_emit_class_files)
518 jcf_dependency_set_target (NULL);
519 else
520 {
45936a85 521 strcpy (buf + (dot - filename), TARGET_OBJECT_SUFFIX);
316a06a1
TT
522 jcf_dependency_set_target (buf);
523 }
524
525 if ((dependency_tracking & DEPEND_FILE_ALREADY_SET))
526 ; /* Nothing. */
527 else if ((dependency_tracking & DEPEND_SET_FILE))
528 {
529 strcpy (buf + (dot - filename), ".d");
530 jcf_dependency_set_dep_file (buf);
531 }
532 else
533 jcf_dependency_set_dep_file ("-");
534
535 free (buf);
fc45c7ef 536 }
fc45c7ef
TT
537 }
538 }
fc45c7ef 539 }
d19cbcb5 540
f5e99456
NB
541 jcf_path_init ();
542 jcf_path_seal (version_flag);
543
f5e99456
NB
544 java_init_decl_processing ();
545
546 using_eh_for_cleanups ();
547
e04a16fb
AG
548 return filename;
549}
550
22703ccc
NB
551static void
552java_finish ()
e04a16fb 553{
fc45c7ef 554 jcf_dependency_write ();
e04a16fb
AG
555}
556
557/* Buffer used by lang_printable_name. */
558static char *decl_buf = NULL;
559
560/* Allocated size of decl_buf. */
561static int decl_buflen = 0;
562
563/* Length of used part of decl_buf; position for next character. */
564static int decl_bufpos = 0;
565
566/* Append the string STR to decl_buf.
567 It length is given by LEN; -1 means the string is nul-terminated. */
568
569static void
570put_decl_string (str, len)
c8e7d2e6 571 const char *str;
e04a16fb
AG
572 int len;
573{
574 if (len < 0)
575 len = strlen (str);
576 if (decl_bufpos + len >= decl_buflen)
577 {
578 if (decl_buf == NULL)
579 {
580 decl_buflen = len + 100;
581 decl_buf = (char *) xmalloc (decl_buflen);
582 }
583 else
584 {
585 decl_buflen *= 2;
586 decl_buf = (char *) xrealloc (decl_buf, decl_buflen);
587 }
588 }
589 strcpy (decl_buf + decl_bufpos, str);
590 decl_bufpos += len;
591}
592
593/* Append to decl_buf a printable name for NODE. */
594
595static void
596put_decl_node (node)
597 tree node;
598{
599 int was_pointer = 0;
600 if (TREE_CODE (node) == POINTER_TYPE)
601 {
602 node = TREE_TYPE (node);
603 was_pointer = 1;
604 }
605 if (TREE_CODE_CLASS (TREE_CODE (node)) == 'd'
606 && DECL_NAME (node) != NULL_TREE)
607 {
bc8a5e56 608 if (TREE_CODE (node) == FUNCTION_DECL)
2c36c7fd 609 {
bc8a5e56
PB
610 /* We want to print the type the DECL belongs to. We don't do
611 that when we handle constructors. */
612 if (! DECL_CONSTRUCTOR_P (node)
613 && ! DECL_ARTIFICIAL (node) && DECL_CONTEXT (node))
e04a16fb 614 {
bc8a5e56
PB
615 put_decl_node (TYPE_NAME (DECL_CONTEXT (node)));
616 put_decl_string (".", 1);
617 }
618 if (! DECL_CONSTRUCTOR_P (node))
619 put_decl_node (DECL_NAME (node));
620 if (TREE_TYPE (node) != NULL_TREE)
621 {
622 int i = 0;
623 tree args = TYPE_ARG_TYPES (TREE_TYPE (node));
624 if (TREE_CODE (TREE_TYPE (node)) == METHOD_TYPE)
625 args = TREE_CHAIN (args);
626 put_decl_string ("(", 1);
627 for ( ; args != end_params_node; args = TREE_CHAIN (args), i++)
628 {
629 if (i > 0)
630 put_decl_string (",", 1);
631 put_decl_node (TREE_VALUE (args));
632 }
633 put_decl_string (")", 1);
e04a16fb 634 }
e04a16fb 635 }
bc8a5e56
PB
636 else
637 put_decl_node (DECL_NAME (node));
e04a16fb
AG
638 }
639 else if (TREE_CODE_CLASS (TREE_CODE (node)) == 't'
640 && TYPE_NAME (node) != NULL_TREE)
641 {
642 if (TREE_CODE (node) == RECORD_TYPE && TYPE_ARRAY_P (node))
643 {
644 put_decl_node (TYPE_ARRAY_ELEMENT (node));
645 put_decl_string("[]", 2);
646 }
647 else if (node == promoted_byte_type_node)
648 put_decl_string ("byte", 4);
649 else if (node == promoted_short_type_node)
650 put_decl_string ("short", 5);
651 else if (node == promoted_char_type_node)
652 put_decl_string ("char", 4);
653 else if (node == promoted_boolean_type_node)
654 put_decl_string ("boolean", 7);
655 else if (node == void_type_node && was_pointer)
656 put_decl_string ("null", 4);
657 else
658 put_decl_node (TYPE_NAME (node));
659 }
660 else if (TREE_CODE (node) == IDENTIFIER_NODE)
661 put_decl_string (IDENTIFIER_POINTER (node), IDENTIFIER_LENGTH (node));
662 else
663 put_decl_string ("<unknown>", -1);
664}
665
666/* Return a user-friendly name for DECL.
667 The resulting string is only valid until the next call.
668 The value of the hook decl_printable_name is this function,
7cb32822 669 which is also called directly by java_print_error_function. */
e04a16fb 670
1b93a502 671const char *
e04a16fb
AG
672lang_printable_name (decl, v)
673 tree decl;
0a2138e2 674 int v __attribute__ ((__unused__));
e04a16fb
AG
675{
676 decl_bufpos = 0;
677 put_decl_node (decl);
678 put_decl_string ("", 1);
679 return decl_buf;
680}
681
761491c8
APB
682/* Does the same thing that lang_printable_name, but add a leading
683 space to the DECL name string -- With Leading Space. */
684
685const char *
686lang_printable_name_wls (decl, v)
687 tree decl;
688 int v __attribute__ ((__unused__));
689{
690 decl_bufpos = 1;
691 put_decl_node (decl);
692 put_decl_string ("", 1);
693 decl_buf [0] = ' ';
694 return decl_buf;
695}
696
e04a16fb 697/* Print on stderr the current class and method context. This function
7cb32822 698 is the value of the hook print_error_function. */
e04a16fb 699
e2500fed
GK
700static GTY(()) tree last_error_function_context;
701static GTY(()) tree last_error_function;
be245ac0 702static void
7cb32822 703java_print_error_function (context, file)
46f018e1 704 diagnostic_context *context __attribute__((__unused__));
0070eeda 705 const char *file;
e04a16fb 706{
7cb32822
NB
707 /* Don't print error messages with bogus function prototypes. */
708 if (inhibit_error_function_printing)
709 return;
710
e04a16fb
AG
711 if (current_function_decl != NULL
712 && DECL_CONTEXT (current_function_decl) != last_error_function_context)
713 {
714 if (file)
715 fprintf (stderr, "%s: ", file);
716
717 last_error_function_context = DECL_CONTEXT (current_function_decl);
718 fprintf (stderr, "In class `%s':\n",
0a2138e2 719 lang_printable_name (last_error_function_context, 0));
e04a16fb
AG
720 }
721 if (last_error_function != current_function_decl)
722 {
723 if (file)
724 fprintf (stderr, "%s: ", file);
725
726 if (current_function_decl == NULL)
727 fprintf (stderr, "At top level:\n");
728 else
729 {
c8e7d2e6 730 const char *name = lang_printable_name (current_function_decl, 2);
bc8a5e56
PB
731 fprintf (stderr, "In %s `%s':\n",
732 (DECL_CONSTRUCTOR_P (current_function_decl) ? "constructor"
733 : "method"),
734 name);
e04a16fb
AG
735 }
736
737 last_error_function = current_function_decl;
738 }
739
740}
741
e04a16fb
AG
742/* Called to install the PRINT_ERROR_FUNCTION hook differently
743 according to LEVEL. LEVEL is 1 during early parsing, when function
7cb32822
NB
744 prototypes aren't fully resolved. java_print_error_function is set
745 so it doesn't print incomplete function prototypes. When LEVEL is
746 2, function prototypes are fully resolved and can be printed when
e04a16fb
AG
747 reporting errors. */
748
749void lang_init_source (level)
750 int level;
751{
7cb32822 752 inhibit_error_function_printing = (level == 1);
e04a16fb
AG
753}
754
ee811cfd
NB
755static void
756java_init_options ()
e04a16fb 757{
13f9ac51 758 flag_bounds_check = 1;
da7da8f9
RH
759 flag_exceptions = 1;
760 flag_non_call_exceptions = 1;
f5eb5fd0
JH
761
762 /* In Java floating point operations never trap. */
763 flag_trapping_math = 0;
e04a16fb 764}
e2500fed
GK
765
766#include "gt-java-lang.h"