OSDN Git Service

Warning fixes:
[pf3gnuchains/gcc-fork.git] / gcc / java / decl.c
1 /* Process declarations and variables for the GNU compiler for the
2    Java(TM) language.
3    Copyright (C) 1996, 1997, 1998, 1999, 2000 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 "toplev.h"
32 #include "flags.h"
33 #include "java-tree.h"
34 #include "jcf.h"
35 #include "toplev.h"
36 #include "function.h"
37 #include "except.h"
38 #include "defaults.h"
39 #include "java-except.h"
40
41 #if defined (DEBUG_JAVA_BINDING_LEVELS)
42 extern void indent PROTO((void));
43 #endif
44
45 static tree push_jvm_slot PARAMS ((int, tree));
46 static tree lookup_name_current_level PARAMS ((tree));
47 static tree push_promoted_type PARAMS ((const char *, tree));
48 static struct binding_level *make_binding_level PARAMS ((void));
49 static boolean emit_init_test_initialization PARAMS ((struct hash_entry *,
50                                                       hash_table_key));
51 static tree create_primitive_vtable PARAMS ((const char *));
52
53 /* Set to non-zero value in order to emit class initilization code
54    before static field references.  */
55 extern int always_initialize_class_p;
56
57 #ifndef INT_TYPE_SIZE
58 #define INT_TYPE_SIZE BITS_PER_WORD
59 #endif
60
61 /* The DECL_MAP is a mapping from (index, type) to a decl node.
62    If index < max_locals, it is the index of a local variable.
63    if index >= max_locals, then index-max_locals is a stack slot.
64    The DECL_MAP mapping is represented as a TREE_VEC whose elements
65    are a list of decls (VAR_DECL or PARM_DECL) chained by
66    DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
67    we search the chain for a decl with a matching TREE_TYPE. */
68
69 tree decl_map;
70
71 /* A list of local variables VAR_DECLs for this method that we have seen
72    debug information, but we have not reached their starting (byte) PC yet. */
73
74 tree pending_local_decls = NULL_TREE;
75
76 /* Push a local variable or stack slot into the decl_map,
77    and assign it an rtl. */
78
79 #if defined(DEBUG_JAVA_BINDING_LEVELS)
80 int binding_depth = 0;
81 int is_class_level = 0;
82 int current_pc;
83
84 void
85 indent ()
86 {
87   register unsigned i;
88
89   for (i = 0; i < binding_depth*2; i++)
90     putc (' ', stderr);
91 }
92 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
93
94 static tree
95 push_jvm_slot (index, decl)
96      int index;
97      tree decl;
98 {
99   struct rtx_def *rtl = NULL;
100   tree type = TREE_TYPE (decl);
101   tree tmp;
102
103   DECL_CONTEXT (decl) = current_function_decl;
104   layout_decl (decl, 0);
105
106   /* See if we have an appropriate rtl (i.e. same mode) at this index.
107      If so, we must use it. */ 
108   tmp = TREE_VEC_ELT (decl_map, index);
109   while (tmp != NULL_TREE)
110     {
111       if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (tmp)))
112         rtl = DECL_RTL (tmp);
113       if (rtl != NULL)
114         break;
115      tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
116     }
117   if (rtl != NULL)
118     DECL_RTL (decl) = rtl;
119   else
120     {
121       if (index >= DECL_MAX_LOCALS (current_function_decl))
122         DECL_REGISTER (decl) = 1;
123       expand_decl (decl);
124     }
125
126   /* Now link the decl into the decl_map. */
127   if (DECL_LANG_SPECIFIC (decl) == NULL)
128     {
129       DECL_LANG_SPECIFIC (decl)
130         = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
131       DECL_LOCAL_START_PC (decl) = 0;
132       DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
133       DECL_LOCAL_SLOT_NUMBER (decl) = index;
134     }
135   DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
136   TREE_VEC_ELT (decl_map, index) = decl;
137   return decl;
138 }
139
140 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
141    that is valid at PC (or -1 if any pc).
142    If there is no existing matching decl, allocate one.  */
143
144 tree
145 find_local_variable (index, type, pc)
146      int index;
147      tree type;
148      int pc;
149 {
150   tree decl = TREE_VEC_ELT (decl_map, index);
151   tree best = NULL_TREE;
152
153   while (decl != NULL_TREE)
154     {
155       int in_range;
156       in_range = pc < 0
157         || (pc >= DECL_LOCAL_START_PC (decl)
158             && pc < DECL_LOCAL_END_PC (decl));
159
160       if ((TREE_TYPE (decl) == type
161            || (TREE_CODE (TREE_TYPE (decl)) == TREE_CODE (type)
162                && TYPE_PRECISION (TREE_TYPE (decl)) <= 32
163                && TYPE_PRECISION (type) <= 32
164                && TREE_CODE (type) != POINTER_TYPE)
165            || (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
166                && type == ptr_type_node))
167            && in_range)
168         {
169           if (best == NULL_TREE
170               || (TREE_TYPE (decl) == type && TREE_TYPE (best) != type)
171               || DECL_LOCAL_START_PC (decl) > DECL_LOCAL_START_PC (best)
172               || DECL_LOCAL_END_PC (decl) < DECL_LOCAL_START_PC (decl))
173             best = decl;
174         }
175       decl = DECL_LOCAL_SLOT_CHAIN (decl);
176     }
177   if (best != NULL_TREE)
178     return best;
179   return push_jvm_slot (index, build_decl (VAR_DECL, NULL_TREE, type));
180 }
181
182
183 /* Same as find_local_index, except that INDEX is a stack index. */
184
185 tree
186 find_stack_slot (index, type)
187      int index;
188      tree type;
189 {
190   return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
191                               type, -1);
192 }
193
194 struct binding_level
195   {
196     /* A chain of _DECL nodes for all variables, constants, functions,
197      * and typedef types.  These are in the reverse of the order supplied.
198      */
199     tree names;
200
201     /* For each level, a list of shadowed outer-level local definitions
202        to be restored when this level is popped.
203        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
204        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
205     tree shadowed;
206
207     /* For each level (except not the global one),
208        a chain of BLOCK nodes for all the levels
209        that were entered and exited one level down.  */
210     tree blocks;
211
212     /* The BLOCK node for this level, if one has been preallocated.
213        If 0, the BLOCK is allocated (if needed) when the level is popped.  */
214     tree this_block;
215
216     /* The binding level which this one is contained in (inherits from).  */
217     struct binding_level *level_chain;
218
219     /* 1 means make a BLOCK for this level regardless of all else.
220        2 for temporary binding contours created by the compiler.  */
221     char keep;
222
223     /* Nonzero means make a BLOCK if this level has any subblocks.  */
224     char keep_if_subblocks;
225
226     /* Nonzero if this level can safely have additional
227        cleanup-needing variables added to it.  */
228     char more_cleanups_ok;
229     char have_cleanups;
230
231     /* The bytecode PC that marks the end of this level. */
232     int end_pc;
233     /* The bytecode PC that marks the start of this level. */
234     int start_pc;
235
236 #if defined(DEBUG_JAVA_BINDING_LEVELS)
237     /* Binding depth at which this level began.  */
238     unsigned binding_depth;
239 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
240   };
241
242 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
243
244 /* The binding level currently in effect.  */
245
246 static struct binding_level *current_binding_level;
247
248 /* A chain of binding_level structures awaiting reuse.  */
249
250 static struct binding_level *free_binding_level;
251
252 /* The outermost binding level, for names of file scope.
253    This is created when the compiler is started and exists
254    through the entire run.  */
255
256 static struct binding_level *global_binding_level;
257
258 /* A PC value bigger than any PC value we may ever may encounter. */
259
260 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
261
262 /* Binding level structures are initialized by copying this one.  */
263
264 static struct binding_level clear_binding_level
265   = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
266        NULL_BINDING_LEVEL, 0, 0, 0, 0, LARGEST_PC, 0};
267
268 #if 0
269 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
270    that have names.  Here so we can clear out their names' definitions
271    at the end of the function.  */
272
273 static tree named_labels;
274
275 /* A list of LABEL_DECLs from outer contexts that are currently shadowed.  */
276
277 static tree shadowed_labels;
278 #endif
279
280 int flag_traditional;
281
282 /* Nonzero means unconditionally make a BLOCK for the next level pushed.  */
283
284 static int keep_next_level_flag;
285
286 /* Nonzero means make a BLOCK for the next level pushed
287    if it has subblocks.  */
288
289 static int keep_next_if_subblocks;
290   
291 tree object_type_node;
292 tree unqualified_object_id_node;
293 tree object_ptr_type_node;
294 tree string_type_node;
295 tree string_ptr_type_node;
296 tree throwable_type_node;
297 tree runtime_exception_type_node;
298 tree error_exception_type_node;
299 tree rawdata_ptr_type_node;
300 tree *predef_filenames;
301 int  predef_filenames_size;
302
303 tree boolean_type_node;
304
305 tree return_address_type_node;
306
307 tree byte_type_node;
308 tree short_type_node;
309 tree int_type_node;
310 tree long_type_node;
311
312 tree promoted_byte_type_node;
313 tree promoted_short_type_node;
314 tree promoted_char_type_node;
315 tree promoted_boolean_type_node;
316
317 tree unsigned_byte_type_node;
318 tree unsigned_short_type_node;
319 tree unsigned_int_type_node;
320 tree unsigned_long_type_node;
321
322 /* The type for struct methodtable. */
323 tree methodtable_type;
324 tree methodtable_ptr_type;
325
326 tree utf8const_type;
327 tree utf8const_ptr_type;
328 tree class_type_node;
329 tree class_ptr_type;
330 tree field_type_node;
331 tree field_ptr_type_node;
332 tree field_info_union_node;
333 tree jexception_type;
334 tree jexception_ptr_type;
335 tree lineNumberEntry_type;
336 tree lineNumbers_type;
337 tree constants_type_node;
338 tree dtable_type;
339 tree dtable_ptr_type;
340 tree method_type_node;
341 tree method_ptr_type_node;
342 tree nativecode_ptr_array_type_node;
343 tree one_elt_array_domain_type;
344 tree access_flags_type_node;
345 tree class_dtable_decl;
346
347 /* Expressions that are constants with value zero, of types
348    `long', `float' and `double'.  */
349 tree long_zero_node;
350 tree float_zero_node;
351 tree double_zero_node;
352
353 tree empty_stmt_node;
354
355 /* Nodes for boolean constants TRUE and FALSE. */
356 tree boolean_true_node;
357 tree boolean_false_node;
358
359 tree TYPE_identifier_node;
360 tree init_identifier_node;
361 tree clinit_identifier_node;
362 tree finit_identifier_node;
363 tree void_signature_node;
364 tree length_identifier_node;
365 tree this_identifier_node;
366 tree super_identifier_node;
367 tree continue_identifier_node;
368 tree access0_identifier_node;   /* 1.1 */
369 tree end_params_node;
370
371 /* References to internal libjava functions we use. */
372 tree alloc_object_node;
373 tree soft_instanceof_node;
374 tree soft_checkcast_node;
375 tree soft_initclass_node;
376 tree soft_newarray_node;
377 tree soft_anewarray_node;
378 tree soft_multianewarray_node;
379 tree soft_badarrayindex_node;
380 tree soft_nullpointer_node;
381 tree throw_node [2];
382 tree soft_checkarraystore_node;
383 tree soft_monitorenter_node;
384 tree soft_monitorexit_node;
385 tree soft_lookupinterfacemethod_node;
386 tree soft_lookupjnimethod_node;
387 tree soft_getjnienvnewframe_node;
388 tree soft_jnipopsystemframe_node;
389 tree soft_fmod_node;
390 tree soft_exceptioninfo_call_node;
391 tree soft_idiv_node;
392 tree soft_irem_node;
393 tree soft_ldiv_node;
394 tree soft_lrem_node;
395
396 /* Declarations for vtables for primitive arrays.  */
397 tree boolean_array_vtable;
398 tree byte_array_vtable;
399 tree char_array_vtable;
400 tree short_array_vtable;
401 tree int_array_vtable;
402 tree long_array_vtable;
403 tree float_array_vtable;
404 tree double_array_vtable;
405
406 /* Build (and pushdecl) a "promoted type" for all standard
407    types shorter than int.  */
408
409 static tree
410 push_promoted_type (name, actual_type)
411      const char *name;
412      tree actual_type;
413 {
414   tree type = make_node (TREE_CODE (actual_type));
415 #if 1
416   tree in_min = TYPE_MIN_VALUE (int_type_node);
417   tree in_max = TYPE_MAX_VALUE (int_type_node);
418 #else
419   tree in_min = TYPE_MIN_VALUE (actual_type);
420   tree in_max = TYPE_MAX_VALUE (actual_type);
421 #endif
422   TYPE_MIN_VALUE (type) = copy_node (in_min);
423   TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
424   TYPE_MAX_VALUE (type) = copy_node (in_max);
425   TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
426   TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
427   layout_type (type);
428   pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
429   return type;
430 }
431
432 /* Nodes for integer constants.  */
433 tree integer_two_node;
434 tree integer_four_node;
435 tree integer_negative_one_node;
436
437 /* Return a definition for a builtin function named NAME and whose data type
438    is TYPE.  TYPE should be a function type with argument types.
439    FUNCTION_CODE tells later passes how to compile calls to this function.
440    See tree.h for its possible values.
441
442    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
443    the name to be called if we can't opencode the function.  */
444
445 tree
446 builtin_function (name, type, function_code, class, library_name)
447      const char *name;
448      tree type;
449      int function_code;
450      enum built_in_class class;
451      const char *library_name;
452 {
453   tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
454   DECL_EXTERNAL (decl) = 1;
455   TREE_PUBLIC (decl) = 1;
456   if (library_name)
457     DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
458   make_decl_rtl (decl, NULL_PTR, 1);
459   pushdecl (decl);
460   DECL_BUILT_IN_CLASS (decl) = class;
461   DECL_FUNCTION_CODE (decl) = function_code;
462   return decl;
463 }
464
465 /* Return tree that represents a vtable for a primitive array.  */
466 static tree
467 create_primitive_vtable (name)
468      const char *name;
469 {
470   tree r;
471   char buf[50];
472
473   sprintf (buf, "_Jv_%sVTable", name);
474   r = build_decl (VAR_DECL, get_identifier (buf), ptr_type_node);
475   DECL_EXTERNAL (r) = 1;
476   make_decl_rtl (r, buf, 1);
477   return r;
478 }
479
480 void
481 init_decl_processing ()
482 {
483   register tree endlink;
484   tree field = NULL_TREE;
485   tree t;
486
487   current_function_decl = NULL;
488   current_binding_level = NULL_BINDING_LEVEL;
489   free_binding_level = NULL_BINDING_LEVEL;
490   pushlevel (0);        /* make the binding_level structure for global names */
491   global_binding_level = current_binding_level;
492
493   /* The code here must be similar to build_common_tree_nodes{,_2} in
494      tree.c, especially as to the order of initializing common nodes.  */
495   error_mark_node = make_node (ERROR_MARK);
496   TREE_TYPE (error_mark_node) = error_mark_node;
497
498   /* Create sizetype first - needed for other types. */
499   initialize_sizetypes ();
500
501   byte_type_node = make_signed_type (8);
502   pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
503   short_type_node = make_signed_type (16);
504   pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
505   int_type_node = make_signed_type (32);
506   pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
507   long_type_node = make_signed_type (64);
508   pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
509
510   unsigned_byte_type_node = make_unsigned_type (8);
511   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
512                         unsigned_byte_type_node));
513   unsigned_short_type_node = make_unsigned_type (16);
514   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
515                         unsigned_short_type_node));
516   unsigned_int_type_node = make_unsigned_type (32);
517   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
518                         unsigned_int_type_node));
519   unsigned_long_type_node = make_unsigned_type (64);
520   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
521                         unsigned_long_type_node));
522
523   set_sizetype (make_unsigned_type (POINTER_SIZE));
524
525   /* Define these next since types below may used them.  */
526   integer_type_node = type_for_size (INT_TYPE_SIZE, 0);
527   integer_zero_node = build_int_2 (0, 0);
528   integer_one_node = build_int_2 (1, 0);
529   integer_two_node = build_int_2 (2, 0);
530   integer_four_node = build_int_2 (4, 0);
531   integer_negative_one_node = build_int_2 (-1, 0);
532
533   size_zero_node = size_int (0);
534   size_one_node = size_int (1);
535   bitsize_zero_node = bitsize_int (0);
536   bitsize_one_node = bitsize_int (1);
537   bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
538
539   long_zero_node = build_int_2 (0, 0);
540   TREE_TYPE (long_zero_node) = long_type_node;
541
542   void_type_node = make_node (VOID_TYPE);
543   pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
544   layout_type (void_type_node); /* Uses size_zero_node */
545   ptr_type_node = build_pointer_type (void_type_node);
546   t = make_node (VOID_TYPE);
547   layout_type (t); /* Uses size_zero_node */
548   return_address_type_node = build_pointer_type (t);
549
550   null_pointer_node = build_int_2 (0, 0);
551   TREE_TYPE (null_pointer_node) = ptr_type_node;
552
553   /* Used by the parser to represent empty statements and blocks. */
554   empty_stmt_node = build1 (NOP_EXPR, void_type_node, size_zero_node);
555   CAN_COMPLETE_NORMALLY (empty_stmt_node) = 1;
556
557 #if 0
558   /* Make a type to be the domain of a few array types
559      whose domains don't really matter.
560      200 is small enough that it always fits in size_t
561      and large enough that it can hold most function names for the
562      initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
563   short_array_type_node = build_prim_array_type (short_type_node, 200);
564 #endif
565   char_type_node = make_node (CHAR_TYPE);
566   TYPE_PRECISION (char_type_node) = 16;
567   fixup_unsigned_type (char_type_node);
568   pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
569
570   boolean_type_node = make_node (BOOLEAN_TYPE);
571   TYPE_PRECISION (boolean_type_node) = 1;
572   fixup_unsigned_type (boolean_type_node);
573   pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
574                         boolean_type_node));
575   boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
576   boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
577
578   promoted_byte_type_node
579     = push_promoted_type ("promoted_byte", byte_type_node);
580   promoted_short_type_node
581     = push_promoted_type ("promoted_short", short_type_node);
582   promoted_char_type_node
583     = push_promoted_type ("promoted_char", char_type_node);
584   promoted_boolean_type_node
585     = push_promoted_type ("promoted_boolean", boolean_type_node);
586
587   float_type_node = make_node (REAL_TYPE);
588   TYPE_PRECISION (float_type_node) = 32;
589   pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
590                         float_type_node));
591   layout_type (float_type_node);
592
593   double_type_node = make_node (REAL_TYPE);
594   TYPE_PRECISION (double_type_node) = 64;
595   pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
596                         double_type_node));
597   layout_type (double_type_node);
598
599   float_zero_node = build_real (float_type_node, dconst0);
600   double_zero_node = build_real (double_type_node, dconst0);
601
602   /* These are the vtables for arrays of primitives.  */
603   boolean_array_vtable = create_primitive_vtable ("boolean");
604   byte_array_vtable = create_primitive_vtable ("byte");
605   char_array_vtable = create_primitive_vtable ("char");
606   short_array_vtable = create_primitive_vtable ("short");
607   int_array_vtable = create_primitive_vtable ("int");
608   long_array_vtable = create_primitive_vtable ("long");
609   float_array_vtable = create_primitive_vtable ("float");
610   double_array_vtable = create_primitive_vtable ("double");
611
612   /* As you're adding items here, please update the code right after
613      this section, so that the filename containing the source code of
614      the pre-defined class gets registered correctly. */
615   unqualified_object_id_node = get_identifier ("Object");
616   object_type_node = lookup_class (get_identifier ("java.lang.Object"));
617   object_ptr_type_node = promote_type (object_type_node);
618   string_type_node = lookup_class (get_identifier ("java.lang.String"));
619   string_ptr_type_node = promote_type (string_type_node);
620   class_type_node = lookup_class (get_identifier ("java.lang.Class"));
621   throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
622   runtime_exception_type_node = 
623     lookup_class (get_identifier ("java.lang.RuntimeException"));
624   error_exception_type_node = 
625     lookup_class (get_identifier ("java.lang.Error"));
626   rawdata_ptr_type_node
627     = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
628
629   /* This section has to be updated as items are added to the previous
630      section. */
631   predef_filenames_size = 7;
632   predef_filenames = (tree *)xmalloc (predef_filenames_size * sizeof (tree));
633   predef_filenames [0] = get_identifier ("java/lang/Class.java");
634   predef_filenames [1] = get_identifier ("java/lang/Error.java");
635   predef_filenames [2] = get_identifier ("java/lang/Object.java");
636   predef_filenames [3] = get_identifier ("java/lang/RuntimeException.java");
637   predef_filenames [4] = get_identifier ("java/lang/String.java");
638   predef_filenames [5] = get_identifier ("java/lang/Throwable.java");
639   predef_filenames [6] = get_identifier ("gnu/gcj/RawData.java");
640
641   methodtable_type = make_node (RECORD_TYPE);
642   layout_type (methodtable_type);
643   build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
644   methodtable_ptr_type = build_pointer_type (methodtable_type);
645
646   TYPE_identifier_node = get_identifier ("TYPE");
647   init_identifier_node = get_identifier ("<init>");
648   clinit_identifier_node = get_identifier ("<clinit>");
649   finit_identifier_node = get_identifier ("$finit$");
650   void_signature_node = get_identifier ("()V");
651   length_identifier_node = get_identifier ("length");
652   this_identifier_node = get_identifier ("this");
653   super_identifier_node = get_identifier ("super");
654   continue_identifier_node = get_identifier ("continue");
655   access0_identifier_node = get_identifier ("access$0");
656
657   /* for lack of a better place to put this stub call */
658   init_expr_processing();
659
660   utf8const_type = make_node (RECORD_TYPE);
661   PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
662   PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
663   FINISH_RECORD (utf8const_type);
664   utf8const_ptr_type = build_pointer_type (utf8const_type);
665
666   constants_type_node = make_node (RECORD_TYPE);
667   PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
668   PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
669   PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
670   FINISH_RECORD (constants_type_node);
671   build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
672
673   access_flags_type_node = unsigned_short_type_node;
674
675   dtable_type = make_node (RECORD_TYPE);
676   dtable_ptr_type = build_pointer_type (dtable_type);
677
678   PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
679   /* This isn't exactly true, but it is what we have in the source.
680      There is an unresolved issue here, which is whether the vtable
681      should be marked by the GC.  */
682   if (! flag_hash_synchronization)
683     PUSH_FIELD (object_type_node, field, "sync_info",
684                 build_pointer_type (object_type_node));
685   for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
686     FIELD_PRIVATE (t) = 1;
687   FINISH_RECORD (object_type_node);
688
689   class_dtable_decl = build_dtable_decl (class_type_node);
690   TREE_STATIC (class_dtable_decl) = 1;
691   DECL_ARTIFICIAL (class_dtable_decl) = 1;
692   DECL_IGNORED_P (class_dtable_decl) = 1;
693   rest_of_decl_compilation (class_dtable_decl, (char*) 0, 1, 0);
694
695   field_type_node = make_node (RECORD_TYPE);
696   field_ptr_type_node = build_pointer_type (field_type_node);
697   method_type_node = make_node (RECORD_TYPE);
698   method_ptr_type_node = build_pointer_type (method_type_node);
699
700   set_super_info (0, class_type_node, object_type_node, 0);
701   set_super_info (0, string_type_node, object_type_node, 0);
702   class_ptr_type = build_pointer_type (class_type_node);
703
704   PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
705   PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
706   PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
707   PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
708   PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
709   PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
710   PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
711   PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
712   PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
713   PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
714   PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
715   PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
716   PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
717   PUSH_FIELD (class_type_node, field, "interfaces",
718               build_pointer_type (class_ptr_type));
719   PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
720   PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
721   PUSH_FIELD (class_type_node, field, "state", byte_type_node);
722   PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
723   PUSH_FIELD (class_type_node, field, "depth", short_type_node);
724   PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
725   PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);  
726   for (t = TYPE_FIELDS (class_type_node);  t != NULL_TREE;  t = TREE_CHAIN (t))
727     FIELD_PRIVATE (t) = 1;
728   push_super_field (class_type_node, object_type_node);
729   FINISH_RECORD (class_type_node);
730   build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
731
732   field_info_union_node = make_node (UNION_TYPE);
733   PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
734   PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
735 #if 0
736   PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
737 #endif
738   layout_type (field_info_union_node);
739
740   PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
741   PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
742   PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
743   PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
744   PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
745   FINISH_RECORD (field_type_node);
746   CLASS_LOADED_P (field_type_node) = 1;
747   build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
748
749   one_elt_array_domain_type = build_index_type (integer_one_node);
750   nativecode_ptr_array_type_node
751     = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
752
753   PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
754   PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
755   FINISH_RECORD (dtable_type);
756   build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
757
758 #define jint_type int_type_node
759 #define jint_ptr_type ptr_type_node
760
761   jexception_type = make_node (RECORD_TYPE);
762   PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
763   PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
764   PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
765   PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
766   FINISH_RECORD (jexception_type);
767   build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
768   jexception_ptr_type = build_pointer_type (jexception_type);
769
770   lineNumberEntry_type = make_node (RECORD_TYPE);
771   PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
772   PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
773   FINISH_RECORD (lineNumberEntry_type);
774
775   lineNumbers_type = make_node (RECORD_TYPE);
776   PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
777   FINISH_RECORD (lineNumbers_type);
778
779 #define instn_ptr_type_node ptr_type_node       /* XXX JH */
780
781 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
782
783   PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
784   PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
785   PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
786   PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
787   FINISH_RECORD (method_type_node);
788   CLASS_LOADED_P (method_type_node) = 1;
789   build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
790
791   endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
792
793   t = tree_cons (NULL_TREE, class_ptr_type,
794                  tree_cons (NULL_TREE, int_type_node, endlink));
795   alloc_object_node = builtin_function ("_Jv_AllocObject",
796                                         build_function_type (ptr_type_node, t),
797                                         0, NOT_BUILT_IN, NULL_PTR);
798   DECL_IS_MALLOC (alloc_object_node) = 1;
799
800   t = tree_cons (NULL_TREE, ptr_type_node, endlink);
801   soft_initclass_node = builtin_function ("_Jv_InitClass",
802                                           build_function_type (void_type_node,
803                                                                t),
804                                           0, NOT_BUILT_IN,
805                                           NULL_PTR);
806   throw_node[0] = builtin_function ("_Jv_Throw",
807                                     build_function_type (ptr_type_node, t),
808                                     0, NOT_BUILT_IN, NULL_PTR);
809   /* Mark throw_nodes as `noreturn' functions with side effects.  */
810   TREE_THIS_VOLATILE (throw_node[0]) = 1;
811   TREE_SIDE_EFFECTS (throw_node[0]) = 1;
812   t = tree_cons (NULL_TREE, ptr_type_node, endlink);
813   throw_node[1] = builtin_function ("_Jv_Sjlj_Throw",
814                                     build_function_type (ptr_type_node, t),
815                                     0, NOT_BUILT_IN, NULL_PTR);
816   TREE_THIS_VOLATILE (throw_node[1]) = 1;
817   TREE_SIDE_EFFECTS (throw_node[1]) = 1;
818   t = build_function_type (int_type_node, endlink);
819   soft_monitorenter_node 
820     = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
821                         NULL_PTR);
822   soft_monitorexit_node 
823     = builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
824                         NULL_PTR);
825   
826   t = tree_cons (NULL_TREE, int_type_node, 
827                  tree_cons (NULL_TREE, int_type_node, endlink));
828   soft_newarray_node
829       = builtin_function ("_Jv_NewArray",
830                           build_function_type(ptr_type_node, t),
831                           0, NOT_BUILT_IN, NULL_PTR);
832   DECL_IS_MALLOC (soft_newarray_node) = 1;
833
834   t = tree_cons (NULL_TREE, int_type_node,
835                  tree_cons (NULL_TREE, class_ptr_type,
836                             tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
837   soft_anewarray_node
838       = builtin_function ("_Jv_NewObjectArray",
839                           build_function_type (ptr_type_node, t),
840                           0, NOT_BUILT_IN, NULL_PTR);
841   DECL_IS_MALLOC (soft_anewarray_node) = 1;
842
843   t = tree_cons (NULL_TREE, ptr_type_node,
844                  tree_cons (NULL_TREE, int_type_node, endlink));
845   soft_multianewarray_node
846       = builtin_function ("_Jv_NewMultiArray",
847                           build_function_type (ptr_type_node, t),
848                           0, NOT_BUILT_IN, NULL_PTR);
849   DECL_IS_MALLOC (soft_multianewarray_node) = 1;
850
851   t = build_function_type (void_type_node, 
852                            tree_cons (NULL_TREE, int_type_node, endlink));
853   soft_badarrayindex_node
854       = builtin_function ("_Jv_ThrowBadArrayIndex", t, 
855                           0, NOT_BUILT_IN, NULL_PTR);
856   /* Mark soft_badarrayindex_node as a `noreturn' function with side
857      effects.  */
858   TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
859   TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
860
861   soft_nullpointer_node
862     = builtin_function ("_Jv_ThrowNullPointerException",
863                         build_function_type (void_type_node, endlink),
864                         0, NOT_BUILT_IN, NULL_PTR);
865   /* Mark soft_nullpointer_node as a `noreturn' function with side
866      effects.  */
867   TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
868   TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
869
870   t = tree_cons (NULL_TREE, class_ptr_type,
871                  tree_cons (NULL_TREE, object_ptr_type_node, endlink));
872   soft_checkcast_node
873     = builtin_function ("_Jv_CheckCast",
874                         build_function_type (ptr_type_node, t),
875                         0, NOT_BUILT_IN, NULL_PTR);
876   t = tree_cons (NULL_TREE, object_ptr_type_node,
877                  tree_cons (NULL_TREE, class_ptr_type, endlink));
878   soft_instanceof_node
879     = builtin_function ("_Jv_IsInstanceOf",
880                         build_function_type (boolean_type_node, t),
881                         0, NOT_BUILT_IN, NULL_PTR);
882   t = tree_cons (NULL_TREE, object_ptr_type_node,
883                  tree_cons (NULL_TREE, object_ptr_type_node, endlink));
884   soft_checkarraystore_node
885     = builtin_function ("_Jv_CheckArrayStore",
886                         build_function_type (void_type_node, t),
887                         0, NOT_BUILT_IN, NULL_PTR);
888   t = tree_cons (NULL_TREE, ptr_type_node,
889                  tree_cons (NULL_TREE, ptr_type_node,
890                             tree_cons (NULL_TREE, int_type_node, endlink)));
891   soft_lookupinterfacemethod_node 
892     = builtin_function ("_Jv_LookupInterfaceMethodIdx",
893                         build_function_type (ptr_type_node, t),
894                         0, NOT_BUILT_IN, NULL_PTR);
895
896   t = tree_cons (NULL_TREE, object_ptr_type_node,
897                  tree_cons (NULL_TREE, ptr_type_node,
898                             tree_cons (NULL_TREE, ptr_type_node, endlink)));
899   soft_lookupjnimethod_node
900     = builtin_function ("_Jv_LookupJNIMethod",
901                         build_function_type (ptr_type_node, t),
902                         0, NOT_BUILT_IN, NULL_PTR);
903   t = tree_cons (NULL_TREE, ptr_type_node, endlink);
904   soft_getjnienvnewframe_node
905     = builtin_function ("_Jv_GetJNIEnvNewFrame",
906                         build_function_type (ptr_type_node, t),
907                         0, NOT_BUILT_IN, NULL_PTR);
908   soft_jnipopsystemframe_node
909     = builtin_function ("_Jv_JNI_PopSystemFrame",
910                         build_function_type (ptr_type_node, t),
911                         0, NOT_BUILT_IN, NULL_PTR);
912
913   t = tree_cons (NULL_TREE, double_type_node,
914                  tree_cons (NULL_TREE, double_type_node, endlink));
915   soft_fmod_node
916     = builtin_function ("__builtin_fmod",
917                         build_function_type (double_type_node, t),
918                         BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmod");
919
920   soft_exceptioninfo_call_node
921     = build (CALL_EXPR, 
922              ptr_type_node,
923              build_address_of 
924                (builtin_function ("_Jv_exception_info", 
925                                   build_function_type (ptr_type_node, endlink),
926                                   0, NOT_BUILT_IN, NULL_PTR)),
927              NULL_TREE, NULL_TREE);
928   TREE_SIDE_EFFECTS (soft_exceptioninfo_call_node) = 1;
929 #if 0
930   t = tree_cons (NULL_TREE, float_type_node,
931                  tree_cons (NULL_TREE, float_type_node, endlink));
932   soft_fmodf_node
933     = builtin_function ("__builtin_fmodf",
934                         build_function_type (float_type_node, t),
935                         BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmodf");
936 #endif
937     
938   soft_idiv_node
939     = builtin_function ("_Jv_divI",
940                         build_function_type (int_type_node, t),
941                         0, NOT_BUILT_IN, NULL_PTR);
942
943   soft_irem_node
944     = builtin_function ("_Jv_remI",
945                         build_function_type (int_type_node, t),
946                         0, NOT_BUILT_IN, NULL_PTR);
947
948   soft_ldiv_node
949     = builtin_function ("_Jv_divJ",
950                         build_function_type (long_type_node, t),
951                         0, NOT_BUILT_IN, NULL_PTR);
952
953   soft_lrem_node
954     = builtin_function ("_Jv_remJ",
955                         build_function_type (long_type_node, t),
956                         0, NOT_BUILT_IN, NULL_PTR);
957
958   init_class_processing ();
959 }
960
961
962 /* Look up NAME in the current binding level and its superiors
963    in the namespace of variables, functions and typedefs.
964    Return a ..._DECL node of some kind representing its definition,
965    or return 0 if it is undefined.  */
966
967 tree
968 lookup_name (name)
969      tree name;
970 {
971   register tree val;
972   if (current_binding_level != global_binding_level
973       && IDENTIFIER_LOCAL_VALUE (name))
974     val = IDENTIFIER_LOCAL_VALUE (name);
975   else
976     val = IDENTIFIER_GLOBAL_VALUE (name);
977   return val;
978 }
979
980 /* Similar to `lookup_name' but look only at current binding level and
981    the previous one if its the parameter level.  */
982
983 static tree
984 lookup_name_current_level (name)
985      tree name;
986 {
987   register tree t;
988
989   if (current_binding_level == global_binding_level)
990     return IDENTIFIER_GLOBAL_VALUE (name);
991
992   if (IDENTIFIER_LOCAL_VALUE (name) == 0)
993     return 0;
994
995   for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
996     if (DECL_NAME (t) == name)
997       break;
998
999   return t;
1000 }
1001
1002 /* Use a binding level to record a labeled block declaration */
1003
1004 void
1005 push_labeled_block (lb)
1006     tree lb;
1007 {
1008   register tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
1009   register struct binding_level *b = current_binding_level;
1010   tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1011   if (oldlocal != 0)
1012       b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1013   TREE_CHAIN (lb) = b->names;
1014   b->names = lb;
1015   IDENTIFIER_LOCAL_VALUE (name) = lb;
1016 }
1017
1018 /* Pop the current binding level, reinstalling values for the previous
1019    labeled block */
1020
1021 void
1022 pop_labeled_block ()
1023 {
1024   struct binding_level *b = current_binding_level;
1025   tree label =  b->names;
1026   IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) = 
1027     NULL_TREE;
1028   if (b->shadowed)
1029     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) = 
1030       TREE_VALUE (b->shadowed);
1031
1032   /* Pop the current level, and free the structure for reuse.  */
1033   current_binding_level = current_binding_level->level_chain;
1034   b->level_chain = free_binding_level;
1035   free_binding_level = b;
1036 }
1037
1038 /* Record a decl-node X as belonging to the current lexical scope.
1039    Check for errors (such as an incompatible declaration for the same
1040    name already seen in the same scope).
1041
1042    Returns either X or an old decl for the same name.
1043    If an old decl is returned, it may have been smashed
1044    to agree with what X says.  */
1045
1046 tree
1047 pushdecl (x)
1048      tree x;
1049 {
1050   register tree t;
1051   register tree name = DECL_NAME (x);
1052   register struct binding_level *b = current_binding_level;
1053   
1054   if (TREE_CODE (x) != TYPE_DECL)
1055     DECL_CONTEXT (x) = current_function_decl;
1056   if (name)
1057     {
1058       const char *file;
1059       int line;
1060
1061       t = lookup_name_current_level (name);
1062       if (t != 0 && t == error_mark_node)
1063         /* error_mark_node is 0 for a while during initialization!  */
1064         {
1065           t = 0;
1066           error_with_decl (x, "`%s' used prior to declaration");
1067         }
1068
1069       if (t != 0)
1070         {
1071           file = DECL_SOURCE_FILE (t);
1072           line = DECL_SOURCE_LINE (t);
1073         }
1074
1075       /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1076          to point to the TYPE_DECL.
1077          Since Java does not have typedefs, a type can only have
1078          one (true) name, given by a class, interface, or builtin. */
1079       if (TREE_CODE (x) == TYPE_DECL
1080           && TYPE_NAME (TREE_TYPE (x)) == 0
1081           && TREE_TYPE (x) != error_mark_node)
1082         {
1083           TYPE_NAME (TREE_TYPE (x)) = x;
1084           TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1085         }
1086
1087       /* This name is new in its binding level.
1088          Install the new declaration and return it.  */
1089       if (b == global_binding_level)
1090         {
1091           /* Install a global value.  */
1092           
1093           IDENTIFIER_GLOBAL_VALUE (name) = x;
1094         }
1095       else
1096         {
1097           /* Here to install a non-global value.  */
1098           tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1099           IDENTIFIER_LOCAL_VALUE (name) = x;
1100
1101 #if 0
1102           /* Warn if shadowing an argument at the top level of the body.  */
1103           if (oldlocal != 0 && !DECL_EXTERNAL (x)
1104               /* This warning doesn't apply to the parms of a nested fcn.  */
1105               && ! current_binding_level->parm_flag
1106               /* Check that this is one level down from the parms.  */
1107               && current_binding_level->level_chain->parm_flag
1108               /* Check that the decl being shadowed
1109                  comes from the parm level, one level up.  */
1110               && chain_member (oldlocal, current_binding_level->level_chain->names))
1111             {
1112               if (TREE_CODE (oldlocal) == PARM_DECL)
1113                 pedwarn ("declaration of `%s' shadows a parameter",
1114                          IDENTIFIER_POINTER (name));
1115               else
1116                 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1117                          IDENTIFIER_POINTER (name));
1118             }
1119
1120           /* Maybe warn if shadowing something else.  */
1121           else if (warn_shadow && !DECL_EXTERNAL (x)
1122                    /* No shadow warnings for internally generated vars.  */
1123                    && DECL_SOURCE_LINE (x) != 0
1124                    /* No shadow warnings for vars made for inlining.  */
1125                    && ! DECL_FROM_INLINE (x))
1126             {
1127               const char *warnstring = 0;
1128
1129               if (TREE_CODE (x) == PARM_DECL
1130                   && current_binding_level->level_chain->parm_flag)
1131                 /* Don't warn about the parm names in function declarator
1132                    within a function declarator.
1133                    It would be nice to avoid warning in any function
1134                    declarator in a declaration, as opposed to a definition,
1135                    but there is no way to tell it's not a definition.  */
1136                 ;
1137               else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
1138                 warnstring = "declaration of `%s' shadows a parameter";
1139               else if (oldlocal != 0)
1140                 warnstring = "declaration of `%s' shadows previous local";
1141               else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
1142                        && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
1143                 warnstring = "declaration of `%s' shadows global declaration";
1144
1145               if (warnstring)
1146                 warning (warnstring, IDENTIFIER_POINTER (name));
1147             }
1148 #endif
1149
1150           /* If storing a local value, there may already be one (inherited).
1151              If so, record it for restoration when this binding level ends.  */
1152           if (oldlocal != 0)
1153             b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1154         }
1155     }
1156
1157   /* Put decls on list in reverse order.
1158      We will reverse them later if necessary.  */
1159   TREE_CHAIN (x) = b->names;
1160   b->names = x;
1161
1162   return x;
1163 }
1164
1165 void
1166 pushdecl_force_head (x)
1167      tree x;
1168 {
1169   current_binding_level->names = x;
1170 }
1171
1172 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate.  */
1173
1174 tree
1175 pushdecl_top_level (x)
1176      tree x;
1177 {
1178   register tree t;
1179   register struct binding_level *b = current_binding_level;
1180
1181   current_binding_level = global_binding_level;
1182   t = pushdecl (x);
1183   current_binding_level = b;
1184   return t;
1185 }
1186
1187 /* Nonzero if we are currently in the global binding level.  */
1188
1189 int
1190 global_bindings_p ()
1191 {
1192   return current_binding_level == global_binding_level;
1193 }
1194
1195 /* Return the list of declarations of the current level.
1196    Note that this list is in reverse order unless/until
1197    you nreverse it; and when you do nreverse it, you must
1198    store the result back using `storedecls' or you will lose.  */
1199
1200 tree
1201 getdecls ()
1202 {
1203   return current_binding_level->names;
1204 }
1205
1206 /* Create a new `struct binding_level'.  */
1207
1208 static struct binding_level *
1209 make_binding_level ()
1210 {
1211   /* NOSTRICT */
1212   return (struct binding_level *) xmalloc (sizeof (struct binding_level));
1213 }
1214
1215 void
1216 pushlevel (unused)
1217   int unused ATTRIBUTE_UNUSED;
1218 {
1219   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1220
1221 #if 0
1222   /* If this is the top level of a function,
1223      just make sure that NAMED_LABELS is 0.  */
1224
1225   if (current_binding_level == global_binding_level)
1226     named_labels = 0;
1227 #endif
1228
1229   /* Reuse or create a struct for this binding level.  */
1230
1231   if (free_binding_level)
1232     {
1233       newlevel = free_binding_level;
1234       free_binding_level = free_binding_level->level_chain;
1235     }
1236   else
1237     {
1238       newlevel = make_binding_level ();
1239     }
1240
1241   /* Add this level to the front of the chain (stack) of levels that
1242      are active.  */
1243
1244   *newlevel = clear_binding_level;
1245   newlevel->level_chain = current_binding_level;
1246   current_binding_level = newlevel;
1247   newlevel->keep = keep_next_level_flag;
1248   keep_next_level_flag = 0;
1249   newlevel->keep_if_subblocks = keep_next_if_subblocks;
1250   keep_next_if_subblocks = 0;
1251 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1252   newlevel->binding_depth = binding_depth;
1253   indent ();
1254   fprintf (stderr, "push %s level 0x%08x pc %d\n",
1255            (is_class_level) ? "class" : "block", newlevel, current_pc);
1256   is_class_level = 0;
1257   binding_depth++;
1258 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1259 }
1260
1261 /* Exit a binding level.
1262    Pop the level off, and restore the state of the identifier-decl mappings
1263    that were in effect when this level was entered.
1264
1265    If KEEP is nonzero, this level had explicit declarations, so
1266    and create a "block" (a BLOCK node) for the level
1267    to record its declarations and subblocks for symbol table output.
1268
1269    If FUNCTIONBODY is nonzero, this level is the body of a function,
1270    so create a block as if KEEP were set and also clear out all
1271    label names.
1272
1273    If REVERSE is nonzero, reverse the order of decls before putting
1274    them into the BLOCK.  */
1275
1276 tree
1277 poplevel (keep, reverse, functionbody)
1278      int keep;
1279      int reverse;
1280      int functionbody;
1281 {
1282   register tree link;
1283   /* The chain of decls was accumulated in reverse order.
1284      Put it into forward order, just for cleanliness.  */
1285   tree decls;
1286   tree subblocks = current_binding_level->blocks;
1287   tree block = 0;
1288   tree decl;
1289   int block_previously_created;
1290
1291 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1292   binding_depth--;
1293   indent ();
1294   if (current_binding_level->end_pc != LARGEST_PC)
1295     fprintf (stderr, "pop  %s level 0x%08x pc %d (end pc %d)\n",
1296              (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1297              current_binding_level->end_pc);
1298   else
1299     fprintf (stderr, "pop  %s level 0x%08x pc %d\n",
1300              (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1301 #if 0
1302   if (is_class_level != (current_binding_level == class_binding_level))
1303     {
1304       indent ();
1305       fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1306     }
1307   is_class_level = 0;
1308 #endif
1309 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1310
1311   keep |= current_binding_level->keep;
1312
1313   /* Get the decls in the order they were written.
1314      Usually current_binding_level->names is in reverse order.
1315      But parameter decls were previously put in forward order.  */
1316
1317   if (reverse)
1318     current_binding_level->names
1319       = decls = nreverse (current_binding_level->names);
1320   else
1321     decls = current_binding_level->names;
1322
1323   /* Output any nested inline functions within this block
1324      if they weren't already output.  */
1325
1326   for (decl = decls; decl; decl = TREE_CHAIN (decl))
1327     if (TREE_CODE (decl) == FUNCTION_DECL
1328         && ! TREE_ASM_WRITTEN (decl)
1329         && DECL_INITIAL (decl) != 0
1330         && TREE_ADDRESSABLE (decl))
1331       {
1332         /* If this decl was copied from a file-scope decl
1333            on account of a block-scope extern decl,
1334            propagate TREE_ADDRESSABLE to the file-scope decl.
1335
1336            DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1337            true, since then the decl goes through save_for_inline_copying.  */
1338         if (DECL_ABSTRACT_ORIGIN (decl) != 0
1339             && DECL_ABSTRACT_ORIGIN (decl) != decl)
1340           TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1341         else
1342           {
1343             push_function_context ();
1344             output_inline_function (decl);
1345             pop_function_context ();
1346           }
1347       }
1348
1349   /* If there were any declarations in that level,
1350      or if this level is a function body,
1351      create a BLOCK to record them for the life of this function.  */
1352
1353   block = 0;
1354   block_previously_created = (current_binding_level->this_block != 0);
1355   if (block_previously_created)
1356     block = current_binding_level->this_block;
1357   else if (keep || functionbody
1358            || (current_binding_level->keep_if_subblocks && subblocks != 0))
1359     block = make_node (BLOCK);
1360   if (block != 0)
1361     {
1362       BLOCK_VARS (block) = decls;
1363       BLOCK_SUBBLOCKS (block) = subblocks;
1364     }
1365
1366   /* In each subblock, record that this is its superior.  */
1367
1368   for (link = subblocks; link; link = TREE_CHAIN (link))
1369     BLOCK_SUPERCONTEXT (link) = block;
1370
1371   /* Clear out the meanings of the local variables of this level.  */
1372
1373   for (link = decls; link; link = TREE_CHAIN (link))
1374     {
1375       tree name = DECL_NAME (link);
1376       if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1377         {
1378           /* If the ident. was used or addressed via a local extern decl,
1379              don't forget that fact.  */
1380           if (DECL_EXTERNAL (link))
1381             {
1382               if (TREE_USED (link))
1383                 TREE_USED (name) = 1;
1384               if (TREE_ADDRESSABLE (link))
1385                 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1386             }
1387           IDENTIFIER_LOCAL_VALUE (name) = 0;
1388         }
1389     }
1390
1391   /* Restore all name-meanings of the outer levels
1392      that were shadowed by this level.  */
1393
1394   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1395     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1396
1397   /* If the level being exited is the top level of a function,
1398      check over all the labels, and clear out the current
1399      (function local) meanings of their names.  */
1400
1401   if (functionbody)
1402     {
1403       /* If this is the top level block of a function,
1404          the vars are the function's parameters.
1405          Don't leave them in the BLOCK because they are
1406          found in the FUNCTION_DECL instead.  */
1407
1408       BLOCK_VARS (block) = 0;
1409
1410       /* Clear out the definitions of all label names,
1411          since their scopes end here,
1412          and add them to BLOCK_VARS.  */
1413
1414 #if 0
1415       for (link = named_labels; link; link = TREE_CHAIN (link))
1416         {
1417           register tree label = TREE_VALUE (link);
1418
1419           if (DECL_INITIAL (label) == 0)
1420             {
1421               error_with_decl (label, "label `%s' used but not defined");
1422               /* Avoid crashing later.  */
1423               define_label (input_filename, lineno,
1424                             DECL_NAME (label));
1425             }
1426           else if (warn_unused[UNUSED_LABEL] && !TREE_USED (label))
1427             warning_with_decl (label, "label `%s' defined but not used");
1428           IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1429
1430           /* Put the labels into the "variables" of the
1431              top-level block, so debugger can see them.  */
1432           TREE_CHAIN (label) = BLOCK_VARS (block);
1433           BLOCK_VARS (block) = label;
1434         }
1435 #endif
1436     }
1437
1438   /* Pop the current level, and free the structure for reuse.  */
1439
1440   {
1441     register struct binding_level *level = current_binding_level;
1442     current_binding_level = current_binding_level->level_chain;
1443
1444     level->level_chain = free_binding_level;
1445     free_binding_level = level;
1446   }
1447
1448   /* Dispose of the block that we just made inside some higher level.  */
1449   if (functionbody)
1450     DECL_INITIAL (current_function_decl) = block;
1451   else if (block)
1452     {
1453       if (!block_previously_created)
1454         current_binding_level->blocks
1455           = chainon (current_binding_level->blocks, block);
1456     }
1457   /* If we did not make a block for the level just exited,
1458      any blocks made for inner levels
1459      (since they cannot be recorded as subblocks in that level)
1460      must be carried forward so they will later become subblocks
1461      of something else.  */
1462   else if (subblocks)
1463     current_binding_level->blocks
1464       = chainon (current_binding_level->blocks, subblocks);
1465
1466   /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1467      binding contour so that they point to the appropriate construct, i.e.
1468      either to the current FUNCTION_DECL node, or else to the BLOCK node
1469      we just constructed.
1470
1471      Note that for tagged types whose scope is just the formal parameter
1472      list for some function type specification, we can't properly set
1473      their TYPE_CONTEXTs here, because we don't have a pointer to the
1474      appropriate FUNCTION_TYPE node readily available to us.  For those
1475      cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1476      in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1477      node which will represent the "scope" for these "parameter list local"
1478      tagged types.
1479   */
1480
1481   if (block)
1482     TREE_USED (block) = 1;
1483   return block;
1484 }
1485
1486 void
1487 maybe_pushlevels (pc)
1488      int pc;
1489 {
1490 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1491   current_pc = pc;
1492 #endif
1493
1494   while (pending_local_decls != NULL_TREE &&
1495          DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1496     {
1497       tree *ptr = &pending_local_decls;
1498       tree decl = *ptr;
1499       int end_pc = DECL_LOCAL_END_PC (decl);
1500
1501       while (*ptr != NULL_TREE
1502              && DECL_LOCAL_START_PC (*ptr) <= pc
1503              && DECL_LOCAL_END_PC (*ptr) == end_pc)
1504         ptr = &TREE_CHAIN (*ptr);
1505       pending_local_decls = *ptr;
1506       *ptr = NULL_TREE;
1507
1508       /* Force non-nested range to be nested in current range. */
1509       if (end_pc > current_binding_level->end_pc)
1510         end_pc = current_binding_level->end_pc;
1511
1512       maybe_start_try (pc, end_pc);
1513       
1514       pushlevel (1);
1515       expand_start_bindings (0);
1516
1517       current_binding_level->end_pc = end_pc;
1518       current_binding_level->start_pc = pc;      
1519       current_binding_level->names = decl;
1520       for ( ; decl != NULL_TREE;  decl = TREE_CHAIN (decl))
1521         {
1522           push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1523         }
1524     }      
1525
1526   maybe_start_try (pc, 0);
1527 }
1528
1529 void
1530 maybe_poplevels (pc)
1531      int pc;
1532 {
1533 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1534   current_pc = pc;
1535 #endif
1536
1537   while (current_binding_level->end_pc <= pc)
1538     {
1539       expand_end_bindings (getdecls (), 1, 0);
1540       maybe_end_try (current_binding_level->start_pc, pc);
1541       poplevel (1, 0, 0);
1542     }
1543   maybe_end_try (0, pc);
1544 }
1545
1546 /* Terminate any binding which began during the range beginning at
1547    start_pc.  This tidies up improperly nested local variable ranges
1548    and exception handlers; a variable declared within an exception
1549    range is forcibly terminated when that exception ends. */
1550
1551 void
1552 force_poplevels (start_pc)
1553      int start_pc;
1554 {
1555   while (current_binding_level->start_pc > start_pc)
1556     {
1557       if (pedantic && current_binding_level->start_pc > start_pc)
1558         warning_with_decl (current_function_decl, 
1559                            "In %s: overlapped variable and exception ranges at %d",
1560                            current_binding_level->start_pc);
1561       expand_end_bindings (getdecls (), 1, 0);
1562       poplevel (1, 0, 0);
1563     }
1564 }
1565
1566 /* Insert BLOCK at the end of the list of subblocks of the
1567    current binding level.  This is used when a BIND_EXPR is expanded,
1568    to handle the BLOCK node inside the BIND_EXPR.  */
1569
1570 void
1571 insert_block (block)
1572      tree block;
1573 {
1574   TREE_USED (block) = 1;
1575   current_binding_level->blocks
1576     = chainon (current_binding_level->blocks, block);
1577 }
1578
1579 /* Set the BLOCK node for the innermost scope
1580    (the one we are currently in).  */
1581
1582 void
1583 set_block (block)
1584      register tree block;
1585 {
1586   current_binding_level->this_block = block;
1587 }
1588
1589 /* integrate_decl_tree calls this function. */
1590
1591 void
1592 copy_lang_decl (node)
1593      tree node;
1594 {
1595   int lang_decl_size
1596     = TREE_CODE (node) == VAR_DECL ? sizeof (struct lang_decl_var)
1597     : sizeof (struct lang_decl);
1598   struct lang_decl *x = (struct lang_decl *) oballoc (lang_decl_size);
1599   bcopy ((PTR) DECL_LANG_SPECIFIC (node), (PTR) x, lang_decl_size);
1600   DECL_LANG_SPECIFIC (node) = x;
1601 }
1602
1603 /* If DECL has a cleanup, build and return that cleanup here.
1604    This is a callback called by expand_expr.  */
1605
1606 tree
1607 maybe_build_cleanup (decl)
1608   tree decl ATTRIBUTE_UNUSED;
1609 {
1610   /* There are no cleanups in Java (I think).  */
1611   return NULL_TREE;
1612 }
1613
1614 void
1615 give_name_to_locals (jcf)
1616      JCF *jcf;
1617 {
1618   int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1619   tree parm;
1620   pending_local_decls = NULL_TREE;
1621   if (n == 0)
1622     return;
1623   JCF_SEEK (jcf, n);
1624   n = JCF_readu2 (jcf);
1625   for (i = 0; i < n; i++)
1626     {
1627       int start_pc = JCF_readu2 (jcf);
1628       int length = JCF_readu2 (jcf);
1629       int name_index = JCF_readu2 (jcf);
1630       int signature_index = JCF_readu2 (jcf);
1631       int slot = JCF_readu2 (jcf);
1632       tree name = get_name_constant (jcf, name_index);
1633       tree type = parse_signature (jcf, signature_index);
1634       if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1635           && start_pc == 0
1636           && length == DECL_CODE_LENGTH (current_function_decl))
1637         {
1638           tree decl = TREE_VEC_ELT (decl_map, slot);
1639           DECL_NAME (decl) = name;
1640           DECL_ASSEMBLER_NAME (decl) = name;
1641           if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1642             warning ("bad type in parameter debug info");
1643         }
1644       else
1645         {
1646           tree *ptr;
1647           int end_pc = start_pc + length;
1648           tree decl = build_decl (VAR_DECL, name, type);
1649           if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1650             {
1651               warning_with_decl (decl,
1652                          "bad PC range for debug info for local `%s'");
1653               end_pc = DECL_CODE_LENGTH (current_function_decl);
1654             }
1655           DECL_LANG_SPECIFIC (decl)
1656             = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
1657           DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1658           DECL_LOCAL_START_PC (decl) = start_pc;
1659 #if 0
1660           /* FIXME: The range used internally for exceptions and local
1661              variable ranges, is a half-open interval: 
1662              start_pc <= pc < end_pc.  However, the range used in the
1663              Java VM spec is inclusive at both ends: 
1664              start_pc <= pc <= end_pc. */
1665           end_pc++;
1666 #endif
1667           DECL_LOCAL_END_PC (decl) = end_pc;
1668
1669           /* Now insert the new decl in the proper place in
1670              pending_local_decls.  We are essentially doing an insertion sort,
1671              which works fine, since the list input will normally already
1672              be sorted. */
1673           ptr = &pending_local_decls;
1674           while (*ptr != NULL_TREE
1675                  && (DECL_LOCAL_START_PC (*ptr) > start_pc
1676                      || (DECL_LOCAL_START_PC (*ptr) == start_pc
1677                          && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1678             ptr = &TREE_CHAIN (*ptr);
1679           TREE_CHAIN (decl) = *ptr;
1680           *ptr = decl;
1681         }
1682     }
1683
1684   pending_local_decls = nreverse (pending_local_decls);
1685
1686   /* Fill in default names for the parameters. */ 
1687   for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1688        parm != NULL_TREE;  parm = TREE_CHAIN (parm), i++)
1689     {
1690       if (DECL_NAME (parm) == NULL_TREE)
1691         {
1692           int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1693           if (arg_i == 0)
1694             DECL_NAME (parm) = get_identifier ("this");
1695           else
1696             {
1697               char buffer[12];
1698               sprintf (buffer, "ARG_%d", arg_i);
1699               DECL_NAME (parm) = get_identifier (buffer);
1700             }
1701           DECL_ASSEMBLER_NAME (parm) = DECL_NAME (parm);
1702         }
1703     }
1704 }
1705
1706 tree
1707 build_result_decl (fndecl)
1708   tree fndecl;
1709 {
1710   tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1711   /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1712   if (INTEGRAL_TYPE_P (restype)
1713       && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1714     restype = integer_type_node;
1715   return (DECL_RESULT (fndecl) = build_decl (RESULT_DECL, NULL_TREE, restype));
1716 }
1717
1718 /* Called for every element in DECL_FUNCTION_INIT_TEST_TABLE in order
1719    to emit initialization code for each test flag.  */
1720
1721 static boolean
1722 emit_init_test_initialization (entry, key)
1723   struct hash_entry *entry;
1724   hash_table_key key ATTRIBUTE_UNUSED;
1725 {
1726   struct init_test_hash_entry *ite = (struct init_test_hash_entry *) entry;
1727   tree klass = build_class_ref ((tree) entry->key);
1728   expand_decl (ite->init_test_decl);
1729
1730   /* We initialize the class init check variable by looking at the
1731      `state' field of the class to see if it is already initialized.
1732      This makes things a bit faster if the class is already
1733      initialized, which should be the common case.  */
1734   expand_expr_stmt
1735     (build (MODIFY_EXPR, boolean_type_node, 
1736             ite->init_test_decl,
1737             build (GE_EXPR, boolean_type_node,
1738                    build (COMPONENT_REF, byte_type_node,
1739                           build1 (INDIRECT_REF, class_type_node, klass),
1740                           lookup_field (&class_type_node,
1741                                         get_identifier ("state"))),
1742                    build_int_2 (JV_STATE_DONE, 0))));
1743
1744   return true;
1745 }
1746
1747 void
1748 complete_start_java_method (fndecl)
1749   tree fndecl;
1750 {
1751   if (! flag_emit_class_files)
1752     {
1753       /* Initialize the RTL code for the function.  */
1754       init_function_start (fndecl, input_filename, lineno);
1755
1756       /* Set up parameters and prepare for return, for the function.  */
1757       expand_function_start (fndecl, 0);
1758
1759       /* Emit initialization code for test flags.  */
1760       if (! always_initialize_class_p)
1761         hash_traverse (&DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1762                        emit_init_test_initialization, 0);
1763     }
1764
1765   /* Allocate further tree nodes temporarily during compilation
1766      of this function only.  */
1767   temporary_allocation ();
1768
1769 #if 0
1770       /* If this fcn was already referenced via a block-scope `extern' decl (or
1771          an implicit decl), propagate certain information about the usage. */
1772       if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
1773         TREE_ADDRESSABLE (current_function_decl) = 1;
1774
1775 #endif
1776
1777   if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
1778       && ! flag_emit_class_files
1779       && ! DECL_CLINIT_P (fndecl)
1780       && ! CLASS_INTERFACE (TYPE_NAME (current_class)))
1781     {
1782       tree clas = DECL_CONTEXT (fndecl);
1783       tree init = build (CALL_EXPR, void_type_node,
1784                          build_address_of (soft_initclass_node),
1785                          build_tree_list (NULL_TREE, build_class_ref (clas)),
1786                          NULL_TREE);
1787       TREE_SIDE_EFFECTS (init) = 1;
1788       expand_expr_stmt (init);
1789     }
1790
1791   /* Push local variables. Function compiled from source code are
1792      using a different local variables management, and for them,
1793      pushlevel shouldn't be called from here.  */
1794   if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1795     {
1796       pushlevel (2);
1797       if (! flag_emit_class_files)
1798         expand_start_bindings (1);
1799     }
1800
1801   if (METHOD_SYNCHRONIZED (fndecl) && ! flag_emit_class_files)
1802     {
1803       /* Wrap function body with a monitorenter plus monitorexit cleanup. */
1804       tree enter, exit, lock;
1805       if (METHOD_STATIC (fndecl))
1806         lock = build_class_ref (DECL_CONTEXT (fndecl));
1807       else
1808         lock = DECL_ARGUMENTS (fndecl);
1809       BUILD_MONITOR_ENTER (enter, lock);
1810       BUILD_MONITOR_EXIT (exit, lock);
1811       if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1812         {
1813           expand_expr_stmt (enter);
1814           expand_decl_cleanup (NULL_TREE, exit);
1815         }
1816       else
1817         {
1818           tree function_body = DECL_FUNCTION_BODY (fndecl);
1819           tree body = BLOCK_EXPR_BODY (function_body);
1820           lock = build (WITH_CLEANUP_EXPR, void_type_node,
1821                         enter,  NULL_TREE, exit);
1822           TREE_SIDE_EFFECTS (lock) = 1;
1823           lock = build (COMPOUND_EXPR, TREE_TYPE (body), lock, body);
1824           TREE_SIDE_EFFECTS (lock) = 1;
1825           lock = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (body), lock);
1826           TREE_SIDE_EFFECTS (lock) = 1;
1827           BLOCK_EXPR_BODY (function_body) = lock;
1828         }
1829     }
1830 }
1831
1832 void
1833 start_java_method (fndecl)
1834      tree fndecl;
1835 {
1836   tree tem, *ptr;
1837   int i;
1838
1839   current_function_decl = fndecl;
1840   announce_function (fndecl);
1841
1842   i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1843   decl_map = make_tree_vec (i);
1844   type_map = (tree *) oballoc (i * sizeof (tree));
1845
1846 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1847   fprintf (stderr, "%s:\n", (*decl_printable_name) (fndecl, 2));
1848   current_pc = 0;
1849 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1850   pushlevel (1);  /* Push parameters. */
1851
1852   ptr = &DECL_ARGUMENTS (fndecl);
1853   for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1854        tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1855     {
1856       tree parm_name = NULL_TREE, parm_decl;
1857       tree parm_type = TREE_VALUE (tem);
1858       if (i >= DECL_MAX_LOCALS(fndecl))
1859         fatal ("function has more parameters than local slots");
1860
1861       parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1862       DECL_CONTEXT (parm_decl) = fndecl;
1863       if (PROMOTE_PROTOTYPES
1864           && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1865           && INTEGRAL_TYPE_P (parm_type))
1866         parm_type = integer_type_node;
1867       DECL_ARG_TYPE (parm_decl) = parm_type;
1868
1869       *ptr = parm_decl;
1870       ptr = &TREE_CHAIN (parm_decl);
1871
1872       /* Add parm_decl to the decl_map. */
1873       push_jvm_slot (i, parm_decl);
1874
1875       type_map[i] = TREE_TYPE (parm_decl);
1876       if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1877         {
1878           i++;
1879           type_map[i] = void_type_node;
1880         }
1881     }
1882   *ptr = NULL_TREE;
1883   DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1884
1885   while (i < DECL_MAX_LOCALS(fndecl))
1886     type_map[i++] = NULL_TREE;
1887
1888   build_result_decl (fndecl);
1889   complete_start_java_method (fndecl);
1890 }
1891
1892 void
1893 end_java_method ()
1894 {
1895   tree fndecl = current_function_decl;
1896   int flag_asynchronous_exceptions = asynchronous_exceptions;
1897
1898   expand_end_bindings (getdecls (), 1, 0);
1899   /* pop out of function */
1900   poplevel (1, 1, 0);
1901
1902   /* pop out of its parameters */
1903   poplevel (1, 0, 1);
1904
1905   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1906
1907   emit_handlers ();
1908
1909   /* Generate rtl for function exit.  */
1910   expand_function_end (input_filename, lineno, 0);
1911
1912   /* FIXME: If the current method contains any exception handlers,
1913      force asynchronous_exceptions: this is necessary because signal
1914      handlers in libjava may throw exceptions.  This is far from being
1915      a perfect solution, but it's better than doing nothing at all.*/
1916   if (catch_clauses)
1917     asynchronous_exceptions = 1;
1918
1919   /* Run the optimizers and output assembler code for this function. */
1920   rest_of_compilation (fndecl);
1921
1922   current_function_decl = NULL_TREE;
1923   permanent_allocation (1);
1924   asynchronous_exceptions = flag_asynchronous_exceptions;
1925 }