OSDN Git Service

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