PR bootstrap/66085
[official-gcc.git] / gcc / java / lang.c
blobdac322d512daeeaded2a6cea795f2ba1be67031b
1 /* Java(TM) language-specific utility routines.
2 Copyright (C) 1996-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>.
20 Java and all Java-based marks are trademarks or registered trademarks
21 of Sun Microsystems, Inc. in the United States and other countries.
22 The Free Software Foundation is independent of Sun Microsystems, Inc. */
24 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "tm.h"
30 #include "hash-set.h"
31 #include "machmode.h"
32 #include "vec.h"
33 #include "double-int.h"
34 #include "input.h"
35 #include "alias.h"
36 #include "symtab.h"
37 #include "wide-int.h"
38 #include "inchash.h"
39 #include "tree.h"
40 #include "input.h"
41 #include "java-tree.h"
42 #include "jcf.h"
43 #include "langhooks.h"
44 #include "langhooks-def.h"
45 #include "flags.h"
46 #include "ggc.h"
47 #include "diagnostic.h"
48 #include "tree-inline.h"
49 #include "splay-tree.h"
50 #include "tree-dump.h"
51 #include "opts.h"
52 #include "options.h"
53 #include "target.h"
54 #include "context.h"
56 static bool java_init (void);
57 static void java_finish (void);
58 static unsigned int java_option_lang_mask (void);
59 static void java_init_options_struct (struct gcc_options *);
60 static void java_init_options (unsigned int, struct cl_decoded_option *);
61 static bool java_post_options (const char **);
63 static bool java_handle_option (size_t, const char *, int, int, location_t,
64 const struct cl_option_handlers *);
65 static void put_decl_string (const char *, int);
66 static void put_decl_node (tree, int);
67 static void java_print_error_function (diagnostic_context *, const char *,
68 diagnostic_info *);
69 static bool java_dump_tree (void *, tree);
70 static void dump_compound_expr (dump_info_p, tree);
71 static bool java_decl_ok_for_sibcall (const_tree);
73 static enum classify_record java_classify_record (tree type);
75 static tree java_eh_personality (void);
77 #ifndef TARGET_OBJECT_SUFFIX
78 # define TARGET_OBJECT_SUFFIX ".o"
79 #endif
81 /* Table of machine-independent attributes. */
82 const struct attribute_spec java_attribute_table[] =
84 { "nonnull", 0, -1, false, true, true,
85 NULL, false },
86 { NULL, 0, 0, false, false, false, NULL, false }
89 /* Used to avoid printing error messages with bogus function
90 prototypes. Starts out false. */
91 static bool inhibit_error_function_printing;
93 const char *resource_name;
95 /* When nonzero, -Wall was turned on. */
96 int flag_wall = 0;
98 /* When nonzero, report use of deprecated classes, methods, or fields. */
99 int flag_deprecated = 1;
101 /* When zero, don't optimize static class initialization. This flag shouldn't
102 be tested alone, use STATIC_CLASS_INITIALIZATION_OPTIMIZATION_P instead. */
103 /* FIXME: Make this work with gimplify. */
104 /* int flag_optimize_sci = 0; */
106 /* Don't attempt to verify invocations. */
107 int flag_verify_invocations = 0;
109 /* When nonzero, print extra version information. */
110 static int v_flag = 0;
112 JCF *current_jcf;
114 /* Variable controlling how dependency tracking is enabled in
115 java_init. */
116 static int dependency_tracking = 0;
118 /* Flag values for DEPENDENCY_TRACKING. */
119 #define DEPEND_SET_FILE 1
120 #define DEPEND_ENABLE 2
121 #define DEPEND_TARGET_SET 4
122 #define DEPEND_FILE_ALREADY_SET 8
124 struct GTY(()) language_function {
125 int unused;
128 #undef LANG_HOOKS_NAME
129 #define LANG_HOOKS_NAME "GNU Java"
130 #undef LANG_HOOKS_INIT
131 #define LANG_HOOKS_INIT java_init
132 #undef LANG_HOOKS_FINISH
133 #define LANG_HOOKS_FINISH java_finish
134 #undef LANG_HOOKS_OPTION_LANG_MASK
135 #define LANG_HOOKS_OPTION_LANG_MASK java_option_lang_mask
136 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
137 #define LANG_HOOKS_INIT_OPTIONS_STRUCT java_init_options_struct
138 #undef LANG_HOOKS_INIT_OPTIONS
139 #define LANG_HOOKS_INIT_OPTIONS java_init_options
140 #undef LANG_HOOKS_HANDLE_OPTION
141 #define LANG_HOOKS_HANDLE_OPTION java_handle_option
142 #undef LANG_HOOKS_POST_OPTIONS
143 #define LANG_HOOKS_POST_OPTIONS java_post_options
144 #undef LANG_HOOKS_PARSE_FILE
145 #define LANG_HOOKS_PARSE_FILE java_parse_file
146 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
147 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL java_dup_lang_specific_decl
148 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
149 #define LANG_HOOKS_DECL_PRINTABLE_NAME lang_printable_name
150 #undef LANG_HOOKS_PRINT_ERROR_FUNCTION
151 #define LANG_HOOKS_PRINT_ERROR_FUNCTION java_print_error_function
152 #undef LANG_HOOKS_WRITE_GLOBALS
153 #define LANG_HOOKS_WRITE_GLOBALS java_write_globals
155 #undef LANG_HOOKS_TYPE_FOR_MODE
156 #define LANG_HOOKS_TYPE_FOR_MODE java_type_for_mode
157 #undef LANG_HOOKS_TYPE_FOR_SIZE
158 #define LANG_HOOKS_TYPE_FOR_SIZE java_type_for_size
159 #undef LANG_HOOKS_CLASSIFY_RECORD
160 #define LANG_HOOKS_CLASSIFY_RECORD java_classify_record
162 #undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN
163 #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN java_dump_tree
165 #undef LANG_HOOKS_GIMPLIFY_EXPR
166 #define LANG_HOOKS_GIMPLIFY_EXPR java_gimplify_expr
168 #undef LANG_HOOKS_DECL_OK_FOR_SIBCALL
169 #define LANG_HOOKS_DECL_OK_FOR_SIBCALL java_decl_ok_for_sibcall
171 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
172 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME java_mangle_decl
174 #undef LANG_HOOKS_ATTRIBUTE_TABLE
175 #define LANG_HOOKS_ATTRIBUTE_TABLE java_attribute_table
177 #undef LANG_HOOKS_EH_PERSONALITY
178 #define LANG_HOOKS_EH_PERSONALITY java_eh_personality
180 #undef LANG_HOOKS_EH_USE_CXA_END_CLEANUP
181 #define LANG_HOOKS_EH_USE_CXA_END_CLEANUP true
183 /* Each front end provides its own. */
184 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
187 * process java-specific compiler command-line options
188 * return false, but do not complain if the option is not recognized.
190 static bool
191 java_handle_option (size_t scode, const char *arg, int value,
192 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
193 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
195 enum opt_code code = (enum opt_code) scode;
197 switch (code)
199 case OPT_I:
200 jcf_path_include_arg (arg);
201 break;
203 case OPT_M:
204 jcf_dependency_init (1);
205 dependency_tracking |= DEPEND_ENABLE;
206 break;
208 case OPT_MD_:
209 jcf_dependency_init (1);
210 dependency_tracking |= DEPEND_SET_FILE | DEPEND_ENABLE;
211 break;
213 case OPT_MF:
214 jcf_dependency_set_dep_file (arg);
215 dependency_tracking |= DEPEND_FILE_ALREADY_SET;
216 break;
218 case OPT_MM:
219 jcf_dependency_init (0);
220 dependency_tracking |= DEPEND_ENABLE;
221 break;
223 case OPT_MMD_:
224 jcf_dependency_init (0);
225 dependency_tracking |= DEPEND_SET_FILE | DEPEND_ENABLE;
226 break;
228 case OPT_MP:
229 jcf_dependency_print_dummies ();
230 break;
232 case OPT_MT:
233 jcf_dependency_set_target (arg);
234 dependency_tracking |= DEPEND_TARGET_SET;
235 break;
237 case OPT_Wall:
238 flag_wall = value;
239 /* When -Wall given, enable -Wunused. We do this because the C
240 compiler does it, and people expect it. */
241 warn_unused = value;
242 break;
244 case OPT_fenable_assertions_:
245 add_enable_assert (arg, value);
246 break;
248 case OPT_fenable_assertions:
249 add_enable_assert ("", value);
250 break;
252 case OPT_fdisable_assertions_:
253 add_enable_assert (arg, !value);
254 break;
256 case OPT_fdisable_assertions:
257 add_enable_assert ("", !value);
258 break;
260 case OPT_fassume_compiled_:
261 add_assume_compiled (arg, !value);
262 break;
264 case OPT_fassume_compiled:
265 add_assume_compiled ("", !value);
266 break;
268 case OPT_fbootclasspath_:
269 jcf_path_bootclasspath_arg (arg);
270 break;
272 case OPT_faux_classpath:
273 case OPT_fclasspath_:
274 jcf_path_classpath_arg (arg);
275 break;
277 case OPT_fcompile_resource_:
278 resource_name = arg;
279 break;
281 case OPT_fdump_:
282 if (!g->get_dumps ()->dump_switch_p (arg))
283 return false;
284 break;
286 case OPT_fencoding_:
287 /* Nothing. */
288 break;
290 case OPT_fextdirs_:
291 jcf_path_extdirs_arg (arg);
292 break;
294 case OPT_foutput_class_dir_:
295 /* FIXME: remove; this is handled by ecj1 now. */
296 break;
298 case OPT_version:
299 v_flag = 1;
300 break;
302 case OPT_fsource_filename_:
303 java_read_sourcefilenames (arg);
304 break;
306 default:
307 if (cl_options[code].flags & CL_Java)
308 break;
309 gcc_unreachable ();
312 return true;
315 /* Global open file. */
316 FILE *finput;
318 static bool
319 java_init (void)
321 /* FIXME: Indirect dispatch isn't yet compatible with static class
322 init optimization. */
323 if (flag_indirect_dispatch)
324 always_initialize_class_p = true;
326 if (!flag_indirect_dispatch)
327 flag_indirect_classes = false;
329 jcf_path_seal (v_flag);
331 java_init_decl_processing ();
333 using_eh_for_cleanups ();
335 return true;
338 static void
339 java_finish (void)
341 jcf_dependency_write ();
344 /* Buffer used by lang_printable_name. */
345 static char *decl_buf = NULL;
347 /* Allocated size of decl_buf. */
348 static int decl_buflen = 0;
350 /* Length of used part of decl_buf; position for next character. */
351 static int decl_bufpos = 0;
353 /* Append the string STR to decl_buf.
354 It length is given by LEN; -1 means the string is nul-terminated. */
356 static void
357 put_decl_string (const char *str, int len)
359 if (len < 0)
360 len = strlen (str);
361 if (decl_bufpos + len >= decl_buflen)
363 if (decl_buf == NULL)
365 decl_buflen = len + 100;
366 decl_buf = XNEWVEC (char, decl_buflen);
368 else
370 decl_buflen *= 2;
371 decl_buf = XRESIZEVAR (char, decl_buf, decl_buflen);
374 strcpy (decl_buf + decl_bufpos, str);
375 decl_bufpos += len;
378 /* Append to decl_buf a printable name for NODE.
379 Depending on VERBOSITY, more information about NODE
380 is printed. Read the comments of decl_printable_name in
381 langhooks.h for more. */
383 static void
384 put_decl_node (tree node, int verbosity)
386 int was_pointer = 0;
387 if (TREE_CODE (node) == POINTER_TYPE)
389 node = TREE_TYPE (node);
390 was_pointer = 1;
392 if (DECL_P (node) && DECL_NAME (node) != NULL_TREE)
394 if (TREE_CODE (node) == FUNCTION_DECL)
396 if (verbosity == 0 && DECL_NAME (node))
397 /* We have been instructed to just print the bare name
398 of the function. */
400 put_decl_node (DECL_NAME (node), 0);
401 return;
404 /* We want to print the type the DECL belongs to. We don't do
405 that when we handle constructors. */
406 if (! DECL_CONSTRUCTOR_P (node)
407 && ! DECL_ARTIFICIAL (node) && DECL_CONTEXT (node)
408 /* We want to print qualified DECL names only
409 if verbosity is higher than 1. */
410 && verbosity >= 1)
412 put_decl_node (TREE_CODE (DECL_CONTEXT (node)) == FUNCTION_DECL
413 ? DECL_CONTEXT (node)
414 : TYPE_NAME (DECL_CONTEXT (node)),
415 verbosity);
416 put_decl_string (".", 1);
418 if (! DECL_CONSTRUCTOR_P (node))
419 put_decl_node (DECL_NAME (node), verbosity);
420 if (TREE_TYPE (node) != NULL_TREE
421 /* We want to print function parameters only if verbosity
422 is higher than 2. */
423 && verbosity >= 2)
425 int i = 0;
426 tree args = TYPE_ARG_TYPES (TREE_TYPE (node));
427 if (TREE_CODE (TREE_TYPE (node)) == METHOD_TYPE)
428 args = TREE_CHAIN (args);
429 put_decl_string ("(", 1);
430 for ( ; args != NULL_TREE && args != end_params_node;
431 args = TREE_CHAIN (args), i++)
433 if (i > 0)
434 put_decl_string (",", 1);
435 put_decl_node (TREE_VALUE (args), verbosity);
437 put_decl_string (")", 1);
440 else
441 put_decl_node (DECL_NAME (node), verbosity);
443 else if (TYPE_P (node) && TYPE_NAME (node) != NULL_TREE)
445 if (TREE_CODE (node) == RECORD_TYPE && TYPE_ARRAY_P (node)
446 /* Print detailed array information only if verbosity is higher
447 than 2. */
448 && verbosity >= 2)
450 put_decl_node (TYPE_ARRAY_ELEMENT (node), verbosity);
451 put_decl_string("[]", 2);
453 else if (node == promoted_byte_type_node)
454 put_decl_string ("byte", 4);
455 else if (node == promoted_short_type_node)
456 put_decl_string ("short", 5);
457 else if (node == promoted_char_type_node)
458 put_decl_string ("char", 4);
459 else if (node == promoted_boolean_type_node)
460 put_decl_string ("boolean", 7);
461 else if (node == void_type_node && was_pointer)
462 put_decl_string ("null", 4);
463 else
464 put_decl_node (TYPE_NAME (node), verbosity);
466 else if (TREE_CODE (node) == IDENTIFIER_NODE)
467 put_decl_string (IDENTIFIER_POINTER (node), IDENTIFIER_LENGTH (node));
468 else
469 put_decl_string ("<unknown>", -1);
472 /* Return a user-friendly name for DECL.
473 The resulting string is only valid until the next call.
474 The value of the hook decl_printable_name is this function,
475 which is also called directly by java_print_error_function. */
477 const char *
478 lang_printable_name (tree decl, int v)
480 decl_bufpos = 0;
481 put_decl_node (decl, v);
482 put_decl_string ("", 1);
483 return decl_buf;
486 /* Print on stderr the current class and method context. This function
487 is the value of the hook print_error_function. */
489 static GTY(()) tree last_error_function_context;
490 static GTY(()) tree last_error_function;
491 static void
492 java_print_error_function (diagnostic_context *context ATTRIBUTE_UNUSED,
493 const char *file,
494 diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
496 /* Don't print error messages with bogus function prototypes. */
497 if (inhibit_error_function_printing)
498 return;
500 if (current_function_decl != NULL
501 && DECL_CONTEXT (current_function_decl) != NULL
502 && DECL_CONTEXT (current_function_decl) != last_error_function_context)
504 if (file)
505 fprintf (stderr, "%s: ", file);
507 last_error_function_context = DECL_CONTEXT (current_function_decl);
508 fprintf (stderr, "In class '%s':\n",
509 lang_printable_name (last_error_function_context, 0));
511 if (last_error_function != current_function_decl)
513 if (file)
514 fprintf (stderr, "%s: ", file);
516 if (current_function_decl == NULL)
517 fprintf (stderr, "At top level:\n");
518 else
520 const char *name = lang_printable_name (current_function_decl, 2);
521 fprintf (stderr, "In %s '%s':\n",
522 (DECL_CONSTRUCTOR_P (current_function_decl) ? "constructor"
523 : "method"),
524 name);
527 last_error_function = current_function_decl;
532 /* Called to install the PRINT_ERROR_FUNCTION hook differently
533 according to LEVEL. LEVEL is 1 during early parsing, when function
534 prototypes aren't fully resolved. java_print_error_function is set
535 so it doesn't print incomplete function prototypes. When LEVEL is
536 2, function prototypes are fully resolved and can be printed when
537 reporting errors. */
539 void
540 lang_init_source (int level)
542 inhibit_error_function_printing = (level == 1);
545 static unsigned int
546 java_option_lang_mask (void)
548 return CL_Java;
551 /* Initialize options structure OPTS. */
553 static void
554 java_init_options_struct (struct gcc_options *opts)
556 opts->x_flag_bounds_check = 1;
557 opts->x_flag_exceptions = 1;
558 opts->x_flag_non_call_exceptions = 1;
560 /* In Java floating point operations never trap. */
561 opts->x_flag_trapping_math = 0;
562 opts->frontend_set_flag_trapping_math = true;
564 /* In Java arithmetic overflow always wraps around. */
565 opts->x_flag_wrapv = 1;
567 /* Java requires left-to-right evaluation of subexpressions. */
568 opts->x_flag_evaluation_order = 1;
570 /* Java catches NULL pointer exceptions, thus we can not necessarily
571 rely on a pointer having a non-NULL value after a dereference. */
572 opts->x_flag_delete_null_pointer_checks = 0;
575 static void
576 java_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
577 struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
579 jcf_path_init ();
582 /* Post-switch processing. */
583 static bool
584 java_post_options (const char **pfilename)
586 const char *filename = *pfilename;
588 /* Excess precision other than "fast" requires front-end
589 support. */
590 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
591 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
592 sorry ("-fexcess-precision=standard for Java");
593 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
595 /* An absolute requirement: if we're not using indirect dispatch, we
596 must always verify everything. */
597 if (! flag_indirect_dispatch)
598 flag_verify_invocations = true;
600 if (flag_reduced_reflection)
602 if (flag_indirect_dispatch)
603 error ("-findirect-dispatch is incompatible "
604 "with -freduced-reflection");
605 if (flag_jni)
606 error ("-fjni is incompatible with -freduced-reflection");
609 /* Open input file. */
611 if (filename == 0 || !strcmp (filename, "-"))
613 finput = stdin;
614 filename = "stdin";
616 if (dependency_tracking)
617 error ("can%'t do dependency tracking with input from stdin");
619 else
621 if (dependency_tracking)
623 const char *dot;
625 /* If the target is set and the output filename is set, then
626 there's no processing to do here. Otherwise we must
627 compute one or the other. */
628 if (! ((dependency_tracking & DEPEND_TARGET_SET)
629 && (dependency_tracking & DEPEND_FILE_ALREADY_SET)))
631 dot = strrchr (filename, '.');
632 if (dot == NULL)
633 error ("couldn%'t determine target name for dependency tracking");
634 else
636 char *buf = XNEWVEC (char, dot - filename +
637 3 + sizeof (TARGET_OBJECT_SUFFIX));
638 strncpy (buf, filename, dot - filename);
640 /* If emitting class files, we might have multiple
641 targets. The class generation code takes care of
642 registering them. Otherwise we compute the
643 target name here. */
644 if ((dependency_tracking & DEPEND_TARGET_SET))
645 ; /* Nothing. */
646 else
648 strcpy (buf + (dot - filename), TARGET_OBJECT_SUFFIX);
649 jcf_dependency_set_target (buf);
652 if ((dependency_tracking & DEPEND_FILE_ALREADY_SET))
653 ; /* Nothing. */
654 else if ((dependency_tracking & DEPEND_SET_FILE))
656 strcpy (buf + (dot - filename), ".d");
657 jcf_dependency_set_dep_file (buf);
659 else
660 jcf_dependency_set_dep_file ("-");
662 free (buf);
667 linemap_add (line_table, LC_ENTER, false, filename, 0);
668 linemap_add (line_table, LC_RENAME, false, "<built-in>", 0);
670 /* Initialize the compiler back end. */
671 return false;
674 /* Return either DECL or its known constant value (if it has one). */
676 tree
677 decl_constant_value (tree decl)
679 if (/* Don't change a variable array bound or initial value to a constant
680 in a place where a variable is invalid. */
681 current_function_decl != 0
682 && ! TREE_THIS_VOLATILE (decl)
683 && TREE_READONLY (decl)
684 && DECL_INITIAL (decl) != 0
685 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
686 /* This is invalid if initial value is not constant.
687 If it has either a function call, a memory reference,
688 or a variable, then re-evaluating it could give different results. */
689 && TREE_CONSTANT (DECL_INITIAL (decl))
690 /* Check for cases where this is sub-optimal, even though valid. */
691 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
692 return DECL_INITIAL (decl);
693 return decl;
696 /* Every call to a static constructor has an associated boolean
697 variable which is in the outermost scope of the calling method.
698 This variable is used to avoid multiple calls to the static
699 constructor for each class.
701 It looks something like this:
703 foo ()
705 boolean dummy = OtherClass.is_initialized;
709 if (! dummy)
710 OtherClass.initialize();
712 ... use OtherClass.data ...
715 Each of these boolean variables has an entry in the
716 DECL_FUNCTION_INIT_TEST_TABLE of a method. When inlining a method
717 we must merge the DECL_FUNCTION_INIT_TEST_TABLE from the function
718 being inlined and create the boolean variables in the outermost
719 scope of the method being inlined into. */
721 /* Create a mapping from a boolean variable in a method being inlined
722 to one in the scope of the method being inlined into. */
725 merge_init_test_initialization (treetreehash_entry **entry, void *x)
727 struct treetreehash_entry *ite = *entry;
728 splay_tree decl_map = (splay_tree)x;
729 splay_tree_node n;
730 tree *init_test_decl;
732 /* See if we have remapped this declaration. If we haven't there's
733 a bug in the inliner. */
734 n = splay_tree_lookup (decl_map, (splay_tree_key) ite->value);
735 gcc_assert (n);
737 /* Create a new entry for the class and its remapped boolean
738 variable. If we already have a mapping for this class we've
739 already initialized it, so don't overwrite the value. */
740 init_test_decl = java_treetreehash_new
741 (DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl), ite->key);
742 if (!*init_test_decl)
743 *init_test_decl = (tree)n->value;
745 /* This fixes a weird case.
747 The front end assumes that once we have called a method that
748 initializes some class, we can assume the class is initialized. It
749 does this by setting the DECL_INITIAL of the init_test_decl for that
750 class, and no initializations are emitted for that class.
752 However, what if the method that is supposed to do the initialization
753 is itself inlined in the caller? When expanding the called method
754 we'll assume that the class initialization has already been done,
755 because the DECL_INITIAL of the init_test_decl is set.
757 To fix this we remove the DECL_INITIAL (in the caller scope) of all
758 the init_test_decls corresponding to classes initialized by the
759 inlined method. This makes the caller no longer assume that the
760 method being inlined does any class initializations. */
761 DECL_INITIAL (*init_test_decl) = NULL;
763 return true;
766 /* Merge the DECL_FUNCTION_INIT_TEST_TABLE from the function we're
767 inlining. */
769 void
770 java_inlining_merge_static_initializers (tree fn, void *decl_map)
772 DECL_FUNCTION_INIT_TEST_TABLE (fn)
773 ->traverse<void *, merge_init_test_initialization> (decl_map);
776 /* Lookup a DECL_FUNCTION_INIT_TEST_TABLE entry in the method we're
777 inlining into. If we already have a corresponding entry in that
778 class we don't need to create another one, so we create a mapping
779 from the variable in the inlined class to the corresponding
780 pre-existing one. */
783 inline_init_test_initialization (treetreehash_entry **entry, void *x)
785 struct treetreehash_entry *ite = *entry;
786 splay_tree decl_map = (splay_tree)x;
788 tree h = java_treetreehash_find
789 (DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl), ite->key);
790 if (! h)
791 return true;
792 splay_tree_insert (decl_map,
793 (splay_tree_key) ite->value,
794 (splay_tree_value) h);
795 return true;
798 /* Look up the boolean variables in the DECL_FUNCTION_INIT_TEST_TABLE
799 of a method being inlined. For each hone, if we already have a
800 variable associated with the same class in the method being inlined
801 into, create a new mapping for it. */
803 void
804 java_inlining_map_static_initializers (tree fn, void *decl_map)
806 DECL_FUNCTION_INIT_TEST_TABLE (fn)
807 ->traverse<void *, inline_init_test_initialization> (decl_map);
810 /* Avoid voluminous output for deep recursion of compound exprs. */
812 static void
813 dump_compound_expr (dump_info_p di, tree t)
815 int i;
817 for (i=0; i<2; i++)
819 switch (TREE_CODE (TREE_OPERAND (t, i)))
821 case COMPOUND_EXPR:
822 dump_compound_expr (di, TREE_OPERAND (t, i));
823 break;
825 default:
826 dump_child ("expr", TREE_OPERAND (t, i));
831 static bool
832 java_dump_tree (void *dump_info, tree t)
834 enum tree_code code;
835 dump_info_p di = (dump_info_p) dump_info;
837 /* Figure out what kind of node this is. */
838 code = TREE_CODE (t);
840 switch (code)
842 case FUNCTION_DECL:
843 dump_child ("args", DECL_ARGUMENTS (t));
844 if (DECL_EXTERNAL (t))
845 dump_string (di, "undefined");
846 if (TREE_PUBLIC (t))
847 dump_string (di, "extern");
848 else
849 dump_string (di, "static");
850 if (DECL_LANG_SPECIFIC (t) && !dump_flag (di, TDF_SLIM, t))
851 dump_child ("inline body", DECL_SAVED_TREE (t));
852 return true;
854 case RETURN_EXPR:
855 dump_child ("expr", TREE_OPERAND (t, 0));
856 return true;
858 case GOTO_EXPR:
859 dump_child ("goto", TREE_OPERAND (t, 0));
860 return true;
862 case LABEL_EXPR:
863 dump_child ("label", TREE_OPERAND (t, 0));
864 return true;
866 case BLOCK:
867 if (BLOCK_EXPR_BODY (t))
869 tree local = BLOCK_VARS (t);
870 while (local)
872 tree next = TREE_CHAIN (local);
873 dump_child ("var", local);
874 local = next;
878 tree block = BLOCK_EXPR_BODY (t);
879 dump_child ("body", block);
880 block = TREE_CHAIN (block);
883 return true;
885 case COMPOUND_EXPR:
886 if (!dump_flag (di, TDF_SLIM, t))
887 return false;
888 dump_compound_expr (di, t);
889 return true;
891 default:
892 break;
894 return false;
897 /* Java calls can't, in general, be sibcalls because we need an
898 accurate stack trace in order to guarantee correct operation of
899 methods such as Class.forName(String) and
900 SecurityManager.getClassContext(). */
902 static bool
903 java_decl_ok_for_sibcall (const_tree decl)
905 return (decl != NULL && DECL_CONTEXT (decl) == output_class
906 && !DECL_UNINLINABLE (decl));
909 static enum classify_record
910 java_classify_record (tree type)
912 if (! CLASS_P (type))
913 return RECORD_IS_STRUCT;
915 if (CLASS_INTERFACE (TYPE_NAME (type)))
916 return RECORD_IS_INTERFACE;
918 return RECORD_IS_CLASS;
921 static GTY(()) tree java_eh_personality_decl;
923 static tree
924 java_eh_personality (void)
926 if (!java_eh_personality_decl)
927 java_eh_personality_decl = build_personality_function ("gcj");
928 return java_eh_personality_decl;
931 #include "gt-java-lang.h"