OSDN Git Service

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