]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/java/lang.c
re PR rtl-optimization/6627 (-fno-align-functions regression from 2.95)
[thirdparty/gcc.git] / gcc / java / lang.c
1 /* Java(TM) language-specific utility routines.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC 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.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
21
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
25
26 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
27
28 #include "config.h"
29 #include "system.h"
30 #include "tree.h"
31 #include "input.h"
32 #include "rtl.h"
33 #include "expr.h"
34 #include "java-tree.h"
35 #include "jcf.h"
36 #include "toplev.h"
37 #include "langhooks.h"
38 #include "langhooks-def.h"
39 #include "flags.h"
40 #include "xref.h"
41 #include "ggc.h"
42 #include "diagnostic.h"
43 #include "tree-inline.h"
44
45 struct string_option
46 {
47 const char *const string;
48 int *const variable;
49 const int on_value;
50 };
51
52 static const char *java_init PARAMS ((const char *));
53 static void java_finish PARAMS ((void));
54 static void java_init_options PARAMS ((void));
55 static bool java_post_options PARAMS ((void));
56
57 static int java_decode_option PARAMS ((int, char **));
58 static void put_decl_string PARAMS ((const char *, int));
59 static void put_decl_node PARAMS ((tree));
60 static void java_print_error_function PARAMS ((diagnostic_context *,
61 const char *));
62 static int process_option_with_no PARAMS ((const char *,
63 const struct string_option *,
64 int));
65 static tree java_tree_inlining_walk_subtrees PARAMS ((tree *,
66 int *,
67 walk_tree_fn,
68 void *,
69 void *));
70 static int java_unsafe_for_reeval PARAMS ((tree));
71 static bool java_can_use_bit_fields_p PARAMS ((void));
72
73
74 #ifndef TARGET_OBJECT_SUFFIX
75 # define TARGET_OBJECT_SUFFIX ".o"
76 #endif
77
78 /* Table indexed by tree code giving a string containing a character
79 classifying the tree code. Possibilities are
80 t, d, s, c, r, <, 1 and 2. See java/java-tree.def for details. */
81
82 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
83
84 const char tree_code_type[] = {
85 #include "tree.def"
86 'x',
87 #include "java-tree.def"
88 };
89 #undef DEFTREECODE
90
91 /* Table indexed by tree code giving number of expression
92 operands beyond the fixed part of the node structure.
93 Not used for types or decls. */
94
95 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
96
97 const unsigned char tree_code_length[] = {
98 #include "tree.def"
99 0,
100 #include "java-tree.def"
101 };
102 #undef DEFTREECODE
103
104 /* Names of tree components.
105 Used for printing out the tree and error messages. */
106 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
107
108 const char *const tree_code_name[] = {
109 #include "tree.def"
110 "@@dummy",
111 #include "java-tree.def"
112 };
113 #undef DEFTREECODE
114
115 /* Used to avoid printing error messages with bogus function
116 prototypes. Starts out false. */
117 static bool inhibit_error_function_printing;
118
119 int compiling_from_source;
120
121 char * resource_name;
122
123 int flag_emit_class_files = 0;
124
125 /* Nonzero if input file is a file with a list of filenames to compile. */
126
127 int flag_filelist_file = 0;
128
129 /* When nonzero, we emit xref strings. Values of the flag for xref
130 backends are defined in xref_flag_table, xref.c. */
131
132 int flag_emit_xref = 0;
133
134 /* When nonzero, -Wall was turned on. */
135 int flag_wall = 0;
136
137 /* When nonzero, check for redundant modifier uses. */
138 int flag_redundant = 0;
139
140 /* When nonzero, call a library routine to do integer divisions. */
141 int flag_use_divide_subroutine = 1;
142
143 /* When nonzero, generate code for the Boehm GC. */
144 int flag_use_boehm_gc = 0;
145
146 /* When nonzero, assume the runtime uses a hash table to map an
147 object to its synchronization structure. */
148 int flag_hash_synchronization;
149
150 /* When nonzero, permit the use of the assert keyword. */
151 int flag_assert = 1;
152
153 /* When nonzero, assume all native functions are implemented with
154 JNI, not CNI. */
155 int flag_jni = 0;
156
157 /* When nonzero, warn when source file is newer than matching class
158 file. */
159 int flag_newer = 1;
160
161 /* When nonzero, generate checks for references to NULL. */
162 int flag_check_references = 0;
163
164 /* The encoding of the source file. */
165 const char *current_encoding = NULL;
166
167 /* When nonzero, report the now deprecated empty statements. */
168 int flag_extraneous_semicolon;
169
170 /* When nonzero, always check for a non gcj generated classes archive. */
171 int flag_force_classes_archive_check;
172
173 /* When zero, don't optimize static class initialization. This flag shouldn't
174 be tested alone, use STATIC_CLASS_INITIALIZATION_OPTIMIZATION_P instead. */
175 int flag_optimize_sci = 1;
176
177 /* When nonzero, use offset tables for virtual method calls
178 in order to improve binary compatibility. */
179 int flag_indirect_dispatch = 0;
180
181 /* When zero, don't generate runtime array store checks. */
182 int flag_store_check = 1;
183
184 /* When nonzero, print extra version information. */
185 static int version_flag = 0;
186
187 /* Set nonzero if the user specified -finline-functions on the command
188 line. */
189 int flag_really_inline = 0;
190
191 /* Table of language-dependent -f options.
192 STRING is the option name. VARIABLE is the address of the variable.
193 ON_VALUE is the value to store in VARIABLE
194 if `-fSTRING' is seen as an option.
195 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
196
197 static const struct string_option
198 lang_f_options[] =
199 {
200 {"emit-class-file", &flag_emit_class_files, 1},
201 {"emit-class-files", &flag_emit_class_files, 1},
202 {"filelist-file", &flag_filelist_file, 1},
203 {"use-divide-subroutine", &flag_use_divide_subroutine, 1},
204 {"use-boehm-gc", &flag_use_boehm_gc, 1},
205 {"hash-synchronization", &flag_hash_synchronization, 1},
206 {"jni", &flag_jni, 1},
207 {"check-references", &flag_check_references, 1},
208 {"force-classes-archive-check", &flag_force_classes_archive_check, 1},
209 {"optimize-static-class-initialization", &flag_optimize_sci, 1 },
210 {"indirect-dispatch", &flag_indirect_dispatch, 1},
211 {"store-check", &flag_store_check, 1},
212 {"assert", &flag_assert, 1}
213 };
214
215 static const struct string_option
216 lang_W_options[] =
217 {
218 { "redundant-modifiers", &flag_redundant, 1 },
219 { "extraneous-semicolon", &flag_extraneous_semicolon, 1 },
220 { "out-of-date", &flag_newer, 1 }
221 };
222
223 JCF *current_jcf;
224
225 /* Variable controlling how dependency tracking is enabled in
226 java_init. */
227 static int dependency_tracking = 0;
228
229 /* Flag values for DEPENDENCY_TRACKING. */
230 #define DEPEND_SET_FILE 1
231 #define DEPEND_ENABLE 2
232 #define DEPEND_TARGET_SET 4
233 #define DEPEND_FILE_ALREADY_SET 8
234
235 struct language_function GTY(())
236 {
237 int unused;
238 };
239
240 #undef LANG_HOOKS_NAME
241 #define LANG_HOOKS_NAME "GNU Java"
242 #undef LANG_HOOKS_INIT
243 #define LANG_HOOKS_INIT java_init
244 #undef LANG_HOOKS_FINISH
245 #define LANG_HOOKS_FINISH java_finish
246 #undef LANG_HOOKS_INIT_OPTIONS
247 #define LANG_HOOKS_INIT_OPTIONS java_init_options
248 #undef LANG_HOOKS_DECODE_OPTION
249 #define LANG_HOOKS_DECODE_OPTION java_decode_option
250 #undef LANG_HOOKS_POST_OPTIONS
251 #define LANG_HOOKS_POST_OPTIONS java_post_options
252 #undef LANG_HOOKS_PARSE_FILE
253 #define LANG_HOOKS_PARSE_FILE java_parse_file
254 #undef LANG_HOOKS_UNSAFE_FOR_REEVAL
255 #define LANG_HOOKS_UNSAFE_FOR_REEVAL java_unsafe_for_reeval
256 #undef LANG_HOOKS_MARK_ADDRESSABLE
257 #define LANG_HOOKS_MARK_ADDRESSABLE java_mark_addressable
258 #undef LANG_HOOKS_EXPAND_EXPR
259 #define LANG_HOOKS_EXPAND_EXPR java_expand_expr
260 #undef LANG_HOOKS_TRUTHVALUE_CONVERSION
261 #define LANG_HOOKS_TRUTHVALUE_CONVERSION java_truthvalue_conversion
262 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
263 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL java_dup_lang_specific_decl
264 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
265 #define LANG_HOOKS_DECL_PRINTABLE_NAME lang_printable_name
266 #undef LANG_HOOKS_PRINT_ERROR_FUNCTION
267 #define LANG_HOOKS_PRINT_ERROR_FUNCTION java_print_error_function
268 #undef LANG_HOOKS_CAN_USE_BIT_FIELDS_P
269 #define LANG_HOOKS_CAN_USE_BIT_FIELDS_P java_can_use_bit_fields_p
270
271 #undef LANG_HOOKS_TYPE_FOR_MODE
272 #define LANG_HOOKS_TYPE_FOR_MODE java_type_for_mode
273 #undef LANG_HOOKS_TYPE_FOR_SIZE
274 #define LANG_HOOKS_TYPE_FOR_SIZE java_type_for_size
275 #undef LANG_HOOKS_SIGNED_TYPE
276 #define LANG_HOOKS_SIGNED_TYPE java_signed_type
277 #undef LANG_HOOKS_UNSIGNED_TYPE
278 #define LANG_HOOKS_UNSIGNED_TYPE java_unsigned_type
279 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
280 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE java_signed_or_unsigned_type
281
282 #undef LANG_HOOKS_TREE_INLINING_WALK_SUBTREES
283 #define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES java_tree_inlining_walk_subtrees
284
285 /* Each front end provides its own. */
286 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
287
288 /* Process an option that can accept a `no-' form.
289 Return 1 if option found, 0 otherwise. */
290 static int
291 process_option_with_no (p, table, table_size)
292 const char *p;
293 const struct string_option *table;
294 int table_size;
295 {
296 int j;
297
298 for (j = 0; j < table_size; j++)
299 {
300 if (!strcmp (p, table[j].string))
301 {
302 *table[j].variable = table[j].on_value;
303 return 1;
304 }
305 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
306 && ! strcmp (p+3, table[j].string))
307 {
308 *table[j].variable = ! table[j].on_value;
309 return 1;
310 }
311 }
312
313 return 0;
314 }
315
316 /*
317 * process java-specific compiler command-line options
318 * return 0, but do not complain if the option is not recognized.
319 */
320 static int
321 java_decode_option (argc, argv)
322 int argc __attribute__ ((__unused__));
323 char **argv;
324 {
325 char *p = argv[0];
326
327 jcf_path_init ();
328
329 if (strcmp (p, "-version") == 0)
330 {
331 version_flag = 1;
332 /* We return 0 so that the caller can process this. */
333 return 0;
334 }
335
336 #define CLARG "-fcompile-resource="
337 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
338 {
339 resource_name = p + sizeof (CLARG) - 1;
340 return 1;
341 }
342 #undef CLARG
343 #define CLARG "-fassume-compiled="
344 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
345 {
346 add_assume_compiled (p + sizeof (CLARG) - 1, 0);
347 return 1;
348 }
349 #undef CLARG
350 #define CLARG "-fno-assume-compiled="
351 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
352 {
353 add_assume_compiled (p + sizeof (CLARG) - 1, 1);
354 return 1;
355 }
356 #undef CLARG
357 #define CLARG "-fassume-compiled"
358 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
359 {
360 add_assume_compiled ("", 0);
361 return 1;
362 }
363 #undef CLARG
364 #define CLARG "-fno-assume-compiled"
365 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
366 {
367 add_assume_compiled ("", 1);
368 return 1;
369 }
370 #undef CLARG
371 #define CLARG "-fCLASSPATH="
372 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
373 {
374 jcf_path_classpath_arg (p + sizeof (CLARG) - 1);
375 return 1;
376 }
377 #undef CLARG
378 #define CLARG "-fclasspath="
379 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
380 {
381 jcf_path_classpath_arg (p + sizeof (CLARG) - 1);
382 return 1;
383 }
384 #undef CLARG
385 #define CLARG "-fbootclasspath="
386 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
387 {
388 jcf_path_bootclasspath_arg (p + sizeof (CLARG) - 1);
389 return 1;
390 }
391 #undef CLARG
392 #define CLARG "-fextdirs="
393 if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
394 {
395 jcf_path_extdirs_arg (p + sizeof (CLARG) - 1);
396 return 1;
397 }
398 #undef CLARG
399 else if (strncmp (p, "-I", 2) == 0)
400 {
401 jcf_path_include_arg (p + 2);
402 return 1;
403 }
404
405 #define ARG "-foutput-class-dir="
406 if (strncmp (p, ARG, sizeof (ARG) - 1) == 0)
407 {
408 jcf_write_base_directory = p + sizeof (ARG) - 1;
409 return 1;
410 }
411 #undef ARG
412 #define ARG "-fencoding="
413 if (strncmp (p, ARG, sizeof (ARG) - 1) == 0)
414 {
415 current_encoding = p + sizeof (ARG) - 1;
416 return 1;
417 }
418 #undef ARG
419 #define ARG "-finline-functions"
420 if (strncmp (p, ARG, sizeof (ARG) - 1) == 0)
421 {
422 flag_inline_functions = 1;
423 flag_really_inline = 1;
424 return 1;
425 }
426 #undef ARG
427
428 if (p[0] == '-' && p[1] == 'f')
429 {
430 /* Some kind of -f option.
431 P's value is the option sans `-f'.
432 Search for it in the table of options. */
433 p += 2;
434 if (process_option_with_no (p, lang_f_options,
435 ARRAY_SIZE (lang_f_options)))
436 return 1;
437 return dump_switch_p (p);
438 }
439
440 if (strcmp (p, "-Wall") == 0)
441 {
442 flag_wall = 1;
443 flag_redundant = 1;
444 flag_extraneous_semicolon = 1;
445 /* When -Wall given, enable -Wunused. We do this because the C
446 compiler does it, and people expect it. */
447 set_Wunused (1);
448 return 1;
449 }
450
451 if (p[0] == '-' && p[1] == 'W')
452 {
453 /* Skip `-W' and see if we accept the option or its `no-' form. */
454 p += 2;
455 return process_option_with_no (p, lang_W_options,
456 ARRAY_SIZE (lang_W_options));
457 }
458
459 if (strcmp (p, "-MD") == 0)
460 {
461 jcf_dependency_init (1);
462 dependency_tracking |= DEPEND_SET_FILE | DEPEND_ENABLE;
463 return 1;
464 }
465 else if (strcmp (p, "-MMD") == 0)
466 {
467 jcf_dependency_init (0);
468 dependency_tracking |= DEPEND_SET_FILE | DEPEND_ENABLE;
469 return 1;
470 }
471 else if (strcmp (p, "-M") == 0)
472 {
473 jcf_dependency_init (1);
474 dependency_tracking |= DEPEND_ENABLE;
475 return 1;
476 }
477 else if (strcmp (p, "-MM") == 0)
478 {
479 jcf_dependency_init (0);
480 dependency_tracking |= DEPEND_ENABLE;
481 return 1;
482 }
483 else if (strcmp (p, "-MP") == 0)
484 {
485 jcf_dependency_print_dummies ();
486 return 1;
487 }
488 else if (strcmp (p, "-MT") == 0)
489 {
490 jcf_dependency_set_target (argv[1]);
491 dependency_tracking |= DEPEND_TARGET_SET;
492 return 2;
493 }
494 else if (strcmp (p, "-MF") == 0)
495 {
496 jcf_dependency_set_dep_file (argv[1]);
497 dependency_tracking |= DEPEND_FILE_ALREADY_SET;
498 return 2;
499 }
500
501 return 0;
502 }
503
504 /* Global open file. */
505 FILE *finput;
506
507 static const char *
508 java_init (filename)
509 const char *filename;
510 {
511 #if 0
512 extern int flag_minimal_debug;
513 flag_minimal_debug = 0;
514 #endif
515
516 if (flag_inline_functions)
517 flag_inline_trees = 1;
518
519 /* Force minimum function alignment if g++ uses the least significant
520 bit of function pointers to store the virtual bit. This is required
521 to keep vtables compatible. */
522 if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
523 && force_align_functions_log < 1)
524 force_align_functions_log = 1;
525
526 /* Open input file. */
527
528 if (filename == 0 || !strcmp (filename, "-"))
529 {
530 finput = stdin;
531 filename = "stdin";
532
533 if (dependency_tracking)
534 error ("can't do dependency tracking with input from stdin");
535 }
536 else
537 {
538 if (dependency_tracking)
539 {
540 char *dot;
541
542 /* If the target is set and the output filename is set, then
543 there's no processing to do here. Otherwise we must
544 compute one or the other. */
545 if (! ((dependency_tracking & DEPEND_TARGET_SET)
546 && (dependency_tracking & DEPEND_FILE_ALREADY_SET)))
547 {
548 dot = strrchr (filename, '.');
549 if (dot == NULL)
550 error ("couldn't determine target name for dependency tracking");
551 else
552 {
553 char *buf = (char *) xmalloc (dot - filename +
554 3 + sizeof (TARGET_OBJECT_SUFFIX));
555 strncpy (buf, filename, dot - filename);
556
557 /* If emitting class files, we might have multiple
558 targets. The class generation code takes care of
559 registering them. Otherwise we compute the
560 target name here. */
561 if ((dependency_tracking & DEPEND_TARGET_SET))
562 ; /* Nothing. */
563 else if (flag_emit_class_files)
564 jcf_dependency_set_target (NULL);
565 else
566 {
567 strcpy (buf + (dot - filename), TARGET_OBJECT_SUFFIX);
568 jcf_dependency_set_target (buf);
569 }
570
571 if ((dependency_tracking & DEPEND_FILE_ALREADY_SET))
572 ; /* Nothing. */
573 else if ((dependency_tracking & DEPEND_SET_FILE))
574 {
575 strcpy (buf + (dot - filename), ".d");
576 jcf_dependency_set_dep_file (buf);
577 }
578 else
579 jcf_dependency_set_dep_file ("-");
580
581 free (buf);
582 }
583 }
584 }
585 }
586
587 jcf_path_init ();
588 jcf_path_seal (version_flag);
589
590 java_init_decl_processing ();
591
592 using_eh_for_cleanups ();
593
594 return filename;
595 }
596
597 static void
598 java_finish ()
599 {
600 jcf_dependency_write ();
601 }
602
603 /* Buffer used by lang_printable_name. */
604 static char *decl_buf = NULL;
605
606 /* Allocated size of decl_buf. */
607 static int decl_buflen = 0;
608
609 /* Length of used part of decl_buf; position for next character. */
610 static int decl_bufpos = 0;
611
612 /* Append the string STR to decl_buf.
613 It length is given by LEN; -1 means the string is nul-terminated. */
614
615 static void
616 put_decl_string (str, len)
617 const char *str;
618 int len;
619 {
620 if (len < 0)
621 len = strlen (str);
622 if (decl_bufpos + len >= decl_buflen)
623 {
624 if (decl_buf == NULL)
625 {
626 decl_buflen = len + 100;
627 decl_buf = (char *) xmalloc (decl_buflen);
628 }
629 else
630 {
631 decl_buflen *= 2;
632 decl_buf = (char *) xrealloc (decl_buf, decl_buflen);
633 }
634 }
635 strcpy (decl_buf + decl_bufpos, str);
636 decl_bufpos += len;
637 }
638
639 /* Append to decl_buf a printable name for NODE. */
640
641 static void
642 put_decl_node (node)
643 tree node;
644 {
645 int was_pointer = 0;
646 if (TREE_CODE (node) == POINTER_TYPE)
647 {
648 node = TREE_TYPE (node);
649 was_pointer = 1;
650 }
651 if (TREE_CODE_CLASS (TREE_CODE (node)) == 'd'
652 && DECL_NAME (node) != NULL_TREE)
653 {
654 if (TREE_CODE (node) == FUNCTION_DECL)
655 {
656 /* We want to print the type the DECL belongs to. We don't do
657 that when we handle constructors. */
658 if (! DECL_CONSTRUCTOR_P (node)
659 && ! DECL_ARTIFICIAL (node) && DECL_CONTEXT (node))
660 {
661 put_decl_node (TYPE_NAME (DECL_CONTEXT (node)));
662 put_decl_string (".", 1);
663 }
664 if (! DECL_CONSTRUCTOR_P (node))
665 put_decl_node (DECL_NAME (node));
666 if (TREE_TYPE (node) != NULL_TREE)
667 {
668 int i = 0;
669 tree args = TYPE_ARG_TYPES (TREE_TYPE (node));
670 if (TREE_CODE (TREE_TYPE (node)) == METHOD_TYPE)
671 args = TREE_CHAIN (args);
672 put_decl_string ("(", 1);
673 for ( ; args != end_params_node; args = TREE_CHAIN (args), i++)
674 {
675 if (i > 0)
676 put_decl_string (",", 1);
677 put_decl_node (TREE_VALUE (args));
678 }
679 put_decl_string (")", 1);
680 }
681 }
682 else
683 put_decl_node (DECL_NAME (node));
684 }
685 else if (TREE_CODE_CLASS (TREE_CODE (node)) == 't'
686 && TYPE_NAME (node) != NULL_TREE)
687 {
688 if (TREE_CODE (node) == RECORD_TYPE && TYPE_ARRAY_P (node))
689 {
690 put_decl_node (TYPE_ARRAY_ELEMENT (node));
691 put_decl_string("[]", 2);
692 }
693 else if (node == promoted_byte_type_node)
694 put_decl_string ("byte", 4);
695 else if (node == promoted_short_type_node)
696 put_decl_string ("short", 5);
697 else if (node == promoted_char_type_node)
698 put_decl_string ("char", 4);
699 else if (node == promoted_boolean_type_node)
700 put_decl_string ("boolean", 7);
701 else if (node == void_type_node && was_pointer)
702 put_decl_string ("null", 4);
703 else
704 put_decl_node (TYPE_NAME (node));
705 }
706 else if (TREE_CODE (node) == IDENTIFIER_NODE)
707 put_decl_string (IDENTIFIER_POINTER (node), IDENTIFIER_LENGTH (node));
708 else
709 put_decl_string ("<unknown>", -1);
710 }
711
712 /* Return a user-friendly name for DECL.
713 The resulting string is only valid until the next call.
714 The value of the hook decl_printable_name is this function,
715 which is also called directly by java_print_error_function. */
716
717 const char *
718 lang_printable_name (decl, v)
719 tree decl;
720 int v __attribute__ ((__unused__));
721 {
722 decl_bufpos = 0;
723 put_decl_node (decl);
724 put_decl_string ("", 1);
725 return decl_buf;
726 }
727
728 /* Does the same thing that lang_printable_name, but add a leading
729 space to the DECL name string -- With Leading Space. */
730
731 const char *
732 lang_printable_name_wls (decl, v)
733 tree decl;
734 int v __attribute__ ((__unused__));
735 {
736 decl_bufpos = 1;
737 put_decl_node (decl);
738 put_decl_string ("", 1);
739 decl_buf [0] = ' ';
740 return decl_buf;
741 }
742
743 /* Print on stderr the current class and method context. This function
744 is the value of the hook print_error_function. */
745
746 static GTY(()) tree last_error_function_context;
747 static GTY(()) tree last_error_function;
748 static void
749 java_print_error_function (context, file)
750 diagnostic_context *context __attribute__((__unused__));
751 const char *file;
752 {
753 /* Don't print error messages with bogus function prototypes. */
754 if (inhibit_error_function_printing)
755 return;
756
757 if (current_function_decl != NULL
758 && DECL_CONTEXT (current_function_decl) != last_error_function_context)
759 {
760 if (file)
761 fprintf (stderr, "%s: ", file);
762
763 last_error_function_context = DECL_CONTEXT (current_function_decl);
764 fprintf (stderr, "In class `%s':\n",
765 lang_printable_name (last_error_function_context, 0));
766 }
767 if (last_error_function != current_function_decl)
768 {
769 if (file)
770 fprintf (stderr, "%s: ", file);
771
772 if (current_function_decl == NULL)
773 fprintf (stderr, "At top level:\n");
774 else
775 {
776 const char *name = lang_printable_name (current_function_decl, 2);
777 fprintf (stderr, "In %s `%s':\n",
778 (DECL_CONSTRUCTOR_P (current_function_decl) ? "constructor"
779 : "method"),
780 name);
781 }
782
783 last_error_function = current_function_decl;
784 }
785
786 }
787
788 /* Called to install the PRINT_ERROR_FUNCTION hook differently
789 according to LEVEL. LEVEL is 1 during early parsing, when function
790 prototypes aren't fully resolved. java_print_error_function is set
791 so it doesn't print incomplete function prototypes. When LEVEL is
792 2, function prototypes are fully resolved and can be printed when
793 reporting errors. */
794
795 void lang_init_source (level)
796 int level;
797 {
798 inhibit_error_function_printing = (level == 1);
799 }
800
801 static void
802 java_init_options ()
803 {
804 flag_bounds_check = 1;
805 flag_exceptions = 1;
806 flag_non_call_exceptions = 1;
807
808 /* In Java floating point operations never trap. */
809 flag_trapping_math = 0;
810 }
811
812 static bool
813 java_can_use_bit_fields_p ()
814 {
815 /* The bit-field optimizations cause problems when generating class
816 files. */
817 return flag_emit_class_files ? false : true;
818 }
819
820 /* Post-switch processing. */
821 static bool
822 java_post_options ()
823 {
824 /* Use tree inlining if possible. Function instrumentation is only
825 done in the RTL level, so we disable tree inlining. */
826 if (! flag_instrument_function_entry_exit)
827 {
828 if (!flag_no_inline)
829 flag_no_inline = 1;
830 if (flag_inline_functions)
831 {
832 flag_inline_trees = 2;
833 flag_inline_functions = 0;
834 }
835 }
836
837 /* Initialize the compiler back end. */
838 return false;
839 }
840
841 /* Return either DECL or its known constant value (if it has one). */
842
843 tree
844 decl_constant_value (decl)
845 tree decl;
846 {
847 if (/* Don't change a variable array bound or initial value to a constant
848 in a place where a variable is invalid. */
849 current_function_decl != 0
850 && ! TREE_THIS_VOLATILE (decl)
851 && TREE_READONLY (decl)
852 && DECL_INITIAL (decl) != 0
853 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
854 /* This is invalid if initial value is not constant.
855 If it has either a function call, a memory reference,
856 or a variable, then re-evaluating it could give different results. */
857 && TREE_CONSTANT (DECL_INITIAL (decl))
858 /* Check for cases where this is sub-optimal, even though valid. */
859 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
860 return DECL_INITIAL (decl);
861 return decl;
862 }
863
864 /* Walk the language specific tree nodes during inlining. */
865
866 static tree
867 java_tree_inlining_walk_subtrees (tp,subtrees,func,data,htab)
868 tree *tp ATTRIBUTE_UNUSED;
869 int *subtrees ATTRIBUTE_UNUSED;
870 walk_tree_fn func ATTRIBUTE_UNUSED;
871 void *data ATTRIBUTE_UNUSED;
872 void *htab ATTRIBUTE_UNUSED;
873 {
874 enum tree_code code;
875 tree result;
876
877 #define WALK_SUBTREE(NODE) \
878 do \
879 { \
880 result = walk_tree (&(NODE), func, data, htab); \
881 if (result) \
882 return result; \
883 } \
884 while (0)
885
886 tree t = *tp;
887 if (!t)
888 return NULL_TREE;
889
890 code = TREE_CODE (t);
891 switch (code)
892 {
893 case BLOCK:
894 if (BLOCK_EXPR_BODY (t))
895 {
896 tree *prev = &BLOCK_EXPR_BODY (*tp);
897 while (*prev)
898 {
899 WALK_SUBTREE (*prev);
900 prev = &TREE_CHAIN (*prev);
901 }
902 }
903 return NULL_TREE;
904 break;
905
906 default:
907 return NULL_TREE;
908 }
909 }
910
911 /* Called from unsafe_for_reeval. */
912 static int
913 java_unsafe_for_reeval (t)
914 tree t;
915 {
916 switch (TREE_CODE (t))
917 {
918 case BLOCK:
919 /* Our expander tries to expand the variables twice. Boom. */
920 if (BLOCK_EXPR_DECLS (t) != NULL)
921 return 2;
922 return unsafe_for_reeval (BLOCK_EXPR_BODY (t));
923
924 default:
925 break;
926 }
927
928 return -1;
929 }
930
931 #include "gt-java-lang.h"