OSDN Git Service

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