OSDN Git Service

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