* langhooks-def.h (lhd_init_options, LANG_HOOKS_OPTION_LANG_MASK,
[official-gcc/alias-decl.git] / gcc / java / lang.c
blobc084cb88a7cc46c8cdbec7eae1e0b352a5b46313
1 /* Java(TM) language-specific utility routines.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2010 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC 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 3, or (at your option)
10 any later version.
12 GCC 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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>.
21 Java and all Java-based marks are trademarks or registered trademarks
22 of Sun Microsystems, Inc. in the United States and other countries.
23 The Free Software Foundation is independent of Sun Microsystems, Inc. */
25 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "tree.h"
32 #include "input.h"
33 #include "java-tree.h"
34 #include "jcf.h"
35 #include "toplev.h"
36 #include "langhooks.h"
37 #include "langhooks-def.h"
38 #include "flags.h"
39 #include "ggc.h"
40 #include "diagnostic.h"
41 #include "tree-inline.h"
42 #include "splay-tree.h"
43 #include "tree-dump.h"
44 #include "opts.h"
45 #include "options.h"
47 static bool java_init (void);
48 static void java_finish (void);
49 static unsigned int java_option_lang_mask (void);
50 static void java_init_options (unsigned int, struct cl_decoded_option *);
51 static bool java_post_options (const char **);
53 static int java_handle_option (size_t scode, const char *arg, int value, int kind);
54 static void put_decl_string (const char *, int);
55 static void put_decl_node (tree, int);
56 static void java_print_error_function (diagnostic_context *, const char *,
57 diagnostic_info *);
58 static int merge_init_test_initialization (void * *, void *);
59 static int inline_init_test_initialization (void * *, void *);
60 static bool java_dump_tree (void *, tree);
61 static void dump_compound_expr (dump_info_p, tree);
62 static bool java_decl_ok_for_sibcall (const_tree);
64 static enum classify_record java_classify_record (tree type);
66 static tree java_eh_personality (void);
68 #ifndef TARGET_OBJECT_SUFFIX
69 # define TARGET_OBJECT_SUFFIX ".o"
70 #endif
72 /* Table of machine-independent attributes. */
73 const struct attribute_spec java_attribute_table[] =
75 { "nonnull", 0, -1, false, true, true,
76 NULL },
77 { NULL, 0, 0, false, false, false, NULL }
80 /* Used to avoid printing error messages with bogus function
81 prototypes. Starts out false. */
82 static bool inhibit_error_function_printing;
84 const char *resource_name;
86 /* When nonzero, -Wall was turned on. */
87 int flag_wall = 0;
89 /* When nonzero, report use of deprecated classes, methods, or fields. */
90 int flag_deprecated = 1;
92 /* When zero, don't optimize static class initialization. This flag shouldn't
93 be tested alone, use STATIC_CLASS_INITIALIZATION_OPTIMIZATION_P instead. */
94 /* FIXME: Make this work with gimplify. */
95 /* int flag_optimize_sci = 0; */
97 /* Don't attempt to verify invocations. */
98 int flag_verify_invocations = 0;
100 /* When nonzero, print extra version information. */
101 static int v_flag = 0;
103 JCF *current_jcf;
105 /* Variable controlling how dependency tracking is enabled in
106 java_init. */
107 static int dependency_tracking = 0;
109 /* Flag values for DEPENDENCY_TRACKING. */
110 #define DEPEND_SET_FILE 1
111 #define DEPEND_ENABLE 2
112 #define DEPEND_TARGET_SET 4
113 #define DEPEND_FILE_ALREADY_SET 8
115 struct GTY(()) language_function {
116 int unused;
119 #undef LANG_HOOKS_NAME
120 #define LANG_HOOKS_NAME "GNU Java"
121 #undef LANG_HOOKS_INIT
122 #define LANG_HOOKS_INIT java_init
123 #undef LANG_HOOKS_FINISH
124 #define LANG_HOOKS_FINISH java_finish
125 #undef LANG_HOOKS_OPTION_LANG_MASK
126 #define LANG_HOOKS_OPTION_LANG_MASK java_option_lang_mask
127 #undef LANG_HOOKS_INIT_OPTIONS
128 #define LANG_HOOKS_INIT_OPTIONS java_init_options
129 #undef LANG_HOOKS_HANDLE_OPTION
130 #define LANG_HOOKS_HANDLE_OPTION java_handle_option
131 #undef LANG_HOOKS_POST_OPTIONS
132 #define LANG_HOOKS_POST_OPTIONS java_post_options
133 #undef LANG_HOOKS_PARSE_FILE
134 #define LANG_HOOKS_PARSE_FILE java_parse_file
135 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
136 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL java_dup_lang_specific_decl
137 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
138 #define LANG_HOOKS_DECL_PRINTABLE_NAME lang_printable_name
139 #undef LANG_HOOKS_PRINT_ERROR_FUNCTION
140 #define LANG_HOOKS_PRINT_ERROR_FUNCTION java_print_error_function
141 #undef LANG_HOOKS_WRITE_GLOBALS
142 #define LANG_HOOKS_WRITE_GLOBALS java_write_globals
144 #undef LANG_HOOKS_TYPE_FOR_MODE
145 #define LANG_HOOKS_TYPE_FOR_MODE java_type_for_mode
146 #undef LANG_HOOKS_TYPE_FOR_SIZE
147 #define LANG_HOOKS_TYPE_FOR_SIZE java_type_for_size
148 #undef LANG_HOOKS_CLASSIFY_RECORD
149 #define LANG_HOOKS_CLASSIFY_RECORD java_classify_record
151 #undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN
152 #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN java_dump_tree
154 #undef LANG_HOOKS_GIMPLIFY_EXPR
155 #define LANG_HOOKS_GIMPLIFY_EXPR java_gimplify_expr
157 #undef LANG_HOOKS_DECL_OK_FOR_SIBCALL
158 #define LANG_HOOKS_DECL_OK_FOR_SIBCALL java_decl_ok_for_sibcall
160 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
161 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME java_mangle_decl
163 #undef LANG_HOOKS_ATTRIBUTE_TABLE
164 #define LANG_HOOKS_ATTRIBUTE_TABLE java_attribute_table
166 #undef LANG_HOOKS_EH_PERSONALITY
167 #define LANG_HOOKS_EH_PERSONALITY java_eh_personality
169 #undef LANG_HOOKS_EH_USE_CXA_END_CLEANUP
170 #define LANG_HOOKS_EH_USE_CXA_END_CLEANUP true
172 /* Each front end provides its own. */
173 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
176 * process java-specific compiler command-line options
177 * return 0, but do not complain if the option is not recognized.
179 static int
180 java_handle_option (size_t scode, const char *arg, int value,
181 int kind ATTRIBUTE_UNUSED)
183 enum opt_code code = (enum opt_code) scode;
185 switch (code)
187 case OPT_I:
188 jcf_path_include_arg (arg);
189 break;
191 case OPT_M:
192 jcf_dependency_init (1);
193 dependency_tracking |= DEPEND_ENABLE;
194 break;
196 case OPT_MD_:
197 jcf_dependency_init (1);
198 dependency_tracking |= DEPEND_SET_FILE | DEPEND_ENABLE;
199 break;
201 case OPT_MF:
202 jcf_dependency_set_dep_file (arg);
203 dependency_tracking |= DEPEND_FILE_ALREADY_SET;
204 break;
206 case OPT_MM:
207 jcf_dependency_init (0);
208 dependency_tracking |= DEPEND_ENABLE;
209 break;
211 case OPT_MMD_:
212 jcf_dependency_init (0);
213 dependency_tracking |= DEPEND_SET_FILE | DEPEND_ENABLE;
214 break;
216 case OPT_MP:
217 jcf_dependency_print_dummies ();
218 break;
220 case OPT_MT:
221 jcf_dependency_set_target (arg);
222 dependency_tracking |= DEPEND_TARGET_SET;
223 break;
225 case OPT_Wall:
226 flag_wall = value;
227 /* When -Wall given, enable -Wunused. We do this because the C
228 compiler does it, and people expect it. */
229 warn_unused = value;
230 break;
232 case OPT_fenable_assertions_:
233 add_enable_assert (arg, value);
234 break;
236 case OPT_fenable_assertions:
237 add_enable_assert ("", value);
238 break;
240 case OPT_fdisable_assertions_:
241 add_enable_assert (arg, !value);
242 break;
244 case OPT_fdisable_assertions:
245 add_enable_assert ("", !value);
246 break;
248 case OPT_fassume_compiled_:
249 add_assume_compiled (arg, !value);
250 break;
252 case OPT_fassume_compiled:
253 add_assume_compiled ("", !value);
254 break;
256 case OPT_fbootclasspath_:
257 jcf_path_bootclasspath_arg (arg);
258 break;
260 case OPT_faux_classpath:
261 case OPT_fclasspath_:
262 case OPT_fCLASSPATH_:
263 jcf_path_classpath_arg (arg);
264 break;
266 case OPT_fcompile_resource_:
267 resource_name = arg;
268 break;
270 case OPT_fdump_:
271 if (!dump_switch_p (arg))
272 return 0;
273 break;
275 case OPT_fencoding_:
276 /* Nothing. */
277 break;
279 case OPT_fextdirs_:
280 jcf_path_extdirs_arg (arg);
281 break;
283 case OPT_foutput_class_dir_:
284 /* FIXME: remove; this is handled by ecj1 now. */
285 break;
287 case OPT_version:
288 v_flag = 1;
289 break;
291 case OPT_fsource_filename_:
292 java_read_sourcefilenames (arg);
293 break;
295 default:
296 if (cl_options[code].flags & CL_Java)
297 break;
298 gcc_unreachable ();
301 return 1;
304 /* Global open file. */
305 FILE *finput;
307 static bool
308 java_init (void)
310 /* FIXME: Indirect dispatch isn't yet compatible with static class
311 init optimization. */
312 if (flag_indirect_dispatch)
313 always_initialize_class_p = true;
315 if (!flag_indirect_dispatch)
316 flag_indirect_classes = false;
318 jcf_path_seal (v_flag);
320 java_init_decl_processing ();
322 using_eh_for_cleanups ();
324 return true;
327 static void
328 java_finish (void)
330 jcf_dependency_write ();
333 /* Buffer used by lang_printable_name. */
334 static char *decl_buf = NULL;
336 /* Allocated size of decl_buf. */
337 static int decl_buflen = 0;
339 /* Length of used part of decl_buf; position for next character. */
340 static int decl_bufpos = 0;
342 /* Append the string STR to decl_buf.
343 It length is given by LEN; -1 means the string is nul-terminated. */
345 static void
346 put_decl_string (const char *str, int len)
348 if (len < 0)
349 len = strlen (str);
350 if (decl_bufpos + len >= decl_buflen)
352 if (decl_buf == NULL)
354 decl_buflen = len + 100;
355 decl_buf = XNEWVEC (char, decl_buflen);
357 else
359 decl_buflen *= 2;
360 decl_buf = XRESIZEVAR (char, decl_buf, decl_buflen);
363 strcpy (decl_buf + decl_bufpos, str);
364 decl_bufpos += len;
367 /* Append to decl_buf a printable name for NODE.
368 Depending on VERBOSITY, more information about NODE
369 is printed. Read the comments of decl_printable_name in
370 langhooks.h for more. */
372 static void
373 put_decl_node (tree node, int verbosity)
375 int was_pointer = 0;
376 if (TREE_CODE (node) == POINTER_TYPE)
378 node = TREE_TYPE (node);
379 was_pointer = 1;
381 if (DECL_P (node) && DECL_NAME (node) != NULL_TREE)
383 if (TREE_CODE (node) == FUNCTION_DECL)
385 if (verbosity == 0 && DECL_NAME (node))
386 /* We have been instructed to just print the bare name
387 of the function. */
389 put_decl_node (DECL_NAME (node), 0);
390 return;
393 /* We want to print the type the DECL belongs to. We don't do
394 that when we handle constructors. */
395 if (! DECL_CONSTRUCTOR_P (node)
396 && ! DECL_ARTIFICIAL (node) && DECL_CONTEXT (node)
397 /* We want to print qualified DECL names only
398 if verbosity is higher than 1. */
399 && verbosity >= 1)
401 put_decl_node (TYPE_NAME (DECL_CONTEXT (node)),
402 verbosity);
403 put_decl_string (".", 1);
405 if (! DECL_CONSTRUCTOR_P (node))
406 put_decl_node (DECL_NAME (node), verbosity);
407 if (TREE_TYPE (node) != NULL_TREE
408 /* We want to print function parameters only if verbosity
409 is higher than 2. */
410 && verbosity >= 2)
412 int i = 0;
413 tree args = TYPE_ARG_TYPES (TREE_TYPE (node));
414 if (TREE_CODE (TREE_TYPE (node)) == METHOD_TYPE)
415 args = TREE_CHAIN (args);
416 put_decl_string ("(", 1);
417 for ( ; args != end_params_node; args = TREE_CHAIN (args), i++)
419 if (i > 0)
420 put_decl_string (",", 1);
421 put_decl_node (TREE_VALUE (args), verbosity);
423 put_decl_string (")", 1);
426 else
427 put_decl_node (DECL_NAME (node), verbosity);
429 else if (TYPE_P (node) && TYPE_NAME (node) != NULL_TREE)
431 if (TREE_CODE (node) == RECORD_TYPE && TYPE_ARRAY_P (node)
432 /* Print detailed array information only if verbosity is higher
433 than 2. */
434 && verbosity >= 2)
436 put_decl_node (TYPE_ARRAY_ELEMENT (node), verbosity);
437 put_decl_string("[]", 2);
439 else if (node == promoted_byte_type_node)
440 put_decl_string ("byte", 4);
441 else if (node == promoted_short_type_node)
442 put_decl_string ("short", 5);
443 else if (node == promoted_char_type_node)
444 put_decl_string ("char", 4);
445 else if (node == promoted_boolean_type_node)
446 put_decl_string ("boolean", 7);
447 else if (node == void_type_node && was_pointer)
448 put_decl_string ("null", 4);
449 else
450 put_decl_node (TYPE_NAME (node), verbosity);
452 else if (TREE_CODE (node) == IDENTIFIER_NODE)
453 put_decl_string (IDENTIFIER_POINTER (node), IDENTIFIER_LENGTH (node));
454 else
455 put_decl_string ("<unknown>", -1);
458 /* Return a user-friendly name for DECL.
459 The resulting string is only valid until the next call.
460 The value of the hook decl_printable_name is this function,
461 which is also called directly by java_print_error_function. */
463 const char *
464 lang_printable_name (tree decl, int v)
466 decl_bufpos = 0;
467 put_decl_node (decl, v);
468 put_decl_string ("", 1);
469 return decl_buf;
472 /* Print on stderr the current class and method context. This function
473 is the value of the hook print_error_function. */
475 static GTY(()) tree last_error_function_context;
476 static GTY(()) tree last_error_function;
477 static void
478 java_print_error_function (diagnostic_context *context ATTRIBUTE_UNUSED,
479 const char *file,
480 diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
482 /* Don't print error messages with bogus function prototypes. */
483 if (inhibit_error_function_printing)
484 return;
486 if (current_function_decl != NULL
487 && DECL_CONTEXT (current_function_decl) != last_error_function_context)
489 if (file)
490 fprintf (stderr, "%s: ", file);
492 last_error_function_context = DECL_CONTEXT (current_function_decl);
493 fprintf (stderr, "In class '%s':\n",
494 lang_printable_name (last_error_function_context, 0));
496 if (last_error_function != current_function_decl)
498 if (file)
499 fprintf (stderr, "%s: ", file);
501 if (current_function_decl == NULL)
502 fprintf (stderr, "At top level:\n");
503 else
505 const char *name = lang_printable_name (current_function_decl, 2);
506 fprintf (stderr, "In %s '%s':\n",
507 (DECL_CONSTRUCTOR_P (current_function_decl) ? "constructor"
508 : "method"),
509 name);
512 last_error_function = current_function_decl;
517 /* Called to install the PRINT_ERROR_FUNCTION hook differently
518 according to LEVEL. LEVEL is 1 during early parsing, when function
519 prototypes aren't fully resolved. java_print_error_function is set
520 so it doesn't print incomplete function prototypes. When LEVEL is
521 2, function prototypes are fully resolved and can be printed when
522 reporting errors. */
524 void
525 lang_init_source (int level)
527 inhibit_error_function_printing = (level == 1);
530 static unsigned int
531 java_option_lang_mask (void)
533 return CL_Java;
536 static void
537 java_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
538 struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
540 flag_bounds_check = 1;
541 flag_exceptions = 1;
542 flag_non_call_exceptions = 1;
544 /* In Java floating point operations never trap. */
545 flag_trapping_math = 0;
547 /* In Java arithmetic overflow always wraps around. */
548 flag_wrapv = 1;
550 /* Java requires left-to-right evaluation of subexpressions. */
551 flag_evaluation_order = 1;
553 jcf_path_init ();
556 /* Post-switch processing. */
557 static bool
558 java_post_options (const char **pfilename)
560 const char *filename = *pfilename;
562 /* Excess precision other than "fast" requires front-end
563 support. */
564 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
565 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
566 sorry ("-fexcess-precision=standard for Java");
567 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
569 /* An absolute requirement: if we're not using indirect dispatch, we
570 must always verify everything. */
571 if (! flag_indirect_dispatch)
572 flag_verify_invocations = true;
574 if (flag_reduced_reflection)
576 if (flag_indirect_dispatch)
577 error ("-findirect-dispatch is incompatible "
578 "with -freduced-reflection");
579 if (flag_jni)
580 error ("-fjni is incompatible with -freduced-reflection");
583 /* Open input file. */
585 if (filename == 0 || !strcmp (filename, "-"))
587 finput = stdin;
588 filename = "stdin";
590 if (dependency_tracking)
591 error ("can't do dependency tracking with input from stdin");
593 else
595 if (dependency_tracking)
597 const char *dot;
599 /* If the target is set and the output filename is set, then
600 there's no processing to do here. Otherwise we must
601 compute one or the other. */
602 if (! ((dependency_tracking & DEPEND_TARGET_SET)
603 && (dependency_tracking & DEPEND_FILE_ALREADY_SET)))
605 dot = strrchr (filename, '.');
606 if (dot == NULL)
607 error ("couldn't determine target name for dependency tracking");
608 else
610 char *buf = XNEWVEC (char, dot - filename +
611 3 + sizeof (TARGET_OBJECT_SUFFIX));
612 strncpy (buf, filename, dot - filename);
614 /* If emitting class files, we might have multiple
615 targets. The class generation code takes care of
616 registering them. Otherwise we compute the
617 target name here. */
618 if ((dependency_tracking & DEPEND_TARGET_SET))
619 ; /* Nothing. */
620 else
622 strcpy (buf + (dot - filename), TARGET_OBJECT_SUFFIX);
623 jcf_dependency_set_target (buf);
626 if ((dependency_tracking & DEPEND_FILE_ALREADY_SET))
627 ; /* Nothing. */
628 else if ((dependency_tracking & DEPEND_SET_FILE))
630 strcpy (buf + (dot - filename), ".d");
631 jcf_dependency_set_dep_file (buf);
633 else
634 jcf_dependency_set_dep_file ("-");
636 free (buf);
641 linemap_add (line_table, LC_ENTER, false, filename, 0);
642 linemap_add (line_table, LC_RENAME, false, "<built-in>", 0);
644 /* Initialize the compiler back end. */
645 return false;
648 /* Return either DECL or its known constant value (if it has one). */
650 tree
651 decl_constant_value (tree decl)
653 if (/* Don't change a variable array bound or initial value to a constant
654 in a place where a variable is invalid. */
655 current_function_decl != 0
656 && ! TREE_THIS_VOLATILE (decl)
657 && TREE_READONLY (decl)
658 && DECL_INITIAL (decl) != 0
659 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
660 /* This is invalid if initial value is not constant.
661 If it has either a function call, a memory reference,
662 or a variable, then re-evaluating it could give different results. */
663 && TREE_CONSTANT (DECL_INITIAL (decl))
664 /* Check for cases where this is sub-optimal, even though valid. */
665 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
666 return DECL_INITIAL (decl);
667 return decl;
670 /* Every call to a static constructor has an associated boolean
671 variable which is in the outermost scope of the calling method.
672 This variable is used to avoid multiple calls to the static
673 constructor for each class.
675 It looks something like this:
677 foo ()
679 boolean dummy = OtherClass.is_initialized;
683 if (! dummy)
684 OtherClass.initialize();
686 ... use OtherClass.data ...
689 Each of these boolean variables has an entry in the
690 DECL_FUNCTION_INIT_TEST_TABLE of a method. When inlining a method
691 we must merge the DECL_FUNCTION_INIT_TEST_TABLE from the function
692 being inlined and create the boolean variables in the outermost
693 scope of the method being inlined into. */
695 /* Create a mapping from a boolean variable in a method being inlined
696 to one in the scope of the method being inlined into. */
698 static int
699 merge_init_test_initialization (void **entry, void *x)
701 struct treetreehash_entry *ite = (struct treetreehash_entry *) *entry;
702 splay_tree decl_map = (splay_tree)x;
703 splay_tree_node n;
704 tree *init_test_decl;
706 /* See if we have remapped this declaration. If we haven't there's
707 a bug in the inliner. */
708 n = splay_tree_lookup (decl_map, (splay_tree_key) ite->value);
709 gcc_assert (n);
711 /* Create a new entry for the class and its remapped boolean
712 variable. If we already have a mapping for this class we've
713 already initialized it, so don't overwrite the value. */
714 init_test_decl = java_treetreehash_new
715 (DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl), ite->key);
716 if (!*init_test_decl)
717 *init_test_decl = (tree)n->value;
719 /* This fixes a weird case.
721 The front end assumes that once we have called a method that
722 initializes some class, we can assume the class is initialized. It
723 does this by setting the DECL_INITIAL of the init_test_decl for that
724 class, and no initializations are emitted for that class.
726 However, what if the method that is supposed to do the initialization
727 is itself inlined in the caller? When expanding the called method
728 we'll assume that the class initialization has already been done,
729 because the DECL_INITIAL of the init_test_decl is set.
731 To fix this we remove the DECL_INITIAL (in the caller scope) of all
732 the init_test_decls corresponding to classes initialized by the
733 inlined method. This makes the caller no longer assume that the
734 method being inlined does any class initializations. */
735 DECL_INITIAL (*init_test_decl) = NULL;
737 return true;
740 /* Merge the DECL_FUNCTION_INIT_TEST_TABLE from the function we're
741 inlining. */
743 void
744 java_inlining_merge_static_initializers (tree fn, void *decl_map)
746 htab_traverse
747 (DECL_FUNCTION_INIT_TEST_TABLE (fn),
748 merge_init_test_initialization, decl_map);
751 /* Lookup a DECL_FUNCTION_INIT_TEST_TABLE entry in the method we're
752 inlining into. If we already have a corresponding entry in that
753 class we don't need to create another one, so we create a mapping
754 from the variable in the inlined class to the corresponding
755 pre-existing one. */
757 static int
758 inline_init_test_initialization (void **entry, void *x)
760 struct treetreehash_entry *ite = (struct treetreehash_entry *) *entry;
761 splay_tree decl_map = (splay_tree)x;
763 tree h = java_treetreehash_find
764 (DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl), ite->key);
765 if (! h)
766 return true;
767 splay_tree_insert (decl_map,
768 (splay_tree_key) ite->value,
769 (splay_tree_value) h);
770 return true;
773 /* Look up the boolean variables in the DECL_FUNCTION_INIT_TEST_TABLE
774 of a method being inlined. For each hone, if we already have a
775 variable associated with the same class in the method being inlined
776 into, create a new mapping for it. */
778 void
779 java_inlining_map_static_initializers (tree fn, void *decl_map)
781 htab_traverse
782 (DECL_FUNCTION_INIT_TEST_TABLE (fn),
783 inline_init_test_initialization, decl_map);
786 /* Avoid voluminous output for deep recursion of compound exprs. */
788 static void
789 dump_compound_expr (dump_info_p di, tree t)
791 int i;
793 for (i=0; i<2; i++)
795 switch (TREE_CODE (TREE_OPERAND (t, i)))
797 case COMPOUND_EXPR:
798 dump_compound_expr (di, TREE_OPERAND (t, i));
799 break;
801 default:
802 dump_child ("expr", TREE_OPERAND (t, i));
807 static bool
808 java_dump_tree (void *dump_info, tree t)
810 enum tree_code code;
811 dump_info_p di = (dump_info_p) dump_info;
813 /* Figure out what kind of node this is. */
814 code = TREE_CODE (t);
816 switch (code)
818 case FUNCTION_DECL:
819 dump_child ("args", DECL_ARGUMENTS (t));
820 if (DECL_EXTERNAL (t))
821 dump_string (di, "undefined");
822 if (TREE_PUBLIC (t))
823 dump_string (di, "extern");
824 else
825 dump_string (di, "static");
826 if (DECL_LANG_SPECIFIC (t) && !dump_flag (di, TDF_SLIM, t))
827 dump_child ("inline body", DECL_SAVED_TREE (t));
828 return true;
830 case RETURN_EXPR:
831 dump_child ("expr", TREE_OPERAND (t, 0));
832 return true;
834 case GOTO_EXPR:
835 dump_child ("goto", TREE_OPERAND (t, 0));
836 return true;
838 case LABEL_EXPR:
839 dump_child ("label", TREE_OPERAND (t, 0));
840 return true;
842 case BLOCK:
843 if (BLOCK_EXPR_BODY (t))
845 tree local = BLOCK_VARS (t);
846 while (local)
848 tree next = TREE_CHAIN (local);
849 dump_child ("var", local);
850 local = next;
854 tree block = BLOCK_EXPR_BODY (t);
855 dump_child ("body", block);
856 block = TREE_CHAIN (block);
859 return true;
861 case COMPOUND_EXPR:
862 if (!dump_flag (di, TDF_SLIM, t))
863 return false;
864 dump_compound_expr (di, t);
865 return true;
867 default:
868 break;
870 return false;
873 /* Java calls can't, in general, be sibcalls because we need an
874 accurate stack trace in order to guarantee correct operation of
875 methods such as Class.forName(String) and
876 SecurityManager.getClassContext(). */
878 static bool
879 java_decl_ok_for_sibcall (const_tree decl)
881 return (decl != NULL && DECL_CONTEXT (decl) == output_class
882 && !DECL_UNINLINABLE (decl));
885 static enum classify_record
886 java_classify_record (tree type)
888 if (! CLASS_P (type))
889 return RECORD_IS_STRUCT;
891 if (CLASS_INTERFACE (TYPE_NAME (type)))
892 return RECORD_IS_INTERFACE;
894 return RECORD_IS_CLASS;
897 static GTY(()) tree java_eh_personality_decl;
899 static tree
900 java_eh_personality (void)
902 if (!java_eh_personality_decl)
903 java_eh_personality_decl
904 = build_personality_function (USING_SJLJ_EXCEPTIONS
905 ? "__gcj_personality_sj0"
906 : "__gcj_personality_v0");
908 return java_eh_personality_decl;
911 #include "gt-java-lang.h"