OSDN Git Service

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