1 /* Java(TM) language-specific utility routines.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 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 2, or (at your option)
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 COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
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. */
26 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
30 #include "coretypes.h"
36 #include "java-tree.h"
39 #include "langhooks.h"
40 #include "langhooks-def.h"
44 #include "diagnostic.h"
45 #include "tree-inline.h"
46 #include "splay-tree.h"
47 #include "tree-dump.h"
51 const char *const string
;
56 static bool java_init (void);
57 static void java_finish (void);
58 static void java_init_options (void);
59 static bool java_post_options (const char **);
61 static int java_decode_option (int, char **);
62 static void put_decl_string (const char *, int);
63 static void put_decl_node (tree
);
64 static void java_print_error_function (diagnostic_context
*, const char *);
65 static int process_option_with_no (const char *, const struct string_option
*, int);
66 static tree
java_tree_inlining_walk_subtrees (tree
*, int *, walk_tree_fn
,
68 static int java_unsafe_for_reeval (tree
);
69 static int merge_init_test_initialization (void * *, void *);
70 static int inline_init_test_initialization (void * *, void *);
71 static bool java_can_use_bit_fields_p (void);
72 static bool java_dump_tree (void *, tree
);
73 static void dump_compound_expr (dump_info_p
, tree
);
75 #ifndef TARGET_OBJECT_SUFFIX
76 # define TARGET_OBJECT_SUFFIX ".o"
79 /* Table indexed by tree code giving a string containing a character
80 classifying the tree code. Possibilities are
81 t, d, s, c, r, <, 1 and 2. See java/java-tree.def for details. */
83 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
85 const char tree_code_type
[] = {
88 #include "java-tree.def"
92 /* Table indexed by tree code giving number of expression
93 operands beyond the fixed part of the node structure.
94 Not used for types or decls. */
96 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
98 const unsigned char tree_code_length
[] = {
101 #include "java-tree.def"
105 /* Names of tree components.
106 Used for printing out the tree and error messages. */
107 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
109 const char *const tree_code_name
[] = {
112 #include "java-tree.def"
116 /* Used to avoid printing error messages with bogus function
117 prototypes. Starts out false. */
118 static bool inhibit_error_function_printing
;
120 int compiling_from_source
;
122 char * resource_name
;
124 int flag_emit_class_files
= 0;
126 /* Nonzero if input file is a file with a list of filenames to compile. */
128 int flag_filelist_file
= 0;
130 /* When nonzero, we emit xref strings. Values of the flag for xref
131 backends are defined in xref_flag_table, xref.c. */
133 int flag_emit_xref
= 0;
135 /* When nonzero, -Wall was turned on. */
138 /* When nonzero, check for redundant modifier uses. */
139 int flag_redundant
= 0;
141 /* When nonzero, call a library routine to do integer divisions. */
142 int flag_use_divide_subroutine
= 1;
144 /* When nonzero, generate code for the Boehm GC. */
145 int flag_use_boehm_gc
= 0;
147 /* When nonzero, assume the runtime uses a hash table to map an
148 object to its synchronization structure. */
149 int flag_hash_synchronization
;
151 /* When nonzero, permit the use of the assert keyword. */
154 /* When nonzero, assume all native functions are implemented with
158 /* When nonzero, warn when source file is newer than matching class
162 /* When nonzero, generate checks for references to NULL. */
163 int flag_check_references
= 0;
165 /* The encoding of the source file. */
166 const char *current_encoding
= NULL
;
168 /* When nonzero, report the now deprecated empty statements. */
169 int flag_extraneous_semicolon
;
171 /* When nonzero, report use of deprecated classes, methods, or fields. */
172 int flag_deprecated
= 1;
174 /* When nonzero, always check for a non gcj generated classes archive. */
175 int flag_force_classes_archive_check
;
177 /* When zero, don't optimize static class initialization. This flag shouldn't
178 be tested alone, use STATIC_CLASS_INITIALIZATION_OPTIMIZATION_P instead. */
179 int flag_optimize_sci
= 1;
181 /* When nonzero, use offset tables for virtual method calls
182 in order to improve binary compatibility. */
183 int flag_indirect_dispatch
= 0;
185 /* When zero, don't generate runtime array store checks. */
186 int flag_store_check
= 1;
188 /* When nonzero, print extra version information. */
189 static int version_flag
= 0;
191 /* Set nonzero if the user specified -finline-functions on the command
193 int flag_really_inline
= 0;
195 /* Table of language-dependent -f options.
196 STRING is the option name. VARIABLE is the address of the variable.
197 ON_VALUE is the value to store in VARIABLE
198 if `-fSTRING' is seen as an option.
199 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
201 static const struct string_option
204 {"emit-class-file", &flag_emit_class_files
, 1},
205 {"emit-class-files", &flag_emit_class_files
, 1},
206 {"filelist-file", &flag_filelist_file
, 1},
207 {"use-divide-subroutine", &flag_use_divide_subroutine
, 1},
208 {"use-boehm-gc", &flag_use_boehm_gc
, 1},
209 {"hash-synchronization", &flag_hash_synchronization
, 1},
210 {"jni", &flag_jni
, 1},
211 {"check-references", &flag_check_references
, 1},
212 {"force-classes-archive-check", &flag_force_classes_archive_check
, 1},
213 {"optimize-static-class-initialization", &flag_optimize_sci
, 1 },
214 {"indirect-dispatch", &flag_indirect_dispatch
, 1},
215 {"store-check", &flag_store_check
, 1},
216 {"assert", &flag_assert
, 1}
219 static const struct string_option
222 { "redundant-modifiers", &flag_redundant
, 1 },
223 { "extraneous-semicolon", &flag_extraneous_semicolon
, 1 },
224 { "out-of-date", &flag_newer
, 1 },
225 { "deprecated", &flag_deprecated
, 1 }
230 /* Variable controlling how dependency tracking is enabled in
232 static int dependency_tracking
= 0;
234 /* Flag values for DEPENDENCY_TRACKING. */
235 #define DEPEND_SET_FILE 1
236 #define DEPEND_ENABLE 2
237 #define DEPEND_TARGET_SET 4
238 #define DEPEND_FILE_ALREADY_SET 8
240 struct language_function
GTY(())
245 #undef LANG_HOOKS_NAME
246 #define LANG_HOOKS_NAME "GNU Java"
247 #undef LANG_HOOKS_INIT
248 #define LANG_HOOKS_INIT java_init
249 #undef LANG_HOOKS_FINISH
250 #define LANG_HOOKS_FINISH java_finish
251 #undef LANG_HOOKS_INIT_OPTIONS
252 #define LANG_HOOKS_INIT_OPTIONS java_init_options
253 #undef LANG_HOOKS_DECODE_OPTION
254 #define LANG_HOOKS_DECODE_OPTION java_decode_option
255 #undef LANG_HOOKS_POST_OPTIONS
256 #define LANG_HOOKS_POST_OPTIONS java_post_options
257 #undef LANG_HOOKS_PARSE_FILE
258 #define LANG_HOOKS_PARSE_FILE java_parse_file
259 #undef LANG_HOOKS_UNSAFE_FOR_REEVAL
260 #define LANG_HOOKS_UNSAFE_FOR_REEVAL java_unsafe_for_reeval
261 #undef LANG_HOOKS_MARK_ADDRESSABLE
262 #define LANG_HOOKS_MARK_ADDRESSABLE java_mark_addressable
263 #undef LANG_HOOKS_EXPAND_EXPR
264 #define LANG_HOOKS_EXPAND_EXPR java_expand_expr
265 #undef LANG_HOOKS_TRUTHVALUE_CONVERSION
266 #define LANG_HOOKS_TRUTHVALUE_CONVERSION java_truthvalue_conversion
267 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
268 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL java_dup_lang_specific_decl
269 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
270 #define LANG_HOOKS_DECL_PRINTABLE_NAME lang_printable_name
271 #undef LANG_HOOKS_PRINT_ERROR_FUNCTION
272 #define LANG_HOOKS_PRINT_ERROR_FUNCTION java_print_error_function
273 #undef LANG_HOOKS_CAN_USE_BIT_FIELDS_P
274 #define LANG_HOOKS_CAN_USE_BIT_FIELDS_P java_can_use_bit_fields_p
276 #undef LANG_HOOKS_TYPE_FOR_MODE
277 #define LANG_HOOKS_TYPE_FOR_MODE java_type_for_mode
278 #undef LANG_HOOKS_TYPE_FOR_SIZE
279 #define LANG_HOOKS_TYPE_FOR_SIZE java_type_for_size
280 #undef LANG_HOOKS_SIGNED_TYPE
281 #define LANG_HOOKS_SIGNED_TYPE java_signed_type
282 #undef LANG_HOOKS_UNSIGNED_TYPE
283 #define LANG_HOOKS_UNSIGNED_TYPE java_unsigned_type
284 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
285 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE java_signed_or_unsigned_type
287 #undef LANG_HOOKS_TREE_INLINING_WALK_SUBTREES
288 #define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES java_tree_inlining_walk_subtrees
290 #undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN
291 #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN java_dump_tree
293 /* Each front end provides its own. */
294 const struct lang_hooks lang_hooks
= LANG_HOOKS_INITIALIZER
;
296 /* Process an option that can accept a `no-' form.
297 Return 1 if option found, 0 otherwise. */
299 process_option_with_no (const char *p
, const struct string_option
*table
,
304 for (j
= 0; j
< table_size
; j
++)
306 if (!strcmp (p
, table
[j
].string
))
308 *table
[j
].variable
= table
[j
].on_value
;
311 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
312 && ! strcmp (p
+3, table
[j
].string
))
314 *table
[j
].variable
= ! table
[j
].on_value
;
323 * process java-specific compiler command-line options
324 * return 0, but do not complain if the option is not recognized.
327 java_decode_option (int argc
__attribute__ ((__unused__
)), char **argv
)
333 if (strcmp (p
, "-version") == 0)
336 /* We return 0 so that the caller can process this. */
340 #define CLARG "-fcompile-resource="
341 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
343 resource_name
= p
+ sizeof (CLARG
) - 1;
347 #define CLARG "-fassume-compiled="
348 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
350 add_assume_compiled (p
+ sizeof (CLARG
) - 1, 0);
354 #define CLARG "-fno-assume-compiled="
355 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
357 add_assume_compiled (p
+ sizeof (CLARG
) - 1, 1);
361 #define CLARG "-fassume-compiled"
362 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
364 add_assume_compiled ("", 0);
368 #define CLARG "-fno-assume-compiled"
369 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
371 add_assume_compiled ("", 1);
375 #define CLARG "-fCLASSPATH="
376 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
378 jcf_path_classpath_arg (p
+ sizeof (CLARG
) - 1);
382 #define CLARG "-fclasspath="
383 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
385 jcf_path_classpath_arg (p
+ sizeof (CLARG
) - 1);
389 #define CLARG "-fbootclasspath="
390 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
392 jcf_path_bootclasspath_arg (p
+ sizeof (CLARG
) - 1);
396 #define CLARG "-fextdirs="
397 if (strncmp (p
, CLARG
, sizeof (CLARG
) - 1) == 0)
399 jcf_path_extdirs_arg (p
+ sizeof (CLARG
) - 1);
403 else if (strncmp (p
, "-I", 2) == 0)
405 jcf_path_include_arg (p
+ 2);
409 #define ARG "-foutput-class-dir="
410 if (strncmp (p
, ARG
, sizeof (ARG
) - 1) == 0)
412 jcf_write_base_directory
= p
+ sizeof (ARG
) - 1;
416 #define ARG "-fencoding="
417 if (strncmp (p
, ARG
, sizeof (ARG
) - 1) == 0)
419 current_encoding
= p
+ sizeof (ARG
) - 1;
423 #define ARG "-finline-functions"
424 if (strncmp (p
, ARG
, sizeof (ARG
) - 1) == 0)
426 flag_inline_functions
= 1;
427 flag_really_inline
= 1;
432 if (p
[0] == '-' && p
[1] == 'f')
434 /* Some kind of -f option.
435 P's value is the option sans `-f'.
436 Search for it in the table of options. */
438 if (process_option_with_no (p
, lang_f_options
,
439 ARRAY_SIZE (lang_f_options
)))
441 return dump_switch_p (p
);
444 if (strcmp (p
, "-Wall") == 0)
448 flag_extraneous_semicolon
= 1;
449 /* When -Wall given, enable -Wunused. We do this because the C
450 compiler does it, and people expect it. */
455 if (p
[0] == '-' && p
[1] == 'W')
457 /* Skip `-W' and see if we accept the option or its `no-' form. */
459 return process_option_with_no (p
, lang_W_options
,
460 ARRAY_SIZE (lang_W_options
));
463 if (strcmp (p
, "-MD") == 0)
465 jcf_dependency_init (1);
466 dependency_tracking
|= DEPEND_SET_FILE
| DEPEND_ENABLE
;
469 else if (strcmp (p
, "-MMD") == 0)
471 jcf_dependency_init (0);
472 dependency_tracking
|= DEPEND_SET_FILE
| DEPEND_ENABLE
;
475 else if (strcmp (p
, "-M") == 0)
477 jcf_dependency_init (1);
478 dependency_tracking
|= DEPEND_ENABLE
;
481 else if (strcmp (p
, "-MM") == 0)
483 jcf_dependency_init (0);
484 dependency_tracking
|= DEPEND_ENABLE
;
487 else if (strcmp (p
, "-MP") == 0)
489 jcf_dependency_print_dummies ();
492 else if (strcmp (p
, "-MT") == 0)
494 jcf_dependency_set_target (argv
[1]);
495 dependency_tracking
|= DEPEND_TARGET_SET
;
498 else if (strcmp (p
, "-MF") == 0)
500 jcf_dependency_set_dep_file (argv
[1]);
501 dependency_tracking
|= DEPEND_FILE_ALREADY_SET
;
508 /* Global open file. */
515 extern int flag_minimal_debug
;
516 flag_minimal_debug
= 0;
519 if (flag_inline_functions
)
520 flag_inline_trees
= 1;
522 /* Force minimum function alignment if g++ uses the least significant
523 bit of function pointers to store the virtual bit. This is required
524 to keep vtables compatible. */
525 if (TARGET_PTRMEMFUNC_VBIT_LOCATION
== ptrmemfunc_vbit_in_pfn
526 && force_align_functions_log
< 1)
527 force_align_functions_log
= 1;
530 jcf_path_seal (version_flag
);
532 java_init_decl_processing ();
534 using_eh_for_cleanups ();
542 jcf_dependency_write ();
545 /* Buffer used by lang_printable_name. */
546 static char *decl_buf
= NULL
;
548 /* Allocated size of decl_buf. */
549 static int decl_buflen
= 0;
551 /* Length of used part of decl_buf; position for next character. */
552 static int decl_bufpos
= 0;
554 /* Append the string STR to decl_buf.
555 It length is given by LEN; -1 means the string is nul-terminated. */
558 put_decl_string (const char *str
, int len
)
562 if (decl_bufpos
+ len
>= decl_buflen
)
564 if (decl_buf
== NULL
)
566 decl_buflen
= len
+ 100;
567 decl_buf
= xmalloc (decl_buflen
);
572 decl_buf
= xrealloc (decl_buf
, decl_buflen
);
575 strcpy (decl_buf
+ decl_bufpos
, str
);
579 /* Append to decl_buf a printable name for NODE. */
582 put_decl_node (tree node
)
585 if (TREE_CODE (node
) == POINTER_TYPE
)
587 node
= TREE_TYPE (node
);
590 if (TREE_CODE_CLASS (TREE_CODE (node
)) == 'd'
591 && DECL_NAME (node
) != NULL_TREE
)
593 if (TREE_CODE (node
) == FUNCTION_DECL
)
595 /* We want to print the type the DECL belongs to. We don't do
596 that when we handle constructors. */
597 if (! DECL_CONSTRUCTOR_P (node
)
598 && ! DECL_ARTIFICIAL (node
) && DECL_CONTEXT (node
))
600 put_decl_node (TYPE_NAME (DECL_CONTEXT (node
)));
601 put_decl_string (".", 1);
603 if (! DECL_CONSTRUCTOR_P (node
))
604 put_decl_node (DECL_NAME (node
));
605 if (TREE_TYPE (node
) != NULL_TREE
)
608 tree args
= TYPE_ARG_TYPES (TREE_TYPE (node
));
609 if (TREE_CODE (TREE_TYPE (node
)) == METHOD_TYPE
)
610 args
= TREE_CHAIN (args
);
611 put_decl_string ("(", 1);
612 for ( ; args
!= end_params_node
; args
= TREE_CHAIN (args
), i
++)
615 put_decl_string (",", 1);
616 put_decl_node (TREE_VALUE (args
));
618 put_decl_string (")", 1);
622 put_decl_node (DECL_NAME (node
));
624 else if (TREE_CODE_CLASS (TREE_CODE (node
)) == 't'
625 && TYPE_NAME (node
) != NULL_TREE
)
627 if (TREE_CODE (node
) == RECORD_TYPE
&& TYPE_ARRAY_P (node
))
629 put_decl_node (TYPE_ARRAY_ELEMENT (node
));
630 put_decl_string("[]", 2);
632 else if (node
== promoted_byte_type_node
)
633 put_decl_string ("byte", 4);
634 else if (node
== promoted_short_type_node
)
635 put_decl_string ("short", 5);
636 else if (node
== promoted_char_type_node
)
637 put_decl_string ("char", 4);
638 else if (node
== promoted_boolean_type_node
)
639 put_decl_string ("boolean", 7);
640 else if (node
== void_type_node
&& was_pointer
)
641 put_decl_string ("null", 4);
643 put_decl_node (TYPE_NAME (node
));
645 else if (TREE_CODE (node
) == IDENTIFIER_NODE
)
646 put_decl_string (IDENTIFIER_POINTER (node
), IDENTIFIER_LENGTH (node
));
648 put_decl_string ("<unknown>", -1);
651 /* Return a user-friendly name for DECL.
652 The resulting string is only valid until the next call.
653 The value of the hook decl_printable_name is this function,
654 which is also called directly by java_print_error_function. */
657 lang_printable_name (tree decl
, int v
__attribute__ ((__unused__
)))
660 put_decl_node (decl
);
661 put_decl_string ("", 1);
665 /* Does the same thing that lang_printable_name, but add a leading
666 space to the DECL name string -- With Leading Space. */
669 lang_printable_name_wls (tree decl
, int v
__attribute__ ((__unused__
)))
672 put_decl_node (decl
);
673 put_decl_string ("", 1);
678 /* Print on stderr the current class and method context. This function
679 is the value of the hook print_error_function. */
681 static GTY(()) tree last_error_function_context
;
682 static GTY(()) tree last_error_function
;
684 java_print_error_function (diagnostic_context
*context ATTRIBUTE_UNUSED
,
687 /* Don't print error messages with bogus function prototypes. */
688 if (inhibit_error_function_printing
)
691 if (current_function_decl
!= NULL
692 && DECL_CONTEXT (current_function_decl
) != last_error_function_context
)
695 fprintf (stderr
, "%s: ", file
);
697 last_error_function_context
= DECL_CONTEXT (current_function_decl
);
698 fprintf (stderr
, "In class `%s':\n",
699 lang_printable_name (last_error_function_context
, 0));
701 if (last_error_function
!= current_function_decl
)
704 fprintf (stderr
, "%s: ", file
);
706 if (current_function_decl
== NULL
)
707 fprintf (stderr
, "At top level:\n");
710 const char *name
= lang_printable_name (current_function_decl
, 2);
711 fprintf (stderr
, "In %s `%s':\n",
712 (DECL_CONSTRUCTOR_P (current_function_decl
) ? "constructor"
717 last_error_function
= current_function_decl
;
722 /* Called to install the PRINT_ERROR_FUNCTION hook differently
723 according to LEVEL. LEVEL is 1 during early parsing, when function
724 prototypes aren't fully resolved. java_print_error_function is set
725 so it doesn't print incomplete function prototypes. When LEVEL is
726 2, function prototypes are fully resolved and can be printed when
729 void lang_init_source (int level
)
731 inhibit_error_function_printing
= (level
== 1);
735 java_init_options (void)
737 flag_bounds_check
= 1;
739 flag_non_call_exceptions
= 1;
741 /* In Java floating point operations never trap. */
742 flag_trapping_math
= 0;
744 /* In Java arithmetic overflow always wraps around. */
749 java_can_use_bit_fields_p (void)
751 /* The bit-field optimizations cause problems when generating class
753 return flag_emit_class_files
? false : true;
756 /* Post-switch processing. */
758 java_post_options (const char **pfilename
)
760 const char *filename
= *pfilename
;
762 /* Use tree inlining if possible. Function instrumentation is only
763 done in the RTL level, so we disable tree inlining. */
764 if (! flag_instrument_function_entry_exit
)
768 if (flag_inline_functions
)
770 flag_inline_trees
= 2;
771 flag_inline_functions
= 0;
775 /* Open input file. */
777 if (filename
== 0 || !strcmp (filename
, "-"))
782 if (dependency_tracking
)
783 error ("can't do dependency tracking with input from stdin");
787 if (dependency_tracking
)
791 /* If the target is set and the output filename is set, then
792 there's no processing to do here. Otherwise we must
793 compute one or the other. */
794 if (! ((dependency_tracking
& DEPEND_TARGET_SET
)
795 && (dependency_tracking
& DEPEND_FILE_ALREADY_SET
)))
797 dot
= strrchr (filename
, '.');
799 error ("couldn't determine target name for dependency tracking");
802 char *buf
= xmalloc (dot
- filename
+
803 3 + sizeof (TARGET_OBJECT_SUFFIX
));
804 strncpy (buf
, filename
, dot
- filename
);
806 /* If emitting class files, we might have multiple
807 targets. The class generation code takes care of
808 registering them. Otherwise we compute the
810 if ((dependency_tracking
& DEPEND_TARGET_SET
))
812 else if (flag_emit_class_files
)
813 jcf_dependency_set_target (NULL
);
816 strcpy (buf
+ (dot
- filename
), TARGET_OBJECT_SUFFIX
);
817 jcf_dependency_set_target (buf
);
820 if ((dependency_tracking
& DEPEND_FILE_ALREADY_SET
))
822 else if ((dependency_tracking
& DEPEND_SET_FILE
))
824 strcpy (buf
+ (dot
- filename
), ".d");
825 jcf_dependency_set_dep_file (buf
);
828 jcf_dependency_set_dep_file ("-");
836 /* Initialize the compiler back end. */
840 /* Return either DECL or its known constant value (if it has one). */
843 decl_constant_value (tree decl
)
845 if (/* Don't change a variable array bound or initial value to a constant
846 in a place where a variable is invalid. */
847 current_function_decl
!= 0
848 && ! TREE_THIS_VOLATILE (decl
)
849 && TREE_READONLY (decl
)
850 && DECL_INITIAL (decl
) != 0
851 && TREE_CODE (DECL_INITIAL (decl
)) != ERROR_MARK
852 /* This is invalid if initial value is not constant.
853 If it has either a function call, a memory reference,
854 or a variable, then re-evaluating it could give different results. */
855 && TREE_CONSTANT (DECL_INITIAL (decl
))
856 /* Check for cases where this is sub-optimal, even though valid. */
857 && TREE_CODE (DECL_INITIAL (decl
)) != CONSTRUCTOR
)
858 return DECL_INITIAL (decl
);
862 /* Walk the language specific tree nodes during inlining. */
865 java_tree_inlining_walk_subtrees (tree
*tp ATTRIBUTE_UNUSED
,
866 int *subtrees ATTRIBUTE_UNUSED
,
867 walk_tree_fn func ATTRIBUTE_UNUSED
,
868 void *data ATTRIBUTE_UNUSED
,
869 void *htab ATTRIBUTE_UNUSED
)
874 #define WALK_SUBTREE(NODE) \
877 result = walk_tree (&(NODE), func, data, htab); \
887 code
= TREE_CODE (t
);
891 if (BLOCK_EXPR_BODY (t
))
893 tree
*prev
= &BLOCK_EXPR_BODY (*tp
);
896 WALK_SUBTREE (*prev
);
897 prev
= &TREE_CHAIN (*prev
);
908 /* Called from unsafe_for_reeval. */
910 java_unsafe_for_reeval (tree t
)
912 switch (TREE_CODE (t
))
915 /* Our expander tries to expand the variables twice. Boom. */
916 if (BLOCK_EXPR_DECLS (t
) != NULL
)
918 return unsafe_for_reeval (BLOCK_EXPR_BODY (t
));
927 /* Every call to a static constructor has an associated boolean
928 variable which is in the outermost scope of the calling method.
929 This variable is used to avoid multiple calls to the static
930 constructor for each class.
932 It looks something like this:
936 boolean dummy = OtherClass.is_initialized;
941 OtherClass.initialize();
943 ... use OtherClass.data ...
946 Each of these boolean variables has an entry in the
947 DECL_FUNCTION_INIT_TEST_TABLE of a method. When inlining a method
948 we must merge the DECL_FUNCTION_INIT_TEST_TABLE from the function
949 being inlined and create the boolean variables in the outermost
950 scope of the method being inlined into. */
952 /* Create a mapping from a boolean variable in a method being inlined
953 to one in the scope of the method being inlined into. */
956 merge_init_test_initialization (void **entry
, void *x
)
958 struct treetreehash_entry
*ite
= (struct treetreehash_entry
*) *entry
;
959 splay_tree decl_map
= (splay_tree
)x
;
961 tree
*init_test_decl
;
963 /* See if we have remapped this declaration. If we haven't there's
964 a bug in the inliner. */
965 n
= splay_tree_lookup (decl_map
, (splay_tree_key
) ite
->value
);
969 /* Create a new entry for the class and its remapped boolean
970 variable. If we already have a mapping for this class we've
971 already initialized it, so don't overwrite the value. */
972 init_test_decl
= java_treetreehash_new
973 (DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl
), ite
->key
);
974 if (!*init_test_decl
)
975 *init_test_decl
= (tree
)n
->value
;
980 /* Merge the DECL_FUNCTION_INIT_TEST_TABLE from the function we're
984 java_inlining_merge_static_initializers (tree fn
, void *decl_map
)
987 (DECL_FUNCTION_INIT_TEST_TABLE (fn
),
988 merge_init_test_initialization
, decl_map
);
991 /* Lookup a DECL_FUNCTION_INIT_TEST_TABLE entry in the method we're
992 inlining into. If we already have a corresponding entry in that
993 class we don't need to create another one, so we create a mapping
994 from the variable in the inlined class to the corresponding
998 inline_init_test_initialization (void **entry
, void *x
)
1000 struct treetreehash_entry
*ite
= (struct treetreehash_entry
*) *entry
;
1001 splay_tree decl_map
= (splay_tree
)x
;
1003 tree h
= java_treetreehash_find
1004 (DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl
), ite
->key
);
1008 splay_tree_insert (decl_map
,
1009 (splay_tree_key
) ite
->value
,
1010 (splay_tree_value
) h
);
1015 /* Look up the boolean variables in the DECL_FUNCTION_INIT_TEST_TABLE
1016 of a method being inlined. For each hone, if we already have a
1017 variable associated with the same class in the method being inlined
1018 into, create a new mapping for it. */
1021 java_inlining_map_static_initializers (tree fn
, void *decl_map
)
1024 (DECL_FUNCTION_INIT_TEST_TABLE (fn
),
1025 inline_init_test_initialization
, decl_map
);
1028 /* Avoid voluminous output for deep recursion of compound exprs. */
1031 dump_compound_expr (dump_info_p di
, tree t
)
1037 switch (TREE_CODE (TREE_OPERAND (t
, i
)))
1040 dump_compound_expr (di
, TREE_OPERAND (t
, i
));
1043 case EXPR_WITH_FILE_LOCATION
:
1045 tree wfl_node
= EXPR_WFL_NODE (TREE_OPERAND (t
, i
));
1046 dump_child ("expr", wfl_node
);
1051 dump_child ("expr", TREE_OPERAND (t
, i
));
1057 java_dump_tree (void *dump_info
, tree t
)
1059 enum tree_code code
;
1060 dump_info_p di
= (dump_info_p
) dump_info
;
1062 /* Figure out what kind of node this is. */
1063 code
= TREE_CODE (t
);
1068 dump_child ("args", DECL_ARGUMENTS (t
));
1069 if (DECL_EXTERNAL (t
))
1070 dump_string (di
, "undefined");
1071 if (TREE_PUBLIC (t
))
1072 dump_string (di
, "extern");
1074 dump_string (di
, "static");
1075 if (DECL_LANG_SPECIFIC (t
))
1076 dump_child ("body", DECL_FUNCTION_BODY (t
));
1077 if (DECL_LANG_SPECIFIC (t
) && !dump_flag (di
, TDF_SLIM
, t
))
1078 dump_child ("inline body", DECL_SAVED_TREE (t
));
1082 dump_child ("expr", TREE_OPERAND (t
, 0));
1086 dump_child ("goto", TREE_OPERAND (t
, 0));
1090 dump_child ("label", TREE_OPERAND (t
, 0));
1093 case LABELED_BLOCK_EXPR
:
1094 dump_child ("label", TREE_OPERAND (t
, 0));
1095 dump_child ("block", TREE_OPERAND (t
, 1));
1098 case EXIT_BLOCK_EXPR
:
1099 dump_child ("block", TREE_OPERAND (t
, 0));
1100 dump_child ("val", TREE_OPERAND (t
, 1));
1104 if (BLOCK_EXPR_BODY (t
))
1106 tree local
= BLOCK_VARS (t
);
1109 tree next
= TREE_CHAIN (local
);
1110 dump_child ("var", local
);
1115 tree block
= BLOCK_EXPR_BODY (t
);
1116 dump_child ("body", block
);
1117 block
= TREE_CHAIN (block
);
1123 if (!dump_flag (di
, TDF_SLIM
, t
))
1125 dump_compound_expr (di
, t
);
1133 #include "gt-java-lang.h"